OpenClonk
StdScheduler Class Reference

#include <StdScheduler.h>

Inheritance diagram for StdScheduler:
[legend]

Public Member Functions

 StdScheduler ()
 
virtual ~StdScheduler ()
 
int getProcCnt () const
 
bool hasProc (StdSchedulerProc *pProc)
 
bool IsInManualLoop ()
 
void Clear ()
 
void Set (StdSchedulerProc **ppProcs, int iProcCnt)
 
void Add (StdSchedulerProc *pProc)
 
void Remove (StdSchedulerProc *pProc)
 
void Added (StdSchedulerProc *pProc)
 
void Removing (StdSchedulerProc *pProc)
 
void Changed (StdSchedulerProc *pProc)
 
void StartOnCurrentThread ()
 
C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow)
 
bool ScheduleProcs (int iTimeout=1000/36)
 
void UnBlock ()
 

Protected Member Functions

virtual void OnError (StdSchedulerProc *)
 
virtual bool DoScheduleProcs (int iTimeout)
 

Detailed Description

Definition at line 220 of file StdScheduler.h.

Constructor & Destructor Documentation

◆ StdScheduler()

StdScheduler::StdScheduler ( )

Definition at line 59 of file StdScheduler.cpp.

60 {
61  Add(&Unblocker);
62 }
void Add(StdSchedulerProc *pProc)

◆ ~StdScheduler()

StdScheduler::~StdScheduler ( )
virtual

Definition at line 64 of file StdScheduler.cpp.

65 {
66  Clear();
67 }

Member Function Documentation

◆ Add()

void StdScheduler::Add ( StdSchedulerProc pProc)

◆ Added()

void StdScheduler::Added ( StdSchedulerProc pProc)

Definition at line 281 of file StdSchedulerMac.mm.

References SCHAdditions::assignAdditionForProc:, and SCHAdditions::requestAdditionsForScheduler:.

282 {
283  [[SCHAdditions requestAdditionsForScheduler:this] assignAdditionForProc:pProc];
284 }
Here is the call graph for this function:

◆ Changed()

void StdScheduler::Changed ( StdSchedulerProc pProc)

Definition at line 294 of file StdSchedulerMac.mm.

References SCHAdditions::additionForProc:, SCHAddition::changed, and SCHAdditions::requestAdditionsForScheduler:.

295 {
296  [[[SCHAdditions requestAdditionsForScheduler:this] additionForProc:pProc] changed];
297 }
Here is the call graph for this function:

◆ Clear()

void StdScheduler::Clear ( )

Definition at line 69 of file StdScheduler.cpp.

Referenced by StdSchedulerThread::Clear().

70 {
71  while (procs.size() > 0)
72  Remove(procs[procs.size()-1]);
73 }
void Remove(StdSchedulerProc *pProc)
Here is the caller graph for this function:

◆ DoScheduleProcs()

virtual bool StdScheduler::DoScheduleProcs ( int  iTimeout)
protectedvirtual

Reimplemented in C4AbstractApp.

Referenced by C4AbstractApp::DoScheduleProcs().

Here is the caller graph for this function:

◆ GetNextTick()

C4TimeMilliseconds StdScheduler::GetNextTick ( C4TimeMilliseconds  tNow)

Definition at line 120 of file StdScheduler.cpp.

References C4TimeMilliseconds::PositiveInfinity.

Referenced by C4AbstractApp::Run().

121 {
123  for (auto proc : procs)
124  {
125  tProcTick = std::min(tProcTick, proc->GetNextTick(tNow));
126  }
127  return tProcTick;
128 }
Here is the caller graph for this function:

◆ getProcCnt()

int StdScheduler::getProcCnt ( ) const
inline

Definition at line 245 of file StdScheduler.h.

Referenced by C4InteractiveThread::AddProc(), and C4InteractiveThread::RemoveProc().

245 { return procs.size()-1; } // ignore internal NoopNotifyProc
Here is the caller graph for this function:

◆ hasProc()

bool StdScheduler::hasProc ( StdSchedulerProc pProc)
inline

Definition at line 246 of file StdScheduler.h.

Referenced by C4InteractiveThread::RemoveProc().

246 { return std::find(procs.begin(), procs.end(), pProc) != procs.end(); }
Here is the caller graph for this function:

◆ IsInManualLoop()

bool StdScheduler::IsInManualLoop ( )
inline

Definition at line 247 of file StdScheduler.h.

References StdSchedulerProc::Changed(), and StdSchedulerProc::GetNextTick().

247 { return isInManualLoop; }
Here is the call graph for this function:

◆ OnError()

virtual void StdScheduler::OnError ( StdSchedulerProc )
inlineprotectedvirtual

Definition at line 268 of file StdScheduler.h.

268 { }

◆ Remove()

void StdScheduler::Remove ( StdSchedulerProc pProc)

Definition at line 96 of file StdScheduler.cpp.

Referenced by C4Application::Clear(), C4Network2::Clear(), C4GameLobby::ScenDesc::Deactivate(), C4Network2ResDlg::Deactivate(), C4GameOptionsList::Deactivate(), C4Network2::DeinitLeague(), C4Network2::InitialConnect::Execute(), StdSchedulerThread::Remove(), C4Network2::StopStreaming(), C4AbstractApp::~C4AbstractApp(), C4GameOverDlg::~C4GameOverDlg(), C4GameSec1Timer::~C4GameSec1Timer(), C4InteractiveThread::~C4InteractiveThread(), C4Network2ClientListBox::~C4Network2ClientListBox(), C4Network2ClientListDlg::~C4Network2ClientListDlg(), C4Network2Stats::~C4Network2Stats(), C4StartupNetDlg::~C4StartupNetDlg(), C4GameLobby::Countdown::~Countdown(), C4GUI::InfoDialog::~InfoDialog(), and C4GameLobby::MainDlg::~MainDlg().

97 {
98  // :o ?
99  if (pProc->scheduler != this)
100  return;
101  Removing(pProc);
102  pProc->scheduler = nullptr;
103  auto pos = std::find(procs.begin(), procs.end(), pProc);
104  if (pos != procs.end())
105  procs.erase(pos);
106 }
void Removing(StdSchedulerProc *pProc)
Here is the caller graph for this function:

◆ Removing()

void StdScheduler::Removing ( StdSchedulerProc pProc)

Definition at line 286 of file StdSchedulerMac.mm.

References SCHAdditions::requestAdditionsForScheduler:.

287 {
288  auto x = [SCHAdditions requestAdditionsForScheduler:this];
289  [x removeAdditionForProc:pProc];
290  if ([x numberOfAdditions] == 0)
291  [SCHAdditions removeAdditions:x];
292 }
Here is the call graph for this function:

◆ ScheduleProcs()

bool StdScheduler::ScheduleProcs ( int  iTimeout = 1000/36)

Definition at line 130 of file StdScheduler.cpp.

References StdSchedulerProc::GetNextTick(), and C4TimeMilliseconds::Now().

Referenced by C4AulDebug::DebugStep(), C4Network2::DoLobby(), C4GUI::Dialog::DoModal(), C4ScenarioListLoader::DoProcessCallback(), C4Network2::InitialConnect::Execute(), C4GUI::Dialog::Execute(), C4Network2::FinalInit(), C4Game::InitNetworkFromAddress(), C4Network2::LeaguePlrAuth(), C4Network2::LeagueStart(), C4AulDebug::Listen(), C4Network2::RetrieveRes(), C4AbstractApp::Run(), and C4AppDelegate::suggestQuitting:.

131 {
132  // Needs at least one process to work properly
133  if (!procs.size()) return false;
134 
135  // Get timeout
137  C4TimeMilliseconds tProcTick = GetNextTick(tNow);
138  if (iTimeout == -1 || tNow + iTimeout > tProcTick)
139  {
140  iTimeout = std::max<decltype(iTimeout)>(tProcTick - tNow, 0);
141  }
142 
143  bool old = isInManualLoop;
144  isInManualLoop = true;
145  bool res = DoScheduleProcs(iTimeout);
146  isInManualLoop = old;
147  return res;
148 }
C4TimeMilliseconds GetNextTick(C4TimeMilliseconds tNow)
virtual bool DoScheduleProcs(int iTimeout)
static C4TimeMilliseconds Now()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set()

void StdScheduler::Set ( StdSchedulerProc **  ppProcs,
int  iProcCnt 
)

Definition at line 75 of file StdScheduler.cpp.

Referenced by StdSchedulerThread::Set().

76 {
77  // Remove previous data
78  Clear();
79  // Copy new
80  for (int i = 0; i < inProcCnt; i++)
81  Add(ppnProcs[i]);
82 }
void Add(StdSchedulerProc *pProc)
Here is the caller graph for this function:

◆ StartOnCurrentThread()

void StdScheduler::StartOnCurrentThread ( )

Definition at line 276 of file StdSchedulerMac.mm.

References SCHAdditions::requestAdditionsForScheduler:, and SCHAdditions::start.

Referenced by C4AppDelegate::isEditorAndGameRunning.

277 {
278  [[SCHAdditions requestAdditionsForScheduler:this] start];
279 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnBlock()

void StdScheduler::UnBlock ( )

Definition at line 150 of file StdScheduler.cpp.

References StdSchedulerThread::StdSchedulerThread().

151 {
152  Unblocker.Notify();
153 }
Here is the call graph for this function:

The documentation for this class was generated from the following files: