- 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
quadCache.clearCacheData(); if(visibleQuad != quadCache.lastVisibleQuad) {
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,37 +3812,40 @@ VisibleQuadContainerCache & Renderer::getQuadCache(bool updateOnDirtyFrame) {
} }
} }
// Object calculations if(visibleQuad != quadCache.lastVisibleQuad) {
const Map *map= world->getMap(); // Object calculations
PosQuadIterator pqi(map, visibleQuad, Map::cellScale); const Map *map= world->getMap();
while(pqi.next()){ PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
const Vec2i &pos= pqi.getPos(); while(pqi.next()){
if(map->isInside(pos)) { const Vec2i &pos= pqi.getPos();
const Vec2i &mapPos = Map::toSurfCoords(pos); if(map->isInside(pos)) {
const Vec2i &mapPos = Map::toSurfCoords(pos);
//quadCache.visibleCellList.push_back(mapPos); //quadCache.visibleCellList.push_back(mapPos);
SurfaceCell *sc = map->getSurfaceCell(mapPos); SurfaceCell *sc = map->getSurfaceCell(mapPos);
Object *o = sc->getObject(); Object *o = sc->getObject();
bool isExplored = (sc->isExplored(world->getThisTeamIndex()) && o != NULL); bool isExplored = (sc->isExplored(world->getThisTeamIndex()) && o != NULL);
//bool isVisible = (sc->isVisible(thisTeamIndex) && o!=NULL); //bool isVisible = (sc->isVisible(thisTeamIndex) && o!=NULL);
bool isVisible = true; bool isVisible = true;
if(isExplored == true && isVisible == true) { if(isExplored == true && isVisible == true) {
quadCache.visibleObjectList.push_back(o); quadCache.visibleObjectList.push_back(o);
}
} }
} }
}
Quad2i scaledQuad = visibleQuad / Map::cellScale; Quad2i scaledQuad = visibleQuad / Map::cellScale;
PosQuadIterator pqis(map, scaledQuad); PosQuadIterator pqis(map, scaledQuad);
while(pqis.next()) { while(pqis.next()) {
const Vec2i &pos= pqis.getPos(); const Vec2i &pos= pqis.getPos();
if(map->isInside(pos)) { if(map->isInside(pos)) {
quadCache.visibleScaledCellList.push_back(pos); quadCache.visibleScaledCellList.push_back(pos);
}
} }
}
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),