From c7c9e69567e8dd3744ca0508c912b32150726c3a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 15 Jun 2010 16:27:52 +0000 Subject: [PATCH] - added initial work to better manage rendering (but not yet enabled) - added new commandline parameter: --version - some thread cleanup to try adjusted timings when threads shutdown --- source/glest_game/facilities/game_util.cpp | 2 +- source/glest_game/game/game.cpp | 79 ++- source/glest_game/graphics/renderer.cpp | 528 +++++++++--------- source/glest_game/graphics/renderer.h | 16 +- source/glest_game/main/main.cpp | 16 + source/glest_game/type_instances/object.cpp | 2 +- source/glest_game/type_instances/object.h | 7 +- source/glest_game/type_instances/unit.cpp | 6 +- source/glest_game/type_instances/unit.h | 6 + source/glest_game/types/tech_tree.cpp | 8 +- source/glest_game/world/world.cpp | 9 + .../include/platform/sdl/platform_main.h | 2 +- .../sources/platform/common/base_thread.cpp | 4 +- source/shared_lib/sources/util/util.cpp | 7 +- 14 files changed, 394 insertions(+), 298 deletions(-) diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index 7a8d1b69..7f16a3ac 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.cpp @@ -26,7 +26,7 @@ using namespace Shared::Platform; namespace Glest{ namespace Game{ const string mailString= "contact_game@glest.org"; -const string glestVersionString= "v3.3.5-beta7"; +const string glestVersionString= "v3.3.5-beta7.1"; string getCrashDumpFileName(){ return "glest" + glestVersionString + ".dmp"; diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 780b80e4..6cef4de7 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -33,7 +33,7 @@ using namespace Shared::Platform; namespace Glest{ namespace Game{ // if FPS is less than this we start to skip 3D renders -int MIN_RENDER_FPS_ALLOWED = 15; +//int MIN_RENDER_FPS_ALLOWED = 15; Game *thisGamePtr = NULL; @@ -54,9 +54,9 @@ Game::Game(Program *program, const GameSettings *gameSettings): this->gameSettings= *gameSettings; scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5"); - MIN_RENDER_FPS_ALLOWED = Config::getInstance().getInt("MIN_RENDER_FPS_ALLOWED",intToStr(MIN_RENDER_FPS_ALLOWED).c_str()); + //MIN_RENDER_FPS_ALLOWED = Config::getInstance().getInt("MIN_RENDER_FPS_ALLOWED",intToStr(MIN_RENDER_FPS_ALLOWED).c_str()); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] MIN_RENDER_FPS_ALLOWED = %d\n",__FILE__,__FUNCTION__,__LINE__,MIN_RENDER_FPS_ALLOWED); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] MIN_RENDER_FPS_ALLOWED = %d\n",__FILE__,__FUNCTION__,__LINE__,MIN_RENDER_FPS_ALLOWED); mouseX=0; mouseY=0; @@ -169,7 +169,7 @@ void Game::load(){ // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); if(loadingImageUsed == false){ // try to use a faction related loading screen @@ -249,7 +249,7 @@ void Game::load(){ // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -265,7 +265,7 @@ void Game::load(){ // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -274,7 +274,7 @@ void Game::load(){ // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -286,7 +286,7 @@ void Game::load(){ // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__); @@ -315,19 +315,19 @@ void Game::init() // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); world.init(this, gameSettings.getDefaultUnits()); // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); gui.init(this); // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); chatManager.init(&console, world.getThisTeamIndex()); console.clearStoredLines(); @@ -337,7 +337,7 @@ void Game::init() // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); scriptManager.init(&world, &gameCamera); @@ -360,7 +360,7 @@ void Game::init() // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); //wheather particle systems if(world.getTileset()->getWeather() == wRainy){ @@ -388,7 +388,7 @@ void Game::init() // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); //sounds SoundRenderer &soundRenderer= SoundRenderer::getInstance(); @@ -442,6 +442,8 @@ void Game::update(){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); try { + Chrono chrono; + chrono.start(); // a) Updates non dependent on speed @@ -459,6 +461,8 @@ void Game::update(){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + NetworkManager &networkManager= NetworkManager::getInstance(); //update for(int i=0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //World world.update(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); // Commander commander.updateNetwork(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //Gui gui.update(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //Particle systems @@ -496,6 +504,7 @@ void Game::update(){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.updateParticleManager(rsGame); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__); } @@ -552,9 +561,9 @@ void Game::renderWorker() { //program->getWindow()->makeCurrentGl(); //renderFps++; - if(renderFps >= MIN_RENDER_FPS_ALLOWED) { - render3d(); - } + //if(renderFps >= MIN_RENDER_FPS_ALLOWED) { + render3d(); + //} //if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1048,7 +1057,7 @@ void Game::render3d(){ //shadow map //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); - renderer.renderShadowsToTexture(); + renderer.renderShadowsToTexture(renderFps); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //clear buffers @@ -1072,13 +1081,13 @@ void Game::render3d(){ //units //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); - renderer.renderUnits(); + renderer.renderUnits(renderFps,world.getFrameCount()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //objects //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); chrono.start(); - renderer.renderObjects(); + renderer.renderObjects(renderFps,world.getFrameCount()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); //water @@ -1165,6 +1174,36 @@ void Game::render2d(){ str+= "\n"; str+= "Visible quad area: " + floatToStr(visibleQuad.area()) +"\n"; + int visibleUnitCount = 0; + for(int i=0; i< world.getFactionCount(); ++i){ + for(int j=0; j< world.getFaction(i)->getUnitCount(); ++j){ + Unit *unit = world.getFaction(i)->getUnit(j); + if(world.toRenderUnit(unit, visibleQuad)) { + visibleUnitCount++; + } + } + } + str+= "Visible unit count: " + intToStr(visibleUnitCount) +"\n"; + + int visibleObjectCount = 0; + Map *map= world.getMap(); + int thisTeamIndex= world.getThisTeamIndex(); + PosQuadIterator pqi(map, visibleQuad, Map::cellScale); + while(pqi.next()){ + const Vec2i &pos= pqi.getPos(); + bool isPosVisible = map->isInside(pos.x, pos.y); + if(isPosVisible == true) { + Vec2i mapPos = Map::toSurfCoords(pos); + SurfaceCell *sc= map->getSurfaceCell(mapPos.x, mapPos.y); + Object *o= sc->getObject(); + bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL); + if(isExplored == true) { + visibleObjectCount++; + } + } + } + str+= "Visible object count: " + intToStr(visibleObjectCount) +"\n"; + // resources for(int i=0; i +#include #include "leak_dumper.h" @@ -40,6 +41,24 @@ namespace Glest { namespace Game{ bool MeshCallbackTeamColor::noTeamColors = false; +// if FPS is less than this we start to skip 3D renders +int MIN_RENDER_FPS_ALLOWED = -1; +int MIN_RENDER_LAG_ALLOWED = 1; +int MAX_RENDER_LAG_ITEMCOUNT_ALLOWED = 60; + +bool RenderEntity::operator<(const RenderEntity &rhs) const { + if(this->type == retUnit || this->type == retUnitFast) { + return(this->unit->getLastRenderFrame() < rhs.unit->getLastRenderFrame()); + } + else { + return(this->o->getLastRenderFrame() < rhs.o->getLastRenderFrame()); + } +} + +bool RenderEntity::operator()(const RenderEntity &lhs,const RenderEntity &rhs) const { + return lhs < lhs; +} + void MeshCallbackTeamColor::execute(const Mesh *mesh){ //team color @@ -1244,95 +1263,99 @@ void Renderer::renderSurface(){ assertGl(); } -void Renderer::renderObjects() { - const World *world= game->getWorld(); - const Map *map= world->getMap(); - - assertGl(); - const Texture2D *fowTex= world->getMinimap()->getFowTexture(); - Vec3f baseFogColor= world->getTileset()->getFogColor()*computeLightColor(world->getTimeFlow()->getTime()); - - glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_FOG_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT); - - if(shadows==sShadowMapping){ - glActiveTexture(shadowTexUnit); - glEnable(GL_TEXTURE_2D); - - glBindTexture(GL_TEXTURE_2D, shadowMapHandle); - - static_cast(modelRenderer)->setDuplicateTexCoords(true); - enableProjectiveTexturing(); +void Renderer::renderObjects(const int renderFps, const int worldFrameCount) { + if(renderFps < MIN_RENDER_FPS_ALLOWED) { + renderObjectsFast(); } + else { + const World *world= game->getWorld(); + const Map *map= world->getMap(); - glActiveTexture(baseTexUnit); + assertGl(); + const Texture2D *fowTex= world->getMinimap()->getFowTexture(); + Vec3f baseFogColor= world->getTileset()->getFogColor()*computeLightColor(world->getTimeFlow()->getTime()); - glEnable(GL_COLOR_MATERIAL); - glAlphaFunc(GL_GREATER, 0.5f); + glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_FOG_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT); - //modelRenderer->begin(true, true, false); - int thisTeamIndex= world->getThisTeamIndex(); + if(shadows==sShadowMapping){ + glActiveTexture(shadowTexUnit); + glEnable(GL_TEXTURE_2D); - std::vector vctEntity; + glBindTexture(GL_TEXTURE_2D, shadowMapHandle); - PosQuadIterator pqi(map, visibleQuad, Map::cellScale); - while(pqi.next()){ - const Vec2i &pos= pqi.getPos(); - bool isPosVisible = map->isInside(pos.x, pos.y); - if(isPosVisible == true) { - Vec2i mapPos = Map::toSurfCoords(pos); - SurfaceCell *sc= map->getSurfaceCell(mapPos.x, mapPos.y); - Object *o= sc->getObject(); - bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL); - if(isExplored == true) { + static_cast(modelRenderer)->setDuplicateTexCoords(true); + enableProjectiveTexturing(); + } + glActiveTexture(baseTexUnit); + + glEnable(GL_COLOR_MATERIAL); + glAlphaFunc(GL_GREATER, 0.5f); + + //modelRenderer->begin(true, true, false); + int thisTeamIndex= world->getThisTeamIndex(); + + std::vector vctEntity; + + PosQuadIterator pqi(map, visibleQuad, Map::cellScale); + while(pqi.next()){ + const Vec2i &pos= pqi.getPos(); + bool isPosVisible = map->isInside(pos.x, pos.y); + if(isPosVisible == true) { + Vec2i mapPos = Map::toSurfCoords(pos); + SurfaceCell *sc= map->getSurfaceCell(mapPos.x, mapPos.y); + Object *o= sc->getObject(); + bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL); + if(isExplored == true) { + /* + if(renderFps < MIN_RENDER_FPS_ALLOWED) { + int renderLag = worldFrameCount - o->getLastRenderFrame(); + if(renderLag > MIN_RENDER_LAG_ALLOWED) { + vctEntity.push_back(RenderEntity(retObject,o,mapPos,NULL)); + } + } + else { + */ + vctEntity.push_back(RenderEntity(retObject,o,mapPos,NULL)); + //} + } + } + } + + modelRenderer->begin(true, true, false); + renderObjectList(vctEntity,baseFogColor,renderFps, worldFrameCount); + modelRenderer->end(); + + //restore + static_cast(modelRenderer)->setDuplicateTexCoords(true); + glPopAttrib(); + } +} + +void Renderer::renderObjectList(std::vector &vctEntity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount) { + // Need to do something to manage bad FPS /* - const Model *objModel= o->getModel(); - const Vec3f &v= o->getConstPos(); + if(renderFps < MIN_RENDER_FPS_ALLOWED) { + // Oldest rendered objects go to top + std::sort(vctEntity.begin(), vctEntity.end()); + for(int idx=0; idx < vctEntity.size(); ++idx) { + RenderEntity &entity = vctEntity[idx]; + prepareObjectForRender(entity); + renderObject(entity,baseFogColor,renderFps, worldFrameCount); - //ambient and diffuse color is taken from cell color - //float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale); - float fowFactor= fowTex->getPixmap()->getPixelf(mapPos.x,mapPos.y); - - Vec4f color= Vec4f(Vec3f(fowFactor), 1.f); - glColor4fv(color.ptr()); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (color*ambFactor).ptr()); - glFogfv(GL_FOG_COLOR, (baseFogColor*fowFactor).ptr()); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glTranslatef(v.x, v.y, v.z); - glRotatef(o->getRotation(), 0.f, 1.f, 0.f); - - objModel->updateInterpolationData(0.f, true); - - modelRenderer->render(objModel); - - triangleCount+= objModel->getTriangleCount(); - pointCount+= objModel->getVertexCount(); - - glPopMatrix(); -*/ - - vctEntity.push_back(RenderEntity(retObject,o,mapPos,NULL)); + if(idx >= MAX_RENDER_LAG_ITEMCOUNT_ALLOWED) { + break; } } } - - modelRenderer->begin(true, true, false); - renderObjectList(vctEntity,baseFogColor); - modelRenderer->end(); - - //restore - static_cast(modelRenderer)->setDuplicateTexCoords(true); - glPopAttrib(); -} - -void Renderer::renderObjectList(std::vector &vctEntity,const Vec3f &baseFogColor) { - for(int idx=0; idx < vctEntity.size(); ++idx) { - RenderEntity &entity = vctEntity[idx]; - prepareObjectForRender(entity); - renderObject(entity,baseFogColor); - } + else { +*/ + for(int idx=0; idx < vctEntity.size(); ++idx) { + RenderEntity &entity = vctEntity[idx]; + prepareObjectForRender(entity); + renderObject(entity,baseFogColor,renderFps, worldFrameCount); + } + //} } void Renderer::prepareObjectForRender(RenderEntity &entity) { @@ -1346,7 +1369,7 @@ void Renderer::prepareObjectForRender(RenderEntity &entity) { entity.setState(resInterpolated); } -void Renderer::renderObject(RenderEntity &entity,const Vec3f &baseFogColor) { +void Renderer::renderObject(RenderEntity &entity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount) { Object *o = entity.o; Vec2i &mapPos = entity.mapPos; if(o != NULL) { @@ -1374,6 +1397,7 @@ void Renderer::renderObject(RenderEntity &entity,const Vec3f &baseFogColor) { //objModel->updateInterpolationData(0.f, true); modelRenderer->render(objModel); + o->setLastRenderFrame(worldFrameCount); triangleCount+= objModel->getTriangleCount(); pointCount+= objModel->getVertexCount(); @@ -1510,8 +1534,7 @@ void Renderer::renderWater(){ assertGl(); } -void Renderer::renderUnits(){ - Unit *unit; +void Renderer::renderUnits(const int renderFps, const int worldFrameCount) { const World *world= game->getWorld(); MeshCallbackTeamColor meshCallbackTeamColor; @@ -1535,58 +1558,27 @@ void Renderer::renderUnits(){ std::vector vctEntity; for(int i=0; igetFactionCount(); ++i){ -// meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture()); for(int j=0; jgetFaction(i)->getUnitCount(); ++j){ - unit= world->getFaction(i)->getUnit(j); + Unit *unit = world->getFaction(i)->getUnit(j); if(world->toRenderUnit(unit, visibleQuad)) { - -/* - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - //translate - Vec3f currVec= unit->getCurrVectorFlat(); - glTranslatef(currVec.x, currVec.y, currVec.z); - - //rotate - glRotatef(unit->getRotation(), 0.f, 1.f, 0.f); - glRotatef(unit->getVerticalRotation(), 1.f, 0.f, 0.f); - - //dead alpha - float alpha= 1.0f; - const SkillType *st= unit->getCurrSkill(); - if(st->getClass()==scDie && static_cast(st)->getFade()){ - alpha= 1.0f-unit->getAnimProgress(); - glDisable(GL_COLOR_MATERIAL); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Vec4f(1.0f, 1.0f, 1.0f, alpha).ptr()); + if(renderFps < MIN_RENDER_FPS_ALLOWED) { + int unitRenderLag = worldFrameCount - unit->getLastRenderFrame(); + if(unitRenderLag > MIN_RENDER_LAG_ALLOWED) { + vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,world->getFaction(i)->getTexture())); + } } - else{ - glEnable(GL_COLOR_MATERIAL); + else { + vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,world->getFaction(i)->getTexture())); } - - //render - const Model *model= unit->getCurrentModel(); - model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive()); - - modelRenderer->render(model); - triangleCount+= model->getTriangleCount(); - pointCount+= model->getVertexCount(); - - glPopMatrix(); - unit->setVisible(true); -*/ - - vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,world->getFaction(i)->getTexture())); } - else - { + else if(unit->getVisible() == true){ unit->setVisible(false); } } } modelRenderer->begin(true, true, true, &meshCallbackTeamColor); - renderUnitList(vctEntity,&meshCallbackTeamColor); + renderUnitList(vctEntity,&meshCallbackTeamColor,renderFps, worldFrameCount); modelRenderer->end(); //restore @@ -1597,15 +1589,31 @@ void Renderer::renderUnits(){ assertGl(); } -void Renderer::renderUnitList(std::vector &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor) { - for(int idx=0; idx < vctEntity.size(); ++idx) { - RenderEntity &entity = vctEntity[idx]; - prepareUnitForRender(entity); - renderUnit(entity,meshCallbackTeamColor); +void Renderer::renderUnitList(std::vector &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount) { + // Need to do something to manage bad FPS + if(renderFps < MIN_RENDER_FPS_ALLOWED) { + // Oldest rendered units go to top + std::sort(vctEntity.begin(), vctEntity.end()); + for(int idx=0; idx < vctEntity.size(); ++idx) { + RenderEntity &entity = vctEntity[idx]; + prepareUnitForRender(entity); + renderUnit(entity,meshCallbackTeamColor,renderFps, worldFrameCount); + + if(idx >= MAX_RENDER_LAG_ITEMCOUNT_ALLOWED) { + break; + } + } + } + else { + for(int idx=0; idx < vctEntity.size(); ++idx) { + RenderEntity &entity = vctEntity[idx]; + prepareUnitForRender(entity); + renderUnit(entity,meshCallbackTeamColor,renderFps, worldFrameCount); + } } } -void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor) { +void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount) { Unit *unit = entity.unit; if(unit != NULL) { if(meshCallbackTeamColor != NULL) { @@ -1640,11 +1648,13 @@ void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallba //model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive()); modelRenderer->render(model); + unit->setLastRenderFrame(worldFrameCount); triangleCount+= model->getTriangleCount(); pointCount+= model->getVertexCount(); glPopMatrix(); unit->setVisible(true); + if(allowRenderUnitTitles == true) { // Add to the pending render unit title list renderUnitTitleList.push_back(std::pair(unit,computeScreenPosition(unit->getCurrVectorFlat())) ); @@ -2295,163 +2305,165 @@ void Renderer::computeSelected(Selection::UnitContainer &units, const Vec2i &pos // ==================== shadows ==================== -void Renderer::renderShadowsToTexture(){ +void Renderer::renderShadowsToTexture(const int renderFps){ Chrono chrono; chrono.start(); - if(shadows==sProjected || shadows==sShadowMapping){ + if(renderFps >= MIN_RENDER_FPS_ALLOWED) { + if(shadows==sProjected || shadows==sShadowMapping){ - shadowMapFrame= (shadowMapFrame + 1) % (shadowFrameSkip + 1); + shadowMapFrame= (shadowMapFrame + 1) % (shadowFrameSkip + 1); - if(shadowMapFrame==0){ + if(shadowMapFrame==0){ - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - chrono.start(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + chrono.start(); - assertGl(); + assertGl(); - glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT | GL_POLYGON_BIT); + glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT | GL_POLYGON_BIT); - if(shadows==sShadowMapping){ - glClear(GL_DEPTH_BUFFER_BIT); - } - else{ - float color= 1.0f-shadowAlpha; - glColor3f(color, color, color); - glClearColor(1.f, 1.f, 1.f, 1.f); - glDisable(GL_DEPTH_TEST); - glClear(GL_COLOR_BUFFER_BIT); - } - - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - chrono.start(); - - //clear color buffer - // - //set viewport, we leave one texel always in white to avoid problems - glViewport(1, 1, shadowTextureSize-2, shadowTextureSize-2); - - if(nearestLightPos.w==0.f){ - //directional light - - //light pos - assert(game != NULL); - assert(game->getWorld() != NULL); - const TimeFlow *tf= game->getWorld()->getTimeFlow(); - assert(tf != NULL); - float ang= tf->isDay()? computeSunAngle(tf->getTime()): computeMoonAngle(tf->getTime()); - ang= radToDeg(ang); - - //push and set projection - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - if(game->getGameCamera()->getState()==GameCamera::sGame){ - glOrtho(-35, 5, -15, 15, -1000, 1000); + if(shadows==sShadowMapping){ + glClear(GL_DEPTH_BUFFER_BIT); } else{ - glOrtho(-30, 30, -20, 20, -1000, 1000); + float color= 1.0f-shadowAlpha; + glColor3f(color, color, color); + glClearColor(1.f, 1.f, 1.f, 1.f); + glDisable(GL_DEPTH_TEST); + glClear(GL_COLOR_BUFFER_BIT); } - //push and set modelview - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + chrono.start(); - glRotatef(15, 0, 1, 0); + //clear color buffer + // + //set viewport, we leave one texel always in white to avoid problems + glViewport(1, 1, shadowTextureSize-2, shadowTextureSize-2); - glRotatef(ang, 1, 0, 0); - glRotatef(90, 0, 1, 0); - Vec3f pos= game->getGameCamera()->getPos(); + if(nearestLightPos.w==0.f){ + //directional light - glTranslatef(static_cast(-pos.x), 0, static_cast(-pos.z)); + //light pos + assert(game != NULL); + assert(game->getWorld() != NULL); + const TimeFlow *tf= game->getWorld()->getTimeFlow(); + assert(tf != NULL); + float ang= tf->isDay()? computeSunAngle(tf->getTime()): computeMoonAngle(tf->getTime()); + ang= radToDeg(ang); + + //push and set projection + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + if(game->getGameCamera()->getState()==GameCamera::sGame){ + glOrtho(-35, 5, -15, 15, -1000, 1000); + } + else{ + glOrtho(-30, 30, -20, 20, -1000, 1000); + } + + //push and set modelview + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glRotatef(15, 0, 1, 0); + + glRotatef(ang, 1, 0, 0); + glRotatef(90, 0, 1, 0); + Vec3f pos= game->getGameCamera()->getPos(); + + glTranslatef(static_cast(-pos.x), 0, static_cast(-pos.z)); + + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + chrono.start(); + } + else{ + //non directional light + + //push projection + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluPerspective(150, 1.f, perspNearPlane, perspFarPlane); + + //push modelview + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glRotatef(-90, -1, 0, 0); + glTranslatef(-nearestLightPos.x, -nearestLightPos.y-2, -nearestLightPos.z); + + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + chrono.start(); + } + + if(shadows==sShadowMapping){ + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 0.001f); + + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + chrono.start(); + } + + //render 3d + renderUnitsFast(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + chrono.start(); + + renderObjectsFast(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + chrono.start(); + + //read color buffer + glBindTexture(GL_TEXTURE_2D, shadowMapHandle); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowTextureSize, shadowTextureSize); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); - } - else{ - //non directional light - //push projection + //get elemental matrices + Matrix4f matrix1; + matrix1[0]= 0.5f; matrix1[4]= 0.f; matrix1[8]= 0.f; matrix1[12]= 0.5f; + matrix1[1]= 0.f; matrix1[5]= 0.5f; matrix1[9]= 0.f; matrix1[13]= 0.5f; + matrix1[2]= 0.f; matrix1[6]= 0.f; matrix1[10]= 0.5f; matrix1[14]= 0.5f; + matrix1[3]= 0.f; matrix1[7]= 0.f; matrix1[11]= 0.f; matrix1[15]= 1.f; + + Matrix4f matrix2; + glGetFloatv(GL_PROJECTION_MATRIX, matrix2.ptr()); + + Matrix4f matrix3; + glGetFloatv(GL_MODELVIEW_MATRIX, matrix3.ptr()); + + //pop both matrices + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); - gluPerspective(150, 1.f, perspNearPlane, perspFarPlane); - //push modelview - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - glRotatef(-90, -1, 0, 0); - glTranslatef(-nearestLightPos.x, -nearestLightPos.y-2, -nearestLightPos.z); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + chrono.start(); + + //compute texture matrix + glLoadMatrixf(matrix1.ptr()); + glMultMatrixf(matrix2.ptr()); + glMultMatrixf(matrix3.ptr()); + glGetFloatv(GL_TRANSPOSE_PROJECTION_MATRIX_ARB, shadowMapMatrix.ptr()); + + //pop + glPopMatrix(); + + glPopAttrib(); + + assertGl(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); chrono.start(); } - - if(shadows==sShadowMapping){ - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0f, 0.001f); - - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - chrono.start(); - } - - //render 3d - renderUnitsFast(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - chrono.start(); - - renderObjectsFast(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - chrono.start(); - - //read color buffer - glBindTexture(GL_TEXTURE_2D, shadowMapHandle); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowTextureSize, shadowTextureSize); - - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - chrono.start(); - - //get elemental matrices - Matrix4f matrix1; - matrix1[0]= 0.5f; matrix1[4]= 0.f; matrix1[8]= 0.f; matrix1[12]= 0.5f; - matrix1[1]= 0.f; matrix1[5]= 0.5f; matrix1[9]= 0.f; matrix1[13]= 0.5f; - matrix1[2]= 0.f; matrix1[6]= 0.f; matrix1[10]= 0.5f; matrix1[14]= 0.5f; - matrix1[3]= 0.f; matrix1[7]= 0.f; matrix1[11]= 0.f; matrix1[15]= 1.f; - - Matrix4f matrix2; - glGetFloatv(GL_PROJECTION_MATRIX, matrix2.ptr()); - - Matrix4f matrix3; - glGetFloatv(GL_MODELVIEW_MATRIX, matrix3.ptr()); - - //pop both matrices - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - chrono.start(); - - //compute texture matrix - glLoadMatrixf(matrix1.ptr()); - glMultMatrixf(matrix2.ptr()); - glMultMatrixf(matrix3.ptr()); - glGetFloatv(GL_TRANSPOSE_PROJECTION_MATRIX_ARB, shadowMapMatrix.ptr()); - - //pop - glPopMatrix(); - - glPopAttrib(); - - assertGl(); - - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - chrono.start(); } } @@ -2779,7 +2791,7 @@ void Renderer::prepareUnitFastForRender(RenderEntity &entity) { } //render objects for selection purposes -void Renderer::renderObjectsFast(){ +void Renderer::renderObjectsFast() { const World *world= game->getWorld(); const Map *map= world->getMap(); diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 71f58392..da287ec5 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -144,6 +144,8 @@ public: CopyAll(obj); return *this; } + bool operator<(const RenderEntity &rhs) const; + bool operator()(const RenderEntity &lhs,const RenderEntity &rhs) const; RenderEntityType type; Object *o; @@ -332,16 +334,16 @@ public: //complex rendering void renderSurface(); - void renderObjects(); - void renderObject(RenderEntity &entity,const Vec3f &baseFogColor); + void renderObjects(const int renderFps, const int worldFrameCount); + void renderObject(RenderEntity &entity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount); void prepareObjectForRender(RenderEntity &entity); - void renderObjectList(std::vector &vctEntity,const Vec3f &baseFogColor); + void renderObjectList(std::vector &vctEntity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount); void renderWater(); - void renderUnits(); + void renderUnits(const int renderFps, const int worldFrameCount); void prepareUnitForRender(RenderEntity &entity); - void renderUnitList(std::vector &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor); - void renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor); + void renderUnitList(std::vector &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount); + void renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount); void renderSelectionEffects(); void renderWaterEffects(); @@ -363,7 +365,7 @@ public: void clearZBuffer(); //shadows - void renderShadowsToTexture(); + void renderShadowsToTexture(const int renderFps); //misc void loadConfig(); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index cce142b0..74423c24 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -265,6 +265,18 @@ void MainWindow::setProgram(Program *program) { // ===================================================== SystemFlags debugger; +bool hasCommandArgument(int argc, char** argv,string argName) { + bool result = false; + + for(int idx = 1; idx < argc; idx++) { + if(stricmp(argName.c_str(),argv[idx]) == 0) { + result = true; + break; + } + } + return result; +} + int glestMain(int argc, char** argv){ #ifdef SL_LEAK_DUMP @@ -279,6 +291,10 @@ int glestMain(int argc, char** argv){ printf("%s, STREFLOP NOT enabled.\n",getNetworkVersionString().c_str()); #endif + if(hasCommandArgument(argc, argv,"--version") == true) { + return -1; + } + SystemFlags::init(); SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled = true; SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = true; diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index 57cdf33a..4fafcc83 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -34,7 +34,7 @@ Object::Object(ObjectType *objectType, const Vec3f &pos){ RandomGen random; random.init(static_cast(pos.x*pos.z)); - + this->lastRenderFrame = 0; this->objectType= objectType; resource= NULL; this->pos= pos + Vec3f(random.randRange(-0.6f, 0.6f), 0.0f, random.randRange(-0.6f, 0.6f)); diff --git a/source/glest_game/type_instances/object.h b/source/glest_game/type_instances/object.h index a77ef8d4..7e4e7138 100644 --- a/source/glest_game/type_instances/object.h +++ b/source/glest_game/type_instances/object.h @@ -30,13 +30,14 @@ using Shared::Graphics::Vec3f; /// A map object: tree, stone... // ===================================================== -class Object{ +class Object { private: ObjectType *objectType; Resource *resource; Vec3f pos; float rotation; int variation; + int lastRenderFrame; public: Object(ObjectType *objectType, const Vec3f &pos); @@ -53,6 +54,10 @@ public: bool getWalkable() const; void setResource(const ResourceType *resourceType, const Vec2i &pos); + + int getLastRenderFrame() const { return lastRenderFrame; } + void setLastRenderFrame(int value) { lastRenderFrame = value; } + }; }}//end namespace diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 672afd7b..12cc4cb0 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -147,6 +147,8 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map this->targetField = fLand; this->targetVec = Vec3f(0.0); this->targetPos = Vec2i(0); + this->lastRenderFrame = 0; + this->visible = true; level= NULL; loadType= NULL; @@ -544,7 +546,9 @@ void Unit::setTargetPos(const Vec2i &targetPos){ logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__)); } -void Unit::setVisible(const bool visible){ +void Unit::setVisible(const bool visible) { + this->visible = visible; + for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it!=unitParticleSystems.end(); ++it){ (*it)->setVisible(visible); } diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index ea3b6a93..34735766 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -197,6 +197,8 @@ private: CardinalDir modelFacing; std::string lastSynchDataString; + int lastRenderFrame; + bool visible; public: Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing); @@ -270,6 +272,7 @@ public: void setTargetVec(const Vec3f &targetVec); void setMeetingPos(const Vec2i &meetingPos); void setVisible(const bool visible); + bool getVisible() const { return visible; } //render related const Model *getCurrentModel() const; @@ -317,6 +320,9 @@ public: bool isMeetingPointSettable() const; + int getLastRenderFrame() const { return lastRenderFrame; } + void setLastRenderFrame(int value) { lastRenderFrame = value; } + std::string toString() const; private: diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index f905f974..1c275b35 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -68,7 +68,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); //load tech tree xml info try{ @@ -91,7 +91,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); //armor types const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types"); @@ -119,7 +119,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); //load factions str= dir+"/factions/*."; @@ -139,7 +139,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum // give CPU time to update other things to avoid apperance of hanging sleep(0); - SDL_PumpEvents(); + //SDL_PumpEvents(); } } diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 5b97a456..cf40a5c6 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -178,14 +178,18 @@ void World::loadScenario(const string &path, Checksum *checksum){ // ==================== misc ==================== void World::update(){ + Chrono chrono; + chrono.start(); ++frameCount; //time timeFlow.update(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //water effects waterEffects.update(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //units for(int i=0; igetUnit(j)); } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //undertake the dead for(int i=0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //food costs for(int i=0; igetResourceTypeCount(); ++i){ @@ -216,18 +222,21 @@ void World::update(){ } } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //fow smoothing if(fogOfWarSmoothing && ((frameCount+1) % (fogOfWarSmoothingFrameSkip+1))==0){ float fogFactor= static_cast(frameCount%GameConstants::updateFps)/GameConstants::updateFps; minimap.updateFowTex(clamp(fogFactor, 0.f, 1.f)); } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //tick if(frameCount%GameConstants::updateFps==0){ computeFow(); tick(); } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } void World::tick(){ diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index a000b680..697b230c 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -15,7 +15,7 @@ #include #define MAIN_FUNCTION(X) int main(int argc, char **argv) \ -{ std::cout << "About to init SDL..." << "\n"; \ +{ \ if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { \ std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n"; \ return 1; \ diff --git a/source/shared_lib/sources/platform/common/base_thread.cpp b/source/shared_lib/sources/platform/common/base_thread.cpp index 53530cbc..53cd5f85 100644 --- a/source/shared_lib/sources/platform/common/base_thread.cpp +++ b/source/shared_lib/sources/platform/common/base_thread.cpp @@ -97,11 +97,13 @@ void BaseThread::shutdownAndWait(BaseThread *pThread) { if(pThread->getRunningStatus() == false) { break; } - sleep(0); + sleep(1); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } + sleep(1); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } + sleep(0); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 22d6ee00..0d5f464f 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -152,9 +152,8 @@ SystemFlags::~SystemFlags() { } void SystemFlags::Close() { - printf("START Closing logfiles\n"); - if(SystemFlags::debugLogFileList.size() > 0) { + printf("START Closing logfiles\n"); for(std::map::iterator iterMap = SystemFlags::debugLogFileList.begin(); iterMap != SystemFlags::debugLogFileList.end(); iterMap++) { SystemFlags::SystemFlagsType ¤tDebugLog = iterMap->second; @@ -176,7 +175,9 @@ void SystemFlags::Close() { } } - printf("END Closing logfiles\n"); + if(SystemFlags::debugLogFileList.size() > 0) { + printf("END Closing logfiles\n"); + } } void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {