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
2020-10-16 18:18:54 +00:00
void reset ( ) override ;
2017-03-08 21:16:03 +00:00
2020-05-08 13:37:00 +00:00
bool suitableToUse ( const osg : : Vec4i & activeGrid ) const ;
2017-03-08 21:16:03 +00:00
void clear ( ) ;
2020-05-08 13:37:00 +00:00
bool contains ( QuadTreeNode * node ) const ;
2017-03-08 23:45:31 +00:00
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
2019-06-13 13:37:00 +00:00
void setActiveGrid ( const osg : : Vec4i & grid ) { if ( grid ! = mActiveGrid ) { mActiveGrid = grid ; mEntries . clear ( ) ; mNumEntries = 0 ; } }
const osg : : Vec4i & getActiveGrid ( ) const { return mActiveGrid ; }
2020-05-08 13:37:00 +00:00
unsigned int getWorldUpdateRevision ( ) const { return mWorldUpdateRevision ; }
void setWorldUpdateRevision ( int updateRevision ) { mWorldUpdateRevision = updateRevision ; }
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 ;
2019-06-13 13:37:00 +00:00
osg : : Vec4i mActiveGrid ;
2020-05-08 13:37:00 +00:00
unsigned int mWorldUpdateRevision ;
2017-03-08 21:16:03 +00:00
} ;
class ViewDataMap : public osg : : Referenced
{
public :
2019-02-20 13:37:00 +00:00
ViewDataMap ( )
2020-05-08 13:37:00 +00:00
: mReuseDistance ( 150 ) // 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.
2019-03-21 13:50:49 +00:00
// 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 )
2020-05-08 13:37:00 +00:00
, mWorldUpdateRevision ( 0 )
2019-02-20 13:37:00 +00:00
{ }
2019-06-13 13:37:00 +00:00
ViewData * getViewData ( osg : : Object * viewer , const osg : : Vec3f & viewPoint , const osg : : Vec4i & activeGrid , bool & needsUpdate ) ;
2017-03-08 21:16:03 +00:00
ViewData * createOrReuseView ( ) ;
2020-05-08 13:37:00 +00:00
ViewData * createIndependentView ( ) const ;
2017-03-08 21:16:03 +00:00
2019-03-21 13:50:49 +00:00
void clearUnusedViews ( double referenceTime ) ;
2020-05-08 13:37:00 +00:00
void rebuildViews ( ) ;
bool storeView ( const ViewData * view , double referenceTime ) ;
2017-03-08 21:16:03 +00:00
private :
std : : list < ViewData > mViewVector ;
2020-05-08 13:37:00 +00:00
typedef std : : map < osg : : ref_ptr < osg : : Object > , ViewData * > ViewerMap ;
ViewerMap mViewers ;
2017-03-08 21:16:03 +00:00
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
2020-05-08 13:37:00 +00:00
unsigned int mWorldUpdateRevision ;
2020-05-12 13:37:00 +00:00
std : : deque < ViewData * > mUsedViews ;
2017-03-08 21:16:03 +00:00
std : : deque < ViewData * > mUnusedViews ;
} ;
}
# endif