Techneck/code/source-c/entity.h

154 lines
5.5 KiB
C
Raw Normal View History

2023-10-14 13:04:52 +00:00
#ifndef TC_ENTITY_H
#define TC_ENTITY_H
#include "utility/location.h"
#include "utility/utility.h"
2023-10-14 13:04:52 +00:00
2023-10-15 09:51:45 +00:00
typedef struct tc_interval tc_interval_s;
2023-10-14 19:17:30 +00:00
typedef struct tc_entity_event tc_entity_event_s;
typedef struct tc_entity_type tc_entity_type_s;
typedef struct tc_entity_attribute tc_entity_attribute_s;
typedef struct tc_entity tc_entity_s;
2023-10-15 09:51:45 +00:00
typedef struct tc_entity_pool tc_entity_pool_s;
typedef struct tc_entity_pool_entry tc_entity_pool_entry_s;
2023-10-14 19:17:30 +00:00
typedef struct tc_entity_registry tc_entity_registry_s;
2023-10-14 13:04:52 +00:00
2023-10-17 11:25:02 +00:00
typedef void (*tc_entity_create_fn) (tc_entity_s *entity, void *userdata);
typedef void (*tc_entity_delete_fn) (tc_entity_s *entity);
typedef void (*tc_entity_send_event_fn) (tc_entity_s *entity, tc_entity_event_s event);
2023-10-14 13:04:52 +00:00
typedef struct
{
2023-10-17 11:25:02 +00:00
tc_entity_create_fn fn_create;
tc_entity_delete_fn fn_delete;
tc_entity_send_event_fn fn_send_event;
2023-10-14 13:04:52 +00:00
} tc_fn_entity_s;
struct tc_entity_event
{
2023-10-15 09:51:45 +00:00
char *identifier;
2023-10-14 13:04:52 +00:00
union
{
void *pointer;
char *string;
2023-10-15 09:51:45 +00:00
i64_t integer;
f64_t floating;
2023-10-14 13:04:52 +00:00
} value;
};
struct tc_entity_type
{
char *internal_name;
char *display_name;
tc_fn_entity_s functions;
2023-10-15 09:51:45 +00:00
u32_t instances_capacity;
u32_t num_instances;
tc_entity_s **instances;
2023-10-14 13:04:52 +00:00
};
struct tc_entity_attribute
{
char *name;
2023-10-15 09:51:45 +00:00
u32_t index;
2023-10-14 13:04:52 +00:00
union
{
void *pointer;
char *string;
2023-10-15 09:51:45 +00:00
i64_t integer;
f64_t floating;
2023-10-14 13:04:52 +00:00
} value;
};
struct tc_entity
{
2023-10-15 09:51:45 +00:00
tc_entity_pool_entry_s *pool_entry;
2023-10-14 13:04:52 +00:00
tc_entity_type_s *type;
2023-10-15 09:51:45 +00:00
u16_t attributes_capacity;
u16_t num_attributes;
2023-10-14 13:04:52 +00:00
tc_entity_attribute_s *attributes;
void *specific;
};
2023-10-14 19:17:30 +00:00
struct tc_interval
{
2023-10-15 09:51:45 +00:00
u64_t last_invocation;
u64_t wanted_delta;
2023-10-14 19:17:30 +00:00
tc_entity_s *entity;
void (*fn_interval) (tc_entity_s *entity);
};
2023-10-15 09:51:45 +00:00
struct tc_entity_pool_entry
{
tc_entity_pool_entry_s *next;
tc_entity_pool_entry_s *previous;
tc_entity_s entity;
};
struct tc_entity_pool
{
u32_t entities_capacity;
tc_entity_pool_entry_s *entities;
tc_entity_pool_entry_s *first_free;
tc_entity_pool_s *continuation;
};
2023-10-14 13:04:52 +00:00
struct tc_entity_registry
{
2023-10-15 09:51:45 +00:00
u32_t types_capacity;
u32_t num_types;
tc_entity_type_s *types;
2023-10-14 19:17:30 +00:00
2023-10-15 09:51:45 +00:00
tc_entity_pool_s *pool;
2023-10-14 13:04:52 +00:00
2023-10-15 09:51:45 +00:00
u32_t intervals_capacity;
u32_t num_intervals;
tc_interval_s *intervals;
2023-10-14 13:04:52 +00:00
};
2023-10-15 09:51:45 +00:00
tc_entity_pool_s * tc_create_entity_pool (u32_t capacity);
2023-10-14 13:04:52 +00:00
tc_entity_registry_s tc_init_entity_registry ();
void tc_register_entity_type (tc_entity_type_s type);
2023-10-14 14:48:09 +00:00
tc_entity_type_s * tc_get_entity_type_with_name (char *name);
2023-10-14 13:04:52 +00:00
2023-10-15 12:41:53 +00:00
tc_entity_s * tc_create_entity (char *type, void *userdata);
2023-10-14 13:04:52 +00:00
void tc_delete_entity (tc_entity_s *entity);
2023-10-14 14:38:38 +00:00
void tc_set_pointer_for_entity (tc_entity_s *entity, char *attr_name, void *pointer);
void tc_set_string_for_entity (tc_entity_s *entity, char *attr_name, char *string);
2023-10-15 09:51:45 +00:00
void tc_set_integer_for_entity (tc_entity_s *entity, char *attr_name, i64_t integer);
void tc_set_float_for_entity (tc_entity_s *entity, char *attr_name, f64_t floating);
2023-10-14 14:38:38 +00:00
void * tc_get_pointer_from_entity (tc_entity_s *entity, char *attr_name);
char * tc_get_string_from_entity (tc_entity_s *entity, char *attr_name);
2023-10-15 09:51:45 +00:00
i64_t tc_get_integer_from_entity (tc_entity_s *entity, char *attr_name);
f64_t tc_get_float_from_entity (tc_entity_s *entity, char *attr_name);
2023-10-14 14:38:38 +00:00
2023-10-14 13:04:52 +00:00
void tc_send_pointer_to_entity (tc_entity_s *entity, char *event_name, void *pointer);
void tc_send_string_to_entity (tc_entity_s *entity, char *event_name, char *string);
2023-10-15 09:51:45 +00:00
void tc_send_integer_to_entity (tc_entity_s *entity, char *event_name, i64_t integer);
void tc_send_float_to_entity (tc_entity_s *entity, char *event_name, f64_t floating);
2023-10-14 13:04:52 +00:00
2023-10-14 19:17:30 +00:00
void tc_schedule_interval (tc_entity_s *entity, float wanted_delta, void (*fn_interval)(tc_entity_s *entity));
void tc_tick_intervals ();
void tc_draw_all_entities_of_type (char *name);
2023-10-14 13:04:52 +00:00
tc_entity_s * tc_allocate_entity ();
void tc_deallocate_entity (tc_entity_s *entity);
#endif // TC_ENTITY_H