- attempt to improve explorecells usage when each unit is signalled to move

This commit is contained in:
Mark Vejvoda 2010-09-09 01:44:25 +00:00
parent 3825192e2e
commit 77eadd7710
5 changed files with 44 additions and 5 deletions

View File

@ -45,6 +45,8 @@ Game::Game(Program *program, const GameSettings *gameSettings):
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Unit::setGame(this);
original_updateFps = GameConstants::updateFps;
original_cameraFps = GameConstants::cameraFps;
// GameConstants::updateFps= 20;
@ -129,6 +131,10 @@ Game::~Game(){
GameConstants::cameraFps = original_cameraFps;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Unit::setGame(NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
bool Game::quitTriggered() {

View File

@ -155,6 +155,8 @@ set<Unit*> Unit::livingUnitsp;
// ============================ Constructor & destructor =============================
Game *Unit::game = NULL;
Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing):id(id) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -571,6 +573,9 @@ void Unit::setPos(const Vec2i &pos){
this->pos= pos;
this->meetingPos= pos - Vec2i(1);
// Attempt to improve performance
this->exploreCells();
logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__));
}
@ -1598,6 +1603,28 @@ int Unit::getFrameCount() {
return frameCount;
}
void Unit::exploreCells() {
if(this->isOperative()) {
const Vec2i &newPos = this->getCenteredPos();
int sightRange = this->getType()->getSight();
int teamIndex = this->getTeam();
Chrono chrono;
chrono.start();
if(game == NULL) {
throw runtime_error("game == NULL");
}
else if(game->getWorld() == NULL) {
throw runtime_error("game->getWorld() == NULL");
}
game->getWorld()->exploreCells(newPos, sightRange, teamIndex);
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
}
}
void Unit::logSynchData(string source) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {

View File

@ -45,6 +45,7 @@ class TotalUpgrade;
class UpgradeType;
class Level;
class MorphCommandType;
class Game;
enum CommandResult{
crSuccess,
@ -270,10 +271,14 @@ private:
Vec3f screenPos;
string currentUnitTitle;
static Game *game;
public:
Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
~Unit();
static void setGame(Game *value) { game=value;}
//queries
int getId() const {return id;}
Field getCurrField() const {return currField;}
@ -405,6 +410,8 @@ public:
string getCurrentUnitTitle() const {return currentUnitTitle;}
void setCurrentUnitTitle(string value) { currentUnitTitle = value;}
void exploreCells();
std::string toString() const;
private:

View File

@ -39,7 +39,7 @@ namespace Glest{ namespace Game{
const float World::airHeight= 5.f;
// This limit is to keep RAM use under control while offering better performance.
int MaxExploredCellsLookupItemCache = 7500;
int MaxExploredCellsLookupItemCache = 9500;
time_t ExploredCellsLookupItem::lastDebug = 0;
// ===================== PUBLIC ========================
@ -1139,9 +1139,7 @@ void World::computeFow(int factionIdxToTick) {
Unit *unit= getFaction(i)->getUnit(j);
//exploration
if(unit->isOperative()) {
exploreCells(unit->getCenteredPos(), unit->getType()->getSight(), unit->getTeam());
}
unit->exploreCells();
}
}
}

View File

@ -206,6 +206,8 @@ public:
int getUpdateFps(int factionIndex) const;
bool canTickWorld() const;
void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex);
private:
void initCells(bool fogOfWar);
@ -221,7 +223,6 @@ private:
bool canTickFaction(int factionIdx);
int tickFactionIndex();
void computeFow(int factionIdxToTick=-1);
void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex);
void updateAllFactionUnits();
void underTakeDeadFactionUnits();