소스 검색

code review

Laserlicht 1 년 전
부모
커밋
11eaed9fef
3개의 변경된 파일22개의 추가작업 그리고 19개의 파일을 삭제
  1. 9 19
      client/adventureMap/AdventureMapShortcuts.cpp
  2. 11 0
      lib/CGameInfoCallback.cpp
  3. 2 0
      lib/CGameInfoCallback.h

+ 9 - 19
client/adventureMap/AdventureMapShortcuts.cpp

@@ -467,29 +467,19 @@ void AdventureMapShortcuts::search(bool next)
 {
 	// get all relevant objects
 	std::vector<ObjectInstanceID> visitableObjInstances;
-	int3 mapSizes = LOCPLINT->cb->getMapSize();
-	for(int x = 0; x < mapSizes.x; x++)
-		for(int y = 0; y < mapSizes.y; y++)
-			for(int z = 0; z < mapSizes.z; z++)
-				for(auto & obj : LOCPLINT->cb->getVisitableObjs(int3(x, y, z), false))
-					if(obj->ID != MapObjectID::MONSTER && obj->ID != MapObjectID::EVENT && obj->ID != MapObjectID::HERO)
-						visitableObjInstances.push_back(obj->id);
-
-	// count of elements for each group
+	for(auto & obj : LOCPLINT->cb->getAllVisitableObjs())
+		if(obj->ID != MapObjectID::MONSTER && obj->ID != MapObjectID::HERO && obj->ID != MapObjectID::TOWN)
+			visitableObjInstances.push_back(obj->id);
+
+	// count of elements for each group (map is already sorted)
 	std::map<std::string, int> mapObjCount;
 	for(auto & obj : visitableObjInstances)
-		mapObjCount[{ VLC->objtypeh->getObjectName(LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex(), LOCPLINT->cb->getObjInstance(obj)->getObjTypeIndex()) }]++;
+		mapObjCount[{ LOCPLINT->cb->getObjInstance(obj)->getObjectName() }]++;
 
-	// sort by name
+	// convert to vector for indexed access
 	std::vector<std::pair<std::string, int>> textCountList;
 	for (auto itr = mapObjCount.begin(); itr != mapObjCount.end(); ++itr)
 		textCountList.push_back(*itr);
-	std::sort(textCountList.begin(), textCountList.end(),
-		[=](std::pair<std::string, int>& a, std::pair<std::string, int>& b)
-		{
-			return a.first < b.first;
-		}
-	);
 
 	// get pos of last selection
 	int lastSel = 0;
@@ -510,7 +500,7 @@ void AdventureMapShortcuts::search(bool next)
 			// filter for matching objects
 			std::vector<ObjectInstanceID> selVisitableObjInstances;
 			for(auto & obj : visitableObjInstances)
-				if(selObj == VLC->objtypeh->getObjectName(LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex(), LOCPLINT->cb->getObjInstance(obj)->getObjTypeIndex()))
+				if(selObj == LOCPLINT->cb->getObjInstance(obj)->getObjectName())
 					selVisitableObjInstances.push_back(obj);
 			
 			if(searchPos + 1 < selVisitableObjInstances.size() && searchLast == selObj)
@@ -520,7 +510,7 @@ void AdventureMapShortcuts::search(bool next)
 
 			auto objInst = LOCPLINT->cb->getObjInstance(selVisitableObjInstances[searchPos]);
 			owner.centerOnObject(objInst);
-			searchLast = VLC->objtypeh->getObjectName(objInst->getObjGroupIndex(), objInst->getObjTypeIndex());
+			searchLast = objInst->getObjectName();
 		};
 
 	if(next)

+ 11 - 0
lib/CGameInfoCallback.cpp

@@ -479,6 +479,17 @@ std::vector <const CGObjectInstance *> CGameInfoCallback::getVisitableObjs(int3
 
 	return ret;
 }
+
+std::vector<ConstTransitivePtr<CGObjectInstance>> CGameInfoCallback::getAllVisitableObjs() const
+{
+	std::vector<ConstTransitivePtr<CGObjectInstance>> ret;
+	for(auto & obj : gs->map->objects)
+		if(obj->isVisitable() && obj->ID != Obj::EVENT && getTile(obj->pos, false))
+			ret.push_back(obj);
+
+	return ret;
+}
+
 const CGObjectInstance * CGameInfoCallback::getTopObj (int3 pos) const
 {
 	return vstd::backOrNull(getVisitableObjs(pos));

+ 2 - 0
lib/CGameInfoCallback.h

@@ -11,6 +11,7 @@
 
 #include "int3.h"
 #include "ResourceSet.h" // for Res
+#include "ConstTransitivePtr.h"
 
 #define ASSERT_IF_CALLED_WITH_PLAYER if(!getPlayerID()) {logGlobal->error(BOOST_CURRENT_FUNCTION); assert(0);}
 
@@ -189,6 +190,7 @@ public:
 	const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const override;
 	virtual std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos)const;
 	std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true) const override;
+	std::vector<ConstTransitivePtr<CGObjectInstance>> getAllVisitableObjs() const;
 	virtual std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
 	virtual const CGObjectInstance * getTopObj (int3 pos) const;
 	virtual PlayerColor getOwner(ObjectInstanceID heroID) const;