diff --git a/ecs2.h b/ecs2.h index 9cbc8b0..3e28c99 100644 --- a/ecs2.h +++ b/ecs2.h @@ -1,6 +1,7 @@ -// A purely global, all macro-driven ecs implementation. -// You are expected to have only a need for a global -// ecs when using this. +// haloopdy - 2024 +// A super simple, all macro-driven ecs implementation. +// Macros create a struct and associated functions to build +// a simple, lightweight ecs implementation #ifndef __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) \ void fname##_run(ecsname *_ecs, ecs_eid eid) { \ 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) \ void fname##_run(ecsname *_ecs, ecs_eid eid) { \ 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) \ void fname##_run(ecsname *_ecs, ecs_eid eid) { \ ecs_cid _ecsflags = type1##_fl | type2##_fl | type3##_fl | type4##_fl; \ diff --git a/ecs2_comps.h b/ecs2_comps.h index 2b6fac6..6dde1c5 100644 --- a/ecs2_comps.h +++ b/ecs2_comps.h @@ -59,9 +59,7 @@ typedef struct { // rt->rot.y = (*cam)->pitch; // } -static void sys_ecs_moveto( - ecs_moveto *mt) { // haloo_ecs *ecs, hecs_eidt id, hecs_cidt mtid) { - // ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs); +static void sys_ecs_moveto(ecs_moveto *mt) { if (mt->timer <= 0) { mt->pos = mt->dst; return; @@ -75,10 +73,7 @@ static void sys_ecs_moveto( mt->timer--; } -static void sys_ecs_rotateto( - 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); +static void sys_ecs_rotateto(ecs_rotateto *rt) { if (rt->timer <= 0) { rt->rot = rt->dstrot; return; @@ -100,22 +95,12 @@ static void sys_ecs_rotateto( // } // 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) { - // 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; } // 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) { - // 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)->pitch = rt->rot.y; } diff --git a/maze.c b/maze.c index b9e1025..17003b8 100644 --- a/maze.c +++ b/maze.c @@ -486,31 +486,11 @@ int main() { // int argc, char **argv) { // --------------------------- 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_moveto_run(&ecs, i); sys_ecs_rotateto_run(&ecs, i); sys_ecs_moveto_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; @@ -564,7 +544,6 @@ int main() { // int argc, char **argv) { // Just to get the compiler to STOP COMPLAINING about unused mecs_deleteentity(&ecs, playerid); - // haloo_ecs_removeentity(&ecs, playerid); //, int eid) haloo3d_easystore_deleteallobj(&storage, haloo3d_obj_free); haloo3d_easystore_deletealltex(&storage, haloo3d_fb_free); diff --git a/ecs.h b/old/ecs.h similarity index 100% rename from ecs.h rename to old/ecs.h diff --git a/ecs_comps.h b/old/ecs_comps.h similarity index 100% rename from ecs_comps.h rename to old/ecs_comps.h