OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 224 of file StdScheduler.h.

Constructor & Destructor Documentation

StdScheduler::StdScheduler ( )

Definition at line 72 of file StdScheduler.cpp.

References Add().

72  : isInManualLoop(false)
73 {
74  Add(&Unblocker);
75 }
void Add(StdSchedulerProc *pProc)

Here is the call graph for this function:

StdScheduler::~StdScheduler ( )
virtual

Definition at line 77 of file StdScheduler.cpp.

References Clear().

78 {
79  Clear();
80 }

Here is the call graph for this function:

Member Function Documentation

void StdScheduler::Add ( StdSchedulerProc pProc)

Definition at line 97 of file StdScheduler.cpp.

References Added().

Referenced by C4GameLobby::ScenDesc::Activate(), C4Network2ResDlg::Activate(), C4GameOptionsList::Activate(), StdSchedulerThread::Add(), C4GameOverDlg::C4GameOverDlg(), C4GameSec1Timer::C4GameSec1Timer(), C4InteractiveThread::C4InteractiveThread(), C4Network2ClientListBox::C4Network2ClientListBox(), C4Network2ClientListDlg::C4Network2ClientListDlg(), C4Network2Stats::C4Network2Stats(), 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().

98 {
99  // Already added to some scheduler
100  if (pProc->scheduler)
101  return;
102  // Add
103  procs.push_back(pProc);
104  pProc->scheduler = this;
105 
106  Added(pProc);
107 }
void Added(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::Added ( StdSchedulerProc pProc)

Definition at line 281 of file StdSchedulerMac.mm.

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

Referenced by Add().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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:

void StdScheduler::Clear ( )

Definition at line 82 of file StdScheduler.cpp.

References Remove().

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

83 {
84  while (procs.size() > 0)
85  Remove(procs[procs.size()-1]);
86 }
void Remove(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool StdScheduler::DoScheduleProcs ( int  iTimeout)
protectedvirtual

Reimplemented in C4AbstractApp.

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

Here is the caller graph for this function:

C4TimeMilliseconds StdScheduler::GetNextTick ( C4TimeMilliseconds  tNow)

Definition at line 133 of file StdScheduler.cpp.

References C4TimeMilliseconds::PositiveInfinity.

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

134 {
136  for (auto proc : procs)
137  {
138  tProcTick = std::min(tProcTick, proc->GetNextTick(tNow));
139  }
140  return tProcTick;
141 }

Here is the caller graph for this function:

int StdScheduler::getProcCnt ( ) const
inline

Definition at line 249 of file StdScheduler.h.

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

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

Here is the caller graph for this function:

bool StdScheduler::hasProc ( StdSchedulerProc pProc)
inline

Definition at line 250 of file StdScheduler.h.

Referenced by C4InteractiveThread::RemoveProc().

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

Here is the caller graph for this function:

bool StdScheduler::IsInManualLoop ( )
inline

Definition at line 251 of file StdScheduler.h.

251 { return isInManualLoop; }
virtual void StdScheduler::OnError ( StdSchedulerProc )
inlineprotectedvirtual

Definition at line 272 of file StdScheduler.h.

272 { }
void StdScheduler::Remove ( StdSchedulerProc pProc)

Definition at line 109 of file StdScheduler.cpp.

References Removing().

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

110 {
111  // :o ?
112  if (pProc->scheduler != this)
113  return;
114  Removing(pProc);
115  pProc->scheduler = nullptr;
116  auto pos = std::find(procs.begin(), procs.end(), pProc);
117  if (pos != procs.end())
118  procs.erase(pos);
119 }
void Removing(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::Removing ( StdSchedulerProc pProc)

Definition at line 286 of file StdSchedulerMac.mm.

References SCHAdditions::requestAdditionsForScheduler:.

Referenced by Remove().

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:

Here is the caller graph for this function:

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

Definition at line 143 of file StdScheduler.cpp.

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(), C4AbstractApp::Run(), and C4AppDelegate::suggestQuitting:.

144 {
145  // Needs at least one process to work properly
146  if (!procs.size()) return false;
147 
148  // Get timeout
150  C4TimeMilliseconds tProcTick = GetNextTick(tNow);
151  if (iTimeout == -1 || tNow + iTimeout > tProcTick)
152  {
153  iTimeout = std::max<decltype(iTimeout)>(tProcTick - tNow, 0);
154  }
155 
156  bool old = isInManualLoop;
157  isInManualLoop = true;
158  bool res = DoScheduleProcs(iTimeout);
159  isInManualLoop = old;
160  return res;
161 }
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:

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

Definition at line 88 of file StdScheduler.cpp.

References Add(), and Clear().

Referenced by StdSchedulerThread::Set().

89 {
90  // Remove previous data
91  Clear();
92  // Copy new
93  for (int i = 0; i < inProcCnt; i++)
94  Add(ppnProcs[i]);
95 }
void Add(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::StartOnCurrentThread ( )

Definition at line 276 of file StdSchedulerMac.mm.

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

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

Here is the call graph for this function:

void StdScheduler::UnBlock ( )

Definition at line 163 of file StdScheduler.cpp.

Referenced by StdSchedulerThread::Stop().

164 {
165  Unblocker.Notify();
166 }

Here is the caller graph for this function:


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