#ifndef TC_ENTITY_H #define TC_ENTITY_H #include "utility/location.h" #include "utility/utility.h" typedef struct tc_interval tc_interval_s; 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_entity_pool tc_entity_pool_s; typedef struct tc_entity_pool_entry tc_entity_pool_entry_s; typedef struct tc_entity_registry tc_entity_registry_s; typedef struct { void (*fn_create) (tc_entity_s *entity); void (*fn_spawn) (tc_entity_s *entity, tc_location_s location); void (*fn_teleport) (tc_entity_s *entity, tc_location_s location); void (*fn_draw) (tc_entity_s *entity); 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 *identifier; union { void *pointer; char *string; i64_t integer; f64_t floating; } value; }; struct tc_entity_type { char *internal_name; char *display_name; tc_fn_entity_s functions; u32_t instances_capacity; u32_t num_instances; tc_entity_s **instances; }; struct tc_entity_attribute { char *name; u32_t index; union { void *pointer; char *string; i64_t integer; f64_t floating; } value; }; struct tc_entity { tc_entity_pool_entry_s *pool_entry; tc_location_s location; tc_entity_type_s *type; u16_t attributes_capacity; u16_t num_attributes; tc_entity_attribute_s *attributes; void *specific; }; struct tc_interval { u64_t last_invocation; u64_t wanted_delta; tc_entity_s *entity; void (*fn_interval) (tc_entity_s *entity); }; 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; }; struct tc_entity_registry { u32_t types_capacity; u32_t num_types; tc_entity_type_s *types; tc_entity_pool_s *pool; u32_t intervals_capacity; u32_t num_intervals; tc_interval_s *intervals; }; tc_entity_pool_s * tc_create_entity_pool (u32_t capacity); tc_entity_registry_s tc_init_entity_registry (); void tc_register_entity_type (tc_entity_type_s type); tc_entity_type_s * tc_get_entity_type_with_name (char *name); 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); void tc_draw_entity (tc_entity_s *entity); void tc_delete_entity (tc_entity_s *entity); 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, i64_t integer); void tc_set_float_for_entity (tc_entity_s *entity, char *attr_name, f64_t 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); 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); 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, i64_t integer); void tc_send_float_to_entity (tc_entity_s *entity, char *event_name, f64_t floating); 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); tc_entity_s * tc_allocate_entity (); void tc_deallocate_entity (tc_entity_s *entity); #endif // TC_ENTITY_H