game_export_t *GetGameAPI( game_import_t *import ) { gameinfo_import_t gameinfo_import; gi = *import; globals.apiversion = GAME_API_VERSION; globals.Init = InitGame; globals.Shutdown = ShutdownGame; globals.WriteLevel = WriteLevel; globals.ReadLevel = ReadLevel; globals.GameAllowedToSaveHere = GameAllowedToSaveHere; globals.ClientThink = ClientThink; globals.ClientConnect = ClientConnect; globals.ClientUserinfoChanged = ClientUserinfoChanged; globals.ClientDisconnect = ClientDisconnect; globals.ClientBegin = ClientBegin; globals.ClientCommand = ClientCommand; globals.RunFrame = G_RunFrame; globals.ConsoleCommand = ConsoleCommand; globals.PrintEntClassname = PrintEntClassname; globals.ValidateAnimRange = PM_ValidateAnimRange; globals.gentitySize = sizeof(gentity_t); gameinfo_import.FS_FOpenFile = gi.FS_FOpenFile; gameinfo_import.FS_Read = gi.FS_Read; gameinfo_import.FS_FCloseFile = gi.FS_FCloseFile; gameinfo_import.Cvar_Set = gi.cvar_set; gameinfo_import.Cvar_VariableStringBuffer = gi.Cvar_VariableStringBuffer; gameinfo_import.Cvar_Create = G_Cvar_Create; GI_Init( &gameinfo_import ); return &globals; }
int main(int _argc, char **_argv) { run = true; argc = _argc; argv = _argv; #if THREADS InitializeCriticalSectionAndSpinCount(&log_crit, 4000); #endif AW_SetBinDir(); fclose(fopen((bin_dir + "log.txt").c_str(), "w+")); log((str("Binary directory: ") + bin_dir + "\n").c_str()); atexit(exit); TCOD_sys_get_current_resolution(&resx, &resy); #if FULLSCREEN CON_RES_X = floor(resx/CHAR_SIZE); CON_RES_Y = floor(resy/CHAR_SIZE); #else CON_RES_X = 70; CON_RES_Y = 40; #endif TCOD_console_set_custom_font("./data/terminal.png", TCOD_FONT_LAYOUT_ASCII_INROW, 16, 48); TCOD_console_init_root(CON_RES_X, CON_RES_Y, "ASCIIWar", false, TCOD_RENDERER_SDL); con = TCOD_console_new(CON_RES_X, CON_RES_Y); #if FULLSCREEN TCOD_sys_force_fullscreen_resolution(resx, resy); TCOD_console_set_fullscreen(true); #endif TCOD_sys_get_current_resolution(&resx, &resy); TCOD_mouse_show_cursor(true); TCOD_sys_set_fps(1000/NORMAL_TIME_STEP); #if FULLSCREEN int offx, offy; TCOD_sys_get_fullscreen_offsets(&offx, &offy); MINIMAP_START_X = offx+CHAR_SIZE*MINIMAP_CON_START_X; LAGOMETER_START_X = resx-offx-LAGOMETER_SIZE; #endif TCOD_console_set_keyboard_repeat(1, 0); trace("ASCIIWar has started."); trace("Parsing configs..."); TCOD_parser_t game_parser = TCOD_parser_new(); TCOD_parser_new_struct(game_parser, (char*)"game"); TCOD_parser_run(game_parser,"game.cfg", &game_parser_listener); trace("Configs parsing done."); trace("Master server at: " + game_desc.master_server); client_gi.name = "asciiwar"; #if RELEASE TCOD_console_credits(); #endif if(_argc >= 4) { game_desc.game_name = (char*)argv[1]; game_desc.player_count_per_team = atoi((char*)argv[2]); game_desc.team_count = atoi((char*)argv[3]); } else { game_desc.game_name = "bahla"; game_desc.player_count_per_team = 1+1; game_desc.team_count = 1; } // client game instance GI_Init(&client_gi, argc, argv); GI_ConnectToMasterServer(&client_gi); GI_AddState(&client_gi, AW_state_join); while(run && !TCOD_console_is_window_closed()) GI_Update(&client_gi); trace("Deleting game instance..."); GI_Close(&client_gi); trace(str("Execution time: " + f2a(TCOD_sys_elapsed_seconds()/60) + " minutes.")); return 0; }