diff --git a/AI/Nullkiller/Pathfinding/AINodeStorage.cpp b/AI/Nullkiller/Pathfinding/AINodeStorage.cpp index f40aa89dd..7e029fe64 100644 --- a/AI/Nullkiller/Pathfinding/AINodeStorage.cpp +++ b/AI/Nullkiller/Pathfinding/AINodeStorage.cpp @@ -90,7 +90,7 @@ void AINodeStorage::initialize(const PathfinderOptions & options, const CGameSta //TODO: fix this code duplication with NodeStorage::initialize, problem is to keep `resetTile` inline const PlayerColor fowPlayer = ai->playerID; - const auto fow = static_cast(gs)->getPlayerTeam(fowPlayer)->fogOfWarMap; + const auto & fow = static_cast(gs)->getPlayerTeam(fowPlayer)->fogOfWarMap; const int3 sizes = gs->getMapSize(); //Each thread gets different x, but an array of y located next to each other in memory diff --git a/client/CMT.cpp b/client/CMT.cpp index f3741bbbf..45199effc 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -346,7 +346,6 @@ int main(int argc, char * argv[]) session["autoSkip"].Bool() = vm.count("autoSkip"); session["oneGoodAI"].Bool() = vm.count("oneGoodAI"); session["aiSolo"].Bool() = false; - std::shared_ptr mmenu; if(vm.count("testmap")) { @@ -362,7 +361,7 @@ int main(int argc, char * argv[]) } else { - mmenu = CMainMenu::create(); + auto mmenu = CMainMenu::create(); GH.curInt = mmenu.get(); } @@ -399,7 +398,7 @@ int main(int argc, char * argv[]) //start lobby immediately names.push_back(session["username"].String()); ESelectionScreen sscreen = session["gamemode"].Integer() == 0 ? ESelectionScreen::newGame : ESelectionScreen::loadGame; - mmenu->openLobby(sscreen, session["host"].Bool(), &names, ELoadMode::MULTI); + CMM->openLobby(sscreen, session["host"].Bool(), &names, ELoadMode::MULTI); } // Restore remote session - start game immediately @@ -472,6 +471,9 @@ static void quitApplication() CCS->musich->release(); CCS->soundh->release(); + delete CCS->consoleh; + delete CCS->curh; + vstd::clear_pointer(CCS); } CMessage::dispose(); diff --git a/client/eventsSDL/InputHandler.cpp b/client/eventsSDL/InputHandler.cpp index 257ee70d0..2db1020a9 100644 --- a/client/eventsSDL/InputHandler.cpp +++ b/client/eventsSDL/InputHandler.cpp @@ -316,6 +316,8 @@ void InputHandler::handleUserEvent(const SDL_UserEvent & current) auto heapFunctor = static_cast*>(current.data1); (*heapFunctor)(); + + delete heapFunctor; } const Point & InputHandler::getCursorPosition() const diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index 44de7bee3..e69dfa0ea 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -726,11 +726,11 @@ CGameInfoCallback::CGameInfoCallback(CGameState * GS): { } -std::shared_ptr> CPlayerSpecificInfoCallback::getVisibilityMap() const -{ - //boost::shared_lock lock(*gs->mx); - return gs->getPlayerTeam(*getPlayerID())->fogOfWarMap; -} +//std::shared_ptr> CPlayerSpecificInfoCallback::getVisibilityMap() const +//{ +// //boost::shared_lock lock(*gs->mx); +// return gs->getPlayerTeam(*getPlayerID())->fogOfWarMap; +//} int CPlayerSpecificInfoCallback::howManyTowns() const { diff --git a/lib/CGameInfoCallback.h b/lib/CGameInfoCallback.h index 794719187..2ab121e08 100644 --- a/lib/CGameInfoCallback.h +++ b/lib/CGameInfoCallback.h @@ -247,7 +247,7 @@ public: virtual int getResourceAmount(GameResID type) const; virtual TResources getResourceAmount() const; - virtual std::shared_ptr> getVisibilityMap() const; //returns visibility map + //virtual std::shared_ptr> getVisibilityMap() const; //returns visibility map //virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const; }; diff --git a/lib/CPlayerState.h b/lib/CPlayerState.h index 66c70619a..7f31ff8ee 100644 --- a/lib/CPlayerState.h +++ b/lib/CPlayerState.h @@ -98,7 +98,7 @@ public: TeamID id; //position in gameState::teams std::set players; // members of this team //TODO: boost::array, bool if possible - std::shared_ptr> fogOfWarMap; //[z][x][y] true - visible, false - hidden + std::unique_ptr> fogOfWarMap; //[z][x][y] true - visible, false - hidden TeamState(); TeamState(TeamState && other) noexcept; diff --git a/lib/ObstacleHandler.cpp b/lib/ObstacleHandler.cpp index fbfc7efe2..deb87f804 100644 --- a/lib/ObstacleHandler.cpp +++ b/lib/ObstacleHandler.cpp @@ -106,8 +106,6 @@ ObstacleInfo * ObstacleHandler::loadFromJson(const std::string & scope, const Js info->isAbsoluteObstacle = json["absolute"].Bool(); info->isForegroundObstacle = json["foreground"].Bool(); - objects.emplace_back(info); - return info; } diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 3a4dea264..f297e5dff 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -259,6 +259,11 @@ void LibClasses::clear() delete battlefieldsHandler; delete generaltexth; delete identifiersHandler; + delete obstacleHandler; + delete terrainTypeHandler; + delete riverTypeHandler; + delete roadTypeHandler; + delete settingsHandler; makeNull(); } @@ -282,6 +287,11 @@ void LibClasses::makeNull() #endif battlefieldsHandler = nullptr; identifiersHandler = nullptr; + obstacleHandler = nullptr; + terrainTypeHandler = nullptr; + riverTypeHandler = nullptr; + roadTypeHandler = nullptr; + settingsHandler = nullptr; } LibClasses::LibClasses() diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index beb8eeda4..b2301be4f 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -700,7 +700,7 @@ void CGameState::initFogOfWar() int layers = map->levels(); for(auto & elem : teams) { - auto fow = elem.second.fogOfWarMap; + auto & fow = elem.second.fogOfWarMap; fow->resize(boost::extents[layers][map->width][map->height]); std::fill(fow->data(), fow->data() + fow->num_elements(), 0); @@ -1952,7 +1952,7 @@ bool RumorState::update(int id, int extra) TeamState::TeamState() { setNodeType(TEAM); - fogOfWarMap = std::make_shared>(); + fogOfWarMap = std::make_unique>(); } TeamState::TeamState(TeamState && other) noexcept: diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index 6fa16d8ce..7f8818121 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -327,13 +327,21 @@ void CGHeroInstance::initHero(CRandomGenerator & rand) { // hero starts with default spellbook presence status if(!getArt(ArtifactPosition::SPELLBOOK) && type->haveSpellBook) - putArtifact(ArtifactPosition::SPELLBOOK, ArtifactUtils::createNewArtifactInstance(ArtifactID::SPELLBOOK)); + { + auto artifact = ArtifactUtils::createNewArtifactInstance(ArtifactID::SPELLBOOK); + cb->gameState()->map->addNewArtifactInstance(artifact); + putArtifact(ArtifactPosition::SPELLBOOK, artifact); + } } else spells -= SpellID::SPELLBOOK_PRESET; if(!getArt(ArtifactPosition::MACH4)) - putArtifact(ArtifactPosition::MACH4, ArtifactUtils::createNewArtifactInstance(ArtifactID::CATAPULT)); //everyone has a catapult + { + auto artifact = ArtifactUtils::createNewArtifactInstance(ArtifactID::CATAPULT); + cb->gameState()->map->addNewArtifactInstance(artifact); + putArtifact(ArtifactPosition::MACH4, artifact); //everyone has a catapult + } if(!hasBonus(Selector::sourceType()(BonusSource::HERO_BASE_SKILL))) { @@ -448,7 +456,11 @@ void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor * dst) ArtifactPosition slot = art->getPossibleSlots().at(ArtBearer::HERO).front(); if(!getArt(slot)) - putArtifact(slot, ArtifactUtils::createNewArtifactInstance(aid)); + { + auto artifact = ArtifactUtils::createNewArtifactInstance(aid); + cb->gameState()->map->addNewArtifactInstance(artifact); + putArtifact(slot, artifact); + } else logGlobal->warn("Hero %s already has artifact at %d, omitting giving artifact %d", getNameTranslated(), slot.toEnum(), aid.toEnum()); } diff --git a/lib/mapObjects/CGObjectInstance.cpp b/lib/mapObjects/CGObjectInstance.cpp index 167e24c75..de38be9d0 100644 --- a/lib/mapObjects/CGObjectInstance.cpp +++ b/lib/mapObjects/CGObjectInstance.cpp @@ -35,10 +35,14 @@ CGObjectInstance::CGObjectInstance(): tempOwner(PlayerColor::UNFLAGGABLE), blockVisit(false) { + logGlobal->debug("Created object at %d", ptrdiff_t(this)); } //must be instantiated in .cpp file for access to complete types of all member fields -CGObjectInstance::~CGObjectInstance() = default; +CGObjectInstance::~CGObjectInstance() +{ + logGlobal->debug("Deleted object %d at %d", id.getNum(), ptrdiff_t(this)); +} MapObjectID CGObjectInstance::getObjGroupIndex() const { diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index e116bf4e6..72839c594 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -181,6 +181,9 @@ CMap::~CMap() for(auto quest : quests) quest.dellNull(); + for(auto artInstance : artInstances) + artInstance.dellNull(); + resetStaticData(); } diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index ac5488e35..9bfe3e96c 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -932,7 +932,7 @@ void SetMovePoints::applyGs(CGameState * gs) const void FoWChange::applyGs(CGameState *gs) { TeamState * team = gs->getPlayerTeam(player); - auto fogOfWarMap = team->fogOfWarMap; + auto & fogOfWarMap = team->fogOfWarMap; for(const int3 & t : tiles) (*fogOfWarMap)[t.z][t.x][t.y] = mode != ETileVisibility::HIDDEN; @@ -1327,7 +1327,7 @@ void TryMoveHero::applyGs(CGameState *gs) gs->map->addBlockVisTiles(h); } - auto fogOfWarMap = gs->getPlayerTeam(h->getOwner())->fogOfWarMap; + auto & fogOfWarMap = gs->getPlayerTeam(h->getOwner())->fogOfWarMap; for(const int3 & t : fowRevealed) (*fogOfWarMap)[t.z][t.x][t.y] = 1; } diff --git a/lib/pathfinder/NodeStorage.cpp b/lib/pathfinder/NodeStorage.cpp index 38936dcf5..67c27fe68 100644 --- a/lib/pathfinder/NodeStorage.cpp +++ b/lib/pathfinder/NodeStorage.cpp @@ -27,7 +27,7 @@ void NodeStorage::initialize(const PathfinderOptions & options, const CGameState int3 pos; const PlayerColor player = out.hero->tempOwner; const int3 sizes = gs->getMapSize(); - const auto fow = static_cast(gs)->getPlayerTeam(player)->fogOfWarMap; + const auto & fow = static_cast(gs)->getPlayerTeam(player)->fogOfWarMap; //make 200% sure that these are loop invariants (also a bit shorter code), let compiler do the rest(loop unswitching) const bool useFlying = options.useFlying; diff --git a/lib/pathfinder/PathfinderUtil.h b/lib/pathfinder/PathfinderUtil.h index 49efd7833..749cc513e 100644 --- a/lib/pathfinder/PathfinderUtil.h +++ b/lib/pathfinder/PathfinderUtil.h @@ -19,11 +19,11 @@ VCMI_LIB_NAMESPACE_BEGIN namespace PathfinderUtil { - using FoW = std::shared_ptr>; + using FoW = std::unique_ptr>; using ELayer = EPathfindingLayer; template - EPathAccessibility evaluateAccessibility(const int3 & pos, const TerrainTile & tinfo, FoW fow, const PlayerColor player, const CGameState * gs) + EPathAccessibility evaluateAccessibility(const int3 & pos, const TerrainTile & tinfo, const FoW & fow, const PlayerColor player, const CGameState * gs) { if(!(*fow)[pos.z][pos.x][pos.y]) return EPathAccessibility::BLOCKED; diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index 1c4858469..0f880baaf 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -292,7 +292,7 @@ public: { typedef typename std::remove_pointer::type npT; typedef typename std::remove_const::type ncpT; - data = ClassObjectCreator::invoke(); + data = ClassObjectCreator::invoke();// !!! ptrAllocated(data, pid); load(*data); } diff --git a/lib/spells/AdventureSpellMechanics.cpp b/lib/spells/AdventureSpellMechanics.cpp index b6b440d02..6e8b02233 100644 --- a/lib/spells/AdventureSpellMechanics.cpp +++ b/lib/spells/AdventureSpellMechanics.cpp @@ -600,7 +600,7 @@ ESpellCastResult ViewMechanics::applyAdventureEffects(SpellCastEnvironment * env const auto spellLevel = parameters.caster->getSpellSchoolLevel(owner); - const auto fowMap = env->getCb()->getPlayerTeam(parameters.caster->getCasterOwner())->fogOfWarMap; + const auto & fowMap = env->getCb()->getPlayerTeam(parameters.caster->getCasterOwner())->fogOfWarMap; for(const CGObjectInstance * obj : env->getMap()->objects) { diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 0d69c0c16..b9011b4db 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -860,7 +860,7 @@ void CGameHandler::onNewTurn() fw.mode = ETileVisibility::REVEALED; fw.player = player; // find all hidden tiles - const auto fow = getPlayerTeam(player)->fogOfWarMap; + const auto & fow = getPlayerTeam(player)->fogOfWarMap; auto shape = fow->shape(); for(size_t z = 0; z < shape[0]; z++)