OpenClonk
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::C4GameControl ( )

Definition at line 36 of file C4GameControl.cpp.

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

References Default().

Here is the call graph for this function:

◆ ~C4GameControl()

C4GameControl::~C4GameControl ( )

Definition at line 42 of file C4GameControl.cpp.

43 {
44  Clear();
45 }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ AdjustControlRate()

void C4GameControl::AdjustControlRate ( int32_t  iBy)

Definition at line 368 of file C4GameControl.cpp.

369 {
370  // control host only
371  if (isCtrlHost())
373 }
@ C4CVT_ControlRate
Definition: C4Control.h:103
C4GameControl Control
@ CDT_Decide
Definition: C4GameControl.h:39
@ CID_Set
Definition: C4PacketBase.h:153
bool isCtrlHost() const
Definition: C4GameControl.h:99
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)

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

Referenced by KeyAdjustControlRate().

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

◆ ChangeToLocal()

void C4GameControl::ChangeToLocal ( )

Definition at line 91 of file C4GameControl.cpp.

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 }
@ CM_Replay
Definition: C4GameControl.h:29
@ CM_Network
Definition: C4GameControl.h:28
@ CM_Local
Definition: C4GameControl.h:27
C4Game Game
Definition: C4Globals.cpp:52
void SetActivated(bool fnActivated)
Definition: C4Client.cpp:120
C4Client * getLocal() const
Definition: C4Client.h:161
void RemoveRemote()
Definition: C4Client.cpp:346
int32_t ControlRate
Definition: C4GameControl.h:88
C4ControlMode eMode
Definition: C4GameControl.h:70
C4Playback * pPlayback
Definition: C4GameControl.h:78
C4ClientList & Clients
Definition: C4Game.h:69
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
int32_t HaltCount
Definition: C4Game.h:112
static bool IsShown()
Definition: C4GameOverDlg.h:91

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().

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

◆ Clear()

void C4GameControl::Clear ( )

Definition at line 203 of file C4GameControl.cpp.

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

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

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

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

◆ ClientID()

int32_t C4GameControl::ClientID ( ) const
inline

Definition at line 102 of file C4GameControl.h.

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

References iClientID.

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

Here is the caller graph for this function:

◆ CtrlTickReached()

bool C4GameControl::CtrlTickReached ( int32_t  iTick)

Definition at line 345 of file C4GameControl.cpp.

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
int32_t FrameCounter
Definition: C4Game.h:129

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

Referenced by C4Network2::CheckStatusReached().

Here is the caller graph for this function:

◆ DbgRec()

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

Definition at line 416 of file C4GameControl.cpp.

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:930
int DoNoDebugRec
Definition: C4Record.cpp:30
int iSize
Definition: TstC4NetIO.cpp:32
int32_t DebugRec
Definition: C4Config.h:63
C4ConfigGeneral General
Definition: C4Config.h:255
C4Record * pRecord
Definition: C4GameControl.h:77
void Check(C4RecordChunkType eType, const uint8_t *pData, int iSize)
Definition: C4Record.cpp:992
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:211
Definition: StdBuf.h:30

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

Referenced by AddDbgRec().

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

◆ DecideControlDelivery()

C4ControlDeliveryType C4GameControl::DecideControlDelivery ( )

Definition at line 433 of file C4GameControl.cpp.

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

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

Referenced by DoInput().

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

◆ Default()

void C4GameControl::Default ( )

Definition at line 210 of file C4GameControl.cpp.

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 }
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
const int C4MaxControlRate
Definition: C4Constants.h:33
const int32_t C4SyncCheckRate
Definition: C4GameControl.h:53
@ CM_None
Definition: C4GameControl.h:26
C4ConfigNetwork Network
Definition: C4Config.h:259
int32_t ControlRate
Definition: C4Config.h:139
void Clear()
Definition: C4Control.cpp:85
C4Control SyncChecks
Definition: C4GameControl.h:80
C4Control Input
Definition: C4GameControl.h:66
C4Control * pExecutingControl
Definition: C4GameControl.h:84
int32_t SyncRate
Definition: C4GameControl.h:90

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

Referenced by C4GameControl(), and Clear().

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

◆ DoInput()

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

Definition at line 382 of file C4GameControl.cpp.

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 }
@ CDT_Private
Definition: C4GameControl.h:37
@ CDT_Queue
Definition: C4GameControl.h:34
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
virtual bool Sync() const
Definition: C4Control.h:55
virtual bool Lobby() const
Definition: C4Control.h:53
void ExecControlPacket(C4PacketType eCtrlType, class C4ControlPacket *pPkt)
C4ControlDeliveryType DecideControlDelivery()
bool isNetwork() const
Definition: C4GameControl.h:97
void DoInput(const C4Control &Input)

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().

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

◆ DoSyncCheck()

void C4GameControl::DoSyncCheck ( )

Definition at line 442 of file C4GameControl.cpp.

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 }
@ CID_SyncCheck
Definition: C4PacketBase.h:151
virtual void Execute() const =0
void RemoveOldSyncChecks()
C4ControlSyncCheck * GetSyncCheck(int32_t iTick)
friend class C4ControlSyncCheck
Definition: C4GameControl.h:59

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().

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

◆ ExecControl()

void C4GameControl::ExecControl ( const C4Control rCtrl)

Definition at line 472 of file C4GameControl.cpp.

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 }
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
bool PreExecute() const
Definition: C4Control.cpp:90
void Execute() const
Definition: C4Control.cpp:110

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

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

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

◆ ExecControlPacket()

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

Definition at line 484 of file C4GameControl.cpp.

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 }

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

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

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

◆ Execute()

void C4GameControl::Execute ( )

Definition at line 273 of file C4GameControl.cpp.

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
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)
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 }
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:239
bool isReplay() const
Definition: C4GameControl.h:98
bool GetControl(C4Control *pCtrl, int32_t iTick)
std::unique_ptr< C4Network2Stats > pNetworkStatistics
Definition: C4Game.h:95
bool ExecuteControl(C4Control *pCtrl, int iFrame)
Definition: C4Record.cpp:840

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

Referenced by Execute(), and C4Game::Execute().

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

◆ getClient() [1/2]

C4GameControlClient* C4GameControl::getClient ( const char *  szName)

◆ getClient() [2/2]

C4GameControlClient* C4GameControl::getClient ( int32_t  iID)

◆ getCtrlTick()

int32_t C4GameControl::getCtrlTick ( int32_t  iFrame) const

Definition at line 355 of file C4GameControl.cpp.

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 }

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

◆ getNextControlTick()

int32_t C4GameControl::getNextControlTick ( ) const

Definition at line 363 of file C4GameControl.cpp.

364 {
365  return ControlTick + (Game.FrameCounter % ControlRate ? 1 : 0);
366 }

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

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

Here is the caller graph for this function:

◆ GetRecord()

C4Record* C4GameControl::GetRecord ( )
inline

Definition at line 101 of file C4GameControl.h.

101 { return pRecord; }

References pRecord.

Referenced by LogSilent().

Here is the caller graph for this function:

◆ GetSyncCheck()

C4ControlSyncCheck * C4GameControl::GetSyncCheck ( int32_t  iTick)
protected

Definition at line 494 of file C4GameControl.cpp.

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 * nextPkt(C4IDPacket *pPkt) const
Definition: C4Control.h:79
int32_t getFrame() const
Definition: C4Control.h:333

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

Referenced by DoSyncCheck().

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

◆ InitLocal()

bool C4GameControl::InitLocal ( C4Client pLocal)

Definition at line 47 of file C4GameControl.cpp.

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

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

Referenced by C4Game::InitControl().

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

◆ InitNetwork()

bool C4GameControl::InitNetwork ( C4Client pLocal)

Definition at line 56 of file C4GameControl.cpp.

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 }
bool isHost() const
Definition: C4Client.h:106
C4GameParameters & Parameters
Definition: C4Game.h:67

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().

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

◆ InitReplay()

bool C4GameControl::InitReplay ( C4Group rGroup)

Definition at line 70 of file C4GameControl.cpp.

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 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Open(C4Group &rGrp)
Definition: C4Record.cpp:382

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().

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

◆ isCtrlHost()

bool C4GameControl::isCtrlHost ( ) const
inline

◆ isLocal()

bool C4GameControl::isLocal ( ) const
inline

Definition at line 96 of file C4GameControl.h.

96 { return eMode == CM_Local; }

References CM_Local, and eMode.

◆ isNetwork()

bool C4GameControl::isNetwork ( ) const
inline

Definition at line 97 of file C4GameControl.h.

97 { return eMode == CM_Network; }

References CM_Network, and eMode.

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

Here is the caller graph for this function:

◆ isRecord()

bool C4GameControl::isRecord ( ) const
inline

Definition at line 100 of file C4GameControl.h.

100 { return !! pRecord; }

References pRecord.

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

Here is the caller graph for this function:

◆ isReplay()

bool C4GameControl::isReplay ( ) const
inline

Definition at line 98 of file C4GameControl.h.

98 { return eMode == CM_Replay; }

References CM_Replay, and eMode.

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

Here is the caller graph for this function:

◆ IsRuntimeRecordPossible()

bool C4GameControl::IsRuntimeRecordPossible ( ) const

Definition at line 185 of file C4GameControl.cpp.

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

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

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

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

◆ KeyAdjustControlRate()

bool C4GameControl::KeyAdjustControlRate ( int32_t  iBy)
inline

Definition at line 140 of file C4GameControl.h.

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

References AdjustControlRate().

Referenced by C4Game::InitKeyboard().

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

◆ NoInput()

bool C4GameControl::NoInput ( ) const
inline

Definition at line 105 of file C4GameControl.h.

105 { return isReplay(); }

References isReplay().

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

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

◆ OnGameSynchronizing()

void C4GameControl::OnGameSynchronizing ( )

Definition at line 125 of file C4GameControl.cpp.

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)

References fRecordNeeded, and StartRecord().

Referenced by C4Game::Synchronize().

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

◆ Prepare()

bool C4GameControl::Prepare ( )

Definition at line 228 of file C4GameControl.cpp.

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 }
bool isActivated() const
Definition: C4Client.h:110
bool CtrlNeeded(int32_t iTick) const
bool CtrlReady(int32_t iTick)

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().

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

◆ PrepareInput()

void C4GameControl::PrepareInput ( )
protected

Definition at line 524 of file C4GameControl.cpp.

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 }
C4Application Application
Definition: C4Globals.cpp:44
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
C4PlayerList Players
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
C4PlayerControl Control
Definition: C4Player.h:129
C4Player * GetLocalByIndex(int iIndex) const

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

Referenced by Execute(), and Prepare().

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

◆ RecAddFile()

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

Definition at line 197 of file C4GameControl.cpp.

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

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

Referenced by C4PlayerInfoList::RecreatePlayers().

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

◆ RemoveOldSyncChecks()

void C4GameControl::RemoveOldSyncChecks ( )
protected

Definition at line 509 of file C4GameControl.cpp.

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 }
const int32_t C4SyncCheckMaxKeep
Definition: C4GameControl.h:55
void Delete(C4IDPacket *pPkt)
Definition: C4Control.h:88

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

Referenced by DoSyncCheck().

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

◆ RequestRuntimeRecord()

void C4GameControl::RequestRuntimeRecord ( )

Definition at line 175 of file C4GameControl.cpp.

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 }
@ CID_Synchronize
Definition: C4PacketBase.h:152
bool IsRuntimeRecordPossible() const

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

Referenced by C4Console::FileRecord().

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

◆ SetActivated()

void C4GameControl::SetActivated ( bool  fActivated)

Definition at line 375 of file C4GameControl.cpp.

376 {
377  fActivated = fnActivated;
378  if (eMode == CM_Network)
379  Network.SetActivated(fnActivated);
380 }
void SetActivated(bool fnActivated)

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

Here is the call graph for this function:

◆ StartRecord()

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

Definition at line 135 of file C4GameControl.cpp.

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 }
bool StartStreaming(bool fInitial)
Definition: C4Record.cpp:311
bool Start(bool fInitial)
Definition: C4Record.cpp:104

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

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

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

◆ StopRecord()

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

Definition at line 164 of file C4GameControl.cpp.

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

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

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

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

◆ SyncMode()

bool C4GameControl::SyncMode ( ) const
inline

Definition at line 103 of file C4GameControl.h.

103 { return eMode != CM_Local || pRecord; }

References CM_Local, eMode, and pRecord.

◆ Ticks()

void C4GameControl::Ticks ( )

Definition at line 325 of file C4GameControl.cpp.

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 }
bool CtrlOverflow(int32_t iTick) const
int32_t GetBehind(int32_t iTick) const
bool DoSkipFrame
Definition: C4Game.h:138
bool GameGo
Definition: C4Game.h:136

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().

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

Friends And Related Function Documentation

◆ C4ControlSyncCheck

friend class C4ControlSyncCheck
friend

Definition at line 59 of file C4GameControl.h.

Referenced by DoSyncCheck().

◆ C4GameControlNetwork

friend class C4GameControlNetwork
friend

Definition at line 60 of file C4GameControl.h.

Member Data Documentation

◆ ControlRate

◆ ControlTick

◆ DoSync

bool C4GameControl::DoSync

Definition at line 91 of file C4GameControl.h.

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

◆ eMode

◆ fActivated

bool C4GameControl::fActivated
protected

Definition at line 73 of file C4GameControl.h.

Referenced by DoSyncCheck(), and SetActivated().

◆ fHost

bool C4GameControl::fHost
protected

◆ fInitComplete

bool C4GameControl::fInitComplete
protected

◆ fRecordNeeded

bool C4GameControl::fRecordNeeded
protected

◆ iClientID

int32_t C4GameControl::iClientID
protected

Definition at line 75 of file C4GameControl.h.

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

◆ Input

C4Control C4GameControl::Input

Definition at line 66 of file C4GameControl.h.

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

◆ Network

◆ pClients

C4GameControlClient* C4GameControl::pClients
protected

Definition at line 82 of file C4GameControl.h.

◆ pExecutingControl

C4Control* C4GameControl::pExecutingControl
protected

Definition at line 84 of file C4GameControl.h.

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

◆ pPlayback

C4Playback* C4GameControl::pPlayback
protected

Definition at line 78 of file C4GameControl.h.

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

◆ pRecord

C4Record* C4GameControl::pRecord
protected

◆ SyncChecks

C4Control C4GameControl::SyncChecks
protected

Definition at line 80 of file C4GameControl.h.

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

◆ SyncRate

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: