2024-02-20 06:35:53 +00:00
|
|
|
|
|
|
|
#ifndef MT_SHADOW_TAG_H
|
|
|
|
#define MT_SHADOW_TAG_H
|
|
|
|
|
2024-03-03 19:28:59 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <alphaumlaut/maths.h>
|
2024-02-20 06:35:53 +00:00
|
|
|
#include <entity.h>
|
|
|
|
|
|
|
|
typedef struct MtShadowTag MtShadowTag;
|
|
|
|
typedef struct MtShadowTagPool MtShadowTagPool;
|
|
|
|
typedef struct MtShadowTagName MtShadowTagName;
|
|
|
|
typedef struct MtShadowTagNameArena MtShadowTagNameArena;
|
|
|
|
typedef struct MtShadowTagNameRegistry MtShadowTagNameRegistry;
|
|
|
|
typedef struct MtShadowTagSystem MtShadowTagSystem;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
MT_SHADOW_TAG_INTEGER,
|
|
|
|
MT_SHADOW_TAG_BOOLEAN,
|
|
|
|
MT_SHADOW_TAG_DECIMAL,
|
|
|
|
MT_SHADOW_TAG_STRING,
|
|
|
|
MT_SHADOW_TAG_RAW_POINTER,
|
|
|
|
MT_SHADOW_TAG_VECTOR_2,
|
|
|
|
MT_SHADOW_TAG_VECTOR_3,
|
|
|
|
MT_SHADOW_TAG_VECTOR_4,
|
|
|
|
MT_SHADOW_TAG_SUB_ENTITY,
|
|
|
|
MT_SHADOW_TAG_RESOURCE
|
|
|
|
|
|
|
|
} MtShadowTagType;
|
|
|
|
|
|
|
|
struct MtShadowTag
|
|
|
|
{
|
|
|
|
MtShadowTagPool *pool;
|
|
|
|
MtShadowTag *next;
|
|
|
|
|
|
|
|
MtShadowTagType type;
|
2024-03-03 19:28:59 +00:00
|
|
|
uint32_t name_identifier;
|
2024-02-20 06:35:53 +00:00
|
|
|
union MtShadowTagData
|
|
|
|
{
|
2024-03-03 19:28:59 +00:00
|
|
|
bool boolean;
|
|
|
|
int64_t integer;
|
|
|
|
double decimal;
|
2024-02-20 06:35:53 +00:00
|
|
|
char *string;
|
|
|
|
void *raw_pointer;
|
2024-03-03 19:28:59 +00:00
|
|
|
AuVec2f vec2f;
|
|
|
|
AuVec3f vec3f;
|
|
|
|
AuVec4f vec4f;
|
2024-02-20 06:35:53 +00:00
|
|
|
MtEntity entity;
|
|
|
|
} data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtShadowTagPool
|
|
|
|
{
|
2024-03-03 19:28:59 +00:00
|
|
|
uint32_t capacity;
|
2024-02-20 06:35:53 +00:00
|
|
|
MtShadowTag *allocation;
|
|
|
|
MtShadowTag *first_free;
|
|
|
|
MtShadowTagPool *continuation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtShadowTagNameArena
|
|
|
|
{
|
2024-03-03 19:28:59 +00:00
|
|
|
uint32_t capacity;
|
|
|
|
uint32_t usage;
|
2024-02-20 06:35:53 +00:00
|
|
|
char *allocation;
|
|
|
|
MtShadowTagNameArena *continuation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtShadowTagName
|
|
|
|
{
|
|
|
|
char *string_in_arena;
|
2024-03-03 19:28:59 +00:00
|
|
|
uint32_t identifier;
|
2024-02-20 06:35:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MtShadowTagNameRegistry
|
|
|
|
{
|
2024-03-03 19:28:59 +00:00
|
|
|
uint32_t names_capacity;
|
|
|
|
uint32_t num_names;
|
2024-02-20 06:35:53 +00:00
|
|
|
MtShadowTagName *names;
|
2024-03-03 19:28:59 +00:00
|
|
|
uint32_t id_counter;
|
2024-02-20 06:35:53 +00:00
|
|
|
|
|
|
|
MtShadowTagNameArena *root_arena;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtShadowTagSystem
|
|
|
|
{
|
|
|
|
MtShadowTagNameRegistry name_registry;
|
|
|
|
MtShadowTagPool root_pool;
|
|
|
|
};
|
|
|
|
|
|
|
|
void mt_init_shadow_tag_system(MtShadowTagSystem *tag_system);
|
|
|
|
void mt_cleanup_shadow_tag_system(MtShadowTagSystem *tag_system);
|
|
|
|
|
2024-03-03 19:28:59 +00:00
|
|
|
MtShadowTagPool * mt_new_shadow_tag_pool(uint32_t capacity);
|
2024-02-20 06:35:53 +00:00
|
|
|
|
|
|
|
/// @brief Crates a new MtShadowTagPool with a given capacity.
|
|
|
|
/// @warning Don't use `mt_free_shadow_tag_pool()` with use created with this method.
|
|
|
|
/// It will result in a call to `free()` for the given pool, which may cause a crash.
|
|
|
|
/// @param pool A pointer to the location at which the pool should be created.
|
|
|
|
/// @param capacity The number of entity shadow tags which should be able to reside in
|
|
|
|
/// the first instance of the pool. The pool will allocate more once needed.
|
2024-03-03 19:28:59 +00:00
|
|
|
void mt_init_shadow_tag_pool(MtShadowTagPool *pool, uint32_t capacity);
|
2024-02-20 06:35:53 +00:00
|
|
|
void mt_free_shadow_tag_pool(MtShadowTagPool *pool);
|
|
|
|
|
|
|
|
MtShadowTag * mt_alloc_shadow_tag(void *context_ptr);
|
|
|
|
MtShadowTag * mt_alloc_shadow_tag_in_pool(MtShadowTagPool *pool);
|
|
|
|
|
|
|
|
/// @brief Crates as new MtShadowTag, makes it the new first of the chain given as input and
|
|
|
|
/// returns the new chain start. The chain start should be set to the returned value
|
|
|
|
/// @param chain_start The current start of the singly linked list of tags which are
|
|
|
|
/// attached to a shadow (the start of the tag chain).
|
|
|
|
/// @return The new tag chain's start.
|
|
|
|
MtShadowTag * mt_alloc_shadow_tag_before(MtShadowTag *chain_start);
|
|
|
|
void mt_free_shadow_tag_chain(MtShadowTag *tag);
|
|
|
|
|
2024-03-03 19:28:59 +00:00
|
|
|
uint32_t mt_tag_name_to_id(void *context_ptr, const char *tag_name);
|
2024-02-20 06:35:53 +00:00
|
|
|
|
|
|
|
#endif // MT_SHADOW_TAG_H
|