diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 88bd4208..adb5df5c 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -3722,6 +3722,38 @@ void Renderer::setQuadCacheDirty(bool value) { quadCache.cacheIsDirty = value; } +void Renderer::removeObjectFromQuadCache(const Object *o) { + VisibleQuadContainerCache &qCache = getQuadCache(); + for(int visibleIndex = 0; + visibleIndex < qCache.visibleObjectList.size(); ++visibleIndex) { + Object *currentObj = qCache.visibleObjectList[visibleIndex]; + if(currentObj == o) { + qCache.visibleObjectList.erase(qCache.visibleObjectList.begin() + visibleIndex); + break; + } + } +} + +void Renderer::removeUnitFromQuadCache(const Unit *unit) { + VisibleQuadContainerCache &qCache = getQuadCache(); + for(int visibleIndex = 0; + visibleIndex < qCache.visibleQuadUnitList.size(); ++visibleIndex) { + Unit *currentUnit = qCache.visibleQuadUnitList[visibleIndex]; + if(currentUnit == unit) { + qCache.visibleQuadUnitList.erase(qCache.visibleQuadUnitList.begin() + visibleIndex); + break; + } + } + for(int visibleIndex = 0; + visibleIndex < qCache.visibleUnitList.size(); ++visibleIndex) { + Unit *currentUnit = qCache.visibleUnitList[visibleIndex]; + if(currentUnit == unit) { + qCache.visibleUnitList.erase(qCache.visibleUnitList.begin() + visibleIndex); + break; + } + } +} + VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame, bool forceNew) { //forceNew = true; diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 9246bc81..49a168f7 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -373,6 +373,8 @@ public: VisibleQuadContainerCache & getQuadCache(bool updateOnDirtyFrame=true,bool forceNew=false); void setQuadCacheDirty(bool value); + void removeObjectFromQuadCache(const Object *o); + void removeUnitFromQuadCache(const Unit *unit); private: //private misc diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index 0e59b68c..974e7132 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -50,7 +50,8 @@ Object::~Object(){ delete resource; Renderer &renderer= Renderer::getInstance(); - renderer.setQuadCacheDirty(true); + //renderer.setQuadCacheDirty(true); + renderer.removeObjectFromQuadCache(this); } const Model *Object::getModel() const{ diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index cf93a554..3e3d26af 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -286,7 +286,8 @@ Unit::~Unit(){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Renderer &renderer= Renderer::getInstance(); - renderer.setQuadCacheDirty(true); + //renderer.setQuadCacheDirty(true); + renderer.removeUnitFromQuadCache(this); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); }