- a few more improvements to rendering cache

This commit is contained in:
Mark Vejvoda
2010-09-10 00:41:51 +00:00
parent 2c1b6b6304
commit 4d9bc556d6
3 changed files with 61 additions and 27 deletions

View File

@@ -3786,9 +3786,17 @@ void Renderer::renderUnitTitles(Font2D *font, Vec3f color) {
VisibleQuadContainerCache & Renderer::getQuadCache(bool updateOnDirtyFrame) { VisibleQuadContainerCache & Renderer::getQuadCache(bool updateOnDirtyFrame) {
if(game != NULL && game->getWorld() != NULL) { if(game != NULL && game->getWorld() != NULL) {
const World *world= game->getWorld(); const World *world= game->getWorld();
if(updateOnDirtyFrame == true && world->getFrameCount() != quadCache.cacheFrame) { if(updateOnDirtyFrame == true &&
(world->getFrameCount() != quadCache.cacheFrame ||
visibleQuad != quadCache.lastVisibleQuad)) {
// Dump cached info // Dump cached info
if(visibleQuad != quadCache.lastVisibleQuad) {
quadCache.clearCacheData(); quadCache.clearCacheData();
}
else {
quadCache.clearVolatileCacheData();
}
// Unit calculations // Unit calculations
for(int i = 0; i < world->getFactionCount(); ++i) { for(int i = 0; i < world->getFactionCount(); ++i) {
@@ -3804,6 +3812,7 @@ VisibleQuadContainerCache & Renderer::getQuadCache(bool updateOnDirtyFrame) {
} }
} }
if(visibleQuad != quadCache.lastVisibleQuad) {
// Object calculations // Object calculations
const Map *map= world->getMap(); const Map *map= world->getMap();
PosQuadIterator pqi(map, visibleQuad, Map::cellScale); PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
@@ -3835,6 +3844,8 @@ VisibleQuadContainerCache & Renderer::getQuadCache(bool updateOnDirtyFrame) {
} }
} }
quadCache.lastVisibleQuad = visibleQuad;
}
quadCache.cacheFrame = world->getFrameCount(); quadCache.cacheFrame = world->getFrameCount();
} }
} }

View File

@@ -153,6 +153,7 @@ protected:
inVisibleUnitList = obj.inVisibleUnitList; inVisibleUnitList = obj.inVisibleUnitList;
//visibleCellList = obj.visibleCellList; //visibleCellList = obj.visibleCellList;
visibleScaledCellList = obj.visibleScaledCellList; visibleScaledCellList = obj.visibleScaledCellList;
lastVisibleQuad = obj.lastVisibleQuad;
} }
public: public:
@@ -172,13 +173,19 @@ public:
//bool operator()(const RenderEntity &lhs,const RenderEntity &rhs) const; //bool operator()(const RenderEntity &lhs,const RenderEntity &rhs) const;
void clearCacheData() { void clearCacheData() {
clearVolatileCacheData();
visibleObjectList.clear(); visibleObjectList.clear();
visibleUnitList.clear();
inVisibleUnitList.clear();
//visibleCellList.clear(); //visibleCellList.clear();
visibleScaledCellList.clear(); visibleScaledCellList.clear();
} }
void clearVolatileCacheData() {
visibleUnitList.clear();
inVisibleUnitList.clear();
}
int cacheFrame; int cacheFrame;
Quad2i lastVisibleQuad;
std::vector<Object *> visibleObjectList; std::vector<Object *> visibleObjectList;
std::vector<Unit *> visibleUnitList; std::vector<Unit *> visibleUnitList;
std::vector<Unit *> inVisibleUnitList; std::vector<Unit *> inVisibleUnitList;

View File

@@ -155,6 +155,22 @@ public:
return false; return false;
} }
bool operator !=(const Quad2<T> &v) const {
if(p[0] != v.p[0]) {
return true;
}
if(p[1] != v.p[1]) {
return true;
}
if(p[2] != v.p[2]) {
return true;
}
if(p[3] != v.p[3]) {
return true;
}
return false;
}
Rect2<T> computeBoundingRect() const{ Rect2<T> computeBoundingRect() const{
return Rect2i( return Rect2i(
min(p[0].x, p[1].x), min(p[0].x, p[1].x),