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)

References Add().

Here is the call graph for this function:

◆ ~StdScheduler()

StdScheduler::~StdScheduler ( )
virtual

Definition at line 64 of file StdScheduler.cpp.

65 {
66  Clear();
67 }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Add()

void StdScheduler::Add ( StdSchedulerProc pProc)

Definition at line 84 of file StdScheduler.cpp.

85 {
86  // Already added to some scheduler
87  if (pProc->scheduler)
88  return;
89  // Add
90  procs.push_back(pProc);
91  pProc->scheduler = this;
92 
93  Added(pProc);
94 }
void Added(StdSchedulerProc *pProc)

References Added().

Referenced by C4GameLobby::ScenDesc::Activate(), C4GameOptionsList::Activate(), C4Network2ResDlg::Activate(), StdSchedulerThread::Add(), C4GameOverDlg::C4GameOverDlg(), C4GameSec1Timer::C4GameSec1Timer(), C4InteractiveThread::C4InteractiveThread(), C4Network2ClientListBox::C4Network2ClientListBox(), C4Network2ClientListDlg::C4Network2ClientListDlg(), C4Network2Stats::C4Network2Stats(), C4StartupModsDlg::C4StartupModsDlg(), C4StartupModsDownloader::C4StartupModsDownloader(), C4StartupNetDlg::C4StartupNetDlg(), C4GameLobby::Countdown::Countdown(), C4Application::DoInit(), C4GUI::InfoDialog::InfoDialog(), C4Network2::InitHost(), C4Network2::InitialConnect::InitialConnect(), C4Network2::InitLeague(), C4AulDebug::Listen(), C4GameLobby::MainDlg::MainDlg(), Set(), C4Network2::StartStreaming(), and StdScheduler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Added()

void StdScheduler::Added ( StdSchedulerProc pProc)

Definition at line 281 of file StdSchedulerMac.mm.

282 {
283  [[SCHAdditions requestAdditionsForScheduler:this] assignAdditionForProc:pProc];
284 }

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

Referenced by Add().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Changed()

void StdScheduler::Changed ( StdSchedulerProc pProc)

Definition at line 294 of file StdSchedulerMac.mm.

295 {
296  [[[SCHAdditions requestAdditionsForScheduler:this] additionForProc:pProc] changed];
297 }

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

Here is the call graph for this function:

◆ Clear()

void StdScheduler::Clear ( )

Definition at line 69 of file StdScheduler.cpp.

70 {
71  while (procs.size() > 0)
72  Remove(procs[procs.size()-1]);
73 }
void Remove(StdSchedulerProc *pProc)

References Remove().

Referenced by StdSchedulerThread::Clear(), Set(), and ~StdScheduler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoScheduleProcs()

virtual bool StdScheduler::DoScheduleProcs ( int  iTimeout)
protectedvirtual

Reimplemented in C4AbstractApp.

Referenced by C4AbstractApp::DoScheduleProcs(), and ScheduleProcs().

Here is the caller graph for this function:

◆ GetNextTick()

C4TimeMilliseconds StdScheduler::GetNextTick ( C4TimeMilliseconds  tNow)

Definition at line 120 of file StdScheduler.cpp.

121 {
123  for (auto proc : procs)
124  {
125  tProcTick = std::min(tProcTick, proc->GetNextTick(tNow));
126  }
127  return tProcTick;
128 }

References C4TimeMilliseconds::PositiveInfinity.

Referenced by C4AbstractApp::Run(), and ScheduleProcs().

Here is the caller graph for this function:

◆ getProcCnt()

int StdScheduler::getProcCnt ( ) const
inline

Definition at line 245 of file StdScheduler.h.

245 { return procs.size()-1; } // ignore internal NoopNotifyProc

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

Here is the caller graph for this function:

◆ hasProc()

bool StdScheduler::hasProc ( StdSchedulerProc pProc)
inline

Definition at line 246 of file StdScheduler.h.

246 { return std::find(procs.begin(), procs.end(), pProc) != procs.end(); }

Referenced by C4InteractiveThread::RemoveProc().

Here is the caller graph for this function:

◆ IsInManualLoop()

bool StdScheduler::IsInManualLoop ( )
inline

Definition at line 247 of file StdScheduler.h.

247 { return isInManualLoop; }

◆ 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.

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)

References Removing().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Removing()

void StdScheduler::Removing ( StdSchedulerProc pProc)

Definition at line 286 of file StdSchedulerMac.mm.

287 {
288  auto x = [SCHAdditions requestAdditionsForScheduler:this];
289  [x removeAdditionForProc:pProc];
290  if ([x numberOfAdditions] == 0)
291  [SCHAdditions removeAdditions:x];
292 }

References SCHAdditions::requestAdditionsForScheduler:.

Referenced by Remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScheduleProcs()

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

Definition at line 130 of file StdScheduler.cpp.

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 }
static C4TimeMilliseconds Now()
virtual bool DoScheduleProcs(int iTimeout)
C4TimeMilliseconds GetNextTick(C4TimeMilliseconds tNow)

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

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

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.

76 {
77  // Remove previous data
78  Clear();
79  // Copy new
80  for (int i = 0; i < inProcCnt; i++)
81  Add(ppnProcs[i]);
82 }

References Add(), and Clear().

Referenced by StdSchedulerThread::Set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartOnCurrentThread()

void StdScheduler::StartOnCurrentThread ( )

Definition at line 276 of file StdSchedulerMac.mm.

277 {
278  [[SCHAdditions requestAdditionsForScheduler:this] start];
279 }

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

Here is the call graph for this function:

◆ UnBlock()

void StdScheduler::UnBlock ( )

Definition at line 150 of file StdScheduler.cpp.

151 {
152  Unblocker.Notify();
153 }

Referenced by StdSchedulerThread::Stop().

Here is the caller graph for this function:

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