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 38 of file C4GameControl.cpp.

References Default().

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

Here is the call graph for this function:

C4GameControl::~C4GameControl ( )

Definition at line 44 of file C4GameControl.cpp.

References Clear().

45 {
46  Clear();
47 }

Here is the call graph for this function:

Member Function Documentation

void C4GameControl::AdjustControlRate ( int32_t  iBy)

Definition at line 370 of file C4GameControl.cpp.

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

Referenced by KeyAdjustControlRate().

371 {
372  // control host only
373  if (isCtrlHost())
375 }
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 93 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().

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

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

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

206 {
207  StopRecord();
208  ChangeToLocal();
209  Default();
210 }
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 347 of file C4GameControl.cpp.

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

Referenced by C4Network2::CheckStatusReached().

348 {
349  // 1. control tick reached?
350  if (ControlTick < iTick) return false;
351  // 2. control tick?
352  if (Game.FrameCounter % ControlRate) return false;
353  // ok then
354  return true;
355 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
int32_t FrameCounter
Definition: C4Game.h:130
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 418 of file C4GameControl.cpp.

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

Referenced by AddDbgRec().

419 {
420  if (Config.General.DebugRec)
421  {
422  if (DoNoDebugRec>0) return;
423  // record data
424  if (pRecord)
425  {
426  C4PktDebugRec dr(eType, StdBuf(pData, iSize));
427  pRecord->Rec(Game.FrameCounter, DecompileToBuf<StdCompilerBinWrite>(dr), eType);
428  }
429  // check against playback
430  if (pPlayback)
431  pPlayback->Check(eType, pData, iSize);
432  }
433 }
C4Config Config
Definition: C4Config.cpp:837
Definition: StdBuf.h:37
C4Game Game
Definition: C4Globals.cpp:52
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:220
C4ConfigGeneral General
Definition: C4Config.h:252
int DoNoDebugRec
Definition: C4Record.cpp:34
int32_t FrameCounter
Definition: C4Game.h:130
void Check(C4RecordChunkType eType, const uint8_t *pData, int iSize)
Definition: C4Record.cpp:1003
C4Record * pRecord
Definition: C4GameControl.h:77
int32_t DebugRec
Definition: C4Config.h:61
C4Playback * pPlayback
Definition: C4GameControl.h:78
int iSize
Definition: TstC4NetIO.cpp:35

Here is the call graph for this function:

Here is the caller graph for this function:

C4ControlDeliveryType C4GameControl::DecideControlDelivery ( )

Definition at line 435 of file C4GameControl.cpp.

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

Referenced by DoInput().

436 {
437  // network
438  if (eMode == CM_Network)
440  // use direct
441  return CDT_Direct;
442 }
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 212 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().

213 {
214  Input.Clear();
215  Network.Clear();
216  eMode = CM_None;
217  fHost = fInitComplete = false;
219  pRecord = nullptr;
220  pPlayback = nullptr;
221  SyncChecks.Clear();
223  ControlTick = 0;
225  DoSync = false;
226  fRecordNeeded = false;
227  pExecutingControl = nullptr;
228 }
C4Config Config
Definition: C4Config.cpp:837
int32_t ControlTick
Definition: C4GameControl.h:89
const int32_t C4SyncCheckRate
Definition: C4GameControl.h:53
int32_t ControlRate
Definition: C4Config.h:140
C4Control SyncChecks
Definition: C4GameControl.h:80
C4Control Input
Definition: C4GameControl.h:66
void Clear()
Definition: C4Control.cpp:95
C4ConfigNetwork Network
Definition: C4Config.h:256
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 384 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().

385 {
386  assert(fInitComplete || pPkt->Lobby());
387 
388  // check if the control can be executed
389  if (eDelivery == CDT_Direct || eDelivery == CDT_Private)
390  assert(!pPkt->Sync());
391 
392  // decide control type
393  if (eDelivery == CDT_Decide)
394  eDelivery = DecideControlDelivery();
395 
396  // queue?
397  if (eDelivery == CDT_Queue)
398  {
399  // add, will be executed/sent later
400  Input.Add(eCtrlType, pPkt);
401  return;
402  }
403 
404  // Network?
405  if (isNetwork())
406  {
407  Network.DoInput(eCtrlType, pPkt, eDelivery);
408  }
409  else
410  {
411  // Local mode: execute at once
412  ExecControlPacket(eCtrlType, pPkt);
413  delete pPkt;
414  }
415 
416 }
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 444 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().

445 {
446  // only once
447  if (!DoSync) return;
448  DoSync = false;
449  // create sync check
450  C4ControlSyncCheck *pSyncCheck = new C4ControlSyncCheck();
451  pSyncCheck->Set();
452  // host?
453  if (fHost)
454  // add sync check to control queue or send it directly if the queue isn't active
456  else
457  {
458  // already have sync check?
460  if (!pSyncCheck2)
461  // add to sync check array
462  SyncChecks.Add(CID_SyncCheck, pSyncCheck);
463  else
464  {
465  // check
466  pSyncCheck->Execute();
467  delete pSyncCheck;
468  }
469  }
470  // remove old
472 }
C4Game Game
Definition: C4Globals.cpp:52
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
int32_t FrameCounter
Definition: C4Game.h:130
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 474 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().

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::Execute ( )

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

276 {
277  // Execute all available control
278 
279  assert(fInitComplete);
280 
281  // control tick? replay must always be executed.
283  return;
284 
285  // Get control
287  if (eMode == CM_Local)
288  {
289  // control = input
290  PrepareInput(); // add per-controlframe input
291  Control.Take(Input);
292  }
293  if (eMode == CM_Network)
294  {
295  // control = network input
296  if (!Network.GetControl(&Control, ControlTick))
297  {
298  LogFatal("Network: could not retrieve control from C4GameControlNetwork!");
299  return;
300  }
301  }
302  if (eMode == CM_Replay)
303  {
304  if (!pPlayback) { ChangeToLocal(); return; }
305  // control = replay data
307  }
308 
309  // Record: Save ctrl
310  if (pRecord)
311  pRecord->Rec(Control, Game.FrameCounter);
312 
313  // debug: recheck PreExecute
314  assert(Control.PreExecute());
315 
316  // execute
318  Control.Execute();
319  Control.Clear();
320  pExecutingControl = nullptr;
321 
322  // statistics record
323  if (Game.pNetworkStatistics) Game.pNetworkStatistics->ExecuteControlFrame();
324 
325 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:220
bool PreExecute() const
Definition: C4Control.cpp:100
void Execute() const
Definition: C4Control.cpp:120
bool GetControl(C4Control *pCtrl, int32_t iTick)
int32_t FrameCounter
Definition: C4Game.h:130
C4GameControl Control
C4Control Input
Definition: C4GameControl.h:66
void Clear()
Definition: C4Control.cpp:95
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
C4Record * pRecord
Definition: C4GameControl.h:77
bool ExecuteControl(C4Control *pCtrl, int iFrame)
Definition: C4Record.cpp:851
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:97
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 357 of file C4GameControl.cpp.

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

Referenced by C4GameControlNetwork::CtrlNeeded().

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

Here is the caller graph for this function:

int32_t C4GameControl::getNextControlTick ( ) const

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

366 {
367  return ControlTick + (Game.FrameCounter % ControlRate ? 1 : 0);
368 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
int32_t FrameCounter
Definition: C4Game.h:130
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 496 of file C4GameControl.cpp.

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

Referenced by DoSyncCheck().

497 {
498  for (C4IDPacket *pPkt = SyncChecks.firstPkt(); pPkt; pPkt = SyncChecks.nextPkt(pPkt))
499  {
500  // should be a sync check
501  if (pPkt->getPktType() != CID_SyncCheck) continue;
502  // get sync check
503  C4ControlSyncCheck *pCheck = static_cast<C4ControlSyncCheck *>(pPkt->getPkt());
504  // packet that's searched for?
505  if (pCheck->getFrame() == iTick)
506  return pCheck;
507  }
508  return nullptr;
509 }
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:339

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameControl::InitLocal ( C4Client pLocal)

Definition at line 49 of file C4GameControl.cpp.

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

Referenced by C4Game::InitControl().

50 {
51  eMode = CM_Local; fInitComplete = true;
52  fHost = true; iClientID = pLocal->getID();
53  ControlRate = 1;
54  // ok
55  return true;
56 }
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 58 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().

59 {
60  // network should already be initialized (by C4Network2)
61  if (!Network.IsEnabled())
62  return false;
63  // set mode
64  eMode = CM_Network; fInitComplete = true;
65  fHost = pLocal->isHost(); iClientID = pLocal->getID();
66  // control rate by parameters
68  // ok
69  return true;
70 }
C4Game Game
Definition: C4Globals.cpp:52
bool isHost() const
Definition: C4Client.h:106
C4GameParameters & Parameters
Definition: C4Game.h:69
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 72 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().

73 {
74  // open replay
75  pPlayback = new C4Playback();
76  if (!pPlayback->Open(rGroup))
77  {
78  LogFatal(LoadResStr("IDS_ERR_REPLAYREAD"));
79  delete pPlayback; pPlayback = nullptr;
80  return false;
81  }
82  // set mode
83  eMode = CM_Replay; fInitComplete = true;
85  // control rate by parameters
87  // just in case
88  StopRecord();
89  // ok
90  return true;
91 }
void StopRecord(StdStrBuf *pRecordName=nullptr, BYTE *pRecordSHA1=nullptr)
C4Game Game
Definition: C4Globals.cpp:52
C4GameParameters & Parameters
Definition: C4Game.h:69
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Open(C4Group &rGrp)
Definition: C4Record.cpp:393
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
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 187 of file C4GameControl.cpp.

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

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

188 {
189  // already requested?
190  if (fRecordNeeded) return false;
191  // not from replay
192  if (isReplay()) return false;
193  // not if recording already
194  if (isRecord()) return false;
195  // Record OK
196  return true;
197 }
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 127 of file C4GameControl.cpp.

References fRecordNeeded, and StartRecord().

Referenced by C4Game::Synchronize().

128 {
129  // start record if desired
130  if (fRecordNeeded)
131  {
132  fRecordNeeded = false;
133  StartRecord(false, false);
134  }
135 }
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 230 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().

231 {
232  assert(fInitComplete);
233 
234  // Prepare control, return true if everything is ready for GameGo.
235  bool is_input_prepared = false;
236 
237  switch (eMode)
238  {
239  // full steam ahead
240  case CM_Local: case CM_Replay:
241  return true;
242 
243  case CM_Network:
244 
245  Network.Execute();
246 
247  // deactivated and got control: request activate
249  ::Network.RequestActivate();
250 
251  // needs input?
253  {
254  if (!is_input_prepared && Game.Clients.getLocal()->isActivated())
255  {
256  // add per-controlframe input
257  PrepareInput();
258  is_input_prepared = true;
259  }
261  Input.Clear();
262  }
263 
264  // control tick?
266  return true;
267 
268  // check GameGo
269  return Network.CtrlReady(ControlTick);
270  default:
271  return false;
272  }
273 }
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:130
C4Control Input
Definition: C4GameControl.h:66
void Clear()
Definition: C4Control.cpp:95
C4GameControlNetwork Network
Definition: C4GameControl.h:67
C4ClientList & Clients
Definition: C4Game.h:71
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 526 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().

527 {
528  // add per-controlframe input
531  // per-player input
532  C4Player *plr; int32_t i=0;
533  while ((plr = ::Players.GetLocalByIndex(i++)))
534  plr->Control.PrepareInput();
535 }
C4PlayerControl Control
Definition: C4Player.h:131
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 199 of file C4GameControl.cpp.

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

Referenced by C4PlayerInfoList::RecreatePlayers().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::RemoveOldSyncChecks ( )
protected

Definition at line 511 of file C4GameControl.cpp.

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

Referenced by DoSyncCheck().

512 {
513  C4IDPacket *pNext;
514  for (C4IDPacket *pPkt = SyncChecks.firstPkt(); pPkt; pPkt = pNext)
515  {
516  pNext = SyncChecks.nextPkt(pPkt);
517  // should be a sync check
518  if (pPkt->getPktType() != CID_SyncCheck) continue;
519  // remove?
520  C4ControlSyncCheck *pCheck = static_cast<C4ControlSyncCheck *>(pPkt->getPkt());
521  if (pCheck->getFrame() < Game.FrameCounter - C4SyncCheckMaxKeep)
522  SyncChecks.Delete(pPkt);
523  }
524 }
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:130
C4Control SyncChecks
Definition: C4GameControl.h:80
C4IDPacket * nextPkt(C4IDPacket *pPkt) const
Definition: C4Control.h:79
int32_t getFrame() const
Definition: C4Control.h:339

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::RequestRuntimeRecord ( )

Definition at line 177 of file C4GameControl.cpp.

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

Referenced by C4Console::FileRecord().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameControl::SetActivated ( bool  fActivated)

Definition at line 377 of file C4GameControl.cpp.

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

378 {
379  fActivated = fnActivated;
380  if (eMode == CM_Network)
381  Network.SetActivated(fnActivated);
382 }
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 137 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().

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

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

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

167 {
168  if (pRecord)
169  {
170  ::Network.FinishStreaming();
171  pRecord->Stop(pRecordName, pRecordSHA1);
172  // just delete
173  delete pRecord; pRecord = nullptr;
174  }
175 }
bool Stop(StdStrBuf *pRecordName=nullptr, BYTE *pRecordSHA1=nullptr)
Definition: C4Record.cpp:178
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 327 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().

328 {
329  assert(fInitComplete);
330 
331  if (!(Game.FrameCounter % ControlRate))
332  ControlTick++;
333  if (!(Game.FrameCounter % SyncRate))
334  DoSync = true;
335 
336  // calc next tick without waiting for timer? (catchup cases)
337  if (eMode == CM_Network)
339  {
340  Game.GameGo = true;
341  if (Network.GetBehind(ControlTick) >= 25)
342  if (Game.FrameCounter % ((Network.GetBehind(ControlTick) + 15) / 20))
343  Game.DoSkipFrame = true;
344  }
345 }
int32_t ControlTick
Definition: C4GameControl.h:89
C4Game Game
Definition: C4Globals.cpp:52
bool DoSkipFrame
Definition: C4Game.h:139
int32_t GetBehind(int32_t iTick) const
int32_t FrameCounter
Definition: C4Game.h:130
C4GameControlNetwork Network
Definition: C4GameControl.h:67
bool GameGo
Definition: C4Game.h:137
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: