sw-battle-test-c

Interesting test task in C instead of C++
git clone git://bsandro.tech/sw-battle-test-c
Log | Files | Refs | README

commit 917e798edec11551ab00d4db014cd7bd70bd6c68
parent 3ebd6b7e876f34e2eaabbba687e91d73f823f641
Author: bsandro <email@bsandro.tech>
Date:   Tue,  8 Sep 2026 00:14:19 +0300

tiny renames

Diffstat:
Mactions/attack_melee.c | 1+
Mcommands/SPAWN_SWORDSMAN.c | 2+-
Mcore/map.c | 2+-
Mcore/map.h | 2+-
Mcore/world.c | 8++++----
Mcore/world.h | 8++++----
Mmain.c | 8++++----
7 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/actions/attack_melee.c b/actions/attack_melee.c @@ -7,5 +7,6 @@ bool Attack_Melee(Entity *e, World *w) { int strength = Entity_Find_Component(e, COMPONENT_MELEE)->melee.strength; //@todo NULL check printf("action melee attack with strength %d\n", strength); + // return true; } diff --git a/commands/SPAWN_SWORDSMAN.c b/commands/SPAWN_SWORDSMAN.c @@ -30,7 +30,7 @@ void cmd_spawn_swordsman(World *w, ...) { .type = COMPONENT_ACTIONS, .actions = actions }); - World_addEntity(w, &swordsman); + World_Add_Entity(w, &swordsman); printf("entity has %ld components:\n", arrlen(swordsman.components)); printf("%d: %dhp\n", swordsman.components[0].type, swordsman.components[0].health.hp); } diff --git a/core/map.c b/core/map.c @@ -2,7 +2,7 @@ #include "map.h" //todo: return 1 or 0 -void Map_init(Map *m, int w, int h) { +void Map_Init(Map *m, int w, int h) { m->w = w; m->h = h; } diff --git a/core/map.h b/core/map.h @@ -5,4 +5,4 @@ typedef struct Map { int h; } Map; -void Map_init(Map *m, int w, int h); +void Map_Init(Map *m, int w, int h); diff --git a/core/world.c b/core/world.c @@ -2,19 +2,19 @@ #include "stb_ds.h" #include "world.h" -World * World_init() { +World * World_Init() { return NULL; } -void World_addEntity(World *w, Entity *e) { +void World_Add_Entity(World *w, Entity *e) { arrput(w->entities, *e); } -void World_addSystem(World *w, System *s) { +void World_Add_System(World *w, System *s) { arrput(w->systems, *s); } -bool World_runSystems(World *w) { +bool World_Run_Systems(World *w) { bool ret = false; for (int i=0;i<arrlen(w->systems);++i) { ret |= w->systems[i].run(w); diff --git a/core/world.h b/core/world.h @@ -11,7 +11,7 @@ typedef struct World { System *systems; } World; -World * World_init(); -void World_addEntity(World *w, Entity *e); -void World_addSystem(World *w, System *s); -bool World_runSystems(World *w); +World * World_Init(); +void World_Add_Entity(World *w, Entity *e); +void World_Add_System(World *w, System *s); +bool World_Run_Systems(World *w); diff --git a/main.c b/main.c @@ -8,11 +8,11 @@ int main(int argc, char **argv) { World w; - Map_init(&w.map, 3, 4); + Map_Init(&w.map, 3, 4); puts("map init ok"); int turn = 0; - World_addSystem(&w, &(System){ .run = actions_run }); - World_addSystem(&w, &(System){ .run = death_run }); + World_Add_System(&w, &(System){ .run = actions_run }); + World_Add_System(&w, &(System){ .run = death_run }); puts("world init ok"); if (argc>1) { @@ -27,7 +27,7 @@ int main(int argc, char **argv) { return 1; fin: - while (World_runSystems(&w)) { + while (World_Run_Systems(&w)) { printf("[turn %3d] world systems run ok\n", turn++); // safeguard if (turn >= 1000) {