- performance fix in both pathfinder and debug output when pressing the debug key

This commit is contained in:
Mark Vejvoda 2010-11-02 19:52:20 +00:00
parent 3c7fbd1fd7
commit cb52b4895d
3 changed files with 38 additions and 21 deletions

View File

@ -371,7 +371,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
// This cache stores the units free cell movement calcs during the looping below // This cache stores the units free cell movement calcs during the looping below
std::map<Vec2i,std::map<Vec2i, bool> > localCacheForUnitCellMovement; //std::map<Vec2i,std::map<Vec2i, bool> > localCacheForUnitCellMovement;
int whileLoopCount = 0; int whileLoopCount = 0;
while(nodeLimitReached == false) { while(nodeLimitReached == false) {
whileLoopCount++; whileLoopCount++;
@ -406,17 +406,17 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
Vec2i sucPos= node->pos + Vec2i(i, j); Vec2i sucPos= node->pos + Vec2i(i, j);
bool canUnitMoveToCell = false; bool canUnitMoveToCell = false;
std::map<Vec2i,std::map<Vec2i, bool> >::iterator iterFind = localCacheForUnitCellMovement.find(node->pos); //std::map<Vec2i,std::map<Vec2i, bool> >::iterator iterFind = localCacheForUnitCellMovement.find(node->pos);
if(iterFind != localCacheForUnitCellMovement.end() && //if(iterFind != localCacheForUnitCellMovement.end() &&
iterFind->second.find(sucPos) != iterFind->second.end()) { // iterFind->second.find(sucPos) != iterFind->second.end()) {
canUnitMoveToCell = iterFind->second.find(sucPos)->second; // canUnitMoveToCell = iterFind->second.find(sucPos)->second;
} //}
else { //else {
canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos); canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos);
if(Config::getInstance().getBool("DisableCaching","false") == false) { //if(Config::getInstance().getBool("DisableCaching","false") == false) {
localCacheForUnitCellMovement[node->pos][sucPos] = canUnitMoveToCell; // localCacheForUnitCellMovement[node->pos][sucPos] = canUnitMoveToCell;
} //}
} //}
if(openPos(sucPos) == false && canUnitMoveToCell == true) { if(openPos(sucPos) == false && canUnitMoveToCell == true) {
//if node is not open and canMove then generate another node //if node is not open and canMove then generate another node

View File

@ -313,6 +313,7 @@ void Renderer::initGame(const Game *game){
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__);
this->game= game; this->game= game;
worldToScreenPosCache.clear();
//check gl caps //check gl caps
checkGlOptionalCaps(); checkGlOptionalCaps();
@ -433,7 +434,7 @@ void Renderer::end(){
glDeleteLists(list2d, 1); glDeleteLists(list2d, 1);
} }
void Renderer::endGame(){ void Renderer::endGame() {
game= NULL; game= NULL;
//delete resources //delete resources
@ -447,6 +448,8 @@ void Renderer::endGame(){
} }
glDeleteLists(list3d, 1); glDeleteLists(list3d, 1);
worldToScreenPosCache.clear();
} }
void Renderer::endMenu(){ void Renderer::endMenu(){
@ -1933,10 +1936,10 @@ void Renderer::renderUnits(const int renderFps) {
unit->setScreenPos(computeScreenPosition(unit->getCurrVectorFlat())); unit->setScreenPos(computeScreenPosition(unit->getCurrVectorFlat()));
visibleFrameUnitList.push_back(unit); visibleFrameUnitList.push_back(unit);
if(allowRenderUnitTitles == true) { //if(allowRenderUnitTitles == true) {
// Add to the pending render unit title list // Add to the pending render unit title list
renderUnitTitleList.push_back(std::pair<Unit *,Vec3f>(unit,computeScreenPosition(unit->getCurrVectorFlat())) ); //renderUnitTitleList.push_back(std::pair<Unit *,Vec3f>(unit,computeScreenPosition(unit->getCurrVectorFlat())) );
} //}
} }
if(modelRenderStarted == true) { if(modelRenderStarted == true) {
@ -2016,10 +2019,10 @@ void Renderer::renderUnits(const int renderFps) {
unit->setScreenPos(computeScreenPosition(unit->getCurrVectorFlat())); unit->setScreenPos(computeScreenPosition(unit->getCurrVectorFlat()));
visibleFrameUnitList.push_back(unit); visibleFrameUnitList.push_back(unit);
if(allowRenderUnitTitles == true) { //if(allowRenderUnitTitles == true) {
// Add to the pending render unit title list // Add to the pending render unit title list
renderUnitTitleList.push_back(std::pair<Unit *,Vec3f>(unit,computeScreenPosition(unit->getCurrVectorFlat())) ); //renderUnitTitleList.push_back(std::pair<Unit *,Vec3f>(unit,computeScreenPosition(unit->getCurrVectorFlat())) );
} //}
} }
else else
{ {
@ -2640,6 +2643,9 @@ bool Renderer::computePosition(const Vec2i &screenPos, Vec2i &worldPos){
// This method takes world co-ordinates and translates them to screen co-ords // This method takes world co-ordinates and translates them to screen co-ords
Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) { Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) {
if(worldToScreenPosCache.find(worldPos) != worldToScreenPosCache.end()) {
return worldToScreenPosCache[worldPos];
}
assertGl(); assertGl();
const Metrics &metrics= Metrics::getInstance(); const Metrics &metrics= Metrics::getInstance();
@ -2667,6 +2673,8 @@ Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) {
&screenX, &screenY, &screenZ); &screenX, &screenY, &screenZ);
Vec3f screenPos(screenX,screenY,screenZ); Vec3f screenPos(screenX,screenY,screenZ);
worldToScreenPosCache[worldPos]=screenPos;
return screenPos; return screenPos;
} }
@ -3923,9 +3931,9 @@ Texture2D::Filter Renderer::strToTextureFilter(const string &s){
void Renderer::setAllowRenderUnitTitles(bool value) { void Renderer::setAllowRenderUnitTitles(bool value) {
allowRenderUnitTitles = value; allowRenderUnitTitles = value;
if(allowRenderUnitTitles == false) { //if(allowRenderUnitTitles == false) {
renderUnitTitleList.clear(); //renderUnitTitleList.clear();
} //}
} }
// This method renders titles for units // This method renders titles for units
@ -3943,10 +3951,16 @@ void Renderer::renderUnitTitles(Font2D *font, Vec3f color) {
unitRenderedList[unit->getId()] = true; unitRenderedList[unit->getId()] = true;
} }
else {
string str = unit->getFullName() + " - " + intToStr(unit->getId());
Vec3f screenPos = unit->getScreenPos();
renderText(str, font, color, fabs(screenPos.x) + 5, fabs(screenPos.y) + 5, false);
}
} }
visibleFrameUnitList.clear(); visibleFrameUnitList.clear();
} }
/*
if(renderUnitTitleList.size() > 0) { if(renderUnitTitleList.size() > 0) {
for(int idx = 0; idx < renderUnitTitleList.size(); idx++) { for(int idx = 0; idx < renderUnitTitleList.size(); idx++) {
std::pair<Unit *,Vec3f> &unitInfo = renderUnitTitleList[idx]; std::pair<Unit *,Vec3f> &unitInfo = renderUnitTitleList[idx];
@ -3965,6 +3979,7 @@ void Renderer::renderUnitTitles(Font2D *font, Vec3f color) {
} }
renderUnitTitleList.clear(); renderUnitTitleList.clear();
} }
*/
} }
void Renderer::setQuadCacheDirty(bool value) { void Renderer::setQuadCacheDirty(bool value) {

View File

@ -248,6 +248,8 @@ private:
Mutex saveScreenShotThreadAccessor; Mutex saveScreenShotThreadAccessor;
std::list<std::pair<string,Pixmap2D *> > saveScreenQueue; std::list<std::pair<string,Pixmap2D *> > saveScreenQueue;
std::map<Vec3f,Vec3f> worldToScreenPosCache;
private: private:
Renderer(); Renderer();
~Renderer(); ~Renderer();