OpenClonk
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
 
const char * argv0
 
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

◆ State

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

Definition at line 87 of file C4Application.h.

Constructor & Destructor Documentation

◆ C4Application()

C4Application::C4Application ( )

Definition at line 49 of file C4Application.cpp.

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

◆ ~C4Application()

C4Application::~C4Application ( )
override

Definition at line 54 of file C4Application.cpp.

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

References CloseLog(), and pGamePadControl.

Here is the call graph for this function:

Member Function Documentation

◆ Activate()

void C4Application::Activate ( )

Definition at line 846 of file C4Application.cpp.

847 {
848 #ifdef USE_WIN32_WINDOWS
849  BringWindowToTop(FullScreen.hWindow);
850  ShowWindow(FullScreen.hWindow, SW_SHOW);
851 #endif
852 }
C4FullScreen FullScreen
Definition: C4Globals.cpp:46

References FullScreen.

Referenced by C4StartupMainDlg::OnShown().

Here is the caller graph for this function:

◆ Add()

void StdScheduler::Add ( StdSchedulerProc pProc)
inherited

Definition at line 84 of file StdScheduler.cpp.

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)

References StdScheduler::Added().

Referenced by C4GameLobby::ScenDesc::Activate(), C4GameOptionsList::Activate(), C4Network2ResDlg::Activate(), StdSchedulerThread::Add(), C4GameOverDlg::C4GameOverDlg(), C4GameSec1Timer::C4GameSec1Timer(), C4InteractiveThread::C4InteractiveThread(), C4Network2ClientListBox::C4Network2ClientListBox(), C4Network2ClientListDlg::C4Network2ClientListDlg(), C4Network2Stats::C4Network2Stats(), C4StartupModsDlg::C4StartupModsDlg(), C4StartupModsDownloader::C4StartupModsDownloader(), 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().

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

◆ Added()

void StdScheduler::Added ( StdSchedulerProc pProc)
inherited

Definition at line 281 of file StdSchedulerMac.mm.

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

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

Referenced by StdScheduler::Add().

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

◆ ApplyResolutionConstraints()

void C4Application::ApplyResolutionConstraints ( )
protected

Definition at line 495 of file C4Application.cpp.

496 {
497  // Not changing the resolution always works anyway
498  if (Config.Graphics.ResX == -1 && Config.Graphics.ResY == -1)
499  return;
500  // Enumerate display modes
501  int32_t idx = -1, iXRes, iYRes, iBitDepth, iRefreshRate;
502  int32_t best_match = -1;
503  uint32_t best_delta = ~0;
504  while (GetIndexedDisplayMode(++idx, &iXRes, &iYRes, &iBitDepth, &iRefreshRate, Config.Graphics.Monitor))
505  {
506  if (iBitDepth != C4Draw::COLOR_DEPTH) continue;
507  uint32_t delta = std::abs(Config.Graphics.ResX*Config.Graphics.ResY - iXRes*iYRes);
508  if (!delta && iBitDepth == C4Draw::COLOR_DEPTH && iRefreshRate == Config.Graphics.RefreshRate)
509  return; // Exactly the expected mode
510  if (delta < best_delta)
511  {
512  // Better match than before
513  best_match = idx;
514  best_delta = delta;
515  }
516  }
517  if (best_match != -1)
518  {
519  // Apply next-best mode
520  GetIndexedDisplayMode(best_match, &iXRes, &iYRes, &iBitDepth, &iRefreshRate, Config.Graphics.Monitor);
521  if (iXRes != Config.Graphics.ResX || iYRes != Config.Graphics.ResY)
522  // Don't warn if only bit depth changes
523  // Also, lang table not loaded yet
524  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);
525  Config.Graphics.ResX = iXRes; Config.Graphics.ResY = iYRes;
526  Config.Graphics.RefreshRate = iRefreshRate;
527  }
528 }
C4Config Config
Definition: C4Config.cpp:930
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
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 ResX
Definition: C4Config.h:104
int32_t ResY
Definition: C4Config.h:104
int32_t RefreshRate
Definition: C4Config.h:106
int32_t Monitor
Definition: C4Config.h:112
C4ConfigGraphics Graphics
Definition: C4Config.h:257
static constexpr int COLOR_DEPTH
Definition: C4Draw.h:89

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

Referenced by DoInit().

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

◆ AssertMainThread()

bool C4AbstractApp::AssertMainThread ( )
inlineinherited

Definition at line 123 of file C4App.h.

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

References C4AbstractApp::MainThread.

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

Here is the caller graph for this function:

◆ Changed()

void StdScheduler::Changed ( StdSchedulerProc pProc)
inherited

Definition at line 294 of file StdSchedulerMac.mm.

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

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

Here is the call graph for this function:

◆ Clear()

void C4Application::Clear ( )
overridevirtual

Reimplemented from C4AbstractApp.

Definition at line 600 of file C4Application.cpp.

601 {
602  Game.Clear();
603  NextMission.clear();
604  // stop timer
605  if (pGameTimer)
606  {
608  delete pGameTimer; pGameTimer = nullptr;
609  }
610  // quit irc
611  IRCClient.Close();
612  // close system group (System.ocg)
613  SystemGroup.Close();
614  // Log
615  if (::Languages.HasStringTable()) // Avoid (double and undefined) message on (second?) shutdown...
616  Log(LoadResStr("IDS_PRC_DEINIT"));
617  // Clear external language packs and string table
618  Languages.Clear();
620  // gamepad clear
621  if (pGamePadControl) { delete pGamePadControl; pGamePadControl=nullptr; }
622  // music system clear
623  MusicSystem.Clear();
624  SoundSystem.Clear();
626  // clear editcursor holding graphics before clearing draw
628  // Clear direct draw (late, because it's needed for e.g. Log)
629  if (pDraw) { delete pDraw; pDraw=nullptr; }
630  // Close window
631  FullScreen.Clear();
632  Console.Clear();
633  // There might be pending saves - do them after the fullscreen windows got closed
634  // so the app just remains as a lingering process until saving is done
636  // The very final stuff
638 }
C4Draw * pDraw
Definition: C4Draw.cpp:42
C4Game Game
Definition: C4Globals.cpp:52
C4Console Console
Definition: C4Globals.cpp:45
C4Language Languages
Definition: C4Language.cpp:42
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
void RestoreVideoMode()
Definition: C4AppSDL.cpp:443
virtual void Clear()
Definition: C4AppSDL.cpp:105
C4Group SystemGroup
Definition: C4Application.h:40
C4MusicSystem MusicSystem
Definition: C4Application.h:41
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:88
C4SoundSystem SoundSystem
Definition: C4Application.h:42
void Clear() override
Definition: C4Console.cpp:418
C4EditCursor EditCursor
Definition: C4Console.h:90
void Clear() override
void Clear()
Definition: C4Game.cpp:672
bool Close()
Definition: C4Group.cpp:971
void ClearLanguage()
Definition: C4Language.cpp:410
void Clear()
Definition: C4Language.cpp:114
bool HasStringTable() const
Definition: C4Language.h:70
bool Close() override
static void WaitForSaves()
Definition: StdPNG.cpp:362
void Remove(StdSchedulerProc *pProc)

References C4Language::Clear(), C4EditCursor::Clear(), C4Game::Clear(), C4AbstractApp::Clear(), C4MusicSystem::Clear(), C4SoundSystem::Clear(), C4Console::Clear(), C4FullScreen::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(), and main().

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

◆ ClearCommandLine()

void C4Application::ClearCommandLine ( )

Definition at line 189 of file C4Application.cpp.

190 {
191  *Game.PlayerFilenames = 0;
192 }
char PlayerFilenames[20 *_MAX_PATH_LEN]
Definition: C4Game.h:104

References Game, and C4Game::PlayerFilenames.

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

Here is the caller graph for this function:

◆ CloseSystemGroup()

void C4Application::CloseSystemGroup ( )
inline

Definition at line 56 of file C4Application.h.

56 { SystemGroup.Close(); }

References C4Group::Close(), and SystemGroup.

Here is the call graph for this function:

◆ Copy()

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

Definition at line 34 of file C4AppMac.mm.

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 }

References Log(), and C4ScriptGuiWindowPropertyName::text.

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

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

◆ DoInit()

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

Implements C4AbstractApp.

Definition at line 62 of file C4Application.cpp.

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

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, C4Language::Init(), C4Config::Init(), C4Reloc::Init(), C4Console::Init(), C4FullScreen::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.

Here is the call graph for this function:

◆ DoScheduleProcs()

bool C4AbstractApp::DoScheduleProcs ( int  iTimeout)
overridevirtualinherited

Reimplemented from StdScheduler.

Definition at line 59 of file C4App.cpp.

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 fQuitMsgReceived
Definition: C4App.h:81
bool FlushMessages()
Definition: C4AppSDL.cpp:115
virtual bool DoScheduleProcs(int iTimeout)

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

Here is the call graph for this function:

◆ Draw()

void C4Application::Draw ( )

Definition at line 760 of file C4Application.cpp.

761 {
762  // Graphics
763 
764  // Fullscreen mode
765  if (!isEditor)
767  // Console mode
768  else
769  Console.Execute();
770 }
void Execute()
Definition: C4Console.cpp:581

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

Referenced by C4ApplicationGameTimer::Execute().

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

◆ Error()

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

Definition at line 99 of file C4App.h.

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

References C4AbstractApp::sLastError.

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

Here is the caller graph for this function:

◆ FlushMessages()

bool C4AbstractApp::FlushMessages ( )
inherited

Definition at line 115 of file C4AppSDL.cpp.

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 }

References C4AbstractApp::fQuitMsgReceived.

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

Here is the caller graph for this function:

◆ FullScreenMode()

bool C4Application::FullScreenMode ( )

Definition at line 873 of file C4Application.cpp.

874 {
875  if(isEditor)
876  return false;
878  return true;
880  return true;
881  return false;
882 }
bool IsRunning
Definition: C4Game.h:140

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

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

Here is the caller graph for this function:

◆ GameTick()

void C4Application::GameTick ( )

Definition at line 683 of file C4Application.cpp.

684 {
685  // Exec depending on game state
686  switch (AppState)
687  {
688  case C4AS_None:
689  assert(AppState != C4AS_None);
690  break;
691  case C4AS_Quit:
692  // Do nothing, the main loop will exit soon
693  break;
694  case C4AS_PreInit:
695  if (!PreInit()) Quit();
696  break;
697  case C4AS_Startup:
701  // wait for the user to start a game
702  break;
703  case C4AS_StartGame:
704  // immediate progress to next state; OpenGame will enter HandleMessage-loops in startup and lobby!
706  AppState = C4AS_Game;
707 #ifdef WITH_QT_EDITOR
708  // Notify console
710 #endif
711  // first-time game initialization
712  if (!Game.Init())
713  {
714  // set error flag (unless this was a lobby user abort)
716  Game.fQuitWithError = true;
717  // no start: Regular QuitGame; this may reset the engine to startup mode if desired
718  QuitGame();
719  break;
720  }
721  if(Config.Graphics.Windowed == 2 && FullScreenMode())
723  if (!isEditor)
724  pWindow->GrabMouse(true);
725  // Gamepad events have to be polled here so that the controller
726  // connection state is always up-to-date before players are
727  // joining.
729  break;
730  case C4AS_AfterGame:
731  // stop game
732  Game.Clear();
733  if(Config.Graphics.Windowed == 2 && NextMission.empty() && !isEditor)
735  if (!isEditor)
736  pWindow->GrabMouse(false);
737  AppState = C4AS_PreInit;
738  // if a next mission is desired, set to start it
739  if (!NextMission.empty())
740  {
741  Game.SetScenarioFilename(NextMission.c_str());
743  Game.fObserve = false;
744  NextMission.clear();
745  }
746  break;
747  case C4AS_Game:
748  // Game
749  if (Game.IsRunning)
750  Game.Execute();
751  // Sound
754  // Gamepad
756  break;
757  }
758 }
void Quit() override
void OnStartGame()
Definition: C4ConsoleGUI.h:114
void SetScenarioFilename(const char *)
Definition: C4Game.cpp:660
bool Init()
Definition: C4Game.cpp:397
bool NetworkActive
Definition: C4Game.h:123
bool Execute()
Definition: C4Game.cpp:868
bool fQuitWithError
Definition: C4Game.h:143
bool fObserve
Definition: C4Game.h:121
bool fLobby
Definition: C4Game.h:119
void Execute(bool force_buffer_checks=false)
static void CloseStartup()
Definition: C4Startup.cpp:292
void GrabMouse(bool grab)
Definition: C4AppT.cpp:107

References Application, C4AS_AfterGame, C4AS_Game, C4AS_None, C4AS_PreInit, C4AS_Quit, C4AS_StartGame, C4AS_Startup, C4Game::Clear(), C4Startup::CloseStartup(), Config, Console, C4Game::Execute(), C4GamePadControl::Execute(), C4SoundSystem::Execute(), C4MusicSystem::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().

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

◆ GetConfigHeight()

int C4Application::GetConfigHeight ( )
inline

Definition at line 84 of file C4Application.h.

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

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

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

◆ GetConfigWidth()

int C4Application::GetConfigWidth ( )
inline

Definition at line 83 of file C4Application.h.

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

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

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

◆ GetIndexedDisplayMode()

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.

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 }

Referenced by ApplyResolutionConstraints().

Here is the caller graph for this function:

◆ GetLastError()

const char* C4AbstractApp::GetLastError ( )
inlineinherited

Definition at line 98 of file C4App.h.

98 { return sLastError.c_str(); }

References C4AbstractApp::sLastError.

◆ GetNextTick()

C4TimeMilliseconds StdScheduler::GetNextTick ( C4TimeMilliseconds  tNow)
inherited

Definition at line 120 of file StdScheduler.cpp.

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

References C4TimeMilliseconds::PositiveInfinity.

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

Here is the caller graph for this function:

◆ getProcCnt()

int StdScheduler::getProcCnt ( ) const
inlineinherited

Definition at line 245 of file StdScheduler.h.

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

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

Here is the caller graph for this function:

◆ GetRevision()

const char* C4Application::GetRevision ( ) const
inline

Definition at line 72 of file C4Application.h.

72 { return Revision.c_str(); }

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

Here is the caller graph for this function:

◆ hasProc()

bool StdScheduler::hasProc ( StdSchedulerProc pProc)
inlineinherited

Definition at line 246 of file StdScheduler.h.

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

Referenced by C4InteractiveThread::RemoveProc().

Here is the caller graph for this function:

◆ Init()

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

Definition at line 87 of file C4AppSDL.cpp.

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

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

Referenced by main().

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

◆ IsClipboardFull()

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

Definition at line 58 of file C4AppMac.mm.

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

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

Here is the caller graph for this function:

◆ IsInManualLoop()

bool StdScheduler::IsInManualLoop ( )
inlineinherited

Definition at line 247 of file StdScheduler.h.

247 { return isInManualLoop; }

◆ IsQuittingGame()

bool C4Application::IsQuittingGame ( ) const
inline

Definition at line 70 of file C4Application.h.

70 { return AppState >= C4AS_AfterGame; }

References C4AS_AfterGame.

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

Here is the caller graph for this function:

◆ MessageDialog()

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

Definition at line 63 of file C4AppMac.mm.

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 }

Referenced by DoInit().

Here is the caller graph for this function:

◆ NextTick()

void C4Application::NextTick ( )

Definition at line 867 of file C4Application.cpp.

868 {
869  if (!pGameTimer) return;
870  pGameTimer->Set();
871 }

References pGameTimer.

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

Here is the caller graph for this function:

◆ NotifyUserIfInactive()

void C4AbstractApp::NotifyUserIfInactive ( )
inherited

Definition at line 89 of file C4App.cpp.

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

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

Referenced by C4Network2::DoLobby().

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

◆ OnCommand()

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

Implements C4AbstractApp.

Definition at line 835 of file C4Application.cpp.

836 {
837  if (AppState == C4AS_Game)
839  else if (AppState == C4AS_Startup)
840  {
841  AppState = C4AS_PreInit;
842  Game.SetScenarioFilename(szCmd);
843  }
844 }
C4MessageInput MessageInput
bool ProcessInput(const char *szText)

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

Referenced by C4StdInProc::Execute().

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

◆ OnError()

virtual void StdScheduler::OnError ( StdSchedulerProc )
inlineprotectedvirtualinherited

Definition at line 268 of file StdScheduler.h.

268 { }

◆ OnKeyboardLayoutChanged()

void C4Application::OnKeyboardLayoutChanged ( )
overridevirtual

Implements C4AbstractApp.

Definition at line 800 of file C4Application.cpp.

801 {
802  // re-resolve all keys
805 }
void OnKeyboardLayoutChanged()
Definition: C4Game.cpp:4242
static C4Startup * Get()
Definition: C4Startup.h:147
void OnKeyboardLayoutChanged()
Definition: C4Startup.cpp:365

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

Referenced by ConsoleDlgProc().

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

◆ OnResolutionChanged()

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

Implements C4AbstractApp.

Definition at line 778 of file C4Application.cpp.

779 {
780  // notify game
781  if (pDraw)
782  {
783  Game.OnResolutionChanged(iXRes, iYRes);
784  pDraw->OnResolutionChanged(iXRes, iYRes);
785  }
786  if (pWindow)
787  {
788  if (pWindow->pSurface)
789  pWindow->pSurface->UpdateSize(iXRes, iYRes);
790  if (!FullScreenMode())
791  {
792  C4Rect r;
793  pWindow->GetSize(&r);
796  }
797  }
798 }
virtual bool OnResolutionChanged(unsigned int iXRes, unsigned int iYRes)=0
void OnResolutionChanged(unsigned int res_x, unsigned int res_y)
Definition: C4Game.cpp:4228
Definition: C4Rect.h:28
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
bool UpdateSize(int wdt, int hgt)
Definition: C4Surface.cpp:301
bool GetSize(C4Rect *pRect)
Definition: C4AppT.cpp:108
C4Surface * pSurface
Definition: C4Window.h:275

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.

Here is the call graph for this function:

◆ OpenGame()

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

Definition at line 655 of file C4Application.cpp.

656 {
657  if (AppState == C4AS_Startup)
658  {
659  if (scenario) Game.SetScenarioFilename(scenario);
660  AppState = C4AS_StartGame;
661  }
662  else
663  {
664  SetNextMission(scenario);
665  AppState = C4AS_AfterGame;
666  }
667 
668 }
void SetNextMission(const char *szMissionFilename)

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

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

◆ OpenSystemGroup()

bool C4Application::OpenSystemGroup ( )
inline

Definition at line 55 of file C4Application.h.

bool IsOpen() const
Definition: C4Group.cpp:2373
bool Open(const char *group_name, bool do_create=false)
Definition: C4Group.cpp:660

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

Referenced by C4Game::InitScriptEngine().

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

◆ ParseCommandLine()

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

Definition at line 194 of file C4Application.cpp.

195 {
196  argv0 = argv[0];
197  StdStrBuf CmdLine("Command line:");
198  for(int i = 0; i < argc; ++i) {
199  CmdLine.Append(" ");
200  CmdLine.Append(argv[i]);
201  }
202  Log(CmdLine.getData());
203 
205  Game.NetworkActive = false;
206  isEditor = 2;
207  int c;
208  while (true)
209  {
210 
211  static struct option long_options[] =
212  {
213  // option, w/ argument?, set directly, set to...
214  {"editor", no_argument, &isEditor, 1},
215  {"fullscreen", no_argument, &isEditor, 0},
216  {"debugwait", no_argument, &Game.DebugWait, 1},
217  {"update", no_argument, &CheckForUpdates, 1},
218  {"noruntimejoin", no_argument, &Config.Network.NoRuntimeJoin, 1},
219  {"runtimejoin", no_argument, &Config.Network.NoRuntimeJoin, 0},
220  {"noleague", no_argument, &Config.Network.LeagueServerSignUp, 0},
221  {"league", no_argument, &Config.Network.LeagueServerSignUp, 1},
222  {"nosignup", no_argument, &Config.Network.MasterServerSignUp, 0},
223  {"signup", no_argument, &Config.Network.MasterServerSignUp, 1},
224 
225  {"debugrecread", required_argument, nullptr, 'K'},
226  {"debugrecwrite", required_argument, nullptr, 'w'},
227 
228  {"client", required_argument, nullptr, 'c'},
229  {"host", no_argument, nullptr, 'h'},
230  {"debughost", required_argument, nullptr, 'H'},
231  {"debugpass", required_argument, nullptr, 'P'},
232  {"debug", required_argument, nullptr, 'D'},
233  {"data", required_argument, nullptr, 'd'},
234  {"startup", required_argument, nullptr, 's'},
235  {"stream", required_argument, nullptr, 'e'},
236  {"recdump", required_argument, nullptr, 'R'},
237  {"comment", required_argument, nullptr, 'm'},
238  {"pass", required_argument, nullptr, 'p'},
239  {"udpport", required_argument, nullptr, 'u'},
240  {"tcpport", required_argument, nullptr, 't'},
241  {"join", required_argument, nullptr, 'j'},
242  {"language", required_argument, nullptr, 'L'},
243  {"scenpar", required_argument, nullptr, 'S'},
244 
245  {"observe", no_argument, nullptr, 'o'},
246  {"nonetwork", no_argument, nullptr, 'N'},
247  {"network", no_argument, nullptr, 'n'},
248  {"record", no_argument, nullptr, 'r'},
249 
250  {"lobby", optional_argument, nullptr, 'l'},
251 
252  {"debug-opengl", no_argument, &Config.Graphics.DebugOpenGL, 1},
253  {"config", required_argument, nullptr, 0},
254  {"show-licenses", no_argument, nullptr, 0},
255  {nullptr, 0, nullptr, 0}
256  };
257  int option_index = 0;
258  c = getopt_long (argc, argv, "abc:d:f:",
259  long_options, &option_index);
260  // no more options
261  if (c == -1)
262  break;
263  switch (c)
264  {
265  case 0:
266  // Signup
267  if (SEqualNoCase(long_options[option_index].name, "signup"))
268  {
269  Game.NetworkActive = true;
270  }
271  // League
272  if (SEqualNoCase(long_options[option_index].name, "league"))
273  {
274  Game.NetworkActive = true;
276  }
277  // Legal stuff
278  if (SEqualNoCase(long_options[option_index].name, "show-licenses"))
279  {
280  std::string sep{"\n=================================\n"};
281  for (const auto& license : OCLicenses)
282  Log((sep + license.path + ": " + license.name + sep + license.content + "\n").c_str());
283  Quit();
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); break;
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:") || SEqual2NoCase(szParameter, "openclonk:"))
442  {
443  // Store address
444  SCopy(SAdvancePast(szParameter, ':'), 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  // Special case: start the mod dialog and initiate installation of a mod.
454  const char* install_mod_command = "installmod";
455  const auto install_mod_command_length = strlen(install_mod_command);
456  if (SEqualNoCase(Game.DirectJoinAddress, install_mod_command, install_mod_command_length))
457  {
458  // Advance the string to the parameter after the command.
459  const char *id = Game.DirectJoinAddress + install_mod_command_length;
460  if (SLen(id) > 1)
461  {
462  ++id; // Remove slash.
463  C4Startup::SetStartScreen("mods", id);
464  }
465  Game.DirectJoinAddress[0] = 0;
466  continue;
467  }
468  // Self-enable network
469  Game.NetworkActive = true;
470  continue;
471  }
472  }
473 
474 #ifdef _WIN32
475  // Clean up some forward/backward slach confusion since many internal OC file functions cannot handle both
482 #endif
483 
484  // Default to editor if scenario given, player mode otherwise
485  if (isEditor == 2)
487 
488  // record?
490 
491  // startup dialog required?
493 }
@ CFG_MaxString
Definition: C4Config.h:28
C4Network2 Network
Definition: C4Globals.cpp:53
const std::vector< OCLicenseInfo > OCLicenses
#define DirectorySeparator
#define AltDirectorySeparator
#define _MAX_PATH
#define DirSep
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:354
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
int SClearFrontBack(char *szString, char cClear)
Definition: Standard.cpp:461
bool SAddModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:563
const char * SAdvancePast(const char *szSPos, char cPast)
Definition: Standard.cpp:438
size_t SLen(const char *sptr)
Definition: Standard.h:74
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:118
char * GetFilename(char *szPath)
Definition: StdFile.cpp:42
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:224
const char * GetWorkingDirectory()
Definition: StdFile.cpp:627
const char * argv0
Definition: C4Application.h:75
std::string IncomingKeyfile
Definition: C4Application.h:99
void ClearCommandLine()
char DebugRecExternalFile[_MAX_PATH_LEN]
Definition: C4Config.h:65
int32_t DebugRecWrite
Definition: C4Config.h:64
int32_t OpenScenarioInGameMode
Definition: C4Config.h:41
int32_t DebugRec
Definition: C4Config.h:63
int32_t DebugOpenGL
Definition: C4Config.h:117
C4ConfigNetwork Network
Definition: C4Config.h:259
ValidatedStdCopyStrBuf< C4InVal::VAL_Comment > Comment
Definition: C4Config.h:146
int32_t MasterServerSignUp
Definition: C4Config.h:147
int32_t PortUDP
Definition: C4Config.h:153
int32_t LeagueServerSignUp
Definition: C4Config.h:151
int32_t NoRuntimeJoin
Definition: C4Config.h:142
int32_t PortTCP
Definition: C4Config.h:153
StdStrBuf RecordStream
Definition: C4Game.h:126
StdStrBuf DebugPassword
Definition: C4Game.h:149
int DebugWait
Definition: C4Game.h:149
bool Record
Definition: C4Game.h:124
StdStrBuf DebugHost
Definition: C4Game.h:149
char DirectJoinAddress[_MAX_PATH_LEN]
Definition: C4Game.h:106
bool HasScenario()
Definition: C4Game.h:163
char ScenarioFilename[_MAX_PATH_LEN]
Definition: C4Game.h:102
int32_t iLobbyTimeout
Definition: C4Game.h:120
class C4ScenarioParameters & StartupScenarioParameters
Definition: C4Game.h:68
StdStrBuf RecordDumpFile
Definition: C4Game.h:125
char DefinitionFilenames[20 *_MAX_PATH_LEN]
Definition: C4Game.h:105
uint16_t DebugPort
Definition: C4Game.h:149
void SetPassword(const char *szToPassword)
Definition: C4Network2.cpp:772
bool AddPath(const char *path, PathType pathType=PATH_Regular)
Definition: C4Reloc.cpp:62
void SetValue(const char *id, int32_t value, bool only_if_larger)
static bool SetStartScreen(const char *szScreen, const char *szSubDialog=nullptr)
Definition: C4Startup.cpp:332
bool SplitAtChar(char cSplit, StdStrBuf *psSplit)
Definition: StdBuf.h:619
int ReplaceChar(char cOld, char cNew)
Definition: StdBuf.cpp:336
void CopyValidated(const char *szFromVal)

References _MAX_PATH, C4Reloc::AddPath(), AltDirectorySeparator, StdStrBuf::Append(), Application, argv0, 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, OCLicenses, C4ConfigGeneral::OpenScenarioInGameMode, C4Game::PlayerFilenames, C4ConfigNetwork::PortTCP, C4ConfigNetwork::PortUDP, Quit(), QuitAfterGame, C4Game::Record, C4Game::RecordDumpFile, C4Game::RecordStream, Reloc, StdStrBuf::ReplaceChar(), SAddModule(), SAdvancePast(), C4Game::ScenarioFilename, SClearFrontBack(), SCopy(), SEqual2NoCase(), SEqualNoCase(), C4Network2::SetPassword(), C4Game::SetScenarioFilename(), C4Startup::SetStartScreen(), C4ScenarioParameters::SetValue(), SLen(), StdStrBuf::SplitAtChar(), SReplaceChar(), and C4Game::StartupScenarioParameters.

Referenced by DoInit().

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

◆ Paste()

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

Definition at line 47 of file C4AppMac.mm.

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 }

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

Here is the caller graph for this function:

◆ PreInit()

bool C4Application::PreInit ( )
protected

Definition at line 530 of file C4Application.cpp.

531 {
532  // startup dialog: Only use if no next mission has been provided
533  bool fUseStartupDialog = !Game.HasScenario();
534 
535  // Load graphics early, before we draw anything, since we need shaders
536  // loaded to draw.
537  Game.SetInitProgress(0.0f);
538  Log(LoadResStr("IDS_PRC_GFXRES"));
539  if (!GraphicsResource.Init()) return false;
540  Game.SetInitProgress(fUseStartupDialog ? 10.0f : 1.0f);
541 
542  // Startup message board
543  if (!isEditor)
545  {
547  GraphicsSystem.MessageBoard->Init(cgo,true);
548  }
549 
550  // init loader: Black screen for first start if a video is to be shown; otherwise default spec
551  if (fUseStartupDialog && !isEditor)
552  {
554  { LogFatal(LoadResStr("IDS_PRC_ERRLOADER")); return false; }
555  }
556  Game.SetInitProgress(fUseStartupDialog ? 20.0f : 2.0f);
557 
558  if (!Game.PreInit()) return false;
559 
560  // Music
561  if (!MusicSystem.Init("frontend"))
562  Log(LoadResStr("IDS_PRC_NOMUSIC"));
563 
564  Game.SetInitProgress(fUseStartupDialog ? 34.0f : 2.0f);
565 
566  // Sound
567  if (!SoundSystem.Init())
568  Log(LoadResStr("IDS_PRC_NOSND"));
569 
570  // Play some music! - after sound init because sound system might be needed by music system
571  if (fUseStartupDialog && !isEditor && Config.Sound.FEMusic)
572  MusicSystem.Play();
573 
574  Game.SetInitProgress(fUseStartupDialog ? 35.0f : 3.0f);
575 
576  if (fUseStartupDialog)
577  {
578  AppState = C4AS_Startup;
579  // default record?
581  // if no scenario or direct join has been specified, get game startup parameters by startup dialog
582  if (!isEditor)
584  }
585  // directly launch scenario / network game
586  else
587  {
588  AppState = C4AS_StartGame;
589  }
590 
591  return true;
592 }
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
C4GraphicsResource GraphicsResource
#define C4CFN_StartupBackgroundMain
Definition: C4Startup.h:23
int32_t DefRec
Definition: C4Config.h:49
int32_t ShowStartupMessages
Definition: C4Config.h:99
C4ConfigSound Sound
Definition: C4Config.h:258
int32_t FEMusic
Definition: C4Config.h:128
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
void SetInitProgress(float to_progress)
Definition: C4Game.cpp:4207
bool PreInit()
Definition: C4Game.cpp:333
bool InitLoaderScreen(const char *image_name)
std::unique_ptr< C4MessageBoard > MessageBoard
bool Play(const char *szSongname=nullptr, bool fLoop=false, int fadetime_ms=0, double max_resume_time=0.0, bool allow_break=false)
bool Init(const char *PlayList=nullptr)
static void InitStartup()
Definition: C4Startup.cpp:319
int32_t GetScreenHgt()
Definition: C4Gui.h:2825
int32_t GetScreenWdt()
Definition: C4Gui.h:2824

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(), C4GraphicsResource::Init(), C4SoundSystem::Init(), C4MusicSystem::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().

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

◆ ProcessCallback()

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

Definition at line 594 of file C4Application.cpp.

595 {
596  Console.Out(szMessage);
597  return true;
598 }
void Out(const char *message)
Definition: C4Console.cpp:684

References Console, and C4ConsoleGUI::Out().

Referenced by DoInit().

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

◆ Quit()

void C4Application::Quit ( )
overridevirtual

Reimplemented from C4AbstractApp.

Definition at line 640 of file C4Application.cpp.

641 {
642  // Participants should not be cleared for usual startup dialog
643 
644  // Save config if there was no loading error
646  // make sure startup data is unloaded
648  // fonts are loaded at start and never unloaded
650  // quit app
652  AppState = C4AS_Quit;
653 }
virtual void Quit()
Definition: C4AppSDL.cpp:110
bool ConfigLoaded
Definition: C4Config.h:266
static void Unload()
Definition: C4Startup.cpp:313

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

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

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

◆ QuitGame()

void C4Application::QuitGame ( )

Definition at line 670 of file C4Application.cpp.

671 {
672  // reinit desired? Do restart
673  if (!QuitAfterGame || !NextMission.empty())
674  {
675  AppState = C4AS_AfterGame;
676  }
677  else
678  {
679  Quit();
680  }
681 }

References C4AS_AfterGame, Quit(), and QuitAfterGame.

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

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

◆ Remove()

void StdScheduler::Remove ( StdSchedulerProc pProc)
inherited

Definition at line 96 of file StdScheduler.cpp.

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)

References StdScheduler::Removing().

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

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

◆ Removing()

void StdScheduler::Removing ( StdSchedulerProc pProc)
inherited

Definition at line 286 of file StdSchedulerMac.mm.

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

References SCHAdditions::requestAdditionsForScheduler:.

Referenced by StdScheduler::Remove().

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

◆ RestoreVideoMode()

void C4AbstractApp::RestoreVideoMode ( )
inherited

Definition at line 443 of file C4AppSDL.cpp.

444 {
445  if (pWindow && pWindow->window)
446  SDL_SetWindowFullscreen(pWindow->window, 0);
447 }

References C4AbstractApp::pWindow.

Referenced by Clear().

Here is the caller graph for this function:

◆ Run()

void C4AbstractApp::Run ( )
inherited

Definition at line 26 of file C4App.cpp.

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 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
static C4TimeMilliseconds Now()
bool ScheduleProcs(int iTimeout=1000/36)
C4TimeMilliseconds GetNextTick(C4TimeMilliseconds tNow)

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

Referenced by main().

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

◆ ScheduleProcs()

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

Definition at line 130 of file StdScheduler.cpp.

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 }

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(), and C4AbstractApp::Run().

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

◆ Set()

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

Definition at line 75 of file StdScheduler.cpp.

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

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

Referenced by StdSchedulerThread::Set().

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

◆ SetGameFont()

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

Definition at line 807 of file C4Application.cpp.

808 {
809 #ifndef USE_CONSOLE
810  // safety
811  if (!szFontFace || !*szFontFace || iFontSize<1 || SLen(szFontFace)>=static_cast<int>(sizeof Config.General.RXFontName)) return false;
812  // first, check if the selected font can be created at all
813  // check regular font only - there's no reason why the other fonts couldn't be created
814  CStdFont TestFont;
815  if (!::FontLoader.InitFont(&TestFont, szFontFace, C4FontLoader::C4FT_Main, iFontSize, &::GraphicsResource.Files))
816  return false;
817  // OK; reinit all fonts
818  StdStrBuf sOldFont; sOldFont.Copy(Config.General.RXFontName);
819  int32_t iOldFontSize = Config.General.RXFontSize;
820  SCopy(szFontFace, Config.General.RXFontName);
821  Config.General.RXFontSize = iFontSize;
823  {
824  // failed :o
825  // shouldn't happen. Better restore config.
826  SCopy(sOldFont.getData(), Config.General.RXFontName);
827  Config.General.RXFontSize = iOldFontSize;
828  return false;
829  }
830 #endif
831  // save changes
832  return true;
833 }
C4FontLoader FontLoader
char RXFontName[CFG_MaxString+1]
Definition: C4Config.h:42
int32_t RXFontSize
Definition: C4Config.h:43
bool InitFont(CStdFont *Font, const char *szFontName, FontType eType, int32_t iSize, C4GroupSet *pGfxGroups, bool fDoShadow=true)
C4StartupGraphics Graphics
Definition: C4Startup.h:112

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

Here is the call graph for this function:

◆ SetGameTickDelay()

void C4Application::SetGameTickDelay ( int  iDelay)

Definition at line 772 of file C4Application.cpp.

773 {
774  if (!pGameTimer) return;
775  pGameTimer->SetGameTickDelay(iDelay);
776 }
void SetGameTickDelay(uint32_t iDelay)

References pGameTimer, and C4ApplicationGameTimer::SetGameTickDelay().

Here is the call graph for this function:

◆ SetNextMission()

void C4Application::SetNextMission ( const char *  szMissionFilename)

Definition at line 854 of file C4Application.cpp.

855 {
856  // set next mission if any is desired
857  if (szMissionFilename)
858  {
859  NextMission = szMissionFilename;
860  // scenarios tend to use the wrong slash
861  std::replace(begin(NextMission), end(NextMission), AltDirectorySeparator, DirectorySeparator);
862  }
863  else
864  NextMission.clear();
865 }

References AltDirectorySeparator, and DirectorySeparator.

Referenced by OpenGame().

Here is the caller graph for this function:

◆ SetVideoMode()

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

Definition at line 354 of file C4AppSDL.cpp.

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
void Error(const char *m)
Definition: C4App.h:99

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

Referenced by DoInit(), and GameTick().

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

◆ StartOnCurrentThread()

void StdScheduler::StartOnCurrentThread ( )
inherited

Definition at line 276 of file StdSchedulerMac.mm.

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

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

Here is the call graph for this function:

◆ UnBlock()

void StdScheduler::UnBlock ( )
inherited

Definition at line 150 of file StdScheduler.cpp.

151 {
152  Unblocker.Notify();
153 }

Referenced by StdSchedulerThread::Stop().

Here is the caller graph for this function:

Member Data Documentation

◆ Active

◆ argv0

const char* C4Application::argv0

Definition at line 75 of file C4Application.h.

Referenced by ParseCommandLine(), and RestartApplication().

◆ C4AS_None

enum C4Application::State C4Application::C4AS_None
protected

Referenced by DoInit(), and GameTick().

◆ CheckForUpdates

int C4Application::CheckForUpdates {false}

Definition at line 80 of file C4Application.h.

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

◆ fDspModeSet

bool C4AbstractApp::fDspModeSet {false}
protectedinherited

Definition at line 157 of file C4App.h.

◆ fQuitMsgReceived

bool C4AbstractApp::fQuitMsgReceived {false}
inherited

◆ IncomingKeyfile

std::string C4Application::IncomingKeyfile
protected

Definition at line 99 of file C4Application.h.

Referenced by ParseCommandLine().

◆ IncomingUpdate

std::string C4Application::IncomingUpdate

Definition at line 78 of file C4Application.h.

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

◆ InteractiveThread

◆ IRCClient

◆ isEditor

◆ MainThread

pthread_t C4AbstractApp::MainThread
inherited

Definition at line 128 of file C4App.h.

Referenced by C4AbstractApp::AssertMainThread().

◆ MusicSystem

◆ pGamePadControl

C4GamePadControl* C4Application::pGamePadControl {nullptr}

Definition at line 43 of file C4Application.h.

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

◆ pGameTimer

C4ApplicationGameTimer* C4Application::pGameTimer {nullptr}
protected

Definition at line 88 of file C4Application.h.

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

◆ pWindow

◆ QuitAfterGame

int C4Application::QuitAfterGame {false}
protected

Definition at line 97 of file C4Application.h.

Referenced by ParseCommandLine(), and QuitGame().

◆ restartAtEnd

bool C4Application::restartAtEnd {false}

Definition at line 38 of file C4Application.h.

Referenced by main().

◆ sLastError

std::string C4AbstractApp::sLastError
protectedinherited

Definition at line 156 of file C4App.h.

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

◆ SoundSystem

◆ SystemGroup


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