128 lines
3.0 KiB
C
128 lines
3.0 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_SPRITE_ANIMATED,
|
|
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 trs rel_trs;
|
|
|
|
struct mat3x3 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 string sprite_name;
|
|
struct trs sprite_trs;
|
|
struct v2 sprite_pivot_norm; /* Pivot x & y are each normalized about sprite dimensions. <0, 0> is center, <1, 1> is bottom right corner, etc. */
|
|
u32 sprite_tint;
|
|
|
|
/* ====================================================================== */
|
|
/* Animation */
|
|
|
|
/* ENTITY_PROP_SPRITE_ANIMATED */
|
|
struct string animation_name;
|
|
u64 animation_flags;
|
|
f64 animation_time_in_frame;
|
|
u64 animation_start_gen;
|
|
u64 animation_gen;
|
|
struct sheet_frame animation_frame;
|
|
|
|
/* ====================================================================== */
|
|
/* Testing */
|
|
|
|
/* ENTITY_PROP_TEST */
|
|
b32 test_initialized;
|
|
struct trs test_start_rel_trs;
|
|
struct trs test_start_sprite_trs;
|
|
|
|
/* 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_rot;
|
|
f32 camera_zoom;
|
|
};
|
|
|
|
/* Nil entity */
|
|
|
|
extern READONLY struct entity _g_entity_nil;
|
|
|
|
INLINE READONLY struct entity *entity_nil(void)
|
|
{
|
|
return &_g_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);
|
|
|
|
/* Animation */
|
|
|
|
#define ANIMATION_FLAG_NONE 0x0
|
|
#define ANIMATION_FLAG_LOOPING 0x1
|
|
|
|
void entity_start_animation(struct entity *entity, struct string animation_name, u64 flags);
|
|
|
|
#endif
|