diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index 598be14ad..95ba730b3 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -256,7 +256,7 @@ void AIGateway::heroVisitsTown(const CGHeroInstance * hero, const CGTownInstance NET_EVENT_HANDLER; } -void AIGateway::tileHidden(const std::unordered_set & pos) +void AIGateway::tileHidden(const std::unordered_set & pos) { LOG_TRACE(logAi); NET_EVENT_HANDLER; @@ -264,7 +264,7 @@ void AIGateway::tileHidden(const std::unordered_set & pos) nullkiller->memory->removeInvisibleObjects(myCb.get()); } -void AIGateway::tileRevealed(const std::unordered_set & pos) +void AIGateway::tileRevealed(const std::unordered_set & pos) { LOG_TRACE(logAi); NET_EVENT_HANDLER; diff --git a/AI/Nullkiller/AIGateway.h b/AI/Nullkiller/AIGateway.h index a3115e3e6..491ee29df 100644 --- a/AI/Nullkiller/AIGateway.h +++ b/AI/Nullkiller/AIGateway.h @@ -127,7 +127,7 @@ public: void heroMoved(const TryMoveHero & details, bool verbose = true) override; void heroInGarrisonChange(const CGTownInstance * town) override; void centerView(int3 pos, int focusTime) override; - void tileHidden(const std::unordered_set & pos) override; + void tileHidden(const std::unordered_set & pos) override; void artifactMoved(const ArtifactLocation & src, const ArtifactLocation & dst) override; void artifactAssembled(const ArtifactLocation & al) override; void showTavernWindow(const CGObjectInstance * townOrTavern) override; @@ -142,7 +142,7 @@ public: void heroVisit(const CGHeroInstance * visitor, const CGObjectInstance * visitedObj, bool start) override; void availableArtifactsChanged(const CGBlackMarket * bm = nullptr) override; void heroVisitsTown(const CGHeroInstance * hero, const CGTownInstance * town) override; - void tileRevealed(const std::unordered_set & pos) override; + void tileRevealed(const std::unordered_set & pos) override; void heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID query) override; void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) override; void showRecruitmentDialog(const CGDwelling * dwelling, const CArmedInstance * dst, int level) override; diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index ec14d11c6..059967627 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -268,7 +268,7 @@ void VCAI::heroVisitsTown(const CGHeroInstance * hero, const CGTownInstance * to //moveCreaturesToHero(town); } -void VCAI::tileHidden(const std::unordered_set & pos) +void VCAI::tileHidden(const std::unordered_set & pos) { LOG_TRACE(logAi); NET_EVENT_HANDLER; @@ -277,7 +277,7 @@ void VCAI::tileHidden(const std::unordered_set & pos) clearPathsInfo(); } -void VCAI::tileRevealed(const std::unordered_set & pos) +void VCAI::tileRevealed(const std::unordered_set & pos) { LOG_TRACE(logAi); NET_EVENT_HANDLER; diff --git a/AI/VCAI/VCAI.h b/AI/VCAI/VCAI.h index f4c63ef93..90b6753f3 100644 --- a/AI/VCAI/VCAI.h +++ b/AI/VCAI/VCAI.h @@ -160,7 +160,7 @@ public: void heroMoved(const TryMoveHero & details, bool verbose = true) override; void heroInGarrisonChange(const CGTownInstance * town) override; void centerView(int3 pos, int focusTime) override; - void tileHidden(const std::unordered_set & pos) override; + void tileHidden(const std::unordered_set & pos) override; void artifactMoved(const ArtifactLocation & src, const ArtifactLocation & dst) override; void artifactAssembled(const ArtifactLocation & al) override; void showTavernWindow(const CGObjectInstance * townOrTavern) override; @@ -175,7 +175,7 @@ public: void heroVisit(const CGHeroInstance * visitor, const CGObjectInstance * visitedObj, bool start) override; void availableArtifactsChanged(const CGBlackMarket * bm = nullptr) override; void heroVisitsTown(const CGHeroInstance * hero, const CGTownInstance * town) override; - void tileRevealed(const std::unordered_set & pos) override; + void tileRevealed(const std::unordered_set & pos) override; void heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID query) override; void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) override; void showRecruitmentDialog(const CGDwelling * dwelling, const CArmedInstance * dst, int level) override; diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 9eabb6b80..29cb9bd67 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -327,9 +327,11 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose) CCS->soundh->playSound(hero->getRemovalSound().value()); } - - adventureInt->onMapTileChanged(hero->convertToVisitablePos(details.start)); - adventureInt->onMapTileChanged(hero->convertToVisitablePos(details.end)); + std::unordered_set changedTiles { + hero->convertToVisitablePos(details.start), + hero->convertToVisitablePos(details.end) + }; + adventureInt->onMapTilesChanged(changedTiles); bool directlyAttackingCreature = details.attackedFrom && paths.hasPath(hero) && paths.getPath(hero).endPos() == *details.attackedFrom; @@ -1193,19 +1195,17 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component GH.pushInt(wnd); } -void CPlayerInterface::tileRevealed(const std::unordered_set &pos) +void CPlayerInterface::tileRevealed(const std::unordered_set &pos) { EVENT_HANDLER_CALLED_BY_CLIENT; //FIXME: wait for dialog? Magi hut/eye would benefit from this but may break other areas - for (auto & po : pos) - adventureInt->onMapTileChanged(po); + adventureInt->onMapTilesChanged(pos); } -void CPlayerInterface::tileHidden(const std::unordered_set &pos) +void CPlayerInterface::tileHidden(const std::unordered_set &pos) { EVENT_HANDLER_CALLED_BY_CLIENT; - for (auto & po : pos) - adventureInt->onMapTileChanged(po); + adventureInt->onMapTilesChanged(pos); } void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero) @@ -1377,13 +1377,7 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop) if (sop->what == ObjProperty::OWNER) { const CGObjectInstance * obj = cb->getObj(sop->id); - std::set pos = obj->getBlockedPos(); - for(auto & po : pos) - { - if(cb->isVisible(po)) - adventureInt->onMapTileChanged(po); - } if(obj->ID == Obj::TOWN) { auto town = static_cast(obj); @@ -1394,8 +1388,12 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop) towns -= obj; adventureInt->onTownChanged(town); - adventureInt->onMapTilesChanged(); } + + std::set pos = obj->getBlockedPos(); + std::unordered_set upos(pos.begin(), pos.end()); + adventureInt->onMapTilesChanged(upos); + assert(cb->getTownsInfo().size() == towns.size()); } } @@ -1505,7 +1503,7 @@ void CPlayerInterface::objectRemoved(const CGObjectInstance * obj) void CPlayerInterface::objectRemovedAfter() { EVENT_HANDLER_CALLED_BY_CLIENT; - adventureInt->onMapTilesChanged(); + adventureInt->onMapTilesChanged(boost::none); } void CPlayerInterface::playerBlocked(int reason, bool start) diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index 24490f9dc..c023d676f 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -186,8 +186,8 @@ public: void showThievesGuildWindow (const CGObjectInstance * obj) override; void showQuestLog() override; void advmapSpellCast(const CGHeroInstance * caster, int spellID) override; //called when a hero casts a spell - void tileHidden(const std::unordered_set &pos) override; //called when given tiles become hidden under fog of war - void tileRevealed(const std::unordered_set &pos) override; //called when fog of war disappears from given tiles + void tileHidden(const std::unordered_set &pos) override; //called when given tiles become hidden under fog of war + void tileRevealed(const std::unordered_set &pos) override; //called when fog of war disappears from given tiles void newObject(const CGObjectInstance * obj) override; void availableArtifactsChanged(const CGBlackMarket *bm = nullptr) override; //bm may be nullptr, then artifacts are changed in the global pool (used by merchants in towns) void yourTurn() override; diff --git a/client/Client.h b/client/Client.h index adc5dfaf4..b4a89e089 100644 --- a/client/Client.h +++ b/client/Client.h @@ -235,7 +235,7 @@ public: void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override {}; void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) override {} - void changeFogOfWar(std::unordered_set & tiles, PlayerColor player, bool hide) override {} + void changeFogOfWar(std::unordered_set & tiles, PlayerColor player, bool hide) override {} void setObjProperty(ObjectInstanceID objid, int prop, si64 val) override {} diff --git a/client/adventureMap/CAdventureMapInterface.cpp b/client/adventureMap/CAdventureMapInterface.cpp index 39411b4df..7406a7ccd 100644 --- a/client/adventureMap/CAdventureMapInterface.cpp +++ b/client/adventureMap/CAdventureMapInterface.cpp @@ -989,14 +989,12 @@ void CAdventureMapInterface::startHotSeatWait(PlayerColor Player) state = EGameStates::WAITING; } -void CAdventureMapInterface::onMapTileChanged(const int3 & mapPosition) +void CAdventureMapInterface::onMapTilesChanged(boost::optional> positions) { - minimap->updateTile(mapPosition); -} - -void CAdventureMapInterface::onMapTilesChanged() -{ - minimap->update(); + if (positions) + minimap->updateTiles(*positions); + else + minimap->update(); } void CAdventureMapInterface::onCurrentPlayerChanged(PlayerColor Player) diff --git a/client/adventureMap/CAdventureMapInterface.h b/client/adventureMap/CAdventureMapInterface.h index 8f42c92d3..da4a618d3 100644 --- a/client/adventureMap/CAdventureMapInterface.h +++ b/client/adventureMap/CAdventureMapInterface.h @@ -177,10 +177,7 @@ public: void onCurrentPlayerChanged(PlayerColor Player); /// Called by PlayerInterface when specific map tile changed and must be updated on minimap - void onMapTileChanged(const int3 & mapPosition); - - /// Called by PlayerInterface when unknown number of tiles changed and minimap should redraw - void onMapTilesChanged(); + void onMapTilesChanged( boost::optional > positions); /// Called by PlayerInterface when hero state changed and hero list must be updated void onHeroChanged(const CGHeroInstance * hero); diff --git a/client/adventureMap/CMinimap.cpp b/client/adventureMap/CMinimap.cpp index 92c5e4558..ce9e0e5bc 100644 --- a/client/adventureMap/CMinimap.cpp +++ b/client/adventureMap/CMinimap.cpp @@ -225,10 +225,13 @@ void CMinimap::setAIRadar(bool on) redraw(); } -void CMinimap::updateTile(const int3 &pos) +void CMinimap::updateTiles(std::unordered_set positions) { if(minimap) - minimap->refreshTile(pos); + { + for (auto const & tile : positions) + minimap->refreshTile(tile); + } redraw(); } diff --git a/client/adventureMap/CMinimap.h b/client/adventureMap/CMinimap.h index 2d0b5287a..fa596ed18 100644 --- a/client/adventureMap/CMinimap.h +++ b/client/adventureMap/CMinimap.h @@ -68,6 +68,6 @@ public: void showAll(SDL_Surface * to) override; - void updateTile(const int3 &pos); + void updateTiles(std::unordered_set positions); }; diff --git a/client/adventureMap/MapAudioPlayer.cpp b/client/adventureMap/MapAudioPlayer.cpp index 5d99d5bd0..17e8aeecb 100644 --- a/client/adventureMap/MapAudioPlayer.cpp +++ b/client/adventureMap/MapAudioPlayer.cpp @@ -157,7 +157,7 @@ void MapAudioPlayer::updateAmbientSounds() }; int3 pos = currentSelection->getSightCenter(); - std::unordered_set tiles; + std::unordered_set tiles; LOCPLINT->cb->getVisibleTilesInRange(tiles, pos, CCS->soundh->ambientGetRange(), int3::DIST_CHEBYSHEV); for(int3 tile : tiles) { diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index c5b99e81d..bc619a569 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -935,7 +935,7 @@ bool CGameInfoCallback::isInTheMap(const int3 &pos) const return gs->map->isInTheMap(pos); } -void CGameInfoCallback::getVisibleTilesInRange(std::unordered_set &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula) const +void CGameInfoCallback::getVisibleTilesInRange(std::unordered_set &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula) const { gs->getTilesInRange(tiles, pos, radious, getLocalPlayer(), -1, distanceFormula); } diff --git a/lib/CGameInfoCallback.h b/lib/CGameInfoCallback.h index dfb586f10..6e57fa34a 100644 --- a/lib/CGameInfoCallback.h +++ b/lib/CGameInfoCallback.h @@ -35,7 +35,6 @@ struct SThievesGuildInfo; class CMapHeader; struct TeamState; struct QuestInfo; -struct ShashInt3; class CGameState; class PathfinderConfig; @@ -99,7 +98,7 @@ public: // const TerrainTile * getTile(int3 tile, bool verbose = true) const; // std::shared_ptr> getAllVisibleTiles() const; // bool isInTheMap(const int3 &pos) const; -// void getVisibleTilesInRange(std::unordered_set &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const; +// void getVisibleTilesInRange(std::unordered_set &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const; //town // const CGTownInstance* getTown(ObjectInstanceID objid) const; @@ -194,7 +193,7 @@ public: virtual const TerrainTile * getTile(int3 tile, bool verbose = true) const; virtual std::shared_ptr> getAllVisibleTiles() const; virtual bool isInTheMap(const int3 &pos) const; - virtual void getVisibleTilesInRange(std::unordered_set &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const; + virtual void getVisibleTilesInRange(std::unordered_set &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const; virtual void calculatePaths(const std::shared_ptr & config); virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out); virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const; diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 899307f9f..70d9d976d 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1643,7 +1643,7 @@ void CGameState::initFogOfWar() { if(!obj || !vstd::contains(elem.second.players, obj->tempOwner)) continue; //not a flagged object - std::unordered_set tiles; + std::unordered_set tiles; getTilesInRange(tiles, obj->getSightCenter(), obj->getSightRadius(), obj->tempOwner, 1); for(const int3 & tile : tiles) { diff --git a/lib/CPathfinder.h b/lib/CPathfinder.h index a34d01032..aef8dc2ee 100644 --- a/lib/CPathfinder.h +++ b/lib/CPathfinder.h @@ -548,7 +548,7 @@ public: PATROL_LOCKED = 1, PATROL_RADIUS } patrolState; - std::unordered_set patrolTiles; + std::unordered_set patrolTiles; int turn; PlayerColor owner; diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 557bd5a68..ba4a99cd1 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -63,7 +63,7 @@ void CPrivilegedInfoCallback::getFreeTiles(std::vector & tiles) const } } -void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set & tiles, +void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set & tiles, const int3 & pos, int radious, std::optional player, @@ -100,7 +100,7 @@ void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set & tiles, std::optional Player, int level, MapTerrainFilterMode tileFilterMode) const +void CPrivilegedInfoCallback::getAllTiles(std::unordered_set & tiles, std::optional Player, int level, MapTerrainFilterMode tileFilterMode) const { if(!!Player && *Player >= PlayerColor::PLAYER_LIMIT) { diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index c34c0bf80..28aa95967 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -26,7 +26,6 @@ struct ArtifactLocation; class CCreatureSet; class CStackBasicDescriptor; class CGCreature; -struct ShashInt3; namespace spells { @@ -59,7 +58,7 @@ public: void getFreeTiles(std::vector &tiles) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only revealed - void getTilesInRange(std::unordered_set & tiles, + void getTilesInRange(std::unordered_set & tiles, const int3 & pos, int radious, std::optional player = std::optional(), @@ -67,7 +66,7 @@ public: int3::EDistanceFormula formula = int3::DIST_2D) const; //returns all tiles on given level (-1 - both levels, otherwise number of level) - void getAllTiles(std::unordered_set &tiles, std::optional player = std::optional(), + void getAllTiles(std::unordered_set &tiles, std::optional player = std::optional(), int level = -1, MapTerrainFilterMode tileFilterMode = MapTerrainFilterMode::NONE) const; //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant @@ -136,7 +135,7 @@ public: virtual void sendAndApply(CPackForClient * pack) = 0; virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) = 0; - virtual void changeFogOfWar(std::unordered_set &tiles, PlayerColor player, bool hide) = 0; + virtual void changeFogOfWar(std::unordered_set &tiles, PlayerColor player, bool hide) = 0; virtual void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) = 0; }; diff --git a/lib/IGameEventsReceiver.h b/lib/IGameEventsReceiver.h index 37eb6b15b..e962e9091 100644 --- a/lib/IGameEventsReceiver.h +++ b/lib/IGameEventsReceiver.h @@ -117,8 +117,8 @@ public: virtual void showThievesGuildWindow (const CGObjectInstance * obj){}; virtual void showQuestLog(){}; virtual void advmapSpellCast(const CGHeroInstance * caster, int spellID){}; //called when a hero casts a spell - virtual void tileHidden(const std::unordered_set &pos){}; - virtual void tileRevealed(const std::unordered_set &pos){}; + virtual void tileHidden(const std::unordered_set &pos){}; + virtual void tileRevealed(const std::unordered_set &pos){}; virtual void newObject(const CGObjectInstance * obj){}; //eg. ship built in shipyard virtual void availableArtifactsChanged(const CGBlackMarket *bm = nullptr){}; //bm may be nullptr, then artifacts are changed in the global pool (used by merchants in towns) virtual void centerView (int3 pos, int focusTime){}; diff --git a/lib/NetPacks.h b/lib/NetPacks.h index d9c59e7da..892047280 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -308,7 +308,7 @@ struct DLL_LINKAGE FoWChange : public CPackForClient { void applyGs(CGameState * gs); - std::unordered_set tiles; + std::unordered_set tiles; PlayerColor player; ui8 mode = 0; //mode==0 - hide, mode==1 - reveal bool waitForDialogs = false; @@ -590,7 +590,7 @@ struct DLL_LINKAGE TryMoveHero : public CPackForClient ui32 movePoints = 0; EResult result = FAILED; //uses EResult int3 start, end; //h3m format - std::unordered_set fowRevealed; //revealed tiles + std::unordered_set fowRevealed; //revealed tiles std::optional attackedFrom; // Set when stepping into endangered tile. virtual void visitTyped(ICPackVisitor & visitor) override; diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index ee3495628..aca775d6d 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -915,7 +915,7 @@ void FoWChange::applyGs(CGameState *gs) (*fogOfWarMap)[t.z][t.x][t.y] = mode; if (mode == 0) //do not hide too much { - std::unordered_set tilesRevealed; + std::unordered_set tilesRevealed; for (auto & elem : gs->map->objects) { const CGObjectInstance *o = elem; diff --git a/lib/int3.h b/lib/int3.h index b665ff2db..8d5b51854 100644 --- a/lib/int3.h +++ b/lib/int3.h @@ -182,9 +182,8 @@ public: } }; -//Why not normal function? -struct ShashInt3 -{ +template<> +struct std::hash { size_t operator()(int3 const& pos) const { size_t ret = std::hash()(pos.x); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index b513c4842..fd05b586e 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -7123,11 +7123,11 @@ void CGameHandler::removeAfterVisit(const CGObjectInstance *object) void CGameHandler::changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) { - std::unordered_set tiles; + std::unordered_set tiles; getTilesInRange(tiles, center, radius, player, hide? -1 : 1); if (hide) { - std::unordered_set observedTiles; //do not hide tiles observed by heroes. May lead to disastrous AI problems + std::unordered_set observedTiles; //do not hide tiles observed by heroes. May lead to disastrous AI problems auto p = getPlayerState(player); for (auto h : p->heroes) { @@ -7143,7 +7143,7 @@ void CGameHandler::changeFogOfWar(int3 center, ui32 radius, PlayerColor player, changeFogOfWar(tiles, player, hide); } -void CGameHandler::changeFogOfWar(std::unordered_set &tiles, PlayerColor player, bool hide) +void CGameHandler::changeFogOfWar(std::unordered_set &tiles, PlayerColor player, bool hide) { FoWChange fow; fow.tiles = tiles; diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 487404f8d..77f34cf98 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -200,7 +200,7 @@ public: void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override; void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) override; - void changeFogOfWar(std::unordered_set &tiles, PlayerColor player, bool hide) override; + void changeFogOfWar(std::unordered_set &tiles, PlayerColor player, bool hide) override; void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override;