Skip to content

Commit

Permalink
ISheduled: move data to ScheduledBase.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Nov 11, 2015
1 parent a8f5a35 commit 4ba953d
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 69 deletions.
20 changes: 10 additions & 10 deletions src/xrEngine/ISheduled.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include "stdafx.h"
#include "xrSheduler.h"
#include "xr_object.h"

ISheduled::ISheduled()
// XXX: rename this file to ScheduledBase.cpp
ScheduledBase::ScheduledBase()
{
shedule.t_min = 20;
shedule.t_max = 1000;
shedule.b_locked = FALSE;
#ifdef DEBUG
dbg_startframe = 1;
dbg_update_shedule = 0;
shedule.dbg_startframe = 1;
shedule.dbg_update_shedule = 0;
#endif
}

extern BOOL g_bSheduleInProgress;
ISheduled::~ISheduled()
ScheduledBase::~ScheduledBase()
{
VERIFY2(
!Engine.Sheduler.Registered(this),
Expand All @@ -28,26 +28,26 @@ ISheduled::~ISheduled()
#endif // DEBUG
}

void ISheduled::shedule_register()
void ScheduledBase::shedule_register()
{
Engine.Sheduler.Register(this);
}

void ISheduled::shedule_unregister()
void ScheduledBase::shedule_unregister()
{
Engine.Sheduler.Unregister(this);
}

void ISheduled::shedule_Update(u32 dt)
void ScheduledBase::shedule_Update(u32 dt)
{
#ifdef DEBUG
if (dbg_startframe == dbg_update_shedule)
if (shedule.dbg_startframe == shedule.dbg_update_shedule)
{
LPCSTR name = "unknown";
CObject* O = dynamic_cast<CObject*> (this);
if (O) name = *O->cName();
Debug.fatal(DEBUG_INFO, "'shedule_Update' called twice per frame for %s", name);
}
dbg_update_shedule = dbg_startframe;
shedule.dbg_update_shedule = shedule.dbg_startframe;
#endif
}
49 changes: 32 additions & 17 deletions src/xrEngine/ISheduled.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
#ifndef XRENGINE_ISHEDULED_H_INCLUDED
#define XRENGINE_ISHEDULED_H_INCLUDED

class ENGINE_API ISheduled
class SchedulerData
{
public:
struct
{
u32 t_min : 14; // minimal bound of update time (sample: 20ms)
u32 t_max : 14; // maximal bound of update time (sample: 200ms)
u32 b_RT : 1;
u32 b_locked : 1;
} shedule;

u32 t_min : 14; // minimal bound of update time (sample: 20ms)
u32 t_max : 14; // maximal bound of update time (sample: 200ms)
u32 b_RT : 1;
u32 b_locked : 1;
#ifdef DEBUG
u32 dbg_startframe;
u32 dbg_update_shedule;
#endif
};

ISheduled();
virtual ~ISheduled();

void shedule_register();
void shedule_unregister();

class ISheduled
{
public:
virtual ~ISheduled() = 0;
virtual SchedulerData &GetSchedulerData() = 0;
virtual float shedule_Scale() = 0;
virtual void shedule_Update(u32 dt);
virtual shared_str shedule_Name() const { return shared_str("unknown"); };
virtual void shedule_Update(u32 dt) = 0;
// XXX nitrocaster: return (const char *) to reduce string pool spoiling
virtual shared_str shedule_Name() const = 0;
virtual bool shedule_Needed() = 0;
};

inline ISheduled::~ISheduled() {}

class ENGINE_API ScheduledBase : public ISheduled
{
public:
SchedulerData shedule;

ScheduledBase();
virtual ~ScheduledBase();

virtual SchedulerData &GetSchedulerData() override { return shedule; }
virtual void shedule_Update(u32 dt) override;
virtual shared_str shedule_Name() const override { return shared_str("unknown"); }

protected:
void shedule_register();
void shedule_unregister();
};

#endif // #ifndef XRENGINE_ISHEDULED_H_INCLUDED
2 changes: 1 addition & 1 deletion src/xrEngine/PS_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void CPS_Instance::shedule_Update(u32 dt)
{
if (renderable.pROS) GlobalEnv.Render->ros_destroy(renderable.pROS); //. particles doesn't need ROS

ISheduled::shedule_Update(dt);
ScheduledBase::shedule_Update(dt);
m_iLifeTime -= dt;

// remove???
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/PS_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ENGINE_API CPS_Instance :
public SpatialBase,
public ISheduled,
public ScheduledBase,
public IRenderable
{
friend class IGame_Persistent;
Expand Down
26 changes: 13 additions & 13 deletions src/xrEngine/xrSheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void CSheduler::internal_Registration()

void CSheduler::internal_Register(ISheduled* O, BOOL RT)
{
VERIFY(!O->shedule.b_locked);
VERIFY(!O->GetSchedulerData().b_locked);
if (RT)
{
// Fill item structure
Expand All @@ -113,7 +113,7 @@ void CSheduler::internal_Register(ISheduled* O, BOOL RT)
TNext.dwTimeOfLastExecute = Device.dwTimeGlobal;
TNext.Object = O;
TNext.scheduled_name = O->shedule_Name();
O->shedule.b_RT = TRUE;
O->GetSchedulerData().b_RT = TRUE;

ItemsRT.push_back(TNext);
}
Expand All @@ -125,7 +125,7 @@ void CSheduler::internal_Register(ISheduled* O, BOOL RT)
TNext.dwTimeOfLastExecute = Device.dwTimeGlobal;
TNext.Object = O;
TNext.scheduled_name = O->shedule_Name();
O->shedule.b_RT = FALSE;
O->GetSchedulerData().b_RT = FALSE;

// Insert into priority Queue
Push(TNext);
Expand Down Expand Up @@ -265,7 +265,7 @@ void CSheduler::Register(ISheduled* A, BOOL RT)
R.OP = TRUE;
R.RT = RT;
R.Object = A;
R.Object->shedule.b_RT = RT;
R.Object->GetSchedulerData().b_RT = RT;

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

if (m_processing_now)
{
if (internal_Unregister(A, A->shedule.b_RT, false))
if (internal_Unregister(A, A->GetSchedulerData().b_RT, false))
return;
}

ItemReg R;
R.OP = FALSE;
R.RT = A->shedule.b_RT;
R.RT = A->GetSchedulerData().b_RT;
R.Object = A;

Registration.push_back(R);
}

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

for (u32 i = 0; i < ItemsRT.size(); i++)
{
Expand Down Expand Up @@ -362,14 +362,14 @@ void CSheduler::ProcessStep()
// Real update call
// Msg ("------- %d:",Device.dwFrame);
#ifdef DEBUG
T.Object->dbg_startframe = Device.dwFrame;
T.Object->GetSchedulerData().dbg_startframe = Device.dwFrame;
eTimer.Start();
// LPCSTR _obj_name = T.Object->shedule_Name().c_str();
#endif // DEBUG

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

m_current_step_obj = T.Object;
// try {
T.Object->shedule_Update(clampr(Elapsed, u32(1), u32(_max(u32(T.Object->shedule.t_max), u32(1000)))));
T.Object->shedule_Update(clampr(Elapsed, u32(1), u32(_max(u32(T.Object->GetSchedulerData().t_max), u32(1000)))));
if (!m_current_step_obj)
{
#ifdef DEBUG_SCHEDULER
Expand Down Expand Up @@ -484,8 +484,8 @@ void CSheduler::Update()

u32 Elapsed = dwTime - T.dwTimeOfLastExecute;
#ifdef DEBUG
VERIFY(T.Object->dbg_startframe != Device.dwFrame);
T.Object->dbg_startframe = Device.dwFrame;
VERIFY(T.Object->GetSchedulerData().dbg_startframe != Device.dwFrame);
T.Object->GetSchedulerData().dbg_startframe = Device.dwFrame;
#endif
T.Object->shedule_Update(Elapsed);
T.dwTimeOfLastExecute = dwTime;
Expand Down
4 changes: 2 additions & 2 deletions src/xrEngine/xr_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ CObject::CObject() :
NameVisual = NULL;

#ifdef DEBUG
dbg_update_shedule = u32(-1) / 2;
shedule.dbg_update_shedule = u32(-1) / 2;
dbg_update_cl = u32(-1) / 2;
#endif
}
Expand Down Expand Up @@ -347,7 +347,7 @@ void CObject::shedule_Update(u32 T)
{
// consistency check
// Msg ("-SUB-:[%x][%s] CObject::shedule_Update",dynamic_cast<void*>(this),*cName());
ISheduled::shedule_Update(T);
ScheduledBase::shedule_Update(T);
spatial_update(base_spu_epsP * 1, base_spu_epsR * 1);

// Always make me crow on shedule-update
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/xr_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ xr_pure_interface IObjectPhysicsCollision;
class ENGINE_API CObject :
public DLL_Pure,
public SpatialBase,
public ISheduled,
public ScheduledBase,
public IRenderable,
public CollidableBase
{
Expand Down
8 changes: 4 additions & 4 deletions src/xrGame/GamePersistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,13 @@ void CGamePersistent::OnFrame ()
if(psActorFlags.test(AF_NO_CLIP))
{
Actor()->dbg_update_cl = 0;
Actor()->dbg_update_shedule = 0;
Actor()->GetSchedulerData().dbg_update_shedule = 0;
Device.dwTimeDelta = 0;
Device.fTimeDelta = 0.01f;
Actor()->UpdateCL ();
Actor()->shedule_Update (0);
Actor()->dbg_update_cl = 0;
Actor()->dbg_update_shedule = 0;
Actor()->GetSchedulerData().dbg_update_shedule = 0;

CSE_Abstract* e = Level().Server->ID_to_entity(Actor()->ID());
VERIFY (e);
Expand All @@ -627,11 +627,11 @@ void CGamePersistent::OnFrame ()
CObject* obj = Level().Objects.net_Find(*it);
if(obj && Engine.Sheduler.Registered(obj))
{
obj->dbg_update_shedule = 0;
obj->GetSchedulerData().dbg_update_shedule = 0;
obj->dbg_update_cl = 0;
obj->shedule_Update (0);
obj->UpdateCL();
obj->dbg_update_shedule = 0;
obj->GetSchedulerData().dbg_update_shedule = 0;
obj->dbg_update_cl = 0;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/xrGame/Spectator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ void CSpectator::UpdateCL()
{
#ifdef DEBUG
m_pActorToLookAt->dbg_update_cl = 0;
m_pActorToLookAt->dbg_update_shedule = 0;
Game().dbg_update_shedule = 0;
m_pActorToLookAt->GetSchedulerData().dbg_update_shedule = 0;
Game().GetSchedulerData().dbg_update_shedule = 0;
#endif
Device.dwTimeDelta = 0;
m_pActorToLookAt->UpdateCL();
m_pActorToLookAt->shedule_Update (0);
Game().shedule_Update (0);
#ifdef DEBUG
m_pActorToLookAt->dbg_update_cl = 0;
m_pActorToLookAt->dbg_update_shedule = 0;
Game().dbg_update_shedule = 0;
m_pActorToLookAt->GetSchedulerData().dbg_update_shedule = 0;
Game().GetSchedulerData().dbg_update_shedule = 0;
#endif
}
}
Expand Down Expand Up @@ -352,14 +352,14 @@ void CSpectator::FirstEye_ToPlayer(CObject* pObject)
{
#ifdef DEBUG
pOldActor->dbg_update_cl = 0;
pOldActor->dbg_update_shedule = 0;
pOldActor->GetSchedulerData().dbg_update_shedule = 0;
#endif
Device.dwTimeDelta = 0;
pOldActor->UpdateCL ();
pOldActor->shedule_Update (0);
#ifdef DEBUG
pOldActor->dbg_update_cl = 0;
pOldActor->dbg_update_shedule = 0;
pOldActor->GetSchedulerData().dbg_update_shedule = 0;
#endif
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/agent_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void CAgentManager::shedule_Update (u32 time_delta)
{
START_PROFILE("Agent_Manager")

ISheduled::shedule_Update (time_delta);
ScheduledBase::shedule_Update (time_delta);

update_impl ();

Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/agent_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CAgentManagerPlanner;
//#define USE_SCHEDULER_IN_AGENT_MANAGER

#ifdef USE_SCHEDULER_IN_AGENT_MANAGER
class CAgentManager : public ISheduled {
class CAgentManager : public ScheduledBase {
#else // USE_SCHEDULER_IN_AGENT_MANAGER
class CAgentManager {
#endif // USE_SCHEDULER_IN_AGENT_MANAGER
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/alife_update_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void CALifeUpdateManager::update ()

void CALifeUpdateManager::shedule_Update (u32 dt)
{
ISheduled::shedule_Update (dt);
ScheduledBase::shedule_Update (dt);

if (!initialized())
return;
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/alife_update_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CALifeUpdateManager :
public CALifeSwitchManager,
public CALifeSurgeManager,
public CALifeStorageManager,
public ISheduled
public ScheduledBase
{
private:
bool m_first_time;
Expand Down
4 changes: 2 additions & 2 deletions src/xrGame/autosave_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#pragma once

class CAutosaveManager : public ISheduled {
class CAutosaveManager : public ScheduledBase {
private:
typedef ISheduled inherited;
typedef ScheduledBase inherited;

private:
u32 m_autosave_interval;
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/configs_dumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class dump_signer : public xr_dsa_signer
void feel_private_dsa_key ();
};

class configs_dumper : public ISheduled
class configs_dumper : public ScheduledBase
{
public:
typedef fastdelegate::FastDelegate3<u8 const*, u32, u32, void> complete_callback_t;
Expand Down
Loading

0 comments on commit 4ba953d

Please sign in to comment.