diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-05-21 22:10:19 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-05-21 22:10:19 +0400 |
commit | 036ebc55233241bf9bd8149f855185cfcfb1ab67 (patch) | |
tree | cf561cf256c9dedb8e0a36bddfcc54cb0ada0749 /source/gameengine/Ketsji/KX_KetsjiEngine.cpp | |
parent | d54126f78edbb48073fe979395de92dca255fd7e (diff) |
BGE: GUI control over frame rate, logic rate, physics rate and physics subrate.
Four new buttons in World settings to control frame rate:
fps: Nominal frame rate in frame per second.
Also sets the physics timestep = 1/fps
phys: Maximum number of physics timestep per game frame in case
the actual fps is less than nominal. This allows the
physics to keep up with real time even if the graphics slows
down the game.
sub: Fixed number of simulation substeps per physic timestep.
Improves the precision of the physics simulation. Useful for
fast moving objects for example.
log: Maximum number of logic steps per game frame in case the
actual fps is less than nominal. This allows the logic
system to follow the physics simulation.
Upper bound = phys
(setting the value higher than phys has no effect).
On games with heavy logic system, it is useful to set this
value to 1, to keep logic time under control.
All these values were already accessible from Python except phys:
GameLogic.getMaxPhysicsFrame():
Gets the maximum number of physics frame per render frame.
GameLogic.setMaxPhysicsFrame(phys):
Sets the maximum number of physics timestep that are executed per render frame.
Higher value allows physics to keep up with realtime even if graphics slows down the game.
Physics timestep is fixed and equal to 1/tickrate (see setLogicTicRate)
maxphysics/ticrate is the maximum delay of the renderer that physics can compensate.
phys: integer
Diffstat (limited to 'source/gameengine/Ketsji/KX_KetsjiEngine.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 4107ed7d82e..983059d0c70 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -77,6 +77,8 @@ #include "RAS_FramingManager.h" #include "stdio.h" +#include "DNA_world_types.h" +#include "DNA_scene_types.h" // If define: little test for Nzc: guarded drawing. If the canvas is // not valid, skip rendering this frame. @@ -98,6 +100,7 @@ const char KX_KetsjiEngine::m_profileLabels[tc_numCategories][15] = { double KX_KetsjiEngine::m_ticrate = DEFAULT_LOGIC_TIC_RATE; int KX_KetsjiEngine::m_maxLogicFrame = 5; +int KX_KetsjiEngine::m_maxPhysicsFrame = 5; double KX_KetsjiEngine::m_anim_framerate = 25.0; double KX_KetsjiEngine::m_suspendedtime = 0.0; double KX_KetsjiEngine::m_suspendeddelta = 0.0; @@ -393,8 +396,20 @@ void KX_KetsjiEngine::StartEngine(bool clearIpo) m_firstframe = true; m_bInitialized = true; - m_ticrate = DEFAULT_LOGIC_TIC_RATE; - m_maxLogicFrame = 5; + // there is always one scene enabled at startup + World* world = m_scenes[0]->GetBlenderScene()->world; + if (world) + { + m_ticrate = world->ticrate; + m_maxLogicFrame = world->maxlogicstep; + m_maxPhysicsFrame = world->maxphystep; + } + else + { + m_ticrate = DEFAULT_LOGIC_TIC_RATE; + m_maxLogicFrame = 5; + m_maxPhysicsFrame = 5; + } if (m_game2ipo) { @@ -545,14 +560,13 @@ else // PIL_sleep_ms(1); KX_SceneList::iterator sceneit; - int frameOut = 5; - if (frames>frameOut) + if (frames>m_maxPhysicsFrame) { // printf("framedOut: %d\n",frames); - m_frameTime+=(frames-frameOut)*timestep; - frames = frameOut; + m_frameTime+=(frames-m_maxPhysicsFrame)*timestep; + frames = m_maxPhysicsFrame; } @@ -1736,6 +1750,16 @@ void KX_KetsjiEngine::SetMaxLogicFrame(int frame) m_maxLogicFrame = frame; } +int KX_KetsjiEngine::GetMaxPhysicsFrame() +{ + return m_maxPhysicsFrame; +} + +void KX_KetsjiEngine::SetMaxPhysicsFrame(int frame) +{ + m_maxPhysicsFrame = frame; +} + double KX_KetsjiEngine::GetAnimFrameRate() { return m_anim_framerate; |