1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
This commit is contained in:
DjWarmonger 2016-12-12 21:38:12 +01:00
parent 80d5f7b4a4
commit 27ff9efd4b
4 changed files with 41 additions and 23 deletions

View File

@ -110,6 +110,7 @@ struct TimeCheck
}
};
//TODO: replace with vstd::
struct AtScopeExit
{
std::function<void()> foo;

View File

@ -60,21 +60,11 @@ struct SetGlobalState
#define NET_EVENT_HANDLER SET_GLOBAL_STATE(this)
#define MAKING_TURN SET_GLOBAL_STATE(this)
unsigned char &retreiveTileN(std::vector< std::vector< std::vector<unsigned char> > > &vectors, const int3 &pos)
{
return vectors[pos.x][pos.y][pos.z];
}
const unsigned char &retreiveTileN(const std::vector< std::vector< std::vector<unsigned char> > > &vectors, const int3 &pos)
{
return vectors[pos.x][pos.y][pos.z];
}
void foreach_tile(std::vector< std::vector< std::vector<unsigned char> > > &vectors, std::function<void(unsigned char &in)> foo)
{
for(auto & vector : vectors)
for(auto j = vector.begin(); j != vector.end(); j++)
for(auto & elem : *j)
for (auto & vector : vectors)
for (auto j = vector.begin(); j != vector.end(); j++)
for (auto & elem : *j)
foo(elem);
}
@ -3036,7 +3026,7 @@ SectorMap::SectorMap(HeroPtr h)
makeParentBFS(h->visitablePos());
}
bool SectorMap::markIfBlocked(ui8 &sec, crint3 pos, const TerrainTile *t)
bool SectorMap::markIfBlocked(TSectorID &sec, crint3 pos, const TerrainTile *t)
{
if(t->blocked && !t->visitable)
{
@ -3047,7 +3037,7 @@ bool SectorMap::markIfBlocked(ui8 &sec, crint3 pos, const TerrainTile *t)
return false;
}
bool SectorMap::markIfBlocked(ui8 &sec, crint3 pos)
bool SectorMap::markIfBlocked(TSectorID &sec, crint3 pos)
{
return markIfBlocked(sec, pos, getTile(pos));
}
@ -3055,6 +3045,8 @@ bool SectorMap::markIfBlocked(ui8 &sec, crint3 pos)
void SectorMap::update()
{
visibleTiles = cb->getAllVisibleTiles();
auto shape = visibleTiles->shape();
sector.resize(boost::extents[shape[0]][shape[1]][shape[2]]);
clear();
int curSector = 3; //0 is invisible, 1 is not explored
@ -3071,9 +3063,28 @@ void SectorMap::update()
valid = true;
}
SectorMap::TSectorID &SectorMap::retreiveTileN(SectorMap::TSectorArray &a, const int3 &pos)
{
return a[pos.x][pos.y][pos.z];
}
const SectorMap::TSectorID &SectorMap::retreiveTileN(const SectorMap::TSectorArray &a, const int3 &pos)
{
return a[pos.x][pos.y][pos.z];
}
void SectorMap::clear()
{
sector = cb->getVisibilityMap();
//TODO: rotate to [z][x][y]
//TODO: any magic to automate this?
auto fow = cb->getVisibilityMap();
auto width = fow.size();
auto height = fow.front().size();
auto depth = fow.front().front().size();
for (size_t x = 0; x < width; x++)
for (size_t y = 0; y < height; y++ )
for (size_t z = 0; z < depth; z++)
sector[x][y][z] = fow[x][y][z];
valid = false;
}
@ -3089,7 +3100,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num, CCallback * cbp)
{
int3 curPos = toVisit.front();
toVisit.pop();
ui8 &sec = retreiveTile(curPos);
TSectorID &sec = retreiveTile(curPos);
if(sec == NOT_CHECKED)
{
const TerrainTile *t = getTile(curPos);
@ -3476,7 +3487,7 @@ void SectorMap::makeParentBFS(crint3 source)
{
int3 curPos = toVisit.front();
toVisit.pop();
ui8 &sec = retreiveTile(curPos);
TSectorID &sec = retreiveTile(curPos);
assert(sec == mySector); //consider only tiles from the same sector
UNUSED(sec);
@ -3494,7 +3505,7 @@ void SectorMap::makeParentBFS(crint3 source)
}
}
unsigned char & SectorMap::retreiveTile(crint3 pos)
SectorMap::TSectorID & SectorMap::retreiveTile(crint3 pos)
{
return retreiveTileN(sector, pos);
}

View File

@ -87,9 +87,12 @@ struct SectorMap
}
};
typedef unsigned short TSectorID; //smaller than int to allow -1 value. Max number of sectors 65K should be enough for any proper map.
typedef boost::multi_array<TSectorID, 3> TSectorArray;
bool valid; //some kind of lazy eval
std::map<int3, int3> parent;
std::vector<std::vector<std::vector<unsigned char>>> sector;
TSectorArray sector;
//std::vector<std::vector<std::vector<unsigned char>>> pathfinderSector;
std::map<int, Sector> infoOnSectors;
@ -102,9 +105,11 @@ struct SectorMap
void exploreNewSector(crint3 pos, int num, CCallback * cbp);
void write(crstring fname);
bool markIfBlocked(ui8 &sec, crint3 pos, const TerrainTile *t);
bool markIfBlocked(ui8 &sec, crint3 pos);
unsigned char &retreiveTile(crint3 pos);
bool markIfBlocked(TSectorID &sec, crint3 pos, const TerrainTile *t);
bool markIfBlocked(TSectorID &sec, crint3 pos);
TSectorID &retreiveTile(crint3 pos);
TSectorID &SectorMap::retreiveTileN(TSectorArray &vectors, const int3 &pos);
const TSectorID &SectorMap::retreiveTileN(const TSectorArray &vectors, const int3 &pos);
TerrainTile* getTile(crint3 pos) const;
std::vector<const CGObjectInstance *> getNearbyObjs(HeroPtr h, bool sectorsAround);

View File

@ -62,6 +62,7 @@ struct DLL_LINKAGE TeamState : public CBonusSystemNode
public:
TeamID id; //position in gameState::teams
std::set<PlayerColor> players; // members of this team
//TODO: boost::array, bool if possible
std::vector<std::vector<std::vector<ui8> > > fogOfWarMap; //true - visible, false - hidden
TeamState();