pxl8/demo3d/client/world/demo3d_entity.h

67 lines
3.2 KiB
C

#pragma once
#include "pxl8_types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct demo3d_entity_pool demo3d_entity_pool;
typedef struct demo3d_entity {
u32 idx;
u32 gen;
} demo3d_entity;
#define DEMO3D_ENTITY_INVALID ((demo3d_entity){0, 0})
typedef u32 demo3d_entity_component;
typedef u32 demo3d_entity_relationship;
#define DEMO3D_ENTITY_COMPONENT_INVALID 0
#define DEMO3D_ENTITY_RELATIONSHIP_INVALID 0
demo3d_entity_pool* demo3d_entity_pool_create(u32 capacity);
void demo3d_entity_pool_clear(demo3d_entity_pool* pool);
void demo3d_entity_pool_destroy(demo3d_entity_pool* pool);
demo3d_entity demo3d_entity_spawn(demo3d_entity_pool* pool);
void demo3d_entity_despawn(demo3d_entity_pool* pool, demo3d_entity e);
bool demo3d_entity_alive(const demo3d_entity_pool* pool, demo3d_entity e);
u32 demo3d_entity_count(const demo3d_entity_pool* pool);
demo3d_entity_component demo3d_entity_component_register(demo3d_entity_pool* pool, const char* name, u32 size);
demo3d_entity_component demo3d_entity_component_find(const demo3d_entity_pool* pool, const char* name);
const char* demo3d_entity_component_name(const demo3d_entity_pool* pool, demo3d_entity_component comp);
void* demo3d_entity_component_add(demo3d_entity_pool* pool, demo3d_entity e, demo3d_entity_component comp);
void* demo3d_entity_component_get(const demo3d_entity_pool* pool, demo3d_entity e, demo3d_entity_component comp);
void demo3d_entity_component_remove(demo3d_entity_pool* pool, demo3d_entity e, demo3d_entity_component comp);
bool demo3d_entity_component_has(const demo3d_entity_pool* pool, demo3d_entity e, demo3d_entity_component comp);
demo3d_entity_relationship demo3d_entity_relationship_register(demo3d_entity_pool* pool, const char* name);
demo3d_entity_relationship demo3d_entity_relationship_find(const demo3d_entity_pool* pool, const char* name);
const char* demo3d_entity_relationship_name(const demo3d_entity_pool* pool, demo3d_entity_relationship rel);
void demo3d_entity_relationship_add(demo3d_entity_pool* pool, demo3d_entity subject, demo3d_entity_relationship rel, demo3d_entity object);
void demo3d_entity_relationship_remove(demo3d_entity_pool* pool, demo3d_entity subject, demo3d_entity_relationship rel, demo3d_entity object);
bool demo3d_entity_relationship_has(const demo3d_entity_pool* pool, demo3d_entity subject, demo3d_entity_relationship rel, demo3d_entity object);
u32 demo3d_entity_relationship_subjects(const demo3d_entity_pool* pool, demo3d_entity object, demo3d_entity_relationship rel, demo3d_entity* out, u32 max);
u32 demo3d_entity_relationship_objects(const demo3d_entity_pool* pool, demo3d_entity subject, demo3d_entity_relationship rel, demo3d_entity* out, u32 max);
typedef void (*demo3d_entity_each_fn)(demo3d_entity_pool* pool, demo3d_entity e, void* ctx);
void demo3d_entity_each(demo3d_entity_pool* pool, demo3d_entity_component comp, demo3d_entity_each_fn fn, void* ctx);
void demo3d_entity_each_with(demo3d_entity_pool* pool, const demo3d_entity_component* comps, u32 count, demo3d_entity_each_fn fn, void* ctx);
static inline bool demo3d_entity_valid(demo3d_entity e) {
return e.idx != 0 || e.gen != 0;
}
static inline bool demo3d_entity_eq(demo3d_entity a, demo3d_entity b) {
return a.idx == b.idx && a.gen == b.gen;
}
#ifdef __cplusplus
}
#endif