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

#include <C4Application.h>

Inheritance diagram for C4Application:
[legend]
Collaboration diagram for C4Application:
[legend]

Public Member Functions

 C4Application ()
 
 ~C4Application ()
 
void Clear ()
 
void ClearCommandLine ()
 
void GameTick ()
 
void Draw ()
 
bool OpenSystemGroup ()
 
void CloseSystemGroup ()
 
void SetGameTickDelay (int iDelay)
 
virtual void OnResolutionChanged (unsigned int iXRes, unsigned int iYRes)
 
virtual void OnKeyboardLayoutChanged ()
 
bool SetGameFont (const char *szFontFace, int32_t iFontSize)
 
void NextTick ()
 
virtual void Quit ()
 
void OpenGame (const char *scenario=0)
 
void QuitGame ()
 
void Activate ()
 
void SetNextMission (const char *szMissionFilename)
 
virtual void OnCommand (const char *szCmd)
 
bool IsQuittingGame () const
 
const char * GetRevision () const
 
bool FullScreenMode ()
 
int GetConfigWidth ()
 
int GetConfigHeight ()
 
bool Init (int argc, char *argv[])
 
void Run ()
 
bool GetIndexedDisplayMode (int32_t iIndex, int32_t *piXRes, int32_t *piYRes, int32_t *piBitDepth, int32_t *piRefreshRate, uint32_t iMonitor)
 
bool SetVideoMode (int iXRes, int iYRes, unsigned int iRefreshRate, unsigned int iMonitor, bool fFullScreen)
 
void RestoreVideoMode ()
 
virtual bool DoScheduleProcs (int iTimeout)
 
bool FlushMessages ()
 
bool Copy (const std::string &text, bool fClipboard=true)
 
std::string Paste (bool fClipboard=true)
 
bool IsClipboardFull (bool fClipboard=true)
 
void NotifyUserIfInactive ()
 
void MessageDialog (const char *message)
 
const char * GetLastError ()
 
void Error (const char *m)
 
bool AssertMainThread ()
 
int getProcCnt () const
 
bool hasProc (StdSchedulerProc *pProc)
 
bool IsInManualLoop ()
 
void Set (StdSchedulerProc **ppProcs, int iProcCnt)
 
void Add (StdSchedulerProc *pProc)
 
void Remove (StdSchedulerProc *pProc)
 
void Added (StdSchedulerProc *pProc)
 
void Removing (StdSchedulerProc *pProc)
 
void Changed (StdSchedulerProc *pProc)
 
void StartOnCurrentThread ()
 
C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow)
 
bool ScheduleProcs (int iTimeout=1000/36)
 
void UnBlock ()
 

Public Attributes

bool restartAtEnd
 
C4Group SystemGroup
 
C4MusicSystem MusicSystem
 
C4SoundSystem SoundSystem
 
C4GamePadControlpGamePadControl
 
C4InteractiveThread InteractiveThread
 
C4Network2IRCClientIRCClient
 
int isEditor
 
std::string IncomingUpdate
 
int CheckForUpdates
 
bool Active
 
C4WindowpWindow
 
bool fQuitMsgReceived
 
pthread_t MainThread
 

Protected Types

enum  State {
  C4AS_None, C4AS_PreInit, C4AS_Startup, C4AS_StartGame,
  C4AS_Game, C4AS_AfterGame, C4AS_Quit
}
 

Protected Member Functions

virtual bool DoInit (int argc, char *argv[])
 
void ParseCommandLine (int argc, char *argv[])
 
bool PreInit ()
 
void ApplyResolutionConstraints ()
 
virtual void OnError (StdSchedulerProc *)
 

Static Protected Member Functions

static bool ProcessCallback (const char *szMessage, int iProcess)
 

Protected Attributes

enum C4Application::State AppState
 
C4ApplicationGameTimerpGameTimer
 
int QuitAfterGame
 
std::string IncomingKeyfile
 
std::string sLastError
 
bool fDspModeSet
 

Detailed Description

Definition at line 32 of file C4Application.h.

Member Enumeration Documentation

enum C4Application::State
protected

Constructor & Destructor Documentation

C4Application::C4Application ( )

Definition at line 51 of file C4Application.cpp.

51  :
52  isEditor(false),
53  IRCClient(ApplicationIRCClient),
54  QuitAfterGame(false),
55  CheckForUpdates(false),
56  restartAtEnd(false),
57  pGamePadControl(nullptr),
59  pGameTimer(nullptr)
60 {
61 }
enum C4Application::State AppState
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:87
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
C4Network2IRCClient & IRCClient
Definition: C4Application.h:47
C4Application::~C4Application ( )

Definition at line 63 of file C4Application.cpp.

References CloseLog(), and pGamePadControl.

64 {
65  // clear gamepad
66  if (pGamePadControl) delete pGamePadControl;
67  // Close log
68  CloseLog();
69 }
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
bool CloseLog()
Definition: C4Log.cpp:100

Here is the call graph for this function:

Member Function Documentation

void C4Application::Activate ( )

Definition at line 831 of file C4Application.cpp.

References FullScreen.

Referenced by C4StartupMainDlg::OnShown().

832 {
833 #ifdef USE_WIN32_WINDOWS
834  BringWindowToTop(FullScreen.hWindow);
835  ShowWindow(FullScreen.hWindow, SW_SHOW);
836 #endif
837 }
C4FullScreen FullScreen
Definition: C4Globals.cpp:46

Here is the caller graph for this function:

void StdScheduler::Add ( StdSchedulerProc pProc)
inherited

Definition at line 97 of file StdScheduler.cpp.

References StdScheduler::Added().

Referenced by C4GameLobby::ScenDesc::Activate(), C4Network2ResDlg::Activate(), C4GameOptionsList::Activate(), StdSchedulerThread::Add(), C4GameOverDlg::C4GameOverDlg(), C4GameSec1Timer::C4GameSec1Timer(), C4InteractiveThread::C4InteractiveThread(), C4Network2ClientListBox::C4Network2ClientListBox(), C4Network2ClientListDlg::C4Network2ClientListDlg(), C4Network2Stats::C4Network2Stats(), C4StartupNetDlg::C4StartupNetDlg(), C4GameLobby::Countdown::Countdown(), DoInit(), C4GUI::InfoDialog::InfoDialog(), C4Network2::InitHost(), C4Network2::InitialConnect::InitialConnect(), C4Network2::InitLeague(), C4AulDebug::Listen(), C4GameLobby::MainDlg::MainDlg(), StdScheduler::Set(), C4Network2::StartStreaming(), and StdScheduler::StdScheduler().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::Added ( StdSchedulerProc pProc)
inherited

Definition at line 281 of file StdSchedulerMac.mm.

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

Referenced by StdScheduler::Add().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::ApplyResolutionConstraints ( )
protected

Definition at line 480 of file C4Application.cpp.

References C4Draw::COLOR_DEPTH, Config, C4AbstractApp::GetIndexedDisplayMode(), C4Config::Graphics, LogF(), C4ConfigGraphics::Monitor, C4ConfigGraphics::RefreshRate, C4ConfigGraphics::ResX, and C4ConfigGraphics::ResY.

Referenced by DoInit().

481 {
482  // Not changing the resolution always works anyway
483  if (Config.Graphics.ResX == -1 && Config.Graphics.ResY == -1)
484  return;
485  // Enumerate display modes
486  int32_t idx = -1, iXRes, iYRes, iBitDepth, iRefreshRate;
487  int32_t best_match = -1;
488  uint32_t best_delta = ~0;
489  while (GetIndexedDisplayMode(++idx, &iXRes, &iYRes, &iBitDepth, &iRefreshRate, Config.Graphics.Monitor))
490  {
491  if (iBitDepth != C4Draw::COLOR_DEPTH) continue;
492  uint32_t delta = std::abs(Config.Graphics.ResX*Config.Graphics.ResY - iXRes*iYRes);
493  if (!delta && iBitDepth == C4Draw::COLOR_DEPTH && iRefreshRate == Config.Graphics.RefreshRate)
494  return; // Exactly the expected mode
495  if (delta < best_delta)
496  {
497  // Better match than before
498  best_match = idx;
499  best_delta = delta;
500  }
501  }
502  if (best_match != -1)
503  {
504  // Apply next-best mode
505  GetIndexedDisplayMode(best_match, &iXRes, &iYRes, &iBitDepth, &iRefreshRate, Config.Graphics.Monitor);
506  if (iXRes != Config.Graphics.ResX || iYRes != Config.Graphics.ResY)
507  // Don't warn if only bit depth changes
508  // Also, lang table not loaded yet
509  LogF("Warning: The selected resolution %dx%d is not available and has been changed to %dx%d.", Config.Graphics.ResX, Config.Graphics.ResY, iXRes, iYRes);
510  Config.Graphics.ResX = iXRes; Config.Graphics.ResY = iYRes;
511  Config.Graphics.RefreshRate = iRefreshRate;
512  }
513 }
int32_t RefreshRate
Definition: C4Config.h:106
C4Config Config
Definition: C4Config.cpp:837
static constexpr int COLOR_DEPTH
Definition: C4Draw.h:89
C4ConfigGraphics Graphics
Definition: C4Config.h:254
bool GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32_t *piYRes, int32_t *piBitDepth, int32_t *piRefreshRate, uint32_t iMonitor)
Definition: C4AppSDL.cpp:339
int32_t Monitor
Definition: C4Config.h:113
int32_t ResX
Definition: C4Config.h:104
int32_t ResY
Definition: C4Config.h:104
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4AbstractApp::AssertMainThread ( )
inlineinherited

Definition at line 123 of file C4App.h.

References C4AbstractApp::MainThread.

Referenced by Log(), LogSilent(), C4Surface::PageFlip(), CStdGL::PrepareRendering(), and ShaderLog().

124  {
125  assert(MainThread == pthread_self());
126  return MainThread == pthread_self();
127  }
pthread_t MainThread
Definition: C4App.h:128

Here is the caller graph for this function:

void StdScheduler::Changed ( StdSchedulerProc pProc)
inherited

Definition at line 294 of file StdSchedulerMac.mm.

References SCHAdditions::additionForProc:, SCHAddition::changed, and SCHAdditions::requestAdditionsForScheduler:.

295 {
296  [[[SCHAdditions requestAdditionsForScheduler:this] additionForProc:pProc] changed];
297 }

Here is the call graph for this function:

void C4Application::Clear ( )
virtual

Reimplemented from C4AbstractApp.

Definition at line 585 of file C4Application.cpp.

References C4MusicSystem::Clear(), C4SoundSystem::Clear(), C4FullScreen::Clear(), C4Console::Clear(), C4Language::Clear(), C4AbstractApp::Clear(), C4EditCursor::Clear(), C4Game::Clear(), C4Language::ClearLanguage(), C4Group::Close(), C4Network2IRCClient::Close(), Console, C4Console::EditCursor, FullScreen, Game, C4Language::HasStringTable(), IRCClient, Languages, LoadResStr(), Log(), MusicSystem, pDraw, pGamePadControl, pGameTimer, StdScheduler::Remove(), C4AbstractApp::RestoreVideoMode(), SoundSystem, SystemGroup, and CPNGFile::WaitForSaves().

Referenced by DoInit(), main(), and C4AppDelegate::suggestQuitting:.

586 {
587  Game.Clear();
588  NextMission.clear();
589  // stop timer
590  if (pGameTimer)
591  {
593  delete pGameTimer; pGameTimer = nullptr;
594  }
595  // quit irc
596  IRCClient.Close();
597  // close system group (System.ocg)
598  SystemGroup.Close();
599  // Log
600  if (::Languages.HasStringTable()) // Avoid (double and undefined) message on (second?) shutdown...
601  Log(LoadResStr("IDS_PRC_DEINIT"));
602  // Clear external language packs and string table
603  Languages.Clear();
605  // gamepad clear
606  if (pGamePadControl) { delete pGamePadControl; pGamePadControl=nullptr; }
607  // music system clear
608  MusicSystem.Clear();
609  SoundSystem.Clear();
611  // clear editcursor holding graphics before clearing draw
613  // Clear direct draw (late, because it's needed for e.g. Log)
614  if (pDraw) { delete pDraw; pDraw=nullptr; }
615  // Close window
616  FullScreen.Clear();
617  Console.Clear();
618  // There might be pending saves - do them after the fullscreen windows got closed
619  // so the app just remains as a lingering process until saving is done
621  // The very final stuff
623 }
C4SoundSystem SoundSystem
Definition: C4Application.h:42
C4EditCursor EditCursor
Definition: C4Console.h:90
C4Console Console
Definition: C4Globals.cpp:45
C4Game Game
Definition: C4Globals.cpp:52
bool HasStringTable() const
Definition: C4Language.h:70
void ClearLanguage()
Definition: C4Language.cpp:413
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
static void WaitForSaves()
Definition: StdPNG.cpp:360
virtual void Clear()
Definition: C4Console.cpp:423
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4Language Languages
Definition: C4Language.cpp:45
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:87
bool Close()
Definition: C4Group.cpp:755
C4Draw * pDraw
Definition: C4Draw.cpp:45
void Remove(StdSchedulerProc *pProc)
void RestoreVideoMode()
Definition: C4AppSDL.cpp:447
virtual void Clear()
Definition: C4AppSDL.cpp:109
virtual void Clear()
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
void Clear()
Definition: C4Game.cpp:541
void Clear()
Definition: C4Language.cpp:117
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
C4Group SystemGroup
Definition: C4Application.h:40
C4Network2IRCClient & IRCClient
Definition: C4Application.h:47
C4MusicSystem MusicSystem
Definition: C4Application.h:41

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::ClearCommandLine ( )

Definition at line 198 of file C4Application.cpp.

References Game, and C4Game::PlayerFilenames.

Referenced by C4Console::FileNew(), C4Console::FileOpen(), C4Console::FileOpenWPlrs(), and ParseCommandLine().

199 {
200  *Game.PlayerFilenames = 0;
201 }
C4Game Game
Definition: C4Globals.cpp:52
char PlayerFilenames[20 *_MAX_PATH+1]
Definition: C4Game.h:106

Here is the caller graph for this function:

void C4Application::CloseSystemGroup ( )
inline

Definition at line 56 of file C4Application.h.

References C4Group::Close().

56 { SystemGroup.Close(); }
bool Close()
Definition: C4Group.cpp:755
C4Group SystemGroup
Definition: C4Application.h:40

Here is the call graph for this function:

bool C4AbstractApp::Copy ( const std::string &  text,
bool  fClipboard = true 
)
inherited

Definition at line 34 of file C4AppMac.mm.

References Log().

Referenced by C4GUI::MessageDialog::KeyCopy().

35 {
36  NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
37  [pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
38  NSString* string = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding];
39  if (![pasteboard setString:string forType:NSStringPboardType])
40  {
41  Log("Writing to Cocoa pasteboard failed");
42  return false;
43  }
44  return true;
45 }
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:

bool C4Application::DoInit ( int  argc,
char *  argv[] 
)
protectedvirtual

Implements C4AbstractApp.

Definition at line 71 of file C4Application.cpp.

References C4AbstractApp::Active, StdScheduler::Add(), Application, ApplyResolutionConstraints(), AppState, C4_OS, C4AS_None, C4AS_PreInit, C4CFN_FLS, C4CFN_System, C4Group_SetProcessCallback(), C4Group_SetSortList(), C4Group_SetTempPath(), C4Config::CleanupTempUpdateFolder(), Clear(), Config, Console, StdStrBuf::Copy(), DDrawInit(), C4Config::Default(), C4ConfigGeneral::ExePath, FullScreen, C4ConfigGeneral::GamepadEnabled, C4Config::General, GetConfigHeight(), GetConfigWidth(), StdStrBuf::getData(), GetRevision(), C4Config::Graphics, C4Language::HasStringTable(), IncomingUpdate, C4FullScreen::Init(), C4Reloc::Init(), C4Console::Init(), C4Language::Init(), C4Config::Init(), C4Config::IsCorrupted(), isEditor, C4ConfigGeneral::LanguageEx, Languages, C4Config::Load(), C4Language::LoadLanguage(), LoadResStr(), Log(), LogF(), LogFatal(), C4AbstractApp::MessageDialog(), C4ConfigGraphics::Monitor, C4Reloc::Open(), OpenExtraLogs(), OpenLog(), ParseCommandLine(), pGamePadControl, pGameTimer, ProcessCallback(), C4AbstractApp::pWindow, C4ConfigGraphics::RefreshRate, Reloc, C4Config::Save(), SEqual2NoCase(), C4Window::SetSize(), C4AbstractApp::SetVideoMode(), ShowGfxErrorDialog(), C4ConfigGeneral::SystemDataPath, SystemGroup, C4ConfigGeneral::TempPath, C4ConfigGeneral::UserDataPath, C4ConfigGraphics::Windowed, C4ConfigGraphics::WindowX, and C4ConfigGraphics::WindowY.

72 {
73  assert(AppState == C4AS_None);
74  // Config overwrite by parameter
75  StdStrBuf sConfigFilename;
76  for (int32_t iPar=0; iPar < argc; iPar++)
77  if (SEqual2NoCase(argv[iPar], "--config="))
78  sConfigFilename.Copy(argv[iPar] + 9);
79  // Config check
80  Config.Init();
81  Config.Load(sConfigFilename.getData());
82  Config.Save();
83  // sometimes, the configuration can become corrupted due to loading errors or w/e
84  // check this and reset defaults if necessary
85  if (Config.IsCorrupted())
86  {
87  if (sConfigFilename)
88  {
89  // custom config corrupted: Fail
90  Log("ERROR: Custom configuration corrupted - program abort!\n");
91  return false;
92  }
93  else
94  {
95  // default config corrupted: Restore default
96  Log("Warning: Configuration corrupted - restoring default!\n");
97  Config.Default();
98  Config.Save();
99  Config.Load();
100  }
101  }
102  // Open log
103  OpenLog();
104 
105  // Engine header message
106  Log(C4ENGINECAPTION);
107  LogF("Version: %s %s (%s - %s)", C4VERSION, C4_OS, GetRevision(), C4REVISION_TS);
108  LogF("ExePath: \"%s\"", Config.General.ExePath.getData());
109  LogF("SystemDataPath: \"%s\"", Config.General.SystemDataPath);
110  LogF("UserDataPath: \"%s\"", Config.General.UserDataPath);
111 
112  // Init C4Group
116 
117  // Cleanup temp folders left behind
119 
120  // Initialize game data paths
121  Reloc.Init();
122 
123  // init system group
125  {
126  // Error opening system group - no LogFatal, because it needs language table.
127  // This will *not* use the FatalErrors stack, but this will cause the game
128  // to instantly halt, anyway.
129  const char *szMessage = "Error opening system group file (System.ocg)!";
130  Log(szMessage);
131  // Fatal error, game cannot start - have player notice
132  MessageDialog(szMessage);
133  return false;
134  }
135  // Parse command line
136  ParseCommandLine(argc, argv);
137 
138  // Open additional logs that depend on command line
139  OpenExtraLogs();
140 
141  // Init external language packs
142  Languages.Init();
143  // Load language string table
145  // No language table was loaded - bad luck...
146  if (!Languages.HasStringTable())
147  Log("WARNING: No language string table loaded!");
148 
149 #if defined(WIN32) && defined(WITH_AUTOMATIC_UPDATE)
150  // Windows: handle incoming updates directly, even before starting up the gui
151  // because updates will be applied in the console anyway.
152  if (!Application.IncomingUpdate.empty())
153  if (C4UpdateDlg::ApplyUpdate(Application.IncomingUpdate.c_str(), false, nullptr))
154  return true;
155 #endif
156 
157  // Fixup resolution
158  if (!Config.Graphics.Windowed)
160 
161  // activate
162  Active=true;
163 
164  // Init carrier window
165  if (!isEditor)
166  {
167  if (!(pWindow = FullScreen.Init(this)))
168  { Clear(); ShowGfxErrorDialog(); return false; }
169  }
170  else
171  {
172  if (!(pWindow = Console.Init(this)))
173  { Clear(); return false; }
174  }
175 
176  // init timers (needs window)
178 
179  // Initialize OpenGL
180  bool success = DDrawInit(this, GetConfigWidth(), GetConfigHeight(), Config.Graphics.Monitor);
181  if (!success) { LogFatal(LoadResStr("IDS_ERR_DDRAW")); Clear(); ShowGfxErrorDialog(); return false; }
182 
183  if (!isEditor)
184  {
187  }
188 
189  // Initialize gamepad
192 
194 
195  return true;
196 }
const char * getData() const
Definition: StdBuf.h:450
int32_t RefreshRate
Definition: C4Config.h:106
void Default()
Definition: C4Config.cpp:287
void ShowGfxErrorDialog()
C4Config Config
Definition: C4Config.cpp:837
C4Console Console
Definition: C4Globals.cpp:45
void MessageDialog(const char *message)
Definition: C4AppMac.mm:63
C4ConfigGeneral General
Definition: C4Config.h:252
bool HasStringTable() const
Definition: C4Language.h:70
void C4Group_SetSortList(const char **ppSortList)
Definition: C4Group.cpp:69
int32_t Windowed
Definition: C4Config.h:107
bool OpenExtraLogs()
Definition: C4Log.cpp:76
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
bool SetVideoMode(int iXRes, int iYRes, unsigned int iRefreshRate, unsigned int iMonitor, bool fFullScreen)
Definition: C4AppSDL.cpp:358
const char * C4CFN_FLS[]
Definition: C4Group.cpp:32
void CleanupTempUpdateFolder()
Definition: C4Config.cpp:808
const char * GetRevision() const
Definition: C4Application.h:72
enum C4Application::State AppState
bool GamepadEnabled
Definition: C4Config.h:59
bool IsCorrupted()
Definition: C4Config.h:285
void Add(StdSchedulerProc *pProc)
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void C4Group_SetProcessCallback(bool(*fnCallback)(const char *, int))
Definition: C4Group.cpp:64
C4ConfigGraphics Graphics
Definition: C4Config.h:254
void SetSize(unsigned int cx, unsigned int cy)
Definition: C4AppT.cpp:111
bool Active
Definition: C4App.h:63
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
C4Language Languages
Definition: C4Language.cpp:45
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:87
std::string IncomingUpdate
Definition: C4Application.h:77
int32_t WindowX
Definition: C4Config.h:105
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
bool Open(C4Group &hGroup, const char *filename) const
Definition: C4Reloc.cpp:69
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
static bool ProcessCallback(const char *szMessage, int iProcess)
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
void ParseCommandLine(int argc, char *argv[])
C4Reloc Reloc
Definition: C4Reloc.cpp:22
int GetConfigWidth()
Definition: C4Application.h:82
void Init()
Definition: C4Reloc.cpp:24
bool DDrawInit(C4AbstractApp *pApp, unsigned int iXRes, unsigned int iYRes, unsigned int iMonitor)
Definition: C4Draw.cpp:799
int32_t Monitor
Definition: C4Config.h:113
bool LoadLanguage(const char *strLanguages)
Definition: C4Language.cpp:364
int32_t WindowY
Definition: C4Config.h:105
StdCopyStrBuf TempPath
Definition: C4Config.h:54
bool OpenLog()
Definition: C4Log.cpp:51
bool Init()
Definition: C4Language.cpp:58
#define C4_OS
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
bool SEqual2NoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:197
bool Save()
Definition: C4Config.cpp:404
void C4Group_SetTempPath(const char *szPath)
Definition: C4Group.cpp:74
bool Load(const char *szConfigFile=nullptr)
Definition: C4Config.cpp:315
StdCopyStrBuf ExePath
Definition: C4Config.h:53
virtual C4Window * Init(C4AbstractApp *app)
Definition: C4Console.cpp:63
int GetConfigHeight()
Definition: C4Application.h:83
bool Init()
Definition: C4Config.cpp:712
#define C4CFN_System
Definition: C4Components.h:29
void ApplyResolutionConstraints()
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
C4Window * Init(C4AbstractApp *pApp)
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
void Copy()
Definition: StdBuf.h:475
C4Window * pWindow
Definition: C4App.h:80
C4Group SystemGroup
Definition: C4Application.h:40
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

bool C4AbstractApp::DoScheduleProcs ( int  iTimeout)
virtualinherited

Reimplemented from StdScheduler.

Definition at line 59 of file C4App.cpp.

References StdScheduler::DoScheduleProcs(), C4AbstractApp::FlushMessages(), and C4AbstractApp::fQuitMsgReceived.

60 {
61  // Always fail after quit message
63  return false;
64 #if defined(USE_SDL_MAINLOOP) || defined(USE_COCOA)
65  // Unfortunately, the SDL event loop needs to be polled
66  FlushMessages();
67 #endif
68 #ifdef WITH_QT_EDITOR
69  // Some places, for example the lobby, have a nested event processing loop.
70  // To prevent the editor from freezing, call the Qt event loop here.
71  if (iTimeout)
72  ProcessQtEvents();
73 #endif
74  return StdScheduler::DoScheduleProcs(iTimeout);
75 }
bool FlushMessages()
Definition: C4AppSDL.cpp:119
bool fQuitMsgReceived
Definition: C4App.h:81
virtual bool DoScheduleProcs(int iTimeout)

Here is the call graph for this function:

void C4Application::Draw ( )

Definition at line 745 of file C4Application.cpp.

References Console, C4FullScreen::Execute(), C4Console::Execute(), FullScreen, and isEditor.

Referenced by C4ApplicationGameTimer::Execute().

746 {
747  // Graphics
748 
749  // Fullscreen mode
750  if (!isEditor)
752  // Console mode
753  else
754  Console.Execute();
755 }
void Execute()
Definition: C4Console.cpp:586
C4Console Console
Definition: C4Globals.cpp:45
C4FullScreen FullScreen
Definition: C4Globals.cpp:46

Here is the call graph for this function:

Here is the caller graph for this function:

void C4AbstractApp::Error ( const char *  m)
inlineinherited

Definition at line 99 of file C4App.h.

References C4AbstractApp::sLastError.

Referenced by C4Draw::Error(), and C4AbstractApp::SetVideoMode().

99 { sLastError = m; }
std::string sLastError
Definition: C4App.h:156

Here is the caller graph for this function:

bool C4AbstractApp::FlushMessages ( )
inherited

Definition at line 119 of file C4AppSDL.cpp.

References C4AbstractApp::fQuitMsgReceived.

Referenced by C4AbstractApp::DoScheduleProcs(), C4Network2::FinalInit(), and C4Game::SetInitProgress().

120 {
121  // Always fail after quit message
122  if (fQuitMsgReceived)
123  return false;
124 
125  // Handle pending SDL messages
126  SDL_Event event;
127  while (SDL_PollEvent(&event))
128  {
129  HandleSDLEvent(event);
130  }
131  return true;
132 }
bool fQuitMsgReceived
Definition: C4App.h:81

Here is the caller graph for this function:

bool C4Application::FullScreenMode ( )

Definition at line 858 of file C4Application.cpp.

References Config, Game, C4Config::Graphics, isEditor, C4Game::IsRunning, and C4ConfigGraphics::Windowed.

Referenced by FullScreenWinProc(), GameTick(), GetConfigHeight(), GetConfigWidth(), and OnResolutionChanged().

859 {
860  if(isEditor)
861  return false;
863  return true;
865  return true;
866  return false;
867 }
bool IsRunning
Definition: C4Game.h:141
C4Config Config
Definition: C4Config.cpp:837
C4Game Game
Definition: C4Globals.cpp:52
int32_t Windowed
Definition: C4Config.h:107
C4ConfigGraphics Graphics
Definition: C4Config.h:254

Here is the caller graph for this function:

void C4Application::GameTick ( )

Definition at line 668 of file C4Application.cpp.

References Application, AppState, C4AS_AfterGame, C4AS_Game, C4AS_None, C4AS_PreInit, C4AS_Quit, C4AS_StartGame, C4AS_Startup, C4Game::Clear(), C4Startup::CloseStartup(), Config, Console, C4MusicSystem::Execute(), C4SoundSystem::Execute(), C4GamePadControl::Execute(), C4Game::Execute(), C4Game::fLobby, C4Game::fObserve, C4Game::fQuitWithError, FullScreenMode(), Game, GetConfigHeight(), GetConfigWidth(), C4Window::GrabMouse(), C4Config::Graphics, C4Game::Init(), isEditor, C4Game::IsRunning, C4ConfigGraphics::Monitor, MusicSystem, C4Game::NetworkActive, C4ConsoleGUI::OnStartGame(), pGamePadControl, PreInit(), C4AbstractApp::pWindow, Quit(), QuitGame(), C4ConfigGraphics::RefreshRate, C4Game::SetScenarioFilename(), C4AbstractApp::SetVideoMode(), SoundSystem, C4GameLobby::UserAbort, and C4ConfigGraphics::Windowed.

Referenced by C4ApplicationGameTimer::Execute().

669 {
670  // Exec depending on game state
671  switch (AppState)
672  {
673  case C4AS_None:
674  assert(AppState != C4AS_None);
675  break;
676  case C4AS_Quit:
677  // Do nothing, the main loop will exit soon
678  break;
679  case C4AS_PreInit:
680  if (!PreInit()) Quit();
681  break;
682  case C4AS_Startup:
686  // wait for the user to start a game
687  break;
688  case C4AS_StartGame:
689  // immediate progress to next state; OpenGame will enter HandleMessage-loops in startup and lobby!
692 #ifdef WITH_QT_EDITOR
693  // Notify console
695 #endif
696  // first-time game initialization
697  if (!Game.Init())
698  {
699  // set error flag (unless this was a lobby user abort)
701  Game.fQuitWithError = true;
702  // no start: Regular QuitGame; this may reset the engine to startup mode if desired
703  QuitGame();
704  break;
705  }
706  if(Config.Graphics.Windowed == 2 && FullScreenMode())
708  if (!isEditor)
709  pWindow->GrabMouse(true);
710  // Gamepad events have to be polled here so that the controller
711  // connection state is always up-to-date before players are
712  // joining.
714  break;
715  case C4AS_AfterGame:
716  // stop game
717  Game.Clear();
718  if(Config.Graphics.Windowed == 2 && NextMission.empty() && !isEditor)
720  if (!isEditor)
721  pWindow->GrabMouse(false);
723  // if a next mission is desired, set to start it
724  if (!NextMission.empty())
725  {
726  Game.SetScenarioFilename(NextMission.c_str());
728  Game.fObserve = false;
729  NextMission.clear();
730  }
731  break;
732  case C4AS_Game:
733  // Game
734  if (Game.IsRunning)
735  Game.Execute();
736  // Sound
739  // Gamepad
741  break;
742  }
743 }
C4SoundSystem SoundSystem
Definition: C4Application.h:42
int32_t RefreshRate
Definition: C4Config.h:106
void Execute(bool force_buffer_checks=false)
bool IsRunning
Definition: C4Game.h:141
C4Config Config
Definition: C4Config.cpp:837
void GrabMouse(bool grab)
Definition: C4AppT.cpp:105
C4Console Console
Definition: C4Globals.cpp:45
C4Game Game
Definition: C4Globals.cpp:52
int32_t Windowed
Definition: C4Config.h:107
bool SetVideoMode(int iXRes, int iYRes, unsigned int iRefreshRate, unsigned int iMonitor, bool fFullScreen)
Definition: C4AppSDL.cpp:358
bool Execute()
Definition: C4Game.cpp:713
enum C4Application::State AppState
void OnStartGame()
Definition: C4ConsoleGUI.h:115
C4ConfigGraphics Graphics
Definition: C4Config.h:254
bool Init()
Definition: C4Game.cpp:332
virtual void Quit()
bool fQuitWithError
Definition: C4Game.h:144
bool NetworkActive
Definition: C4Game.h:124
void SetScenarioFilename(const char *)
Definition: C4Game.cpp:532
int GetConfigWidth()
Definition: C4Application.h:82
bool fObserve
Definition: C4Game.h:122
int32_t Monitor
Definition: C4Config.h:113
static void CloseStartup()
Definition: C4Startup.cpp:282
int GetConfigHeight()
Definition: C4Application.h:83
void Clear()
Definition: C4Game.cpp:541
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
bool fLobby
Definition: C4Game.h:120
C4Window * pWindow
Definition: C4App.h:80
C4Application Application
Definition: C4Globals.cpp:44
C4MusicSystem MusicSystem
Definition: C4Application.h:41

Here is the call graph for this function:

Here is the caller graph for this function:

int C4Application::GetConfigHeight ( )
inline

Definition at line 83 of file C4Application.h.

References Config, FullScreenMode(), C4Config::Graphics, C4ConfigGraphics::ResY, and C4ConfigGraphics::WindowY.

Referenced by DoInit(), FullScreenWinProc(), GameTick(), and C4FullScreen::Init().

C4Config Config
Definition: C4Config.cpp:837
C4ConfigGraphics Graphics
Definition: C4Config.h:254
int32_t WindowY
Definition: C4Config.h:105
int32_t ResY
Definition: C4Config.h:104

Here is the call graph for this function:

Here is the caller graph for this function:

int C4Application::GetConfigWidth ( )
inline

Definition at line 82 of file C4Application.h.

References Config, FullScreenMode(), C4Config::Graphics, C4ConfigGraphics::ResX, and C4ConfigGraphics::WindowX.

Referenced by DoInit(), FullScreenWinProc(), GameTick(), and C4FullScreen::Init().

C4Config Config
Definition: C4Config.cpp:837
C4ConfigGraphics Graphics
Definition: C4Config.h:254
int32_t WindowX
Definition: C4Config.h:105
int32_t ResX
Definition: C4Config.h:104

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4AbstractApp::GetIndexedDisplayMode ( int32_t  iIndex,
int32_t *  piXRes,
int32_t *  piYRes,
int32_t *  piBitDepth,
int32_t *  piRefreshRate,
uint32_t  iMonitor 
)
inherited

Definition at line 339 of file C4AppSDL.cpp.

Referenced by ApplyResolutionConstraints().

340 {
341  if (!modeCount)
342  {
343  modeCount = SDL_GetNumDisplayModes(iMonitor);
344  }
345 
346  if (iIndex >= modeCount)
347  return false;
348 
349  SDL_DisplayMode mode;
350  SDL_GetDisplayMode(iMonitor, iIndex, &mode);
351  *piXRes = mode.w;
352  *piYRes = mode.h;
353  *piBitDepth = bits_per_pixel(mode.format);
354  if (piRefreshRate) *piRefreshRate = mode.refresh_rate;
355  return true;
356 }

Here is the caller graph for this function:

const char* C4AbstractApp::GetLastError ( )
inlineinherited

Definition at line 98 of file C4App.h.

References C4AbstractApp::sLastError.

98 { return sLastError.c_str(); }
std::string sLastError
Definition: C4App.h:156
C4TimeMilliseconds StdScheduler::GetNextTick ( C4TimeMilliseconds  tNow)
inherited

Definition at line 133 of file StdScheduler.cpp.

References C4TimeMilliseconds::PositiveInfinity.

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

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

Here is the caller graph for this function:

int StdScheduler::getProcCnt ( ) const
inlineinherited

Definition at line 249 of file StdScheduler.h.

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

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

Here is the caller graph for this function:

const char* C4Application::GetRevision ( ) const
inline

Definition at line 72 of file C4Application.h.

Referenced by DoInit(), C4Network2::Join(), and C4ClientCore::SetLocal().

72 { return Revision.c_str(); }

Here is the caller graph for this function:

bool StdScheduler::hasProc ( StdSchedulerProc pProc)
inlineinherited

Definition at line 250 of file StdScheduler.h.

Referenced by C4InteractiveThread::RemoveProc().

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

Here is the caller graph for this function:

bool C4AbstractApp::Init ( int  argc,
char *  argv[] 
)
inherited

Definition at line 91 of file C4AppSDL.cpp.

References C4AbstractApp::DoInit(), and LogF().

Referenced by main().

92 {
93  // Set locale
94  setlocale(LC_ALL,"");
95 
96  if (SDL_Init(SDL_INIT_VIDEO) != 0)
97  {
98  LogF("SDL_Init: %s", SDL_GetError());
99  return false;
100  }
101 
102  //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
103 
104  // Custom initialization
105  return DoInit (argc, argv);
106 }
virtual bool DoInit(int argc, char *argv[])=0
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4AbstractApp::IsClipboardFull ( bool  fClipboard = true)
inherited

Definition at line 58 of file C4AppMac.mm.

Referenced by C4GUI::Edit::OnContext().

59 {
60  return [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]];
61 }

Here is the caller graph for this function:

bool StdScheduler::IsInManualLoop ( )
inlineinherited

Definition at line 251 of file StdScheduler.h.

251 { return isInManualLoop; }
bool C4Application::IsQuittingGame ( ) const
inline

Definition at line 70 of file C4Application.h.

References AppState, and C4AS_AfterGame.

Referenced by C4GUI::Dialog::DoModal().

70 { return AppState >= C4AS_AfterGame; }
enum C4Application::State AppState

Here is the caller graph for this function:

void C4AbstractApp::MessageDialog ( const char *  message)
inherited

Definition at line 63 of file C4AppMac.mm.

Referenced by DoInit().

64 {
65  NSAlert* alert = [NSAlert alertWithMessageText:@"Fatal Error"
66  defaultButton:nil
67  alternateButton:nil
68  otherButton:nil
69  informativeTextWithFormat:@"%@",
70  [NSString stringWithUTF8String:message]
71  ];
72  [alert runModal];
73 }

Here is the caller graph for this function:

void C4Application::NextTick ( )

Definition at line 852 of file C4Application.cpp.

References pGameTimer.

Referenced by C4GameControlNetwork::CheckCompleteCtrl(), C4MessageInput::ProcessCommand(), and C4Game::Ticks().

853 {
854  if (!pGameTimer) return;
855  pGameTimer->Set();
856 }
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:87

Here is the caller graph for this function:

void C4AbstractApp::NotifyUserIfInactive ( )
inherited

Definition at line 89 of file C4App.cpp.

References C4AbstractApp::Active, C4Window::FlashWindow(), and C4AbstractApp::pWindow.

Referenced by C4Network2::DoLobby().

90 {
91 #ifdef _WIN32
92  if (!Active && pWindow) pWindow->FlashWindow();
93 #else
94  if (pWindow) pWindow->FlashWindow();
95 #endif
96 }
void FlashWindow()
Definition: C4AppMac.mm:75
bool Active
Definition: C4App.h:63
C4Window * pWindow
Definition: C4App.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::OnCommand ( const char *  szCmd)
virtual

Implements C4AbstractApp.

Definition at line 820 of file C4Application.cpp.

References AppState, C4AS_Game, C4AS_PreInit, C4AS_Startup, Game, MessageInput, C4MessageInput::ProcessInput(), and C4Game::SetScenarioFilename().

Referenced by C4StdInProc::Execute().

821 {
822  if (AppState == C4AS_Game)
824  else if (AppState == C4AS_Startup)
825  {
827  Game.SetScenarioFilename(szCmd);
828  }
829 }
C4Game Game
Definition: C4Globals.cpp:52
C4MessageInput MessageInput
enum C4Application::State AppState
void SetScenarioFilename(const char *)
Definition: C4Game.cpp:532
bool ProcessInput(const char *szText)

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void StdScheduler::OnError ( StdSchedulerProc )
inlineprotectedvirtualinherited

Definition at line 272 of file StdScheduler.h.

272 { }
void C4Application::OnKeyboardLayoutChanged ( )
virtual

Implements C4AbstractApp.

Definition at line 785 of file C4Application.cpp.

References AppState, C4AS_Startup, Game, C4Startup::Get(), C4Startup::OnKeyboardLayoutChanged(), and C4Game::OnKeyboardLayoutChanged().

Referenced by ConsoleDlgProc(), and FullScreenWinProc().

786 {
787  // re-resolve all keys
790 }
C4Game Game
Definition: C4Globals.cpp:52
void OnKeyboardLayoutChanged()
Definition: C4Startup.cpp:350
enum C4Application::State AppState
static C4Startup * Get()
Definition: C4Startup.h:133
void OnKeyboardLayoutChanged()
Definition: C4Game.cpp:3422

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::OnResolutionChanged ( unsigned int  iXRes,
unsigned int  iYRes 
)
virtual

Implements C4AbstractApp.

Definition at line 763 of file C4Application.cpp.

References Config, FullScreenMode(), Game, C4Window::GetSize(), C4Config::Graphics, C4Rect::Hgt, C4Draw::OnResolutionChanged(), C4Game::OnResolutionChanged(), pDraw, C4Window::pSurface, C4AbstractApp::pWindow, C4Surface::UpdateSize(), C4Rect::Wdt, C4ConfigGraphics::WindowX, and C4ConfigGraphics::WindowY.

Referenced by FullScreenWinProc().

764 {
765  // notify game
766  if (pDraw)
767  {
768  Game.OnResolutionChanged(iXRes, iYRes);
769  pDraw->OnResolutionChanged(iXRes, iYRes);
770  }
771  if (pWindow)
772  {
773  if (pWindow->pSurface)
774  pWindow->pSurface->UpdateSize(iXRes, iYRes);
775  if (!FullScreenMode())
776  {
777  C4Rect r;
778  pWindow->GetSize(&r);
781  }
782  }
783 }
C4Config Config
Definition: C4Config.cpp:837
bool GetSize(C4Rect *pRect)
Definition: C4AppT.cpp:106
C4Game Game
Definition: C4Globals.cpp:52
C4Surface * pSurface
Definition: C4Window.h:279
Definition: C4Rect.h:29
C4ConfigGraphics Graphics
Definition: C4Config.h:254
int32_t Wdt
Definition: C4Rect.h:32
bool UpdateSize(int wdt, int hgt)
Definition: C4Surface.cpp:311
int32_t WindowX
Definition: C4Config.h:105
C4Draw * pDraw
Definition: C4Draw.cpp:45
virtual bool OnResolutionChanged(unsigned int iXRes, unsigned int iYRes)=0
int32_t WindowY
Definition: C4Config.h:105
void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes)
Definition: C4Game.cpp:3410
int32_t Hgt
Definition: C4Rect.h:32
C4Window * pWindow
Definition: C4App.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::OpenGame ( const char *  scenario = 0)

Definition at line 640 of file C4Application.cpp.

References AppState, C4AS_AfterGame, C4AS_StartGame, C4AS_Startup, Game, SetNextMission(), and C4Game::SetScenarioFilename().

Referenced by C4StartupNetDlg::DoOK(), C4Console::FileNew(), C4Console::FileOpen(), C4Console::FileOpenWPlrs(), C4StartupMainDlg::OnNetJoin(), and C4StartupScenSelDlg::StartScenario().

641 {
642  if (AppState == C4AS_Startup)
643  {
644  if (scenario) Game.SetScenarioFilename(scenario);
646  }
647  else
648  {
649  SetNextMission(scenario);
651  }
652 
653 }
C4Game Game
Definition: C4Globals.cpp:52
enum C4Application::State AppState
void SetScenarioFilename(const char *)
Definition: C4Game.cpp:532
void SetNextMission(const char *szMissionFilename)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Application::OpenSystemGroup ( )
inline

Definition at line 55 of file C4Application.h.

References C4CFN_System, C4Group::IsOpen(), and C4Group::Open().

Referenced by C4Game::InitScriptEngine().

bool IsOpen() const
Definition: C4Group.cpp:1891
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
#define C4CFN_System
Definition: C4Components.h:29
C4Group SystemGroup
Definition: C4Application.h:40

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::ParseCommandLine ( int  argc,
char *  argv[] 
)
protected

Definition at line 203 of file C4Application.cpp.

References _MAX_PATH, C4Reloc::AddPath(), AltDirectorySeparator, StdStrBuf::Append(), Application, CFG_MaxString, CheckForUpdates, ClearCommandLine(), C4ConfigNetwork::Comment, Config, StdStrBuf::Copy(), ValidatedStdCopyStrBufBase::CopyValidated(), C4Game::DebugHost, C4ConfigGraphics::DebugOpenGL, C4Game::DebugPassword, C4Game::DebugPort, C4ConfigGeneral::DebugRec, C4ConfigGeneral::DebugRecExternalFile, C4ConfigGeneral::DebugRecWrite, C4Game::DebugWait, C4Game::DefinitionFilenames, C4Game::DirectJoinAddress, DirectorySeparator, DirSep, C4Game::fLobby, C4Game::fObserve, Game, C4Config::General, StdStrBuf::getData(), GetExtension(), GetFilename(), GetWorkingDirectory(), C4Config::Graphics, C4Game::HasScenario(), C4Game::iLobbyTimeout, IncomingKeyfile, IncomingUpdate, isEditor, IsGlobalPath(), C4ConfigGeneral::LanguageEx, C4ConfigNetwork::LeagueServerSignUp, Log(), LogF(), C4ConfigNetwork::MasterServerSignUp, Network, C4Config::Network, C4Game::NetworkActive, C4ConfigNetwork::NoRuntimeJoin, C4ConfigGeneral::OpenScenarioInGameMode, C4Game::PlayerFilenames, C4ConfigNetwork::PortTCP, C4ConfigNetwork::PortUDP, QuitAfterGame, C4Game::Record, C4Game::RecordDumpFile, C4Game::RecordStream, Reloc, StdStrBuf::ReplaceChar(), SAddModule(), C4Game::ScenarioFilename, SClearFrontBack(), SCopy(), SEqual2NoCase(), SEqualNoCase(), C4Network2::SetPassword(), C4Game::SetScenarioFilename(), C4Startup::SetStartScreen(), C4ScenarioParameters::SetValue(), SLen(), StdStrBuf::SplitAtChar(), SReplaceChar(), and C4Game::StartupScenarioParameters.

Referenced by DoInit().

204 {
205 
206  StdStrBuf CmdLine("Command line:");
207  for(int i = 0; i < argc; ++i) {
208  CmdLine.Append(" ");
209  CmdLine.Append(argv[i]);
210  }
211  Log(CmdLine.getData());
212 
214  Game.NetworkActive = false;
215  isEditor = 2;
216  int c;
217  while (1)
218  {
219 
220  static struct option long_options[] =
221  {
222  // option, w/ argument?, set directly, set to...
223  {"editor", no_argument, &isEditor, 1},
224  {"fullscreen", no_argument, &isEditor, 0},
225  {"debugwait", no_argument, &Game.DebugWait, 1},
226  {"update", no_argument, &CheckForUpdates, 1},
227  {"noruntimejoin", no_argument, &Config.Network.NoRuntimeJoin, 1},
228  {"runtimejoin", no_argument, &Config.Network.NoRuntimeJoin, 0},
229  {"noleague", no_argument, &Config.Network.LeagueServerSignUp, 0},
230  {"league", no_argument, &Config.Network.LeagueServerSignUp, 1},
231  {"nosignup", no_argument, &Config.Network.MasterServerSignUp, 0},
232  {"signup", no_argument, &Config.Network.MasterServerSignUp, 1},
233 
234  {"debugrecread", required_argument, 0, 'K'},
235  {"debugrecwrite", required_argument, 0, 'w'},
236 
237  {"client", required_argument, 0, 'c'},
238  {"host", no_argument, 0, 'h'},
239  {"debughost", required_argument, 0, 'H'},
240  {"debugpass", required_argument, 0, 'P'},
241  {"debug", required_argument, 0, 'D'},
242  {"data", required_argument, 0, 'd'},
243  {"startup", required_argument, 0, 's'},
244  {"stream", required_argument, 0, 'e'},
245  {"recdump", required_argument, 0, 'R'},
246  {"comment", required_argument, 0, 'm'},
247  {"pass", required_argument, 0, 'p'},
248  {"udpport", required_argument, 0, 'u'},
249  {"tcpport", required_argument, 0, 't'},
250  {"join", required_argument, 0, 'j'},
251  {"language", required_argument, 0, 'L'},
252  {"scenpar", required_argument, 0, 'S'},
253 
254  {"observe", no_argument, 0, 'o'},
255  {"nonetwork", no_argument, 0, 'N'},
256  {"network", no_argument, 0, 'n'},
257  {"record", no_argument, 0, 'r'},
258 
259  {"lobby", optional_argument, 0, 'l'},
260 
261  {"debug-opengl", no_argument, &Config.Graphics.DebugOpenGL, 1},
262  {"config", required_argument, nullptr, 0},
263  {0, 0, 0, 0}
264  };
265  int option_index = 0;
266  c = getopt_long (argc, argv, "abc:d:f:",
267  long_options, &option_index);
268  // no more options
269  if (c == -1)
270  break;
271  switch (c)
272  {
273  case 0:
274  // Signup
275  if (SEqualNoCase(long_options[option_index].name, "signup"))
276  {
277  Game.NetworkActive = true;
278  }
279  // League
280  if (SEqualNoCase(long_options[option_index].name, "league"))
281  {
282  Game.NetworkActive = true;
284  }
285  // Config: Already handled earlier.
286  break;
287  // Lobby
288  case 'l':
289  Game.fLobby = true;
290  // lobby timeout specified? (e.g. --lobby=120)
291  if (optarg)
292  {
293  Game.iLobbyTimeout = atoi(optarg);
294  if (Game.iLobbyTimeout < 0) Game.iLobbyTimeout = 0;
295  }
296  break;
297  case 'o': Game.fObserve = true; break;
298  // Direct join
299  case 'j':
300  Game.NetworkActive = true;
302  break;
303  case 'K':
304  if (optarg && optarg[0])
305  {
306  LogF("Reading from DebugRec file '%s'", optarg);
308  }
309  else
310  Log("Reading DebugRec from CtrlRec file in scenario record");
311  Config.General.DebugRec = 1;
313  break;
314  case 'w':
315  if (optarg && optarg[0])
316  {
317  LogF("Writing to DebugRec file '%s'", optarg);
319  }
320  else
321  Log("Writing DebugRec to CtrlRec file in scenario record");
322  Config.General.DebugRec = 1;
324  break;
325  case 'r': Game.Record = true; break;
326  case 'n': Game.NetworkActive = true; break;
327  case 'N': Game.NetworkActive = false; break;
328  // Language override by parameter
329  case 'L': SCopy(optarg, Config.General.LanguageEx, CFG_MaxString);
330  // port overrides
331  case 't': Config.Network.PortTCP = atoi(optarg); break;
332  case 'u': Config.Network.PortUDP = atoi(optarg); break;
333  // network game password
334  case 'p': Network.SetPassword(optarg); break;
335  // network game comment
336  case 'm': Config.Network.Comment.CopyValidated(optarg); break;
337  // record dump
338  case 'R': Game.RecordDumpFile.Copy(optarg); break;
339  // record stream
340  case 'e': Game.RecordStream.Copy(optarg); break;
341  // startup start screen
342  case 's': C4Startup::SetStartScreen(optarg); break;
343  // additional read-only data path
344  case 'd': Reloc.AddPath(optarg); break;
345  // debug options
346  case 'D': Game.DebugPort = atoi(optarg); break;
347  case 'P': Game.DebugPassword = optarg; break;
348  case 'H': Game.DebugHost = optarg; break;
349  // set custom scenario parameter by command line
350  case 'S':
351  {
352  StdStrBuf sopt, soptval; sopt.Copy(optarg);
353  int32_t val=1;
354  if (sopt.SplitAtChar('=', &soptval)) val=atoi(soptval.getData());
355  Game.StartupScenarioParameters.SetValue(sopt.getData(), val, false);
356  }
357  break;
358  // debug configs
359  case 'h':
360  Game.NetworkActive = true;
361  Game.fLobby = true;
362  Config.Network.PortTCP = 11112;
363  Config.Network.PortUDP = 11113;
365  break;
366  case 'c':
367  Game.NetworkActive = true;
368  SCopy("localhost", Game.DirectJoinAddress, _MAX_PATH);
369  Game.fLobby = true;
370  Config.Network.PortTCP = 11112 + 2*(atoi(optarg)+1);
371  Config.Network.PortUDP = 11113 + 2*(atoi(optarg)+1);
372  break;
373  case '?': /* getopt_long already printed an error message. */ break;
374  default: assert(!"unexpected getopt_long return value");
375  }
376  }
379  if (Game.fObserve || Game.fLobby)
380  Game.NetworkActive = true;
381 
382  while (optind < argc)
383  {
384  char * szParameter = argv[optind++];
385  { // Strip trailing / that result from tab-completing unpacked c4groups
386  int iLen = SLen(szParameter);
387  if (iLen > 5 && szParameter[iLen-1] == '/' && szParameter[iLen-5] == '.' && szParameter[iLen-4] == 'o' && szParameter[iLen-3] == 'c')
388  {
389  szParameter[iLen-1] = '\0';
390  }
391  }
392  // Scenario file
393  if (SEqualNoCase(GetExtension(szParameter),"ocs"))
394  {
395  if(IsGlobalPath(szParameter))
396  Game.SetScenarioFilename(szParameter);
397  else
398  Game.SetScenarioFilename((std::string(GetWorkingDirectory()) + DirSep + szParameter).c_str());
399 
400  continue;
401  }
402  if (SEqualNoCase(GetFilename(szParameter),"scenario.txt"))
403  {
404  Game.SetScenarioFilename(szParameter);
405  continue;
406  }
407  // Player file
408  if (SEqualNoCase(GetExtension(szParameter),"ocp"))
409  {
410  if(IsGlobalPath(szParameter))
411  SAddModule(Game.PlayerFilenames, szParameter);
412  else
413  SAddModule(Game.PlayerFilenames, (std::string(GetWorkingDirectory()) + DirSep + szParameter).c_str());
414 
415  continue;
416  }
417  // Definition file
418  if (SEqualNoCase(GetExtension(szParameter),"ocd"))
419  {
420  SAddModule(Game.DefinitionFilenames,szParameter);
421  continue;
422  }
423  // Key file
424  if (SEqualNoCase(GetExtension(szParameter),"c4k"))
425  {
426  Application.IncomingKeyfile = szParameter;
427  continue;
428  }
429  // Update file
430  if (SEqualNoCase(GetExtension(szParameter),"ocu"))
431  {
432  Application.IncomingUpdate = szParameter;
433  continue;
434  }
435  // record stream
436  if (SEqualNoCase(GetExtension(szParameter),"c4r"))
437  {
438  Game.RecordStream.Copy(szParameter);
439  }
440  // Direct join by URL
441  if (SEqual2NoCase(szParameter, "clonk:"))
442  {
443  // Store address
444  SCopy(szParameter + 6, Game.DirectJoinAddress, _MAX_PATH);
446  // Special case: if the target address is "update" then this is used for update initiation by url
447  if (SEqualNoCase(Game.DirectJoinAddress, "update"))
448  {
450  Game.DirectJoinAddress[0] = 0;
451  continue;
452  }
453  // Self-enable network
454  Game.NetworkActive = true;
455  continue;
456  }
457  }
458 
459 #ifdef _WIN32
460  // Clean up some forward/backward slach confusion since many internal OC file functions cannot handle both
467 #endif
468 
469  // Default to editor if scenario given, player mode otherwise
470  if (isEditor == 2)
472 
473  // record?
475 
476  // startup dialog required?
478 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
int32_t OpenScenarioInGameMode
Definition: C4Config.h:41
void SetPassword(const char *szToPassword)
Definition: C4Network2.cpp:794
int32_t DebugOpenGL
Definition: C4Config.h:118
int32_t iLobbyTimeout
Definition: C4Game.h:121
char ScenarioFilename[_MAX_PATH+1]
Definition: C4Game.h:104
C4Config Config
Definition: C4Config.cpp:837
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
StdStrBuf RecordDumpFile
Definition: C4Game.h:126
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:237
C4Game Game
Definition: C4Globals.cpp:52
bool SplitAtChar(char cSplit, StdStrBuf *psSplit)
Definition: StdBuf.h:627
C4ConfigGeneral General
Definition: C4Config.h:252
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:184
ValidatedStdCopyStrBuf< C4InVal::VAL_Comment > Comment
Definition: C4Config.h:147
StdStrBuf DebugHost
Definition: C4Game.h:150
char DebugRecExternalFile[_MAX_PATH+1]
Definition: C4Config.h:65
static bool SetStartScreen(const char *szScreen)
Definition: C4Startup.cpp:322
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:78
StdStrBuf DebugPassword
Definition: C4Game.h:150
#define AltDirectorySeparator
C4ConfigGraphics Graphics
Definition: C4Config.h:254
uint16_t DebugPort
Definition: C4Game.h:150
C4Network2 Network
Definition: C4Globals.cpp:53
const char * GetWorkingDirectory()
Definition: StdFile.cpp:613
std::string IncomingUpdate
Definition: C4Application.h:77
C4ConfigNetwork Network
Definition: C4Config.h:256
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:131
bool NetworkActive
Definition: C4Game.h:124
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
void SetScenarioFilename(const char *)
Definition: C4Game.cpp:532
int ReplaceChar(char cOld, char cNew)
Definition: StdBuf.cpp:343
C4Reloc Reloc
Definition: C4Reloc.cpp:22
bool fObserve
Definition: C4Game.h:122
int32_t LeagueServerSignUp
Definition: C4Config.h:152
int32_t MasterServerSignUp
Definition: C4Config.h:148
bool AddPath(const char *path, PathType pathType=PATH_Regular)
Definition: C4Reloc.cpp:47
char PlayerFilenames[20 *_MAX_PATH+1]
Definition: C4Game.h:106
int SClearFrontBack(char *szString, char cClear)
Definition: Standard.cpp:432
bool HasScenario()
Definition: C4Game.h:164
class C4ScenarioParameters & StartupScenarioParameters
Definition: C4Game.h:70
std::string IncomingKeyfile
Definition: C4Application.h:98
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
bool Record
Definition: C4Game.h:125
int32_t DebugRecWrite
Definition: C4Config.h:63
StdStrBuf RecordStream
Definition: C4Game.h:127
bool SEqual2NoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:197
char DefinitionFilenames[20 *_MAX_PATH+1]
Definition: C4Game.h:107
int32_t NoRuntimeJoin
Definition: C4Config.h:143
int32_t DebugRec
Definition: C4Config.h:61
void ClearCommandLine()
char DirectJoinAddress[_MAX_PATH+1]
Definition: C4Game.h:108
#define DirSep
bool fLobby
Definition: C4Game.h:120
#define DirectorySeparator
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
void Copy()
Definition: StdBuf.h:475
int32_t PortTCP
Definition: C4Config.h:154
void CopyValidated(const char *szFromVal)
bool SAddModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:534
C4Application Application
Definition: C4Globals.cpp:44
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:325
int32_t PortUDP
Definition: C4Config.h:154
void SetValue(const char *id, int32_t value, bool only_if_larger)
int DebugWait
Definition: C4Game.h:150

Here is the call graph for this function:

Here is the caller graph for this function:

std::string C4AbstractApp::Paste ( bool  fClipboard = true)
inherited

Definition at line 47 of file C4AppMac.mm.

Referenced by C4GUI::Edit::MouseInput().

48 {
49  if (fClipboard)
50  {
51  NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
52  const char* chars = [[pasteboard stringForType:NSStringPboardType] cStringUsingEncoding:NSUTF8StringEncoding];
53  return chars;
54  }
55  return std::string();
56 }

Here is the caller graph for this function:

bool C4Application::PreInit ( )
protected

Definition at line 515 of file C4Application.cpp.

References AppState, C4AS_StartGame, C4AS_Startup, C4CFN_StartupBackgroundMain, Config, C4ConfigGeneral::DefRec, C4ConfigSound::FEMusic, FullScreen, Game, C4Config::General, C4GUI::GetScreenHgt(), C4GUI::GetScreenWdt(), C4Config::Graphics, GraphicsResource, GraphicsSystem, C4Game::HasScenario(), C4MusicSystem::Init(), C4SoundSystem::Init(), C4GraphicsResource::Init(), C4GraphicsSystem::InitLoaderScreen(), C4Startup::InitStartup(), isEditor, LoadResStr(), Log(), LogFatal(), C4GraphicsSystem::MessageBoard, MusicSystem, C4Game::NetworkActive, C4MusicSystem::Play(), C4Game::PreInit(), C4Window::pSurface, C4Game::Record, C4Facet::Set(), C4Game::SetInitProgress(), C4ConfigGraphics::ShowStartupMessages, C4Config::Sound, and SoundSystem.

Referenced by GameTick().

516 {
517  // startup dialog: Only use if no next mission has been provided
518  bool fUseStartupDialog = !Game.HasScenario();
519 
520  // Load graphics early, before we draw anything, since we need shaders
521  // loaded to draw.
522  Game.SetInitProgress(0.0f);
523  Log(LoadResStr("IDS_PRC_GFXRES"));
524  if (!GraphicsResource.Init()) return false;
525  Game.SetInitProgress(fUseStartupDialog ? 10.0f : 1.0f);
526 
527  // Startup message board
528  if (!isEditor)
530  {
532  GraphicsSystem.MessageBoard->Init(cgo,true);
533  }
534 
535  // init loader: Black screen for first start if a video is to be shown; otherwise default spec
536  if (fUseStartupDialog && !isEditor)
537  {
539  { LogFatal(LoadResStr("IDS_PRC_ERRLOADER")); return false; }
540  }
541  Game.SetInitProgress(fUseStartupDialog ? 20.0f : 2.0f);
542 
543  if (!Game.PreInit()) return false;
544 
545  // Music
546  if (!MusicSystem.Init("frontend"))
547  Log(LoadResStr("IDS_PRC_NOMUSIC"));
548 
549  Game.SetInitProgress(fUseStartupDialog ? 34.0f : 2.0f);
550 
551  // Sound
552  if (!SoundSystem.Init())
553  Log(LoadResStr("IDS_PRC_NOSND"));
554 
555  // Play some music! - after sound init because sound system might be needed by music system
556  if (fUseStartupDialog && !isEditor && Config.Sound.FEMusic)
557  MusicSystem.Play();
558 
559  Game.SetInitProgress(fUseStartupDialog ? 35.0f : 3.0f);
560 
561  if (fUseStartupDialog)
562  {
564  // default record?
566  // if no scenario or direct join has been specified, get game startup parameters by startup dialog
567  if (!isEditor)
569  }
570  // directly launch scenario / network game
571  else
572  {
574  }
575 
576  return true;
577 }
C4SoundSystem SoundSystem
Definition: C4Application.h:42
void SetInitProgress(float fToProgress)
Definition: C4Game.cpp:3389
C4Config Config
Definition: C4Config.cpp:837
C4Game Game
Definition: C4Globals.cpp:52
C4ConfigGeneral General
Definition: C4Config.h:252
int32_t FEMusic
Definition: C4Config.h:129
C4Surface * pSurface
Definition: C4Window.h:279
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
bool Init(const char *PlayList=nullptr)
int32_t GetScreenWdt()
Definition: C4Gui.h:2821
enum C4Application::State AppState
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
C4GraphicsResource GraphicsResource
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4ConfigGraphics Graphics
Definition: C4Config.h:254
bool InitLoaderScreen(const char *szLoaderSpec)
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
int32_t DefRec
Definition: C4Config.h:48
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
bool NetworkActive
Definition: C4Game.h:124
int32_t GetScreenHgt()
Definition: C4Gui.h:2822
bool PreInit()
Definition: C4Game.cpp:286
static void InitStartup()
Definition: C4Startup.cpp:309
bool HasScenario()
Definition: C4Game.h:164
std::unique_ptr< C4MessageBoard > MessageBoard
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
bool Record
Definition: C4Game.h:125
C4ConfigSound Sound
Definition: C4Config.h:255
#define C4CFN_StartupBackgroundMain
Definition: C4Startup.h:23
int32_t ShowStartupMessages
Definition: C4Config.h:99
bool Play(const char *szSongname=nullptr, bool fLoop=false, int fadetime_ms=0, double max_resume_time=0.0, bool allow_break=false)
C4MusicSystem MusicSystem
Definition: C4Application.h:41

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Application::ProcessCallback ( const char *  szMessage,
int  iProcess 
)
staticprotected

Definition at line 579 of file C4Application.cpp.

References Console, and C4ConsoleGUI::Out().

Referenced by DoInit().

580 {
581  Console.Out(szMessage);
582  return true;
583 }
C4Console Console
Definition: C4Globals.cpp:45
void Out(const char *message)
Definition: C4Console.cpp:689

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::Quit ( )
virtual

Reimplemented from C4AbstractApp.

Definition at line 625 of file C4Application.cpp.

References AppState, C4AS_Quit, C4GraphicsResource::ClearFonts(), Config, C4Config::fConfigLoaded, GraphicsResource, C4AbstractApp::Quit(), C4Config::Save(), and C4Startup::Unload().

Referenced by C4Console::Clear(), C4FullScreen::Close(), C4Console::Close(), ConsoleDlgProc(), C4StdInProc::Execute(), FullScreenWinProc(), GameTick(), C4Startup::InitStartup(), C4Network2::OnClientDisconnect(), C4StartupMainDlg::OnClosed(), C4StartupMainDlg::OnExitBtn(), C4GameLobby::Countdown::OnSec1Timer(), QuitGame(), RestartApplication(), and C4AppDelegate::suggestQuitting:.

626 {
627  // Participants should not be cleared for usual startup dialog
628 
629  // Save config if there was no loading error
631  // make sure startup data is unloaded
633  // fonts are loaded at start and never unloaded
635  // quit app
638 }
C4Config Config
Definition: C4Config.cpp:837
static void Unload()
Definition: C4Startup.cpp:303
enum C4Application::State AppState
C4GraphicsResource GraphicsResource
virtual void Quit()
Definition: C4AppSDL.cpp:114
bool Save()
Definition: C4Config.cpp:404
bool fConfigLoaded
Definition: C4Config.h:263

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::QuitGame ( )

Definition at line 655 of file C4Application.cpp.

References AppState, C4AS_AfterGame, Quit(), and QuitAfterGame.

Referenced by C4Game::Abort(), C4Console::FileClose(), GameTick(), and C4Game::ShowGameOverDlg().

656 {
657  // reinit desired? Do restart
658  if (!QuitAfterGame || !NextMission.empty())
659  {
661  }
662  else
663  {
664  Quit();
665  }
666 }
enum C4Application::State AppState
virtual void Quit()

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::Remove ( StdSchedulerProc pProc)
inherited

Definition at line 109 of file StdScheduler.cpp.

References StdScheduler::Removing().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::Removing ( StdSchedulerProc pProc)
inherited

Definition at line 286 of file StdSchedulerMac.mm.

References SCHAdditions::requestAdditionsForScheduler:.

Referenced by StdScheduler::Remove().

287 {
288  auto x = [SCHAdditions requestAdditionsForScheduler:this];
289  [x removeAdditionForProc:pProc];
290  if ([x numberOfAdditions] == 0)
291  [SCHAdditions removeAdditions:x];
292 }

Here is the call graph for this function:

Here is the caller graph for this function:

void C4AbstractApp::RestoreVideoMode ( )
inherited

Definition at line 447 of file C4AppSDL.cpp.

References C4AbstractApp::pWindow.

Referenced by Clear().

448 {
449  if (pWindow && pWindow->window)
450  SDL_SetWindowFullscreen(pWindow->window, 0);
451 }
C4Window * pWindow
Definition: C4App.h:80

Here is the caller graph for this function:

void C4AbstractApp::Run ( )
inherited

Definition at line 26 of file C4App.cpp.

References Application, Clamp(), C4AbstractApp::fQuitMsgReceived, StdScheduler::GetNextTick(), isEditor, C4TimeMilliseconds::Now(), and StdScheduler::ScheduleProcs().

Referenced by main().

27 {
28 #ifdef WITH_QT_EDITOR
30  {
31  // Qt has its own event loop. Use a timer to call our own event handling whenever Qt is done
32  // with its events. The alternative (calling Qt's event handling from
33  // C4Console::Execute) is too slow, at least on Linux.
34  // FIXME: All of this should be happening in a background thread instead of on the UI thread
35  QTimer timer;
36  QObject::connect(&timer, &QTimer::timeout, [this, &timer]() {
37  ScheduleProcs(0);
38  if (fQuitMsgReceived)
39  {
40  QApplication::quit();
41  return;
42  }
43  auto now = C4TimeMilliseconds::Now();
44  auto next_tick = GetNextTick(now);
45  timer.setInterval(Clamp(next_tick - now, 0, 1000/36));
46  });
47  timer.setTimerType(Qt::PreciseTimer);
48  timer.start();
49  QApplication::exec();
50  return;
51  }
52 #endif
53 
54  // Main message loop
55  while (!fQuitMsgReceived)
56  ScheduleProcs();
57 }
C4TimeMilliseconds GetNextTick(C4TimeMilliseconds tNow)
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
bool fQuitMsgReceived
Definition: C4App.h:81
bool ScheduleProcs(int iTimeout=1000/36)
C4Application Application
Definition: C4Globals.cpp:44
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 143 of file StdScheduler.cpp.

References StdScheduler::DoScheduleProcs(), StdScheduler::GetNextTick(), and C4TimeMilliseconds::Now().

Referenced by C4AulDebug::DebugStep(), C4Network2::DoLobby(), C4GUI::Dialog::DoModal(), C4ScenarioListLoader::DoProcessCallback(), C4GUI::Dialog::Execute(), C4Network2::FinalInit(), C4Game::InitNetworkFromAddress(), C4Network2::LeaguePlrAuth(), C4Network2::LeagueStart(), C4AulDebug::Listen(), C4Network2::RetrieveRes(), C4AbstractApp::Run(), and C4AppDelegate::suggestQuitting:.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 88 of file StdScheduler.cpp.

References StdScheduler::Add(), and StdScheduler::Clear().

Referenced by StdSchedulerThread::Set().

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Application::SetGameFont ( const char *  szFontFace,
int32_t  iFontSize 
)

Definition at line 792 of file C4Application.cpp.

References C4FontLoader::C4FT_Main, Config, StdStrBuf::Copy(), C4GraphicsResource::Files, FontLoader, C4Config::General, C4Startup::Get(), StdStrBuf::getData(), C4Startup::Graphics, GraphicsResource, C4FontLoader::InitFont(), C4StartupGraphics::InitFonts(), C4GraphicsResource::InitFonts(), C4ConfigGeneral::RXFontName, C4ConfigGeneral::RXFontSize, SCopy(), and SLen().

793 {
794 #ifndef USE_CONSOLE
795  // safety
796  if (!szFontFace || !*szFontFace || iFontSize<1 || SLen(szFontFace)>=static_cast<int>(sizeof Config.General.RXFontName)) return false;
797  // first, check if the selected font can be created at all
798  // check regular font only - there's no reason why the other fonts couldn't be created
799  CStdFont TestFont;
800  if (!::FontLoader.InitFont(&TestFont, szFontFace, C4FontLoader::C4FT_Main, iFontSize, &::GraphicsResource.Files))
801  return false;
802  // OK; reinit all fonts
803  StdStrBuf sOldFont; sOldFont.Copy(Config.General.RXFontName);
804  int32_t iOldFontSize = Config.General.RXFontSize;
805  SCopy(szFontFace, Config.General.RXFontName);
806  Config.General.RXFontSize = iFontSize;
808  {
809  // failed :o
810  // shouldn't happen. Better restore config.
811  SCopy(sOldFont.getData(), Config.General.RXFontName);
812  Config.General.RXFontSize = iOldFontSize;
813  return false;
814  }
815 #endif
816  // save changes
817  return true;
818 }
const char * getData() const
Definition: StdBuf.h:450
C4Config Config
Definition: C4Config.cpp:837
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
C4ConfigGeneral General
Definition: C4Config.h:252
size_t SLen(const char *sptr)
Definition: Standard.h:78
C4GraphicsResource GraphicsResource
char RXFontName[CFG_MaxString+1]
Definition: C4Config.h:42
C4FontLoader FontLoader
int32_t RXFontSize
Definition: C4Config.h:43
static C4Startup * Get()
Definition: C4Startup.h:133
void Copy()
Definition: StdBuf.h:475
C4StartupGraphics Graphics
Definition: C4Startup.h:100
bool InitFont(CStdFont *Font, const char *szFontName, FontType eType, int32_t iSize, C4GroupSet *pGfxGroups, bool fDoShadow=true)

Here is the call graph for this function:

void C4Application::SetGameTickDelay ( int  iDelay)

Definition at line 757 of file C4Application.cpp.

References pGameTimer, and C4ApplicationGameTimer::SetGameTickDelay().

758 {
759  if (!pGameTimer) return;
760  pGameTimer->SetGameTickDelay(iDelay);
761 }
void SetGameTickDelay(uint32_t iDelay)
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:87

Here is the call graph for this function:

void C4Application::SetNextMission ( const char *  szMissionFilename)

Definition at line 839 of file C4Application.cpp.

References AltDirectorySeparator, and DirectorySeparator.

Referenced by OpenGame().

840 {
841  // set next mission if any is desired
842  if (szMissionFilename)
843  {
844  NextMission = szMissionFilename;
845  // scenarios tend to use the wrong slash
846  std::replace(begin(NextMission), end(NextMission), AltDirectorySeparator, DirectorySeparator);
847  }
848  else
849  NextMission.clear();
850 }
#define AltDirectorySeparator
#define DirectorySeparator

Here is the caller graph for this function:

bool C4AbstractApp::SetVideoMode ( int  iXRes,
int  iYRes,
unsigned int  iRefreshRate,
unsigned int  iMonitor,
bool  fFullScreen 
)
inherited

Definition at line 358 of file C4AppSDL.cpp.

References C4Draw::COLOR_DEPTH, C4AbstractApp::Error(), LogF(), C4AbstractApp::OnResolutionChanged(), C4AbstractApp::pWindow, and C4Window::SetSize().

Referenced by DoInit(), FullScreenWinProc(), and GameTick().

359 {
360  int res;
361  if (!fFullScreen)
362  {
363  if (iXRes == -1)
364  {
365  SDL_DisplayMode desktop_mode;
366  res = SDL_GetDesktopDisplayMode(iMonitor, &desktop_mode);
367  if (res)
368  {
369  Error(SDL_GetError());
370  LogF("SDL_GetDesktopDisplayMode: %s", SDL_GetError());
371  return false;
372  }
373 
374  iXRes = desktop_mode.w;
375  iYRes = desktop_mode.h;
376  }
377 
378  res = SDL_SetWindowFullscreen(pWindow->window, 0);
379  if (res)
380  {
381  Error(SDL_GetError());
382  LogF("SDL_SetWindowFullscreen: %s", SDL_GetError());
383  return false;
384  }
385 
386  pWindow->SetSize(iXRes, iYRes);
387  OnResolutionChanged(iXRes, iYRes);
388  return true;
389  }
390  SDL_DisplayMode mode;
391  if (iXRes < 0 || iYRes < 0)
392  {
393  res = SDL_SetWindowFullscreen(pWindow->window, SDL_WINDOW_FULLSCREEN_DESKTOP);
394  if (res)
395  {
396  Error(SDL_GetError());
397  LogF("SDL_SetWindowFullscreen: %s", SDL_GetError());
398  return false;
399  }
400  res = SDL_GetDesktopDisplayMode(iMonitor, &mode);
401  if (res)
402  {
403  Error(SDL_GetError());
404  LogF("SDL_GetDesktopDisplayMode: %s", SDL_GetError());
405  return false;
406  }
407  OnResolutionChanged(mode.w, mode.h);
408  return true;
409  }
410 
411  for (int i = 0; i < modeCount; ++i)
412  {
413  res = SDL_GetDisplayMode(iMonitor, i, &mode);
414 
415  if (res)
416  {
417  Error(SDL_GetError());
418  LogF("SDL_GetDisplayMode: %s", SDL_GetError());
419  return false;
420  }
421 
422  if (mode.w == iXRes && mode.h == iYRes && (RefreshRate == 0 || mode.refresh_rate == RefreshRate) && bits_per_pixel(mode.format) == C4Draw::COLOR_DEPTH)
423  {
424  res = SDL_SetWindowDisplayMode(pWindow->window, &mode);
425  if (res)
426  {
427  Error(SDL_GetError());
428  LogF("SDL_SetWindowDisplayMode: %s", SDL_GetError());
429  return false;
430  }
431  res = SDL_SetWindowFullscreen(pWindow->window, SDL_WINDOW_FULLSCREEN);
432  if (res)
433  {
434  Error(SDL_GetError());
435  LogF("SDL_SetWindowFullscreen: %s", SDL_GetError());
436  return false;
437  }
438  OnResolutionChanged(mode.w, mode.h);
439  return true;
440  }
441  }
442 
443  Error("No such resolution available");
444  return false;
445 }
virtual void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes)=0
static constexpr int COLOR_DEPTH
Definition: C4Draw.h:89
void SetSize(unsigned int cx, unsigned int cy)
Definition: C4AppT.cpp:111
void Error(const char *m)
Definition: C4App.h:99
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
C4Window * pWindow
Definition: C4App.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::StartOnCurrentThread ( )
inherited

Definition at line 276 of file StdSchedulerMac.mm.

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

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

Here is the call graph for this function:

void StdScheduler::UnBlock ( )
inherited

Definition at line 163 of file StdScheduler.cpp.

Referenced by StdSchedulerThread::Stop().

164 {
165  Unblocker.Notify();
166 }

Here is the caller graph for this function:

Member Data Documentation

int C4Application::CheckForUpdates

Definition at line 79 of file C4Application.h.

Referenced by C4StartupMainDlg::OnShown(), and ParseCommandLine().

bool C4AbstractApp::fDspModeSet
protectedinherited

Definition at line 157 of file C4App.h.

std::string C4Application::IncomingKeyfile
protected

Definition at line 98 of file C4Application.h.

Referenced by ParseCommandLine().

std::string C4Application::IncomingUpdate

Definition at line 77 of file C4Application.h.

Referenced by DoInit(), C4StartupMainDlg::OnShown(), and ParseCommandLine().

pthread_t C4AbstractApp::MainThread
inherited

Definition at line 128 of file C4App.h.

Referenced by C4AbstractApp::AssertMainThread().

C4GamePadControl* C4Application::pGamePadControl

Definition at line 43 of file C4Application.h.

Referenced by Clear(), DoInit(), GameTick(), C4GameControl::PrepareInput(), and ~C4Application().

C4ApplicationGameTimer* C4Application::pGameTimer
protected

Definition at line 87 of file C4Application.h.

Referenced by Clear(), DoInit(), NextTick(), and SetGameTickDelay().

int C4Application::QuitAfterGame
protected

Definition at line 96 of file C4Application.h.

Referenced by ParseCommandLine(), and QuitGame().

bool C4Application::restartAtEnd

Definition at line 38 of file C4Application.h.

Referenced by main().

std::string C4AbstractApp::sLastError
protectedinherited

Definition at line 156 of file C4App.h.

Referenced by C4AbstractApp::Error(), and C4AbstractApp::GetLastError().

C4Group C4Application::SystemGroup

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