#ifndef TC_ENTITY_H #define TC_ENTITY_H #include #include 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 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); typedef struct { tc_entity_create_fn fn_create; tc_entity_delete_fn fn_delete; tc_entity_send_event_fn fn_send_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_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 *userdata); 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