OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4GameControl Class Reference

#include <C4GameControl.h>

Collaboration diagram for C4GameControl:
[legend]

Public Member Functions

 C4GameControl ()
 
 ~C4GameControl ()
 
bool isLocal () const
 
bool isNetwork () const
 
bool isReplay () const
 
bool isCtrlHost () const
 
bool isRecord () const
 
C4RecordGetRecord ()
 
int32_t ClientID () const
 
bool SyncMode () const
 
bool NoInput () const
 
C4GameControlClientgetClient (int32_t iID)
 
C4GameControlClientgetClient (const char *szName)
 
bool InitLocal (C4Client *pLocal)
 
bool InitNetwork (C4Client *pLocal)
 
bool InitReplay (C4Group &rGroup)
 
void ChangeToLocal ()
 
void Clear ()
 
void Default ()
 
bool StartRecord (bool fInitial, bool fStreaming)
 
void StopRecord (StdStrBuf *pRecordName=nullptr, BYTE *pRecordSHA1=nullptr)
 
void RequestRuntimeRecord ()
 
bool IsRuntimeRecordPossible () const
 
bool RecAddFile (const char *szLocalFilename, const char *szAddAs)
 
bool Prepare ()
 
void Execute ()
 
void Ticks ()
 
bool CtrlTickReached (int32_t iTick)
 
int32_t getCtrlTick (int32_t iFrame) const
 
int32_t getNextControlTick () const
 
void AdjustControlRate (int32_t iBy)
 
bool KeyAdjustControlRate (int32_t iBy)
 
void SetActivated (bool fActivated)
 
void DoInput (C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
 
void DbgRec (C4RecordChunkType eType, const uint8_t *pData=nullptr, size_t iSize=0)
 
C4ControlDeliveryType DecideControlDelivery ()
 
void DoSyncCheck ()
 
void ExecControl (const C4Control &rCtrl)
 
void ExecControlPacket (C4PacketType eCtrlType, class C4ControlPacket *pPkt)
 
void OnGameSynchronizing ()
 

Public Attributes

C4Control Input
 
C4GameControlNetwork Network
 
int32_t ControlRate
 
int32_t ControlTick
 
int32_t SyncRate
 
bool DoSync
 

Protected Member Functions

C4ControlSyncCheckGetSyncCheck (int32_t iTick)
 
void RemoveOldSyncChecks ()
 
void PrepareInput ()
 

Protected Attributes

C4ControlMode eMode
 
bool fInitComplete
 
bool fHost
 
bool fActivated
 
bool fRecordNeeded
 
int32_t iClientID
 
C4RecordpRecord
 
C4PlaybackpPlayback
 
C4Control SyncChecks
 
C4GameControlClientpClients
 
C4ControlpExecutingControl
 

Friends

class C4ControlSyncCheck
 
class C4GameControlNetwork
 

Detailed Description

Definition at line 57 of file C4GameControl.h.

Constructor & Destructor Documentation

C4GameControl::C4GameControl ( )

Definition at line 36 of file C4GameControl.cpp.

References Default().

37  : Network(this)
38 {
39  Default();
40 }
C4GameControlNetwork Network
Definition: C4GameControl.h:67

Here is the call graph for this function:

C4GameControl::~C4GameControl ( )

Definition at line 42 of file C4GameControl.cpp.

References Clear().

43 {
44  Clear();
45 }

Here is the call graph for this function:

Member Function Documentation

void C4GameControl::AdjustControlRate ( int32_t  iBy)

Definition at line 368 of file C4GameControl.cpp.

References C4CVT_ControlRate, CDT_Decide, CID_Set, Control, DoInput(), and isCtrlHost().

Referenced by KeyAdjustControlRate().

369 {
370  // control host only
371  if (isCtrlHost())
373 }
bool isCtrlHost() const
Definition: C4GameControl.h:99
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::ChangeToLocal ( )

Definition at line 91 of file C4GameControl.cpp.

References C4GameControlNetwork::Clear(), C4Game::Clients, CM_Local, CM_Network, CM_Replay, ControlRate, eMode, fHost, C4PlayerInfoList::FixIDCounter(), Game, C4ClientList::getLocal(), C4Game::HaltCount, C4GameOverDlg::IsShown(), Network, C4Game::PlayerInfos, pPlayback, C4ClientList::RemoveRemote(), and C4Client::SetActivated().

Referenced by Clear(), C4Network2::Clear(), and Execute().

92 {
93  // changes from any given mode to local
94  // (emergency - think of network disconnect)
95 
96  // remove all non-local clients
98  // activate local client
99  if (Game.Clients.getLocal())
101 
102  // network: clear network
103  if (eMode == CM_Network)
104  {
105  Network.Clear();
106  if (::Network.isEnabled())
107  ::Network.Clear();
108  }
109  // replay: close playback
110  else if (eMode == CM_Replay)
111  { delete pPlayback; pPlayback = nullptr; }
112 
113  // we're now managing our own player info list; make sure counter works
115 
116  // start the game, if we're not in the game over dialog
117  // (otherwise, clients start game when host disconnected!)
119 
120  // set status
121  eMode = CM_Local; fHost = true;
122  ControlRate = 1;
123 }
C4Client * getLocal() const
Definition: C4Client.h:161
C4Game Game
Definition: C4Globals.cpp:52
void RemoveRemote()
Definition: C4Client.cpp:346
static bool IsShown()
Definition: C4GameOverDlg.h:92
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
C4GameControlNetwork Network
Definition: C4GameControl.h:67
C4ClientList & Clients
Definition: C4Game.h:69
C4ControlMode eMode
Definition: C4GameControl.h:70
C4Playback * pPlayback
Definition: C4GameControl.h:78
int32_t HaltCount
Definition: C4Game.h:112
void SetActivated(bool fnActivated)
Definition: C4Client.cpp:120
int32_t ControlRate
Definition: C4GameControl.h:88

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::Clear ( )

Definition at line 203 of file C4GameControl.cpp.

References ChangeToLocal(), Default(), and StopRecord().

Referenced by C4Game::Clear(), and ~C4GameControl().

204 {
205  StopRecord();
206  ChangeToLocal();
207  Default();
208 }
void StopRecord(StdStrBuf *pRecordName=nullptr, BYTE *pRecordSHA1=nullptr)
void ChangeToLocal()

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4GameControl::ClientID ( ) const
inline

Definition at line 102 of file C4GameControl.h.

References iClientID.

Referenced by C4Game::Abort(), C4ClientPlayerInfos::C4ClientPlayerInfos(), C4PlayerList::GetAtRemoteClient(), C4ControlPacket::LocalControl(), C4PlayerInfoList::LocalJoinUnjoinedPlayersInQueue(), C4Network2::OpenVoteDialog(), C4PlayerInfoList::RecreatePlayers(), and C4Network2::Vote().

102 { return iClientID; }
int32_t iClientID
Definition: C4GameControl.h:75

Here is the caller graph for this function:

bool C4GameControl::CtrlTickReached ( int32_t  iTick)

Definition at line 345 of file C4GameControl.cpp.

References ControlRate, ControlTick, C4Game::FrameCounter, and Game.

Referenced by C4Network2::CheckStatusReached().

346 {
347  // 1. control tick reached?
348  if (ControlTick < iTick) return false;
349  // 2. control tick?
350  if (Game.FrameCounter % ControlRate) return false;
351  // ok then
352  return true;
353 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
int32_t FrameCounter
Definition: C4Game.h:128
int32_t ControlRate
Definition: C4GameControl.h:88

Here is the caller graph for this function:

void C4GameControl::DbgRec ( C4RecordChunkType  eType,
const uint8_t *  pData = nullptr,
size_t  iSize = 0 
)

Definition at line 416 of file C4GameControl.cpp.

References C4Playback::Check(), Config, C4ConfigGeneral::DebugRec, DoNoDebugRec, C4Game::FrameCounter, Game, C4Config::General, pPlayback, pRecord, and C4Record::Rec().

Referenced by AddDbgRec().

417 {
418  if (Config.General.DebugRec)
419  {
420  if (DoNoDebugRec>0) return;
421  // record data
422  if (pRecord)
423  {
424  C4PktDebugRec dr(eType, StdBuf(pData, iSize));
425  pRecord->Rec(Game.FrameCounter, DecompileToBuf<StdCompilerBinWrite>(dr), eType);
426  }
427  // check against playback
428  if (pPlayback)
429  pPlayback->Check(eType, pData, iSize);
430  }
431 }
C4Config Config
Definition: C4Config.cpp:833
Definition: StdBuf.h:29
C4Game Game
Definition: C4Globals.cpp:52
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:211
C4ConfigGeneral General
Definition: C4Config.h:251
int DoNoDebugRec
Definition: C4Record.cpp:30
int32_t FrameCounter
Definition: C4Game.h:128
void Check(C4RecordChunkType eType, const uint8_t *pData, int iSize)
Definition: C4Record.cpp:992
C4Record * pRecord
Definition: C4GameControl.h:77
int32_t DebugRec
Definition: C4Config.h:60
C4Playback * pPlayback
Definition: C4GameControl.h:78
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

C4ControlDeliveryType C4GameControl::DecideControlDelivery ( )

Definition at line 433 of file C4GameControl.cpp.

References CDT_Direct, CM_Network, C4GameControlNetwork::DecideControlDelivery(), eMode, and Network.

Referenced by DoInput().

434 {
435  // network
436  if (eMode == CM_Network)
438  // use direct
439  return CDT_Direct;
440 }
C4GameControlNetwork Network
Definition: C4GameControl.h:67
C4ControlMode eMode
Definition: C4GameControl.h:70
C4ControlDeliveryType DecideControlDelivery() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::Default ( )

Definition at line 210 of file C4GameControl.cpp.

References C4ClientIDUnknown, C4MaxControlRate, C4SyncCheckRate, C4Control::Clear(), C4GameControlNetwork::Clear(), CM_None, Config, ControlRate, C4ConfigNetwork::ControlRate, ControlTick, DoSync, eMode, fHost, fInitComplete, fRecordNeeded, iClientID, Input, Network, C4Config::Network, pExecutingControl, pPlayback, pRecord, SyncChecks, and SyncRate.

Referenced by C4GameControl(), and Clear().

211 {
212  Input.Clear();
213  Network.Clear();
214  eMode = CM_None;
215  fHost = fInitComplete = false;
217  pRecord = nullptr;
218  pPlayback = nullptr;
219  SyncChecks.Clear();
221  ControlTick = 0;
223  DoSync = false;
224  fRecordNeeded = false;
225  pExecutingControl = nullptr;
226 }
C4Config Config
Definition: C4Config.cpp:833
int32_t ControlTick
Definition: C4GameControl.h:89
const int32_t C4SyncCheckRate
Definition: C4GameControl.h:53
int32_t ControlRate
Definition: C4Config.h:139
C4Control SyncChecks
Definition: C4GameControl.h:80
C4Control Input
Definition: C4GameControl.h:66
void Clear()
Definition: C4Control.cpp:85
C4ConfigNetwork Network
Definition: C4Config.h:255
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
C4Record * pRecord
Definition: C4GameControl.h:77
int32_t iClientID
Definition: C4GameControl.h:75
C4GameControlNetwork Network
Definition: C4GameControl.h:67
C4ControlMode eMode
Definition: C4GameControl.h:70
int32_t SyncRate
Definition: C4GameControl.h:90
C4Playback * pPlayback
Definition: C4GameControl.h:78
int32_t ControlRate
Definition: C4GameControl.h:88
C4Control * pExecutingControl
Definition: C4GameControl.h:84
const int C4MaxControlRate
Definition: C4Constants.h:33

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::DoInput ( C4PacketType  eCtrlType,
C4ControlPacket pPkt,
C4ControlDeliveryType  eDelivery 
)

Definition at line 382 of file C4GameControl.cpp.

References C4Control::Add(), CDT_Decide, CDT_Direct, CDT_Private, CDT_Queue, DecideControlDelivery(), C4GameControlNetwork::DoInput(), ExecControlPacket(), fInitComplete, Input, isNetwork(), C4ControlPacket::Lobby(), Network, and C4ControlPacket::Sync().

Referenced by AdjustControlRate(), C4ClientList::CtrlRemove(), C4Network2::DeactivateInactiveClients(), C4PlayerInfoList::DoLocalNonNetworkPlayerInfoUpdate(), DoSyncCheck(), C4Game::DropDef(), C4EditCursor::EMControl(), C4Network2::Execute(), C4Network2::HandleActivateReq(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4Console::In(), C4Network2::Join(), C4ChatInputDialog::OnChatCancel(), C4ChatInputDialog::OnChatInput(), C4GameLobby::MainDlg::OnReadyCheck(), C4MessageInput::ProcessCommand(), C4MessageInput::ProcessInput(), C4Network2::RequestActivate(), RequestRuntimeRecord(), C4Network2::SendJoinData(), C4TeamList::SendSetTeamColors(), C4TeamList::SendSetTeamDist(), C4Network2Players::SendUpdatedPlayers(), C4ToolsDlg::SetLandscapeMode(), and C4Network2::Vote().

383 {
384  assert(fInitComplete || pPkt->Lobby());
385 
386  // check if the control can be executed
387  if (eDelivery == CDT_Direct || eDelivery == CDT_Private)
388  assert(!pPkt->Sync());
389 
390  // decide control type
391  if (eDelivery == CDT_Decide)
392  eDelivery = DecideControlDelivery();
393 
394  // queue?
395  if (eDelivery == CDT_Queue)
396  {
397  // add, will be executed/sent later
398  Input.Add(eCtrlType, pPkt);
399  return;
400  }
401 
402  // Network?
403  if (isNetwork())
404  {
405  Network.DoInput(eCtrlType, pPkt, eDelivery);
406  }
407  else
408  {
409  // Local mode: execute at once
410  ExecControlPacket(eCtrlType, pPkt);
411  delete pPkt;
412  }
413 
414 }
void DoInput(const C4Control &Input)
C4ControlDeliveryType DecideControlDelivery()
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
void ExecControlPacket(C4PacketType eCtrlType, class C4ControlPacket *pPkt)
virtual bool Lobby() const
Definition: C4Control.h:53
bool isNetwork() const
Definition: C4GameControl.h:97
C4Control Input
Definition: C4GameControl.h:66
C4GameControlNetwork Network
Definition: C4GameControl.h:67
virtual bool Sync() const
Definition: C4Control.h:55

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::DoSyncCheck ( )

Definition at line 442 of file C4GameControl.cpp.

References C4Control::Add(), C4ControlSyncCheck, CDT_Direct, CDT_Queue, CID_SyncCheck, DoInput(), DoSync, C4ControlPacket::Execute(), fActivated, fHost, C4Game::FrameCounter, Game, GetSyncCheck(), RemoveOldSyncChecks(), C4ControlSyncCheck::Set(), and SyncChecks.

Referenced by C4Game::Execute().

443 {
444  // only once
445  if (!DoSync) return;
446  DoSync = false;
447  // create sync check
448  C4ControlSyncCheck *pSyncCheck = new C4ControlSyncCheck();
449  pSyncCheck->Set();
450  // host?
451  if (fHost)
452  // add sync check to control queue or send it directly if the queue isn't active
454  else
455  {
456  // already have sync check?
458  if (!pSyncCheck2)
459  // add to sync check array
460  SyncChecks.Add(CID_SyncCheck, pSyncCheck);
461  else
462  {
463  // check
464  pSyncCheck->Execute();
465  delete pSyncCheck;
466  }
467  }
468  // remove old
470 }
C4Game Game
Definition: C4Globals.cpp:52
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
int32_t FrameCounter
Definition: C4Game.h:128
C4Control SyncChecks
Definition: C4GameControl.h:80
C4ControlSyncCheck * GetSyncCheck(int32_t iTick)
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
friend class C4ControlSyncCheck
Definition: C4GameControl.h:59
void RemoveOldSyncChecks()
virtual void Execute() const =0

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::ExecControl ( const C4Control rCtrl)

Definition at line 472 of file C4GameControl.cpp.

References C4Control::Execute(), C4Control::firstPkt(), C4Game::FrameCounter, Game, Log(), pRecord, C4Control::PreExecute(), and C4Record::Rec().

Referenced by C4GameControlNetwork::ExecQueuedSyncCtrl(), and C4GameControlNetwork::ExecSyncControl().

473 {
474  // nothing to do?
475  if (!rCtrl.firstPkt()) return;
476  // execute it
477  if (!rCtrl.PreExecute()) Log("Control: PreExecute failed for sync control!");
478  rCtrl.Execute();
479  // record
480  if (pRecord)
481  pRecord->Rec(rCtrl, Game.FrameCounter);
482 }
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
C4Game Game
Definition: C4Globals.cpp:52
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:211
bool PreExecute() const
Definition: C4Control.cpp:90
void Execute() const
Definition: C4Control.cpp:110
int32_t FrameCounter
Definition: C4Game.h:128
C4Record * pRecord
Definition: C4GameControl.h:77
bool Log(const char *szMessage)
Definition: C4Log.cpp:192

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::ExecControlPacket ( C4PacketType  eCtrlType,
class C4ControlPacket pPkt 
)

Definition at line 484 of file C4GameControl.cpp.

References C4ControlPacket::Execute(), C4Game::FrameCounter, Game, Log(), pRecord, C4ControlPacket::PreExecute(), and C4Record::Rec().

Referenced by C4Playback::Check(), C4GameControlNetwork::DoInput(), DoInput(), and C4GameControlNetwork::HandleControlPkt().

485 {
486  // execute it
487  if (!pPkt->PreExecute()) Log("Control: PreExecute failed for direct control!");
488  pPkt->Execute();
489  // record it
490  if (pRecord)
491  pRecord->Rec(eCtrlType, pPkt, Game.FrameCounter);
492 }
C4Game Game
Definition: C4Globals.cpp:52
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:211
int32_t FrameCounter
Definition: C4Game.h:128
C4Record * pRecord
Definition: C4GameControl.h:77
bool Log(const char *szMessage)
Definition: C4Log.cpp:192

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::Execute ( )

Definition at line 273 of file C4GameControl.cpp.

References ChangeToLocal(), C4Control::Clear(), CM_Local, CM_Network, CM_Replay, Control, ControlRate, ControlTick, eMode, C4Control::Execute(), C4Playback::ExecuteControl(), fInitComplete, C4Game::FrameCounter, Game, C4GameControlNetwork::GetControl(), Input, isReplay(), LogFatal(), Network, pExecutingControl, C4Game::pNetworkStatistics, pPlayback, pRecord, C4Control::PreExecute(), PrepareInput(), C4Record::Rec(), and C4Control::Take().

Referenced by C4Game::Execute().

274 {
275  // Execute all available control
276 
277  assert(fInitComplete);
278 
279  // control tick? replay must always be executed.
281  return;
282 
283  // Get control
285  if (eMode == CM_Local)
286  {
287  // control = input
288  PrepareInput(); // add per-controlframe input
289  Control.Take(Input);
290  }
291  if (eMode == CM_Network)
292  {
293  // control = network input
294  if (!Network.GetControl(&Control, ControlTick))
295  {
296  LogFatal("Network: could not retrieve control from C4GameControlNetwork!");
297  return;
298  }
299  }
300  if (eMode == CM_Replay)
301  {
302  if (!pPlayback) { ChangeToLocal(); return; }
303  // control = replay data
305  }
306 
307  // Record: Save ctrl
308  if (pRecord)
309  pRecord->Rec(Control, Game.FrameCounter);
310 
311  // debug: recheck PreExecute
312  assert(Control.PreExecute());
313 
314  // execute
316  Control.Execute();
317  Control.Clear();
318  pExecutingControl = nullptr;
319 
320  // statistics record
321  if (Game.pNetworkStatistics) Game.pNetworkStatistics->ExecuteControlFrame();
322 
323 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:211
bool PreExecute() const
Definition: C4Control.cpp:90
void Execute() const
Definition: C4Control.cpp:110
bool GetControl(C4Control *pCtrl, int32_t iTick)
int32_t FrameCounter
Definition: C4Game.h:128
C4GameControl Control
C4Control Input
Definition: C4GameControl.h:66
void Clear()
Definition: C4Control.cpp:85
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:227
C4Record * pRecord
Definition: C4GameControl.h:77
bool ExecuteControl(C4Control *pCtrl, int iFrame)
Definition: C4Record.cpp:840
C4GameControlNetwork Network
Definition: C4GameControl.h:67
bool isReplay() const
Definition: C4GameControl.h:98
C4ControlMode eMode
Definition: C4GameControl.h:70
C4Playback * pPlayback
Definition: C4GameControl.h:78
void Take(C4Control &Ctrl)
Definition: C4Control.h:84
std::unique_ptr< C4Network2Stats > pNetworkStatistics
Definition: C4Game.h:95
void ChangeToLocal()
int32_t ControlRate
Definition: C4GameControl.h:88
C4Control * pExecutingControl
Definition: C4GameControl.h:84

Here is the call graph for this function:

Here is the caller graph for this function:

C4GameControlClient* C4GameControl::getClient ( int32_t  iID)
C4GameControlClient* C4GameControl::getClient ( const char *  szName)
int32_t C4GameControl::getCtrlTick ( int32_t  iFrame) const

Definition at line 355 of file C4GameControl.cpp.

References ControlRate, ControlTick, C4Game::FrameCounter, and Game.

Referenced by C4GameControlNetwork::CtrlNeeded().

356 {
357  // returns control tick by frame. Note this is a guess, as the control rate
358  // can always change, so don't rely on the return value too much.
359 
360  return iFrame / ControlRate + ControlTick - Game.FrameCounter / ControlRate;
361 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
int32_t FrameCounter
Definition: C4Game.h:128
int32_t ControlRate
Definition: C4GameControl.h:88

Here is the caller graph for this function:

int32_t C4GameControl::getNextControlTick ( ) const

Definition at line 363 of file C4GameControl.cpp.

References ControlRate, ControlTick, C4Game::FrameCounter, and Game.

Referenced by C4Network2::CreateDynamic(), C4GameControlNetwork::Init(), C4Network2::InitHost(), C4Network2::Pause(), C4GameControlNetwork::SetActivated(), and C4Network2::Sync().

364 {
365  return ControlTick + (Game.FrameCounter % ControlRate ? 1 : 0);
366 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
int32_t FrameCounter
Definition: C4Game.h:128
int32_t ControlRate
Definition: C4GameControl.h:88

Here is the caller graph for this function:

C4Record* C4GameControl::GetRecord ( )
inline

Definition at line 101 of file C4GameControl.h.

References pRecord.

Referenced by LogSilent().

101 { return pRecord; }
C4Record * pRecord
Definition: C4GameControl.h:77

Here is the caller graph for this function:

C4ControlSyncCheck * C4GameControl::GetSyncCheck ( int32_t  iTick)
protected

Definition at line 494 of file C4GameControl.cpp.

References CID_SyncCheck, C4Control::firstPkt(), C4ControlSyncCheck::getFrame(), C4Control::nextPkt(), and SyncChecks.

Referenced by DoSyncCheck().

495 {
496  for (C4IDPacket *pPkt = SyncChecks.firstPkt(); pPkt; pPkt = SyncChecks.nextPkt(pPkt))
497  {
498  // should be a sync check
499  if (pPkt->getPktType() != CID_SyncCheck) continue;
500  // get sync check
501  C4ControlSyncCheck *pCheck = static_cast<C4ControlSyncCheck *>(pPkt->getPkt());
502  // packet that's searched for?
503  if (pCheck->getFrame() == iTick)
504  return pCheck;
505  }
506  return nullptr;
507 }
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
C4Control SyncChecks
Definition: C4GameControl.h:80
C4IDPacket * nextPkt(C4IDPacket *pPkt) const
Definition: C4Control.h:79
int32_t getFrame() const
Definition: C4Control.h:333

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::InitLocal ( C4Client pLocal)

Definition at line 47 of file C4GameControl.cpp.

References CM_Local, ControlRate, eMode, fHost, fInitComplete, C4Client::getID(), and iClientID.

Referenced by C4Game::InitControl().

48 {
49  eMode = CM_Local; fInitComplete = true;
50  fHost = true; iClientID = pLocal->getID();
51  ControlRate = 1;
52  // ok
53  return true;
54 }
int32_t getID() const
Definition: C4Client.h:105
int32_t iClientID
Definition: C4GameControl.h:75
C4ControlMode eMode
Definition: C4GameControl.h:70
int32_t ControlRate
Definition: C4GameControl.h:88

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::InitNetwork ( C4Client pLocal)

Definition at line 56 of file C4GameControl.cpp.

References CM_Network, ControlRate, C4GameParameters::ControlRate, eMode, fHost, fInitComplete, Game, C4Client::getID(), iClientID, C4GameControlNetwork::IsEnabled(), C4Client::isHost(), Network, and C4Game::Parameters.

Referenced by C4Game::InitControl(), C4Game::InitNetworkFromReference(), and C4Game::InitNetworkHost().

57 {
58  // network should already be initialized (by C4Network2)
59  if (!Network.IsEnabled())
60  return false;
61  // set mode
62  eMode = CM_Network; fInitComplete = true;
63  fHost = pLocal->isHost(); iClientID = pLocal->getID();
64  // control rate by parameters
66  // ok
67  return true;
68 }
C4Game Game
Definition: C4Globals.cpp:52
bool isHost() const
Definition: C4Client.h:106
C4GameParameters & Parameters
Definition: C4Game.h:67
int32_t getID() const
Definition: C4Client.h:105
int32_t iClientID
Definition: C4GameControl.h:75
C4GameControlNetwork Network
Definition: C4GameControl.h:67
C4ControlMode eMode
Definition: C4GameControl.h:70
int32_t ControlRate
Definition: C4GameControl.h:88

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::InitReplay ( C4Group rGroup)

Definition at line 70 of file C4GameControl.cpp.

References C4ClientIDUnknown, CM_Replay, ControlRate, C4GameParameters::ControlRate, eMode, fHost, fInitComplete, Game, iClientID, LoadResStr(), LogFatal(), C4Playback::Open(), C4Game::Parameters, pPlayback, and StopRecord().

Referenced by C4Game::InitControl().

71 {
72  // open replay
73  pPlayback = new C4Playback();
74  if (!pPlayback->Open(rGroup))
75  {
76  LogFatal(LoadResStr("IDS_ERR_REPLAYREAD"));
77  delete pPlayback; pPlayback = nullptr;
78  return false;
79  }
80  // set mode
81  eMode = CM_Replay; fInitComplete = true;
83  // control rate by parameters
85  // just in case
86  StopRecord();
87  // ok
88  return true;
89 }
void StopRecord(StdStrBuf *pRecordName=nullptr, BYTE *pRecordSHA1=nullptr)
C4Game Game
Definition: C4Globals.cpp:52
C4GameParameters & Parameters
Definition: C4Game.h:67
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Open(C4Group &rGrp)
Definition: C4Record.cpp:382
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:227
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
int32_t iClientID
Definition: C4GameControl.h:75
C4ControlMode eMode
Definition: C4GameControl.h:70
C4Playback * pPlayback
Definition: C4GameControl.h:78
int32_t ControlRate
Definition: C4GameControl.h:88

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::isCtrlHost ( ) const
inline
bool C4GameControl::isLocal ( ) const
inline

Definition at line 96 of file C4GameControl.h.

References CM_Local.

96 { return eMode == CM_Local; }
C4ControlMode eMode
Definition: C4GameControl.h:70
bool C4GameControl::isNetwork ( ) const
inline

Definition at line 97 of file C4GameControl.h.

References CM_Network.

Referenced by C4ClientPlayerInfos::C4ClientPlayerInfos(), C4Network2::Clear(), DoInput(), C4PlayerInfoList::DoPlayerInfoUpdate(), C4ControlJoinPlayer::PreExecute(), and C4MessageInput::ProcessCommand().

97 { return eMode == CM_Network; }
C4ControlMode eMode
Definition: C4GameControl.h:70

Here is the caller graph for this function:

bool C4GameControl::isRecord ( ) const
inline

Definition at line 100 of file C4GameControl.h.

References pRecord.

Referenced by C4Game::Evaluate(), IsRuntimeRecordPossible(), RecAddFile(), and C4PlayerInfoList::RecreatePlayers().

100 { return !! pRecord; }
C4Record * pRecord
Definition: C4GameControl.h:77

Here is the caller graph for this function:

bool C4GameControl::isReplay ( ) const
inline

Definition at line 98 of file C4GameControl.h.

References CM_Replay.

Referenced by Execute(), C4Game::GameOverCheck(), C4MouseControl::IsPassive(), IsRuntimeRecordPossible(), NoInput(), C4PlayerInfoList::RestoreSavegameInfos(), C4PlayerList::Retire(), and C4Game::Synchronize().

98 { return eMode == CM_Replay; }
C4ControlMode eMode
Definition: C4GameControl.h:70

Here is the caller graph for this function:

bool C4GameControl::IsRuntimeRecordPossible ( ) const

Definition at line 185 of file C4GameControl.cpp.

References fRecordNeeded, isRecord(), and isReplay().

Referenced by C4Console::FileRecord(), and RequestRuntimeRecord().

186 {
187  // already requested?
188  if (fRecordNeeded) return false;
189  // not from replay
190  if (isReplay()) return false;
191  // not if recording already
192  if (isRecord()) return false;
193  // Record OK
194  return true;
195 }
bool isRecord() const
bool isReplay() const
Definition: C4GameControl.h:98

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::KeyAdjustControlRate ( int32_t  iBy)
inline

Definition at line 140 of file C4GameControl.h.

References AdjustControlRate().

Referenced by C4Game::InitKeyboard().

141  { AdjustControlRate(iBy); return true; }
void AdjustControlRate(int32_t iBy)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::NoInput ( ) const
inline

Definition at line 105 of file C4GameControl.h.

References isReplay().

Referenced by C4ConsoleGUI::EnableControls(), and C4Game::InitPlayers().

105 { return isReplay(); }
bool isReplay() const
Definition: C4GameControl.h:98

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::OnGameSynchronizing ( )

Definition at line 125 of file C4GameControl.cpp.

References fRecordNeeded, and StartRecord().

Referenced by C4Game::Synchronize().

126 {
127  // start record if desired
128  if (fRecordNeeded)
129  {
130  fRecordNeeded = false;
131  StartRecord(false, false);
132  }
133 }
bool StartRecord(bool fInitial, bool fStreaming)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::Prepare ( )

Definition at line 228 of file C4GameControl.cpp.

References C4Control::Clear(), C4Game::Clients, CM_Local, CM_Network, CM_Replay, ControlRate, ControlTick, C4GameControlNetwork::CtrlNeeded(), C4GameControlNetwork::CtrlReady(), C4GameControlNetwork::DoInput(), eMode, C4GameControlNetwork::Execute(), fInitComplete, C4Control::firstPkt(), C4Game::FrameCounter, Game, C4ClientList::getLocal(), Input, C4Client::isActivated(), Network, and PrepareInput().

Referenced by C4Game::Execute().

229 {
230  assert(fInitComplete);
231 
232  // Prepare control, return true if everything is ready for GameGo.
233  bool is_input_prepared = false;
234 
235  switch (eMode)
236  {
237  // full steam ahead
238  case CM_Local: case CM_Replay:
239  return true;
240 
241  case CM_Network:
242 
243  Network.Execute();
244 
245  // deactivated and got control: request activate
247  ::Network.RequestActivate();
248 
249  // needs input?
251  {
252  if (!is_input_prepared && Game.Clients.getLocal()->isActivated())
253  {
254  // add per-controlframe input
255  PrepareInput();
256  is_input_prepared = true;
257  }
259  Input.Clear();
260  }
261 
262  // control tick?
264  return true;
265 
266  // check GameGo
267  return Network.CtrlReady(ControlTick);
268  default:
269  return false;
270  }
271 }
C4Client * getLocal() const
Definition: C4Client.h:161
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
void DoInput(const C4Control &Input)
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
bool isActivated() const
Definition: C4Client.h:110
bool CtrlNeeded(int32_t iTick) const
bool CtrlReady(int32_t iTick)
int32_t FrameCounter
Definition: C4Game.h:128
C4Control Input
Definition: C4GameControl.h:66
void Clear()
Definition: C4Control.cpp:85
C4GameControlNetwork Network
Definition: C4GameControl.h:67
C4ClientList & Clients
Definition: C4Game.h:69
C4ControlMode eMode
Definition: C4GameControl.h:70
int32_t ControlRate
Definition: C4GameControl.h:88

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::PrepareInput ( )
protected

Definition at line 524 of file C4GameControl.cpp.

References Application, C4Player::Control, C4GamePadControl::DoAxisInput(), C4MouseControl::DoMoveInput(), C4PlayerList::GetLocalByIndex(), MouseControl, C4Application::pGamePadControl, Players, and C4PlayerControl::PrepareInput().

Referenced by Execute(), and Prepare().

525 {
526  // add per-controlframe input
529  // per-player input
530  C4Player *plr; int32_t i=0;
531  while ((plr = ::Players.GetLocalByIndex(i++)))
532  plr->Control.PrepareInput();
533 }
C4PlayerControl Control
Definition: C4Player.h:129
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
C4PlayerList Players
C4Player * GetLocalByIndex(int iIndex) const
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::RecAddFile ( const char *  szLocalFilename,
const char *  szAddAs 
)

Definition at line 197 of file C4GameControl.cpp.

References C4Record::AddFile(), isRecord(), and pRecord.

Referenced by C4PlayerInfoList::RecreatePlayers().

198 {
199  if (!isRecord() || !pRecord) return false;
200  return pRecord->AddFile(szLocalFilename, szAddAs);
201 }
bool isRecord() const
C4Record * pRecord
Definition: C4GameControl.h:77
bool AddFile(const char *szLocalFilename, const char *szAddAs, bool fDelete=false)
Definition: C4Record.cpp:266

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::RemoveOldSyncChecks ( )
protected

Definition at line 509 of file C4GameControl.cpp.

References C4SyncCheckMaxKeep, CID_SyncCheck, C4Control::Delete(), C4Control::firstPkt(), C4Game::FrameCounter, Game, C4ControlSyncCheck::getFrame(), C4Control::nextPkt(), and SyncChecks.

Referenced by DoSyncCheck().

510 {
511  C4IDPacket *pNext;
512  for (C4IDPacket *pPkt = SyncChecks.firstPkt(); pPkt; pPkt = pNext)
513  {
514  pNext = SyncChecks.nextPkt(pPkt);
515  // should be a sync check
516  if (pPkt->getPktType() != CID_SyncCheck) continue;
517  // remove?
518  C4ControlSyncCheck *pCheck = static_cast<C4ControlSyncCheck *>(pPkt->getPkt());
519  if (pCheck->getFrame() < Game.FrameCounter - C4SyncCheckMaxKeep)
520  SyncChecks.Delete(pPkt);
521  }
522 }
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
C4Game Game
Definition: C4Globals.cpp:52
void Delete(C4IDPacket *pPkt)
Definition: C4Control.h:88
const int32_t C4SyncCheckMaxKeep
Definition: C4GameControl.h:55
int32_t FrameCounter
Definition: C4Game.h:128
C4Control SyncChecks
Definition: C4GameControl.h:80
C4IDPacket * nextPkt(C4IDPacket *pPkt) const
Definition: C4Control.h:79
int32_t getFrame() const
Definition: C4Control.h:333

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::RequestRuntimeRecord ( )

Definition at line 175 of file C4GameControl.cpp.

References CDT_Queue, CID_Synchronize, Config, Control, C4ConfigGeneral::DebugRec, DoInput(), fRecordNeeded, C4Config::General, and IsRuntimeRecordPossible().

Referenced by C4Console::FileRecord().

176 {
177  if (!IsRuntimeRecordPossible()) return; // cannot record
178  fRecordNeeded = true;
179  // request through a synchronize-call
180  // currnetly do not request, but start record with next gamesync, so network runtime join can be debugged
181  if (Config.General.DebugRec)
183 }
C4Config Config
Definition: C4Config.cpp:833
C4ConfigGeneral General
Definition: C4Config.h:251
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
bool IsRuntimeRecordPossible() const
int32_t DebugRec
Definition: C4Config.h:60

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::SetActivated ( bool  fActivated)

Definition at line 375 of file C4GameControl.cpp.

References CM_Network, eMode, fActivated, Network, and C4GameControlNetwork::SetActivated().

376 {
377  fActivated = fnActivated;
378  if (eMode == CM_Network)
379  Network.SetActivated(fnActivated);
380 }
void SetActivated(bool fnActivated)
C4GameControlNetwork Network
Definition: C4GameControl.h:67
C4ControlMode eMode
Definition: C4GameControl.h:70

Here is the call graph for this function:

bool C4GameControl::StartRecord ( bool  fInitial,
bool  fStreaming 
)

Definition at line 135 of file C4GameControl.cpp.

References fInitComplete, C4Game::FrameCounter, Game, Network, pExecutingControl, pRecord, C4Record::Rec(), C4Record::Start(), C4Record::StartStreaming(), and StopRecord().

Referenced by C4Game::InitControl(), and OnGameSynchronizing().

136 {
137  assert(fInitComplete);
138  // already recording?
139  if (pRecord) StopRecord();
140  // start
141  pRecord = new C4Record();
142  if (!pRecord->Start(fInitial))
143  {
144  delete pRecord; pRecord = nullptr;
145  return false;
146  }
147  // streaming
148  if (fStreaming)
149  {
150  if (!pRecord->StartStreaming(fInitial) ||
151  !::Network.StartStreaming(pRecord))
152  {
153  delete pRecord; pRecord = nullptr;
154  return false;
155  }
156  }
157  // runtime records executed through queue: Must record initial control
158  if (pExecutingControl)
160  // ok
161  return true;
162 }
void StopRecord(StdStrBuf *pRecordName=nullptr, BYTE *pRecordSHA1=nullptr)
C4Game Game
Definition: C4Globals.cpp:52
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:211
int32_t FrameCounter
Definition: C4Game.h:128
C4Record * pRecord
Definition: C4GameControl.h:77
bool Start(bool fInitial)
Definition: C4Record.cpp:104
C4GameControlNetwork Network
Definition: C4GameControl.h:67
bool StartStreaming(bool fInitial)
Definition: C4Record.cpp:311
C4Control * pExecutingControl
Definition: C4GameControl.h:84

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::StopRecord ( StdStrBuf pRecordName = nullptr,
BYTE pRecordSHA1 = nullptr 
)

Definition at line 164 of file C4GameControl.cpp.

References Network, pRecord, and C4Record::Stop().

Referenced by Clear(), C4Game::Evaluate(), InitReplay(), and StartRecord().

165 {
166  if (pRecord)
167  {
168  ::Network.FinishStreaming();
169  pRecord->Stop(pRecordName, pRecordSHA1);
170  // just delete
171  delete pRecord; pRecord = nullptr;
172  }
173 }
bool Stop(StdStrBuf *pRecordName=nullptr, BYTE *pRecordSHA1=nullptr)
Definition: C4Record.cpp:169
C4Record * pRecord
Definition: C4GameControl.h:77
C4GameControlNetwork Network
Definition: C4GameControl.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::SyncMode ( ) const
inline

Definition at line 103 of file C4GameControl.h.

References CM_Local, and pRecord.

103 { return eMode != CM_Local || pRecord; }
C4Record * pRecord
Definition: C4GameControl.h:77
C4ControlMode eMode
Definition: C4GameControl.h:70
void C4GameControl::Ticks ( )

Definition at line 325 of file C4GameControl.cpp.

References CM_Network, ControlRate, ControlTick, C4GameControlNetwork::CtrlOverflow(), C4Game::DoSkipFrame, DoSync, eMode, fInitComplete, C4Game::FrameCounter, Game, C4Game::GameGo, C4GameControlNetwork::GetBehind(), Network, and SyncRate.

Referenced by C4Game::Ticks().

326 {
327  assert(fInitComplete);
328 
329  if (!(Game.FrameCounter % ControlRate))
330  ControlTick++;
331  if (!(Game.FrameCounter % SyncRate))
332  DoSync = true;
333 
334  // calc next tick without waiting for timer? (catchup cases)
335  if (eMode == CM_Network)
337  {
338  Game.GameGo = true;
339  if (Network.GetBehind(ControlTick) >= 25)
340  if (Game.FrameCounter % ((Network.GetBehind(ControlTick) + 15) / 20))
341  Game.DoSkipFrame = true;
342  }
343 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
bool DoSkipFrame
Definition: C4Game.h:137
int32_t GetBehind(int32_t iTick) const
int32_t FrameCounter
Definition: C4Game.h:128
C4GameControlNetwork Network
Definition: C4GameControl.h:67
bool GameGo
Definition: C4Game.h:135
C4ControlMode eMode
Definition: C4GameControl.h:70
int32_t SyncRate
Definition: C4GameControl.h:90
int32_t ControlRate
Definition: C4GameControl.h:88
bool CtrlOverflow(int32_t iTick) const

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4ControlSyncCheck
friend

Definition at line 59 of file C4GameControl.h.

Referenced by DoSyncCheck().

friend class C4GameControlNetwork
friend

Definition at line 60 of file C4GameControl.h.

Member Data Documentation

bool C4GameControl::DoSync

Definition at line 91 of file C4GameControl.h.

Referenced by Default(), DoSyncCheck(), and Ticks().

bool C4GameControl::fActivated
protected

Definition at line 73 of file C4GameControl.h.

Referenced by DoSyncCheck(), and SetActivated().

bool C4GameControl::fHost
protected
bool C4GameControl::fInitComplete
protected
bool C4GameControl::fRecordNeeded
protected
int32_t C4GameControl::iClientID
protected

Definition at line 75 of file C4GameControl.h.

Referenced by ClientID(), Default(), InitLocal(), InitNetwork(), and InitReplay().

C4Control C4GameControl::Input

Definition at line 66 of file C4GameControl.h.

Referenced by ConsoleDlgProc(), Default(), DoInput(), Execute(), and Prepare().

C4GameControlClient* C4GameControl::pClients
protected

Definition at line 82 of file C4GameControl.h.

C4Control* C4GameControl::pExecutingControl
protected

Definition at line 84 of file C4GameControl.h.

Referenced by Default(), Execute(), and StartRecord().

C4Playback* C4GameControl::pPlayback
protected

Definition at line 78 of file C4GameControl.h.

Referenced by ChangeToLocal(), DbgRec(), Default(), Execute(), and InitReplay().

C4Record* C4GameControl::pRecord
protected
C4Control C4GameControl::SyncChecks
protected

Definition at line 80 of file C4GameControl.h.

Referenced by Default(), DoSyncCheck(), GetSyncCheck(), and RemoveOldSyncChecks().

int32_t C4GameControl::SyncRate

Definition at line 90 of file C4GameControl.h.

Referenced by C4Game::CompileFunc(), Default(), and Ticks().


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