void ThreadTree::FixOverlappedMap(std::set<MapEntry*, MapComparator>* map_set, const MapEntry* map) { for (auto it = map_set->begin(); it != map_set->end();) { if ((*it)->start_addr >= map->get_end_addr()) { // No more overlapped maps. break; } if ((*it)->get_end_addr() <= map->start_addr) { ++it; } else { MapEntry* old = *it; if (old->start_addr < map->start_addr) { MapEntry* before = AllocateMap(MapEntry(old->start_addr, map->start_addr - old->start_addr, old->pgoff, old->time, old->dso)); map_set->insert(before); } if (old->get_end_addr() > map->get_end_addr()) { MapEntry* after = AllocateMap( MapEntry(map->get_end_addr(), old->get_end_addr() - map->get_end_addr(), map->get_end_addr() - old->start_addr + old->pgoff, old->time, old->dso)); map_set->insert(after); } it = map_set->erase(it); } } }
void ThreadTree::AddThreadMap(int pid, int tid, uint64_t start_addr, uint64_t len, uint64_t pgoff, uint64_t time, const std::string& filename) { ThreadEntry* thread = FindThreadOrNew(pid, tid); Dso* dso = FindUserDsoOrNew(filename); MapEntry* map = AllocateMap(MapEntry(start_addr, len, pgoff, time, dso)); FixOverlappedMap(&thread->maps, map); auto pair = thread->maps.insert(map); CHECK(pair.second); }
void ThreadTree::AddKernelMap(uint64_t start_addr, uint64_t len, uint64_t pgoff, uint64_t time, const std::string& filename) { // kernel map len can be 0 when record command is not run in supervisor mode. if (len == 0) { return; } Dso* dso = FindKernelDsoOrNew(filename); MapEntry* map = AllocateMap(MapEntry(start_addr, len, pgoff, time, dso)); FixOverlappedMap(&kernel_map_tree_, map); auto pair = kernel_map_tree_.insert(map); CHECK(pair.second); }
int InitOpcodeTraps(DISZ80 *d) { int err; char buf[_MAX_PATH + 64]; if (d->scriptFileName[0]) { if (d->pTrapMap == NULL) { if ((d->pTrapMap = AllocateMap(d, "Couldn't allocate memory for the opcode trap map.", 256)) == NULL) { DisZ80CleanUp(d); return DERR_OUTOFMEM; } } err = InitScripting(d); if (err != DERR_NONE) return err; err = lua_dofile(d->ls, d->scriptFileName); if (err) { switch(err) { case 2: sprintf(buf, "Couldn't open the script file \"%s\"", d->scriptFileName); dZ80_Error(d, buf); return DERR_COULDNTOPENFILE; default: return DERR_SCRIPTERROR; } } } return DERR_NONE; }
void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings) { /* Make sure there isn't any window that can influence anything * related to the new game we're about to start/load. */ UnInitWindowSystem(); AllocateMap(size_x, size_y); _pause_mode = PM_UNPAUSED; _fast_forward = 0; _tick_counter = 0; _cur_tileloop_tile = 0; _thd.redsq = INVALID_TILE; if (reset_settings) MakeNewgameSettingsLive(); if (reset_date) { SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0); InitializeOldNames(); } PoolBase::Clean(PT_NORMAL); ResetPersistentNewGRFData(); InitializeSound(); InitializeMusic(); InitializeVehicles(); InitNewsItemStructs(); InitializeLandscape(); InitializeRailGui(); InitializeRoadGui(); InitializeAirportGui(); InitializeDockGui(); InitializeObjectGui(); InitializeAIGui(); InitializeTrees(); InitializeIndustries(); InitializeObjects(); InitializeBuildingCounts(); InitializeNPF(); InitializeCompanies(); AI::Initialize(); Game::Initialize(); InitializeCheats(); InitTextEffects(); #ifdef ENABLE_NETWORK NetworkInitChatMessage(); #endif /* ENABLE_NETWORK */ InitializeAnimatedTiles(); InitializeEconomy(); ResetObjectToPlace(); GamelogReset(); GamelogStartAction(GLAT_START); GamelogRevision(); GamelogMode(); GamelogGRFAddList(_grfconfig); GamelogStopAction(); }
static void Load_MAPS() { SlGlobList(_map_dimensions); AllocateMap(_map_dim_x, _map_dim_y); }
// Load map void _Map::Load(const std::string &Path, bool Static) { std::string AtlasPath; // Load file gzifstream File(Path.c_str()); if(!File) throw std::runtime_error("Cannot load map: " + Path); _Tile *Tile = nullptr; while(!File.eof() && File.peek() != EOF) { // Read chunk type char ChunkType; File >> ChunkType; switch(ChunkType) { // Map version case 'V': { int FileVersion; File >> FileVersion; if(FileVersion != MAP_VERSION) throw std::runtime_error("Level version mismatch: " + std::to_string(FileVersion)); } break; // Map size case 'S': { File >> Size.x >> Size.y; FreeMap(); AllocateMap(); } break; // Ambient light case 'A': { File >> AmbientLight.r >> AmbientLight.g >> AmbientLight.b; } break; // Outside case 'O': { File >> IsOutside; } break; case 'B': { if(UseAtlas) { File >> BackgroundMapFile; BackgroundMap = new _Map(); BackgroundMap->UseAtlas = true; try { BackgroundMap->Load(BackgroundMapFile, true); } catch(std::exception &Error) { delete BackgroundMap; BackgroundMap = nullptr; } } } break; case 'Z': { if(UseAtlas) File >> BackgroundOffset.x >> BackgroundOffset.y >> BackgroundOffset.z; } break; // Atlas texture case 'a': { File >> AtlasPath; } break; // Tile case 'T': { glm::ivec2 Coordinate; File >> Coordinate.x >> Coordinate.y; if(Coordinate.x < Size.x && Coordinate.y < Size.y) Tile = &Tiles[Coordinate.x][Coordinate.y]; else Tile = nullptr; } break; // Texture index case 'b': { if(Tile) File >> Tile->TextureIndex[0]; } break; // Foreground texture index case 'f': { if(Tile) File >> Tile->TextureIndex[1]; } break; // Zone case 'z': { if(Tile) File >> Tile->Zone; } break; // Event case 'e': { if(Tile) File >> Tile->Event.Type >> Tile->Event.Data; } break; // Wall case 'w': { if(Tile) File >> Tile->Wall; } break; // PVP case 'p': { if(Tile) File >> Tile->PVP; } break; default: File.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); break; } } File.close(); // Index events IndexEvents(); // Initialize 2d tile rendering if(UseAtlas) { InitAtlas(AtlasPath, Static); } }