OpenClonk
C4Application.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 #ifndef INC_C4Application
19 #define INC_C4Application
20 
21 #include "c4group/C4Components.h"
22 #include "c4group/C4Group.h"
24 #include "platform/C4App.h"
25 #include "platform/C4MusicSystem.h"
26 #include "platform/C4SoundSystem.h"
27 
29 
30 /* Main class to initialize configuration and execute the game */
31 
33 {
34 public:
35  C4Application();
36  ~C4Application() override;
37  // Flag for restarting the engine at the end
38  bool restartAtEnd{false};
39  // main System.ocg in working folder
44  // Thread for interactive processes (automatically starts as needed)
46  // IRC client for global chat
48  // clear app
49  void Clear() override;
50  void ClearCommandLine();
51  // Tick timing
52  void GameTick();
53  void Draw();
54  // System.ocg helper funcs
55  bool OpenSystemGroup() { return SystemGroup.IsOpen() || SystemGroup.Open(C4CFN_System); }
56  void CloseSystemGroup() { SystemGroup.Close(); }
57  void SetGameTickDelay(int iDelay);
58  void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes) override;
59  void OnKeyboardLayoutChanged() override;
60  bool SetGameFont(const char *szFontFace, int32_t iFontSize);
61  void NextTick();
62 
63  void Quit() override;
64  void OpenGame(const char * scenario = nullptr); // start game in the next main loop round
65  void QuitGame(); // quit game, and application if in fullscreen without startup
66  void Activate(); // activate app to gain full focus in OS
67  void SetNextMission(const char *szMissionFilename);
68  void OnCommand(const char *szCmd) override;
69 
70  bool IsQuittingGame() const { return AppState >= C4AS_AfterGame; }
71 
72  const char *GetRevision() const { return Revision.c_str(); }
73 
74  // set by ParseCommandLine
75  const char *argv0;
76  int isEditor{false};
77  // set by ParseCommandLine, for manually applying downloaded update packs
78  std::string IncomingUpdate;
79  // set by ParseCommandLine, for manually invoking an update check by command line or url
80  int CheckForUpdates{false};
81 
82  bool FullScreenMode();
85 
86 protected:
89 
90  bool DoInit(int argc, char * argv[]) override;
91  void ParseCommandLine(int argc, char * argv[]);
92  bool PreInit();
93  static bool ProcessCallback(const char *szMessage, int iProcess);
95 
96  // set by ParseCommandLine, if neither editor, scenario nor direct join adress has been specified
97  int QuitAfterGame{false};
98  // set by ParseCommandLine, for installing registration keys
99  std::string IncomingKeyfile;
100 private:
101  // if set, this mission will be launched next
102  std::string NextMission;
103  // version information strings
104  static const std::string Revision;
105 };
106 
108 
110 {
111 public:
113 private:
114  C4TimeMilliseconds tLastGameTick;
115  unsigned int iGameTickDelay{28};
116  unsigned int iExtraGameTickDelay{0};
117 public:
118  void SetGameTickDelay(uint32_t iDelay);
119 
120  bool Execute(int iTimeout, pollfd *) override;
121  bool IsLowPriority() override;
122 };
123 
124 #endif
C4SoundSystem SoundSystem
Definition: C4Application.h:42
void OpenGame(const char *scenario=nullptr)
C4Config Config
Definition: C4Config.cpp:833
void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes) override
enum C4Application::State C4AS_None
const char * GetRevision() const
Definition: C4Application.h:72
bool OpenSystemGroup()
Definition: C4Application.h:55
C4ConfigGraphics Graphics
Definition: C4Config.h:253
void Clear() override
bool IsQuittingGame() const
Definition: C4Application.h:70
void OnCommand(const char *szCmd) override
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:88
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
std::string IncomingUpdate
Definition: C4Application.h:78
bool SetGameFont(const char *szFontFace, int32_t iFontSize)
int32_t WindowX
Definition: C4Config.h:104
#define CStdMultimediaTimerProc
Definition: StdScheduler.h:216
const char * argv0
Definition: C4Application.h:75
bool Close()
Definition: C4Group.cpp:755
static bool ProcessCallback(const char *szMessage, int iProcess)
C4Application Application
Definition: C4Globals.cpp:44
void ParseCommandLine(int argc, char *argv[])
int GetConfigWidth()
Definition: C4Application.h:83
void Quit() override
void CloseSystemGroup()
Definition: C4Application.h:56
int32_t WindowY
Definition: C4Config.h:104
void SetGameTickDelay(int iDelay)
int32_t ResX
Definition: C4Config.h:103
int32_t ResY
Definition: C4Config.h:103
std::string IncomingKeyfile
Definition: C4Application.h:99
bool DoInit(int argc, char *argv[]) override
void ClearCommandLine()
int GetConfigHeight()
Definition: C4Application.h:84
#define C4CFN_System
Definition: C4Components.h:29
void ApplyResolutionConstraints()
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
void SetNextMission(const char *szMissionFilename)
bool IsOpen() const
Definition: C4Group.cpp:1891
void OnKeyboardLayoutChanged() override
C4Group SystemGroup
Definition: C4Application.h:40
C4InteractiveThread InteractiveThread
Definition: C4Application.h:45
~C4Application() override
C4Network2IRCClient & IRCClient
Definition: C4Application.h:47
C4MusicSystem MusicSystem
Definition: C4Application.h:41