#include <OSDLScheduler.h>
Collaboration diagram for OSDL::Engine::Scheduler:
Two kinds of active objects can be scheduled :
Whereas the scheduler internal time (EngineTick) is kept in synchronism with actual user time (in quasi-hard real time), the simulation and rendering times cannot ensure that deadlines are respected (because of many reasons, from the machine load to peak resource needs, OS scheduling and so on). Therefore they are only in soft real-time, and it is the job of the scheduler to manage that everything is done on time, on a best effort basis. Whenever a failure to meet a deadline occurs, the impacted objects are provided a means of being noticed, in order to be able to take any counter-measures they can.
The scheduler has two main data structures :
Our scheduler can follow two different behaviours :
Choosing a high logic frequency, and moreover higher than the rendering frequency, is the way to go, since it allows to get rid of interpolation and resampling issues. Clearly 33 Hz is the very least logic frequency one should use, and 100 Hz or higher frequencies should be preferred. Logic frequency should be multiple times higher than rendering frequency.
For the logic, please remember that the only time unit that should be used is the simulation tick. Do not try to depend on any real time measurement, since it would bypass the efforts of the scheduler to provide the application with a virtual fixed-rate logic time, and make it fail.
For the rendering, beware that some graphic primitives wait for vsync, which may freeze the process until the remaining part of the, say, 1/60th of second is reached. This hard real time practise would interfere badly with any scheduler. You can disable vsync, but one might experience more tearing and shearing. Conversely, the scheduler could take this behaviour into account and synchronize itself on the display refresh rate. It would have to manage a decrease in the frame rate if the scene complexity comes too close to have a rendering duration of the magic times (1/60 of second, 1/30 etc.) : because of random variations, some frames would go slightly over or under the time, leading to an irregular framerate which may be visually disturbing. Better switch to lower rendering rates and have a constant frame rate.
Rendering is obtained thanks to a renderer, if available, which is called at each rendering tick. If no renderer is being used, then the video module will be used, and requested to redraw at each rendering tick. The scheduled objects are in this case responsible for the updating of the screen surface.
add a means of knowing whether hardware synch with refresh rate is possible and, if so, use it not to schedule instead of the scheduler, but to make the scheduler start at the right time, so that it keeps naturally the synchronisation with the refresh rate. Or force the engine tick to be a hardware-locked frame pace.
Apart the logic and rendering frequencies, the scheduler have to handle the input frequency, which is the frequency at which input devices (such as keyboard, mouse, joysticks, etc.) are updated, according to pending low level events. One of the purposes of input handling is to have the controllers updated so that the simulation world is interactive. SDL input loop runs at 100 Hz, so higher frequencies would be useless.
The Scheduler is meant to be used as a singleton : having multiple scheduler instances on activity would be meaningless, and they would probably fail collectively.
For the simulation step, there could be too a two-pass algorithm : first compute, but do not apply, all the newer states of all objects, then, second pass, apply them. The problem is indeed that an object whose state depends on the state of other objects should take them into account at time t, when computing state at t+1, in their state at t, and not t+1. If all objects were to be updated in a single row, the first ones would be already at t+1 while the remaining would have to be updated from t to t+1. As among the remaining objects some may depend on the first ones, they would take into account t+1 states and not t states. Moreover, as there may be cyclic dependencies (say, for collisions, where two objects became mutually dependent), no right order can be found. Therefore a two-pass algorithm may be helpful.
The scheduler can run continuously for up to 48 days : after, engine ticks will overflow and it will lead to a scheduler shutdown.
Definition at line 217 of file OSDLScheduler.h.
Public Member Functions | |
virtual bool | hasRenderer () const throw () |
Tells whether a renderer is available to this scheduler. | |
virtual Rendering::Renderer & | getRenderer () const throw ( SchedulingException ) |
Returns currently used renderer, if any. | |
virtual void | setRenderer (Rendering::Renderer &newRenderer) throw () |
Assigns a new renderer, which will be called on every rendering tick, either to actually render, or to be notified of a rendering skip. | |
virtual void | setScreenshotMode (bool on, const std::string &frameFilenamePrefix, Events::Hertz frameFrequency=25) throw () |
Tells whether the application should run interactively, in real time (if on is false), or if it should run in record mode, with a virtual fixed framerate (as specified as frameFrequency), with logic and rendering taking all the time they need. | |
virtual void | setTimeSliceDuration (Ceylan::System::Microsecond engineTickDuration) throw () |
Defines how many microseconds an engine tick should last, and updates accordingly the simulation and rendering ticks. | |
virtual Ceylan::System::Microsecond | getTimeSliceDuration () const throw () |
Returns the current time slice duration, as used by this scheduler. | |
virtual void | setSimulationFrequency (Events::Hertz frequency) throw ( SchedulingException ) |
Sets the simulation frequency, by evaluating the number of engine ticks to be associated to one simulation tick for frequency to be met. | |
virtual Events::Period | getSimulationTickCount () const throw () |
Returns the number of engine ticks which correspond to one simulation tick. | |
virtual void | setRenderingFrequency (Events::Hertz frequency) throw ( SchedulingException ) |
Sets the rendering frequency, by evaluating the number of engine ticks to be associated to one rendering tick. | |
virtual Events::Period | getRenderingTickCount () const throw () |
Returns the number of engine ticks which correspond to one rendering tick. | |
virtual void | setScreenshotFrequency (Events::Hertz frequency) throw ( SchedulingException ) |
Sets the screenshot frequency, by evaluating the number of engine ticks to be associated to one screenshot tick for frequency to be met. | |
virtual Events::Period | getScreenshotTickCount () const throw () |
Returns the number of engine ticks which correspond to one screenshot tick. | |
virtual void | setInputPollingFrequency (Events::Hertz frequency) throw ( SchedulingException ) |
Sets the input polling frequency, by evaluating the number of engine ticks to be associated to one input tick. | |
virtual Events::Period | getInputPollingTickCount () const throw () |
Returns the number of engine ticks which correspond to one input tick. | |
virtual void | setIdleCallback (Ceylan::System::Callback idleCallback=0, void *callbackData=0, Ceylan::System::Microsecond callbackExpectedMaxDuration=0) throw () |
Sets the idle function, which is called whenever the scheduler detects a period of idle activity. | |
virtual Events::EngineTick | getCurrentEngineTick () const throw () |
Returns the current actual engine tick. | |
virtual Events::SimulationTick | getCurrentSimulationTick () const throw () |
Returns the current actual simulation tick. | |
virtual Events::RenderingTick | getCurrentRenderingTick () const throw () |
Returns the current actual rendering tick. | |
virtual Events::RenderingTick | getCurrentInputTick () const throw () |
Returns the current actual input tick. | |
virtual void | registerObject (ActiveObject &toRegister) throw () |
Registers specified active object in scheduling slots. | |
virtual void | schedule () throw ( SchedulingException ) |
Launches the schedule loop, which behaves as a specialized never-ending event loop. | |
virtual void | stop () throw () |
Requests the scheduler to stop its activities at the end of current engine tick. | |
virtual const std::string | toString (Ceylan::VerbosityLevels level=Ceylan::high) const throw () |
Returns an user-friendly description of the state of this object. | |
Static Public Member Functions | |
static Scheduler & | GetExistingScheduler () throw ( SchedulingException ) |
Returns the one and only one scheduler instance, that should be already available. | |
static Scheduler & | GetScheduler () throw () |
Returns the one and only scheduler instance. | |
static void | DeleteExistingScheduler () throw ( SchedulingException ) |
Deletes the existing shared scheduler. | |
static void | DeleteScheduler () throw () |
Deletes the shared scheduler, if any. | |
Static Public Attributes | |
static const Ceylan::System::Microsecond | DefaultEngineTickDuration = 1000 |
Determines the default engine tick duration. | |
static const Events::Hertz | DefaultSimulationFrequency = 100 |
Determines the default frequency for logic (simulation). | |
static const Events::Hertz | DefaultRenderingFrequency = 40 |
Determines the default frequency for rendering. | |
static const Ceylan::Uint32 | DefaultMovieFrameFrequency = 25 |
By default, generated screenshots will be saved on the purpose of being gathered by a movie with 25 images per second. | |
static const Events::Hertz | DefaultInputFrequency = 20 |
Determines the default frequency for rendering. | |
Protected Member Functions | |
Scheduler () throw () | |
Constructs a new scheduler. | |
virtual | ~Scheduler () throw () |
Virtual destructor, any existing renderer is deleted whereas no active object is destroyed. | |
virtual void | scheduleBestEffort () throw ( SchedulingException ) |
Actual scheduling method used for real-time and/or interactive applications. | |
virtual void | scheduleNoDeadline (bool pollInputs=true) throw ( SchedulingException ) |
Actual scheduling method used for batch applications, which do not care about keeping any user-defined pace. | |
virtual Events::EngineTick | computeEngineTickFromCurrentTime () throw () |
Returns the value that should be the engine tick, if no scheduling skip had happened. | |
virtual void | scheduleSimulation (Events::SimulationTick current) throw () |
Takes care of the simulation by making live relevant active objects, when a simulation step is reached. | |
virtual void | scheduleProgrammedObjects (Events::SimulationTick current) throw () |
Takes care of the simulation of programmed objects, by activating the relevant ones. | |
virtual void | schedulePeriodicObjects (Events::SimulationTick currentSimulationTick) throw () |
Takes care of the simulation of periodic objects, by activating the relevant ones. | |
virtual void | scheduleRendering (Events::RenderingTick currentRenderingTick) throw () |
Triggers the rendering. | |
virtual void | scheduleInput (Events::InputTick currentInputTick) throw () |
Triggers the input update. | |
virtual void | scheduleActiveObjectList (Events::RenderingTick currentSimulationTick, ListOfActiveObjects &objectList) throw () |
Helper method to schedule (execute) in turn every active object of the list. | |
virtual void | onSimulationSkipped (Events::SimulationTick skipped) throw ( SchedulingException ) |
Overridable method called when this scheduler detects that processing power was not high enough to perform on time specified simulation step, which will have therefore to be skipped. | |
virtual void | onRenderingSkipped (Events::RenderingTick skipped) throw ( SchedulingException ) |
Overridable method called when this scheduler detects that processing power was not high enough to perform on time specified rendering step, which will have therefore to be skipped. | |
virtual void | onInputSkipped (Events::InputTick skipped) throw ( SchedulingException ) |
Overridable method called when this scheduler detects that processing power was not high enough to perform on time specified input step, which will have therefore to be skipped. | |
virtual void | onIdle () throw () |
Called whenever the application is deemed idle. | |
virtual void | onScheduleFailure (Delay currentBucket) throw () |
Called whenever the scheduler does not succeed in keeping up the pace with what the application demanded : if the runtime resources are not high enough, then the scheduler may fail regularly and progressively fill up its delay bucket. | |
virtual void | programTriggerFor (ActiveObject &objectToProgram, Events::SimulationTick targetTick) throw () |
Adds a programmed activation for objectToProgram at simulation tick targetTick. | |
virtual PeriodicSlot & | getPeriodicSlotFor (Events::Period period) throw () |
Returns the internal periodic slot for specified period. | |
Protected Attributes | |
bool | _screenshotMode |
Tells whether screenshot mode is activated (default : deactivated). | |
std::string | _frameFilenamePrefix |
Records which prefix should be used to name numbered screenshot files. | |
Events::Hertz | _desiredScreenshotFrequency |
Records the user-defined screenshot frequency, which is the targeted number of frames per second. | |
Events::Period | _screenshotPeriod |
Stores the period corresponding to the planned framerate for the movie that would be generated, if screenshot mode is activated. | |
std::list< PeriodicSlot * > | _periodicSlots |
A list containing all available periodic slots, sorted by increasing periods. | |
std::map< Events::SimulationTick, ListOfActiveObjects > | _programmedActivated |
Map for programmed activations. | |
Ceylan::System::Microsecond | _engineTickDuration |
Defines the duration in microseconds of an elementary scheduler tick. | |
Ceylan::Uint32 | _secondToEngineTick |
Multiplicative factor that allows to convert seconds into engine ticks. | |
Events::EngineTick | _currentEngineTick |
Records the current engine tick. | |
Events::SimulationTick | _currentSimulationTick |
Records the current simulation tick. | |
Events::RenderingTick | _currentRenderingTick |
Records the current rendering tick. | |
Events::RenderingTick | _currentInputTick |
Records the current input tick. | |
Events::Period | _simulationPeriod |
Duration between two successive simulation steps, expressed in engine ticks. | |
Events::Period | _renderingPeriod |
Duration between two successive rendering steps, expressed in engine ticks. | |
Events::Period | _inputPeriod |
Duration between two successive input steps, expressed in engine ticks. | |
Events::Hertz | _desiredSimulationFrequency |
Records the user-defined simulation frequency. | |
Events::Hertz | _desiredRenderingFrequency |
Records the user-defined rendering frequency. | |
Events::Hertz | _desiredInputFrequency |
Records the user-defined input frequency. | |
Ceylan::System::Callback | _idleCallback |
The idle callback, if any, to be called by the scheduler. | |
void * | _idleCallbackData |
The data, if any, to provide to the idle callback. | |
Ceylan::System::Microsecond | _idleCallbackMaxDuration |
An estimated upper bound of the duration of current idle callback. | |
Ceylan::Uint32 | _idleCallsCount |
Count the number of idle calls made during the current scheduler session. | |
bool | _stopRequested |
Tells whether the scheduler has been requested to stop. | |
Ceylan::System::Second | _scheduleStartingSecond |
Stores the second when scheduling started. | |
Ceylan::System::Microsecond | _scheduleStartingMicrosecond |
Stores the microsecond when scheduling started. | |
Ceylan::Uint32 | _recoveredSimulationTicks |
Records how many simulation ticks were recovered since the scheduler was started. | |
Ceylan::Uint32 | _missedSimulationTicks |
Records how many simulation ticks were missed since the scheduler was started. | |
Ceylan::Uint32 | _recoveredRenderingTicks |
Records how many rendering ticks were recovered since the scheduler was started. | |
Ceylan::Uint32 | _missedRenderingTicks |
Records how many rendering ticks were missed since the scheduler was started. | |
Ceylan::Uint32 | _recoveredInputPollingTicks |
Records how many input ticks were recovered since the scheduler was started. | |
Ceylan::Uint32 | _missedInputPollingTicks |
Records how many input ticks were missed since the scheduler was started. | |
Ceylan::Uint32 | _scheduleFailureCount |
Records how many schedule failures were reported. | |
Events::EventsModule * | _eventsModule |
References the events module, if necessary. | |
Rendering::Renderer * | _renderer |
References the renderer to be used, if any. | |
Video::VideoModule * | _videoModule |
References the video module, if necessary. | |
Static Protected Attributes | |
static const Delay | ShutdownBucketLevel |
Threshold for the level of delay bucket, above which the scheduler will be stopped automatically. | |
Private Types | |
typedef Ceylan::Uint32 | Delay |
Used to measure time past deadlines. | |
Private Member Functions | |
Scheduler (const Scheduler &source) throw () | |
Copy constructor made private to ensure that it will never be called. | |
Scheduler & | operator= (const Scheduler &source) throw () |
Assignment operator made private to ensure that it will never be called. | |
Static Private Attributes | |
static Scheduler * | _internalScheduler |
The internal single instance of scheduler, if any. |
typedef Ceylan::Uint32 OSDL::Engine::Scheduler::Delay [private] |
Scheduler::Scheduler | ( | ) | throw () [explicit, protected] |
Constructs a new scheduler.
Definition at line 768 of file OSDLScheduler.cc.
References DefaultEngineTickDuration, setTimeSliceDuration(), and OSDL::Video::Pixels::toString().
Referenced by GetScheduler().
Scheduler::~Scheduler | ( | ) | throw () [protected, virtual] |
Virtual destructor, any existing renderer is deleted whereas no active object is destroyed.
Definition at line 818 of file OSDLScheduler.cc.
References _periodicSlots, and _renderer.
OSDL::Engine::Scheduler::Scheduler | ( | const Scheduler & | source | ) | throw () [explicit, private] |
Copy constructor made private to ensure that it will never be called.
The compiler should complain whenever this undefined constructor is called, implicitly or not.
bool Scheduler::hasRenderer | ( | ) | const throw () [virtual] |
Tells whether a renderer is available to this scheduler.
If no renderer is registered, the video module will be used instead.
Definition at line 54 of file OSDLScheduler.cc.
References _renderer.
Renderer & Scheduler::getRenderer | ( | ) | const throw ( SchedulingException ) [virtual] |
Returns currently used renderer, if any.
SchedulingException | if no renderer is available. |
Definition at line 62 of file OSDLScheduler.cc.
References _renderer.
void Scheduler::setRenderer | ( | Rendering::Renderer & | newRenderer | ) | throw () [virtual] |
Assigns a new renderer, which will be called on every rendering tick, either to actually render, or to be notified of a rendering skip.
newRenderer | the renderer to be used from now. |
Definition at line 74 of file OSDLScheduler.cc.
virtual void OSDL::Engine::Scheduler::setScreenshotMode | ( | bool | on, | |
const std::string & | frameFilenamePrefix, | |||
Events::Hertz | frameFrequency = 25 | |||
) | throw () [virtual] |
Tells whether the application should run interactively, in real time (if on is false), or if it should run in record mode, with a virtual fixed framerate (as specified as frameFrequency), with logic and rendering taking all the time they need.
In this mode, even if the logic and the rendering tasks last for two hours for each virtual second, the resulting set of PNG files is made so that these files can be gathered to form an animation with, for instance, 25 frames per second. When this animation will be played, the logic will seem to have acted with respect to the planned framerate, as if in real time.
on | tells whether frames are to be rendered to file (iff on), or if the application should run interactively. | |
frameFilenamePrefix | determines which prefix will be used to name successive screenshots, in the form : 'frameFilenamePrefix'-n.png, n being the frame count of the animation. | |
frameFrequency | tells how many frames should be rendered each second. At least 25 frames per second is recommended to be able to realize smooth animations. |
virtual void OSDL::Engine::Scheduler::setTimeSliceDuration | ( | Ceylan::System::Microsecond | engineTickDuration | ) | throw () [virtual] |
Defines how many microseconds an engine tick should last, and updates accordingly the simulation and rendering ticks.
For example, an engine tick duration of 1000 microseconds defines a scheduling frequency of 1 kHz (1000 Hz). Then all scheduled events should then have a periodicity of at most 1000 Hz, probably far lower.
engineTickDuration | the period of time between two scheduler elementary ticks, expressed in microseconds. |
Referenced by Scheduler().
Microsecond Scheduler::getTimeSliceDuration | ( | ) | const throw () [virtual] |
Returns the current time slice duration, as used by this scheduler.
Definition at line 116 of file OSDLScheduler.cc.
References _engineTickDuration.
Referenced by OSDL::Engine::ActiveObject::setFrequency().
void Scheduler::setSimulationFrequency | ( | Events::Hertz | frequency | ) | throw ( SchedulingException ) [virtual] |
Sets the simulation frequency, by evaluating the number of engine ticks to be associated to one simulation tick for frequency to be met.
SchedulingException | if requested frequency is superior to engine frequency. |
Definition at line 124 of file OSDLScheduler.cc.
References OSDL::Video::Pixels::toString().
Period Scheduler::getSimulationTickCount | ( | ) | const throw () [virtual] |
Returns the number of engine ticks which correspond to one simulation tick.
Definition at line 162 of file OSDLScheduler.cc.
References _simulationPeriod.
Referenced by OSDL::Engine::ActiveObject::setFrequency().
void Scheduler::setRenderingFrequency | ( | Events::Hertz | frequency | ) | throw ( SchedulingException ) [virtual] |
Sets the rendering frequency, by evaluating the number of engine ticks to be associated to one rendering tick.
SchedulingException | if requested frequency is superior to engine frequency. |
Definition at line 170 of file OSDLScheduler.cc.
References OSDL::Video::Pixels::toString().
Period Scheduler::getRenderingTickCount | ( | ) | const throw () [virtual] |
Returns the number of engine ticks which correspond to one rendering tick.
Definition at line 209 of file OSDLScheduler.cc.
References _renderingPeriod.
void Scheduler::setScreenshotFrequency | ( | Events::Hertz | frequency | ) | throw ( SchedulingException ) [virtual] |
Sets the screenshot frequency, by evaluating the number of engine ticks to be associated to one screenshot tick for frequency to be met.
SchedulingException | if requested frequency is superior to engine frequency. |
Definition at line 217 of file OSDLScheduler.cc.
References OSDL::Video::Pixels::toString().
Period Scheduler::getScreenshotTickCount | ( | ) | const throw () [virtual] |
Returns the number of engine ticks which correspond to one screenshot tick.
Definition at line 260 of file OSDLScheduler.cc.
References _screenshotPeriod.
void Scheduler::setInputPollingFrequency | ( | Events::Hertz | frequency | ) | throw ( SchedulingException ) [virtual] |
Sets the input polling frequency, by evaluating the number of engine ticks to be associated to one input tick.
SchedulingException | if requested frequency is superior to engine frequency. |
Definition at line 268 of file OSDLScheduler.cc.
References OSDL::Video::Pixels::toString().
Period Scheduler::getInputPollingTickCount | ( | ) | const throw () [virtual] |
Returns the number of engine ticks which correspond to one input tick.
Definition at line 325 of file OSDLScheduler.cc.
References _inputPeriod.
void Scheduler::setIdleCallback | ( | Ceylan::System::Callback | idleCallback = 0 , |
|
void * | callbackData = 0 , |
|||
Ceylan::System::Microsecond | callbackExpectedMaxDuration = 0 | |||
) | throw () [virtual] |
Sets the idle function, which is called whenever the scheduler detects a period of idle activity.
The callback can be useful for example to let the process yield some CPU time so that the OS does not consider it as too CPU-hungry, and does not take counter-measures against it.
idleCallback | the idle callback, which can be null (0) to specify no idle callback is wanted. | |
callbackData | the user-supplied data pointer that the idle callback will be given, if not null. | |
callbackExpectedMaxDuration | the maximum duration, in microseconds, expected for this idle call-back. Helps the scheduler enforcing its target frequency. If this value is null, the idle callback will be launched once immediately (during the call of this method), and the measured duration, increased of 20%, will be kept as upper bound. |
Definition at line 306 of file OSDLScheduler.cc.
EngineTick Scheduler::getCurrentEngineTick | ( | ) | const throw () [virtual] |
Returns the current actual engine tick.
Definition at line 333 of file OSDLScheduler.cc.
References _currentEngineTick.
SimulationTick Scheduler::getCurrentSimulationTick | ( | ) | const throw () [virtual] |
Returns the current actual simulation tick.
Definition at line 341 of file OSDLScheduler.cc.
References _currentSimulationTick.
RenderingTick Scheduler::getCurrentRenderingTick | ( | ) | const throw () [virtual] |
Returns the current actual rendering tick.
Definition at line 349 of file OSDLScheduler.cc.
References _currentRenderingTick.
RenderingTick Scheduler::getCurrentInputTick | ( | ) | const throw () [virtual] |
Returns the current actual input tick.
Definition at line 357 of file OSDLScheduler.cc.
References _currentInputTick.
void Scheduler::registerObject | ( | ActiveObject & | toRegister | ) | throw () [virtual] |
Registers specified active object in scheduling slots.
Depending on the object defining or not a periodic and/or programmed activations, the scheduler will store these informations in order to be able to activate periodically and/or at specific simulation ticks this object.
toRegister | the active object to register to the scheduler. |
Definition at line 365 of file OSDLScheduler.cc.
void Scheduler::schedule | ( | ) | throw ( SchedulingException ) [virtual] |
Launches the schedule loop, which behaves as a specialized never-ending event loop.
SchedulingException,when | propagated from active objects having problems. |
Definition at line 409 of file OSDLScheduler.cc.
References _eventsModule, _renderer, _screenshotMode, _videoModule, OSDL::CommonModule::getEventsModule(), OSDL::getExistingCommonModule(), OSDL::CommonModule::getVideoModule(), scheduleBestEffort(), scheduleNoDeadline(), and OSDL::Rendering::Renderer::toString().
void Scheduler::stop | ( | ) | throw () [virtual] |
Requests the scheduler to stop its activities at the end of current engine tick.
Definition at line 455 of file OSDLScheduler.cc.
References _stopRequested.
const string Scheduler::toString | ( | Ceylan::VerbosityLevels | level = Ceylan::high |
) | const throw () [virtual] |
Returns an user-friendly description of the state of this object.
level | the requested verbosity level. |
Definition at line 463 of file OSDLScheduler.cc.
References OSDL::Video::Pixels::toString().
Referenced by scheduleBestEffort().
Scheduler & Scheduler::GetExistingScheduler | ( | ) | throw ( SchedulingException ) [static] |
Returns the one and only one scheduler instance, that should be already available.
The returned value is a reference and not a pointer, to avoid any abnormal deallocation by its users, that should never deallocate the scheduler.
SchedulingException | if there is no scheduler available. |
Definition at line 681 of file OSDLScheduler.cc.
References _internalScheduler.
Referenced by OSDL::Engine::ActiveObject::setFrequency().
Scheduler & Scheduler::GetScheduler | ( | ) | throw () [static] |
Returns the one and only scheduler instance.
If no scheduler was already available, a new singletoned instance is created.
The returned value is a reference and not a pointer, to avoid any abnormal deallocation by its users, that should never deallocate the scheduler.
Definition at line 693 of file OSDLScheduler.cc.
References _internalScheduler, Scheduler(), and OSDL::Video::Pixels::toString().
void Scheduler::DeleteExistingScheduler | ( | ) | throw ( SchedulingException ) [static] |
Deletes the existing shared scheduler.
SchedulingException | if not scheduler was available. |
Definition at line 720 of file OSDLScheduler.cc.
References _internalScheduler.
void Scheduler::DeleteScheduler | ( | ) | throw () [static] |
Deletes the shared scheduler, if any.
Definition at line 738 of file OSDLScheduler.cc.
References _internalScheduler.
void Scheduler::scheduleBestEffort | ( | ) | throw ( SchedulingException ) [protected, virtual] |
Actual scheduling method used for real-time and/or interactive applications.
Definition at line 833 of file OSDLScheduler.cc.
References _currentEngineTick, _currentInputTick, _currentRenderingTick, _currentSimulationTick, _desiredInputFrequency, _desiredRenderingFrequency, _desiredSimulationFrequency, _engineTickDuration, _idleCallback, _idleCallbackMaxDuration, _idleCallsCount, _inputPeriod, _missedInputPollingTicks, _missedRenderingTicks, _missedSimulationTicks, _recoveredInputPollingTicks, _recoveredRenderingTicks, _recoveredSimulationTicks, _renderingPeriod, _scheduleFailureCount, _scheduleStartingMicrosecond, _scheduleStartingSecond, _simulationPeriod, _stopRequested, computeEngineTickFromCurrentTime(), DefaultEngineTickDuration, onIdle(), onInputSkipped(), onRenderingSkipped(), onScheduleFailure(), onSimulationSkipped(), OSDL_SCHEDULE_LOG, scheduleInput(), scheduleRendering(), scheduleSimulation(), ShutdownBucketLevel, OSDL::Video::Pixels::toString(), and toString().
Referenced by schedule().
void Scheduler::scheduleNoDeadline | ( | bool | pollInputs = true |
) | throw ( SchedulingException ) [protected, virtual] |
Actual scheduling method used for batch applications, which do not care about keeping any user-defined pace.
pollInputs | tells whether inputs should be polled nevertheless. |
Definition at line 2185 of file OSDLScheduler.cc.
References OSDL_SCHEDULE_LOG, and OSDL::Video::Pixels::toString().
Referenced by schedule().
EngineTick Scheduler::computeEngineTickFromCurrentTime | ( | ) | throw () [protected, virtual] |
Returns the value that should be the engine tick, if no scheduling skip had happened.
This engine tick is computed from the current time since the beginning of scheduling, which is obtained thanks to a call to a precise actual time measurement minus the offset corresponding to the starting time of the scheduling.
Definition at line 2506 of file OSDLScheduler.cc.
References _engineTickDuration, _scheduleStartingMicrosecond, _scheduleStartingSecond, _secondToEngineTick, and _stopRequested.
Referenced by scheduleBestEffort().
void Scheduler::scheduleSimulation | ( | Events::SimulationTick | current | ) | throw () [protected, virtual] |
Takes care of the simulation by making live relevant active objects, when a simulation step is reached.
current | the simulation tick to perform, for objects to be able to behave appropriatly, for example for first behaviour approach (stateless objects). |
Definition at line 2560 of file OSDLScheduler.cc.
References OSDL_SCHEDULE_LOG.
Referenced by scheduleBestEffort().
void Scheduler::scheduleProgrammedObjects | ( | Events::SimulationTick | current | ) | throw () [protected, virtual] |
Takes care of the simulation of programmed objects, by activating the relevant ones.
current | the simulation tick to perform, for programmed objects to know to which programmed step this activation corresponds. |
Definition at line 2576 of file OSDLScheduler.cc.
void Scheduler::schedulePeriodicObjects | ( | Events::SimulationTick | currentSimulationTick | ) | throw () [protected, virtual] |
Takes care of the simulation of periodic objects, by activating the relevant ones.
currentSimulationTick | the simulation tick to perform, for objects to be able to behave appropriately, for example for first behaviour approach (stateless objects). |
Definition at line 2596 of file OSDLScheduler.cc.
void Scheduler::scheduleRendering | ( | Events::RenderingTick | currentRenderingTick | ) | throw () [protected, virtual] |
Triggers the rendering.
currentRenderingTick | the current rendering tick. |
Definition at line 2610 of file OSDLScheduler.cc.
References OSDL_SCHEDULE_LOG.
Referenced by scheduleBestEffort().
void Scheduler::scheduleInput | ( | Events::InputTick | currentInputTick | ) | throw () [protected, virtual] |
Triggers the input update.
currentInputTick | the current input tick. |
Definition at line 2631 of file OSDLScheduler.cc.
References OSDL_SCHEDULE_LOG.
Referenced by scheduleBestEffort().
void Scheduler::scheduleActiveObjectList | ( | Events::RenderingTick | currentSimulationTick, | |
ListOfActiveObjects & | objectList | |||
) | throw () [protected, virtual] |
Helper method to schedule (execute) in turn every active object of the list.
currentSimulationTick | the simulation tick to be passed to the activated objects. | |
objectList | the list of the active objects to execute in turn. |
Definition at line 2647 of file OSDLScheduler.cc.
void Scheduler::onSimulationSkipped | ( | Events::SimulationTick | skipped | ) | throw ( SchedulingException ) [protected, virtual] |
Overridable method called when this scheduler detects that processing power was not high enough to perform on time specified simulation step, which will have therefore to be skipped.
By default, this method calls on all active objects whose simulation step has been skipped their onSkip method.
Skipping methods should be, on average, faster than their normally scheduled counterparts (onNextTick), otherwise the scheduler will have no chance of keeping up with the real time.
Definition at line 2661 of file OSDLScheduler.cc.
References OSDL::Video::Pixels::toString().
Referenced by scheduleBestEffort().
void Scheduler::onRenderingSkipped | ( | Events::RenderingTick | skipped | ) | throw ( SchedulingException ) [protected, virtual] |
Overridable method called when this scheduler detects that processing power was not high enough to perform on time specified rendering step, which will have therefore to be skipped.
By default, this method does nothing except complaining in the warning channel.
Definition at line 2706 of file OSDLScheduler.cc.
References OSDL::Video::Pixels::toString().
Referenced by scheduleBestEffort().
void Scheduler::onInputSkipped | ( | Events::InputTick | skipped | ) | throw ( SchedulingException ) [protected, virtual] |
Overridable method called when this scheduler detects that processing power was not high enough to perform on time specified input step, which will have therefore to be skipped.
By default, this method does nothing at all. As only the freshest inputs are generally useful, most applications will leave this method as a do-nothing one.
Definition at line 2723 of file OSDLScheduler.cc.
Referenced by scheduleBestEffort().
void Scheduler::onIdle | ( | ) | throw () [protected, virtual] |
Called whenever the application is deemed idle.
Applies the idle behaviour, which can be user-defined (setIdleCallback), or otherwise which will default to micro-sleeps.
Definition at line 2734 of file OSDLScheduler.cc.
References _idleCallback, _idleCallbackData, _idleCallsCount, and OSDL_SCHEDULE_LOG.
Referenced by scheduleBestEffort().
void Scheduler::onScheduleFailure | ( | Delay | currentBucket | ) | throw () [protected, virtual] |
Called whenever the scheduler does not succeed in keeping up the pace with what the application demanded : if the runtime resources are not high enough, then the scheduler may fail regularly and progressively fill up its delay bucket.
In this case this method - made to be overloaded - is called with the current bucket value. It can then take countermeasures (preferably without taking too much time, otherwise it will be responsible for the scheduling failure).
The default implementation will send notifications in the error log channel if below ShutdownBucketLevel, and will stop the scheduler if higher.
Definition at line 2763 of file OSDLScheduler.cc.
References OSDL_SCHEDULE_LOG, OSDL::stop(), and OSDL::Video::Pixels::toString().
Referenced by scheduleBestEffort().
void Scheduler::programTriggerFor | ( | ActiveObject & | objectToProgram, | |
Events::SimulationTick | targetTick | |||
) | throw () [protected, virtual] |
Adds a programmed activation for objectToProgram at simulation tick targetTick.
objectToProgram | the object whose activation is being programmed. | |
targetTick | the simulation tick when specified object should be activated. |
Definition at line 2808 of file OSDLScheduler.cc.
PeriodicSlot & Scheduler::getPeriodicSlotFor | ( | Events::Period | period | ) | throw () [protected, virtual] |
Returns the internal periodic slot for specified period.
If there is no slot for this period, a new slot is created and returned.
Definition at line 2837 of file OSDLScheduler.cc.
Assignment operator made private to ensure that it will never be called.
The compiler should complain whenever this undefined operator is called, implicitly or not.
const Ceylan::System::Microsecond OSDL::Engine::Scheduler::DefaultEngineTickDuration = 1000 [static] |
Determines the default engine tick duration.
Definition at line 631 of file OSDLScheduler.h.
Referenced by scheduleBestEffort(), and Scheduler().
const Events::Hertz OSDL::Engine::Scheduler::DefaultSimulationFrequency = 100 [static] |
Determines the default frequency for logic (simulation).
Definition at line 640 of file OSDLScheduler.h.
const Events::Hertz OSDL::Engine::Scheduler::DefaultRenderingFrequency = 40 [static] |
Determines the default frequency for rendering.
Definition at line 650 of file OSDLScheduler.h.
const Ceylan::Uint32 OSDL::Engine::Scheduler::DefaultMovieFrameFrequency = 25 [static] |
By default, generated screenshots will be saved on the purpose of being gathered by a movie with 25 images per second.
Definition at line 661 of file OSDLScheduler.h.
const Events::Hertz OSDL::Engine::Scheduler::DefaultInputFrequency = 20 [static] |
Determines the default frequency for rendering.
Definition at line 671 of file OSDLScheduler.h.
const Scheduler::Delay Scheduler::ShutdownBucketLevel [static, protected] |
Threshold for the level of delay bucket, above which the scheduler will be stopped automatically.
Definition at line 903 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
bool OSDL::Engine::Scheduler::_screenshotMode [protected] |
Tells whether screenshot mode is activated (default : deactivated).
Definition at line 968 of file OSDLScheduler.h.
Referenced by schedule().
std::string OSDL::Engine::Scheduler::_frameFilenamePrefix [protected] |
Records which prefix should be used to name numbered screenshot files.
The purpose of these files is mainly to be gathered in a movie (ex : MPEG).
Definition at line 979 of file OSDLScheduler.h.
Records the user-defined screenshot frequency, which is the targeted number of frames per second.
Useful if the corresponding period had to be computed again after the engine tick duration changed.
Definition at line 990 of file OSDLScheduler.h.
Stores the period corresponding to the planned framerate for the movie that would be generated, if screenshot mode is activated.
Movie periods, which are the duration between two successive screenshots, are expressed in engine ticks.
Definition at line 1002 of file OSDLScheduler.h.
Referenced by getScreenshotTickCount().
std::list<PeriodicSlot *> OSDL::Engine::Scheduler::_periodicSlots [protected] |
A list containing all available periodic slots, sorted by increasing periods.
Definition at line 1025 of file OSDLScheduler.h.
Referenced by ~Scheduler().
std::map<Events::SimulationTick, ListOfActiveObjects> OSDL::Engine::Scheduler::_programmedActivated [protected] |
Map for programmed activations.
Each key of the map is a specific simulation tick, whereas its value is a list of all objects having requested to be scheduled at this particular simulation tick.
A map (namely, a hash table) has been prefered to a list sorted in chronological order, since with a map, even if reading whether there are programmed triggers next simulation steps is slower (0(log n) instead of 0(1)), insertion times are much faster, (0(n.log n) instead of 0(n)).
As there may be numerous programmed triggers (ex : for playing sound delayed by distance), the map might be helpful here.
Definition at line 1049 of file OSDLScheduler.h.
Ceylan::System::Microsecond OSDL::Engine::Scheduler::_engineTickDuration [protected] |
Defines the duration in microseconds of an elementary scheduler tick.
Definition at line 1059 of file OSDLScheduler.h.
Referenced by computeEngineTickFromCurrentTime(), getTimeSliceDuration(), and scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_secondToEngineTick [protected] |
Multiplicative factor that allows to convert seconds into engine ticks.
Definition at line 1069 of file OSDLScheduler.h.
Referenced by computeEngineTickFromCurrentTime().
Records the current engine tick.
Useful to determine how much time have elapsed since last schedule action.
Therefore, this data member is the only one that is authoritative (the only actual value).
Definition at line 1094 of file OSDLScheduler.h.
Referenced by getCurrentEngineTick(), and scheduleBestEffort().
Records the current simulation tick.
Useful to determine how much time have elapsed since last simulation action.
Definition at line 1118 of file OSDLScheduler.h.
Referenced by getCurrentSimulationTick(), and scheduleBestEffort().
Records the current rendering tick.
Useful to determine how much time have elapsed since last rendering action.
Definition at line 1142 of file OSDLScheduler.h.
Referenced by getCurrentRenderingTick(), and scheduleBestEffort().
Records the current input tick.
Useful to determine how much time have elapsed since last input polling.
Definition at line 1166 of file OSDLScheduler.h.
Referenced by getCurrentInputTick(), and scheduleBestEffort().
Duration between two successive simulation steps, expressed in engine ticks.
Definition at line 1174 of file OSDLScheduler.h.
Referenced by getSimulationTickCount(), and scheduleBestEffort().
Duration between two successive rendering steps, expressed in engine ticks.
Definition at line 1182 of file OSDLScheduler.h.
Referenced by getRenderingTickCount(), and scheduleBestEffort().
Events::Period OSDL::Engine::Scheduler::_inputPeriod [protected] |
Duration between two successive input steps, expressed in engine ticks.
Definition at line 1190 of file OSDLScheduler.h.
Referenced by getInputPollingTickCount(), and scheduleBestEffort().
Records the user-defined simulation frequency.
Useful if the corresponding period had to be computed again after the engine tick duration changed.
Definition at line 1200 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Records the user-defined rendering frequency.
Useful if the corresponding period had to be computed again after the engine tick duration changed.
Definition at line 1210 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Records the user-defined input frequency.
Useful if the corresponding period had to be computed again after the engine tick duration changed.
Definition at line 1220 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Ceylan::System::Callback OSDL::Engine::Scheduler::_idleCallback [protected] |
The idle callback, if any, to be called by the scheduler.
Definition at line 1233 of file OSDLScheduler.h.
Referenced by onIdle(), and scheduleBestEffort().
void* OSDL::Engine::Scheduler::_idleCallbackData [protected] |
The data, if any, to provide to the idle callback.
Definition at line 1240 of file OSDLScheduler.h.
Referenced by onIdle().
Ceylan::System::Microsecond OSDL::Engine::Scheduler::_idleCallbackMaxDuration [protected] |
An estimated upper bound of the duration of current idle callback.
Helps the scheduler to respect its expected pace.
Definition at line 1250 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_idleCallsCount [protected] |
Count the number of idle calls made during the current scheduler session.
Definition at line 1258 of file OSDLScheduler.h.
Referenced by onIdle(), and scheduleBestEffort().
bool OSDL::Engine::Scheduler::_stopRequested [protected] |
Tells whether the scheduler has been requested to stop.
Definition at line 1263 of file OSDLScheduler.h.
Referenced by computeEngineTickFromCurrentTime(), scheduleBestEffort(), and stop().
Ceylan::System::Second OSDL::Engine::Scheduler::_scheduleStartingSecond [protected] |
Stores the second when scheduling started.
Definition at line 1270 of file OSDLScheduler.h.
Referenced by computeEngineTickFromCurrentTime(), and scheduleBestEffort().
Ceylan::System::Microsecond OSDL::Engine::Scheduler::_scheduleStartingMicrosecond [protected] |
Stores the microsecond when scheduling started.
Definition at line 1277 of file OSDLScheduler.h.
Referenced by computeEngineTickFromCurrentTime(), and scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_recoveredSimulationTicks [protected] |
Records how many simulation ticks were recovered since the scheduler was started.
Definition at line 1286 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_missedSimulationTicks [protected] |
Records how many simulation ticks were missed since the scheduler was started.
Definition at line 1294 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_recoveredRenderingTicks [protected] |
Records how many rendering ticks were recovered since the scheduler was started.
Definition at line 1303 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_missedRenderingTicks [protected] |
Records how many rendering ticks were missed since the scheduler was started.
Definition at line 1311 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_recoveredInputPollingTicks [protected] |
Records how many input ticks were recovered since the scheduler was started.
Definition at line 1320 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_missedInputPollingTicks [protected] |
Records how many input ticks were missed since the scheduler was started.
Definition at line 1328 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
Ceylan::Uint32 OSDL::Engine::Scheduler::_scheduleFailureCount [protected] |
Records how many schedule failures were reported.
Happens when the delay bucket reaches its first threashold.
Definition at line 1337 of file OSDLScheduler.h.
Referenced by scheduleBestEffort().
References the events module, if necessary.
Definition at line 1347 of file OSDLScheduler.h.
Referenced by schedule().
Rendering::Renderer* OSDL::Engine::Scheduler::_renderer [protected] |
References the renderer to be used, if any.
Definition at line 1354 of file OSDLScheduler.h.
Referenced by getRenderer(), hasRenderer(), schedule(), and ~Scheduler().
Video::VideoModule* OSDL::Engine::Scheduler::_videoModule [protected] |
References the video module, if necessary.
Definition at line 1368 of file OSDLScheduler.h.
Referenced by schedule().
Scheduler * Scheduler::_internalScheduler [static, private] |
The internal single instance of scheduler, if any.
Definition at line 1398 of file OSDLScheduler.h.
Referenced by DeleteExistingScheduler(), DeleteScheduler(), GetExistingScheduler(), and GetScheduler().