Small cleanup

This commit is contained in:
Carlos Sanchez 2024-08-18 19:13:25 -04:00
parent 7a14287e53
commit 8abf116c60
5 changed files with 15 additions and 41 deletions

16
ecs2.h
View File

@ -1,6 +1,7 @@
// A purely global, all macro-driven ecs implementation. // haloopdy - 2024
// You are expected to have only a need for a global // A super simple, all macro-driven ecs implementation.
// ecs when using this. // Macros create a struct and associated functions to build
// a simple, lightweight ecs implementation
#ifndef __HALOO3D_ECS2_H #ifndef __HALOO3D_ECS2_H
#define __HALOO3D_ECS2_H #define __HALOO3D_ECS2_H
@ -66,6 +67,9 @@ typedef int ecs_eid;
} \ } \
} }
// Add a system function which automatically calls your given function with
// pre-pulled items from the entity component arrays. The new function is
// named the same as the old one, just with _run appeneded
#define ECS_SYSTEM2(ecsname, fname, type1, type2) \ #define ECS_SYSTEM2(ecsname, fname, type1, type2) \
void fname##_run(ecsname *_ecs, ecs_eid eid) { \ void fname##_run(ecsname *_ecs, ecs_eid eid) { \
ecs_cid _ecsflags = type1##_fl | type2##_fl; \ ecs_cid _ecsflags = type1##_fl | type2##_fl; \
@ -74,6 +78,9 @@ typedef int ecs_eid;
} \ } \
} }
// Add a system function which automatically calls your given function with
// pre-pulled items from the entity component arrays. The new function is
// named the same as the old one, just with _run appeneded
#define ECS_SYSTEM3(ecsname, fname, type1, type2, type3) \ #define ECS_SYSTEM3(ecsname, fname, type1, type2, type3) \
void fname##_run(ecsname *_ecs, ecs_eid eid) { \ void fname##_run(ecsname *_ecs, ecs_eid eid) { \
ecs_cid _ecsflags = type1##_fl | type2##_fl | type3##_fl; \ ecs_cid _ecsflags = type1##_fl | type2##_fl | type3##_fl; \
@ -83,6 +90,9 @@ typedef int ecs_eid;
} \ } \
} }
// Add a system function which automatically calls your given function with
// pre-pulled items from the entity component arrays. The new function is
// named the same as the old one, just with _run appeneded
#define ECS_SYSTEM4(ecsname, fname, type1, type2, type3, type4) \ #define ECS_SYSTEM4(ecsname, fname, type1, type2, type3, type4) \
void fname##_run(ecsname *_ecs, ecs_eid eid) { \ void fname##_run(ecsname *_ecs, ecs_eid eid) { \
ecs_cid _ecsflags = type1##_fl | type2##_fl | type3##_fl | type4##_fl; \ ecs_cid _ecsflags = type1##_fl | type2##_fl | type3##_fl | type4##_fl; \

View File

@ -59,9 +59,7 @@ typedef struct {
// rt->rot.y = (*cam)->pitch; // rt->rot.y = (*cam)->pitch;
// } // }
static void sys_ecs_moveto( static void sys_ecs_moveto(ecs_moveto *mt) {
ecs_moveto *mt) { // haloo_ecs *ecs, hecs_eidt id, hecs_cidt mtid) {
// ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
if (mt->timer <= 0) { if (mt->timer <= 0) {
mt->pos = mt->dst; mt->pos = mt->dst;
return; return;
@ -75,10 +73,7 @@ static void sys_ecs_moveto(
mt->timer--; mt->timer--;
} }
static void sys_ecs_rotateto( static void sys_ecs_rotateto(ecs_rotateto *rt) {
ecs_rotateto *rt) { // haloo_ecs *ecs, hecs_eidt id, hecs_cidt rtid) {
// static void sys_ecs_rotateto(haloo_ecs *ecs, hecs_eidt id, hecs_cidt rtid)
// { ecs_rotateto *rt = HECS_ENTITYCOMPONENT(ecs_rotateto *, id, rtid, ecs);
if (rt->timer <= 0) { if (rt->timer <= 0) {
rt->rot = rt->dstrot; rt->rot = rt->dstrot;
return; return;
@ -100,22 +95,12 @@ static void sys_ecs_rotateto(
// } // }
// Move movement pos back into camera // Move movement pos back into camera
// static void sys_ecs_moveto_camera(haloo_ecs *ecs, hecs_eidt id, hecs_cidt
// mtid, hecs_cidt camid) {
static void sys_ecs_moveto_camera(ecs_moveto *mt, ecs_camera *cam) { static void sys_ecs_moveto_camera(ecs_moveto *mt, ecs_camera *cam) {
// haloo_ecs *ecs, hecs_eidt id, hecs_cidt mtid, hecs_cidt camid) {
// ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
// ecs_camera *cam = HECS_ENTITYCOMPONENT(ecs_camera *, id, camid, ecs);
(*cam)->pos = mt->pos; (*cam)->pos = mt->pos;
} }
// Move rotation back into camera // Move rotation back into camera
// static void sys_ecs_rotateto_camera(haloo_ecs *ecs, hecs_eidt id, hecs_cidt
// rtid, hecs_cidt camid) {
static void sys_ecs_rotateto_camera(ecs_rotateto *rt, ecs_camera *cam) { static void sys_ecs_rotateto_camera(ecs_rotateto *rt, ecs_camera *cam) {
// haloo_ecs *ecs, hecs_eidt id, hecs_cidt rtid, hecs_cidt camid) {
// ecs_rotateto *rt = HECS_ENTITYCOMPONENT(ecs_rotateto *, id, rtid, ecs);
// ecs_camera *cam = HECS_ENTITYCOMPONENT(ecs_camera *, id, camid, ecs);
(*cam)->yaw = rt->rot.x; (*cam)->yaw = rt->rot.x;
(*cam)->pitch = rt->rot.y; (*cam)->pitch = rt->rot.y;
} }

21
maze.c
View File

@ -486,31 +486,11 @@ int main() { // int argc, char **argv) {
// --------------------------- // ---------------------------
for (int i = 0; i < ECS_MAXENTITIES; i++) { for (int i = 0; i < ECS_MAXENTITIES; i++) {
// eprintf("CHECKING EID %d\n", i);
// HECS_RUNSYS(&ecs, i, sys_ecs_objin_moveto, ecs_objin_id,
// ecs_moveto_id);
// HECS_RUNSYS(&ecs, i, sys_ecs_camera_rotateto, ecs_camera_id,
// ecs_rotateto_id);
// HECS_RUNSYS(&ecs, i, sys_ecs_camera_moveto, ecs_camera_id,
// ecs_moveto_id);
sys_ecs_smartai_run(&ecs, i); sys_ecs_smartai_run(&ecs, i);
sys_ecs_moveto_run(&ecs, i); sys_ecs_moveto_run(&ecs, i);
sys_ecs_rotateto_run(&ecs, i); sys_ecs_rotateto_run(&ecs, i);
sys_ecs_moveto_camera_run(&ecs, i); sys_ecs_moveto_camera_run(&ecs, i);
sys_ecs_rotateto_camera_run(&ecs, i); sys_ecs_rotateto_camera_run(&ecs, i);
// HECS_RUNSYS(&ecs, i, sys_ecs_smartai, ecs_smartai_id, ecs_maze_id,
// ecs_moveto_id, ecs_rotateto_id);
// HECS_RUNSYS(&ecs, i, sys_ecs_moveto, ecs_moveto_id);
// HECS_RUNSYS(&ecs, i, sys_ecs_rotateto, ecs_rotateto_id);
// HECS_RUNSYS(&ecs, i, sys_ecs_moveto_camera, ecs_moveto_id,
// ecs_camera_id); HECS_RUNSYS(&ecs, i, sys_ecs_rotateto_camera,
// ecs_rotateto_id,
// ecs_camera_id);
// HECS_RUNSYS(&ecs, i, sys_ecs_moveto_objin, ecs_moveto_id,
// ecs_objin_id);
} }
totaldrawn = 0; totaldrawn = 0;
@ -564,7 +544,6 @@ int main() { // int argc, char **argv) {
// Just to get the compiler to STOP COMPLAINING about unused // Just to get the compiler to STOP COMPLAINING about unused
mecs_deleteentity(&ecs, playerid); mecs_deleteentity(&ecs, playerid);
// haloo_ecs_removeentity(&ecs, playerid); //, int eid)
haloo3d_easystore_deleteallobj(&storage, haloo3d_obj_free); haloo3d_easystore_deleteallobj(&storage, haloo3d_obj_free);
haloo3d_easystore_deletealltex(&storage, haloo3d_fb_free); haloo3d_easystore_deletealltex(&storage, haloo3d_fb_free);

View File