diff options
| author | tech kaczynski <tk@techkaczynski.dev> | 2026-09-22 22:38:57 +1000 |
|---|---|---|
| committer | tech kaczynski <tk@techkaczynski.dev> | 2026-09-22 22:38:57 +1000 |
| commit | 08cb8d6a585dd552b69a488d9db1be123f01467a (patch) | |
| tree | 77d50ce30bbc102b08486929ba654b5bef70af43 /ent.h | |
initial commit.
Diffstat (limited to 'ent.h')
| -rw-r--r-- | ent.h | 96 |
1 files changed, 96 insertions, 0 deletions
@@ -0,0 +1,96 @@ +#ifndef ENT_H +#define ENT_H + +#include "common.h" +#include "physics.h" + +#define ENTITY_INVALID_IDX UINT32_MAX + +// typedef enum { +// ENT_COMP_TRANSFORM, +// ENT_COMP_MODEL, +// ENT_COMP_PHYSICS, +// ENT_COMP_EDITOR, +// ENT_COMP_CNT, +// } EntityComponentType; + +typedef struct { + u64 parent; + u64 first_child; + u64 prev, next; // siblings + /* parent-local */ + Vec3 pos, scale; + Quaternion rot; +} TransformCmp; + +typedef struct { + char *key; + Model *mdl; + bool has, draw; +} ModelCmp; + +typedef struct { + PhysicsBody *bodies; + PhysicsJoint *joints; + u32 body_cnt, joint_cnt; + + struct { + PhysicsBodyRuntime *bodies; + b3JointId *joints; + } runtime; + + bool has, debug_draw; +} PhysicsCmp; + +typedef struct { + bool selected; +} EditorCmp; // transient data for non transient entities ^___^ + +typedef struct { + TransformCmp tr; + ModelCmp mdl; + PhysicsCmp phys; + EditorCmp ed; + + u64 pid; // persistent serialized id, not runtime entity id + char *name; +} Entity; + +void entity_system_init(void); +void entity_system_exit(void); +void entity_system_clear(void); +void entity_system_update(void); +void entity_system_draw_3d(void); +void entity_system_set_next_pid(u64); + +/* clears all entities of their selected flag */ +void entities_clear_selected(void); + +u64 entity_create(bool transient); // transient means no pid +u64 entity_restore(u64 pid); +void entity_delete(u64 id); +void entity_clean(Entity*); // clean entity data without removing +Entity entity_extract_now(u64 id); // removes, returns ownership +bool entity_valid(u64 id); + +Entity* entity_get(u64 id); +u64 entity_id_at(u32 dense_idx); +u64 entity_id_from_pid(u64 pid); +Entity* entity_data(void); +u32 entity_count(void); +u64 entity_next_pid(void); + +bool entity_set_parent(u64 id, u64 parent_id); + +/* transform component data */ +Matrix entity_world_matrix(u64 id); +/* space identifies the reference entity, 0 means world space. */ +Vec3 entity_point_to_world(u64 space, Vec3 point); +bool entity_point_to_local(u64 space, Vec3 point, Vec3 *out); + +Vec3 entity_world_pos(u64 id); +Quaternion entity_world_rot(u64 id); +void entity_set_world_pos(Entity*, Vec3); +void entity_set_world_rot(Entity*, Quaternion); + +#endif |
