- small improvement for when units and objects are deleted.

This commit is contained in:
Mark Vejvoda 2010-09-10 19:44:00 +00:00
parent f4e6e8ffd7
commit ab88a2971a
4 changed files with 38 additions and 2 deletions

View File

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

View File

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

View File

@ -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{

View File

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