- added a cache for compute fog of war
This commit is contained in:
parent
0ef23749b8
commit
5a796444b8
|
@ -252,12 +252,12 @@ void Program::loopWorker() {
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(skipRenderFrameCount <= 0) {
|
//if(skipRenderFrameCount <= 0) {
|
||||||
programState->render();
|
programState->render();
|
||||||
}
|
//}
|
||||||
else {
|
//else {
|
||||||
skipRenderFrameCount--;
|
// skipRenderFrameCount--;
|
||||||
}
|
//}
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
|
|
@ -344,8 +344,8 @@ class NetworkMessageSynchNetworkGameData: public NetworkMessage{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static const int maxStringSize= 100;
|
static const int maxStringSize= 200;
|
||||||
static const int maxFileCRCCount= 500;
|
static const int maxFileCRCCount= 400;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ World::World(){
|
||||||
ExploredCellsLookupItemCache.clear();
|
ExploredCellsLookupItemCache.clear();
|
||||||
ExploredCellsLookupItemCacheTimer.clear();
|
ExploredCellsLookupItemCacheTimer.clear();
|
||||||
ExploredCellsLookupItemCacheTimerCount = 0;
|
ExploredCellsLookupItemCacheTimerCount = 0;
|
||||||
|
FowAlphaCellsLookupItemCache.clear();
|
||||||
|
|
||||||
techTree = NULL;
|
techTree = NULL;
|
||||||
fogOfWarOverride = false;
|
fogOfWarOverride = false;
|
||||||
|
@ -78,6 +79,7 @@ World::~World() {
|
||||||
|
|
||||||
ExploredCellsLookupItemCache.clear();
|
ExploredCellsLookupItemCache.clear();
|
||||||
ExploredCellsLookupItemCacheTimer.clear();
|
ExploredCellsLookupItemCacheTimer.clear();
|
||||||
|
FowAlphaCellsLookupItemCache.clear();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -111,6 +113,7 @@ void World::end(){
|
||||||
|
|
||||||
ExploredCellsLookupItemCache.clear();
|
ExploredCellsLookupItemCache.clear();
|
||||||
ExploredCellsLookupItemCacheTimer.clear();
|
ExploredCellsLookupItemCacheTimer.clear();
|
||||||
|
FowAlphaCellsLookupItemCache.clear();
|
||||||
|
|
||||||
for(int i= 0; i<factions.size(); ++i){
|
for(int i= 0; i<factions.size(); ++i){
|
||||||
factions[i].end();
|
factions[i].end();
|
||||||
|
@ -142,6 +145,7 @@ void World::init(Game *game, bool createUnits){
|
||||||
|
|
||||||
ExploredCellsLookupItemCache.clear();
|
ExploredCellsLookupItemCache.clear();
|
||||||
ExploredCellsLookupItemCacheTimer.clear();
|
ExploredCellsLookupItemCacheTimer.clear();
|
||||||
|
FowAlphaCellsLookupItemCache.clear();
|
||||||
|
|
||||||
this->game = game;
|
this->game = game;
|
||||||
scriptManager= game->getScriptManager();
|
scriptManager= game->getScriptManager();
|
||||||
|
@ -1133,13 +1137,32 @@ void World::computeFow(int factionIdxToTick) {
|
||||||
//compute texture
|
//compute texture
|
||||||
if(fogOfWar) {
|
if(fogOfWar) {
|
||||||
for(int i=0; i<getFactionCount(); ++i) {
|
for(int i=0; i<getFactionCount(); ++i) {
|
||||||
//if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
|
Faction *faction= getFaction(i);
|
||||||
Faction *faction= getFaction(i);
|
if(faction->getTeam() == thisTeamIndex){
|
||||||
if(faction->getTeam() == thisTeamIndex){
|
for(int j=0; j<faction->getUnitCount(); ++j){
|
||||||
for(int j=0; j<faction->getUnitCount(); ++j){
|
const Unit *unit= faction->getUnit(j);
|
||||||
const Unit *unit= faction->getUnit(j);
|
if(unit->isOperative()){
|
||||||
if(unit->isOperative()){
|
int sightRange= unit->getType()->getSight();
|
||||||
int sightRange= unit->getType()->getSight();
|
|
||||||
|
bool foundInCache = false;
|
||||||
|
std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos());
|
||||||
|
if(iterMap != FowAlphaCellsLookupItemCache.end()) {
|
||||||
|
std::map<int, FowAlphaCellsLookupItem>::iterator iterMap2 = iterMap->second.find(sightRange);
|
||||||
|
if(iterMap2 != iterMap->second.end()) {
|
||||||
|
foundInCache = true;
|
||||||
|
|
||||||
|
FowAlphaCellsLookupItem &cellList = iterMap2->second;
|
||||||
|
for(int k = 0; k < cellList.surfPosList.size(); ++k) {
|
||||||
|
Vec2i &surfPos = cellList.surfPosList[k];
|
||||||
|
float &alpha = cellList.alphaList[k];
|
||||||
|
|
||||||
|
minimap.incFowTextureAlphaSurface(surfPos, alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(foundInCache == false) {
|
||||||
|
FowAlphaCellsLookupItem itemCache;
|
||||||
|
|
||||||
//iterate through all cells
|
//iterate through all cells
|
||||||
PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange);
|
PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange);
|
||||||
|
@ -1163,11 +1186,18 @@ void World::computeFow(int factionIdxToTick) {
|
||||||
alpha= clamp(1.f-(dist-sightRange)/(indirectSightRange), 0.f, maxAlpha);
|
alpha= clamp(1.f-(dist-sightRange)/(indirectSightRange), 0.f, maxAlpha);
|
||||||
}
|
}
|
||||||
minimap.incFowTextureAlphaSurface(surfPos, alpha);
|
minimap.incFowTextureAlphaSurface(surfPos, alpha);
|
||||||
|
|
||||||
|
itemCache.surfPosList.push_back(surfPos);
|
||||||
|
itemCache.alphaList.push_back(alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(itemCache.surfPosList.size() > 0) {
|
||||||
|
FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,15 @@ public:
|
||||||
static time_t lastDebug;
|
static time_t lastDebug;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class FowAlphaCellsLookupItem {
|
||||||
|
public:
|
||||||
|
|
||||||
|
std::vector<Vec2i> surfPosList;
|
||||||
|
std::vector<float> alphaList;
|
||||||
|
|
||||||
|
static time_t lastDebug;
|
||||||
|
};
|
||||||
|
|
||||||
class World{
|
class World{
|
||||||
private:
|
private:
|
||||||
typedef vector<Faction> Factions;
|
typedef vector<Faction> Factions;
|
||||||
|
@ -78,6 +87,8 @@ private:
|
||||||
std::map<int,ExploredCellsLookupKey> ExploredCellsLookupItemCacheTimer;
|
std::map<int,ExploredCellsLookupKey> ExploredCellsLookupItemCacheTimer;
|
||||||
int ExploredCellsLookupItemCacheTimerCount;
|
int ExploredCellsLookupItemCacheTimerCount;
|
||||||
|
|
||||||
|
std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > > FowAlphaCellsLookupItemCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int generationArea= 100;
|
static const int generationArea= 100;
|
||||||
static const float airHeight;
|
static const float airHeight;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user