Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
globals.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <map>
5 #include <vector>
6 
7 #include <Strings/components/resources/color/BlamColor.h>
8 #include <Strings/components/utils/string/string.h>
9 
10 #define GVARS_FILE "./globals.xml"
11 
12 #ifndef BLAM
13 #define BLAM
14 #endif
15 
16 namespace Blam
17 {
21  namespace Globals
22  {
27  {
30  Ok,
34  };
35 
39  enum GvarType
40  {
42  Real,
44  Long,
47  Int,
50  };
51 
62  struct EngineGlobal
63  {
65  std::string name = "";
66  std::string info = "";
67  std::string value_raw = "";
68  bool read_only = false;
69 
71  // Additional value storage types, these are used in place of value_raw based on type. //
73 
74  bool boolean_value = false;
75  short short_value = 0;
76  long long_value = 0;
77  int int_value = 0;
78  float float_value = 0.0f;
79  BlamColor color_value = BlamColor(0, 0, 0);
80  };
81 
90  BLAM std::map<std::string, EngineGlobal>* GetGlobalsList();
91 
98 
106  BLAM std::string GetGvarTypeLabel(GvarType type);
107 
115  BLAM bool GlobalExists(std::string id);
116 
122  BLAM void RegisterGvar(EngineGlobal var);
123 
131  BLAM void RegisterGvar(std::string name, std::string value_raw, GvarType type);
132 
141  BLAM void RegisterGvar(std::string name, std::string value_raw, GvarType type, std::string info);
142 
150  BLAM EngineGlobal* GetGlobal(std::string name);
151 
160  BLAM GvarUpdateResult UpdateGlobalWrap(std::string name, std::string new_value);
161 
170  BLAM GvarUpdateResult UpdateGlobal(std::string name, std::string new_value);
171 
180  BLAM GvarUpdateResult UpdateGlobal(std::string name, bool new_value);
181 
190  BLAM GvarUpdateResult UpdateGlobal(std::string name, int new_value);
191 
200  BLAM GvarUpdateResult UpdateGlobal(std::string name, short new_value);
201 
210  BLAM GvarUpdateResult UpdateGlobal(std::string name, long new_value);
211 
220  BLAM GvarUpdateResult UpdateGlobal(std::string name, float new_value);
221 
230  BLAM GvarUpdateResult UpdateGlobal(std::string name, BlamColor new_value);
231 
239  BLAM bool* GetGlobalAsBoolean(std::string name);
240 
248  BLAM std::string* GetGlobalAsString(std::string name);
249 
257  BLAM short* GetGlobalAsShort(std::string name);
258 
266  BLAM long* GetGlobalAsLong(std::string name);
267 
275  BLAM int* GetGlobalAsInteger(std::string name);
276 
284  BLAM float* GetGlobalAsFloat(std::string name);
285 
293  BLAM BlamColor* GetGlobalAsColor(std::string name);
294  }
295 }
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:18
Blam::Globals::RegisterGvar
BLAM void RegisterGvar(EngineGlobal var)
Registers a new engine global.
Definition: globals.cpp:65
Blam::Globals::GetGlobal
BLAM EngineGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: globals.cpp:193
Blam::Globals::GlobalExists
BLAM bool GlobalExists(std::string id)
Determines whether or not a global exists.
Definition: globals.cpp:27
Blam::Globals::EngineGlobal::float_value
float float_value
The float value of the global.
Definition: globals.h:78
Blam::Globals::EngineGlobal::info
std::string info
An optional description of the global.
Definition: globals.h:66
Blam::Globals::Int
@ Int
Represents an int.
Definition: globals.h:47
Blam::Globals::EngineGlobal::color_value
BlamColor color_value
The color value of the global.
Definition: globals.h:79
Blam::Globals::UnknownGlobal
@ UnknownGlobal
The specified global does not exist.
Definition: globals.h:29
Blam::Globals::Long
@ Long
Represents a long.
Definition: globals.h:44
Blam::Globals::GlobalIsProtected
@ GlobalIsProtected
The specified global is protected and cannot be modified during runtime.
Definition: globals.h:33
Blam::Globals::LoadGlobalsFromFile
BLAM bool LoadGlobalsFromFile()
Loads any globals from GVARS_FILE.
Definition: globals.cpp:206
Blam::Globals::GetGlobalAsFloat
BLAM float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: globals.cpp:400
Blam::Globals::InvalidArgs
@ InvalidArgs
The provided arguments were invalid.
Definition: globals.h:31
Blam::Globals::Real
@ Real
Same as Float.
Definition: globals.h:42
Blam::Globals::UpdateGlobalWrap
BLAM GvarUpdateResult UpdateGlobalWrap(std::string name, std::string new_value)
Updates a global's raw value.
Definition: globals.cpp:428
Blam::Globals::EngineGlobal::read_only
bool read_only
Whether or not the global is protected from modification.
Definition: globals.h:68
Blam::Globals::EngineGlobal::name
std::string name
The name of the global.
Definition: globals.h:65
Blam::Globals::GvarType
GvarType
Enumerator for the type of global variable.
Definition: globals.h:39
Blam::Globals::EngineGlobal::short_value
short short_value
The short value of the global.
Definition: globals.h:75
Blam::Globals::GetGlobalAsColor
BLAM BlamColor * GetGlobalAsColor(std::string name)
Retrieves a global's value as a BlamColor.
Definition: globals.cpp:412
Blam::Globals::String
@ String
Represents a std::string.
Definition: globals.h:46
BLAM
#define BLAM
Definition: globals.h:13
Blam::Globals::EngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:62
Blam::Globals::Float
@ Float
Represents a float.
Definition: globals.h:48
Blam::Globals::EngineGlobal::long_value
long long_value
The long value of the global.
Definition: globals.h:76
Blam::Globals::GvarUpdateResult
GvarUpdateResult
Enumerator for the result of a global update attempt.
Definition: globals.h:26
Blam::Globals::GetGlobalAsShort
BLAM short * GetGlobalAsShort(std::string name)
Retrieves a global's value as a short.
Definition: globals.cpp:364
Blam::Globals::InvalidType
@ InvalidType
The provided value was of an invalid type.
Definition: globals.h:28
Blam::Globals::Object
@ Object
Unknown. Referenced within the hs_doc from Halo 2 Sapien.
Definition: globals.h:45
Blam::Globals::Short
@ Short
Represents a short.
Definition: globals.h:43
Blam::Globals::EngineGlobal::int_value
int int_value
The int value of the global.
Definition: globals.h:77
Blam::Globals::GetGlobalsList
BLAM std::map< std::string, EngineGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: globals.cpp:22
Blam::Globals::OutOfBounds
@ OutOfBounds
The provided value was too small or too large for the globals' data type.
Definition: globals.h:32
Blam::Globals::GetGlobalAsLong
BLAM long * GetGlobalAsLong(std::string name)
Retrieves a global's value as a long.
Definition: globals.cpp:376
Blam::Globals::Color
@ Color
Represents a BlamColor. See #BlamColor for details.
Definition: globals.h:49
Blam::Globals::Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:41
Blam::Globals::GetGlobalAsString
BLAM std::string * GetGlobalAsString(std::string name)
Retrieves a global's value as a string.
Definition: globals.cpp:352
Blam::Globals::EngineGlobal::value_raw
std::string value_raw
The raw value of the global as a string.
Definition: globals.h:67
Blam::Globals::EngineGlobal::type
GvarType type
The type of the global.
Definition: globals.h:64
Blam::Globals::Ok
@ Ok
The global was updated successfully.
Definition: globals.h:30
Blam::Globals::GetGlobalAsBoolean
BLAM bool * GetGlobalAsBoolean(std::string name)
Retrieves a global's value as a boolean.
Definition: globals.cpp:340
Blam::Globals::EngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:74
Blam::Globals::UpdateGlobal
BLAM GvarUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: globals.cpp:571
Blam::Globals::GetGvarTypeLabel
BLAM std::string GetGvarTypeLabel(GvarType type)
Retrieves a string representation of a global's type, for use in UI.
Definition: globals.cpp:40
Blam::Globals::GetGlobalAsInteger
BLAM int * GetGlobalAsInteger(std::string name)
Retrieves a global's value as an int.
Definition: globals.cpp:388