vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vrecko::Scheduler Class Reference

#include <Scheduler.h>

Classes

struct  classcomp
 
struct  TimerStruct
 

Public Member Functions

 Scheduler ()
 
 ~Scheduler ()
 
 Scheduler (Scheduler &s)
 
void update (void)
 
void start (void)
 
void stop (void)
 
void addEntity (BaseClass *ent, float frequency=FRAME_FREQUENCY)
 
void addEntity (BaseClass *ent, const std::string &private_timer_name, float frequency=FRAME_FREQUENCY)
 
void removeEntity (BaseClass *ent)
 
bool isEntityPresent (BaseClass *ent)
 
bool getState ()
 
void resetObjectUpdatesCounter ()
 
int getObjectUpdatesCounter ()
 

Protected Types

typedef std::map< float,
TimerStruct
TimerMap
 
typedef std::map< std::string,
TimerStruct
PrivateTimerMap
 

Protected Attributes

TimerMap timer_map
 
PrivateTimerMap private_timer_map
 
bool state
 
int iObjectUpdatesCounter
 
std::multimap< long int,
BaseClass *, classcomp
updateMMap
 

Detailed Description

Class Scheduler serves for periodic updates of other entities.

Member Typedef Documentation

typedef std::map<std::string, TimerStruct > vrecko::Scheduler::PrivateTimerMap
protected
typedef std::map<float, TimerStruct > vrecko::Scheduler::TimerMap
protected

Constructor & Destructor Documentation

Scheduler::Scheduler ( )
Scheduler::~Scheduler ( )
Scheduler::Scheduler ( Scheduler s)

Member Function Documentation

void Scheduler::addEntity ( BaseClass ent,
float  frequency = FRAME_FREQUENCY 
)

This is the good version addEntity() method you would want to use when registering your class to be called periodically.

The system will attempt to call your object at specified intervals, however, it will do so ONLY ONCE PER FRAME in the main thread together with processing the graphics and other abilities.

This will mean, for example: If your frequency is 100 Hz and the main thread runs at 30 Hz, your ability will be called approximately three times IN A ROW, then other processing happens (rendering, other abilities), then your ability is called three times etc.

Because of this, it is usually good to use the FRAME_FREQUENCY constant, so your object is called exactly once per frame (you have to use the osg::Timer to get the delay between calls)

You can also use very low frequencies, such as 1/60, meaning once per minute.

void Scheduler::addEntity ( BaseClass ent,
const std::string &  private_timer_name,
float  frequency = FRAME_FREQUENCY 
)

[SEE WARNINGS IN THE DESCRIPTION] This method creates a new thread and runs it on a different frequency to achieve really asynchronous run.

However:

1) (V.K. - summer 2011) I am not sure, it if runs properly now.

2) (V.K.) You have to take EXTREMELY GOOD CARE that you won't break anything on your thread, which is fairly difficult. For starters, you can't delete objects from the scene and when accessing the existing object, you should probably not modify them (but you can use MTMatrixTransform ability instead of using the getMatrix()/setMatrix() methods).

Sending events from any thread is ok (they will be automatically processed in the main thread at one time during the frame). Sending requests is not recommended - thay have to be processed immediately, i.e. the target ability has to know it can be called from a non-main thread.

int vrecko::Scheduler::getObjectUpdatesCounter ( )
inline

Debug method.

bool vrecko::Scheduler::getState ( )
inline

Is the Scheduler running?

bool Scheduler::isEntityPresent ( BaseClass ent)

Is the entity currently periodically updated?

void Scheduler::removeEntity ( BaseClass ent)

Remove entity from being periodically updated.

void vrecko::Scheduler::resetObjectUpdatesCounter ( )
inline

Debug method.

void Scheduler::start ( void  )
void Scheduler::stop ( void  )
void Scheduler::update ( void  )

Member Data Documentation

int vrecko::Scheduler::iObjectUpdatesCounter
protected
PrivateTimerMap vrecko::Scheduler::private_timer_map
protected
bool vrecko::Scheduler::state
protected
TimerMap vrecko::Scheduler::timer_map
protected
std::multimap<long int, BaseClass*, classcomp> vrecko::Scheduler::updateMMap
protected

A multimap used for the update(). The reason for the declaration here is that it can be accessed also in the removeEntity() method. NOTE that unusual sorting is used (reversed).


The documentation for this class was generated from the following files: