2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 1998-2000, Matthes Bender
|
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2009-05-08 13:28:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INC_C4Application
|
|
|
|
#define INC_C4Application
|
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "c4group/C4Components.h"
|
2017-04-30 08:49:09 +00:00
|
|
|
#include "c4group/C4Group.h"
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "network/C4InteractiveThread.h"
|
|
|
|
#include "platform/C4App.h"
|
2017-04-30 08:49:09 +00:00
|
|
|
#include "platform/C4MusicSystem.h"
|
|
|
|
#include "platform/C4SoundSystem.h"
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
class C4ApplicationGameTimer;
|
|
|
|
|
|
|
|
/* Main class to initialize configuration and execute the game */
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
class C4Application: public C4AbstractApp
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
C4Application();
|
2017-05-07 11:50:00 +00:00
|
|
|
~C4Application() override;
|
2010-03-28 17:58:21 +00:00
|
|
|
// Flag for restarting the engine at the end
|
2017-05-07 11:50:00 +00:00
|
|
|
bool restartAtEnd{false};
|
2011-03-13 15:16:45 +00:00
|
|
|
// main System.ocg in working folder
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Group SystemGroup;
|
|
|
|
C4MusicSystem MusicSystem;
|
|
|
|
C4SoundSystem SoundSystem;
|
2017-05-07 11:50:00 +00:00
|
|
|
C4GamePadControl * pGamePadControl{nullptr};
|
2010-03-28 17:58:21 +00:00
|
|
|
// Thread for interactive processes (automatically starts as needed)
|
|
|
|
C4InteractiveThread InteractiveThread;
|
|
|
|
// IRC client for global chat
|
2011-03-11 02:41:05 +00:00
|
|
|
C4Network2IRCClient &IRCClient;
|
2012-10-13 15:17:06 +00:00
|
|
|
// clear app
|
2017-05-07 11:50:00 +00:00
|
|
|
void Clear() override;
|
2010-10-04 19:39:19 +00:00
|
|
|
void ClearCommandLine();
|
|
|
|
// Tick timing
|
2010-03-28 17:58:21 +00:00
|
|
|
void GameTick();
|
|
|
|
void Draw();
|
2011-03-13 15:16:45 +00:00
|
|
|
// System.ocg helper funcs
|
2010-03-28 17:58:21 +00:00
|
|
|
bool OpenSystemGroup() { return SystemGroup.IsOpen() || SystemGroup.Open(C4CFN_System); }
|
|
|
|
void CloseSystemGroup() { SystemGroup.Close(); }
|
|
|
|
void SetGameTickDelay(int iDelay);
|
2017-05-07 11:50:00 +00:00
|
|
|
void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes) override;
|
|
|
|
void OnKeyboardLayoutChanged() override;
|
2010-03-28 17:58:21 +00:00
|
|
|
bool SetGameFont(const char *szFontFace, int32_t iFontSize);
|
|
|
|
void NextTick();
|
2010-10-04 19:39:19 +00:00
|
|
|
|
2017-05-07 11:50:00 +00:00
|
|
|
void Quit() override;
|
|
|
|
void OpenGame(const char * scenario = nullptr); // start game in the next main loop round
|
2011-01-06 23:51:35 +00:00
|
|
|
void QuitGame(); // quit game, and application if in fullscreen without startup
|
2010-10-04 19:39:19 +00:00
|
|
|
void Activate(); // activate app to gain full focus in OS
|
|
|
|
void SetNextMission(const char *szMissionFilename);
|
2017-05-07 11:50:00 +00:00
|
|
|
void OnCommand(const char *szCmd) override;
|
2010-10-04 19:39:19 +00:00
|
|
|
|
2014-10-03 22:16:03 +00:00
|
|
|
bool IsQuittingGame() const { return AppState >= C4AS_AfterGame; }
|
|
|
|
|
2017-03-13 16:42:14 +00:00
|
|
|
const char *GetRevision() const { return Revision.c_str(); }
|
2010-10-04 19:39:19 +00:00
|
|
|
|
|
|
|
// set by ParseCommandLine
|
2018-02-17 11:57:43 +00:00
|
|
|
const char *argv0;
|
2017-05-07 11:50:00 +00:00
|
|
|
int isEditor{false};
|
2010-10-04 19:39:19 +00:00
|
|
|
// set by ParseCommandLine, for manually applying downloaded update packs
|
2017-03-13 16:42:14 +00:00
|
|
|
std::string IncomingUpdate;
|
2010-10-04 19:39:19 +00:00
|
|
|
// set by ParseCommandLine, for manually invoking an update check by command line or url
|
2017-05-07 11:50:00 +00:00
|
|
|
int CheckForUpdates{false};
|
2012-09-29 21:49:30 +00:00
|
|
|
|
2012-10-14 11:28:38 +00:00
|
|
|
bool FullScreenMode();
|
2012-10-22 21:15:48 +00:00
|
|
|
int GetConfigWidth() { return (!FullScreenMode()) ? Config.Graphics.WindowX : Config.Graphics.ResX; }
|
|
|
|
int GetConfigHeight() { return (!FullScreenMode()) ? Config.Graphics.WindowY : Config.Graphics.ResY; }
|
2012-10-14 11:28:38 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
protected:
|
2017-05-07 11:50:00 +00:00
|
|
|
enum State { C4AS_None, C4AS_PreInit, C4AS_Startup, C4AS_StartGame, C4AS_Game, C4AS_AfterGame, C4AS_Quit } AppState{C4AS_None};
|
|
|
|
C4ApplicationGameTimer *pGameTimer{nullptr};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2017-05-07 11:50:00 +00:00
|
|
|
bool DoInit(int argc, char * argv[]) override;
|
2010-10-04 19:39:19 +00:00
|
|
|
void ParseCommandLine(int argc, char * argv[]);
|
2010-03-28 17:58:21 +00:00
|
|
|
bool PreInit();
|
|
|
|
static bool ProcessCallback(const char *szMessage, int iProcess);
|
|
|
|
void ApplyResolutionConstraints();
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-09-12 21:25:16 +00:00
|
|
|
// set by ParseCommandLine, if neither editor, scenario nor direct join adress has been specified
|
2017-05-07 11:50:00 +00:00
|
|
|
int QuitAfterGame{false};
|
2010-10-04 19:39:19 +00:00
|
|
|
// set by ParseCommandLine, for installing registration keys
|
2017-03-13 16:42:14 +00:00
|
|
|
std::string IncomingKeyfile;
|
2010-10-04 19:39:19 +00:00
|
|
|
private:
|
|
|
|
// if set, this mission will be launched next
|
2017-03-13 16:42:14 +00:00
|
|
|
std::string NextMission;
|
2010-10-04 19:39:19 +00:00
|
|
|
// version information strings
|
2017-03-13 16:42:14 +00:00
|
|
|
static const std::string Revision;
|
2010-03-28 17:58:21 +00:00
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
extern C4Application Application;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
class C4ApplicationGameTimer : public CStdMultimediaTimerProc
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
C4ApplicationGameTimer();
|
|
|
|
private:
|
2013-12-04 12:35:07 +00:00
|
|
|
C4TimeMilliseconds tLastGameTick;
|
2017-05-07 11:50:00 +00:00
|
|
|
unsigned int iGameTickDelay{28};
|
|
|
|
unsigned int iExtraGameTickDelay{0};
|
2010-03-28 17:58:21 +00:00
|
|
|
public:
|
|
|
|
void SetGameTickDelay(uint32_t iDelay);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2017-05-07 11:50:00 +00:00
|
|
|
bool Execute(int iTimeout, pollfd *) override;
|
|
|
|
bool IsLowPriority() override;
|
2010-03-28 17:58:21 +00:00
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#endif
|