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 () override
 
void Clear () override
 
void ClearCommandLine ()
 
void GameTick ()
 
void Draw ()
 
bool OpenSystemGroup ()
 
void CloseSystemGroup ()
 
void SetGameTickDelay (int iDelay)
 
void OnResolutionChanged (unsigned int iXRes, unsigned int iYRes) override
 
void OnKeyboardLayoutChanged () override
 
bool SetGameFont (const char *szFontFace, int32_t iFontSize)
 
void NextTick ()
 
void Quit () override
 
void OpenGame (const char *scenario=nullptr)
 
void QuitGame ()
 
void Activate ()
 
void SetNextMission (const char *szMissionFilename)
 
void OnCommand (const char *szCmd) override
 
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 ()
 
bool DoScheduleProcs (int iTimeout) override
 
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 {false}
 
C4Group SystemGroup
 
C4MusicSystem MusicSystem
 
C4SoundSystem SoundSystem
 
C4GamePadControlpGamePadControl {nullptr}
 
C4InteractiveThread InteractiveThread
 
C4Network2IRCClientIRCClient
 
int isEditor {false}
 
std::string IncomingUpdate
 
int CheckForUpdates {false}
 
bool Active {false}
 
C4WindowpWindow {nullptr}
 
bool fQuitMsgReceived {false}
 
pthread_t MainThread
 

Protected Types

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

Protected Member Functions

bool DoInit (int argc, char *argv[]) override
 
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 C4AS_None
 
C4ApplicationGameTimerpGameTimer {nullptr}
 
int QuitAfterGame {false}
 
std::string IncomingKeyfile
 
std::string sLastError
 
bool fDspModeSet {false}
 

Detailed Description

Definition at line 32 of file C4Application.h.

Member Enumeration Documentation

enum C4Application::State
protected
Enumerator
C4AS_None 
C4AS_PreInit 
C4AS_Startup 
C4AS_StartGame 
C4AS_Game 
C4AS_AfterGame 
C4AS_Quit 

Definition at line 86 of file C4Application.h.

Constructor & Destructor Documentation

C4Application::C4Application ( )

Definition at line 48 of file C4Application.cpp.

48  :
49  IRCClient(ApplicationIRCClient)
50 {
51 }
C4Network2IRCClient & IRCClient
Definition: C4Application.h:47
C4Application::~C4Application ( )
override

Definition at line 53 of file C4Application.cpp.

References CloseLog(), and pGamePadControl.

54 {
55  // clear gamepad
56  if (pGamePadControl) delete pGamePadControl;
57  // Close log
58  CloseLog();
59 }
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
bool CloseLog()
Definition: C4Log.cpp:97

Here is the call graph for this function:

Member Function Documentation

void C4Application::Activate ( )

Definition at line 821 of file C4Application.cpp.

References FullScreen.

Referenced by C4StartupMainDlg::OnShown().

822 {
823 #ifdef USE_WIN32_WINDOWS
824  BringWindowToTop(FullScreen.hWindow);
825  ShowWindow(FullScreen.hWindow, SW_SHOW);
826 #endif
827 }
C4FullScreen FullScreen
Definition: C4Globals.cpp:46

Here is the caller graph for this function:

void StdScheduler::Add ( StdSchedulerProc pProc)
inherited

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

85 {
86  // Already added to some scheduler
87  if (pProc->scheduler)
88  return;
89  // Add
90  procs.push_back(pProc);
91  pProc->scheduler = this;
92 
93  Added(pProc);
94 }
void Added(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::Added ( StdSchedulerProc pProc)
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 470 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().

471 {
472  // Not changing the resolution always works anyway
473  if (Config.Graphics.ResX == -1 && Config.Graphics.ResY == -1)
474  return;
475  // Enumerate display modes
476  int32_t idx = -1, iXRes, iYRes, iBitDepth, iRefreshRate;
477  int32_t best_match = -1;
478  uint32_t best_delta = ~0;
479  while (GetIndexedDisplayMode(++idx, &iXRes, &iYRes, &iBitDepth, &iRefreshRate, Config.Graphics.Monitor))
480  {
481  if (iBitDepth != C4Draw::COLOR_DEPTH) continue;
482  uint32_t delta = std::abs(Config.Graphics.ResX*Config.Graphics.ResY - iXRes*iYRes);
483  if (!delta && iBitDepth == C4Draw::COLOR_DEPTH && iRefreshRate == Config.Graphics.RefreshRate)
484  return; // Exactly the expected mode
485  if (delta < best_delta)
486  {
487  // Better match than before
488  best_match = idx;
489  best_delta = delta;
490  }
491  }
492  if (best_match != -1)
493  {
494  // Apply next-best mode
495  GetIndexedDisplayMode(best_match, &iXRes, &iYRes, &iBitDepth, &iRefreshRate, Config.Graphics.Monitor);
496  if (iXRes != Config.Graphics.ResX || iYRes != Config.Graphics.ResY)
497  // Don't warn if only bit depth changes
498  // Also, lang table not loaded yet
499  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);
500  Config.Graphics.ResX = iXRes; Config.Graphics.ResY = iYRes;
501  Config.Graphics.RefreshRate = iRefreshRate;
502  }
503 }
int32_t RefreshRate
Definition: C4Config.h:105
C4Config Config
Definition: C4Config.cpp:833
static constexpr int COLOR_DEPTH
Definition: C4Draw.h:89
C4ConfigGraphics Graphics
Definition: C4Config.h:253
bool GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32_t *piYRes, int32_t *piBitDepth, int32_t *piRefreshRate, uint32_t iMonitor)
Definition: C4AppSDL.cpp:335
int32_t Monitor
Definition: C4Config.h:112
int32_t ResX
Definition: C4Config.h:103
int32_t ResY
Definition: C4Config.h:103
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250

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

Reimplemented from C4AbstractApp.

Definition at line 575 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:.

576 {
577  Game.Clear();
578  NextMission.clear();
579  // stop timer
580  if (pGameTimer)
581  {
583  delete pGameTimer; pGameTimer = nullptr;
584  }
585  // quit irc
586  IRCClient.Close();
587  // close system group (System.ocg)
588  SystemGroup.Close();
589  // Log
590  if (::Languages.HasStringTable()) // Avoid (double and undefined) message on (second?) shutdown...
591  Log(LoadResStr("IDS_PRC_DEINIT"));
592  // Clear external language packs and string table
593  Languages.Clear();
595  // gamepad clear
596  if (pGamePadControl) { delete pGamePadControl; pGamePadControl=nullptr; }
597  // music system clear
598  MusicSystem.Clear();
599  SoundSystem.Clear();
601  // clear editcursor holding graphics before clearing draw
603  // Clear direct draw (late, because it's needed for e.g. Log)
604  if (pDraw) { delete pDraw; pDraw=nullptr; }
605  // Close window
606  FullScreen.Clear();
607  Console.Clear();
608  // There might be pending saves - do them after the fullscreen windows got closed
609  // so the app just remains as a lingering process until saving is done
611  // The very final stuff
613 }
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:410
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
static void WaitForSaves()
Definition: StdPNG.cpp:360
bool Close() override
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void Clear() override
Definition: C4Console.cpp:418
C4Language Languages
Definition: C4Language.cpp:42
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:87
bool Close()
Definition: C4Group.cpp:755
C4Draw * pDraw
Definition: C4Draw.cpp:42
void Clear() override
void Remove(StdSchedulerProc *pProc)
void RestoreVideoMode()
Definition: C4AppSDL.cpp:443
virtual void Clear()
Definition: C4AppSDL.cpp:105
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
void Clear()
Definition: C4Game.cpp:537
void Clear()
Definition: C4Language.cpp:114
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 188 of file C4Application.cpp.

References Game, and C4Game::PlayerFilenames.

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

189 {
190  *Game.PlayerFilenames = 0;
191 }
C4Game Game
Definition: C4Globals.cpp:52
char PlayerFilenames[20 *_MAX_PATH+1]
Definition: C4Game.h:104

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 33 of file C4AppMac.mm.

References Log().

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

34 {
35  NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
36  [pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
37  NSString* string = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding];
38  if (![pasteboard setString:string forType:NSStringPboardType])
39  {
40  Log("Writing to Cocoa pasteboard failed");
41  return false;
42  }
43  return true;
44 }
bool Log(const char *szMessage)
Definition: C4Log.cpp:192

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements C4AbstractApp.

Definition at line 61 of file C4Application.cpp.

References C4AbstractApp::Active, StdScheduler::Add(), Application, ApplyResolutionConstraints(), 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, C4Reloc::Init(), C4FullScreen::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.

62 {
63  assert(AppState == C4AS_None);
64  // Config overwrite by parameter
65  StdStrBuf sConfigFilename;
66  for (int32_t iPar=0; iPar < argc; iPar++)
67  if (SEqual2NoCase(argv[iPar], "--config="))
68  sConfigFilename.Copy(argv[iPar] + 9);
69  // Config check
70  Config.Init();
71  Config.Load(sConfigFilename.getData());
72  Config.Save();
73  // sometimes, the configuration can become corrupted due to loading errors or w/e
74  // check this and reset defaults if necessary
75  if (Config.IsCorrupted())
76  {
77  if (sConfigFilename)
78  {
79  // custom config corrupted: Fail
80  Log("ERROR: Custom configuration corrupted - program abort!\n");
81  return false;
82  }
83  else
84  {
85  // default config corrupted: Restore default
86  Log("Warning: Configuration corrupted - restoring default!\n");
87  Config.Default();
88  Config.Save();
89  Config.Load();
90  }
91  }
92  // Open log
93  OpenLog();
94 
95  // Engine header message
96  Log(C4ENGINECAPTION);
97  LogF("Version: %s %s (%s - %s)", C4VERSION, C4_OS, GetRevision(), C4REVISION_TS);
98  LogF(R"(ExePath: "%s")", Config.General.ExePath.getData());
99  LogF(R"(SystemDataPath: "%s")", Config.General.SystemDataPath);
100  LogF(R"(UserDataPath: "%s")", Config.General.UserDataPath);
101 
102  // Init C4Group
106 
107  // Cleanup temp folders left behind
109 
110  // Initialize game data paths
111  Reloc.Init();
112 
113  // init system group
115  {
116  // Error opening system group - no LogFatal, because it needs language table.
117  // This will *not* use the FatalErrors stack, but this will cause the game
118  // to instantly halt, anyway.
119  const char *szMessage = "Error opening system group file (System.ocg)!";
120  Log(szMessage);
121  // Fatal error, game cannot start - have player notice
122  MessageDialog(szMessage);
123  return false;
124  }
125  // Parse command line
126  ParseCommandLine(argc, argv);
127 
128  // Open additional logs that depend on command line
129  OpenExtraLogs();
130 
131  // Init external language packs
132  Languages.Init();
133  // Load language string table
135  // No language table was loaded - bad luck...
136  if (!Languages.HasStringTable())
137  Log("WARNING: No language string table loaded!");
138 
139 #if defined(WIN32) && defined(WITH_AUTOMATIC_UPDATE)
140  // Windows: handle incoming updates directly, even before starting up the gui
141  // because updates will be applied in the console anyway.
142  if (!Application.IncomingUpdate.empty())
143  if (C4UpdateDlg::ApplyUpdate(Application.IncomingUpdate.c_str(), false, nullptr))
144  return true;
145 #endif
146 
147  // Fixup resolution
148  if (!Config.Graphics.Windowed)
150 
151  // activate
152  Active=true;
153 
154  // Init carrier window
155  if (!isEditor)
156  {
157  if (!(pWindow = FullScreen.Init(this)))
158  { Clear(); ShowGfxErrorDialog(); return false; }
159  }
160  else
161  {
162  if (!(pWindow = Console.Init(this)))
163  { Clear(); return false; }
164  }
165 
166  // init timers (needs window)
168 
169  // Initialize OpenGL
170  bool success = DDrawInit(this, GetConfigWidth(), GetConfigHeight(), Config.Graphics.Monitor);
171  if (!success) { LogFatal(LoadResStr("IDS_ERR_DDRAW")); Clear(); ShowGfxErrorDialog(); return false; }
172 
173  if (!isEditor)
174  {
177  }
178 
179  // Initialize gamepad
182 
183  AppState = C4AS_PreInit;
184 
185  return true;
186 }
const char * getData() const
Definition: StdBuf.h:442
int32_t RefreshRate
Definition: C4Config.h:105
void Default()
Definition: C4Config.cpp:283
void ShowGfxErrorDialog()
C4Config Config
Definition: C4Config.cpp:833
C4Console Console
Definition: C4Globals.cpp:45
void MessageDialog(const char *message)
Definition: C4AppMac.mm:62
C4ConfigGeneral General
Definition: C4Config.h:251
bool HasStringTable() const
Definition: C4Language.h:70
void C4Group_SetSortList(const char **ppSortList)
Definition: C4Group.cpp:69
int32_t Windowed
Definition: C4Config.h:106
bool OpenExtraLogs()
Definition: C4Log.cpp:73
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
bool SetVideoMode(int iXRes, int iYRes, unsigned int iRefreshRate, unsigned int iMonitor, bool fFullScreen)
Definition: C4AppSDL.cpp:354
const char * C4CFN_FLS[]
Definition: C4Group.cpp:32
void CleanupTempUpdateFolder()
Definition: C4Config.cpp:804
enum C4Application::State C4AS_None
const char * GetRevision() const
Definition: C4Application.h:72
bool GamepadEnabled
Definition: C4Config.h:58
bool IsCorrupted()
Definition: C4Config.h:284
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:253
void SetSize(unsigned int cx, unsigned int cy)
Definition: C4AppT.cpp:110
void Clear() override
bool Active
Definition: C4App.h:63
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:54
C4Language Languages
Definition: C4Language.cpp:42
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:87
std::string IncomingUpdate
Definition: C4Application.h:77
int32_t WindowX
Definition: C4Config.h:104
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
bool Open(C4Group &hGroup, const char *filename) const
Definition: C4Reloc.cpp:82
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:227
static bool ProcessCallback(const char *szMessage, int iProcess)
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:37
void ParseCommandLine(int argc, char *argv[])
C4Reloc Reloc
Definition: C4Reloc.cpp:21
int GetConfigWidth()
Definition: C4Application.h:82
void Init()
Definition: C4Reloc.cpp:23
bool DDrawInit(C4AbstractApp *pApp, unsigned int iXRes, unsigned int iYRes, unsigned int iMonitor)
Definition: C4Draw.cpp:796
int32_t Monitor
Definition: C4Config.h:112
bool LoadLanguage(const char *strLanguages)
Definition: C4Language.cpp:361
int32_t WindowY
Definition: C4Config.h:104
StdCopyStrBuf TempPath
Definition: C4Config.h:53
bool OpenLog()
Definition: C4Log.cpp:48
bool Init()
Definition: C4Language.cpp:55
#define C4_OS
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
bool SEqual2NoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:220
bool Save()
Definition: C4Config.cpp:400
void C4Group_SetTempPath(const char *szPath)
Definition: C4Group.cpp:74
bool Load(const char *szConfigFile=nullptr)
Definition: C4Config.cpp:311
StdCopyStrBuf ExePath
Definition: C4Config.h:52
virtual C4Window * Init(C4AbstractApp *app)
Definition: C4Console.cpp:58
int GetConfigHeight()
Definition: C4Application.h:83
bool Init()
Definition: C4Config.cpp:708
#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:250
void Copy()
Definition: StdBuf.h:467
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)
overridevirtualinherited

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:115
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 735 of file C4Application.cpp.

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

Referenced by C4ApplicationGameTimer::Execute().

736 {
737  // Graphics
738 
739  // Fullscreen mode
740  if (!isEditor)
742  // Console mode
743  else
744  Console.Execute();
745 }
void Execute()
Definition: C4Console.cpp:581
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 115 of file C4AppSDL.cpp.

References C4AbstractApp::fQuitMsgReceived.

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

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

Here is the caller graph for this function:

bool C4Application::FullScreenMode ( )

Definition at line 848 of file C4Application.cpp.

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

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

849 {
850  if(isEditor)
851  return false;
853  return true;
855  return true;
856  return false;
857 }
bool IsRunning
Definition: C4Game.h:139
C4Config Config
Definition: C4Config.cpp:833
C4Game Game
Definition: C4Globals.cpp:52
int32_t Windowed
Definition: C4Config.h:106
C4ConfigGraphics Graphics
Definition: C4Config.h:253

Here is the caller graph for this function:

void C4Application::GameTick ( )

Definition at line 658 of file C4Application.cpp.

References Application, 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().

659 {
660  // Exec depending on game state
661  switch (AppState)
662  {
663  case C4AS_None:
664  assert(AppState != C4AS_None);
665  break;
666  case C4AS_Quit:
667  // Do nothing, the main loop will exit soon
668  break;
669  case C4AS_PreInit:
670  if (!PreInit()) Quit();
671  break;
672  case C4AS_Startup:
676  // wait for the user to start a game
677  break;
678  case C4AS_StartGame:
679  // immediate progress to next state; OpenGame will enter HandleMessage-loops in startup and lobby!
681  AppState = C4AS_Game;
682 #ifdef WITH_QT_EDITOR
683  // Notify console
685 #endif
686  // first-time game initialization
687  if (!Game.Init())
688  {
689  // set error flag (unless this was a lobby user abort)
691  Game.fQuitWithError = true;
692  // no start: Regular QuitGame; this may reset the engine to startup mode if desired
693  QuitGame();
694  break;
695  }
696  if(Config.Graphics.Windowed == 2 && FullScreenMode())
698  if (!isEditor)
699  pWindow->GrabMouse(true);
700  // Gamepad events have to be polled here so that the controller
701  // connection state is always up-to-date before players are
702  // joining.
704  break;
705  case C4AS_AfterGame:
706  // stop game
707  Game.Clear();
708  if(Config.Graphics.Windowed == 2 && NextMission.empty() && !isEditor)
710  if (!isEditor)
711  pWindow->GrabMouse(false);
712  AppState = C4AS_PreInit;
713  // if a next mission is desired, set to start it
714  if (!NextMission.empty())
715  {
716  Game.SetScenarioFilename(NextMission.c_str());
718  Game.fObserve = false;
719  NextMission.clear();
720  }
721  break;
722  case C4AS_Game:
723  // Game
724  if (Game.IsRunning)
725  Game.Execute();
726  // Sound
729  // Gamepad
731  break;
732  }
733 }
C4SoundSystem SoundSystem
Definition: C4Application.h:42
int32_t RefreshRate
Definition: C4Config.h:105
void Execute(bool force_buffer_checks=false)
bool IsRunning
Definition: C4Game.h:139
C4Config Config
Definition: C4Config.cpp:833
void GrabMouse(bool grab)
Definition: C4AppT.cpp:104
C4Console Console
Definition: C4Globals.cpp:45
C4Game Game
Definition: C4Globals.cpp:52
int32_t Windowed
Definition: C4Config.h:106
bool SetVideoMode(int iXRes, int iYRes, unsigned int iRefreshRate, unsigned int iMonitor, bool fFullScreen)
Definition: C4AppSDL.cpp:354
bool Execute()
Definition: C4Game.cpp:709
enum C4Application::State C4AS_None
void OnStartGame()
Definition: C4ConsoleGUI.h:114
C4ConfigGraphics Graphics
Definition: C4Config.h:253
bool Init()
Definition: C4Game.cpp:328
bool fQuitWithError
Definition: C4Game.h:142
bool NetworkActive
Definition: C4Game.h:122
void SetScenarioFilename(const char *)
Definition: C4Game.cpp:528
int GetConfigWidth()
Definition: C4Application.h:82
bool fObserve
Definition: C4Game.h:120
void Quit() override
int32_t Monitor
Definition: C4Config.h:112
static void CloseStartup()
Definition: C4Startup.cpp:280
int GetConfigHeight()
Definition: C4Application.h:83
void Clear()
Definition: C4Game.cpp:537
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
bool fLobby
Definition: C4Game.h:118
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:833
C4ConfigGraphics Graphics
Definition: C4Config.h:253
int32_t WindowY
Definition: C4Config.h:104
int32_t ResY
Definition: C4Config.h:103

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:833
C4ConfigGraphics Graphics
Definition: C4Config.h:253
int32_t WindowX
Definition: C4Config.h:104
int32_t ResX
Definition: C4Config.h:103

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 335 of file C4AppSDL.cpp.

Referenced by ApplyResolutionConstraints().

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

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

References C4TimeMilliseconds::PositiveInfinity.

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

121 {
123  for (auto proc : procs)
124  {
125  tProcTick = std::min(tProcTick, proc->GetNextTick(tNow));
126  }
127  return tProcTick;
128 }

Here is the caller graph for this function:

int StdScheduler::getProcCnt ( ) const
inlineinherited

Definition at line 245 of file StdScheduler.h.

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

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

Here is the caller graph for this function:

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

Referenced by C4InteractiveThread::RemoveProc().

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

Here is the caller graph for this function:

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

Definition at line 87 of file C4AppSDL.cpp.

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

Referenced by main().

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

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 57 of file C4AppMac.mm.

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

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

Here is the caller graph for this function:

bool StdScheduler::IsInManualLoop ( )
inlineinherited

Definition at line 247 of file StdScheduler.h.

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

Definition at line 70 of file C4Application.h.

References C4AS_AfterGame.

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

70 { return AppState >= C4AS_AfterGame; }

Here is the caller graph for this function:

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

Definition at line 62 of file C4AppMac.mm.

Referenced by DoInit().

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

Here is the caller graph for this function:

void C4Application::NextTick ( )

Definition at line 842 of file C4Application.cpp.

References pGameTimer.

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

843 {
844  if (!pGameTimer) return;
845  pGameTimer->Set();
846 }
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:74
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)
overridevirtual

Implements C4AbstractApp.

Definition at line 810 of file C4Application.cpp.

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

Referenced by C4StdInProc::Execute().

811 {
812  if (AppState == C4AS_Game)
814  else if (AppState == C4AS_Startup)
815  {
816  AppState = C4AS_PreInit;
817  Game.SetScenarioFilename(szCmd);
818  }
819 }
C4Game Game
Definition: C4Globals.cpp:52
C4MessageInput MessageInput
void SetScenarioFilename(const char *)
Definition: C4Game.cpp:528
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 268 of file StdScheduler.h.

268 { }
void C4Application::OnKeyboardLayoutChanged ( )
overridevirtual

Implements C4AbstractApp.

Definition at line 775 of file C4Application.cpp.

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

Referenced by ConsoleDlgProc(), and FullScreenWinProc().

776 {
777  // re-resolve all keys
780 }
C4Game Game
Definition: C4Globals.cpp:52
void OnKeyboardLayoutChanged()
Definition: C4Startup.cpp:348
static C4Startup * Get()
Definition: C4Startup.h:133
void OnKeyboardLayoutChanged()
Definition: C4Game.cpp:3418

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 
)
overridevirtual

Implements C4AbstractApp.

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

754 {
755  // notify game
756  if (pDraw)
757  {
758  Game.OnResolutionChanged(iXRes, iYRes);
759  pDraw->OnResolutionChanged(iXRes, iYRes);
760  }
761  if (pWindow)
762  {
763  if (pWindow->pSurface)
764  pWindow->pSurface->UpdateSize(iXRes, iYRes);
765  if (!FullScreenMode())
766  {
767  C4Rect r;
768  pWindow->GetSize(&r);
771  }
772  }
773 }
C4Config Config
Definition: C4Config.cpp:833
bool GetSize(C4Rect *pRect)
Definition: C4AppT.cpp:105
C4Game Game
Definition: C4Globals.cpp:52
C4Surface * pSurface
Definition: C4Window.h:274
Definition: C4Rect.h:27
C4ConfigGraphics Graphics
Definition: C4Config.h:253
int32_t Wdt
Definition: C4Rect.h:30
bool UpdateSize(int wdt, int hgt)
Definition: C4Surface.cpp:301
int32_t WindowX
Definition: C4Config.h:104
C4Draw * pDraw
Definition: C4Draw.cpp:42
virtual bool OnResolutionChanged(unsigned int iXRes, unsigned int iYRes)=0
int32_t WindowY
Definition: C4Config.h:104
void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes)
Definition: C4Game.cpp:3406
int32_t Hgt
Definition: C4Rect.h:30
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 = nullptr)

Definition at line 630 of file C4Application.cpp.

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

631 {
632  if (AppState == C4AS_Startup)
633  {
634  if (scenario) Game.SetScenarioFilename(scenario);
635  AppState = C4AS_StartGame;
636  }
637  else
638  {
639  SetNextMission(scenario);
640  AppState = C4AS_AfterGame;
641  }
642 
643 }
C4Game Game
Definition: C4Globals.cpp:52
void SetScenarioFilename(const char *)
Definition: C4Game.cpp:528
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 193 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().

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

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 46 of file C4AppMac.mm.

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

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

Here is the caller graph for this function:

bool C4Application::PreInit ( )
protected

Definition at line 505 of file C4Application.cpp.

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

506 {
507  // startup dialog: Only use if no next mission has been provided
508  bool fUseStartupDialog = !Game.HasScenario();
509 
510  // Load graphics early, before we draw anything, since we need shaders
511  // loaded to draw.
512  Game.SetInitProgress(0.0f);
513  Log(LoadResStr("IDS_PRC_GFXRES"));
514  if (!GraphicsResource.Init()) return false;
515  Game.SetInitProgress(fUseStartupDialog ? 10.0f : 1.0f);
516 
517  // Startup message board
518  if (!isEditor)
520  {
522  GraphicsSystem.MessageBoard->Init(cgo,true);
523  }
524 
525  // init loader: Black screen for first start if a video is to be shown; otherwise default spec
526  if (fUseStartupDialog && !isEditor)
527  {
529  { LogFatal(LoadResStr("IDS_PRC_ERRLOADER")); return false; }
530  }
531  Game.SetInitProgress(fUseStartupDialog ? 20.0f : 2.0f);
532 
533  if (!Game.PreInit()) return false;
534 
535  // Music
536  if (!MusicSystem.Init("frontend"))
537  Log(LoadResStr("IDS_PRC_NOMUSIC"));
538 
539  Game.SetInitProgress(fUseStartupDialog ? 34.0f : 2.0f);
540 
541  // Sound
542  if (!SoundSystem.Init())
543  Log(LoadResStr("IDS_PRC_NOSND"));
544 
545  // Play some music! - after sound init because sound system might be needed by music system
546  if (fUseStartupDialog && !isEditor && Config.Sound.FEMusic)
547  MusicSystem.Play();
548 
549  Game.SetInitProgress(fUseStartupDialog ? 35.0f : 3.0f);
550 
551  if (fUseStartupDialog)
552  {
553  AppState = C4AS_Startup;
554  // default record?
556  // if no scenario or direct join has been specified, get game startup parameters by startup dialog
557  if (!isEditor)
559  }
560  // directly launch scenario / network game
561  else
562  {
563  AppState = C4AS_StartGame;
564  }
565 
566  return true;
567 }
C4SoundSystem SoundSystem
Definition: C4Application.h:42
void SetInitProgress(float fToProgress)
Definition: C4Game.cpp:3385
C4Config Config
Definition: C4Config.cpp:833
C4Game Game
Definition: C4Globals.cpp:52
C4ConfigGeneral General
Definition: C4Config.h:251
int32_t FEMusic
Definition: C4Config.h:128
C4Surface * pSurface
Definition: C4Window.h:274
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
bool Init(const char *PlayList=nullptr)
int32_t GetScreenWdt()
Definition: C4Gui.h:2821
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:253
bool InitLoaderScreen(const char *szLoaderSpec)
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
int32_t DefRec
Definition: C4Config.h:47
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:227
bool NetworkActive
Definition: C4Game.h:122
int32_t GetScreenHgt()
Definition: C4Gui.h:2822
bool PreInit()
Definition: C4Game.cpp:282
static void InitStartup()
Definition: C4Startup.cpp:307
bool HasScenario()
Definition: C4Game.h:162
std::unique_ptr< C4MessageBoard > MessageBoard
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
bool Record
Definition: C4Game.h:123
C4ConfigSound Sound
Definition: C4Config.h:254
#define C4CFN_StartupBackgroundMain
Definition: C4Startup.h:23
int32_t ShowStartupMessages
Definition: C4Config.h:98
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 569 of file C4Application.cpp.

References Console, and C4ConsoleGUI::Out().

Referenced by DoInit().

570 {
571  Console.Out(szMessage);
572  return true;
573 }
C4Console Console
Definition: C4Globals.cpp:45
void Out(const char *message)
Definition: C4Console.cpp:684

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::Quit ( )
overridevirtual

Reimplemented from C4AbstractApp.

Definition at line 615 of file C4Application.cpp.

References 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:.

616 {
617  // Participants should not be cleared for usual startup dialog
618 
619  // Save config if there was no loading error
621  // make sure startup data is unloaded
623  // fonts are loaded at start and never unloaded
625  // quit app
627  AppState = C4AS_Quit;
628 }
C4Config Config
Definition: C4Config.cpp:833
static void Unload()
Definition: C4Startup.cpp:301
C4GraphicsResource GraphicsResource
virtual void Quit()
Definition: C4AppSDL.cpp:110
bool Save()
Definition: C4Config.cpp:400
bool fConfigLoaded
Definition: C4Config.h:262

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Application::QuitGame ( )

Definition at line 645 of file C4Application.cpp.

References C4AS_AfterGame, Quit(), and QuitAfterGame.

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

646 {
647  // reinit desired? Do restart
648  if (!QuitAfterGame || !NextMission.empty())
649  {
650  AppState = C4AS_AfterGame;
651  }
652  else
653  {
654  Quit();
655  }
656 }
void Quit() override

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 96 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(), C4AbstractApp::~C4AbstractApp(), C4GameOverDlg::~C4GameOverDlg(), C4GameSec1Timer::~C4GameSec1Timer(), C4InteractiveThread::~C4InteractiveThread(), C4Network2ClientListBox::~C4Network2ClientListBox(), C4Network2ClientListDlg::~C4Network2ClientListDlg(), C4Network2Stats::~C4Network2Stats(), C4StartupNetDlg::~C4StartupNetDlg(), C4GameLobby::Countdown::~Countdown(), C4GUI::InfoDialog::~InfoDialog(), and C4GameLobby::MainDlg::~MainDlg().

97 {
98  // :o ?
99  if (pProc->scheduler != this)
100  return;
101  Removing(pProc);
102  pProc->scheduler = nullptr;
103  auto pos = std::find(procs.begin(), procs.end(), pProc);
104  if (pos != procs.end())
105  procs.erase(pos);
106 }
void Removing(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

void StdScheduler::Removing ( StdSchedulerProc pProc)
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 443 of file C4AppSDL.cpp.

References C4AbstractApp::pWindow.

Referenced by Clear().

444 {
445  if (pWindow && pWindow->window)
446  SDL_SetWindowFullscreen(pWindow->window, 0);
447 }
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:44
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 130 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:.

131 {
132  // Needs at least one process to work properly
133  if (!procs.size()) return false;
134 
135  // Get timeout
137  C4TimeMilliseconds tProcTick = GetNextTick(tNow);
138  if (iTimeout == -1 || tNow + iTimeout > tProcTick)
139  {
140  iTimeout = std::max<decltype(iTimeout)>(tProcTick - tNow, 0);
141  }
142 
143  bool old = isInManualLoop;
144  isInManualLoop = true;
145  bool res = DoScheduleProcs(iTimeout);
146  isInManualLoop = old;
147  return res;
148 }
C4TimeMilliseconds GetNextTick(C4TimeMilliseconds tNow)
virtual bool DoScheduleProcs(int iTimeout)
static C4TimeMilliseconds Now()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 75 of file StdScheduler.cpp.

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

Referenced by StdSchedulerThread::Set().

76 {
77  // Remove previous data
78  Clear();
79  // Copy new
80  for (int i = 0; i < inProcCnt; i++)
81  Add(ppnProcs[i]);
82 }
void Add(StdSchedulerProc *pProc)

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

783 {
784 #ifndef USE_CONSOLE
785  // safety
786  if (!szFontFace || !*szFontFace || iFontSize<1 || SLen(szFontFace)>=static_cast<int>(sizeof Config.General.RXFontName)) return false;
787  // first, check if the selected font can be created at all
788  // check regular font only - there's no reason why the other fonts couldn't be created
789  CStdFont TestFont;
790  if (!::FontLoader.InitFont(&TestFont, szFontFace, C4FontLoader::C4FT_Main, iFontSize, &::GraphicsResource.Files))
791  return false;
792  // OK; reinit all fonts
793  StdStrBuf sOldFont; sOldFont.Copy(Config.General.RXFontName);
794  int32_t iOldFontSize = Config.General.RXFontSize;
795  SCopy(szFontFace, Config.General.RXFontName);
796  Config.General.RXFontSize = iFontSize;
798  {
799  // failed :o
800  // shouldn't happen. Better restore config.
801  SCopy(sOldFont.getData(), Config.General.RXFontName);
802  Config.General.RXFontSize = iOldFontSize;
803  return false;
804  }
805 #endif
806  // save changes
807  return true;
808 }
const char * getData() const
Definition: StdBuf.h:442
C4Config Config
Definition: C4Config.cpp:833
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
C4ConfigGeneral General
Definition: C4Config.h:251
size_t SLen(const char *sptr)
Definition: Standard.h:74
C4GraphicsResource GraphicsResource
char RXFontName[CFG_MaxString+1]
Definition: C4Config.h:41
C4FontLoader FontLoader
int32_t RXFontSize
Definition: C4Config.h:42
static C4Startup * Get()
Definition: C4Startup.h:133
void Copy()
Definition: StdBuf.h:467
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 747 of file C4Application.cpp.

References pGameTimer, and C4ApplicationGameTimer::SetGameTickDelay().

748 {
749  if (!pGameTimer) return;
750  pGameTimer->SetGameTickDelay(iDelay);
751 }
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 829 of file C4Application.cpp.

References AltDirectorySeparator, and DirectorySeparator.

Referenced by OpenGame().

830 {
831  // set next mission if any is desired
832  if (szMissionFilename)
833  {
834  NextMission = szMissionFilename;
835  // scenarios tend to use the wrong slash
836  std::replace(begin(NextMission), end(NextMission), AltDirectorySeparator, DirectorySeparator);
837  }
838  else
839  NextMission.clear();
840 }
#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 354 of file C4AppSDL.cpp.

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

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

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

Referenced by StdSchedulerThread::Stop().

151 {
152  Unblocker.Notify();
153 }

Here is the caller graph for this function:

Member Data Documentation

enum C4Application::State C4Application::C4AS_None
protected

Referenced by DoInit(), and GameTick().

int C4Application::CheckForUpdates {false}

Definition at line 79 of file C4Application.h.

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

bool C4AbstractApp::fDspModeSet {false}
protectedinherited

Definition at line 157 of file C4App.h.

bool C4AbstractApp::fQuitMsgReceived {false}
inherited
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 {nullptr}

Definition at line 43 of file C4Application.h.

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

C4ApplicationGameTimer* C4Application::pGameTimer {nullptr}
protected

Definition at line 87 of file C4Application.h.

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

int C4Application::QuitAfterGame {false}
protected

Definition at line 96 of file C4Application.h.

Referenced by ParseCommandLine(), and QuitGame().

bool C4Application::restartAtEnd {false}

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: