1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00
- Performance improvements, refactoring
This commit is contained in:
DjWarmonger 2014-02-15 19:39:03 +00:00
parent d8933b5c36
commit b368e565ab
5 changed files with 23 additions and 18 deletions

View File

@ -406,8 +406,7 @@ TGoalVec ClearWayTo::getAllPossibleSubgoals()
h->visitablePos() == tile) //we are already on that tile! what does it mean?
continue;
cb->setSelection(h);
SectorMap sm;
SectorMap sm(h);
int3 tileToHit = sm.firstTileToGet(hero ? hero : h, tile);
//if our hero is trapped, make sure we request clearing the way from OUR perspective
@ -509,10 +508,9 @@ TGoalVec Explore::getAllPossibleSubgoals()
}
for (auto h : heroes)
{
SectorMap sm(h);
for (auto obj : objs) //double loop, performance risk?
{
cb->setSelection(h);
SectorMap sm; //seems to depend on hero
auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
if (t.valid())
{
@ -803,10 +801,9 @@ TGoalVec Conquer::getAllPossibleSubgoals()
for (auto h : cb->getHeroesInfo())
{
SectorMap sm(h);
for (auto obj : objs) //double loop, performance risk?
{
cb->setSelection(h);
SectorMap sm; //seems to depend on hero
auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
if (t.valid())
{

View File

@ -2537,17 +2537,16 @@ void AIStatus::setMove(bool ongoing)
SectorMap::SectorMap()
{
// int3 sizes = cb->getMapSize();
// sector.resize(sizes.x);
// for(auto &i : sector)
// i.resize(sizes.y);
//
// for(auto &i : sector)
// for(auto &j : i)
// j.resize(sizes.z, 0);
update();
}
SectorMap::SectorMap(HeroPtr h)
{
cb->setSelection(h.h);
update();
makeParentBFS(h->visitablePos());
}
bool markIfBlocked(ui8 &sec, crint3 pos, const TerrainTile *t)
{
if(t->blocked && !t->visitable)
@ -2776,7 +2775,6 @@ For ship construction etc, another function (goal?) is needed
*/
{
int3 ret(-1,-1,-1);
cb->setSelection(h.h);
int sourceSector = retreiveTile(h->visitablePos()),
destinationSector = retreiveTile(dst);
@ -2929,7 +2927,6 @@ For ship construction etc, another function (goal?) is needed
}
else
{
makeParentBFS(h->visitablePos());
int3 curtile = dst;
while(curtile != h->visitablePos())
{
@ -2985,8 +2982,11 @@ void SectorMap::makeParentBFS(crint3 source)
{
if(retreiveTile(neighPos) == mySector && !vstd::contains(parent, neighPos))
{
toVisit.push(neighPos);
parent[neighPos] = curPos;
if (cb->canMoveBetween(curPos, neighPos))
{
toVisit.push(neighPos);
parent[neighPos] = curPos;
}
}
});
}

View File

@ -98,6 +98,7 @@ struct SectorMap
std::map<int, Sector> infoOnSectors;
SectorMap();
SectorMap(HeroPtr h);
void update();
void clear();
void exploreNewSector(crint3 pos, int num);

View File

@ -321,6 +321,12 @@ int CCallback::getDistance( int3 tile )
return 255;
}
bool CCallback::canMoveBetween(const int3 &a, const int3 &b)
{
//TODO: merge with Pathfinder::canMoveBetween
return gs->checkForVisitableDir(a, b) && gs->checkForVisitableDir(b, a);
}
bool CCallback::getPath2( int3 dest, CGPath &ret )
{
if (!gs->map->isInTheMap(dest))

View File

@ -110,6 +110,7 @@ public:
virtual const CGPathNode *getPathInfo(int3 tile); //uses main, client pathfinder info
virtual int getDistance(int3 tile);
virtual bool getPath2(int3 dest, CGPath &ret); //uses main, client pathfinder info
virtual bool canMoveBetween(const int3 &a, const int3 &b);
virtual int getMovementCost(const CGHeroInstance * hero, int3 dest);
virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1);