#include "viewdata.hpp" namespace Terrain { ViewData::ViewData() : mNumEntries(0) , mFrameLastUsed(0) , mChanged(false) , mPersistent(false) { } void ViewData::add(QuadTreeNode *node, bool visible) { unsigned int index = mNumEntries++; if (index+1 > mEntries.size()) mEntries.resize(index+1); Entry& entry = mEntries[index]; if (entry.set(node, visible)) mChanged = true; } unsigned int ViewData::getNumEntries() const { return mNumEntries; } ViewData::Entry &ViewData::getEntry(unsigned int i) { return mEntries[i]; } void ViewData::reset(unsigned int frame) { // clear any unused entries for (unsigned int i=mNumEntries; isetViewer(viewer); mViews[viewer] = vd; return vd; } else return found->second; } ViewData *ViewDataMap::createOrReuseView() { if (mUnusedViews.size()) { ViewData* vd = mUnusedViews.front(); mUnusedViews.pop_front(); return vd; } else { mViewVector.push_back(ViewData()); return &mViewVector.back(); } } void ViewDataMap::clearUnusedViews(unsigned int frame) { for (Map::iterator it = mViews.begin(); it != mViews.end(); ) { ViewData* vd = it->second; if (!vd->getPersistent() && (!vd->getViewer() // if no ref was held, always need to clear to avoid holding a dangling ref. || vd->getFrameLastUsed() + 2 < frame)) { vd->setViewer(NULL); vd->clear(); mUnusedViews.push_back(vd); mViews.erase(it++); } else ++it; } } void ViewDataMap::clear() { mViews.clear(); mUnusedViews.clear(); mViewVector.clear(); } }