Blamite Game Engine - Blam (Core)
tags.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 #include <Windows.h>
6 
7 #include "components/3rdparty/imgui/imgui.h"
9 
10 #ifndef BLAM
11 #define BLAM
12 #endif
13 
18 {
23 };
24 
29 {
30 public:
31  void* address;
32  int size;
33 
44  char path[256];
45  std::string tag_class;
47 
55  bool SetTagPath(std::string new_path)
56  {
57  if (new_path.length() > 256)
58  {
59  Blam::Logger::LogEvent("### ERROR tried to set tag '" + std::string(path) + "' to a new path that was too long (" + std::to_string(new_path.length()) + ") '" + new_path + "'", WSV_ERROR, Blam::Logger::ReportType::TagDebug);
60  return false;
61  }
62  else
63  {
64  Blam::Logger::LogEvent("tag '" + std::string(path) + "' had path set to new value '" + new_path + "'", WSV_NONE, Blam::Logger::ReportType::TagDebug);
65 
66  void* clear_path = calloc(1, 256);
67  memcpy(path, clear_path, 256);
68  free(clear_path);
69 
70  memcpy(path, new_path.c_str(), new_path.length());
71  return true;
72  }
73  }
74 };
75 
76 // find a way to ensure that this stuff (mainly the identifier) is preserved
77 // if its missing theres literally no possible way to identify a tag block when trying to save a tag file
78 struct tag_block
79 {
80  char block_identifier[6];
81  int entry_size = 0;
83  int entry_count = 0;
84 };
85 
90 {
91  char tag_path[256];
92  void* tag_address;
93 
95  {
96  void* empty_data = calloc(1, 256);
97  memcpy(tag_path, empty_data, 256);
98  }
99 };
100 
104 namespace Blam::Content::Tags
105 {
112  BLAM void ShowImPropertyEditor(void* tag, std::string tag_class);
113 
114  BLAM std::string RegisterCreatedTag(void* tag, std::string tag_class);
115 
124  BLAM HRESULT LoadTagFromFile(std::string tag_path);
125 
136  BLAM HRESULT SaveTag(void* tag_data, std::string tag_class, int tag_size, std::string tag_path);
137 
148  BLAM tag_memory_data* GetTagData(std::string tag_path);
149 
150  BLAM void CleanupTagData();
151 
157  BLAM std::vector<tag_memory_data>* GetLoadedTags();
158 }
tag_reference::tag_address
void * tag_address
Address to the referenced tag. Once this is set, should be used exclusively rather than the path.
Definition: tags.h:92
Blam::Content::Tags::LoadTagFromFile
BLAM HRESULT LoadTagFromFile(std::string tag_path)
Loads a tag from the engine's tag directory (default is '.
Definition: tags.cpp:156
Blam::Content::Tags
Namespace containing things related to tag data.
Definition: bitmap.h:9
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:33
tag_block
Definition: tags.h:78
tag_memory_data::tag_class
std::string tag_class
The tag's short class name.
Definition: tags.h:45
logger.h
tag_memory_data::address
void * address
The address pointing to the start of the tag's data.
Definition: tags.h:31
CacheFile
@ CacheFile
Indicates the tag originated from a Blam Cache File (.map).
Definition: tags.h:22
tag_block::entry_data_address
void * entry_data_address
The address of the blocks' entry data.
Definition: tags.h:82
tag_memory_data::size
int size
The size of the tag's data in memory.
Definition: tags.h:32
tag_block::block_identifier
char block_identifier[6]
Special variable that is used for saving tag data to a file from within the engine....
Definition: tags.h:80
WSV_ERROR
#define WSV_ERROR
Macro for 'Error' log seveirty. Original pre-enum value was 2.
Definition: logger.h:17
TagOrigin
TagOrigin
Enum used to specify a tag's origin.
Definition: tags.h:17
tag_block::entry_size
int entry_size
The size of each block entry.
Definition: tags.h:81
tag_reference::tag_path
char tag_path[256]
The path to the tag file. Used for initial tag loading.
Definition: tags.h:91
tag_memory_data::origin
TagOrigin origin
The origin of the tag.
Definition: tags.h:46
Memory
@ Memory
Indicates the tag originated from the engine's memory.
Definition: tags.h:20
tag_reference
Structure representing a tag reference.
Definition: tags.h:89
WSV_NONE
#define WSV_NONE
Macro for 'None' log seveirty. Original pre-enum value was 0.
Definition: logger.h:15
Blam::Content::Tags::RegisterCreatedTag
BLAM std::string RegisterCreatedTag(void *tag, std::string tag_class)
Definition: tags.cpp:45
tag_memory_data
Class representing a tag's data.
Definition: tags.h:28
Blam::Content::Tags::GetLoadedTags
BLAM std::vector< tag_memory_data > * GetLoadedTags()
Retrieves the list of loaded tag data.
Definition: tags.cpp:507
tag_memory_data::SetTagPath
bool SetTagPath(std::string new_path)
Updates the tag path.
Definition: tags.h:55
Blam::Content::Tags::CleanupTagData
BLAM void CleanupTagData()
Definition: tags.cpp:499
Blam::Content::Tags::ShowImPropertyEditor
BLAM void ShowImPropertyEditor(void *tag, std::string tag_class)
Shows an ImGUI editor for a given tag.
Definition: tags.cpp:21
BLAM
#define BLAM
Definition: tags.h:11
Blam::Logger::TagDebug
@ TagDebug
Report file for all tag related messages.
Definition: logger.h:80
Blam::Content::Tags::GetTagData
BLAM tag_memory_data * GetTagData(std::string tag_path)
Retrieves information for a given tag.
Definition: tags.cpp:486
XMLFile
@ XMLFile
Indicates the tag originated from an XML file. Currently unsupported.
Definition: tags.h:21
tag_reference::tag_reference
tag_reference()
Definition: tags.h:94
Blam::Content::Tags::SaveTag
BLAM HRESULT SaveTag(void *tag_data, std::string tag_class, int tag_size, std::string tag_path)
Saves a tag data to a file.
Definition: tags.cpp:381
tag_block::entry_count
int entry_count
The number of entries within the tag block.
Definition: tags.h:83
BinaryFile
@ BinaryFile
Indicates the tag originated from a binary file.
Definition: tags.h:19
tag_memory_data::path
char path[256]
The tag's path.
Definition: tags.h:44