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

View File

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

View File

@ -155,6 +155,22 @@ public:
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{
return Rect2i(
min(p[0].x, p[1].x),