attempt to squeeze a bit more performance

This commit is contained in:
Mark Vejvoda 2013-11-11 18:09:00 +00:00
parent 9625bd77a4
commit c98a09b905
4 changed files with 55 additions and 30 deletions

View File

@ -34,8 +34,10 @@ const float Minimap::exploredAlpha= 0.5f;
Minimap::Minimap() {
fowPixmap0= NULL;
fowPixmap1= NULL;
fowPixmap1_default=NULL;
fowPixmap0Copy = NULL;
fowPixmap1Copy = NULL;
fowPixmap1Copy_default = NULL;
fogOfWar= true;
gameSettings= NULL;
tex=NULL;
@ -63,7 +65,9 @@ void Minimap::init(int w, int h, const World *world, bool fogOfWar) {
fowPixmap0 = new Pixmap2D(potW, potH, 1);
fowPixmap0Copy = new Pixmap2D(potW, potH, 1);
fowPixmap1 = new Pixmap2D(potW, potH, 1);
fowPixmap1_default = new Pixmap2D(potW, potH, 1);
fowPixmap1Copy = new Pixmap2D(potW, potH, 1);
fowPixmap1Copy_default = new Pixmap2D(potW, potH, 1);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -120,8 +124,12 @@ Minimap::~Minimap() {
fowPixmap0Copy = NULL;
delete fowPixmap1;
fowPixmap1=NULL;
delete fowPixmap1_default;
fowPixmap1_default = NULL;
delete fowPixmap1Copy;
fowPixmap1Copy=NULL;
delete fowPixmap1Copy_default;
fowPixmap1Copy_default = NULL;
}
// ==================== set ====================
@ -143,6 +151,15 @@ void Minimap::incFowTextureAlphaSurface(const Vec2i &sPos, float alpha,
}
}
void Minimap::copyFowTexAlphaSurface() {
fowPixmap1_default->copy(fowPixmap1);
fowPixmap1Copy_default->copy(fowPixmap1Copy);
}
void Minimap::restoreFowTexAlphaSurface() {
fowPixmap1->copy(fowPixmap1_default);
fowPixmap1Copy->copy(fowPixmap1Copy_default);
}
void Minimap::setFogOfWar(bool value) {
fogOfWar = value;
resetFowTex();

View File

@ -50,8 +50,10 @@ class Minimap{
private:
Pixmap2D *fowPixmap0;
Pixmap2D *fowPixmap1;
Pixmap2D *fowPixmap1_default;
Pixmap2D *fowPixmap0Copy;
Pixmap2D *fowPixmap1Copy;
Pixmap2D *fowPixmap1Copy_default;
Texture2D *tex;
Texture2D *fowTex; //Fog Of War Texture2D
@ -77,6 +79,9 @@ public:
void copyFowTex();
void restoreFowTex();
void copyFowTexAlphaSurface();
void restoreFowTexAlphaSurface();
void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode);

View File

@ -84,6 +84,8 @@ World::World() {
disableAttackEffects = false;
loadWorldNode = NULL;
cacheFowAlphaTexture = false;
cacheFowAlphaTextureFogOfWarValue = false;
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
@ -160,6 +162,8 @@ void World::endScenario() {
fogOfWarOverride = false;
originalGameFogOfWar = fogOfWar;
fogOfWarSkillTypeValue = -1;
cacheFowAlphaTexture = false;
cacheFowAlphaTextureFogOfWarValue = false;
map.end();
@ -197,6 +201,8 @@ void World::end(){
fogOfWarSkillTypeValue = -1;
map.end();
cacheFowAlphaTexture = false;
cacheFowAlphaTextureFogOfWarValue = false;
//stats will be deleted by BattleEnd
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -2446,14 +2452,6 @@ bool World::showWorldForPlayer(int factionIndex, bool excludeFogOfWarCheck) cons
void World::computeFow() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
//bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
//Chrono chronoPerf;
//char perfBuf[8096]="";
//std::vector<string> perfList;
//if(showPerfStats) chronoPerf.start();
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
Chrono chronoGamePerformanceCounts;
if(this->game) chronoGamePerformanceCounts.start();
@ -2461,16 +2459,21 @@ void World::computeFow() {
if(this->game) this->game->addPerformanceCount("world minimap.resetFowTex",chronoGamePerformanceCounts.getMillis());
// if(showPerfStats) {
// sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
// perfList.push_back(perfBuf);
// }
// reset cells
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
if(this->game) chronoGamePerformanceCounts.start();
// Once we have calculated fog of war texture alpha, they are cached so we
// restore the default texture in one shot for speed
if(cacheFowAlphaTexture == true) {
if(cacheFowAlphaTextureFogOfWarValue != fogOfWar) {
cacheFowAlphaTexture = false;
}
else {
minimap.restoreFowTexAlphaSurface();
}
}
int resetFowAlphaFactionCount = 0;
for(int indexFaction = 0;
indexFaction < GameConstants::maxPlayers + GameConstants::specialFactions;
@ -2483,9 +2486,13 @@ void World::computeFow() {
for(int indexSurfaceW = 0; indexSurfaceW < map.getSurfaceW(); ++indexSurfaceW) {
for(int indexSurfaceH = 0; indexSurfaceH < map.getSurfaceH(); ++indexSurfaceH) {
// set all cells to not visible
map.getSurfaceCell(indexSurfaceW, indexSurfaceH)->setVisible(indexFaction, false);
if(showWorldForFaction == true && resetFowAlphaFactionCount <= 1) {
// reset fog of ware texture alpha values
if(cacheFowAlphaTexture == false &&
showWorldForFaction == true &&
resetFowAlphaFactionCount <= 1) {
const Vec2i surfPos(indexSurfaceW,indexSurfaceH);
//compute max alpha
@ -2501,7 +2508,7 @@ void World::computeFow() {
maxAlpha= 0.3f;
}
//compute alpha
// compute alpha
float alpha = maxAlpha;
minimap.incFowTextureAlphaSurface(surfPos, alpha);
}
@ -2511,13 +2518,17 @@ void World::computeFow() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
}
// Once we have calculated fog of war texture alpha, will we cache it so that we
// can restore it later
if(cacheFowAlphaTexture == false) {
cacheFowAlphaTexture = true;
cacheFowAlphaTextureFogOfWarValue = fogOfWar;
minimap.copyFowTexAlphaSurface();
}
if(this->game) this->game->addPerformanceCount("world reset cells",chronoGamePerformanceCounts.getMillis());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
// if(showPerfStats) {
// sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
// perfList.push_back(perfBuf);
// }
//compute cells
if(this->game) chronoGamePerformanceCounts.start();
@ -2575,17 +2586,6 @@ void World::computeFow() {
}
if(this->game) this->game->addPerformanceCount("world compute cells",chronoGamePerformanceCounts.getMillis());
// if(showPerfStats) {
// sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
// perfList.push_back(perfBuf);
// }
//
// if(showPerfStats && chronoPerf.getMillis() >= 50) {
// for(unsigned int x = 0; x < perfList.size(); ++x) {
// printf("%s",perfList[x].c_str());
// }
// }
}
GameSettings * World::getGameSettingsPtr() {

View File

@ -151,6 +151,9 @@ private:
bool animatedTilesetObjectPosListLoaded;
std::vector<Vec2i> animatedTilesetObjectPosList;
bool cacheFowAlphaTexture;
bool cacheFowAlphaTextureFogOfWarValue;
public:
World();
~World();