2017-03-08 21:16:03 +00:00
# ifndef OPENMW_COMPONENTS_TERRAIN_VIEWDATA_H
# define OPENMW_COMPONENTS_TERRAIN_VIEWDATA_H
# include <vector>
# include <deque>
# include <osg/Node>
2017-03-09 03:17:25 +00:00
# include "world.hpp"
2017-03-08 21:16:03 +00:00
namespace Terrain
{
class QuadTreeNode ;
2017-03-09 03:17:25 +00:00
class ViewData : public View
2017-03-08 21:16:03 +00:00
{
public :
ViewData ( ) ;
2017-03-09 03:17:25 +00:00
~ ViewData ( ) ;
2017-03-08 21:16:03 +00:00
2019-02-20 13:37:00 +00:00
void add ( QuadTreeNode * node ) ;
2017-03-08 21:16:03 +00:00
2019-02-20 13:37:00 +00:00
void reset ( ) ;
2017-03-08 21:16:03 +00:00
void clear ( ) ;
2017-03-08 23:45:31 +00:00
bool contains ( QuadTreeNode * node ) ;
2019-02-20 13:37:00 +00:00
void copyFrom ( const ViewData & other ) ;
2017-03-08 21:16:03 +00:00
struct Entry
{
Entry ( ) ;
2019-02-20 13:37:00 +00:00
bool set ( QuadTreeNode * node ) ;
2017-03-08 21:16:03 +00:00
QuadTreeNode * mNode ;
2017-03-09 03:14:07 +00:00
unsigned int mLodFlags ;
2017-03-08 21:16:03 +00:00
osg : : ref_ptr < osg : : Node > mRenderingNode ;
} ;
unsigned int getNumEntries ( ) const ;
Entry & getEntry ( unsigned int i ) ;
2019-03-21 13:50:49 +00:00
double getLastUsageTimeStamp ( ) const { return mLastUsageTimeStamp ; }
void setLastUsageTimeStamp ( double timeStamp ) { mLastUsageTimeStamp = timeStamp ; }
2017-03-08 21:16:03 +00:00
2017-03-09 03:14:07 +00:00
/// @return Have any nodes changed since the last frame
bool hasChanged ( ) const ;
2019-03-21 13:50:49 +00:00
void markUnchanged ( ) { mChanged = false ; }
2017-03-09 03:14:07 +00:00
2019-02-20 13:37:00 +00:00
bool hasViewPoint ( ) const ;
2017-07-19 11:11:44 +00:00
2019-02-20 13:37:00 +00:00
void setViewPoint ( const osg : : Vec3f & viewPoint ) ;
const osg : : Vec3f & getViewPoint ( ) const ;
2017-07-19 11:11:44 +00:00
2017-03-08 21:16:03 +00:00
private :
std : : vector < Entry > mEntries ;
unsigned int mNumEntries ;
2019-03-21 13:50:49 +00:00
double mLastUsageTimeStamp ;
2017-03-08 21:16:03 +00:00
bool mChanged ;
2019-02-20 13:37:00 +00:00
osg : : Vec3f mViewPoint ;
bool mHasViewPoint ;
2017-03-08 21:16:03 +00:00
} ;
class ViewDataMap : public osg : : Referenced
{
public :
2019-02-20 13:37:00 +00:00
ViewDataMap ( )
2019-03-21 13:50:49 +00:00
: mReuseDistance ( 300 ) // large value should be safe because the visibility of each node is still updated individually for each camera even if the base view was reused.
// this value also serves as a threshold for when a newly loaded LOD gets unloaded again so that if you hover around an LOD transition point the LODs won't keep loading and unloading all the time.
, mExpiryDelay ( 1.f )
2019-02-20 13:37:00 +00:00
{ }
ViewData * getViewData ( osg : : Object * viewer , const osg : : Vec3f & viewPoint , bool & needsUpdate ) ;
2017-03-08 21:16:03 +00:00
ViewData * createOrReuseView ( ) ;
2019-03-21 13:50:49 +00:00
void clearUnusedViews ( double referenceTime ) ;
2017-03-08 21:16:03 +00:00
void clear ( ) ;
private :
std : : list < ViewData > mViewVector ;
2019-02-20 13:37:00 +00:00
typedef std : : map < osg : : ref_ptr < osg : : Object > , ViewData * > Map ;
2017-03-08 21:16:03 +00:00
Map mViews ;
2019-02-20 13:37:00 +00:00
float mReuseDistance ;
2019-03-21 13:50:49 +00:00
float mExpiryDelay ; // time in seconds for unused view to be removed
2019-02-20 13:37:00 +00:00
2017-03-08 21:16:03 +00:00
std : : deque < ViewData * > mUnusedViews ;
} ;
}
# endif