/* preparing the parser */ void namegen_parser_prepare (void) { static bool namegen_parser_ready = false; if (namegen_parser_ready == true) return; else { TCOD_parser_struct_t parser_name ; namegen_parser = TCOD_parser_new(); parser_name = TCOD_parser_new_struct(namegen_parser, "name"); TCOD_struct_add_property(parser_name, "phonemesVocals", TCOD_TYPE_STRING, false); TCOD_struct_add_property(parser_name, "phonemesConsonants", TCOD_TYPE_STRING, false); TCOD_struct_add_property(parser_name, "syllablesPre", TCOD_TYPE_STRING, false); TCOD_struct_add_property(parser_name, "syllablesStart", TCOD_TYPE_STRING, false); TCOD_struct_add_property(parser_name, "syllablesMiddle", TCOD_TYPE_STRING, false); TCOD_struct_add_property(parser_name, "syllablesEnd", TCOD_TYPE_STRING, false); TCOD_struct_add_property(parser_name, "syllablesPost", TCOD_TYPE_STRING, false); TCOD_struct_add_property(parser_name, "illegal", TCOD_TYPE_STRING, false); TCOD_struct_add_property(parser_name, "rules", TCOD_TYPE_STRING, true); namegen_parser_ready = true; } }
static void TCOD_sys_load_player_config() { const char *renderer; const char *font; int fullscreenWidth,fullscreenHeight; /* define file structure */ TCOD_parser_t parser=TCOD_parser_new(); TCOD_parser_struct_t libtcod = TCOD_parser_new_struct(parser, "libtcod"); TCOD_struct_add_property(libtcod, "renderer", TCOD_TYPE_STRING, false); TCOD_struct_add_property(libtcod, "font", TCOD_TYPE_STRING, false); TCOD_struct_add_property(libtcod, "fontInRow", TCOD_TYPE_BOOL, false); TCOD_struct_add_property(libtcod, "fontGreyscale", TCOD_TYPE_BOOL, false); TCOD_struct_add_property(libtcod, "fontTcodLayout", TCOD_TYPE_BOOL, false); TCOD_struct_add_property(libtcod, "fontNbCharHoriz", TCOD_TYPE_INT, false); TCOD_struct_add_property(libtcod, "fontNbCharVertic", TCOD_TYPE_INT, false); TCOD_struct_add_property(libtcod, "fullscreen", TCOD_TYPE_BOOL, false); TCOD_struct_add_property(libtcod, "fullscreenWidth", TCOD_TYPE_INT, false); TCOD_struct_add_property(libtcod, "fullscreenHeight", TCOD_TYPE_INT, false); /* parse file */ TCOD_parser_run(parser,"./libtcod.cfg",NULL); /* set user preferences */ renderer=TCOD_parser_get_string_property(parser, "libtcod.renderer"); if ( renderer != NULL ) { /* custom renderer */ if ( TCOD_strcasecmp(renderer,"GLSL") == 0 ) TCOD_ctx.renderer=TCOD_RENDERER_GLSL; else if ( TCOD_strcasecmp(renderer,"OPENGL") == 0 ) TCOD_ctx.renderer=TCOD_RENDERER_OPENGL; else if ( TCOD_strcasecmp(renderer,"SDL") == 0 ) TCOD_ctx.renderer=TCOD_RENDERER_SDL; else printf ("Warning : unknown renderer '%s' in libtcod.cfg\n", renderer); } font=TCOD_parser_get_string_property(parser, "libtcod.font"); if ( font != NULL ) { /* custom font */ FILE *f=fopen(font,"rb"); if (f) { int fontNbCharHoriz,fontNbCharVertic; fclose(f); strcpy(TCOD_ctx.font_file,font); TCOD_ctx.font_in_row=TCOD_parser_get_bool_property(parser,"libtcod.fontInRow"); TCOD_ctx.font_greyscale=TCOD_parser_get_bool_property(parser,"libtcod.fontGreyscale"); TCOD_ctx.font_tcod_layout=TCOD_parser_get_bool_property(parser,"libtcod.fontTcodLayout"); fontNbCharHoriz=TCOD_parser_get_int_property(parser,"libtcod.fontNbCharHoriz"); fontNbCharVertic=TCOD_parser_get_int_property(parser,"libtcod.fontNbCharVertic"); if ( fontNbCharHoriz > 0 ) TCOD_ctx.fontNbCharHoriz=fontNbCharHoriz; if ( fontNbCharVertic > 0 ) TCOD_ctx.fontNbCharVertic=fontNbCharVertic; if ( charmap ) { SDL_FreeSurface(charmap); charmap=NULL; } } else { printf ("Warning : font file '%s' does not exist\n",font); } } /* custom fullscreen resolution */ TCOD_ctx.fullscreen=TCOD_parser_get_bool_property(parser,"libtcod.fullscreen"); fullscreenWidth=TCOD_parser_get_int_property(parser,"libtcod.fullscreenWidth"); fullscreenHeight=TCOD_parser_get_int_property(parser,"libtcod.fullscreenHeight"); if ( fullscreenWidth > 0 ) TCOD_ctx.fullscreen_width=fullscreenWidth; if ( fullscreenHeight > 0 ) TCOD_ctx.fullscreen_height=fullscreenHeight; }
TCODParser::TCODParser() { data = TCOD_parser_new(); }
Loader loader_init(Loader l, char *basePath) { l->path = strdup(basePath); //first, install the basic trigger schema. this happens before any config files are loaded. l->triggerSchema = flagschema_init(flagschema_new()); #define ADD_TRIGGER(_trigName) flagschema_insert(l->triggerSchema, "on_" #_trigName , 1) ADD_TRIGGER(enter); ADD_TRIGGER(exit); ADD_TRIGGER(inside); ADD_TRIGGER(bump); ADD_TRIGGER(atop); ADD_TRIGGER(walk_up); ADD_TRIGGER(walk_down); ADD_TRIGGER(fall_onto); ADD_TRIGGER(fall_through); ADD_TRIGGER(chomp); ADD_TRIGGER(unchomp); ADD_TRIGGER(attach); ADD_TRIGGER(release); ADD_TRIGGER(eat); ADD_TRIGGER(digesting); ADD_TRIGGER(digested); ADD_TRIGGER(carry); ADD_TRIGGER(carry_left); ADD_TRIGGER(carry_right); ADD_TRIGGER(carry_back); ADD_TRIGGER(carry_forward); ADD_TRIGGER(carry_up); ADD_TRIGGER(carry_down); ADD_TRIGGER(latch); ADD_TRIGGER(tug_left); ADD_TRIGGER(tug_right); ADD_TRIGGER(tug_back); ADD_TRIGGER(tug_forward); #undef ADD_TRIGGER l->configParser = configlistener_init_parser(TCOD_parser_new(), l); l->configListener = configlistener_init(configlistener_new(), l); l->moveFlags = TCOD_list_new(); loader_add_move_flag(l, "normal"); loader_load_config(l, "init"); l->statusParser = statuslistener_init_parser(TCOD_parser_new(), l); l->statusListener = statuslistener_init(statuslistener_new(), l); TCOD_list_t statusFiles = configlistener_status_files(l->configListener); TS_LIST_FOREACH(statusFiles, loader_load_status(l, each)); l->objectParser = objectlistener_init_parser(TCOD_parser_new(), l); l->objectListener = objectlistener_init(objectlistener_new(), l); l->mapParser = maplistener_init_parser(TCOD_parser_new(), l); l->mapListener = maplistener_init(maplistener_new(), l); l->saveParser = savelistener_init_parser(TCOD_parser_new(), l); l->saveListener = savelistener_init(savelistener_new(), l); return l; }
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; }