From 39ad29ba3d1d2c858670646b561da1aff61d6359 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 7 Jul 2010 18:50:55 +0000 Subject: [PATCH] - attempt to improve rendering speed by rolling back render code to be more like 3.3.4 - added new ini setting to adjust http timeout and set default timeout to 10 seconds now --- source/glest_game/game/game_camera.cpp | 18 +- source/glest_game/graphics/renderer.cpp | 256 +++++++++--------------- source/glest_game/main/main.cpp | 4 + source/glest_game/world/minimap.cpp | 7 +- source/glest_game/world/world.cpp | 24 +-- source/shared_lib/include/util/util.h | 3 +- source/shared_lib/sources/util/util.cpp | 10 +- 7 files changed, 132 insertions(+), 190 deletions(-) diff --git a/source/glest_game/game/game_camera.cpp b/source/glest_game/game/game_camera.cpp index 2b23219f..4850e41c 100644 --- a/source/glest_game/game/game_camera.cpp +++ b/source/glest_game/game/game_camera.cpp @@ -166,12 +166,12 @@ void GameCamera::update(){ Quad2i GameCamera::computeVisibleQuad() const { // - quadCacheLookup lookup(fov, hAng, pos); - string lookupKey = lookup.getString(); - std::map::const_iterator iterFind = cacheVisibleQuad.find(lookupKey); - if(iterFind != cacheVisibleQuad.end()) { - return iterFind->second; - } + //quadCacheLookup lookup(fov, hAng, pos); + //string lookupKey = lookup.getString(); + //std::map::const_iterator iterFind = cacheVisibleQuad.find(lookupKey); + //if(iterFind != cacheVisibleQuad.end()) { + // return iterFind->second; + //} // float nearDist = 20.f; @@ -209,9 +209,9 @@ Quad2i GameCamera::computeVisibleQuad() const { } //cacheVisibleQuad[lookupKey] = Quad2i(p4, p3, p2, p1); - cacheVisibleQuad.insert(std::make_pair(lookupKey,Quad2i(p4, p3, p2, p1))); - return cacheVisibleQuad[lookupKey]; -// return Quad2i(p4, p3, p2, p1); + //cacheVisibleQuad.insert(std::make_pair(lookupKey,Quad2i(p4, p3, p2, p1))); + //return cacheVisibleQuad[lookupKey]; + return Quad2i(p4, p3, p2, p1); } void GameCamera::switchState(){ diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index e4160117..3beef596 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -267,8 +267,6 @@ void Renderer::initGame(const Game *game){ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - if(shadows==sShadowMapping){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1274,7 +1272,7 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) { const World *world= game->getWorld(); const Map *map= world->getMap(); - assertGl(); + assertGl(); const Texture2D *fowTex= world->getMinimap()->getFowTexture(); Vec3f baseFogColor= world->getTileset()->getFogColor()*computeLightColor(world->getTimeFlow()->getTime()); @@ -1293,37 +1291,48 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) { glActiveTexture(baseTexUnit); glEnable(GL_COLOR_MATERIAL); - glAlphaFunc(GL_GREATER, 0.5f); + 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) { - const Vec2i &mapPos = Map::toSurfCoords(pos); - SurfaceCell *sc= map->getSurfaceCell(mapPos.x, mapPos.y); - Object *o= sc->getObject(); - bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL); - //bool isVisible = (sc->isVisible(thisTeamIndex) && o!=NULL); - bool isVisible = true; + const Vec2i pos= pqi.getPos(); + + if(map->isInside(pos)){ + + SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(pos)); + Object *o= sc->getObject(); + if(sc->isExplored(thisTeamIndex) && o!=NULL){ + + const Model *objModel= sc->getObject()->getModel(); + Vec3f v= o->getPos(); + + //ambient and diffuse color is taken from cell color + float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale); + 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(); - if(isExplored == true && isVisible == true) { - const Model *objModel= o->getModel(); - if(objModel != NULL) { - objModel->updateInterpolationData(0.f, true); - } - renderObject(o,mapPos,baseFogColor,worldFrameCount); } } } - //modelRenderer->begin(true, true, false); - //renderObjectList(vctEntity,baseFogColor,renderFps, worldFrameCount); modelRenderer->end(); //restore @@ -1331,71 +1340,6 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) { glPopAttrib(); } -void Renderer::renderObjectList(std::vector &vctEntity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount) { - for(int idx=0; idx < vctEntity.size(); ++idx) { - RenderEntity &entity = vctEntity[idx]; - prepareObjectForRender(entity); - renderObject(entity,baseFogColor,renderFps, worldFrameCount); - } -} - -void Renderer::prepareObjectForRender(RenderEntity &entity) { - Object *o = entity.o; - if(o != NULL) { - const Model *objModel= o->getModel(); - if(objModel != NULL) { - objModel->updateInterpolationData(0.f, true); - } - } - entity.setState(resInterpolated); -} - -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) { - const Model *objModel= o->getModel(); - if(objModel != NULL) { - renderObject(o,mapPos,baseFogColor,worldFrameCount); - entity.setState(resRendered); - } - } -} - -void Renderer::renderObject(Object *o,const Vec2i &mapPos,const Vec3f &baseFogColor,const int worldFrameCount) { - if(o != NULL) { - const Model *objModel= o->getModel(); - if(objModel != NULL) { - //objModel->updateInterpolationData(0.f, true); - - const Vec3f &v= o->getConstPos(); - - //ambient and diffuse color is taken from cell color - const World *world= game->getWorld(); - const Texture2D *fowTex= world->getMinimap()->getFowTexture(); - 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); - - modelRenderer->render(objModel); - o->setLastRenderFrame(worldFrameCount); - - triangleCount+= objModel->getTriangleCount(); - pointCount+= objModel->getVertexCount(); - - glPopMatrix(); - } - } -} - void Renderer::renderWater(){ bool closed= false; @@ -1522,6 +1466,7 @@ void Renderer::renderWater(){ } void Renderer::renderUnits(const int renderFps, const int worldFrameCount) { + Unit *unit; const World *world= game->getWorld(); MeshCallbackTeamColor meshCallbackTeamColor; @@ -1541,27 +1486,55 @@ void Renderer::renderUnits(const int renderFps, const int worldFrameCount) { enableProjectiveTexturing(); } glActiveTexture(baseTexUnit); + modelRenderer->begin(true, true, true, &meshCallbackTeamColor); - std::vector vctEntity; - - for(int i=0; igetFactionCount(); ++i) { - const Texture2D *teamTexture = world->getFaction(i)->getTexture(); + for(int i=0; igetFactionCount(); ++i){ + meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture()); for(int j=0; jgetFaction(i)->getUnitCount(); ++j){ - Unit *unit = world->getFaction(i)->getUnit(j); + 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()); + } + else{ + glEnable(GL_COLOR_MATERIAL); + } + + //render const Model *model= unit->getCurrentModel(); model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive()); - renderUnit(unit,&meshCallbackTeamColor, teamTexture, worldFrameCount); + + modelRenderer->render(model); + triangleCount+= model->getTriangleCount(); + pointCount+= model->getVertexCount(); + + glPopMatrix(); + unit->setVisible(true); } - else { + else + { unit->setVisible(false); } } } - - //modelRenderer->begin(true, true, true, &meshCallbackTeamColor); - //renderUnitList(vctEntity,&meshCallbackTeamColor,renderFps, worldFrameCount); modelRenderer->end(); //restore @@ -2280,9 +2253,11 @@ void Renderer::computeSelected(Selection::UnitContainer &units, const Vec2i &pos void Renderer::renderShadowsToTexture(const int renderFps){ if(shadows==sProjected || shadows==sShadowMapping){ + shadowMapFrame= (shadowMapFrame + 1) % (shadowFrameSkip + 1); if(shadowMapFrame==0){ + assertGl(); glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT | GL_POLYGON_BIT); @@ -2337,6 +2312,7 @@ void Renderer::renderShadowsToTexture(const int renderFps){ Vec3f pos= game->getGameCamera()->getPos(); glTranslatef(static_cast(-pos.x), 0, static_cast(-pos.z)); + } else{ //non directional light @@ -2362,7 +2338,6 @@ void Renderer::renderShadowsToTexture(const int renderFps){ //render 3d renderUnitsFast(); - renderObjectsFast(); //read color buffer @@ -2632,85 +2607,42 @@ void Renderer::renderUnitsFast(){ glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); - //std::vector vctEntity; - modelRenderer->begin(false, false, false); glInitNames(); - for(int i=0; igetFactionCount(); ++i){ -// glPushName(i); + glPushName(i); for(int j=0; jgetFaction(i)->getUnitCount(); ++j){ -// glPushName(j); + glPushName(j); Unit *unit= world->getFaction(i)->getUnit(j); if(world->toRenderUnit(unit, visibleQuad)) { - //Vec2i mapPos = Vec2i(i,j); - //vctEntity.push_back(RenderEntity(retUnitFast,NULL,mapPos,unit)); + glMatrixMode(GL_MODELVIEW); + //debuxar modelo + glPushMatrix(); + + //translate + Vec3f currVec= unit->getCurrVectorFlat(); + glTranslatef(currVec.x, currVec.y, currVec.z); + + //rotate + glRotatef(unit->getRotation(), 0.f, 1.f, 0.f); + + //render const Model *model= unit->getCurrentModel(); - if(model != NULL) { - model->updateInterpolationVertices(unit->getAnimProgress(), unit->isAlive()); - } + model->updateInterpolationVertices(unit->getAnimProgress(), unit->isAlive()); + modelRenderer->render(model); + + glPopMatrix(); - renderUnitFast(unit, i,j); } - //glPopName(); + glPopName(); } -// glPopName(); + glPopName(); } - -// glInitNames(); - -// modelRenderer->begin(false, false, false); -// renderUnitFastList(vctEntity); modelRenderer->end(); - glPopAttrib(); } -void Renderer::renderUnitFastList(std::vector &vctEntity) { - for(int idx=0; idx < vctEntity.size(); ++idx) { - RenderEntity &entity = vctEntity[idx]; - prepareUnitFastForRender(entity); - renderUnitFast(entity); - } -} - -void Renderer::renderUnitFast(RenderEntity &entity) { - Unit *unit = entity.unit; - if(unit != NULL) { - renderUnitFast(unit, entity.mapPos.x,entity.mapPos.y); - entity.setState(resRendered); - } -} - -void Renderer::renderUnitFast(Unit *unit, int x, int y) { - if(unit != NULL) { - glPushName(x); - glPushName(y); - - glMatrixMode(GL_MODELVIEW); - - //debuxar modelo - glPushMatrix(); - - //translate - Vec3f currVec= unit->getCurrVectorFlat(); - glTranslatef(currVec.x, currVec.y, currVec.z); - - //rotate - glRotatef(unit->getRotation(), 0.f, 1.f, 0.f); - - //render - const Model *model= unit->getCurrentModel(); - //model->updateInterpolationVertices(unit->getAnimProgress(), unit->isAlive()); - modelRenderer->render(model); - - glPopMatrix(); - glPopName(); - glPopName(); - } -} - void Renderer::prepareUnitFastForRender(RenderEntity &entity) { if(entity.unit != NULL) { const Model *model= entity.unit->getCurrentModel(); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 24db850b..b18f3cff 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -449,6 +449,10 @@ int glestMain(int argc, char** argv){ if(config.getBool("No2DMouseRendering","false") == false) { showCursor(false); } + if(config.getInt("DEFAULT_HTTP_TIMEOUT",intToStr(SystemFlags::DEFAULT_HTTP_TIMEOUT).c_str()) >= 0) { + SystemFlags::DEFAULT_HTTP_TIMEOUT = config.getInt("DEFAULT_HTTP_TIMEOUT",intToStr(SystemFlags::DEFAULT_HTTP_TIMEOUT).c_str()); + } + bool allowAltEnterFullscreenToggle = config.getBool("AllowAltEnterFullscreenToggle",boolToStr(Window::getAllowAltEnterFullscreenToggle()).c_str()); Window::setAllowAltEnterFullscreenToggle(allowAltEnterFullscreenToggle); diff --git a/source/glest_game/world/minimap.cpp b/source/glest_game/world/minimap.cpp index 350dd230..ddb4b32b 100644 --- a/source/glest_game/world/minimap.cpp +++ b/source/glest_game/world/minimap.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -88,9 +88,12 @@ void Minimap::resetFowTex(){ fowPixmap0= fowPixmap1; fowPixmap1= tmpPixmap; + // Could turn off ONLY fog of war by setting below to false + bool overridefogOfWarValue = fogOfWar; + for(int i=0; igetPixmap()->getW(); ++i){ for(int j=0; jgetPixmap()->getH(); ++j){ - if(fogOfWar){ + if(fogOfWar && overridefogOfWarValue){ float p0= fowPixmap0->getPixelf(i, j); float p1= fowPixmap1->getPixelf(i, j); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 9c5b46e6..f59222a2 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -48,8 +48,6 @@ World::World(){ fogOfWarSmoothing= config.getBool("FogOfWarSmoothing"); fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip"); - bool perfTimerEnabled = SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled; - frameCount= 0; //nextUnitId= 0; @@ -179,19 +177,18 @@ void World::loadScenario(const string &path, Checksum *checksum){ // ==================== misc ==================== void World::update(){ - if(perfTimerEnabled == true) { - chronoPerfTimer.start(); - } + Chrono chrono; + chrono.start(); ++frameCount; //time timeFlow.update(); - if(perfTimerEnabled == true && chronoPerfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chronoPerfTimer.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //water effects waterEffects.update(); - if(perfTimerEnabled == true && chronoPerfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chronoPerfTimer.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //units for(int i=0; igetUnit(j)); } } - if(perfTimerEnabled == true && chronoPerfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chronoPerfTimer.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\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: %lld\n",__FILE__,__FUNCTION__,__LINE__,chronoPerfTimer.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //food costs for(int i=0; igetResourceTypeCount(); ++i){ @@ -224,21 +221,21 @@ void World::update(){ } } } - if(perfTimerEnabled == true && chronoPerfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chronoPerfTimer.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\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(perfTimerEnabled == true && chronoPerfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chronoPerfTimer.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //tick if(frameCount%GameConstants::updateFps==0){ computeFow(); tick(); } - if(perfTimerEnabled == true && chronoPerfTimer.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chronoPerfTimer.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } void World::tick(){ @@ -796,9 +793,10 @@ void World::computeFow(){ //iterate through all cells PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange); while(pci.next()){ - const Vec2i &pos= pci.getPos(); + Vec2i pos= pci.getPos(); Vec2i surfPos= Map::toSurfCoords(pos); + //compute max alpha float maxAlpha; if(surfPos.x>1 && surfPos.y>1 && surfPos.x