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" 23 #include "network/C4InteractiveThread.h" 24 #include "platform/C4App.h" 25 #include "platform/C4MusicSystem.h" 26 #include "platform/C4SoundSystem.h" 27 28 class C4ApplicationGameTimer; 29 30 /* Main class to initialize configuration and execute the game */ 31 32 class C4Application: public C4AbstractApp 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 40 C4Group SystemGroup; 41 C4MusicSystem MusicSystem; 42 C4SoundSystem SoundSystem; 43 C4GamePadControl * pGamePadControl{nullptr}; 44 // Thread for interactive processes (automatically starts as needed) 45 C4InteractiveThread InteractiveThread; 46 // IRC client for global chat 47 C4Network2IRCClient &IRCClient; 48 // clear app 49 void Clear() override; 50 void ClearCommandLine(); 51 // Tick timing 52 void GameTick(); 53 void Draw(); 54 // System.ocg helper funcs OpenSystemGroup()55 bool OpenSystemGroup() { return SystemGroup.IsOpen() || SystemGroup.Open(C4CFN_System); } CloseSystemGroup()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 IsQuittingGame()70 bool IsQuittingGame() const { return AppState >= C4AS_AfterGame; } 71 GetRevision()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(); GetConfigWidth()83 int GetConfigWidth() { return (!FullScreenMode()) ? Config.Graphics.WindowX : Config.Graphics.ResX; } GetConfigHeight()84 int GetConfigHeight() { return (!FullScreenMode()) ? Config.Graphics.WindowY : Config.Graphics.ResY; } 85 86 protected: 87 enum State { C4AS_None, C4AS_PreInit, C4AS_Startup, C4AS_StartGame, C4AS_Game, C4AS_AfterGame, C4AS_Quit } AppState{C4AS_None}; 88 C4ApplicationGameTimer *pGameTimer{nullptr}; 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); 94 void ApplyResolutionConstraints(); 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 107 extern C4Application Application; 108 109 class C4ApplicationGameTimer : public CStdMultimediaTimerProc 110 { 111 public: 112 C4ApplicationGameTimer(); 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 125