Inheritance diagram for nrEngine::Clock:
Public Member Functions | |
void | setTimeSource (SharedPtr< TimeSource > timeSource) |
bool | isAnySourceBounded () |
SharedPtr< TimeSource > | getTimeSource () |
Result | onStartTask () |
Result | updateTask () |
Result | stopTask () |
void | Ticks () |
float64 | getTime () const |
float32 | getFrameInterval () const |
int32 | getFrameNumber () const |
float32 | getFrameRate () const |
float32 | getRealFrameInterval () const |
float32 | getRealFrameRate () const |
void | setMaxFrameRate (bool set, float32 maxFPS=60.0) |
int32 | addObserver (SharedPtr< ITimeObserver > timeObserver) |
Result | removeObserver (int32 observerID) |
Result | addObserver (const std::string &obsName, SharedPtr< ITimeObserver > timeObserver) |
Result | removeObserver (const std::string &obsName) |
void | setFrameWindow (int32 frameCount=10, float32 defaultFrameTime=0.03333) |
void | setFixFrameRate (bool setFixRate, float32 fixFrameRate=60.0f) |
SharedPtr< Timer > | createTimer () |
void | setSyncInterval (uint32 milliseconds) |
void | reset (float64 resetToTime=0.0f, bool resetAllObservers=false) |
ScriptFunctionDef (scriptResetClock) | |
Friends | |
class | Engine |
Only engine's core object can create instance. |
Definition at line 55 of file Clock.h.
void nrEngine::Clock::setTimeSource | ( | SharedPtr< TimeSource > | timeSource | ) |
Set the time source to be used to get current time. Our clock class is platform independent but the time get code depends mostly on the platform you using. So just derive your time source from ITimeSource interface and add this source into our clock.
timeSource | smart pointer containing to the time source |
Definition at line 126 of file Clock.cpp.
Referenced by nrEngine::Engine::initializeEngine(), and reset().
bool nrEngine::Clock::isAnySourceBounded | ( | ) |
SharedPtr<TimeSource> nrEngine::Clock::getTimeSource | ( | ) |
Result nrEngine::Clock::onStartTask | ( | ) | [virtual] |
This method will be called by the kernel to start the clock. It is called when clock is added to the kernel pipeline.
Reimplemented from nrEngine::ITask.
Definition at line 170 of file Clock.cpp.
References nrEngine::ScriptEngine::add(), nrEngine::OK, and nrEngine::Engine::sScriptEngine().
Result nrEngine::Clock::updateTask | ( | ) | [virtual] |
Updates the clock task by getting time values and calculating of frame rate and frame interval. Also each connected time observer will be notified so it can do own updates. This allows you just to create any observer (like timer) bind them to the clock and forgett it.
Implements nrEngine::ITask.
Definition at line 197 of file Clock.cpp.
References nrEngine::CLOCK_NO_TIME_SOURCE, and nrEngine::OK.
Result nrEngine::Clock::stopTask | ( | ) | [virtual] |
Stop the clock task and release all used objects. So all observers will be deleted from the observer list and also the time source is removed. After this function you still able to access to the clock and timers (because of smart pointers), but the time will hold on and no updates of the time will be made.
Reimplemented from nrEngine::ITask.
Definition at line 181 of file Clock.cpp.
References nrEngine::ScriptEngine::del(), nrEngine::OK, reset(), and nrEngine::Engine::sScriptEngine().
void nrEngine::Clock::Ticks | ( | ) |
float64 nrEngine::Clock::getTime | ( | ) | const |
float32 nrEngine::Clock::getFrameInterval | ( | ) | const |
Returns filtered interval time between two or more frames. nrEngine's clock does not only calculate the interval between two following frames, but it uses a arithmetic average to compute the frame interval between a lot of frames. This helps you to ignore some frames if their update time was to big or to less.
Definition at line 244 of file Clock.cpp.
Referenced by getFrameRate(), and nrEngine::Timer::notifyTimeObserver().
int32 nrEngine::Clock::getFrameNumber | ( | ) | const |
float32 nrEngine::Clock::getFrameRate | ( | ) | const |
Returns FPS. Like the frameinterval this value is also computed as average between a lot of frames. So this value is more smooth.
Definition at line 266 of file Clock.cpp.
References getFrameInterval().
float32 nrEngine::Clock::getRealFrameInterval | ( | ) | const |
Get the frame interval time of a real time. If you use fix frame rate, so you get as an interval a 1.0 / fix frame rate. This method allows you to get the time which your frame really need to render.
Definition at line 249 of file Clock.cpp.
Referenced by nrEngine::Timer::getRealFrameInterval(), and getRealFrameRate().
float32 nrEngine::Clock::getRealFrameRate | ( | ) | const |
Get real frame rate based on getRealFrameInterval() method
Definition at line 255 of file Clock.cpp.
References getRealFrameInterval().
void nrEngine::Clock::setMaxFrameRate | ( | bool | set, | |
float32 | maxFPS = 60.0 | |||
) |
This method allows you to set the maximal frame rate at which the clock shoudl run. It will use this frame rate as an upper bound. If applications runs faster than this time, so it will retard to this speed. If app runs much slower so nothing happens. At speed above the given boundaries the clock runs as for fixed frame rate. So you would retrieve fixed frame interval values. Function which retrieves real values are not affected by them, so you are still able to get information about the real time, which you frame need
int32 nrEngine::Clock::addObserver | ( | SharedPtr< ITimeObserver > | timeObserver | ) |
Add new time observer to our list of observers. Each observer will be notified on each frame after clock calculations are done. With this system we can separate our timers from game loop, but they still be updated on each frame.
timeObserver | smart pointers to the observer |
Definition at line 271 of file Clock.cpp.
Referenced by createTimer().
Removes an observer from the list by given ID
observerID | id of the observer returned by addObserver() |
Definition at line 286 of file Clock.cpp.
References nrEngine::CLOCK_OBSERVER_NOT_FOUND, and nrEngine::OK.
Result nrEngine::Clock::addObserver | ( | const std::string & | obsName, | |
SharedPtr< ITimeObserver > | timeObserver | |||
) |
Add an time observer by a name. So you can delete them also by using this name.
obsName | name of the observer | |
timeObserver | smart pointer pointing to the observer |
Definition at line 307 of file Clock.cpp.
References nrEngine::CLOCK_OBSERVER_ALREADY_ADDED, and nrEngine::OK.
Result nrEngine::Clock::removeObserver | ( | const std::string & | obsName | ) |
Removes an observer by using it's name.
obsName | name of the observer |
Definition at line 327 of file Clock.cpp.
References nrEngine::CLOCK_OBSERVER_NOT_FOUND, and nrEngine::OK.
Set the count of frames to be computed to calculate frame rate/interval. We need this to smooth big peaks on frame rates to allow application run smoother than without this window. Here we just using averaging of the frame intervals during certain number of frames.
frameCount | size of such frame calculation window | |
defaultFrameTime | is a frame interval added by default as if there was a frame rendered with this speed. This allows us to start smoothly |
Definition at line 340 of file Clock.cpp.
Referenced by reset().
void nrEngine::Clock::setFixFrameRate | ( | bool | setFixRate, | |
float32 | fixFrameRate = 60.0f | |||
) |
If you set this to true so fix frame rate will be used. This helps us to run our application on console or do internal calculations based on fix frame rate like Doom3 does.
setFixRate | if true fix frame rate will be used. | |
fixFrameRate | frame rate to be used |
SharedPtr< Timer > nrEngine::Clock::createTimer | ( | ) |
Create a new timer which does use this clock as reference.
Definition at line 148 of file Clock.cpp.
References addObserver(), nrEngine::Log::LL_DEBUG, nrEngine::Log::LL_WARNING, and nrEngine::Log::LOG_ENGINE.
void nrEngine::Clock::setSyncInterval | ( | uint32 | milliseconds | ) |
void nrEngine::Clock::reset | ( | float64 | resetToTime = 0.0f , |
|
bool | resetAllObservers = false | |||
) |
Reset the clock. The clock time will be resetted to the given time.
resetToTime | Reset the clock to the given time value | |
resetAllObservers | if true all registered obseervers would be also resetted |
Definition at line 97 of file Clock.cpp.
References nrEngine::Log::LOG_ENGINE, setFrameWindow(), and setTimeSource().
Referenced by nrEngine::ScriptFunctionDec(), and stopTask().
nrEngine::Clock::ScriptFunctionDef | ( | scriptResetClock | ) |
Script-Function to reset the clock. You can specify in parameters if all timers, which were created before should be also reseted.