void LoadAllCampaigns(custom_campaigns_t *campaigns) { char buf[CDOGS_PATH_MAX]; CampaignListInit(&campaigns->campaignList); CampaignListInit(&campaigns->dogfightList); GetDataFilePath(buf, CDOGS_CAMPAIGN_DIR); LOG(LM_MAIN, LL_INFO, "Load campaigns from dir %s...", buf); LoadCampaignsFromFolder( &campaigns->campaignList, "", buf, GAME_MODE_NORMAL); GetDataFilePath(buf, CDOGS_DOGFIGHT_DIR); LOG(LM_MAIN, LL_INFO, "Load dogfights from dir %s...", buf); LoadCampaignsFromFolder( &campaigns->dogfightList, "", buf, GAME_MODE_DOGFIGHT); LOG(LM_MAIN, LL_INFO, "Load quick play..."); LoadQuickPlayEntry(&campaigns->quickPlayEntry); }
void LoadAllCampaigns(custom_campaigns_t *campaigns) { CampaignListInit(&campaigns->campaignList); CampaignListInit(&campaigns->dogfightList); printf("\nCampaigns:\n"); LoadBuiltinCampaigns(&campaigns->campaignList); LoadCampaignsFromFolder( &campaigns->campaignList, "", GetDataFilePath(CDOGS_CAMPAIGN_DIR), 0); printf("\nDogfights:\n"); LoadBuiltinDogfights(&campaigns->dogfightList); LoadCampaignsFromFolder( &campaigns->dogfightList, "", GetDataFilePath(CDOGS_DOGFIGHT_DIR), 1); LoadQuickPlayEntry(&campaigns->quickPlayEntry); printf("\n"); }
int PicManagerTryInit( PicManager *pm, const char *oldGfxFile1, const char *oldGfxFile2) { int i; memset(pm, 0, sizeof *pm); CArrayInit(&pm->pics, sizeof(NamedPic)); CArrayInit(&pm->sprites, sizeof(NamedSprites)); CArrayInit(&pm->customPics, sizeof(NamedPic)); CArrayInit(&pm->customSprites, sizeof(NamedSprites)); char buf[CDOGS_PATH_MAX]; GetDataFilePath(buf, oldGfxFile1); i = ReadPics(buf, pm->oldPics, PIC_COUNT1, pm->palette); if (!i) { printf("Unable to read %s\n", buf); return 0; } GetDataFilePath(buf, oldGfxFile2); if (!AppendPics(buf, pm->oldPics, PIC_COUNT1, PIC_MAX)) { printf("Unable to read %s\n", buf); return 0; } pm->palette[0].r = pm->palette[0].g = pm->palette[0].b = 0; return 1; }
void JoyInit(CArray *joys) { char buf[CDOGS_PATH_MAX]; GetDataFilePath(buf, "data/gamecontrollerdb.txt"); if (SDL_GameControllerAddMappingsFromFile(buf) == -1) { LOG(LM_INPUT, LL_ERROR, "cannot load controller mappings file: %s", SDL_GetError()); } GetDataFilePath(buf, "data/gamecontrollerbuttondb.txt"); if (SDLJBN_AddMappingsFromFile(buf) == -1) { LOG(LM_INPUT, LL_ERROR, "cannot load button mappings file: %s", SDLJBN_GetError()); } CArrayInit(joys, sizeof(Joystick)); // Detect all current controllers const int n = SDL_NumJoysticks(); LOG(LM_INPUT, LL_INFO, "%d controllers found", n); if (n == 0) { return; } for (int i = 0; i < n; i++) { JoyAdded(i); } }
void MusicPlayGame( SoundDevice *device, const char *missionPath, const char *music) { // Play a tune // Start by trying to play a mission specific song, // otherwise pick one from the general collection... MusicStop(device); bool played = false; if (music != NULL && strlen(music) != 0) { char buf[CDOGS_PATH_MAX]; // First, try to play music from the same directory // This may be a new-style directory campaign GetDataFilePath(buf, missionPath); strcat(buf, "/"); strcat(buf, music); played = MusicPlay(device, buf); if (!played) { char buf2[CDOGS_PATH_MAX]; GetDataFilePath(buf2, missionPath); PathGetDirname(buf, buf2); strcat(buf, music); played = MusicPlay(device, buf); } } if (!played && gGameSongs != NULL) { MusicPlay(device, gGameSongs->path); ShiftSongs(&gGameSongs); } }
void LookForCustomCampaigns(void) { int i; printf("\nCampaigns:\n"); campaignList = GetFilesFromDirectory(GetDataFilePath("missions/")); GetCampaignTitles(&campaignList); i = 0; while (SetupBuiltinCampaign(i)) { AddFileEntry(&campaignList, "", gCampaign.setting->title, i); i++; } printf("\nDogfights:\n"); dogfightList = GetFilesFromDirectory(GetDataFilePath("dogfights/")); GetCampaignTitles(&dogfightList); i = 0; while (SetupBuiltinDogfight(i)) { AddFileEntry(&dogfightList, "", gCampaign.setting->title, i); i++; } printf("\n"); }
bool PlayerSelection(void) { PlayerSelectionData data; memset(&data, 0, sizeof data); data.IsOK = true; GetDataFilePath(data.prefixes, "data/prefixes.txt"); GetDataFilePath(data.suffixes, "data/suffixes.txt"); GetDataFilePath(data.suffixnames, "data/suffixnames.txt"); NameGenInit(&data.g, data.prefixes, data.suffixes, data.suffixnames); // Create selection menus for each local player for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } PlayerSelectMenusCreate( &data.menus[idx], GetNumPlayers(false, false, true), idx, i, &gEventHandlers, &gGraphicsDevice, &data.g); } if (!gCampaign.IsClient) { NetServerOpen(&gNetServer); } GameLoopData gData = GameLoopDataNew( &data, PlayerSelectionUpdate, &data, PlayerSelectionDraw); GameLoop(&gData); if (data.IsOK) { for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++) { PlayerData *p = CArrayGet(&gPlayerDatas, i); if (!p->IsLocal) { idx--; continue; } // For any player slots not picked, turn them into AIs if (p->inputDevice == INPUT_DEVICE_UNSET) { PlayerSetInputDevice(p, INPUT_DEVICE_AI, 0); } } } for (int i = 0; i < GetNumPlayers(false, false, true); i++) { MenuSystemTerminate(&data.menus[i].ms); } NameGenTerminate(&data.g); return data.IsOK; }
int InitSoundDevice(void) { int i; struct stat st; SDL_AudioSpec tmpspec; // Initialization goes here... Mix_OpenAudio(22050, AUDIO_S16, 2, 512); Mix_AllocateChannels(20); // C-Dogs internals: loadSampleConfiguration(); for (i = 0; i < SND_COUNT; i++) { if (!snd[i].name[0] || snd[i].freq <= 0) snd[i].exists = 0; else { if (stat(GetDataFilePath(snd[i].name), &st) == -1) snd[i].exists = 0; else { snd[i].exists = 1; if ((snd[i].data = Mix_LoadWAV (GetDataFilePath(snd[i].name))) == NULL) snd[i].exists = 0; else snd[i].exists = 1; } if (!snd[i].exists) printf("Error loading sample '%s'\n", GetDataFilePath(snd[i].name)); } } memset(channelPriority, 0, sizeof(channelPriority)); memset(channelPosition, 0, sizeof(channelPosition)); memset(channelTime, 0, sizeof(channelTime)); soundInitialized = 1; spec = (SDL_AudioSpec *) malloc(sizeof(SDL_AudioSpec)); memset(spec, 0, sizeof(SDL_AudioSpec)); /* spec->freq = 22050; spec->format = AUDIO_S16; spec->samples = 512; spec->callback = &SoundCallback; spec->userdata = (void *)31337; //we don't need this spec->channels = 1;*/ tmpspec.samples = 512; tmpspec.callback = &SoundCallback; /* if (SDL_OpenAudio(&tmpspec, NULL) == -1) { */ /* printf("%s\n", SDL_GetError()); */ /* return 0; */ /* } */ /* SDL_PauseAudio(0); */ return 1; }
void Console_Load(struct Game *game) { game->_priv.font_console = NULL; game->_priv.console = NULL; game->_priv.font_console = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"),al_get_display_height(game->display)*0.025,0 ); if (al_get_display_height(game->display)*0.025 >= 16) { game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/PerfectDOSVGA437.ttf"),16,0 ); } else { game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"), al_get_display_height(game->display)*0.025,0 ); } game->_priv.console = al_create_bitmap((al_get_display_width(game->display) / 320) * 320, al_get_font_line_height(game->_priv.font_console)*5); game->_priv.font = al_load_ttf_font(GetDataFilePath(game, "fonts/MonkeyIsland.ttf"), 0 ,0 ); al_set_target_bitmap(game->_priv.console); al_clear_to_color(al_map_rgba(0,0,0,80)); al_set_target_bitmap(al_get_backbuffer(game->display)); }
void AmmoInitialize(AmmoClasses *ammo, const char *path) { memset(ammo, 0, sizeof *ammo); CArrayInit(&ammo->Ammo, sizeof(Ammo)); CArrayInit(&ammo->CustomAmmo, sizeof(Ammo)); json_t *root = NULL; enum json_error e; char buf[CDOGS_PATH_MAX]; GetDataFilePath(buf, path); FILE *f = fopen(buf, "r"); if (f == NULL) { LOG(LM_MAIN, LL_ERROR, "Error: cannot load ammo file %s", buf); goto bail; } e = json_stream_parse(f, &root); if (e != JSON_OK) { LOG(LM_MAIN, LL_ERROR, "Error parsing ammo file %s [error %d]", buf, (int)e); goto bail; } AmmoLoadJSON(&ammo->Ammo, root); bail: if (f) { fclose(f); } json_free_value(&root); }
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) { struct dosowiskoResources *data = malloc(sizeof(struct dosowiskoResources)); data->bitmap = al_load_bitmap( GetDataFilePath(game, "bg.png")); data->font = al_load_font(GetDataFilePath(game, "fonts/MonkeyIsland.ttf"),100, ALLEGRO_TTF_MONOCHROME ); (*progress)(game); data->sample = al_load_sample( GetDataFilePath(game, "end.flac") ); data->sound = al_create_sample_instance(data->sample); al_attach_sample_instance_to_mixer(data->sound, game->audio.fx); al_set_sample_instance_playmode(data->sound, ALLEGRO_PLAYMODE_ONCE); al_set_sample_instance_gain(data->sound, 1.5); return data; }
void OBSAbout::ShowLicense() { std::string path; QString error = "Error! File could not be read.\n\n \ Go to: https://github.com/obsproject/obs-studio/blob/master/COPYING"; if (!GetDataFilePath("license/gplv2.txt", path)) { ui->textBrowser->setPlainText(error); return; } BPtr<char> text = os_quick_read_utf8_file(path.c_str()); if (!text || !*text) { ui->textBrowser->setPlainText(error); return; } ui->textBrowser->setPlainText(QT_UTF8(text)); ui->info->hide(); ui->contribute->hide(); ui->donate->hide(); ui->getInvolved->hide(); ui->textBrowser->show(); }
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) { struct GamestateResources *data = malloc(sizeof(struct GamestateResources)); data->font = al_load_font(GetDataFilePath(game, "fonts/MonkeyIsland.ttf"),8,0 ); (*progress)(game); return data; }
TEST_F(TConfigParserTest, ForceDebug) { TConfigParser parser(GetDataFilePath("../config-test.json"), true, TSerialDeviceFactory::GetRegisterTypes); PHandlerConfig config = parser.Parse(); ASSERT_TRUE(config->Debug); }
bool CampaignLoad(CampaignOptions *co, CampaignEntry *entry) { CASSERT(!co->IsLoaded, "loading campaign without unloading last one"); // Note: use the mode already set by the menus const GameMode mode = co->Entry.Mode; co->Entry = *entry; co->Entry.Mode = mode; CampaignSettingInit(&co->Setting); if (entry->Mode == GAME_MODE_QUICK_PLAY) { SetupQuickPlayCampaign(&co->Setting); co->IsLoaded = true; } else { // Normalise the path char buf[CDOGS_PATH_MAX]; GetDataFilePath(buf, entry->Path); if (MapNewLoad(buf, &co->Setting)) { LOG(LM_MAIN, LL_ERROR, "failed to load campaign %s!", buf); CASSERT(false, "Failed to load campaign"); } else { co->IsLoaded = true; } } if (co->IsLoaded) { LOG(LM_MAIN, LL_INFO, "loaded campaign/dogfight"); } return co->IsLoaded; }
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) { struct GamestateResources *data = malloc(sizeof(struct GamestateResources)); data->timeline = TM_Init(game, "main"); data->bitmap = al_create_bitmap(game->viewport.width, game->viewport.height); data->checkerboard = al_create_bitmap(game->viewport.width, game->viewport.height); data->pixelator = al_create_bitmap(game->viewport.width, game->viewport.height); al_set_target_bitmap(data->checkerboard); al_lock_bitmap(data->checkerboard, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); int x, y; for (x = 0; x < al_get_bitmap_width(data->checkerboard); x=x+2) { for (y = 0; y < al_get_bitmap_height(data->checkerboard); y=y+2) { al_put_pixel(x, y, al_map_rgba(0,0,0,64)); al_put_pixel(x+1, y, al_map_rgba(0,0,0,0)); al_put_pixel(x, y+1, al_map_rgba(0,0,0,0)); al_put_pixel(x+1, y+1, al_map_rgba(0,0,0,0)); } } al_unlock_bitmap(data->checkerboard); al_set_target_backbuffer(game->display); (*progress)(game); data->font = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"), (int)(game->viewport.height*0.1666 / 8) * 8 ,0 ); (*progress)(game); data->sample = al_load_sample( GetDataFilePath(game, "dosowisko.flac") ); data->sound = al_create_sample_instance(data->sample); al_attach_sample_instance_to_mixer(data->sound, game->audio.music); al_set_sample_instance_playmode(data->sound, ALLEGRO_PLAYMODE_ONCE); (*progress)(game); data->kbd_sample = al_load_sample( GetDataFilePath(game, "kbd.flac") ); data->kbd = al_create_sample_instance(data->kbd_sample); al_attach_sample_instance_to_mixer(data->kbd, game->audio.fx); al_set_sample_instance_playmode(data->kbd, ALLEGRO_PLAYMODE_ONCE); (*progress)(game); data->key_sample = al_load_sample( GetDataFilePath(game, "key.flac") ); data->key = al_create_sample_instance(data->key_sample); al_attach_sample_instance_to_mixer(data->key, game->audio.fx); al_set_sample_instance_playmode(data->key, ALLEGRO_PLAYMODE_ONCE); (*progress)(game); return data; }
void TModbusDeviceTest::SetUp() { TModbusTestBase::SetUp(); TConfigParser parser(GetDataFilePath("../config-test.json"), false, TSerialDeviceFactory::GetRegisterTypes); Config = parser.Parse(); // NOTE: only one port is currently supported Config->PortConfigs[0]->ConnSettings.Device = FakeSerial->GetPrimaryPtsName(); MQTTClient = PFakeMQTTClient(new TFakeMQTTClient("modbus-test", *this)); }
void* Load(struct Game *game) { struct LoadingResources *data = malloc(sizeof(struct LoadingResources)); al_clear_to_color(al_map_rgb(0,0,0)); data->loading_bitmap = al_create_bitmap(game->viewport.width, game->viewport.height); data->bg = al_load_bitmap( GetDataFilePath(game, "bg.png") ); al_set_target_bitmap(data->loading_bitmap); al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(data->bg, 0, 0, 0); al_draw_filled_rectangle(0, game->viewport.height/2 - 1, game->viewport.width, game->viewport.height/2 + 1, al_map_rgba(32,32,32,32)); al_set_target_bitmap(al_get_backbuffer(game->display)); return data; }
void Level1_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, float)) { PROGRESS_INIT(Level1_PreloadSteps()); game->level.level1.owl = LoadScaledBitmap("levels/1/owl.png", game->viewportWidth*0.08, game->viewportWidth*0.08); PROGRESS; game->level.letter_font = al_load_ttf_font(GetDataFilePath("fonts/DejaVuSans.ttf"),game->viewportHeight*0.0225,0 ); PROGRESS; game->level.letter = LoadScaledBitmap("levels/1/letter.png", game->viewportHeight*1.3, game->viewportHeight*1.2); al_set_target_bitmap(game->level.letter); float y = 0.20; float x = 0.19; void draw_text(char* text) { al_draw_text(game->level.letter_font, al_map_rgb(0,0,0), al_get_bitmap_width(game->level.letter)*x, game->viewportHeight*y, ALLEGRO_ALIGN_LEFT, text); y+=0.028; }
void FillPage(struct Game *game, int page) { char filename[30] = { }; sprintf(filename, "intro/%d.flac", page); game->intro.audiostream = al_load_audio_stream(GetDataFilePath(filename), 4, 1024); al_attach_audio_stream_to_mixer(game->intro.audiostream, game->audio.voice); al_set_audio_stream_playing(game->intro.audiostream, false); al_set_audio_stream_gain(game->intro.audiostream, 1.75); al_set_target_bitmap(game->intro.table); float y = 0.2; float oldx = -1; void draw_text(int page, char* text) { float x = 0.45; if (page!=oldx) { y=0.2; oldx=page; } al_draw_text_with_shadow(game->intro.font, al_map_rgb(255,255,255), game->viewportWidth*x, game->viewportHeight*y, ALLEGRO_ALIGN_LEFT, text); y+=0.07; }
bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (state == TM_ACTIONSTATE_INIT) { float* f = (float*)malloc(sizeof(float)); *f = 0; ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)malloc(sizeof(ALLEGRO_AUDIO_STREAM*)); *stream = al_load_audio_stream(GetDataFilePath(GetLevelFilename(game, "levels/?/letter.flac")), 4, 1024); al_attach_audio_stream_to_mixer(*stream, game->audio.voice); al_set_audio_stream_playing(*stream, false); al_set_audio_stream_gain(*stream, 2.00); action->arguments = TM_AddToArgs(action->arguments, (void*)f); action->arguments = TM_AddToArgs(action->arguments, (void*)stream); action->arguments->next->next = NULL; } else if (state == TM_ACTIONSTATE_DESTROY) { ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; al_set_audio_stream_playing(*stream, false); al_destroy_audio_stream(*stream); free(action->arguments->next->value); free(action->arguments->value); TM_DestroyArgs(action->arguments); } else if (state == TM_ACTIONSTATE_DRAW) { float* f = (float*)action->arguments->value; al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0); return false; } else if (state == TM_ACTIONSTATE_PAUSE) { ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; al_set_audio_stream_playing(*stream, false); } else if ((state == TM_ACTIONSTATE_RESUME) || (state == TM_ACTIONSTATE_START)) { ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value; al_set_audio_stream_playing(*stream, true); } if (state != TM_ACTIONSTATE_RUNNING) return false; float* f = (float*)action->arguments->value; *f+=5; if (*f>255) *f=255; al_draw_tinted_bitmap(game->level.letter, al_map_rgba(*f,*f,*f,*f), (game->viewportWidth-al_get_bitmap_width(game->level.letter))/2.0, al_get_bitmap_height(game->level.letter)*-0.05, 0); struct ALLEGRO_KEYBOARD_STATE keyboard; al_get_keyboard_state(&keyboard); // FIXME: do it the proper way if (al_key_down(&keyboard, ALLEGRO_KEY_ENTER)) { return true; } return false; }
void MapObjectsInit( MapObjects *classes, const char *filename, const AmmoClasses *ammo, const GunClasses *guns) { CArrayInit(&classes->Classes, sizeof(MapObject)); CArrayInit(&classes->CustomClasses, sizeof(MapObject)); CArrayInit(&classes->Destructibles, sizeof(char *)); CArrayInit(&classes->Bloods, sizeof(char *)); char buf[CDOGS_PATH_MAX]; GetDataFilePath(buf, filename); FILE *f = fopen(buf, "r"); json_t *root = NULL; if (f == NULL) { LOG(LM_MAIN, LL_ERROR, "Error: cannot load map objects file %s", buf); goto bail; } enum json_error e = json_stream_parse(f, &root); if (e != JSON_OK) { LOG(LM_MAIN, LL_ERROR, "Error parsing map objects file %s", buf); goto bail; } MapObjectsLoadJSON(&classes->Classes, root); // Load initial ammo/weapon spawners MapObjectsLoadAmmoAndGunSpawners(classes, ammo, guns, false); bail: if (f != NULL) { fclose(f); } json_free_value(&root); }
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) { struct MenuResources *data = malloc(sizeof(struct MenuResources)); data->options.fullscreen = game->config.fullscreen; data->options.fps = game->config.fps; data->options.width = game->config.width; data->options.height = game->config.height; data->options.resolution = game->config.width / 320; if (game->config.height / 180 < data->options.resolution) data->options.resolution = game->config.height / 180; (*progress)(game); data->bg = al_load_bitmap( GetDataFilePath(game, "bg.png") ); data->monster = al_load_bitmap( GetDataFilePath(game, "monster.png") ); data->title = al_load_bitmap( GetDataFilePath(game, "title.png") ); (*progress)(game); data->sample = al_load_sample( GetDataFilePath(game, "monster.flac") ); data->click_sample = al_load_sample( GetDataFilePath(game, "click.flac") ); (*progress)(game); data->music = al_create_sample_instance(data->sample); al_attach_sample_instance_to_mixer(data->music, game->audio.music); al_set_sample_instance_playmode(data->music, ALLEGRO_PLAYMODE_LOOP); data->click = al_create_sample_instance(data->click_sample); al_attach_sample_instance_to_mixer(data->click, game->audio.fx); al_set_sample_instance_playmode(data->click, ALLEGRO_PLAYMODE_ONCE); if (!data->click_sample){ fprintf(stderr, "Audio clip sample not loaded!\n" ); exit(-1); } (*progress)(game); data->font = al_load_ttf_font(GetDataFilePath(game, "fonts/MonkeyIsland.ttf"),game->viewport.height*0.05,0 ); al_set_target_backbuffer(game->display); return data; }
void* Gamestate_Load(struct Game *game, void (*progress)(struct Game*)) { struct RocketsResources *data = malloc(sizeof(struct RocketsResources)); data->timeline = TM_Init(game, "riots"); data->bg = al_load_bitmap( GetDataFilePath(game, "riots/bg.png")); data->earth = al_load_bitmap( GetDataFilePath(game, "riots/separator.png")); data->clouds = al_load_bitmap( GetDataFilePath(game, "riots/fog.png")); (*progress)(game); data->rocket_sample = al_load_sample( GetDataFilePath(game, "bump.flac") ); (*progress)(game); data->boom_sample = al_load_sample( GetDataFilePath(game, "boom.flac") ); (*progress)(game); data->jump_sample = al_load_sample( GetDataFilePath(game, "launch.flac") ); (*progress)(game); data->rainbow_sample = al_load_sample( GetDataFilePath(game, "win.flac") ); (*progress)(game); data->wuwu_sample = al_load_sample( GetDataFilePath(game, "riots/vuvu.flac") ); (*progress)(game); data->riot_sample = al_load_sample( GetDataFilePath(game, "riots/riot.flac") ); (*progress)(game); data->rocket_sound = al_create_sample_instance(data->rocket_sample); al_attach_sample_instance_to_mixer(data->rocket_sound, game->audio.fx); al_set_sample_instance_playmode(data->rocket_sound, ALLEGRO_PLAYMODE_ONCE); data->boom_sound = al_create_sample_instance(data->boom_sample); al_attach_sample_instance_to_mixer(data->boom_sound, game->audio.fx); al_set_sample_instance_playmode(data->boom_sound, ALLEGRO_PLAYMODE_ONCE); data->rainbow_sound = al_create_sample_instance(data->rainbow_sample); al_attach_sample_instance_to_mixer(data->rainbow_sound, game->audio.fx); al_set_sample_instance_playmode(data->rainbow_sound, ALLEGRO_PLAYMODE_ONCE); data->jump_sound = al_create_sample_instance(data->jump_sample); al_attach_sample_instance_to_mixer(data->jump_sound, game->audio.fx); al_set_sample_instance_playmode(data->jump_sound, ALLEGRO_PLAYMODE_ONCE); data->riot_sound = al_create_sample_instance(data->riot_sample); al_attach_sample_instance_to_mixer(data->riot_sound, game->audio.fx); al_set_sample_instance_playmode(data->riot_sound, ALLEGRO_PLAYMODE_ONCE); data->wuwu_sound = al_create_sample_instance(data->wuwu_sample); al_attach_sample_instance_to_mixer(data->wuwu_sound, game->audio.fx); al_set_sample_instance_playmode(data->wuwu_sound, ALLEGRO_PLAYMODE_ONCE); data->cursor = CreateCharacter(game, "cursor"); RegisterSpritesheet(game, data->cursor, "hand"); LoadSpritesheets(game, data->cursor); (*progress)(game); data->pixelator = al_create_bitmap(320, 180); al_set_target_bitmap(data->pixelator); al_clear_to_color(al_map_rgb(0, 0, 0)); al_set_target_backbuffer(game->display); data->rocket_template = CreateCharacter(game, "rocket"); RegisterSpritesheet(game, data->rocket_template, "rock"); RegisterSpritesheet(game, data->rocket_template, "bottle"); RegisterSpritesheet(game, data->rocket_template, "bottle2"); RegisterSpritesheet(game, data->rocket_template, "atom"); RegisterSpritesheet(game, data->rocket_template, "boom"); RegisterSpritesheet(game, data->rocket_template, "blank"); LoadSpritesheets(game, data->rocket_template); (*progress)(game); data->usa_flag = CreateCharacter(game, "kibols"); RegisterSpritesheet(game, data->usa_flag, "legia"); RegisterSpritesheet(game, data->usa_flag, "poland"); LoadSpritesheets(game, data->usa_flag); data->ru_flag = CreateCharacter(game, "kibols"); RegisterSpritesheet(game, data->ru_flag, "lech"); RegisterSpritesheet(game, data->ru_flag, "poland"); LoadSpritesheets(game, data->ru_flag); (*progress)(game); data->rainbow = CreateCharacter(game, "rainbow"); RegisterSpritesheet(game, data->rainbow, "shine"); RegisterSpritesheet(game, data->rainbow, "be"); LoadSpritesheets(game, data->rainbow); data->riot = CreateCharacter(game, "riot"); RegisterSpritesheet(game, data->riot, "riot"); LoadSpritesheets(game, data->riot); (*progress)(game); data->euro = CreateCharacter(game, "euro"); RegisterSpritesheet(game, data->euro, "euro"); LoadSpritesheets(game, data->euro); return data; }
/* Initialises the video subsystem. Note: dynamic resolution change is not supported. */ int InitVideo(void) { char title[32]; SDL_Surface *new_screen = NULL; int sdl_flags = 0; int w, h = 0; int rw, rh; sdl_flags |= SDL_HWPALETTE; sdl_flags |= SDL_SWSURFACE; if (Hint(HINT_FULLSCREEN)) sdl_flags |= SDL_FULLSCREEN; if (screen == NULL) { rw = w = Hint(HINT_WIDTH); rh = h = Hint(HINT_HEIGHT); } else { /* We do this because the game dies horribly if you try to dynamically change the _virtual_ resolution */ rw = w = screen_w; rh = h = screen_h; } if (Hint(HINT_SCALEFACTOR) > 1) { rw *= Hint(HINT_SCALEFACTOR); rh *= Hint(HINT_SCALEFACTOR); } if (!Hint(HINT_FORCEMODE)) { if (!ValidMode(w, h)) { printf("!!! Invalid Video Mode %dx%d\n", w, h); return -1; } } else { printf("\n"); printf(" BIG FAT WARNING: If this blows up in your face,\n"); printf(" and mutilates your cat, please don't cry.\n"); printf("\n"); } printf("Window dimensions:\t%dx%d\n", rw, rh); new_screen = SDL_SetVideoMode(rw, rh, 8, sdl_flags); if (new_screen == NULL) { printf("ERROR: InitVideo: %s\n", SDL_GetError() ); return -1; } if (screen == NULL) { /* only do this the first time */ debug(D_NORMAL, "setting caption and icon...\n"); sprintf(title, "C-Dogs %s [Port %s]", CDOGS_VERSION, CDOGS_SDL_VERSION); SDL_WM_SetCaption(title, NULL); SDL_WM_SetIcon(SDL_LoadBMP(GetDataFilePath("cdogs_icon.bmp")), NULL); SDL_ShowCursor(SDL_DISABLE); } else { debug(D_NORMAL, "Changed video mode...\n"); } if (screen == NULL) { screen_w = Hint(HINT_WIDTH); screen_h = Hint(HINT_HEIGHT); } screen = new_screen; SetClip(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1); debug(D_NORMAL, "Internal dimensions:\t%dx%d\n", SCREEN_WIDTH, SCREEN_HEIGHT); SetPalette(gPalette); return 0; }
void GraphicsInitialize(GraphicsDevice *g) { if (g->IsInitialized && !g->cachedConfig.RestartFlags) { return; } if (!g->IsWindowInitialized) { char buf[CDOGS_PATH_MAX]; GetDataFilePath(buf, "cdogs_icon.bmp"); g->icon = IMG_Load(buf); AddSupportedGraphicsModes(g); g->IsWindowInitialized = true; } g->IsInitialized = false; const int w = g->cachedConfig.Res.x; const int h = g->cachedConfig.Res.y; const bool initRenderer = !!(g->cachedConfig.RestartFlags & RESTART_RESOLUTION); const bool initTextures = !!(g->cachedConfig.RestartFlags & (RESTART_RESOLUTION | RESTART_SCALE_MODE)); const bool initBrightness = !!(g->cachedConfig.RestartFlags & (RESTART_RESOLUTION | RESTART_SCALE_MODE | RESTART_BRIGHTNESS)); if (initRenderer) { Uint32 sdlFlags = SDL_WINDOW_RESIZABLE; if (g->cachedConfig.Fullscreen) { sdlFlags |= SDL_WINDOW_FULLSCREEN; } LOG(LM_GFX, LL_INFO, "graphics mode(%dx%d %dx)", w, h, g->cachedConfig.ScaleFactor); // Get the previous window's size and recreate it Vec2i windowSize = Vec2iNew( w * g->cachedConfig.ScaleFactor, h * g->cachedConfig.ScaleFactor); if (g->window) { SDL_GetWindowSize(g->window, &windowSize.x, &windowSize.y); } LOG(LM_GFX, LL_DEBUG, "destroying previous renderer"); SDL_DestroyTexture(g->screen); SDL_DestroyTexture(g->bkg); SDL_DestroyTexture(g->brightnessOverlay); SDL_DestroyRenderer(g->renderer); SDL_FreeFormat(g->Format); SDL_DestroyWindow(g->window); LOG(LM_GFX, LL_DEBUG, "creating window %dx%d flags(%X)", windowSize.x, windowSize.y, sdlFlags); if (SDL_CreateWindowAndRenderer( windowSize.x, windowSize.y, sdlFlags, &g->window, &g->renderer) == -1 || g->window == NULL || g->renderer == NULL) { LOG(LM_GFX, LL_ERROR, "cannot create window or renderer: %s", SDL_GetError()); return; } char title[32]; sprintf(title, "C-Dogs SDL %s%s", g->cachedConfig.IsEditor ? "Editor " : "", CDOGS_SDL_VERSION); LOG(LM_GFX, LL_DEBUG, "setting title(%s) and icon", title); SDL_SetWindowTitle(g->window, title); SDL_SetWindowIcon(g->window, g->icon); g->Format = SDL_AllocFormat(SDL_PIXELFORMAT_ARGB8888); if (SDL_RenderSetLogicalSize(g->renderer, w, h) != 0) { LOG(LM_GFX, LL_ERROR, "cannot set renderer logical size: %s", SDL_GetError()); return; } GraphicsSetBlitClip( g, 0, 0, g->cachedConfig.Res.x - 1, g->cachedConfig.Res.y - 1); } if (initTextures) { if (!initRenderer) { SDL_DestroyTexture(g->screen); SDL_DestroyTexture(g->bkg); SDL_DestroyTexture(g->brightnessOverlay); } // Set render scale mode const char *renderScaleQuality = "nearest"; switch ((ScaleMode)ConfigGetEnum(&gConfig, "Graphics.ScaleMode")) { case SCALE_MODE_NN: renderScaleQuality = "nearest"; break; case SCALE_MODE_BILINEAR: renderScaleQuality = "linear"; break; default: CASSERT(false, "unknown scale mode"); break; } LOG(LM_GFX, LL_DEBUG, "setting scale quality %s", renderScaleQuality); if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, renderScaleQuality)) { LOG(LM_GFX, LL_WARN, "cannot set render quality hint: %s", SDL_GetError()); } g->screen = CreateTexture( g->renderer, SDL_TEXTUREACCESS_STREAMING, Vec2iNew(w, h), SDL_BLENDMODE_BLEND, 255); if (g->screen == NULL) { return; } CFREE(g->buf); CCALLOC(g->buf, GraphicsGetMemSize(&g->cachedConfig)); g->bkg = CreateTexture( g->renderer, SDL_TEXTUREACCESS_STATIC, Vec2iNew(w, h), SDL_BLENDMODE_NONE, 255); if (g->bkg == NULL) { return; } } if (initBrightness) { if (!initRenderer && !initTextures) { SDL_DestroyTexture(g->brightnessOverlay); } const int brightness = ConfigGetInt(&gConfig, "Graphics.Brightness"); // Alpha is approximately 50% max const Uint8 alpha = (Uint8)(brightness > 0 ? brightness : -brightness) * 13; g->brightnessOverlay = CreateTexture( g->renderer, SDL_TEXTUREACCESS_STATIC, Vec2iNew(w, h), SDL_BLENDMODE_BLEND, alpha); if (g->brightnessOverlay == NULL) { return; } const color_t overlayColour = brightness > 0 ? colorWhite : colorBlack; DrawRectangle(g, Vec2iZero(), g->cachedConfig.Res, overlayColour, 0); SDL_UpdateTexture( g->brightnessOverlay, NULL, g->buf, g->cachedConfig.Res.x * sizeof(Uint32)); memset(g->buf, 0, GraphicsGetMemSize(&g->cachedConfig)); g->cachedConfig.Brightness = brightness; } g->IsInitialized = true; g->cachedConfig.Res.x = w; g->cachedConfig.Res.y = h; g->cachedConfig.RestartFlags = 0; }
// Initialises the video subsystem. // To prevent needless screen flickering, config is compared with cache // to see if anything changed. If not, don't recreate the screen. void GraphicsInitialize(GraphicsDevice *g, const bool force) { #ifdef __GCWZERO__ int sdl_flags = SDL_HWSURFACE | SDL_TRIPLEBUF; #else int sdl_flags = SDL_SWSURFACE; #endif unsigned int w, h = 0; unsigned int rw, rh; if (g->IsInitialized && !g->cachedConfig.needRestart) { return; } if (!g->IsWindowInitialized) { /* only do this the first time */ char title[32]; debug(D_NORMAL, "setting caption and icon...\n"); sprintf(title, "C-Dogs SDL %s%s", g->cachedConfig.IsEditor ? "Editor " : "", CDOGS_SDL_VERSION); SDL_WM_SetCaption(title, NULL); char buf[CDOGS_PATH_MAX]; GetDataFilePath(buf, "cdogs_icon.bmp"); g->icon = SDL_LoadBMP(buf); SDL_WM_SetIcon(g->icon, NULL); AddSupportedGraphicsModes(g); } g->IsInitialized = false; sdl_flags |= g->cachedConfig.IsEditor ? SDL_RESIZABLE : 0; if (g->cachedConfig.Fullscreen) { sdl_flags |= SDL_FULLSCREEN; } rw = w = g->cachedConfig.Res.x; rh = h = g->cachedConfig.Res.y; if (g->cachedConfig.ScaleFactor > 1) { rw *= g->cachedConfig.ScaleFactor; rh *= g->cachedConfig.ScaleFactor; } if (!force && !g->cachedConfig.IsEditor) { g->modeIndex = FindValidMode(g, w, h, g->cachedConfig.ScaleFactor); if (g->modeIndex == -1) { g->modeIndex = 0; printf("!!! Invalid Video Mode %dx%d\n", w, h); return; } } printf("Graphics mode:\t%dx%d %dx (actual %dx%d)\n", w, h, g->cachedConfig.ScaleFactor, rw, rh); SDL_FreeSurface(g->screen); g->screen = SDL_SetVideoMode(rw, rh, 32, sdl_flags); if (g->screen == NULL) { printf("ERROR: InitVideo: %s\n", SDL_GetError()); return; } SDL_PixelFormat *f = g->screen->format; g->Amask = -1 & ~(f->Rmask | f->Gmask | f->Bmask); Uint32 aMask = g->Amask; g->Ashift = 0; while (aMask != 0xff) { g->Ashift += 8; aMask >>= 8; } CFREE(g->buf); CCALLOC(g->buf, GraphicsGetMemSize(&g->cachedConfig)); CFREE(g->bkg); CCALLOC(g->bkg, GraphicsGetMemSize(&g->cachedConfig)); debug(D_NORMAL, "Changed video mode...\n"); GraphicsSetBlitClip( g, 0, 0, g->cachedConfig.Res.x - 1, g->cachedConfig.Res.y - 1); debug(D_NORMAL, "Internal dimensions:\t%dx%d\n", g->cachedConfig.Res.x, g->cachedConfig.Res.y); g->IsInitialized = true; g->IsWindowInitialized = true; g->cachedConfig.Res.x = w; g->cachedConfig.Res.y = h; g->cachedConfig.needRestart = false; }
int main(int argc, char *argv[]) { int i; int loaded = 0; printf("C-Dogs SDL Editor\n"); debug(D_NORMAL, "Initialising SDL...\n"); if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO) != 0) { printf("Failed to start SDL!\n"); return -1; } SDL_EnableUNICODE(SDL_ENABLE); printf("Data directory:\t\t%s\n", GetDataFilePath("")); printf("Config directory:\t%s\n\n", GetConfigFilePath("")); EditorBrushInit(&brush); ConfigLoadDefault(&gConfig); ConfigLoad(&gConfig, GetConfigFilePath(CONFIG_FILE)); gConfig.Graphics.IsEditor = 1; if (!PicManagerTryInit( &gPicManager, "graphics/cdogs.px", "graphics/cdogs2.px")) { exit(0); } memcpy(origPalette, gPicManager.palette, sizeof origPalette); BuildTranslationTables(gPicManager.palette); TextManagerInit(&gTextManager, GetDataFilePath("graphics/font.px")); GraphicsInit(&gGraphicsDevice); // Hardcode config settings gConfig.Graphics.ScaleMode = SCALE_MODE_NN; gConfig.Graphics.ScaleFactor = 2; gConfig.Graphics.Res.x = 400; gConfig.Graphics.Res.y = 300; GraphicsInitialize( &gGraphicsDevice, &gConfig.Graphics, gPicManager.palette, 0); if (!gGraphicsDevice.IsInitialized) { printf("Video didn't init!\n"); exit(EXIT_FAILURE); } TextManagerGenerateOldPics(&gTextManager, &gGraphicsDevice); PicManagerLoadDir(&gPicManager, GetDataFilePath("graphics")); BulletInitialize(); WeaponInitialize(&gGunDescriptions, GetDataFilePath("guns.json")); CampaignInit(&gCampaign); MissionInit(&lastMission); MissionInit(¤tMission); PlayerDataInitialize(); MapInit(&gMap); // initialise UI collections // Note: must do this after text init since positions depend on text height sObjs = CreateMainObjs(&gCampaign, &brush, Vec2iNew(320, 240)); memset(&sDrawObjs, 0, sizeof sDrawObjs); DrawBufferInit(&sDrawBuffer, Vec2iNew(X_TILES, Y_TILES), &gGraphicsDevice); // Reset campaign (graphics init may have created dummy campaigns) CampaignSettingTerminate(&gCampaign.Setting); CampaignSettingInit(&gCampaign.Setting); EventInit(&gEventHandlers, NULL, false); for (i = 1; i < argc; i++) { if (!loaded) { debug(D_NORMAL, "Loading map %s\n", argv[i]); memset(lastFile, 0, sizeof(lastFile)); strncpy(lastFile, argv[i], sizeof(lastFile) - 1); if (strchr(lastFile, '.') == NULL && sizeof lastFile - strlen(lastFile) > 3) { strcat(lastFile, ".CPN"); } if (MapNewLoad(lastFile, &gCampaign.Setting) == 0) { loaded = 1; } debug(D_NORMAL, "Loaded map %s\n", argv[i]); } } debug(D_NORMAL, "Starting editor\n"); EditCampaign(); MapTerminate(&gMap); WeaponTerminate(&gGunDescriptions); CampaignTerminate(&gCampaign); MissionTerminate(&lastMission); MissionTerminate(¤tMission); DrawBufferTerminate(&sDrawBuffer); GraphicsTerminate(&gGraphicsDevice); PicManagerTerminate(&gPicManager); TextManagerTerminate(&gTextManager); UIObjectDestroy(sObjs); CArrayTerminate(&sDrawObjs); EditorBrushTerminate(&brush); SDL_Quit(); exit(EXIT_SUCCESS); }
void Menu_Preload(struct Game *game, void (*progress)(struct Game*, float)) { PROGRESS_INIT(16); game->menu.options.fullscreen = game->fullscreen; game->menu.options.fps = game->fps; game->menu.options.width = game->width; game->menu.options.height = game->height; game->menu.loaded = true; game->menu.image = LoadScaledBitmap( "menu/menu.png", game->viewportWidth, game->viewportWidth*(1240.0/3910.0)); PROGRESS; game->menu.mountain = LoadScaledBitmap( "menu/mountain.png", game->viewportHeight*1.6*0.055, game->viewportHeight/9 ); PROGRESS; game->menu.cloud = LoadScaledBitmap( "menu/cloud.png", game->viewportHeight*1.6*0.5, game->viewportHeight*0.25 ); PROGRESS; game->menu.cloud2 = LoadScaledBitmap( "menu/cloud2.png", game->viewportHeight*1.6*0.2, game->viewportHeight*0.1 ); PROGRESS; game->menu.logo = LoadScaledBitmap( "menu/logo.png", game->viewportHeight*1.6*0.3, game->viewportHeight*0.35 ); game->menu.blurbg = al_create_bitmap(game->viewportHeight*1.6*0.3, game->viewportHeight*0.35); game->menu.blurbg2 = al_create_bitmap(game->viewportHeight*1.6*0.3, game->viewportHeight*0.35); PROGRESS; game->menu.logoblur = al_create_bitmap(game->viewportHeight*1.6*0.3+4, game->viewportHeight*0.35+4); al_set_target_bitmap(game->menu.logoblur); al_clear_to_color(al_map_rgba(0,0,0,0)); float alpha = (1.0/40.0); ALLEGRO_COLOR color = al_map_rgba_f(alpha, alpha, alpha, alpha); int by, bx; for (by = -2; by <= 2; by++) { for (bx = -2; bx <= 2; bx++) { if (sqrt(bx*bx+by*by) <= 2) al_draw_tinted_bitmap(game->menu.logo, color, bx, by, 0); } } al_set_target_bitmap(al_get_backbuffer(game->display)); PROGRESS; game->menu.glass = LoadScaledBitmap( "menu/glass.png", game->viewportHeight*1.6*0.3, game->viewportHeight*0.35 ); PROGRESS; //game->menu.pinkcloud = LoadScaledBitmap( "menu/pinkcloud.png", game->viewportWidth*0.33125, game->viewportHeight*0.8122); game->menu.pinkcloud = LoadScaledBitmap( "menu/pinkcloud.png", game->viewportHeight*0.8122*(1171.0/2218.0), game->viewportHeight*0.8122); PROGRESS; al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); game->menu.rain = al_load_bitmap( GetDataFilePath("menu/rain.png") ); PROGRESS; game->menu.pie = al_load_bitmap( GetDataFilePath("menu/pie.png") ); al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR); PROGRESS; game->menu.sample = al_load_sample( GetDataFilePath("menu/menu.flac") ); PROGRESS; game->menu.rain_sample = al_load_sample( GetDataFilePath("menu/rain.flac") ); PROGRESS; game->menu.click_sample = al_load_sample( GetDataFilePath("menu/click.flac") ); PROGRESS; game->menu.mountain_position = game->viewportWidth*0.7; game->menu.music = al_create_sample_instance(game->menu.sample); al_attach_sample_instance_to_mixer(game->menu.music, game->audio.music); al_set_sample_instance_playmode(game->menu.music, ALLEGRO_PLAYMODE_LOOP); game->menu.rain_sound = al_create_sample_instance(game->menu.rain_sample); al_attach_sample_instance_to_mixer(game->menu.rain_sound, game->audio.fx); al_set_sample_instance_playmode(game->menu.rain_sound, ALLEGRO_PLAYMODE_LOOP); game->menu.click = al_create_sample_instance(game->menu.click_sample); al_attach_sample_instance_to_mixer(game->menu.click, game->audio.fx); al_set_sample_instance_playmode(game->menu.click, ALLEGRO_PLAYMODE_ONCE); game->menu.font_title = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.16,0 ); game->menu.font_subtitle = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.08,0 ); game->menu.font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.05,0 ); game->menu.font_selected = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.065,0 ); PROGRESS; if (!game->menu.sample){ fprintf(stderr, "Audio clip sample not loaded!\n" ); exit(-1); } if (!game->menu.rain_sample){ fprintf(stderr, "Audio clip sample#2 not loaded!\n" ); exit(-1); } if (!game->menu.click_sample){ fprintf(stderr, "Audio clip sample#3 not loaded!\n" ); exit(-1); } game->menu.pinkcloud_bitmap = al_create_bitmap(game->viewportHeight*0.8122*(1171.0/2218.0), game->viewportHeight); game->menu.pie_bitmap = al_create_bitmap(game->viewportHeight*0.8, game->viewportHeight); al_set_target_bitmap(game->menu.pie_bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); al_draw_scaled_bitmap(game->menu.pie, 0, 0, al_get_bitmap_width(game->menu.pie), al_get_bitmap_height(game->menu.pie), al_get_bitmap_width(game->menu.pie_bitmap)*0.5, 0, game->viewportHeight*1.6*0.11875, game->viewportHeight*0.0825, 0); al_draw_scaled_bitmap(game->menu.pie, 0, 0, al_get_bitmap_width(game->menu.pie), al_get_bitmap_height(game->menu.pie), al_get_bitmap_width(game->menu.pie_bitmap)*0.1, al_get_bitmap_height(game->menu.pie_bitmap)*0.3, game->viewportHeight*1.6*0.09, game->viewportHeight*0.06, ALLEGRO_FLIP_HORIZONTAL); al_draw_scaled_bitmap(game->menu.pie, 0, 0, al_get_bitmap_width(game->menu.pie), al_get_bitmap_height(game->menu.pie), al_get_bitmap_width(game->menu.pie_bitmap)*0.3, al_get_bitmap_height(game->menu.pie_bitmap)*0.6, game->viewportHeight*1.6*0.13, game->viewportHeight*0.1, 0); al_destroy_bitmap(game->menu.pie); PROGRESS; al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); game->menu.rain_bitmap = al_create_bitmap(al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.5, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.1); al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR); al_set_target_bitmap(game->menu.rain_bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); al_draw_scaled_bitmap(game->menu.rain,0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), 0, 0, al_get_bitmap_width(game->menu.rain_bitmap), al_get_bitmap_height(game->menu.rain_bitmap),0); al_destroy_bitmap(game->menu.rain); PROGRESS; }
int main(int argc, char *argv[]) { int wait = 0; int controllerFlag = SDL_INIT_GAMECONTROLLER; credits_displayer_t creditsDisplayer; memset(&creditsDisplayer, 0, sizeof creditsDisplayer); custom_campaigns_t campaigns; memset(&campaigns, 0, sizeof campaigns); int forceResolution = 0; int err = 0; const char *loadCampaign = NULL; ENetAddress connectAddr; memset(&connectAddr, 0, sizeof connectAddr); srand((unsigned int)time(NULL)); LogInit(); PrintTitle(); if (getenv("DEBUG") != NULL) { debug = true; char *dbg; if ((dbg = getenv("DEBUG_LEVEL")) != NULL) { debug_level = CLAMP(atoi(dbg), D_NORMAL, D_MAX); } } SetupConfigDir(); gConfig = ConfigLoad(GetConfigFilePath(CONFIG_FILE)); LoadCredits(&creditsDisplayer, colorPurple, colorDarker); AutosaveInit(&gAutosave); AutosaveLoad(&gAutosave, GetConfigFilePath(AUTOSAVE_FILE)); if (enet_initialize() != 0) { LOG(LM_MAIN, LL_ERROR, "An error occurred while initializing ENet."); err = EXIT_FAILURE; goto bail; } NetClientInit(&gNetClient); // Print command line char buf[CDOGS_PATH_MAX]; buf[0] = '\0'; for (int i = 0; i < argc; i++) { strcat(buf, " "); // HACK: for OS X, blank out the -psn_XXXX argument so that it doesn't // break arg parsing #ifdef __APPLE__ if (strncmp(argv[i], "-psn", strlen("-psn")) == 0) { argv[i] = ""; } #endif strcat(buf, argv[i]); } LOG(LM_MAIN, LL_INFO, "Command line (%d args):%s", argc, buf); { struct option longopts[] = { {"fullscreen", no_argument, NULL, 'f'}, {"scale", required_argument, NULL, 's'}, {"screen", required_argument, NULL, 'c'}, {"forcemode", no_argument, NULL, 'o'}, {"nosound", no_argument, NULL, 'n'}, {"nojoystick", no_argument, NULL, 'j'}, {"wait", no_argument, NULL, 'w'}, {"shakemult", required_argument, NULL, 'm'}, {"connect", required_argument, NULL, 'x'}, {"debug", required_argument, NULL, 'd'}, {"log", required_argument, NULL, 1000}, {"help", no_argument, NULL, 'h'}, {0, 0, NULL, 0} }; int opt = 0; int idx = 0; while ((opt = getopt_long(argc, argv, "fs:c:onjwm:xd\0h", longopts, &idx)) != -1) { switch (opt) { case 'f': ConfigGet(&gConfig, "Graphics.Fullscreen")->u.Bool.Value = true; break; case 's': ConfigSetInt(&gConfig, "Graphics.ScaleFactor", atoi(optarg)); break; case 'c': sscanf(optarg, "%dx%d", &ConfigGet(&gConfig, "Graphics.ResolutionWidth")->u.Int.Value, &ConfigGet(&gConfig, "Graphics.ResolutionHeight")->u.Int.Value); LOG(LM_MAIN, LL_DEBUG, "Video mode %dx%d set...", ConfigGetInt(&gConfig, "Graphics.ResolutionWidth"), ConfigGetInt(&gConfig, "Graphics.ResolutionHeight")); break; case 'o': forceResolution = 1; break; case 'n': LOG(LM_MAIN, LL_INFO, "Sound to 0 volume"); ConfigGet(&gConfig, "Sound.SoundVolume")->u.Int.Value = 0; ConfigGet(&gConfig, "Sound.MusicVolume")->u.Int.Value = 0; break; case 'j': debug(D_NORMAL, "nojoystick\n"); controllerFlag = 0; break; case 'w': wait = 1; break; case 'm': { ConfigGet(&gConfig, "Graphics.ShakeMultiplier")->u.Int.Value = MAX(atoi(optarg), 0); printf("Shake multiplier: %d\n", ConfigGetInt(&gConfig, "Graphics.ShakeMultiplier")); } break; case 'h': PrintHelp(); goto bail; case 'd': // Set debug level debug = true; debug_level = CLAMP(atoi(optarg), D_NORMAL, D_MAX); break; case 1000: { char *comma = strchr(optarg, ','); if (comma) { // Set logging level for a single module // The module and level are comma separated *comma = '\0'; const LogLevel ll = StrLogLevel(comma + 1); LogModuleSetLevel(StrLogModule(optarg), ll); printf("Logging %s at %s\n", optarg, LogLevelName(ll)); } else { // Set logging level for all modules const LogLevel ll = StrLogLevel(optarg); for (int i = 0; i < (int)LM_COUNT; i++) { LogModuleSetLevel((LogModule)i, ll); } printf("Logging everything at %s\n", LogLevelName(ll)); } } break; case 'x': if (enet_address_set_host(&connectAddr, optarg) != 0) { printf("Error: unknown host %s\n", optarg); } break; default: PrintHelp(); // Ignore unknown arguments break; } } if (optind < argc) { // non-option ARGV-elements for (; optind < argc; optind++) { // Load campaign loadCampaign = argv[optind]; } } } debug(D_NORMAL, "Initialising SDL...\n"); const int sdlFlags = SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_HAPTIC; if (SDL_Init(sdlFlags | controllerFlag) != 0) { LOG(LM_MAIN, LL_ERROR, "Could not initialise SDL: %s", SDL_GetError()); err = EXIT_FAILURE; goto bail; } if (SDLJBN_Init() != 0) { LOG(LM_MAIN, LL_ERROR, "Could not initialise SDLJBN: %s", SDLJBN_GetError()); err = EXIT_FAILURE; goto bail; } SDL_EventState(SDL_DROPFILE, SDL_DISABLE); GetDataFilePath(buf, ""); LOG(LM_MAIN, LL_INFO, "data dir(%s)", buf); LOG(LM_MAIN, LL_INFO, "config dir(%s)", GetConfigFilePath("")); SoundInitialize(&gSoundDevice, "sounds"); if (!gSoundDevice.isInitialised) { LOG(LM_MAIN, LL_ERROR, "Sound initialization failed!"); } LoadHighScores(); debug(D_NORMAL, "Loading song lists...\n"); LoadSongs(); MusicPlayMenu(&gSoundDevice); EventInit(&gEventHandlers, NULL, NULL, true); NetServerInit(&gNetServer); if (wait) { printf("Press the enter key to continue...\n"); getchar(); } if (!PicManagerTryInit( &gPicManager, "graphics/cdogs.px", "graphics/cdogs2.px")) { LOG(LM_MAIN, LL_ERROR, "Failed to initialize graphics"); err = EXIT_FAILURE; goto bail; } memcpy(origPalette, gPicManager.palette, sizeof(origPalette)); GraphicsInit(&gGraphicsDevice, &gConfig); GraphicsInitialize(&gGraphicsDevice, forceResolution); if (!gGraphicsDevice.IsInitialized) { LOG(LM_MAIN, LL_WARN, "Cannot initialise video; trying default config"); ConfigResetDefault(ConfigGet(&gConfig, "Graphics")); GraphicsInit(&gGraphicsDevice, &gConfig); GraphicsInitialize(&gGraphicsDevice, forceResolution); } if (!gGraphicsDevice.IsInitialized) { LOG(LM_MAIN, LL_ERROR, "Video didn't init!"); err = EXIT_FAILURE; goto bail; } FontLoadFromJSON(&gFont, "graphics/font.png", "graphics/font.json"); PicManagerLoadDir(&gPicManager, "graphics"); ParticleClassesInit(&gParticleClasses, "data/particles.json"); AmmoInitialize(&gAmmo, "data/ammo.json"); BulletAndWeaponInitialize( &gBulletClasses, &gGunDescriptions, "data/bullets.json", "data/guns.json"); CharacterClassesInitialize(&gCharacterClasses, "data/character_classes.json"); LoadPlayerTemplates( &gPlayerTemplates, &gCharacterClasses, PLAYER_TEMPLATE_FILE); PickupClassesInit( &gPickupClasses, "data/pickups.json", &gAmmo, &gGunDescriptions); MapObjectsInit(&gMapObjects, "data/map_objects.json"); CollisionSystemInit(&gCollisionSystem); CampaignInit(&gCampaign); LoadAllCampaigns(&campaigns); PlayerDataInit(&gPlayerDatas); GrafxMakeRandomBackground( &gGraphicsDevice, &gCampaign, &gMission, &gMap); debug(D_NORMAL, ">> Entering main loop\n"); // Attempt to pre-load campaign if requested if (loadCampaign != NULL) { LOG(LM_MAIN, LL_INFO, "Loading campaign %s...", loadCampaign); gCampaign.Entry.Mode = strstr(loadCampaign, "/" CDOGS_DOGFIGHT_DIR "/") != NULL ? GAME_MODE_DOGFIGHT : GAME_MODE_NORMAL; CampaignEntry entry; if (!CampaignEntryTryLoad(&entry, loadCampaign, GAME_MODE_NORMAL) || !CampaignLoad(&gCampaign, &entry)) { LOG(LM_MAIN, LL_ERROR, "Failed to load campaign %s", loadCampaign); } } else if (connectAddr.host != 0) { if (NetClientTryScanAndConnect(&gNetClient, connectAddr.host)) { ScreenWaitForCampaignDef(); } else { printf("Failed to connect\n"); } } LOG(LM_MAIN, LL_INFO, "Starting game"); MainLoop(&creditsDisplayer, &campaigns); bail: debug(D_NORMAL, ">> Shutting down...\n"); MapTerminate(&gMap); PlayerDataTerminate(&gPlayerDatas); MapObjectsTerminate(&gMapObjects); PickupClassesTerminate(&gPickupClasses); ParticleClassesTerminate(&gParticleClasses); AmmoTerminate(&gAmmo); WeaponTerminate(&gGunDescriptions); BulletTerminate(&gBulletClasses); CharacterClassesTerminate(&gCharacterClasses); MissionOptionsTerminate(&gMission); NetClientTerminate(&gNetClient); atexit(enet_deinitialize); EventTerminate(&gEventHandlers); GraphicsTerminate(&gGraphicsDevice); PicManagerTerminate(&gPicManager); FontTerminate(&gFont); AutosaveSave(&gAutosave, GetConfigFilePath(AUTOSAVE_FILE)); AutosaveTerminate(&gAutosave); ConfigSave(&gConfig, GetConfigFilePath(CONFIG_FILE)); SavePlayerTemplates(&gPlayerTemplates, PLAYER_TEMPLATE_FILE); CArrayTerminate(&gPlayerTemplates); FreeSongs(&gMenuSongs); FreeSongs(&gGameSongs); SaveHighScores(); UnloadCredits(&creditsDisplayer); UnloadAllCampaigns(&campaigns); CampaignTerminate(&gCampaign); SoundTerminate(&gSoundDevice, true); ConfigDestroy(&gConfig); SDLJBN_Quit(); SDL_Quit(); return err; }