Skip to content

Commit 4ba953d

Browse files
author
nitrocaster
committed
ISheduled: move data to ScheduledBase.
1 parent a8f5a35 commit 4ba953d

21 files changed

+84
-69
lines changed

src/xrEngine/ISheduled.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#include "stdafx.h"
22
#include "xrSheduler.h"
33
#include "xr_object.h"
4-
5-
ISheduled::ISheduled()
4+
// XXX: rename this file to ScheduledBase.cpp
5+
ScheduledBase::ScheduledBase()
66
{
77
shedule.t_min = 20;
88
shedule.t_max = 1000;
99
shedule.b_locked = FALSE;
1010
#ifdef DEBUG
11-
dbg_startframe = 1;
12-
dbg_update_shedule = 0;
11+
shedule.dbg_startframe = 1;
12+
shedule.dbg_update_shedule = 0;
1313
#endif
1414
}
1515

1616
extern BOOL g_bSheduleInProgress;
17-
ISheduled::~ISheduled()
17+
ScheduledBase::~ScheduledBase()
1818
{
1919
VERIFY2(
2020
!Engine.Sheduler.Registered(this),
@@ -28,26 +28,26 @@ ISheduled::~ISheduled()
2828
#endif // DEBUG
2929
}
3030

31-
void ISheduled::shedule_register()
31+
void ScheduledBase::shedule_register()
3232
{
3333
Engine.Sheduler.Register(this);
3434
}
3535

36-
void ISheduled::shedule_unregister()
36+
void ScheduledBase::shedule_unregister()
3737
{
3838
Engine.Sheduler.Unregister(this);
3939
}
4040

41-
void ISheduled::shedule_Update(u32 dt)
41+
void ScheduledBase::shedule_Update(u32 dt)
4242
{
4343
#ifdef DEBUG
44-
if (dbg_startframe == dbg_update_shedule)
44+
if (shedule.dbg_startframe == shedule.dbg_update_shedule)
4545
{
4646
LPCSTR name = "unknown";
4747
CObject* O = dynamic_cast<CObject*> (this);
4848
if (O) name = *O->cName();
4949
Debug.fatal(DEBUG_INFO, "'shedule_Update' called twice per frame for %s", name);
5050
}
51-
dbg_update_shedule = dbg_startframe;
51+
shedule.dbg_update_shedule = shedule.dbg_startframe;
5252
#endif
5353
}

src/xrEngine/ISheduled.h

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
11
#ifndef XRENGINE_ISHEDULED_H_INCLUDED
22
#define XRENGINE_ISHEDULED_H_INCLUDED
33

4-
class ENGINE_API ISheduled
4+
class SchedulerData
55
{
66
public:
7-
struct
8-
{
9-
u32 t_min : 14; // minimal bound of update time (sample: 20ms)
10-
u32 t_max : 14; // maximal bound of update time (sample: 200ms)
11-
u32 b_RT : 1;
12-
u32 b_locked : 1;
13-
} shedule;
14-
7+
u32 t_min : 14; // minimal bound of update time (sample: 20ms)
8+
u32 t_max : 14; // maximal bound of update time (sample: 200ms)
9+
u32 b_RT : 1;
10+
u32 b_locked : 1;
1511
#ifdef DEBUG
1612
u32 dbg_startframe;
1713
u32 dbg_update_shedule;
1814
#endif
15+
};
1916

20-
ISheduled();
21-
virtual ~ISheduled();
22-
23-
void shedule_register();
24-
void shedule_unregister();
25-
17+
class ISheduled
18+
{
19+
public:
20+
virtual ~ISheduled() = 0;
21+
virtual SchedulerData &GetSchedulerData() = 0;
2622
virtual float shedule_Scale() = 0;
27-
virtual void shedule_Update(u32 dt);
28-
virtual shared_str shedule_Name() const { return shared_str("unknown"); };
23+
virtual void shedule_Update(u32 dt) = 0;
24+
// XXX nitrocaster: return (const char *) to reduce string pool spoiling
25+
virtual shared_str shedule_Name() const = 0;
2926
virtual bool shedule_Needed() = 0;
27+
};
3028

29+
inline ISheduled::~ISheduled() {}
30+
31+
class ENGINE_API ScheduledBase : public ISheduled
32+
{
33+
public:
34+
SchedulerData shedule;
35+
36+
ScheduledBase();
37+
virtual ~ScheduledBase();
38+
39+
virtual SchedulerData &GetSchedulerData() override { return shedule; }
40+
virtual void shedule_Update(u32 dt) override;
41+
virtual shared_str shedule_Name() const override { return shared_str("unknown"); }
42+
43+
protected:
44+
void shedule_register();
45+
void shedule_unregister();
3146
};
3247

3348
#endif // #ifndef XRENGINE_ISHEDULED_H_INCLUDED

src/xrEngine/PS_instance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void CPS_Instance::shedule_Update(u32 dt)
4141
{
4242
if (renderable.pROS) GlobalEnv.Render->ros_destroy(renderable.pROS); //. particles doesn't need ROS
4343

44-
ISheduled::shedule_Update(dt);
44+
ScheduledBase::shedule_Update(dt);
4545
m_iLifeTime -= dt;
4646

4747
// remove???

src/xrEngine/PS_instance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class ENGINE_API CPS_Instance :
99
public SpatialBase,
10-
public ISheduled,
10+
public ScheduledBase,
1111
public IRenderable
1212
{
1313
friend class IGame_Persistent;

src/xrEngine/xrSheduler.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void CSheduler::internal_Registration()
104104

105105
void CSheduler::internal_Register(ISheduled* O, BOOL RT)
106106
{
107-
VERIFY(!O->shedule.b_locked);
107+
VERIFY(!O->GetSchedulerData().b_locked);
108108
if (RT)
109109
{
110110
// Fill item structure
@@ -113,7 +113,7 @@ void CSheduler::internal_Register(ISheduled* O, BOOL RT)
113113
TNext.dwTimeOfLastExecute = Device.dwTimeGlobal;
114114
TNext.Object = O;
115115
TNext.scheduled_name = O->shedule_Name();
116-
O->shedule.b_RT = TRUE;
116+
O->GetSchedulerData().b_RT = TRUE;
117117

118118
ItemsRT.push_back(TNext);
119119
}
@@ -125,7 +125,7 @@ void CSheduler::internal_Register(ISheduled* O, BOOL RT)
125125
TNext.dwTimeOfLastExecute = Device.dwTimeGlobal;
126126
TNext.Object = O;
127127
TNext.scheduled_name = O->shedule_Name();
128-
O->shedule.b_RT = FALSE;
128+
O->GetSchedulerData().b_RT = FALSE;
129129

130130
// Insert into priority Queue
131131
Push(TNext);
@@ -265,7 +265,7 @@ void CSheduler::Register(ISheduled* A, BOOL RT)
265265
R.OP = TRUE;
266266
R.RT = RT;
267267
R.Object = A;
268-
R.Object->shedule.b_RT = RT;
268+
R.Object->GetSchedulerData().b_RT = RT;
269269

270270
#ifdef DEBUG_SCHEDULER
271271
Msg("SCHEDULER: register [%s][%x]", *A->shedule_Name(), A);
@@ -284,21 +284,21 @@ void CSheduler::Unregister(ISheduled* A)
284284

285285
if (m_processing_now)
286286
{
287-
if (internal_Unregister(A, A->shedule.b_RT, false))
287+
if (internal_Unregister(A, A->GetSchedulerData().b_RT, false))
288288
return;
289289
}
290290

291291
ItemReg R;
292292
R.OP = FALSE;
293-
R.RT = A->shedule.b_RT;
293+
R.RT = A->GetSchedulerData().b_RT;
294294
R.Object = A;
295295

296296
Registration.push_back(R);
297297
}
298298

299299
void CSheduler::EnsureOrder(ISheduled* Before, ISheduled* After)
300300
{
301-
VERIFY(Before->shedule.b_RT && After->shedule.b_RT);
301+
VERIFY(Before->GetSchedulerData().b_RT && After->GetSchedulerData().b_RT);
302302

303303
for (u32 i = 0; i < ItemsRT.size(); i++)
304304
{
@@ -362,14 +362,14 @@ void CSheduler::ProcessStep()
362362
// Real update call
363363
// Msg ("------- %d:",Device.dwFrame);
364364
#ifdef DEBUG
365-
T.Object->dbg_startframe = Device.dwFrame;
365+
T.Object->GetSchedulerData().dbg_startframe = Device.dwFrame;
366366
eTimer.Start();
367367
// LPCSTR _obj_name = T.Object->shedule_Name().c_str();
368368
#endif // DEBUG
369369

370370
// Calc next update interval
371-
u32 dwMin = _max(u32(30), T.Object->shedule.t_min);
372-
u32 dwMax = (1000 + T.Object->shedule.t_max) / 2;
371+
u32 dwMin = _max(u32(30), T.Object->GetSchedulerData().t_min);
372+
u32 dwMax = (1000 + T.Object->GetSchedulerData().t_max) / 2;
373373
float scale = T.Object->shedule_Scale();
374374
u32 dwUpdate = dwMin + iFloor(float(dwMax - dwMin)*scale);
375375
clamp(dwUpdate, u32(_max(dwMin, u32(20))), dwMax);
@@ -378,7 +378,7 @@ void CSheduler::ProcessStep()
378378

379379
m_current_step_obj = T.Object;
380380
// try {
381-
T.Object->shedule_Update(clampr(Elapsed, u32(1), u32(_max(u32(T.Object->shedule.t_max), u32(1000)))));
381+
T.Object->shedule_Update(clampr(Elapsed, u32(1), u32(_max(u32(T.Object->GetSchedulerData().t_max), u32(1000)))));
382382
if (!m_current_step_obj)
383383
{
384384
#ifdef DEBUG_SCHEDULER
@@ -484,8 +484,8 @@ void CSheduler::Update()
484484

485485
u32 Elapsed = dwTime - T.dwTimeOfLastExecute;
486486
#ifdef DEBUG
487-
VERIFY(T.Object->dbg_startframe != Device.dwFrame);
488-
T.Object->dbg_startframe = Device.dwFrame;
487+
VERIFY(T.Object->GetSchedulerData().dbg_startframe != Device.dwFrame);
488+
T.Object->GetSchedulerData().dbg_startframe = Device.dwFrame;
489489
#endif
490490
T.Object->shedule_Update(Elapsed);
491491
T.dwTimeOfLastExecute = dwTime;

src/xrEngine/xr_object.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ CObject::CObject() :
170170
NameVisual = NULL;
171171

172172
#ifdef DEBUG
173-
dbg_update_shedule = u32(-1) / 2;
173+
shedule.dbg_update_shedule = u32(-1) / 2;
174174
dbg_update_cl = u32(-1) / 2;
175175
#endif
176176
}
@@ -347,7 +347,7 @@ void CObject::shedule_Update(u32 T)
347347
{
348348
// consistency check
349349
// Msg ("-SUB-:[%x][%s] CObject::shedule_Update",dynamic_cast<void*>(this),*cName());
350-
ISheduled::shedule_Update(T);
350+
ScheduledBase::shedule_Update(T);
351351
spatial_update(base_spu_epsP * 1, base_spu_epsR * 1);
352352

353353
// Always make me crow on shedule-update

src/xrEngine/xr_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ xr_pure_interface IObjectPhysicsCollision;
2929
class ENGINE_API CObject :
3030
public DLL_Pure,
3131
public SpatialBase,
32-
public ISheduled,
32+
public ScheduledBase,
3333
public IRenderable,
3434
public CollidableBase
3535
{

src/xrGame/GamePersistent.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,13 @@ void CGamePersistent::OnFrame ()
609609
if(psActorFlags.test(AF_NO_CLIP))
610610
{
611611
Actor()->dbg_update_cl = 0;
612-
Actor()->dbg_update_shedule = 0;
612+
Actor()->GetSchedulerData().dbg_update_shedule = 0;
613613
Device.dwTimeDelta = 0;
614614
Device.fTimeDelta = 0.01f;
615615
Actor()->UpdateCL ();
616616
Actor()->shedule_Update (0);
617617
Actor()->dbg_update_cl = 0;
618-
Actor()->dbg_update_shedule = 0;
618+
Actor()->GetSchedulerData().dbg_update_shedule = 0;
619619

620620
CSE_Abstract* e = Level().Server->ID_to_entity(Actor()->ID());
621621
VERIFY (e);
@@ -627,11 +627,11 @@ void CGamePersistent::OnFrame ()
627627
CObject* obj = Level().Objects.net_Find(*it);
628628
if(obj && Engine.Sheduler.Registered(obj))
629629
{
630-
obj->dbg_update_shedule = 0;
630+
obj->GetSchedulerData().dbg_update_shedule = 0;
631631
obj->dbg_update_cl = 0;
632632
obj->shedule_Update (0);
633633
obj->UpdateCL();
634-
obj->dbg_update_shedule = 0;
634+
obj->GetSchedulerData().dbg_update_shedule = 0;
635635
obj->dbg_update_cl = 0;
636636
}
637637
}

src/xrGame/Spectator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ void CSpectator::UpdateCL()
8585
{
8686
#ifdef DEBUG
8787
m_pActorToLookAt->dbg_update_cl = 0;
88-
m_pActorToLookAt->dbg_update_shedule = 0;
89-
Game().dbg_update_shedule = 0;
88+
m_pActorToLookAt->GetSchedulerData().dbg_update_shedule = 0;
89+
Game().GetSchedulerData().dbg_update_shedule = 0;
9090
#endif
9191
Device.dwTimeDelta = 0;
9292
m_pActorToLookAt->UpdateCL();
9393
m_pActorToLookAt->shedule_Update (0);
9494
Game().shedule_Update (0);
9595
#ifdef DEBUG
9696
m_pActorToLookAt->dbg_update_cl = 0;
97-
m_pActorToLookAt->dbg_update_shedule = 0;
98-
Game().dbg_update_shedule = 0;
97+
m_pActorToLookAt->GetSchedulerData().dbg_update_shedule = 0;
98+
Game().GetSchedulerData().dbg_update_shedule = 0;
9999
#endif
100100
}
101101
}
@@ -352,14 +352,14 @@ void CSpectator::FirstEye_ToPlayer(CObject* pObject)
352352
{
353353
#ifdef DEBUG
354354
pOldActor->dbg_update_cl = 0;
355-
pOldActor->dbg_update_shedule = 0;
355+
pOldActor->GetSchedulerData().dbg_update_shedule = 0;
356356
#endif
357357
Device.dwTimeDelta = 0;
358358
pOldActor->UpdateCL ();
359359
pOldActor->shedule_Update (0);
360360
#ifdef DEBUG
361361
pOldActor->dbg_update_cl = 0;
362-
pOldActor->dbg_update_shedule = 0;
362+
pOldActor->GetSchedulerData().dbg_update_shedule = 0;
363363
#endif
364364
}
365365
};

src/xrGame/agent_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void CAgentManager::shedule_Update (u32 time_delta)
103103
{
104104
START_PROFILE("Agent_Manager")
105105

106-
ISheduled::shedule_Update (time_delta);
106+
ScheduledBase::shedule_Update (time_delta);
107107

108108
update_impl ();
109109

0 commit comments

Comments
 (0)