- 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
This commit is contained in:
Mark Vejvoda 2010-07-07 18:50:55 +00:00
parent 64705aa786
commit 39ad29ba3d
7 changed files with 132 additions and 190 deletions

View File

@ -166,12 +166,12 @@ void GameCamera::update(){
Quad2i GameCamera::computeVisibleQuad() const {
//
quadCacheLookup lookup(fov, hAng, pos);
string lookupKey = lookup.getString();
std::map<std::string, Quad2i>::const_iterator iterFind = cacheVisibleQuad.find(lookupKey);
if(iterFind != cacheVisibleQuad.end()) {
return iterFind->second;
}
//quadCacheLookup lookup(fov, hAng, pos);
//string lookupKey = lookup.getString();
//std::map<std::string, Quad2i>::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(){

View File

@ -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<RenderEntity> 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<RenderEntity> &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<RenderEntity> vctEntity;
for(int i=0; i<world->getFactionCount(); ++i) {
const Texture2D *teamTexture = world->getFaction(i)->getTexture();
for(int i=0; i<world->getFactionCount(); ++i){
meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture());
for(int j=0; j<world->getFaction(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<const DieSkillType*>(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<int>(-pos.x), 0, static_cast<int>(-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<RenderEntity> vctEntity;
modelRenderer->begin(false, false, false);
glInitNames();
for(int i=0; i<world->getFactionCount(); ++i){
// glPushName(i);
glPushName(i);
for(int j=0; j<world->getFaction(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<RenderEntity> &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();

View File

@ -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);

View File

@ -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; i<fowTex->getPixmap()->getW(); ++i){
for(int j=0; j<fowTex->getPixmap()->getH(); ++j){
if(fogOfWar){
if(fogOfWar && overridefogOfWarValue){
float p0= fowPixmap0->getPixelf(i, j);
float p1= fowPixmap1->getPixelf(i, j);

View File

@ -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; i<getFactionCount(); ++i){
@ -199,7 +196,7 @@ void World::update(){
unitUpdater.updateUnit(getFaction(i)->getUnit(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<getFactionCount(); ++i){
@ -213,7 +210,7 @@ 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());
//food costs
for(int i=0; i<techTree->getResourceTypeCount(); ++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<float>(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<map.getSurfaceW()-2 && surfPos.y<map.getSurfaceH()-2){

View File

@ -110,6 +110,7 @@ protected:
public:
static CURL *curl_handle;
static int DEFAULT_HTTP_TIMEOUT;
SystemFlags();
~SystemFlags();
@ -117,7 +118,7 @@ public:
static void init();
static SystemFlagsType & getSystemSettingType(DebugType type) { return debugLogFileList[type]; }
static size_t httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data);
static std::string getHTTP(std::string URL,CURL *handle=NULL);
static std::string getHTTP(std::string URL,CURL *handle=NULL, int timeOut=-1);
static std::string escapeURL(std::string URL, CURL *handle=NULL);
static CURL *initHTTP();

View File

@ -43,6 +43,7 @@ int SystemFlags::lockFile = -1;
int SystemFlags::lockFileCountIndex = -1;
string SystemFlags::lockfilename = "";
CURL *SystemFlags::curl_handle = NULL;
int SystemFlags::DEFAULT_HTTP_TIMEOUT = 10;
//
static void *myrealloc(void *ptr, size_t size)
@ -83,7 +84,7 @@ std::string SystemFlags::escapeURL(std::string URL, CURL *handle) {
return result;
}
std::string SystemFlags::getHTTP(std::string URL,CURL *handle) {
std::string SystemFlags::getHTTP(std::string URL,CURL *handle,int timeOut) {
if(handle == NULL) {
handle = SystemFlags::curl_handle;
}
@ -117,8 +118,11 @@ std::string SystemFlags::getHTTP(std::string URL,CURL *handle) {
char errbuf[CURL_ERROR_SIZE]="";
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errbuf);
// max 5 seconds to connect to the URL
curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 5);
// max X seconds to connect to the URL
if(timeOut < 0) {
timeOut = SystemFlags::DEFAULT_HTTP_TIMEOUT;
}
curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, timeOut);
/* get contents from the URL */
CURLcode result = curl_easy_perform(handle);