#ifndef THING_H
#define THING_H
#include "cglm/cglm.h"
#define MAX_THING_TYPES 16
#define MAX_THINGS 1024
#define MAX_FIELDS 8
typedef enum {
COLLISION_NONE,
COLLISION_SPHERE,
COLLISION_BOX,
} CollisionShapeType;
#define DEFINE_FIELDS(name, ...) \
FieldDef name[] = { __VA_ARGS__ }; \
enum { name##_count = sizeof(name) / sizeof(FieldDef) }
#define DEFINE_THING_TYPE(var_name, type_name_str, field_array, update_fn, render_fn, physics_fn) \
ThingTypeDef var_name = { \
.name = type_name_str, \
.fields = field_array, \
.field_count = field_array##_count, \
.update = update_fn, \
.render = render_fn, \
.physics = physics_fn \
}
typedef int ThingID;
typedef int ThingTypeID;
typedef struct {
ThingTypeID type_id;
int index;
int alive;
} ThingInfo;
extern ThingInfo g_things[MAX_THINGS];
typedef enum {
FIELD_INT,
FIELD_FLOAT,
FIELD_VEC3,
FIELD_STRING
} FieldType;
typedef struct {
const char* name;
FieldType type;
} FieldDef;
typedef struct {
const char* name;
FieldDef* fields;
int field_count;
void (*update)(ThingID id);
void (*render)(ThingID id);
void (*physics)(ThingID id);
} ThingTypeDef;
ThingTypeID thing_register_type(ThingTypeDef* def);
ThingID thing_spawn(ThingTypeID type_id);
int thing_has_field(ThingID id, const char* field_name);
void thing_destroy(ThingID id);
void thing_clear_all();
float thing_get_float(ThingID id, const char* name);
int thing_get_int(ThingID id, const char* name);
void thing_get_vec3(ThingID id, const char* name, vec3 out);
const char* thing_get_string(ThingID id, const char* name);
void thing_set_float(ThingID id, const char* name, float f);
void thing_set_int(ThingID id, const char* name, int i);
void thing_set_vec3(ThingID id, const char* name, vec3 in);
void thing_set_string(ThingID id, const char* name, const char* s);
void thing_update_all();
void thing_render_all();
void thing_physics_all();
int thing_type_has_physics(ThingTypeID type_id, void (*physics_cb)(ThingID));
#endif