diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 59a742b4..a1dc66be 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1315,12 +1315,12 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) { glEnable(GL_COLOR_MATERIAL); glAlphaFunc(GL_GREATER, 0.5f); + int thisTeamIndex= world->getThisTeamIndex(); modelRenderer->begin(true, true, false); - int thisTeamIndex= world->getThisTeamIndex(); PosQuadIterator pqi(map, visibleQuad, Map::cellScale); while(pqi.next()){ - const Vec2i pos= pqi.getPos(); + const Vec2i &pos= pqi.getPos(); if(map->isInside(pos)){ @@ -1329,7 +1329,7 @@ void Renderer::renderObjects(const int renderFps, const int worldFrameCount) { if(sc->isExplored(thisTeamIndex) && o!=NULL){ const Model *objModel= sc->getObject()->getModel(); - Vec3f v= o->getPos(); + const Vec3f &v= o->getConstPos(); //ambient and diffuse color is taken from cell color float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale); diff --git a/source/shared_lib/include/graphics/interpolation.h b/source/shared_lib/include/graphics/interpolation.h index 716345d1..4f571ee1 100644 --- a/source/shared_lib/include/graphics/interpolation.h +++ b/source/shared_lib/include/graphics/interpolation.h @@ -32,6 +32,9 @@ private: //std::map cacheVertices; //std::map cacheNormals; + std::map > cacheVertices; + std::map > cacheNormals; + public: InterpolationData(const Mesh *mesh); ~InterpolationData(); diff --git a/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp index 260df41a..77d9bf07 100644 --- a/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp @@ -215,8 +215,8 @@ void ModelRendererGl::renderMeshNormals(const Mesh *mesh){ glBegin(GL_LINES); for(int i= 0; igetIndexCount(); ++i){ - Vec3f vertex= mesh->getInterpolationData()->getVertices()[mesh->getIndices()[i]]; - Vec3f normal= vertex + mesh->getInterpolationData()->getNormals()[mesh->getIndices()[i]]; + const Vec3f &vertex= mesh->getInterpolationData()->getVertices()[mesh->getIndices()[i]]; + const Vec3f &normal= vertex + mesh->getInterpolationData()->getNormals()[mesh->getIndices()[i]]; glVertex3fv(vertex.ptr()); glVertex3fv(normal.ptr()); diff --git a/source/shared_lib/sources/graphics/interpolation.cpp b/source/shared_lib/sources/graphics/interpolation.cpp index 24cb6869..7155f183 100644 --- a/source/shared_lib/sources/graphics/interpolation.cpp +++ b/source/shared_lib/sources/graphics/interpolation.cpp @@ -39,24 +39,30 @@ InterpolationData::InterpolationData(const Mesh *mesh){ normals= new Vec3f[mesh->getVertexCount()]; } - //cacheVertices.clear(); - //cacheNormals.clear(); + cacheVertices.clear(); + cacheNormals.clear(); } InterpolationData::~InterpolationData(){ delete [] vertices; delete [] normals; -/* - for(std::map::iterator iterVert = cacheVertices.begin(); + + for(std::map >::iterator iterVert = cacheVertices.begin(); iterVert != cacheVertices.end(); iterVert++) { - delete [] iterVert->second; + for(std::map::iterator iterVert2 = iterVert->second.begin(); + iterVert2 != iterVert->second.end(); iterVert2++) { + delete [] iterVert2->second; + } } - for(std::map::iterator iterVert = cacheNormals.begin(); + + for(std::map >::iterator iterVert = cacheNormals.begin(); iterVert != cacheNormals.end(); iterVert++) { - delete [] iterVert->second; + for(std::map::iterator iterVert2 = iterVert->second.begin(); + iterVert2 != iterVert->second.end(); iterVert2++) { + delete [] iterVert2->second; + } } -*/ } void InterpolationData::update(float t, bool cycle){ @@ -71,21 +77,22 @@ void InterpolationData::updateVertices(float t, bool cycle) { uint32 vertexCount= mesh->getVertexCount(); if(frameCount > 1) { -/* - std::string lookupKey = floatToStr(t) + "_" + boolToStr(cycle); - std::map::iterator iterFind = cacheVertices.find(lookupKey); + std::map >::iterator iterFind = cacheVertices.find(t); if(iterFind != cacheVertices.end()) { - for(uint32 j=0; j< vertexCount; ++j){ - vertices[j] = iterFind->second[j]; + std::map::iterator iterFind2 = iterFind->second.find(cycle); + if(iterFind2 != iterFind->second.end()) { + //for(uint32 j=0; j< vertexCount; ++j){ + // vertices[j] = iterFind2->second[j]; + //} + memcpy(vertices,iterFind2->second,sizeof(Vec3f) * vertexCount); + return; } - return; } - else { - cacheVertices[lookupKey] = new Vec3f[vertexCount]; - iterFind = cacheVertices.find(lookupKey); - } -*/ + cacheVertices[t][cycle] = new Vec3f[vertexCount]; + + + const Vec3f *meshVertices= mesh->getVertices(); //misc vars @@ -102,7 +109,8 @@ void InterpolationData::updateVertices(float t, bool cycle) { //interpolate vertices for(uint32 j=0; jsecond[j] = vertices[j]; + + cacheVertices[t][cycle][j] = vertices[j]; } } } @@ -114,20 +122,21 @@ void InterpolationData::updateNormals(float t, bool cycle){ uint32 vertexCount= mesh->getVertexCount(); if(frameCount > 1) { -/* - std::string lookupKey = floatToStr(t) + "_" + boolToStr(cycle); - std::map::iterator iterFind = cacheNormals.find(lookupKey); + + std::map >::iterator iterFind = cacheNormals.find(t); if(iterFind != cacheNormals.end()) { - for(uint32 j=0; jsecond[j]; + std::map::iterator iterFind2 = iterFind->second.find(cycle); + if(iterFind2 != iterFind->second.end()) { + //for(uint32 j=0; j< vertexCount; ++j){ + // normals[j] = iterFind2->second[j]; + //} + memcpy(normals,iterFind2->second,sizeof(Vec3f) * vertexCount); + return; } - return; } - else { - cacheNormals[lookupKey] = new Vec3f[mesh->getVertexCount()]; - iterFind = cacheNormals.find(lookupKey); - } -*/ + cacheNormals[t][cycle] = new Vec3f[vertexCount]; + + const Vec3f *meshNormals= mesh->getNormals(); //misc vars @@ -144,7 +153,8 @@ void InterpolationData::updateNormals(float t, bool cycle){ //interpolate vertices for(uint32 j=0; jsecond[j] = normals[j]; + + cacheNormals[t][cycle][j] = normals[j]; } } }