void NetPanzerData::load_data(const std::string& datadir_) { datadir = datadir_; std::cout << "NetPanzerData: Loading data from '" << datadir << "'" << std::endl; palette = load_palette(datadir + "/" + "wads/netp.act"); load_tileset(datadir + "/" + "wads/summer12mb.tls"); }
void cata_tiles::init(std::string json_path, std::string tileset_path) { // load files DebugLog() << "Attempting to Load JSON file\n"; load_tilejson(json_path); DebugLog() << "Attempting to Load Tileset file\n"; load_tileset(tileset_path); DebugLog() << "Attempting to Create Rotation Cache\n"; create_rotation_cache(); }
void cata_tiles::init(SDL_Surface *screen, std::string json_path, std::string tileset_path) { display_screen = screen; // load files DebugLog() << "Attempting to Load JSON file\n"; load_tilejson(json_path); DebugLog() << "Attempting to Load Tileset file\n"; load_tileset(tileset_path); DebugLog() << "Attempting to Create Rotation Cache\n"; create_rotation_cache(); }
int event(s_sdl *s_init, int **table, int xe, int ce) { SDL_Event event; int i; SDL_Texture *character; SDL_Rect dest; int x; int y; SDL_Texture *tileset; tileset = load_tileset(s_init); if (tileset == NULL) return (0); if (!(character = (load_character(s_init)))) printf("Character NULL"); i = 0; x = 100; y = 100; while (!i) { SDL_PollEvent(&event); switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: i = 1; return (0); case SDLK_LEFT: x = x - 1; break; case SDLK_RIGHT: x = x + 1; break; case SDLK_UP: y = y - 1; break; case SDLK_DOWN: y = y + 1; break; } break; } pos_character(&dest, &x, &y); print_tile(s_init, table, xe, ce, tileset); SDL_RenderCopy(s_init->renderer, character, NULL, &dest); SDL_RenderPresent(s_init->renderer); } }
/// /// See: https://github.com/bjorn/tiled/wiki/TMX-Map-Format /// https://code.google.com/p/tmx-parser /// /// NOTE /// We don't support the TMX file format fully. The TmxParser library /// can fully parse the files but we don't make use of all of these /// attributes and have only parsed them if we need them. /// bool MapLoader::load_map(const std::string source) { LOG(INFO) << "Loading map"; map.ParseFile(source); if (map.HasError()) { LOG(ERROR) << map.GetErrorCode() << " " << map.GetErrorText(); return false; } map_width = map.GetWidth(); map_height = map.GetHeight(); load_tileset(); load_layers(); return true; }
DFhackCExport command_result plugin_init ( color_ostream &out, vector <PluginCommand> &commands) { out2 = &out; *out2 << "TWBT: version " << TWBT_VER << std::endl; int mode = get_mode(); if (!mode) { *out2 << COLOR_RED << "TWBT: set PRINT_MODE to TWBT in data/init/init.txt to activate the plugin" << std::endl; *out2 << COLOR_RESET; return CR_OK; } if (mode == 1) { #ifdef LEGACY_MODE_ONLY *out2 << COLOR_RED << "TWBT: falling back to legacy mode with this version of DF" << std::endl; *out2 << COLOR_RESET; mode = -1; #else #ifdef NO_RENDERING_PATCH *out2 << "TWBT: no rendering patch (not an error)" << std::endl; #endif #ifdef NO_DISPLAY_PATCH *out2 << "TWBT: no display patch (not an error)" << std::endl; #endif #endif } legacy_mode = (mode == -1); #ifdef WIN32 _load_multi_pdim = (LOAD_MULTI_PDIM) (A_LOAD_MULTI_PDIM + Core::getInstance().vinfo->getRebaseDelta()); _render_map = (RENDER_MAP) (A_RENDER_MAP + Core::getInstance().vinfo->getRebaseDelta()); _render_updown = (RENDER_UPDOWN) (A_RENDER_UPDOWN + Core::getInstance().vinfo->getRebaseDelta()); #elif defined(__APPLE__) _load_multi_pdim = (LOAD_MULTI_PDIM) A_LOAD_MULTI_PDIM; _render_map = (RENDER_MAP) A_RENDER_MAP; _render_updown = (RENDER_UPDOWN) A_RENDER_UPDOWN; #else _load_multi_pdim = (LOAD_MULTI_PDIM) dlsym(RTLD_DEFAULT, "_ZN8textures15load_multi_pdimERKSsPlllbS2_S2_"); _render_map = (RENDER_MAP) A_RENDER_MAP; _render_updown = (RENDER_UPDOWN) A_RENDER_UPDOWN; #endif bad_item_flags.whole = 0; bad_item_flags.bits.in_building = true; bad_item_flags.bits.garbage_collect = true; bad_item_flags.bits.removed = true; bad_item_flags.bits.dead_dwarf = true; bad_item_flags.bits.murder = true; bad_item_flags.bits.construction = true; bad_item_flags.bits.in_inventory = true; bad_item_flags.bits.in_chest = true; // Used only if rendering patch is not available skytile = d_init->sky_tile; chasmtile = d_init->chasm_tile; struct stat buf; if (stat("data/art/white1px.png", &buf) == 0) { long dx, dy; load_tileset("data/art/white1px.png", &white_texpos, 1, 1, &dx, &dy); } else { *out2 << COLOR_RED << "TWBT: data/art/white1px.png not found, can not continue" << std::endl; *out2 << COLOR_RESET; return CR_FAILURE; } if (stat("data/art/transparent1px.png", &buf) == 0) { long dx, dy; load_tileset("data/art/transparent1px.png", &transparent_texpos, 1, 1, &dx, &dy); } else { *out2 << COLOR_RED << "TWBT: data/art/transparent1px.png not found, can not continue" << std::endl; *out2 << COLOR_RESET; return CR_FAILURE; } if (init->display.flag.is_set(init_display_flags::USE_GRAPHICS)) { // Graphics is enabled. Map tileset is already loaded, so use it. Then load text tileset. // Existing map tileset - accessible at index 0 struct tileset ts; memcpy(ts.small_texpos, init->font.small_font_texpos, sizeof(ts.small_texpos)); tilesets.push_back(ts); // We will replace init->font with text font, so let's save graphics tile size small_map_dispx = init->font.small_font_dispx, small_map_dispy = init->font.small_font_dispy; has_textfont = load_text_font(); if (!has_textfont) tilesets.push_back(tilesets[0]); } else { // Graphics is disabled. Text tileset is already loaded. Load map tileset. has_textfont = load_map_font(); // Existing text tileset - accessible at index 1 if (has_textfont) { struct tileset ts; memcpy(ts.small_texpos, init->font.small_font_texpos, sizeof(ts.small_texpos)); tilesets.push_back(ts); } else tilesets.push_back(tilesets[0]); } init_text_tileset_layers(); if (!has_textfont) { *out2 << COLOR_YELLOW << "TWBT: FONT and GRAPHICS_FONT are the same" << std::endl; *out2 << COLOR_RESET; } has_overrides = load_overrides(); // Load shadows if (stat("data/art/shadows.png", &buf) == 0) { long dx, dy; load_tileset("data/art/shadows.png", shadow_texpos, 8, 1, &dx, &dy); shadowsloaded = true; } else { *out2 << COLOR_RED << "TWBT: data/art/shadows.png not found, shadows will not be rendered" << std::endl; *out2 << COLOR_RESET; } map_texpos = tilesets[0].small_texpos; text_texpos = tilesets[1].small_texpos; commands.push_back(PluginCommand( "mapshot", "Mapshot!", mapshot_cmd, true, "" )); commands.push_back(PluginCommand( "multilevel", "Multi-level rendering", multilevel_cmd, false, "" )); commands.push_back(PluginCommand( "colormap", "Colomap manipulation", colormap_cmd, false, "" )); commands.push_back(PluginCommand( "twbt", "Text Will Be Text", twbt_cmd, false, "" )); if (!legacy_mode) { replace_renderer(); INTERPOSE_HOOK(dwarfmode_hook, render).apply(true); INTERPOSE_HOOK(dwarfmode_hook, logic).apply(true); INTERPOSE_HOOK(dwarfmode_hook, feed).apply(true); INTERPOSE_HOOK(viewscreen_unitlistst_zoomfix, feed).apply(true); INTERPOSE_HOOK(viewscreen_buildinglistst_zoomfix, feed).apply(true); INTERPOSE_HOOK(viewscreen_layer_unit_relationshipst_zoomfix, feed).apply(true); INTERPOSE_HOOK(dungeonmode_hook, render).apply(true); INTERPOSE_HOOK(dungeonmode_hook, logic).apply(true); INTERPOSE_HOOK(dungeonmode_hook, feed).apply(true); enable_building_hooks(); enable_item_hooks(); enable_unit_hooks(); } else { hook_legacy(); INTERPOSE_HOOK(dwarfmode_hook_legacy, render).apply(true); } return CR_OK; }
int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { printf("Can't initialize SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } atexit(SDL_Quit); SDL_Surface *screen, *text, *save_message; SDL_Event event; TTF_Font *font; int i, done = 0, mouse_x = 0, mouse_y = 0; unsigned int frames = SDL_GetTicks() + FLIMIT; unsigned int *frame_limit; frame_limit = &frames; int *mouse_x_ptr, *mouse_y_ptr; mouse_x_ptr = &mouse_x; mouse_y_ptr = &mouse_y; int show_save_msg = 0; screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, SDL_DOUBLEBUF | SDL_HWSURFACE); //screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, SDL_DOUBLEBUF | SDL_FULLSCREEN); if(NULL == screen) { printf("Can't set video mode: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* set window title */ SDL_WM_SetCaption("2D SIMULATION", NULL); /* disable cursor */ SDL_ShowCursor(SDL_DISABLE); /* load new cursor */ load_cursor(); /* load the map and fill tiles array */ load_map(); /* load tileset */ load_tileset(); /* load player */ load_player_image(); /* setup font */ TTF_Init(); SDL_Color text_color = {255, 255, 255}; font = TTF_OpenFont("media/fonts/slkscrb.ttf", 8); /* game loop */ while(!done) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: done = 1; break; case SAVE_EVENT: show_save_msg = 0; //printf("SDL_USEREVENT: %i\n", SAVE_EVENT); break; case SDL_MOUSEMOTION: *mouse_x_ptr = event.motion.x; *mouse_y_ptr = event.motion.y; break; case SDL_MOUSEBUTTONDOWN: switch(event.button.button) { case 1: //destroy_block(screen, event.button.x, event.button.y); input.mleft = 1; break; case 3: //place_block(event.button.x, event.button.y, &player); input.mright = 1; break; default: break; } break; case SDL_MOUSEBUTTONUP: switch(event.button.button) { /* removed because if player falls down, it deletes always the block below the player */ case 1: input.mleft = 0; break; case 3: input.mright = 0; break; default: break; } break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_ESCAPE: done = 1; break; case SDLK_a: input.left = 1; break; case SDLK_d: input.right = 1; break; case SDLK_SPACE: input.jump = 1; break; case SDLK_1: player.selected = DIRT; break; case SDLK_2: player.selected = GRASS; break; case SDLK_3: player.selected = SAND; break; case SDLK_4: player.selected = ROCK; break; case SDLK_5: player.selected = WATER5; break; case SDLK_6: player.selected = OIL; break; case SDLK_F12: save_map(); SDL_AddTimer (2000, msg_event, NULL); show_save_msg = 1; break; default: break; } break; case SDL_KEYUP: switch(event.key.keysym.sym) { case SDLK_a: input.left = 0; break; case SDLK_d: input.right = 0; break; default: break; } break; } } move_player(&player); // and camera move_sand(); simulate_water(); simulate_oil(); place_and_destroy_blocks(screen, event.button.x, event.button.y, &player); //input.mleft = 0; // uncomment for click once to delete one block //input.mright = 0; // uncomment for click once to place one block draw(screen, mouse_x_ptr, mouse_y_ptr, &player, text, font, text_color, show_save_msg, save_message); delay(frame_limit); *frame_limit = SDL_GetTicks() + FLIMIT; } /* free tiles/mass/new_mass array in reverse order */ for(i = 0; i < map.h; i++) { free(map.tiles[i]); free(map.water_mass[i]); free(map.new_water_mass[i]); free(map.oil_mass[i]); free(map.new_oil_mass[i]); } free(map.tiles); free(map.water_mass); free(map.new_water_mass); free(map.oil_mass); free(map.new_oil_mass); SDL_FreeSurface(tileset); SDL_FreeSurface(player_image); SDL_FreeSurface(cursor); SDL_FreeSurface(text); SDL_FreeSurface(save_message); return 0; }