2023-10-14 13:04:52 +00:00
|
|
|
|
|
|
|
#ifndef TC_ENTITY_H
|
|
|
|
#define TC_ENTITY_H
|
|
|
|
|
2023-10-15 08:07:33 +00:00
|
|
|
#include "utility/location.h"
|
|
|
|
#include "utility/utility.h"
|
2023-10-14 13:04:52 +00:00
|
|
|
|
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;
|
|
|
|
typedef struct tc_interval tc_interval_s;
|
|
|
|
typedef struct tc_entity_registry tc_entity_registry_s;
|
2023-10-14 13:04:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
tc_entity_s * (*fn_create) ();
|
|
|
|
void (*fn_spawn) (tc_entity_s *entity, tc_location_s location);
|
|
|
|
void (*fn_teleport) (tc_entity_s *entity, tc_location_s location);
|
2023-10-14 19:17:30 +00:00
|
|
|
void (*fn_draw) (tc_entity_s *entity);
|
2023-10-14 13:04:52 +00:00
|
|
|
void (*fn_delete) (tc_entity_s *entity);
|
|
|
|
void (*fn_send_event) (tc_entity_s *entity, tc_entity_event_s event);
|
|
|
|
|
|
|
|
} tc_fn_entity_s;
|
|
|
|
|
|
|
|
struct tc_entity_event
|
|
|
|
{
|
|
|
|
char *event_type;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
void *pointer;
|
|
|
|
char *string;
|
|
|
|
int64_t integer;
|
|
|
|
double floating;
|
|
|
|
} value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tc_entity_type
|
|
|
|
{
|
|
|
|
char *internal_name;
|
|
|
|
char *display_name;
|
|
|
|
|
|
|
|
tc_fn_entity_s functions;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tc_entity_attribute
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
uint32_t index;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
void *pointer;
|
|
|
|
char *string;
|
|
|
|
int64_t integer;
|
2023-10-14 14:38:38 +00:00
|
|
|
double floating;
|
2023-10-14 13:04:52 +00:00
|
|
|
} value;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tc_entity
|
|
|
|
{
|
|
|
|
tc_location_s location;
|
|
|
|
tc_entity_type_s *type;
|
|
|
|
|
|
|
|
uint16_t attributes_capacity;
|
|
|
|
uint16_t num_attributes;
|
|
|
|
tc_entity_attribute_s *attributes;
|
|
|
|
|
|
|
|
void *specific;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-10-14 19:17:30 +00:00
|
|
|
struct tc_interval
|
|
|
|
{
|
|
|
|
uint64_t last_invocation;
|
|
|
|
uint64_t wanted_delta;
|
|
|
|
tc_entity_s *entity;
|
|
|
|
void (*fn_interval) (tc_entity_s *entity);
|
|
|
|
};
|
|
|
|
|
2023-10-14 13:04:52 +00:00
|
|
|
struct tc_entity_registry
|
|
|
|
{
|
2023-10-14 19:17:30 +00:00
|
|
|
uint32_t types_capacity;
|
|
|
|
uint32_t num_types;
|
|
|
|
tc_entity_type_s *types;
|
|
|
|
|
|
|
|
uint32_t entities_capacity;
|
|
|
|
uint32_t num_entities;
|
|
|
|
tc_entity_s **entities;
|
2023-10-14 13:04:52 +00:00
|
|
|
|
2023-10-14 19:17:30 +00:00
|
|
|
uint32_t intervals_capacity;
|
|
|
|
uint32_t num_intervals;
|
|
|
|
tc_interval_s *intervals;
|
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
|
|
|
|
|
|
|
tc_entity_s * tc_create_entity (char *type);
|
|
|
|
void tc_spawn_entity (tc_entity_s *entity, tc_location_s location);
|
|
|
|
void tc_teleport_entity (tc_entity_s *entity, tc_location_s location);
|
2023-10-14 19:17:30 +00:00
|
|
|
void tc_draw_entity (tc_entity_s *entity);
|
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);
|
|
|
|
void tc_set_integer_for_entity (tc_entity_s *entity, char *attr_name, int64_t integer);
|
|
|
|
void tc_set_float_for_entity (tc_entity_s *entity, char *attr_name, double floating);
|
|
|
|
|
|
|
|
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);
|
|
|
|
int64_t tc_get_integer_from_entity (tc_entity_s *entity, char *attr_name);
|
|
|
|
double tc_get_float_from_entity (tc_entity_s *entity, char *attr_name);
|
|
|
|
|
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);
|
|
|
|
void tc_send_integer_to_entity (tc_entity_s *entity, char *event_name, int64_t integer);
|
|
|
|
void tc_send_float_to_entity (tc_entity_s *entity, char *event_name, double floating);
|
|
|
|
|
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
|
|
|
|
|