Leviathan  0.8.0.0
Leviathan game engine
AppDefine.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2018 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
7 
8 #include "Common/ThreadSafe.h"
9 
10 #include <functional>
11 
12 #ifdef _WIN32
13 #include "WindowsInclude.h"
14 #endif // _WIN32
15 
16 namespace Leviathan {
17 
18 class NamedVars;
19 
22 #ifdef _WIN32
23  WindowDataDetails(const std::string& title, const int& width, const int& height,
24  const std::string& fullscreen, bool vsync, int displaynumber, int FSAA,
25  const bool& windowborder, HICON icon, LeviathanApplication* appvirtualptr);
26 
27  void ApplyIconToHandle(HWND hwnd) const;
28 
29 
30  HICON Icon;
31 #else
32  WindowDataDetails(const std::string& title, const int& width, const int& height,
33  const std::string& fullscreen, bool vsync, int displaynumber, int fsaa,
34  const bool& windowborder, LeviathanApplication* appvirtualptr);
35 
36 #endif
37  std::string Title;
38  int Height;
39  int Width;
40  std::string FullScreen;
41  bool VSync;
43  // TODO: move the WindowMultiSampleCount here
44  int FSAA;
45 };
46 
47 
48 class AppDef {
49  friend Engine;
50 
51 public:
52  DLLEXPORT AppDef(const bool& isdef = false);
53  DLLEXPORT virtual ~AppDef();
54 
55 
57 
58  // named constructor functions //
59 #ifdef _WIN32
60  DLLEXPORT AppDef& SetHInstance(HINSTANCE instance)
61  {
62 
63  HInstance = instance;
64  return *this;
65  }
66 
67  DLLEXPORT HINSTANCE GetHInstance()
68  {
69 
70  return HInstance;
71  }
72 #else
73  // \todo linux equivalent
74 #endif
76  {
77 
78  WDetails = det;
79  return *this;
80  }
81 
83  {
84 
85  MasterServerInfo = info;
86  return *this;
87  }
88  // Sets the version information of the application, leviathan version is set automatically
89  // //
90  DLLEXPORT AppDef& SetApplicationIdentification(const std::string& userreadable,
91  const std::string& gamename, const std::string& gameversion);
92 
94  {
95  return WDetails;
96  }
98  {
99  return MasterServerInfo;
100  }
101 
103  {
104  return _GameConfiguration;
105  }
106 
108  {
109  return _KeyConfiguration;
110  }
111 
112  DLLEXPORT inline static AppDef* GetDefault()
113  {
114  return Defaultconf;
115  }
116 
117  DLLEXPORT static AppDef* GenerateAppdefine(const std::string& engineconfigfile,
118  const std::string& gameconfig, const std::string& keyconfig,
119  std::function<void(Lock& guard, GameConfiguration* configobj)> configchecker,
120  std::function<void(Lock& guard, KeyConfiguration* keysobject)> keychecker);
121 
122 #ifdef _WIN32
123  DLLEXPORT void StoreWindowDetails(const std::string& title, const bool& windowborder,
124  HICON icon, LeviathanApplication* appvirtualptr);
125 #else
126  DLLEXPORT void StoreWindowDetails(const std::string& title, const bool& windowborder,
127  LeviathanApplication* appvirtualptr);
128 #endif
129 
130 
132  std::string& userreadable, std::string& gamename, std::string& gameversion);
133 
139  DLLEXPORT virtual bool FillDefaultEngineConf(NamedVars& variables);
140 
143  std::function<void(Lock& guard, GameConfiguration* configobj)> configchecker = nullptr,
144  std::function<void(Lock& guard, KeyConfiguration* keysobject)> keychecker = nullptr);
145 
146 protected:
147  std::unique_ptr<NamedVars> ConfigurationValues;
148 #ifdef _WIN32
149  HINSTANCE HInstance;
150 #else
152 #endif
154 
155  std::shared_ptr<NetworkInterface> _NetworkInterface;
156 
157  // details used to create a window //
159 
160  // Game variables //
163 
164  Logger* Mainlog = nullptr;
165 
166 
169  bool DeleteLog = false;
170 
171  std::string LeviathanVersion;
172  std::string GameVersion;
173  std::string Game;
174  std::string UserReadableGame;
175 
176  // ------------------------------------ //
178 };
179 } // namespace Leviathan
180 
181 #ifdef LEAK_INTO_GLOBAL
182 using Leviathan::AppDef;
184 #endif
std::unique_ptr< NamedVars > ConfigurationValues
Definition: AppDefine.h:147
KeyConfiguration * _KeyConfiguration
Definition: AppDefine.h:162
Holds key configuration for an application.
static DLLEXPORT AppDef * GenerateAppdefine(const std::string &engineconfigfile, const std::string &gameconfig, const std::string &keyconfig, std::function< void(Lock &guard, GameConfiguration *configobj)> configchecker, std::function< void(Lock &guard, KeyConfiguration *keysobject)> keychecker)
Definition: AppDefine.cpp:45
DLLEXPORT MasterServerInformation & GetMasterServerInfo()
Definition: AppDefine.h:97
DLLEXPORT AppDef & SetMasterServerParameters(const MasterServerInformation &info)
Definition: AppDefine.h:82
DLLEXPORT void StoreWindowDetails(const std::string &title, const bool &windowborder, LeviathanApplication *appvirtualptr)
Definition: AppDefine.cpp:139
virtual DLLEXPORT bool FillDefaultEngineConf(NamedVars &variables)
This is called then the engine config file isn't found to fill the options with default values.
Definition: AppDefine.cpp:193
DLLEXPORT WindowDataDetails & GetWindowDetails()
Definition: AppDefine.h:93
The main class of the Leviathan Game Engine.
Definition: Engine.h:37
Logger class for all text output.
Definition: Logger.h:10
DLLEXPORT AppDef & SetApplicationIdentification(const std::string &userreadable, const std::string &gamename, const std::string &gameversion)
Definition: AppDefine.cpp:173
std::string Game
Definition: AppDefine.h:173
DLLEXPORT void GetGameIdentificationData(std::string &userreadable, std::string &gamename, std::string &gameversion)
Definition: AppDefine.cpp:185
DLLEXPORT void ReplaceGameAndKeyConfigInMemory(std::function< void(Lock &guard, GameConfiguration *configobj)> configchecker=nullptr, std::function< void(Lock &guard, KeyConfiguration *keysobject)> keychecker=nullptr)
Creates game and key configurations without file backing that are empty.
Definition: AppDefine.cpp:109
DLLEXPORT NamedVars * GetValues()
Definition: AppDefine.cpp:40
DLLEXPORT auto * GetKeyConfiguration()
Definition: AppDefine.h:107
GameConfiguration * _GameConfiguration
Definition: AppDefine.h:161
MasterServerInformation MasterServerInfo
Definition: AppDefine.h:153
std::string LeviathanVersion
Definition: AppDefine.h:171
DLLEXPORT AppDef & SetWindowDetails(const WindowDataDetails &det)
Definition: AppDefine.h:75
WindowDataDetails WDetails
Definition: AppDefine.h:158
std::shared_ptr< NetworkInterface > _NetworkInterface
Definition: AppDefine.h:155
#define DLLEXPORT
Definition: Include.h:84
std::string UserReadableGame
Definition: AppDefine.h:174
static AppDef * Defaultconf
Definition: AppDefine.h:177
DLLEXPORT auto * GetGameConfiguration()
Definition: AppDefine.h:102
Base class for all leviathan programs.
Definition: Application.h:16
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
virtual DLLEXPORT ~AppDef()
Definition: AppDefine.cpp:28
static DLLEXPORT AppDef * GetDefault()
Definition: AppDefine.h:112
std::string GameVersion
Definition: AppDefine.h:172
DLLEXPORT AppDef(const bool &isdef=false)
Definition: AppDefine.cpp:15
std::unique_lock< std::mutex > Lock
Definition: ThreadSafe.h:18
Logger * Mainlog
Definition: AppDefine.h:164