void CCustomExplosionGenerator::RefreshCache(const std::string& tag) { // re-parse the projectile and generator tables explGenHandler->ParseExplosionTables(); if (tag.empty()) { std::map<std::string, unsigned int> oldExplosionIDs(explosionIDs); std::map<std::string, unsigned int>::const_iterator it; ClearCache(); // reload all currently cached CEGs by tag // (ID's of active CEGs will remain valid) for (it = oldExplosionIDs.begin(); it != oldExplosionIDs.end(); ++it) { const std::string& tmpTag = it->first; logOutput.Print("[%s] reloading CEG \"%s\" (ID %u)", __FUNCTION__, tmpTag.c_str(), it->second); Load(explGenHandler, tmpTag); } } else { // reload a single CEG const std::map<std::string, unsigned int>::const_iterator it = explosionIDs.find(tag); if (it == explosionIDs.end()) { logOutput.Print("[%s] unknown CEG-tag \"%s\"", __FUNCTION__, tag.c_str()); return; } const unsigned int numCEGs = explosionData.size(); const unsigned int cegIndex = it->second; // note: if numCEGs == 1, these refer to the same data CEGData oldCEG = explosionData[cegIndex]; CEGData tmpCEG = explosionData[numCEGs - 1]; // get rid of the old data explosionIDs.erase(tag); explosionData[cegIndex] = tmpCEG; explosionData.pop_back(); logOutput.Print("[%s] reloading single CEG \"%s\" (ID %u)", __FUNCTION__, tag.c_str(), cegIndex); if (Load(explGenHandler, tag) == -1U) { logOutput.Print("[%s] failed to reload single CEG \"%s\" (ID %u)", __FUNCTION__, tag.c_str(), cegIndex); // reload failed, keep the old CEG explosionIDs[tag] = cegIndex; explosionData.push_back(tmpCEG); explosionData[cegIndex] = oldCEG; return; } // re-map the old ID to the new data explosionIDs[tag] = cegIndex; if (numCEGs > 1) { explosionData[cegIndex] = explosionData[numCEGs - 1]; explosionData[numCEGs - 1] = tmpCEG; } } }
void CCustomExplosionGenerator::Reload(CExplosionGeneratorHandler* handler, const std::string& tag) { if (tag.empty()) { std::map<std::string, unsigned int> oldExplosionIDs(explosionIDs); std::map<std::string, unsigned int>::const_iterator it; Unload(handler); ClearCache(); // reload all currently cached CEGs by tag // (ID's of active CEGs will remain valid) for (it = oldExplosionIDs.begin(); it != oldExplosionIDs.end(); ++it) { const std::string& tmpTag = it->first; const char* fmt = "[%s][generatorID=%u] reloading CEG \"%s\" (tagID %u)"; LOG(fmt, __FUNCTION__, generatorID, tmpTag.c_str(), it->second); Load(explGenHandler, tmpTag); } } else { // reload a single CEG const std::map<std::string, unsigned int>::const_iterator it = explosionIDs.find(tag); if (it == explosionIDs.end()) { //LOG_L(L_WARNING, "[%s][generatorID=%u] unknown CEG-tag \"%s\"", // __FUNCTION__, generatorID, tag.c_str()); return; } const unsigned int numCEGs = explosionData.size(); const unsigned int cegIndex = it->second; // note: if numCEGs == 1, these refer to the same data CEGData oldCEG = explosionData[cegIndex]; CEGData tmpCEG = explosionData[numCEGs - 1]; // get rid of the old data explosionIDs.erase(tag); explosionData[cegIndex] = tmpCEG; explosionData.pop_back(); LOG("[%s][generatorID=%u] reloading single CEG \"%s\" (tagID %u)", __FUNCTION__, generatorID, tag.c_str(), cegIndex); if (Load(explGenHandler, tag) == -1U) { LOG_L(L_ERROR, "[%s][generatorID=%u] failed to reload single CEG \"%s\" (tagID %u)", __FUNCTION__, generatorID, tag.c_str(), cegIndex); // reload failed, keep the old CEG explosionIDs[tag] = cegIndex; explosionData.push_back(tmpCEG); explosionData[cegIndex] = oldCEG; return; } // re-map the old ID to the new data explosionIDs[tag] = cegIndex; if (numCEGs > 1) { explosionData[cegIndex] = explosionData[numCEGs - 1]; explosionData[numCEGs - 1] = tmpCEG; } } }