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:145
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 193 of file AppDefine.cpp.

194 {
195  bool changed = false;
196 
197  if(variables.ShouldAddValueIfNotFoundOrWrongType<bool>("Vsync")) {
198  changed = true;
199  variables.Add(std::make_shared<NamedVariableList>("Vsync", false));
200  }
201 
202  if(variables.ShouldAddValueIfNotFoundOrWrongType<std::string>("FullScreen")) {
203  changed = true;
204  variables.Add(
205  std::make_shared<NamedVariableList>("FullScreen", new StringBlock("no")));
206  }
207 
208  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("DisplayNumber")) {
209  changed = true;
210  variables.Add(std::make_shared<NamedVariableList>("DisplayNumber", 0));
211  }
212 
213  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("Width")) {
214  changed = true;
215  variables.Add(std::make_shared<NamedVariableList>("Width", 1280));
216  }
217 
218  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("Height")) {
219  changed = true;
220  variables.Add(std::make_shared<NamedVariableList>("Height", 720));
221  }
222 
223  if(variables.ShouldAddValueIfNotFoundOrWrongType<int>("MaxFPS")) {
224  changed = true;
225  variables.Add(std::make_shared<NamedVariableList>("MaxFPS", 144));
226  }
227 
228  if(variables.ShouldAddValueIfNotFoundOrWrongType<std::string>("AudioDevice")) {
229 
230  changed = true;
231  variables.Add(
232  std::make_shared<NamedVariableList>("AudioDevice", new StringBlock("default")));
233  }
234 
235  return changed;
236 }
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:96
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:456

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

187 {
188  userreadable = UserReadableGame;
189  gamename = Game;
190  gameversion = GameVersion;
191 }
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:96
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 173 of file AppDefine.cpp.

176 {
177  UserReadableGame = userreadable;
178  Game = gamename;
179  GameVersion = gameversion;
181 
182  return *this;
183 }
#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 
152  ConfigurationValues.get(), "Width", width, 1280, Logger::Get(), "Create window: ");
154  ConfigurationValues.get(), "Height", height, 720, Logger::Get(), "Create window: ");
155  ObjectFileProcessor::LoadValueFromNamedVars<std::string>(ConfigurationValues.get(),
156  "FullScreen", fullscreen, "no", Logger::Get(), "Create window: ");
157  ObjectFileProcessor::LoadValueFromNamedVars<int>(
158  ConfigurationValues.get(), "WindowMultiSampleCount", FSAA, 1);
159  ObjectFileProcessor::LoadValueFromNamedVars<int>(ConfigurationValues.get(),
160  "DisplayNumber", displayNumber, 0, Logger::Get(), "Create window: ");
161  ObjectFileProcessor::LoadValueFromNamedVars<bool>(
162  *ConfigurationValues, "Vsync", vsync, false, Logger::Get(), "Create window: ");
163 
164 #ifdef _WIN32
165  this->SetWindowDetails(WindowDataDetails(title, width, height, fullscreen, vsync,
166  displayNumber, FSAA, windowborder, icon, appvirtualptr));
167 #else
168  this->SetWindowDetails(WindowDataDetails(title, width, height, fullscreen, vsync,
169  displayNumber, FSAA, windowborder, appvirtualptr));
170 #endif
171 }
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: