151 lines
3.8 KiB
C
151 lines
3.8 KiB
C
#ifndef __MAZE_ECSTYPES
|
|
#define __MAZE_ECSTYPES
|
|
|
|
#include "ecs2.h"
|
|
#include "haloo3d/haloo3d.h"
|
|
#include "haloo3d/haloo3dex_easy.h"
|
|
|
|
// Turning into a blob? IDK. Maybe certain things should be
|
|
// global state, which is this.
|
|
typedef struct {
|
|
uint8_t state;
|
|
uint8_t *maze;
|
|
int size; // The length of an edge, guaranteed to be a square
|
|
// A suggested start and end. The end is the actual
|
|
// end, where we put the ending indicator
|
|
struct vec2i start;
|
|
struct vec2i end;
|
|
// Some simple calcs for you to use
|
|
mfloat_t cellsize;
|
|
} worldstate;
|
|
|
|
// A component that stores a position and a facing direction
|
|
// as an angle
|
|
typedef struct {
|
|
struct vec3 pos;
|
|
struct vec2 rot; // x is yaw, y is pitch
|
|
} ecs_placement;
|
|
|
|
typedef haloo3d_camera *ecs_camera;
|
|
typedef haloo3d_obj_instance *ecs_object;
|
|
|
|
// A component which allows automatic navigation
|
|
// of position through the use of timers.
|
|
typedef struct {
|
|
struct vec3 dest;
|
|
int timer;
|
|
} ecs_autonav;
|
|
|
|
// A component which allows automatic rotation
|
|
// through the use of timers.
|
|
typedef struct {
|
|
struct vec2 dest; // x is yaw, y is pitch
|
|
int timer;
|
|
} ecs_autorotate;
|
|
|
|
// Component which enables synchronized scale y from 0 to 1 or 1 to 0. It is
|
|
// expected that an external source is modifying the value
|
|
typedef struct {
|
|
haloo3d_obj_instance *obj;
|
|
mfloat_t *scale;
|
|
// When scales are set, they're multiplied by this
|
|
mfloat_t basescale;
|
|
int *timer;
|
|
} ecs_syncgrow;
|
|
|
|
// A billboard for OUR system, which does not look up or down at the target. As
|
|
// such, no matter what the lookat is set to, y is always going to be equal to
|
|
// the y of the instance, so it appears to be looking "straight"
|
|
typedef struct {
|
|
haloo3d_obj_instance *obj;
|
|
struct vec3 *lookat;
|
|
} ecs_billboard;
|
|
|
|
// A component which holds onto data specifically for world
|
|
// entities. You can think of it as private data so people
|
|
// can't poke at the worldstate data
|
|
typedef struct {
|
|
worldstate *state;
|
|
haloo3d_obj *wallmodel;
|
|
haloo3d_obj_instance *endobj;
|
|
haloo3d_easyinstancer *instancer;
|
|
// paintingmanager * pm;
|
|
int scaletimer;
|
|
mfloat_t scaleto;
|
|
} ecs_world;
|
|
|
|
// State for tracking a smart ai moving through the maze.
|
|
typedef struct {
|
|
int32_t timer;
|
|
mfloat_t rotchange;
|
|
struct vec2i mpos;
|
|
worldstate *ws;
|
|
haloo3d_obj_instance *startmarker;
|
|
uint8_t state;
|
|
uint8_t dir;
|
|
uint8_t upsidedown;
|
|
} ecs_smartai;
|
|
|
|
typedef struct {
|
|
uint8_t state;
|
|
uint8_t dir;
|
|
struct vec2i mpos;
|
|
worldstate *ws;
|
|
} ecs_mouseai;
|
|
|
|
// A component which allows an object instance to die
|
|
// when the maze is initiailized.
|
|
typedef struct {
|
|
haloo3d_obj_instance *obj;
|
|
haloo3d_easyrender *render;
|
|
worldstate *ws;
|
|
void (*diefunc)(haloo3d_obj_instance *);
|
|
} ecs_dieoninit;
|
|
|
|
// A component which indicates where in a maze an entity is.
|
|
// This is tile-based and so entities can't overlap (here at least),
|
|
// but just in case, there's an entity type too
|
|
typedef struct {
|
|
struct vec2i mpos;
|
|
uint8_t type;
|
|
} ecs_mazeentity;
|
|
|
|
// Setup ECS system for our game
|
|
ECS_START(mecs)
|
|
ECS_COMPONENT(ecs_world);
|
|
ECS_COMPONENT(ecs_autonav);
|
|
ECS_COMPONENT(ecs_autorotate);
|
|
ECS_COMPONENT(ecs_placement);
|
|
ECS_COMPONENT(ecs_camera);
|
|
ECS_COMPONENT(ecs_smartai);
|
|
ECS_COMPONENT(ecs_syncgrow);
|
|
ECS_COMPONENT(ecs_billboard);
|
|
ECS_COMPONENT(ecs_dieoninit);
|
|
ECS_COMPONENT(ecs_mouseai);
|
|
ECS_COMPONENT(ecs_object);
|
|
ECS_COMPONENT(ecs_mazeentity);
|
|
ECS_END(mecs)
|
|
|
|
ECS_FN_INIT(mecs)
|
|
ECS_FN_NEWENTITY(mecs)
|
|
ECS_FN_DELETEENTITY(mecs)
|
|
ECS_FN_EID(mecs)
|
|
ECS_FN_QUERY(mecs)
|
|
|
|
// And then a copy of the components here... that sucksssss
|
|
ECS_CID(ecs_worldstate, 0);
|
|
ECS_CID(ecs_world, 1);
|
|
ECS_CID(ecs_autonav, 2);
|
|
ECS_CID(ecs_autorotate, 3);
|
|
ECS_CID(ecs_placement, 4);
|
|
ECS_CID(ecs_camera, 5);
|
|
ECS_CID(ecs_smartai, 6);
|
|
ECS_CID(ecs_syncgrow, 7);
|
|
ECS_CID(ecs_billboard, 8);
|
|
ECS_CID(ecs_dieoninit, 9);
|
|
ECS_CID(ecs_mouseai, 10);
|
|
ECS_CID(ecs_object, 11);
|
|
ECS_CID(ecs_mazeentity, 12);
|
|
|
|
#endif
|