Leviathan  0.8.0.0
Leviathan game engine
GameConfiguration.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2019 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
7 #include "Common/ThreadSafe.h"
8 #include <boost/function.hpp>
9 
10 
11 namespace Leviathan {
12 
13 #define GAMECONFIGURATION_GET_VARIABLEACCESS(x) \
14  NamedVars* x = NULL; \
15  Lock varlockaccess; \
16  { \
17  GameConfiguration* configvar = GameConfiguration::Get(); \
18  if(configvar != NULL) { \
19  varlockaccess = Lock(configvar->ObjectsLock); \
20  x = configvar->AccessVariables(varlockaccess); \
21  } \
22  }
23 
24 class GameConfiguration : public ThreadSafe {
25 public:
26  DLLEXPORT GameConfiguration(const std::string& configfile);
27 
31 
32 
35  DLLEXPORT bool Init(
36  std::function<void(Lock& guard, GameConfiguration* configobj)> sanitycheckcallback);
37 
39  DLLEXPORT void Release();
40 
42  DLLEXPORT void SaveCheck();
43 
48 
50  DLLEXPORT void MarkModified(Lock& guard);
51 
55 
57 
58 private:
59  std::string GameConfigFile;
60 
61  // This stores all the values and is passed around from this object to reduce bloat //
62  NamedVars* GameVars = nullptr;
63  // Controls when to save changes //
64  bool Modified = false;
65 
67  bool InMemory = false;
68 
69  static GameConfiguration* staticaccess;
70 };
71 
72 } // namespace Leviathan
73 
74 #ifdef LEAK_INTO_GLOBAL
76 #endif
DLLEXPORT void Release()
Tries to save the changes.
Allows the inherited object to be locked.
Definition: ThreadSafe.h:123
DLLEXPORT void SaveCheck()
Saves current values (if marked as unsaved)
DLLEXPORT NamedVars * AccessVariables(Lock &guard)
static DLLEXPORT GameConfiguration * Get()
DLLEXPORT void MarkModified(Lock &guard)
Call this when you have changed variables.
DLLEXPORT void VerifyGlobalVariables(Lock &guard)
#define DLLEXPORT
Definition: Include.h:115
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT GameConfiguration()
Creates an in-memory only configuration.
DLLEXPORT bool Init(std::function< void(Lock &guard, GameConfiguration *configobj)> sanitycheckcallback)
std::unique_lock< std::mutex > Lock
Definition: ThreadSafe.h:16