power_play/src/entity.h
2024-03-08 17:39:07 -06:00

108 lines
2.5 KiB
C

#ifndef ENTITY_H
#define ENTITY_H
#include "sheet.h"
#include "mixer.h"
/* ========================== *
* Entity
* ========================== */
struct entity_handle {
u64 idx;
u64 gen;
};
enum entity_prop {
ENTITY_PROP_NONE,
ENTITY_PROP_ANIMATING,
ENTITY_PROP_PLAYER_CONTROLLED,
ENTITY_PROP_CAMERA,
/* Test props */
ENTITY_PROP_TEST,
ENTITY_PROP_TEST_FOLLOW_MOUSE,
ENTITY_PROP_TEST_SOUND_EMITTER,
ENTITY_PROP_COUNT
};
struct entity {
b32 valid;
struct entity_handle handle;
u64 continuity_gen;
u64 props[(ENTITY_PROP_COUNT + 63) / 64];
struct entity *next_free;
/* Tree */
struct entity_handle parent;
struct entity_handle next;
struct entity_handle prev;
struct entity_handle first;
struct entity_handle last;
/* ====================================================================== */
/* Translation, rotation, scale in relation to parent entity */
struct xform rel_xform;
struct xform world_xform; /* Calculated post-physics */
/* ====================================================================== */
/* Physics */
struct v2 acceleration;
struct v2 velocity;
/* ENTITY_PROP_PLAYER_CONTROLLED */
f32 player_max_speed;
f32 player_acceleration;
/* ====================================================================== */
/* Sprite */
struct xform sprite_xform;
struct string sprite_name;
struct string sprite_tag_name;
u32 sprite_tint;
/* ====================================================================== */
/* Animation */
/* ENTITY_PROP_ANIMATING */
b32 animation_looping;
f64 animation_start_time; /* Calculated */
/* ====================================================================== */
/* Testing */
/* ENTITY_PROP_TEST */
b32 test_initialized;
struct xform test_start_rel_xform;
struct xform test_start_sprite_xform;
/* ENTITY_PROP_TEST_SOUND_EMITTER */
struct string sound_name;
struct mixer_desc sound_desc;
struct mixer_track_handle sound_handle;
/* ====================================================================== */
/* ENTITY_PROP_CAMERA */
b32 camera_active;
struct entity_handle camera_follow;
f32 camera_zoom;
};
DECLARE_NIL_STRUCT(struct entity, entity_nil);
/* Prop */
void entity_enable_prop(struct entity *entity, enum entity_prop prop);
void entity_disable_prop(struct entity *entity, enum entity_prop prop);
b32 entity_has_prop(struct entity *entity, enum entity_prop prop);
#endif