Techneck/code/source-c/entity.h

134 lines
5.3 KiB
C

#ifndef TC_ENTITY_H
#define TC_ENTITY_H
#include "location.h"
#include "utility.h"
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;
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);
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 *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;
double floating;
} 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;
};
struct tc_interval
{
uint64_t last_invocation;
uint64_t wanted_delta;
tc_entity_s *entity;
void (*fn_interval) (tc_entity_s *entity);
};
struct tc_entity_registry
{
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;
uint32_t intervals_capacity;
uint32_t num_intervals;
tc_interval_s *intervals;
};
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, 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);
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);
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