diff options
author | Arnaud Degroote <arnaud.degroote@isae-supaero.fr> | 2015-12-12 04:37:42 +0300 |
---|---|---|
committer | Jorge Bernal <jbernalmartinez@gmail.com> | 2015-12-12 04:46:53 +0300 |
commit | aae93ae4c6c13e2b30ba272e24354dd020880868 (patch) | |
tree | 2f3cea018e4e19258d562ae45ccfdef929ff12d0 /source/gameengine/Ketsji/KX_KetsjiEngine.h | |
parent | e089b1f08bdf72eb4441e62f9c99e01ace0ef5c4 (diff) |
BGE: Improve clock management
This patch improves clock management in BGE, to be able to accelerate /
slow the time, and also to finely synchronize clock with external
engines. Several new python functions have been added and existence ones
have been improved for that purpose. Now we have:
- getClockTime(): Get the current BGE render time, in seconds. The BGE
render time is the simulation time corresponding to the next scene that
will be rendered.
- getFrameTime(): Get the current BGE frame time, in seconds. The BGE
frame time is the simulation time corresponding to the current call of
the logic system. Generally speaking, it is what the user is interested
in.
- getRealTime(): Get the number of real (system-clock) seconds elapsed
since the beginning of the simulation.
- getTimeScale(): Get the time multiplier between real-time and
simulation time. The default value is 1.0. A value greater than 1.0
means that the simulation is going faster than real-time, a value lower
than 1.0 means that the simulation is going slower than real-time.
- setTimeScale(time_scale): Set the time multiplier between real-time
and simulation time. A value greater than 1.0 means that the simulation
is going faster than real-time, a value lower than 1.0 means that the
simulation is going slower than real-time. Note that a too large value
may lead to some physics instabilities.
- getUseExternalClock(): Get if the BGE use the inner BGE clock, or rely
or on an external clock. The default is to use the inner BGE clock.
- setUseExternalClock(use_external_clock): Set if the BGE use the inner
BGE clock, or rely or on an external clock. If the user selects the use
of an external clock, he should call regularly the setClockTime method.
- setClockTime(new_time): Set the next value of the simulation clock. It
is preferable to use this method from a custom main function in python,
as calling it in the logic block can easily lead to a blocked system (if
the time does not advance enough to run at least the next logic step).
Rationale are described more precisely in the thread
http://lists.blender.org/pipermail/bf-gamedev/2013-November/000165.html.
See also T37640
Reviewers: sybren, panzergame, #game_engine, lordloki, moguri
Reviewed By: sybren, panzergame, #game_engine, lordloki, moguri
Subscribers: moguri, hg1, sybren, panzergame, dfelinto, lordloki
Projects: #game_engine
Maniphest Tasks: T37640
Differential Revision: https://developer.blender.org/D728
Diffstat (limited to 'source/gameengine/Ketsji/KX_KetsjiEngine.h')
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.h | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index ec855be3212..3b8cec2ac82 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -103,16 +103,19 @@ private: bool m_bInitialized; int m_activecam; bool m_bFixedTime; + bool m_useExternalClock; bool m_firstframe; int m_currentFrame; - double m_frameTime;//discrete timestamp of the 'game logic frame' - double m_clockTime;//current time - double m_previousClockTime;//previous clock time - double m_previousAnimTime; //the last time animations were updated + double m_frameTime; // current logic game time + double m_clockTime; // game time for the next rendering step + double m_previousClockTime; // game time of the previous rendering step + double m_previousAnimTime; //game time when the animations were last updated double m_remainingTime; + double m_timescale; // time scaling parameter. if > 1.0, time goes faster than real-time. If < 1.0, times goes slower than real-time. + double m_previousRealTime; static int m_maxLogicFrame; /* maximum number of consecutive logic frame */ static int m_maxPhysicsFrame; /* maximum number of consecutive physics frame */ @@ -297,15 +300,37 @@ public: bool GetUseFixedTime(void) const; /** - * Returns current render frame clock time + * Sets if the BGE relies on a external clock or its own internal clock + */ + void SetUseExternalClock(bool bUseExternalClock); + + /** + * Returns if we rely on an external clock + * \return Current setting + */ + bool GetUseExternalClock(void) const; + + /** + * Returns next render frame game time */ double GetClockTime(void) const; + + /** + * Set the next render frame game time. It will impact also frame time, as + * this one is derived from clocktime + */ + void SetClockTime(double externalClockTime); + /** - * Returns current logic frame clock time + * Returns current logic frame game time */ double GetFrameTime(void) const; + /** + * Returns the real (system) time + */ double GetRealTime(void) const; + /** * Returns the difference between the local time of the scene (when it * was running and not suspended) and the "curtime" @@ -361,6 +386,16 @@ public: */ static double GetAverageFrameRate(); + /** + * Gets the time scale multiplier + */ + double GetTimeScale() const; + + /** + * Sets the time scale multiplier + */ + void SetTimeScale(double scale); + static void SetExitKey(short key); static short GetExitKey(); |