Skip to content

Commit 459c393

Browse files
committed
UPBGE: Refactor scene suspended time managment.
Previously when a scene was suspended, the function UpdateSuspendedScenes was checking that the suspended scene has a valid suspended time, this value is the clock time when the scene was suspended. If this value was to zero it was set. After, when the scene was resumed, the same function checked if the suspended time was not zero, in this case the scene was just resumed, the delta suspended time (the time passed during the scene suspend) wad set and the suspended time was set to zero. This mechanism is to complicated for the informations we need, indeed only the suspended delta time is used for animations. This delta time could be incremented each frame by the frame step. So the suspended time of a scene is removed and UpdateSuspendedScenes get as argument the frame step which is incremented to the scene suspended delta time. Tested with #D1569.
1 parent a09fbbb commit 459c393

File tree

5 files changed

+14
-59
lines changed

5 files changed

+14
-59
lines changed

source/gameengine/Ketsji/BL_Action.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ bool BL_Action::Play(const std::string& name,
246246
}
247247

248248
// Now that we have an action, we have something we can play
249-
m_starttime = KX_GetActiveEngine()->GetFrameTime() - kxscene->getSuspendedDelta();
249+
m_starttime = KX_GetActiveEngine()->GetFrameTime() - kxscene->GetSuspendedDelta();
250250
m_startframe = m_localframe = start;
251251
m_endframe = end;
252252
m_blendin = blendin;
@@ -379,7 +379,8 @@ void BL_Action::Update(float curtime, bool applyToObject)
379379
}
380380
m_prevUpdate = curtime;
381381

382-
curtime -= (float)KX_KetsjiEngine::GetSuspendedDelta();
382+
KX_Scene *scene = m_obj->GetScene();
383+
curtime -= (float)scene->GetSuspendedDelta();
383384

384385
if (m_calc_localtime)
385386
SetLocalTime(curtime);

source/gameengine/Ketsji/KX_KetsjiEngine.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ double KX_KetsjiEngine::m_ticrate = DEFAULT_LOGIC_TIC_RATE;
102102
int KX_KetsjiEngine::m_maxLogicFrame = 5;
103103
int KX_KetsjiEngine::m_maxPhysicsFrame = 5;
104104
double KX_KetsjiEngine::m_anim_framerate = 25.0;
105-
double KX_KetsjiEngine::m_suspendedtime = 0.0;
106-
double KX_KetsjiEngine::m_suspendeddelta = 0.0;
107105
double KX_KetsjiEngine::m_average_framerate = 0.0;
108106
bool KX_KetsjiEngine::m_restrict_anim_fps = false;
109107
short KX_KetsjiEngine::m_exitkey = 130; // ESC Key
@@ -480,7 +478,7 @@ bool KX_KetsjiEngine::NextFrame()
480478
m_inputDevice->ClearInputs();
481479
}
482480

483-
UpdateSuspendedScenes();
481+
UpdateSuspendedScenes(framestep);
484482
// scene management
485483
ProcessScheduledScenes();
486484

@@ -493,21 +491,12 @@ bool KX_KetsjiEngine::NextFrame()
493491
return doRender && m_doRender;
494492
}
495493

496-
void KX_KetsjiEngine::UpdateSuspendedScenes()
494+
void KX_KetsjiEngine::UpdateSuspendedScenes(double framestep)
497495
{
498496
for (CListValue::iterator<KX_Scene> sceneit = m_scenes->GetBegin(), sceneend = m_scenes->GetEnd(); sceneit != sceneend; ++sceneit) {
499497
KX_Scene *scene = *sceneit;
500498
if (scene->IsSuspended()) {
501-
if (scene->getSuspendedTime() == 0.0f) {
502-
scene->setSuspendedTime(m_clockTime);
503-
}
504-
}
505-
else {
506-
// if the scene was suspended recalcutlate the delta to "curtime"
507-
if (scene->getSuspendedTime() != 0.0f) {
508-
scene->setSuspendedDelta(scene->getSuspendedDelta() + m_clockTime - scene->getSuspendedTime());
509-
}
510-
scene->setSuspendedTime(0.0f);
499+
scene->SetSuspendedDelta(scene->GetSuspendedDelta() + framestep);
511500
}
512501
}
513502
}
@@ -800,8 +789,6 @@ void KX_KetsjiEngine::UpdateAnimations(KX_Scene *scene)
800789
return;
801790
}
802791

803-
// Set scene total pause duration, used for animations played on scene which was suspended.
804-
m_suspendeddelta = scene->getSuspendedDelta();
805792
// Handle the animations independently of the logic time step
806793
if (GetRestrictAnimationFPS()) {
807794
double anim_timestep = 1.0 / scene->GetAnimationFPS();
@@ -1489,11 +1476,6 @@ bool KX_KetsjiEngine::GetUseExternalClock(void) const
14891476
return m_useExternalClock;
14901477
}
14911478

1492-
double KX_KetsjiEngine::GetSuspendedDelta()
1493-
{
1494-
return m_suspendeddelta;
1495-
}
1496-
14971479
double KX_KetsjiEngine::GetTicRate()
14981480
{
14991481
return m_ticrate;

source/gameengine/Ketsji/KX_KetsjiEngine.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ class KX_KetsjiEngine
139139

140140
static bool m_restrict_anim_fps;
141141

142-
static double m_suspendedtime;
143-
static double m_suspendeddelta;
144-
145142
static bool m_doRender; /* whether or not the scene should be rendered after the logic frame */
146143

147144
/// Key used to exit the BGE
@@ -221,9 +218,9 @@ class KX_KetsjiEngine
221218
* The render functions, called after and which update animations,
222219
* will see the first scene as active and will proceed to it,
223220
* but it will cause some negative current frame on actions because of the
224-
* total pause duration not setted.
221+
* total pause duration not set.
225222
*/
226-
void UpdateSuspendedScenes();
223+
void UpdateSuspendedScenes(double framestep);
227224

228225
/// Update and return the projection matrix of a camera depending on the viewport.
229226
const MT_Matrix4x4& GetCameraProjectionMatrix(KX_Scene *scene, KX_Camera *cam, const RAS_Rect& viewport, const RAS_Rect& area);
@@ -361,12 +358,6 @@ class KX_KetsjiEngine
361358
*/
362359
double GetRealTime(void) const;
363360

364-
/**
365-
* Returns the difference between the local time of the scene (when it
366-
* was running and not suspended) and the "curtime"
367-
*/
368-
static double GetSuspendedDelta();
369-
370361
/**
371362
* Gets the number of logic updates per second.
372363
*/

source/gameengine/Ketsji/KX_Scene.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,11 @@ KX_Scene::KX_Scene(SCA_IInputDevice *inputDevice,
151151
m_sceneName(sceneName),
152152
m_active_camera(nullptr),
153153
m_ueberExecutionPriority(0),
154+
m_suspendeddelta(0.0),
154155
m_blenderScene(scene),
155156
m_isActivedHysteresis(false),
156157
m_lodHysteresisValue(0)
157158
{
158-
m_suspendedtime = 0.0;
159-
m_suspendeddelta = 0.0;
160159

161160
m_dbvt_culling = false;
162161
m_dbvt_occlusion_res = 0;
@@ -1817,19 +1816,11 @@ void KX_Scene::SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv)
18171816
}
18181817
}
18191818

1820-
void KX_Scene::setSuspendedTime(double suspendedtime)
1821-
{
1822-
m_suspendedtime = suspendedtime;
1823-
}
1824-
double KX_Scene::getSuspendedTime()
1825-
{
1826-
return m_suspendedtime;
1827-
}
1828-
void KX_Scene::setSuspendedDelta(double suspendeddelta)
1819+
void KX_Scene::SetSuspendedDelta(double suspendeddelta)
18291820
{
18301821
m_suspendeddelta = suspendeddelta;
18311822
}
1832-
double KX_Scene::getSuspendedDelta()
1823+
double KX_Scene::GetSuspendedDelta() const
18331824
{
18341825
return m_suspendeddelta;
18351826
}

source/gameengine/Ketsji/KX_Scene.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class KX_Scene : public CValue, public SCA_IScene
248248
* Suspend (freeze) the entire scene.
249249
*/
250250
bool m_suspend;
251+
double m_suspendeddelta;
251252

252253
/**
253254
* Radius in Manhattan distance of the box for activity culling.
@@ -287,9 +288,6 @@ class KX_Scene : public CValue, public SCA_IScene
287288
void MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj, KX_Camera*cam, int layer=0);
288289
static void PhysicsCullingCallback(KX_ClientObjectInfo* objectInfo, void* cullingInfo);
289290

290-
double m_suspendedtime;
291-
double m_suspendeddelta;
292-
293291
struct Scene* m_blenderScene;
294292

295293
KX_2DFilterManager *m_filterManager;
@@ -596,24 +594,16 @@ class KX_Scene : public CValue, public SCA_IScene
596594
void RunDrawingCallbacks(DrawingCallbackType callbackType, KX_Camera *camera);
597595
#endif
598596

599-
/**
600-
* Sets the time the scene was suspended
601-
*/
602-
void setSuspendedTime(double suspendedtime);
603-
/**
604-
* Returns the "curtime" the scene was suspended
605-
*/
606-
double getSuspendedTime();
607597
/**
608598
* Sets the difference between the local time of the scene (when it
609599
* was running and not suspended) and the "curtime"
610600
*/
611-
void setSuspendedDelta(double suspendeddelta);
601+
void SetSuspendedDelta(double suspendeddelta);
612602
/**
613603
* Returns the difference between the local time of the scene (when it
614604
* was running and not suspended) and the "curtime"
615605
*/
616-
double getSuspendedDelta();
606+
double GetSuspendedDelta() const;
617607
/**
618608
* Returns the Blender scene this was made from
619609
*/

0 commit comments

Comments
 (0)