Leviathan  0.8.0.0
Leviathan game engine
Leviathan::AppDef Class Reference

#include <AppDefine.h>

Public Member Functions

DLLEXPORT AppDef (const bool &isdef=false)
 
virtual 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...
 
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. 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:147
static AppDef * Defaultconf
Definition: AppDefine.h:177

◆ ~AppDef()

AppDef::~AppDef ( )
virtual

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:162
GameConfiguration * _GameConfiguration
Definition: AppDefine.h:161
#define SAFE_RELEASEDEL(x)
Definition: Define.h:133
static AppDef * Defaultconf
Definition: AppDefine.h:177

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 196 of file AppDefine.cpp.

197 {
198  bool changed = false;
199 
200  if(variables.ShouldAddValueIfNotFoundOrWrongType<bool>("Vsync")) {
201  changed = true;
202  variables.Add(std::make_shared<NamedVariableList>("Vsync", false));
203  }
204 
205  if(variables.ShouldAddValueIfNotFoundOrWrongType<bool>("UseGamma")) {
206  changed = true;
207  variables.Add(std::make_shared<NamedVariableList>("UseGamma", true));
208  }
209 
210  if(variables.ShouldAddValueIfNotFoundOrWrongType<bool>("OgreBoreMe")) {
211  changed = true;
212  variables.Add(std::make_shared<NamedVariableList>("OgreBoreMe", false));
213  }
214 
215  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("FSAA")) {
216  changed = true;
217  variables.Add(std::make_shared<NamedVariableList>("FSAA", 4));
218  }
219 
220  if(variables.ShouldAddValueIfNotFoundOrWrongType<std::string>("FullScreen")) {
221  changed = true;
222  variables.Add(
223  std::make_shared<NamedVariableList>("FullScreen", new StringBlock("no")));
224  }
225 
226  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("DisplayNumber")) {
227  changed = true;
228  variables.Add(std::make_shared<NamedVariableList>("DisplayNumber", 0));
229  }
230 
231  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("Width")) {
232  changed = true;
233  variables.Add(std::make_shared<NamedVariableList>("Width", 1280));
234  }
235 
236  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("Height")) {
237  changed = true;
238  variables.Add(std::make_shared<NamedVariableList>("Height", 720));
239  }
240 
241  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("MaxFPS")) {
242  changed = true;
243  variables.Add(std::make_shared<NamedVariableList>("MaxFPS", 120));
244  }
245 
246  if(variables.ShouldAddValueIfNotFoundOrWrongType<std::string>("AudioDevice")) {
247 
248  changed = true;
249  variables.Add(
250  std::make_shared<NamedVariableList>("AudioDevice", new StringBlock("default")));
251  }
252 
253  return changed;
254 }
bool ShouldAddValueIfNotFoundOrWrongType(const std::string &name)
Definition: NamedVars.h:376
DLLEXPORT bool Add(std::shared_ptr< NamedVariableList > value)
Adds a value.
Definition: NamedVars.cpp:883
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:84
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:461

◆ 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:177

◆ 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:161

◆ GetGameIdentificationData()

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

Definition at line 188 of file AppDefine.cpp.

190 {
191  userreadable = UserReadableGame;
192  gamename = Game;
193  gameversion = GameVersion;
194 }
std::string Game
Definition: AppDefine.h:173
std::string UserReadableGame
Definition: AppDefine.h:174
std::string GameVersion
Definition: AppDefine.h:172

◆ 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:162

◆ 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:153

◆ 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:147

◆ 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:158

◆ ReplaceGameAndKeyConfigInMemory()

DLLEXPORT void AppDef::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 at line 109 of file AppDefine.cpp.

112 {
114  delete _GameConfiguration;
115 
117 
118  if(!_GameConfiguration->Init(configchecker)) {
119 
120  LOG_ERROR("AppDef: failed to init new in-memory game configuration");
121  }
122 
123  // Load key configuration //
125 
126  if(!_KeyConfiguration->Init(keychecker)) {
127 
128  LOG_ERROR("AppDef: failed to init new in-memory key configuration");
129  }
130 }
KeyConfiguration * _KeyConfiguration
Definition: AppDefine.h:162
#define LOG_ERROR(x)
Definition: Define.h:84
Holds key configuration for an application.
GameConfiguration * _GameConfiguration
Definition: AppDefine.h:161
DLLEXPORT bool Init(std::function< void(Lock &guard, GameConfiguration *configobj)> sanitycheckcallback)
DLLEXPORT bool Init(std::function< void(Lock &guard, KeyConfiguration *checkfrom)> functocheck)
Loads the defined keys from a file.

◆ SetApplicationIdentification()

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

Definition at line 176 of file AppDefine.cpp.

179 {
180  UserReadableGame = userreadable;
181  Game = gamename;
182  GameVersion = gameversion;
184 
185  return *this;
186 }
#define LEVIATHAN_VERSION_ANSIS
Definition: Include.h:56
std::string Game
Definition: AppDefine.h:173
std::string LeviathanVersion
Definition: AppDefine.h:171
std::string UserReadableGame
Definition: AppDefine.h:174
std::string GameVersion
Definition: AppDefine.h:172

◆ 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:153

◆ 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:158

◆ StoreWindowDetails()

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

Definition at line 139 of file AppDefine.cpp.

141 {
142 #endif
143  // store the parameters to be used for window creation //
144  int width;
145  int height;
146  std::string fullscreen;
147  int FSAA;
148  int displayNumber;
149  bool vsync;
150  bool gamma;
151 
153  ConfigurationValues.get(), "Width", width, 1280, Logger::Get(), "Create window: ");
155  ConfigurationValues.get(), "Height", height, 720, Logger::Get(), "Create window: ");
156  ObjectFileProcessor::LoadValueFromNamedVars<std::string>(ConfigurationValues.get(),
157  "FullScreen", fullscreen, "no", Logger::Get(), "Create window: ");
158  ObjectFileProcessor::LoadValueFromNamedVars<int>(
159  ConfigurationValues.get(), "FSAA", FSAA, 4, Logger::Get(), "Create window: ");
160  ObjectFileProcessor::LoadValueFromNamedVars<int>(ConfigurationValues.get(),
161  "DisplayNumber", displayNumber, 0, Logger::Get(), "Create window: ");
162  ObjectFileProcessor::LoadValueFromNamedVars<bool>(
163  *ConfigurationValues, "Vsync", vsync, false, Logger::Get(), "Create window: ");
164  ObjectFileProcessor::LoadValueFromNamedVars<bool>(
165  *ConfigurationValues, "UseGamma", gamma, false, Logger::Get(), "Create window: ");
166 
167 #ifdef _WIN32
168  this->SetWindowDetails(WindowDataDetails(title, width, height, fullscreen, vsync, gamma,
169  displayNumber, FSAA, windowborder, icon, appvirtualptr));
170 #else
171  this->SetWindowDetails(WindowDataDetails(title, width, height, fullscreen, vsync, gamma,
172  displayNumber, FSAA, windowborder, appvirtualptr));
173 #endif
174 }
std::unique_ptr< NamedVars > ConfigurationValues
Definition: AppDefine.h:147
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 161 of file AppDefine.h.

◆ _KeyConfiguration

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

Definition at line 162 of file AppDefine.h.

◆ _NetworkInterface

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

Definition at line 155 of file AppDefine.h.

◆ ConfigurationValues

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

Definition at line 147 of file AppDefine.h.

◆ Defaultconf

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

Definition at line 177 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 169 of file AppDefine.h.

◆ Game

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

Definition at line 173 of file AppDefine.h.

◆ GameVersion

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

Definition at line 172 of file AppDefine.h.

◆ HInstance

int Leviathan::AppDef::HInstance
protected

Definition at line 151 of file AppDefine.h.

◆ LeviathanVersion

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

Definition at line 171 of file AppDefine.h.

◆ Mainlog

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

Definition at line 164 of file AppDefine.h.

◆ MasterServerInfo

MasterServerInformation Leviathan::AppDef::MasterServerInfo
protected

Definition at line 153 of file AppDefine.h.

◆ UserReadableGame

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

Definition at line 174 of file AppDefine.h.

◆ WDetails

WindowDataDetails Leviathan::AppDef::WDetails
protected

Definition at line 158 of file AppDefine.h.


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