OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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  int isEditor{false};
76  // set by ParseCommandLine, for manually applying downloaded update packs
77  std::string IncomingUpdate;
78  // set by ParseCommandLine, for manually invoking an update check by command line or url
79  int CheckForUpdates{false};
80 
81  bool FullScreenMode();
84 
85 protected:
88 
89  bool DoInit(int argc, char * argv[]) override;
90  void ParseCommandLine(int argc, char * argv[]);
91  bool PreInit();
92  static bool ProcessCallback(const char *szMessage, int iProcess);
94 
95  // set by ParseCommandLine, if neither editor, scenario nor direct join adress has been specified
96  int QuitAfterGame{false};
97  // set by ParseCommandLine, for installing registration keys
98  std::string IncomingKeyfile;
99 private:
100  // if set, this mission will be launched next
101  std::string NextMission;
102  // version information strings
103  static const std::string Revision;
104 };
105 
107 
109 {
110 public:
112 private:
113  C4TimeMilliseconds tLastGameTick;
114  unsigned int iGameTickDelay{28};
115  unsigned int iExtraGameTickDelay{0};
116 public:
117  void SetGameTickDelay(uint32_t iDelay);
118 
119  bool Execute(int iTimeout, pollfd *) override;
120  bool IsLowPriority() override;
121 };
122 
123 #endif
C4SoundSystem SoundSystem
Definition: C4Application.h:42
void OpenGame(const char *scenario=nullptr)
C4Config Config
Definition: C4Config.cpp:833
bool IsLowPriority() override
void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes) override
bool Execute(int iTimeout, pollfd *) override
void SetGameTickDelay(uint32_t iDelay)
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 IsOpen() const
Definition: C4Group.cpp:1891
void OnCommand(const char *szCmd) override
C4ApplicationGameTimer * pGameTimer
Definition: C4Application.h:87
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
std::string IncomingUpdate
Definition: C4Application.h:77
bool SetGameFont(const char *szFontFace, int32_t iFontSize)
int32_t WindowX
Definition: C4Config.h:104
#define CStdMultimediaTimerProc
Definition: StdScheduler.h:216
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:82
void Quit() override
void CloseSystemGroup()
Definition: C4Application.h:56
bool IsQuittingGame() const
Definition: C4Application.h:70
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:98
bool DoInit(int argc, char *argv[]) override
void ClearCommandLine()
int GetConfigHeight()
Definition: C4Application.h:83
#define C4CFN_System
Definition: C4Components.h:29
void ApplyResolutionConstraints()
C4GamePadControl * pGamePadControl
Definition: C4Application.h:43
void SetNextMission(const char *szMissionFilename)
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