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 220 of file StdScheduler.h.

Constructor & Destructor Documentation

StdScheduler::StdScheduler ( )

Definition at line 59 of file StdScheduler.cpp.

References Add().

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

Here is the call graph for this function:

StdScheduler::~StdScheduler ( )
virtual

Definition at line 64 of file StdScheduler.cpp.

References Clear().

65 {
66  Clear();
67 }

Here is the call graph for this function:

Member Function Documentation

void StdScheduler::Add ( StdSchedulerProc pProc)

Definition at line 84 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().

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)

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 69 of file StdScheduler.cpp.

References Remove().

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

70 {
71  while (procs.size() > 0)
72  Remove(procs[procs.size()-1]);
73 }
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 120 of file StdScheduler.cpp.

References C4TimeMilliseconds::PositiveInfinity.

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

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:

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:

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:

bool StdScheduler::IsInManualLoop ( )
inline

Definition at line 247 of file StdScheduler.h.

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

Definition at line 268 of file StdScheduler.h.

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

Definition at line 96 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(), 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 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 130 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:.

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:

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

Definition at line 75 of file StdScheduler.cpp.

References Add(), and Clear().

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 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 150 of file StdScheduler.cpp.

Referenced by StdSchedulerThread::Stop().

151 {
152  Unblocker.Notify();
153 }

Here is the caller graph for this function:


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