3dtoys/terrain_ecstypes.h

166 lines
5.1 KiB
C
Raw Normal View History

2024-09-08 22:42:50 +00:00
#ifndef __TERRAIN_ECSTYPES
#define __TERRAIN_ECSTYPES
2024-09-14 07:30:53 +00:00
#define ECS_FNTYPE static
2024-09-08 22:42:50 +00:00
#include "ecs2.h"
#include "haloo3d/haloo3d.h"
2024-09-14 05:00:20 +00:00
#include "haloo3d/haloo3dex_easy.h"
#define TERRAIN_MAXPLAYERS 4
2024-09-08 22:42:50 +00:00
// Baseline render context. When a pointer to this is attached as a component,
// it becomes a render target, and that entity will perform the precalcs
// necessary for later object rendering.
typedef struct {
mfloat_t precalc_screen[MAT4_SIZE];
mfloat_t precalc_halfwidth; // Optimization for reducing calcs per tri
mfloat_t precalc_halfheight; // Optimization for reducing calcs per tri
mfloat_t fov;
mfloat_t nearclip;
mfloat_t farclip;
// NOTE: aspect ratio calculated from window
2024-09-08 22:42:50 +00:00
haloo3d_fb window;
// Baseline render settings. Some of these settings will be applied to
// each object associated with this context
haloo3d_trirender rendersettings;
// If alpha is 0, screen is not cleared
uint16_t windowclear;
2024-09-08 22:42:50 +00:00
} render_context;
// Associate this to some entity along with a placement and it will be the
// main "renderer" for a viewpoint
typedef render_context *ecs_rendercontext;
// Associate lighting with some object. Since this is part of the renderer,
// this isn't a component you can assign (it also doesn't mean anything on its
// own)
typedef struct {
struct vec3 dir;
mfloat_t minlight;
// Whether to automatically move lighting when models have a
// lookvec. This also normalizes the light
uint8_t autolightfix;
} object_lighting;
2024-09-08 22:42:50 +00:00
// All values which allow rendering of a 3d object
typedef struct {
// haloo3d_trirender rendersettings; // baseline settings for THIS object.
2024-09-14 05:00:20 +00:00
render_context *context[TERRAIN_MAXPLAYERS]; // What to render into
struct vec3 scale; // how big the thing should be in world
object_lighting *lighting; // a pointer to lighting, null for none
2024-09-08 22:42:50 +00:00
haloo3d_obj *model;
haloo3d_fb *texture;
uint8_t cullbackface; // Whether to cull backfaces (you probably should)
2024-09-14 05:00:20 +00:00
uint8_t contextcount; // How many contexts we render into
2024-09-20 02:33:53 +00:00
float flatdither; // A flat dither amount. Set to -1 to disable
2024-09-08 22:42:50 +00:00
} ecs_object;
// Some placement within the world. Doesn't imply anything other than a
// position and a facing direction
typedef struct {
struct vec3 pos;
struct vec3 up;
struct vec3 lookvec;
} ecs_placement;
2024-09-19 08:13:39 +00:00
// If set, locks the placement of one entity to another
typedef struct {
ecs_placement *link;
// struct vec3 posofs; // The offset from linked pos
uint8_t options; // Which things to lock
} ecs_placement_lock;
#define TECS_PLOCK_LOCKLOOKX 1
#define TECS_PLOCK_LOCKLOOKY 2
#define TECS_PLOCK_LOCKLOOKZ 4
#define TECS_PLOCK_LOCKPOSX 8
#define TECS_PLOCK_LOCKPOSY 16
#define TECS_PLOCK_LOCKPOSZ 32
#define TECS_PLOCK_LOCKUP 64
// typedef ecs_placement *ecs_placement_lock;
// Movement is applied to placement and may also be used to check for
// collisions and whatever
typedef struct {
struct vec3 pos;
struct vec3 up;
struct vec3 lookvec;
} ecs_movement;
// Use rotation to override the lookvec of an ecs_placement
typedef struct {
mfloat_t yaw;
mfloat_t pitch;
} ecs_rotation;
2024-09-09 06:32:02 +00:00
// Type to track and mark some entity as receiving input events.
typedef struct {
int numevents;
} ecs_input;
2024-09-14 05:00:20 +00:00
// Simple component for some entity that should clean itself up
// when there are no more "references" to it. Whatever that means...
// some fields are for special cleanup
typedef struct {
char dynmodel[8]; // A model we may have to cleanup
} ecs_playergarbage;
// Represents the singular object that is the entire stationary
// object of terrain. The position is the "chunk position", which
// should be integer aligned. Not necessarily 1:1 with world
// coordinates?
typedef struct {
2024-09-14 08:34:19 +00:00
struct vec3i pos;
2024-09-14 05:00:20 +00:00
// uint8_t generation; // The type(?) of generation (idk honestly)
} ecs_chunk;
2024-09-08 22:42:50 +00:00
// // 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;
// Setup ECS system for our game
ECS_START(tecs)
2024-09-14 05:00:20 +00:00
float delta_s; // Store delta time in ecs
int totaldrawn; // A place to store total drawn tris
struct vec3 globallighting; // the global lighting to apply to terrain
object_lighting chunklight; // lighting to assign to a chunk
// Everyone needs to be able to get and set obj/texture
haloo3d_easystore storage;
2024-09-14 07:30:53 +00:00
ECS_COMPONENT(ecs_rendercontext)
ECS_COMPONENT(ecs_object)
ECS_COMPONENT(ecs_placement)
ECS_COMPONENT(ecs_rotation)
ECS_COMPONENT(ecs_movement)
ECS_COMPONENT(ecs_input)
ECS_COMPONENT(ecs_playergarbage)
ECS_COMPONENT(ecs_chunk)
2024-09-19 08:13:39 +00:00
ECS_COMPONENT(ecs_placement_lock)
2024-09-08 22:42:50 +00:00
ECS_END(tecs)
2024-09-09 06:13:24 +00:00
ECS_FN_INIT(tecs)
ECS_FN_NEWENTITY(tecs)
2024-09-14 05:00:20 +00:00
ECS_FN_DELETEENTITY(tecs)
ECS_FN_EID(tecs)
2024-09-14 07:30:53 +00:00
ECS_FN_QUERY(tecs)
2024-09-09 06:13:24 +00:00
2024-09-08 22:42:50 +00:00
// And then a copy of the components here... that sucksssss
2024-09-14 07:30:53 +00:00
ECS_CID(ecs_rendercontext, 0)
ECS_CID(ecs_object, 1)
ECS_CID(ecs_placement, 2)
ECS_CID(ecs_rotation, 3)
ECS_CID(ecs_movement, 4)
ECS_CID(ecs_input, 5)
ECS_CID(ecs_playergarbage, 6)
ECS_CID(ecs_chunk, 7)
2024-09-19 08:13:39 +00:00
ECS_CID(ecs_placement_lock, 8)
2024-09-08 22:42:50 +00:00
#endif