Browse Source

int3 now has proper hasher function

Ivan Savenko 2 years ago
parent
commit
7db67a3101

+ 2 - 2
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<int3, ShashInt3> & pos)
+void AIGateway::tileHidden(const std::unordered_set<int3> & pos)
 {
 	LOG_TRACE(logAi);
 	NET_EVENT_HANDLER;
@@ -264,7 +264,7 @@ void AIGateway::tileHidden(const std::unordered_set<int3, ShashInt3> & pos)
 	nullkiller->memory->removeInvisibleObjects(myCb.get());
 }
 
-void AIGateway::tileRevealed(const std::unordered_set<int3, ShashInt3> & pos)
+void AIGateway::tileRevealed(const std::unordered_set<int3> & pos)
 {
 	LOG_TRACE(logAi);
 	NET_EVENT_HANDLER;

+ 2 - 2
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<int3, ShashInt3> & pos) override;
+	void tileHidden(const std::unordered_set<int3> & 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<int3, ShashInt3> & pos) override;
+	void tileRevealed(const std::unordered_set<int3> & 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;

+ 2 - 2
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<int3, ShashInt3> & pos)
+void VCAI::tileHidden(const std::unordered_set<int3> & pos)
 {
 	LOG_TRACE(logAi);
 	NET_EVENT_HANDLER;
@@ -277,7 +277,7 @@ void VCAI::tileHidden(const std::unordered_set<int3, ShashInt3> & pos)
 	clearPathsInfo();
 }
 
-void VCAI::tileRevealed(const std::unordered_set<int3, ShashInt3> & pos)
+void VCAI::tileRevealed(const std::unordered_set<int3> & pos)
 {
 	LOG_TRACE(logAi);
 	NET_EVENT_HANDLER;

+ 2 - 2
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<int3, ShashInt3> & pos) override;
+	void tileHidden(const std::unordered_set<int3> & 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<int3, ShashInt3> & pos) override;
+	void tileRevealed(const std::unordered_set<int3> & 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;

+ 15 - 17
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<int3> 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<int3, ShashInt3> &pos)
+void CPlayerInterface::tileRevealed(const std::unordered_set<int3> &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<int3, ShashInt3> &pos)
+void CPlayerInterface::tileHidden(const std::unordered_set<int3> &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<int3> pos = obj->getBlockedPos();
 
-		for(auto & po : pos)
-		{
-			if(cb->isVisible(po))
-				adventureInt->onMapTileChanged(po);
-		}
 		if(obj->ID == Obj::TOWN)
 		{
 			auto town = static_cast<const CGTownInstance *>(obj);
@@ -1394,8 +1388,12 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
 				towns -= obj;
 
 			adventureInt->onTownChanged(town);
-			adventureInt->onMapTilesChanged();
 		}
+
+		std::set<int3> pos = obj->getBlockedPos();
+		std::unordered_set<int3> 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)

+ 2 - 2
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<int3, ShashInt3> &pos) override; //called when given tiles become hidden under fog of war
-	void tileRevealed(const std::unordered_set<int3, ShashInt3> &pos) override; //called when fog of war disappears from given tiles
+	void tileHidden(const std::unordered_set<int3> &pos) override; //called when given tiles become hidden under fog of war
+	void tileRevealed(const std::unordered_set<int3> &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;

+ 1 - 1
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<int3, ShashInt3> & tiles, PlayerColor player, bool hide) override {}
+	void changeFogOfWar(std::unordered_set<int3> & tiles, PlayerColor player, bool hide) override {}
 
 	void setObjProperty(ObjectInstanceID objid, int prop, si64 val) override {}
 

+ 5 - 7
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<std::unordered_set<int3>> positions)
 {
-	minimap->updateTile(mapPosition);
-}
-
-void CAdventureMapInterface::onMapTilesChanged()
-{
-	minimap->update();
+	if (positions)
+		minimap->updateTiles(*positions);
+	else
+		minimap->update();
 }
 
 void CAdventureMapInterface::onCurrentPlayerChanged(PlayerColor Player)

+ 1 - 4
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<std::unordered_set<int3> > positions);
 
 	/// Called by PlayerInterface when hero state changed and hero list must be updated
 	void onHeroChanged(const CGHeroInstance * hero);

+ 5 - 2
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<int3> positions)
 {
 	if(minimap)
-		minimap->refreshTile(pos);
+	{
+		for (auto const & tile : positions)
+			minimap->refreshTile(tile);
+	}
 	redraw();
 }
 

+ 1 - 1
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<int3> positions);
 };
 

+ 1 - 1
client/adventureMap/MapAudioPlayer.cpp

@@ -157,7 +157,7 @@ void MapAudioPlayer::updateAmbientSounds()
 	};
 
 	int3 pos = currentSelection->getSightCenter();
-	std::unordered_set<int3, ShashInt3> tiles;
+	std::unordered_set<int3> tiles;
 	LOCPLINT->cb->getVisibleTilesInRange(tiles, pos, CCS->soundh->ambientGetRange(), int3::DIST_CHEBYSHEV);
 	for(int3 tile : tiles)
 	{

+ 1 - 1
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<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula) const
+void CGameInfoCallback::getVisibleTilesInRange(std::unordered_set<int3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula) const
 {
 	gs->getTilesInRange(tiles, pos, radious, getLocalPlayer(), -1, distanceFormula);
 }

+ 2 - 3
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<boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
 //	bool isInTheMap(const int3 &pos) const;
-//	void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
+//	void getVisibleTilesInRange(std::unordered_set<int3> &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<const boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
 	virtual bool isInTheMap(const int3 &pos) const;
-	virtual void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
+	virtual void getVisibleTilesInRange(std::unordered_set<int3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
 	virtual void calculatePaths(const std::shared_ptr<PathfinderConfig> & config);
 	virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out);
 	virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const;

+ 1 - 1
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<int3, ShashInt3> tiles;
+			std::unordered_set<int3> tiles;
 			getTilesInRange(tiles, obj->getSightCenter(), obj->getSightRadius(), obj->tempOwner, 1);
 			for(const int3 & tile : tiles)
 			{

+ 1 - 1
lib/CPathfinder.h

@@ -548,7 +548,7 @@ public:
 		PATROL_LOCKED = 1,
 		PATROL_RADIUS
 	} patrolState;
-	std::unordered_set<int3, ShashInt3> patrolTiles;
+	std::unordered_set<int3> patrolTiles;
 
 	int turn;
 	PlayerColor owner;

+ 2 - 2
lib/IGameCallback.cpp

@@ -63,7 +63,7 @@ void CPrivilegedInfoCallback::getFreeTiles(std::vector<int3> & tiles) const
 	}
 }
 
-void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles,
+void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set<int3> & tiles,
 											  const int3 & pos,
 											  int radious,
 											  std::optional<PlayerColor> player,
@@ -100,7 +100,7 @@ void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set<int3, ShashInt3
 	}
 }
 
-void CPrivilegedInfoCallback::getAllTiles(std::unordered_set<int3, ShashInt3> & tiles, std::optional<PlayerColor> Player, int level, MapTerrainFilterMode tileFilterMode) const
+void CPrivilegedInfoCallback::getAllTiles(std::unordered_set<int3> & tiles, std::optional<PlayerColor> Player, int level, MapTerrainFilterMode tileFilterMode) const
 {
 	if(!!Player && *Player >= PlayerColor::PLAYER_LIMIT)
 	{

+ 3 - 4
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<int3> &tiles) const;
 
 	//mode 1 - only unrevealed tiles; mode 0 - all, mode -1 -  only revealed
-	void getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles,
+	void getTilesInRange(std::unordered_set<int3> & tiles,
 						 const int3 & pos,
 						 int radious,
 						 std::optional<PlayerColor> player = std::optional<PlayerColor>(),
@@ -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<int3, ShashInt3> &tiles, std::optional<PlayerColor> player = std::optional<PlayerColor>(),
+	void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player = std::optional<PlayerColor>(),
 					 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<int3, ShashInt3> &tiles, PlayerColor player, bool hide) = 0;
+	virtual void changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor player, bool hide) = 0;
 	
 	virtual void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) = 0;
 };

+ 2 - 2
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<int3, ShashInt3> &pos){};
-	virtual void tileRevealed(const std::unordered_set<int3, ShashInt3> &pos){};
+	virtual void tileHidden(const std::unordered_set<int3> &pos){};
+	virtual void tileRevealed(const std::unordered_set<int3> &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){};

+ 2 - 2
lib/NetPacks.h

@@ -308,7 +308,7 @@ struct DLL_LINKAGE FoWChange : public CPackForClient
 {
 	void applyGs(CGameState * gs);
 
-	std::unordered_set<int3, struct ShashInt3 > tiles;
+	std::unordered_set<int3> 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<int3, ShashInt3> fowRevealed; //revealed tiles
+	std::unordered_set<int3> fowRevealed; //revealed tiles
 	std::optional<int3> attackedFrom; // Set when stepping into endangered tile.
 
 	virtual void visitTyped(ICPackVisitor & visitor) override;

+ 1 - 1
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<int3, ShashInt3> tilesRevealed;
+		std::unordered_set<int3> tilesRevealed;
 		for (auto & elem : gs->map->objects)
 		{
 			const CGObjectInstance *o = elem;

+ 2 - 3
lib/int3.h

@@ -182,9 +182,8 @@ public:
 	}
 };
 
-//Why not normal function?
-struct ShashInt3
-{
+template<>
+struct std::hash<int3> {
 	size_t operator()(int3 const& pos) const
 	{
 		size_t ret = std::hash<int>()(pos.x);

+ 3 - 3
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<int3, ShashInt3> tiles;
+	std::unordered_set<int3> tiles;
 	getTilesInRange(tiles, center, radius, player, hide? -1 : 1);
 	if (hide)
 	{
-		std::unordered_set<int3, ShashInt3> observedTiles; //do not hide tiles observed by heroes. May lead to disastrous AI problems
+		std::unordered_set<int3> 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<int3, ShashInt3> &tiles, PlayerColor player, bool hide)
+void CGameHandler::changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor player, bool hide)
 {
 	FoWChange fow;
 	fow.tiles = tiles;

+ 1 - 1
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<int3, ShashInt3> &tiles, PlayerColor player, bool hide) override;
+	void changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor player, bool hide) override;
 	
 	void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override;