Chunk::~Chunk() { if(m_Volume->getBaseDir() != NULL) assert(m_Modified == false); assert(m_References == 0); clearLayers(true); }
/** * Clears all layers, blocks and entities of this graphic. * A default layer (0) is created. */ void RS_Graphic::newDoc() { RS_DEBUG->print("RS_Graphic::newDoc"); clear(); clearLayers(); clearBlocks(); addLayer(new RS_Layer("0")); //addLayer(new RS_Layer("ByBlock")); setModified(false); }
int Map::load(std::string fname) { FileParser infile; maprow *cur_layer = NULL; clearEvents(); clearLayers(); clearQueues(); // @CLASS Map|Description of maps/ if (!infile.open(fname)) return 0; this->filename = fname; while (infile.next()) { if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "enemy") enemies.push(Map_Enemy()); else if (infile.section == "enemygroup") enemy_groups.push(Map_Group()); else if (infile.section == "npc") npcs.push(Map_NPC()); else if (infile.section == "event") events.push_back(Event()); } if (infile.section == "header") loadHeader(infile); else if (infile.section == "layer") loadLayer(infile, &cur_layer); else if (infile.section == "enemy") loadEnemy(infile); else if (infile.section == "enemygroup") loadEnemyGroup(infile, &enemy_groups.back()); else if (infile.section == "npc") loadNPC(infile); else if (infile.section == "event") EventManager::loadEvent(infile, &events.back()); } infile.close(); return 0; }
MapRenderer::~MapRenderer() { if (music != NULL) { Mix_HaltMusic(); Mix_FreeMusic(music); } tip_buf.clear(); clearLayers(); clearEvents(); clearQueues(); delete tip; /* unload sounds */ snd->reset(); while (!sids.empty()) { snd->unload(sids.back()); sids.pop_back(); } }
int Map::load(const std::string& fname) { FileParser infile; clearEvents(); clearLayers(); clearQueues(); music_filename = ""; // @CLASS Map|Description of maps/ if (!infile.open(fname)) return 0; this->filename = fname; while (infile.next()) { if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "enemy") enemy_groups.push(Map_Group()); else if (infile.section == "npc") npcs.push(Map_NPC()); else if (infile.section == "event") events.push_back(Event()); } if (infile.section == "header") loadHeader(infile); else if (infile.section == "layer") loadLayer(infile); else if (infile.section == "enemy") loadEnemyGroup(infile, &enemy_groups.back()); else if (infile.section == "npc") loadNPC(infile); else if (infile.section == "event") EventManager::loadEvent(infile, &events.back()); } infile.close(); // create a temporary EffectDef for immunity; will be used for map StatBlocks EffectDef immunity_effect; immunity_effect.id = "MAP_EVENT_IMMUNITY"; immunity_effect.type = "immunity"; // create StatBlocks for events that need powers for (unsigned i=0; i<events.size(); ++i) { Event_Component *ec_power = events[i].getComponent(EC_POWER); if (ec_power) { statblocks.push_back(StatBlock()); StatBlock *statb = &statblocks.back(); if (!statb) { logError("Map: Could not create StatBlock for Event."); continue; } // store the index of this StatBlock so that we can find it when the event is activated ec_power->y = static_cast<int>(statblocks.size())-1; statb->starting[STAT_ACCURACY] = 1000; // always hit the target Event_Component *ec_path = events[i].getComponent(EC_POWER_PATH); if (ec_path) { // source is power path start statb->pos.x = static_cast<float>(ec_path->x) + 0.5f; statb->pos.y = static_cast<float>(ec_path->y) + 0.5f; } else { // source is event location statb->pos.x = static_cast<float>(events[i].location.x) + 0.5f; statb->pos.y = static_cast<float>(events[i].location.y) + 0.5f; } Event_Component *ec_damage = events[i].getComponent(EC_POWER_DAMAGE); if (ec_damage) { statb->starting[STAT_DMG_MELEE_MIN] = statb->starting[STAT_DMG_RANGED_MIN] = statb->starting[STAT_DMG_MENT_MIN] = ec_damage->a; statb->starting[STAT_DMG_MELEE_MAX] = statb->starting[STAT_DMG_RANGED_MAX] = statb->starting[STAT_DMG_MENT_MAX] = ec_damage->b; } // this is used to store cooldown ticks for a map power // the power id, type, etc are not used statb->powers_ai.resize(1); // make this StatBlock immune to negative status effects // this is mostly to prevent a player with a damage return bonus from damaging this StatBlock statb->effects.addEffect(immunity_effect, 0, 0, false, -1, 0, SOURCE_TYPE_ENEMY); } } // ensure that our map contains a collison layer if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) { layernames.push_back("collision"); layers.resize(layers.size()+1); layers.back().resize(w); for (size_t i=0; i<layers.back().size(); ++i) { layers.back()[i].resize(h, 0); } collision_layer = static_cast<int>(layers.size())-1; } return 0; }
Map::~Map() { clearLayers(); }
CloudSystem::~CloudSystem() { clearLayers (); }
bool Chunk::loadFromFile() { m_Volume->incStatistic(STATISTIC_CHUNK_LOAD_OPS); m_Volume->log(VMAN_LOG_DEBUG, "Loading chunk %s from file ..\n", toString().c_str()); if(m_Volume->getBaseDir() == NULL) { assert(!"Probably redundant."); return false; } const int voxelsPerChunk = m_Volume->getVoxelsPerChunk(); std::string fileName = m_Volume->getChunkFileName(m_ChunkX, m_ChunkY, m_ChunkZ); FILE* f = fopen(fileName.c_str(), "rb"); if(f == NULL) { m_Volume->log(VMAN_LOG_DEBUG, "%s: File does not exist.\n", fileName.c_str()); return false; } try { // -- Read header -- ChunkFileHeader header; if(fread(&header, sizeof(header), 1, f) != 1) throw "Read error in file header."; header.version = LittleEndian(header.version); header.edgeLength = LittleEndian(header.edgeLength); header.layerCount = LittleEndian(header.layerCount); m_Volume->log(VMAN_LOG_DEBUG, "version: %d\n", header.version); m_Volume->log(VMAN_LOG_DEBUG, "edgeLength: %d\n", header.edgeLength); m_Volume->log(VMAN_LOG_DEBUG, "layerCount: %d\n", header.layerCount); if(header.version != ChunkFileVersion) throw "Incorrect file version."; std::vector<ChunkFileLayerInfo> layerInfos(header.layerCount); // -- Read layer list -- for(int i = 0; i < layerInfos.size(); ++i) { ChunkFileLayerInfo* layerInfo = &layerInfos[i]; if(fread(layerInfo, sizeof(ChunkFileLayerInfo), 1, f) != 1) throw Format("Read error in layer info %d", i); layerInfo->voxelSize = LittleEndian(layerInfo->voxelSize); layerInfo->revision = LittleEndian(layerInfo->revision); layerInfo->fileOffset = LittleEndian(layerInfo->fileOffset); m_Volume->log(VMAN_LOG_DEBUG, "[layer %d] name: '%s'\n", i, layerInfo->name); m_Volume->log(VMAN_LOG_DEBUG, "[layer %d] voxelSize: %d\n", i, layerInfo->voxelSize); m_Volume->log(VMAN_LOG_DEBUG, "[layer %d] revision: %d\n", i, layerInfo->revision); m_Volume->log(VMAN_LOG_DEBUG, "[layer %d] fileOffset: %d\n", i, layerInfo->fileOffset); if(m_Volume->getLayerIndexByName(layerInfo->name) == -1) { m_Volume->log(VMAN_LOG_INFO, "%s: Ignoring chunk layer '%s'.\n", fileName.c_str(), layerInfo->name); } } // -- Copy used layers -- std::vector<char> buffer(voxelsPerChunk * m_Volume->getMaxLayerVoxelSize()); for(int i = 0; i < m_Layers.size(); ++i) { const vmanLayer* layer = m_Volume->getLayer(i); const ChunkFileLayerInfo* layerInfo = FindChunkLayerByName(layerInfos, layer->name); if(layerInfo) { if( (layer->voxelSize != layerInfo->voxelSize) || (layer->revision != layerInfo->revision) ) { m_Volume->log(VMAN_LOG_ERROR,"%s: Chunk layer '%s' differs, ignoring it.\n", fileName.c_str(), layer->name); // TODO: Maybe let the application try to import/convert the layer. continue; } fseek(f, layerInfo->fileOffset, SEEK_SET); if(fread(&buffer[0], voxelsPerChunk*layer->voxelSize, 1, f) != 1) throw Format("Read error in layer %d.", i); m_Layers[i] = new char[voxelsPerChunk*layer->voxelSize]; layer->deserializeFn(&buffer[0], m_Layers[i], voxelsPerChunk*layer->voxelSize); } } } catch(const std::string e) { m_Volume->log(VMAN_LOG_ERROR, "%s: %s\n", fileName.c_str(), e.c_str()); fclose(f); clearLayers(); assert(false); return false; } fclose(f); return true; }
int Map::load(const std::string& fname) { FileParser infile; clearEvents(); clearLayers(); clearQueues(); music_filename = ""; collision_layer = -1; w = 1; h = 1; hero_pos_enabled = false; hero_pos.x = 0; hero_pos.y = 0; // @CLASS Map|Description of maps/ if (!infile.open(fname)) return 0; logInfo("Map: Loading map '%s'", fname.c_str()); this->filename = fname; while (infile.next()) { if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "enemy") enemy_groups.push(Map_Group()); else if (infile.section == "npc") npcs.push(Map_NPC()); else if (infile.section == "event") events.push_back(Event()); } if (infile.section == "header") loadHeader(infile); else if (infile.section == "layer") loadLayer(infile); else if (infile.section == "enemy") loadEnemyGroup(infile, &enemy_groups.back()); else if (infile.section == "npc") loadNPC(infile); else if (infile.section == "event") EventManager::loadEvent(infile, &events.back()); } infile.close(); // create StatBlocks for events that need powers for (unsigned i=0; i<events.size(); ++i) { Event_Component *ec_power = events[i].getComponent(EC_POWER); if (ec_power) { // store the index of this StatBlock so that we can find it when the event is activated ec_power->y = addEventStatBlock(events[i]); } } // ensure that our map contains a collision layer if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) { layernames.push_back("collision"); layers.resize(layers.size()+1); layers.back().resize(w); for (size_t i=0; i<layers.back().size(); ++i) { layers.back()[i].resize(h, 0); } collision_layer = static_cast<int>(layers.size())-1; } if (!hero_pos_enabled) { logError("Map: Hero spawn position (hero_pos) not defined in map header. Defaulting to (0,0)."); } return 0; }