Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2009-05-01 20:35:06 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2009-05-01 20:35:06 +0400
commit672492f563e148dc608965c5d0011413fbfae0eb (patch)
tree57aa0b79b8de32cef7ce3dee32e6013045e30d76 /source/gameengine/Ketsji/KX_KetsjiEngine.cpp
parent1c6cd47f2b93ba05c54f82c9363f269c71e28cda (diff)
BGE: New function GameLogic.setMaxLogicFrame() to allow better control over the time spent on logic.
This function sets the maximum number of logic frame executed per render frame. Valid values: 1..5 This function is useful to control the amount of processing consumed by logic. By default, up to 5 logic frames can be executed per render frame. This is fine as long as the time spent on logic is negligible compared to the render time. If it's not the case, the default value will drag the performance of the game down by executing unnecessary logic frames that take up most of the CPU time. You can avoid that by lowering the value with this function. The drawback is less precision in the logic system to physics and I/O activity. Note that it does not affect the physics system: physics will still run at full frame rate (actually up to 5 times the ticrate). You can further control the render frame rate with GameLogic.setLogicTicRate().
Diffstat (limited to 'source/gameengine/Ketsji/KX_KetsjiEngine.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index 764c3c2dfec..d6747bd1ba4 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -97,6 +97,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;
double KX_KetsjiEngine::m_anim_framerate = 25.0;
double KX_KetsjiEngine::m_suspendedtime = 0.0;
double KX_KetsjiEngine::m_suspendeddelta = 0.0;
@@ -399,6 +400,7 @@ void KX_KetsjiEngine::StartEngine(bool clearIpo)
m_firstframe = true;
m_bInitialized = true;
m_ticrate = DEFAULT_LOGIC_TIC_RATE;
+ m_maxLogicFrame = 5;
if (m_game2ipo)
{
@@ -511,7 +513,8 @@ void KX_KetsjiEngine::EndFrame()
bool KX_KetsjiEngine::NextFrame()
{
-
+ double timestep = 1.0/m_ticrate;
+ double framestep = timestep;
// static hidden::Clock sClock;
m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(),true);
@@ -520,7 +523,7 @@ m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(),true);
//sClock.reset();
if (m_bFixedTime)
- m_clockTime += 1./m_ticrate;
+ m_clockTime += timestep;
else
{
@@ -554,18 +557,24 @@ else
{
// printf("framedOut: %d\n",frames);
- m_frameTime+=(frames-frameOut)*(1.0/m_ticrate);
+ m_frameTime+=(frames-frameOut)*timestep;
frames = frameOut;
}
bool doRender = frames>0;
+ if (frames > m_maxLogicFrame)
+ {
+ framestep = (frames*timestep)/m_maxLogicFrame;
+ frames = m_maxLogicFrame;
+ }
+
while (frames)
{
- m_frameTime += 1.0/m_ticrate;
+ m_frameTime += framestep;
for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
// for each scene, call the proceed functions
@@ -644,7 +653,7 @@ else
// Perform physics calculations on the scene. This can involve
// many iterations of the physics solver.
- scene->GetPhysicsEnvironment()->proceedDeltaTime(m_frameTime,1.0/m_ticrate);//m_deltatimerealDeltaTime);
+ scene->GetPhysicsEnvironment()->proceedDeltaTime(m_frameTime,timestep,framestep);//m_deltatimerealDeltaTime);
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
SG_SetActiveStage(SG_STAGE_PHYSICS2_UPDATE);
@@ -717,7 +726,7 @@ else
// Perform physics calculations on the scene. This can involve
// many iterations of the physics solver.
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
- scene->GetPhysicsEnvironment()->proceedDeltaTime(m_clockTime,0.f);
+ scene->GetPhysicsEnvironment()->proceedDeltaTime(m_clockTime,timestep,timestep);
// Update scenegraph after physics step. This maps physics calculations
// into node positions.
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
@@ -1729,6 +1738,16 @@ void KX_KetsjiEngine::SetTicRate(double ticrate)
m_ticrate = ticrate;
}
+int KX_KetsjiEngine::GetMaxLogicFrame()
+{
+ return m_maxLogicFrame;
+}
+
+void KX_KetsjiEngine::SetMaxLogicFrame(int frame)
+{
+ m_maxLogicFrame = frame;
+}
+
double KX_KetsjiEngine::GetAnimFrameRate()
{
return m_anim_framerate;