Leviathan  0.8.0.0
Leviathan game engine
Leviathan::AppDef Class Reference

#include <AppDefine.h>

Public Member Functions

DLLEXPORT AppDef (const bool &isdef=false)
 
DLLEXPORT ~AppDef ()
 
DLLEXPORT NamedVarsGetValues ()
 
DLLEXPORT AppDefSetWindowDetails (const WindowDataDetails &det)
 
DLLEXPORT AppDefSetMasterServerParameters (const MasterServerInformation &info)
 
DLLEXPORT AppDefSetApplicationIdentification (const std::string &userreadable, const std::string &gamename, const std::string &gameversion)
 
DLLEXPORT WindowDataDetailsGetWindowDetails ()
 
DLLEXPORT MasterServerInformationGetMasterServerInfo ()
 
DLLEXPORT auto * GetGameConfiguration ()
 
DLLEXPORT auto * GetKeyConfiguration ()
 
DLLEXPORT void StoreWindowDetails (const std::string &title, const bool &windowborder, LeviathanApplication *appvirtualptr)
 
DLLEXPORT void GetGameIdentificationData (std::string &userreadable, std::string &gamename, std::string &gameversion)
 
virtual DLLEXPORT bool FillDefaultEngineConf (NamedVars &variables)
 This is called then the engine config file isn't found to fill the options with default values. More...
 

Static Public Member Functions

static DLLEXPORT AppDefGetDefault ()
 
static DLLEXPORT AppDefGenerateAppdefine (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)
 

Protected Attributes

std::unique_ptr< NamedVarsConfigurationValues
 
int HInstance
 
MasterServerInformation MasterServerInfo
 
std::shared_ptr< NetworkInterface_NetworkInterface
 
WindowDataDetails WDetails
 
GameConfiguration_GameConfiguration = nullptr
 
KeyConfiguration_KeyConfiguration = nullptr
 
LoggerMainlog = nullptr
 
bool DeleteLog = false
 
std::string LeviathanVersion
 
std::string GameVersion
 
std::string Game
 
std::string UserReadableGame
 

Static Protected Attributes

static AppDefDefaultconf = nullptr
 

Detailed Description

Definition at line 48 of file AppDefine.h.

Constructor & Destructor Documentation

◆ AppDef()

DLLEXPORT Leviathan::AppDef::AppDef ( const bool &  isdef = false)

Definition at line 15 of file AppDefine.cpp.

15  :
17 #ifdef _WIN32
18  HInstance(NULL)
19 #else
20  HInstance(0)
21 #endif //_WIN32
22 {
23  // If this is the default configuration set as the static access one //
24  if(isdef)
25  Defaultconf = this;
26 }
std::unique_ptr< NamedVars > ConfigurationValues
Definition: AppDefine.h:142
static AppDef * Defaultconf
Definition: AppDefine.h:172

◆ ~AppDef()

AppDef::~AppDef ( )

Definition at line 28 of file AppDefine.cpp.

29 {
30  // reset static access if this is it //
31  if(Defaultconf == this)
32  Defaultconf = nullptr;
33 
36 }
KeyConfiguration * _KeyConfiguration
Definition: AppDefine.h:157
GameConfiguration * _GameConfiguration
Definition: AppDefine.h:156
#define SAFE_RELEASEDEL(x)
Definition: Define.h:115
static AppDef * Defaultconf
Definition: AppDefine.h:172

Member Function Documentation

◆ FillDefaultEngineConf()

DLLEXPORT bool AppDef::FillDefaultEngineConf ( NamedVars variables)
virtual

This is called then the engine config file isn't found to fill the options with default values.

This is also used to fill existing configs with missing values

Returns
True if options need to be saved (changes were made)

Definition at line 173 of file AppDefine.cpp.

174 {
175  bool changed = false;
176 
177  if(variables.ShouldAddValueIfNotFoundOrWrongType<bool>("Vsync")) {
178  changed = true;
179  variables.Add(std::make_shared<NamedVariableList>("Vsync", false));
180  }
181 
182  if(variables.ShouldAddValueIfNotFoundOrWrongType<bool>("UseGamma")) {
183  changed = true;
184  variables.Add(std::make_shared<NamedVariableList>("UseGamma", true));
185  }
186 
187  if(variables.ShouldAddValueIfNotFoundOrWrongType<bool>("OgreBoreMe")) {
188  changed = true;
189  variables.Add(std::make_shared<NamedVariableList>("OgreBoreMe", false));
190  }
191 
192  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("FSAA")) {
193  changed = true;
194  variables.Add(std::make_shared<NamedVariableList>("FSAA", 4));
195  }
196 
197  if(variables.ShouldAddValueIfNotFoundOrWrongType<std::string>("FullScreen")) {
198  changed = true;
199  variables.Add(
200  std::make_shared<NamedVariableList>("FullScreen", new StringBlock("no")));
201  }
202 
203  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("DisplayNumber")) {
204  changed = true;
205  variables.Add(std::make_shared<NamedVariableList>("DisplayNumber", 0));
206  }
207 
208  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("Width")) {
209  changed = true;
210  variables.Add(std::make_shared<NamedVariableList>("Width", 1280));
211  }
212 
213  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("Height")) {
214  changed = true;
215  variables.Add(std::make_shared<NamedVariableList>("Height", 720));
216  }
217 
218  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("MaxFPS")) {
219  changed = true;
220  variables.Add(std::make_shared<NamedVariableList>("MaxFPS", 120));
221  }
222 
223  if(variables.ShouldAddValueIfNotFoundOrWrongType<std::string>("AudioDevice")) {
224 
225  LOG_INFO("AppDefine: Detecting default audio device for creating default config");
226 
227  size_t defaultDevice = 0;
228  const auto devices = SoundDevice::GetAudioDevices(&defaultDevice);
229 
230  if(devices.empty() || defaultDevice >= devices.size()) {
231 
232  LOG_ERROR("AppDefine: Couldn't detect default audio device");
233 
234  } else {
235 
236  LOG_INFO("AppDefine: default audio device is: " + devices[defaultDevice]);
237 
238  changed = true;
239  variables.Add(
240  std::make_shared<NamedVariableList>("AudioDevice", devices[defaultDevice]));
241  }
242  }
243 
244  return changed;
245 }
#define LOG_INFO(x)
Definition: Define.h:81
#define LOG_ERROR(x)
Definition: Define.h:83
bool ShouldAddValueIfNotFoundOrWrongType(const std::string &name)
Definition: NamedVars.h:372
DLLEXPORT bool Add(std::shared_ptr< NamedVariableList > value)
Adds a value.
Definition: NamedVars.cpp:879
static DLLEXPORT std::vector< std::string > GetAudioDevices(size_t *indexofdefault=nullptr)
Returns a list of audio playback devices.
DataBlock< std::string > StringBlock
Definition: DataBlock.h:386

◆ GenerateAppdefine()

DLLEXPORT AppDef * Leviathan::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 
)
static

Definition at line 45 of file AppDefine.cpp.

49 {
50  auto tmpptr = std::make_unique<AppDef>(true);
51 
52  // We created a new one //
53  tmpptr->DeleteLog = true;
54 
55  if(!Logger::Get()) {
56 
57  std::cout << "Error: main log hasn't been created before AppDef: GenerateAppdefine"
58  << std::endl;
59  return nullptr;
60  }
61 
62  // load variables from configuration file //
63  // TODO: refactor this duplicated code
64  if(!tmpptr->ConfigurationValues->LoadVarsFromFile(engineconfigfile, Logger::Get())) {
65 
66  // Set default values //
67  tmpptr->FillDefaultEngineConf(*tmpptr->ConfigurationValues);
68 
69  // Write it to the file for next time //
71  tmpptr->ConfigurationValues->Serialize(), engineconfigfile)) {
72 
73  LOG_ERROR(
74  "AppDef: failed to write default engine config to file: " + engineconfigfile);
75  }
76  } else {
77  // Fill missing values //
78  if(tmpptr->FillDefaultEngineConf(*tmpptr->ConfigurationValues)) {
79 
80  // Save changes
82  tmpptr->ConfigurationValues->Serialize(), engineconfigfile)) {
83 
84  LOG_ERROR("AppDef: failed to write amended engine config to file: " +
85  engineconfigfile);
86  }
87  }
88  }
89 
90  // Load game configuration //
91  tmpptr->_GameConfiguration = new GameConfiguration(gameconfig);
92 
93  if(!tmpptr->_GameConfiguration->Init(configchecker)) {
94 
95  return nullptr;
96  }
97 
98  // Load key configuration //
99  tmpptr->_KeyConfiguration = new KeyConfiguration(keyconfig);
100 
101  if(!tmpptr->_KeyConfiguration->Init(keychecker)) {
102 
103  return nullptr;
104  }
105 
106  return tmpptr.release();
107 }
#define LOG_ERROR(x)
Definition: Define.h:83
Holds key configuration for an application.
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
static DLLEXPORT bool WriteToFile(const std::string &data, const std::string &filename)
Definition: FileSystem.cpp:462

◆ GetDefault()

static DLLEXPORT AppDef* Leviathan::AppDef::GetDefault ( )
inlinestatic

Definition at line 112 of file AppDefine.h.

113  {
114  return Defaultconf;
115  }
static AppDef * Defaultconf
Definition: AppDefine.h:172

◆ GetGameConfiguration()

DLLEXPORT auto* Leviathan::AppDef::GetGameConfiguration ( )
inline

Definition at line 102 of file AppDefine.h.

103  {
104  return _GameConfiguration;
105  }
GameConfiguration * _GameConfiguration
Definition: AppDefine.h:156

◆ GetGameIdentificationData()

DLLEXPORT void Leviathan::AppDef::GetGameIdentificationData ( std::string &  userreadable,
std::string &  gamename,
std::string &  gameversion 
)

Definition at line 165 of file AppDefine.cpp.

167 {
168  userreadable = UserReadableGame;
169  gamename = Game;
170  gameversion = GameVersion;
171 }
std::string Game
Definition: AppDefine.h:168
std::string UserReadableGame
Definition: AppDefine.h:169
std::string GameVersion
Definition: AppDefine.h:167

◆ GetKeyConfiguration()

DLLEXPORT auto* Leviathan::AppDef::GetKeyConfiguration ( )
inline

Definition at line 107 of file AppDefine.h.

108  {
109  return _KeyConfiguration;
110  }
KeyConfiguration * _KeyConfiguration
Definition: AppDefine.h:157

◆ GetMasterServerInfo()

DLLEXPORT MasterServerInformation& Leviathan::AppDef::GetMasterServerInfo ( )
inline

Definition at line 97 of file AppDefine.h.

98  {
99  return MasterServerInfo;
100  }
MasterServerInformation MasterServerInfo
Definition: AppDefine.h:148

◆ GetValues()

NamedVars * Leviathan::AppDef::GetValues ( )

Definition at line 40 of file AppDefine.cpp.

41 {
42  return ConfigurationValues.get();
43 }
std::unique_ptr< NamedVars > ConfigurationValues
Definition: AppDefine.h:142

◆ GetWindowDetails()

DLLEXPORT WindowDataDetails& Leviathan::AppDef::GetWindowDetails ( )
inline

Definition at line 93 of file AppDefine.h.

94  {
95  return WDetails;
96  }
WindowDataDetails WDetails
Definition: AppDefine.h:153

◆ SetApplicationIdentification()

DLLEXPORT AppDef & Leviathan::AppDef::SetApplicationIdentification ( const std::string &  userreadable,
const std::string &  gamename,
const std::string &  gameversion 
)

Definition at line 153 of file AppDefine.cpp.

156 {
157  UserReadableGame = userreadable;
158  Game = gamename;
159  GameVersion = gameversion;
161 
162  return *this;
163 }
#define LEVIATHAN_VERSION_ANSIS
Definition: Include.h:90
std::string Game
Definition: AppDefine.h:168
std::string LeviathanVersion
Definition: AppDefine.h:166
std::string UserReadableGame
Definition: AppDefine.h:169
std::string GameVersion
Definition: AppDefine.h:167

◆ SetMasterServerParameters()

DLLEXPORT AppDef& Leviathan::AppDef::SetMasterServerParameters ( const MasterServerInformation info)
inline

Definition at line 82 of file AppDefine.h.

83  {
84 
85  MasterServerInfo = info;
86  return *this;
87  }
MasterServerInformation MasterServerInfo
Definition: AppDefine.h:148

◆ SetWindowDetails()

DLLEXPORT AppDef& Leviathan::AppDef::SetWindowDetails ( const WindowDataDetails det)
inline

Definition at line 75 of file AppDefine.h.

76  {
77 
78  WDetails = det;
79  return *this;
80  }
WindowDataDetails WDetails
Definition: AppDefine.h:153

◆ StoreWindowDetails()

DLLEXPORT void Leviathan::AppDef::StoreWindowDetails ( const std::string &  title,
const bool &  windowborder,
LeviathanApplication appvirtualptr 
)

Definition at line 116 of file AppDefine.cpp.

118 {
119 #endif
120  // store the parameters to be used for window creation //
121  int width;
122  int height;
123  std::string fullscreen;
124  int FSAA;
125  int displayNumber;
126  bool vsync;
127  bool gamma;
128 
130  ConfigurationValues.get(), "Width", width, 1280, Logger::Get(), "Create window: ");
132  ConfigurationValues.get(), "Height", height, 720, Logger::Get(), "Create window: ");
133  ObjectFileProcessor::LoadValueFromNamedVars<std::string>(ConfigurationValues.get(),
134  "FullScreen", fullscreen, "no", Logger::Get(), "Create window: ");
135  ObjectFileProcessor::LoadValueFromNamedVars<int>(
136  ConfigurationValues.get(), "FSAA", FSAA, 4, Logger::Get(), "Create window: ");
137  ObjectFileProcessor::LoadValueFromNamedVars<int>(ConfigurationValues.get(),
138  "DisplayNumber", displayNumber, 0, Logger::Get(), "Create window: ");
139  ObjectFileProcessor::LoadValueFromNamedVars<bool>(
140  *ConfigurationValues, "Vsync", vsync, false, Logger::Get(), "Create window: ");
141  ObjectFileProcessor::LoadValueFromNamedVars<bool>(
142  *ConfigurationValues, "UseGamma", gamma, false, Logger::Get(), "Create window: ");
143 
144 #ifdef _WIN32
145  this->SetWindowDetails(WindowDataDetails(title, width, height, fullscreen, vsync, gamma,
146  displayNumber, FSAA, windowborder, icon, appvirtualptr));
147 #else
148  this->SetWindowDetails(WindowDataDetails(title, width, height, fullscreen, vsync, gamma,
149  displayNumber, FSAA, windowborder, appvirtualptr));
150 #endif
151 }
std::unique_ptr< NamedVars > ConfigurationValues
Definition: AppDefine.h:142
static bool LoadValueFromNamedVars(NamedVars *block, const std::string &varname, T &receiver, const T &defaultvalue, LErrorReporter *ReportError=nullptr, const std::string &errorprefix="")
DLLEXPORT AppDef & SetWindowDetails(const WindowDataDetails &det)
Definition: AppDefine.h:75
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

Member Data Documentation

◆ _GameConfiguration

GameConfiguration* Leviathan::AppDef::_GameConfiguration = nullptr
protected

Definition at line 156 of file AppDefine.h.

◆ _KeyConfiguration

KeyConfiguration* Leviathan::AppDef::_KeyConfiguration = nullptr
protected

Definition at line 157 of file AppDefine.h.

◆ _NetworkInterface

std::shared_ptr<NetworkInterface> Leviathan::AppDef::_NetworkInterface
protected

Definition at line 150 of file AppDefine.h.

◆ ConfigurationValues

std::unique_ptr<NamedVars> Leviathan::AppDef::ConfigurationValues
protected

Definition at line 142 of file AppDefine.h.

◆ Defaultconf

AppDef * Leviathan::AppDef::Defaultconf = nullptr
staticprotected

Definition at line 172 of file AppDefine.h.

◆ DeleteLog

bool Leviathan::AppDef::DeleteLog = false
protected

Controls whether the destructor deletes Mainlog

Note
Used to not delete loggers that weren't created by this instance

Definition at line 164 of file AppDefine.h.

◆ Game

std::string Leviathan::AppDef::Game
protected

Definition at line 168 of file AppDefine.h.

◆ GameVersion

std::string Leviathan::AppDef::GameVersion
protected

Definition at line 167 of file AppDefine.h.

◆ HInstance

int Leviathan::AppDef::HInstance
protected

Definition at line 146 of file AppDefine.h.

◆ LeviathanVersion

std::string Leviathan::AppDef::LeviathanVersion
protected

Definition at line 166 of file AppDefine.h.

◆ Mainlog

Logger* Leviathan::AppDef::Mainlog = nullptr
protected

Definition at line 159 of file AppDefine.h.

◆ MasterServerInfo

MasterServerInformation Leviathan::AppDef::MasterServerInfo
protected

Definition at line 148 of file AppDefine.h.

◆ UserReadableGame

std::string Leviathan::AppDef::UserReadableGame
protected

Definition at line 169 of file AppDefine.h.

◆ WDetails

WindowDataDetails Leviathan::AppDef::WDetails
protected

Definition at line 153 of file AppDefine.h.


The documentation for this class was generated from the following files: