From f841a35a536838e1e41bb29cc7454192ba13c75e Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 21 May 2026 11:07:21 -0500 Subject: [PATCH] Revert "Disable old ent code" This reverts commit efd31237be74b3005c81e7f69d12827b250dba03. --- src/dusk/CMakeLists.txt | 1 + src/dusk/engine/engine.c | 4 + {archive => src/dusk}/entity/CMakeLists.txt | 0 {archive => src/dusk}/entity/component.c | 0 {archive => src/dusk}/entity/component.h | 0 .../dusk}/entity/component/CMakeLists.txt | 0 .../entity/component/display/CMakeLists.txt | 0 .../entity/component/display/entitycamera.c | 0 .../entity/component/display/entitycamera.h | 0 .../entity/component/display/entityposition.c | 0 .../entity/component/display/entityposition.h | 0 .../component/display/entityrenderable.c | 0 .../component/display/entityrenderable.h | 0 .../entity/component/physics/CMakeLists.txt | 0 .../entity/component/physics/entityphysics.c | 0 .../entity/component/physics/entityphysics.h | 0 .../entity/component/script/CMakeLists.txt | 0 .../entity/component/trigger/CMakeLists.txt | 0 .../entity/component/trigger/entitytrigger.c | 0 .../entity/component/trigger/entitytrigger.h | 0 {archive => src/dusk}/entity/componentlist.h | 0 {archive => src/dusk}/entity/entity.c | 0 {archive => src/dusk}/entity/entity.h | 0 {archive => src/dusk}/entity/entitybase.h | 0 {archive => src/dusk}/entity/entitymanager.c | 0 {archive => src/dusk}/entity/entitymanager.h | 0 src/dusk/overworld/mapchunk.c | 9 + src/dusk/overworld/mapchunk.h | 3 + src/dusk/physics/physicsworld.c | 208 +++++++++--------- src/dusk/scene/scene.c | 3 + 30 files changed, 124 insertions(+), 104 deletions(-) rename {archive => src/dusk}/entity/CMakeLists.txt (100%) rename {archive => src/dusk}/entity/component.c (100%) rename {archive => src/dusk}/entity/component.h (100%) rename {archive => src/dusk}/entity/component/CMakeLists.txt (100%) rename {archive => src/dusk}/entity/component/display/CMakeLists.txt (100%) rename {archive => src/dusk}/entity/component/display/entitycamera.c (100%) rename {archive => src/dusk}/entity/component/display/entitycamera.h (100%) rename {archive => src/dusk}/entity/component/display/entityposition.c (100%) rename {archive => src/dusk}/entity/component/display/entityposition.h (100%) rename {archive => src/dusk}/entity/component/display/entityrenderable.c (100%) rename {archive => src/dusk}/entity/component/display/entityrenderable.h (100%) rename {archive => src/dusk}/entity/component/physics/CMakeLists.txt (100%) rename {archive => src/dusk}/entity/component/physics/entityphysics.c (100%) rename {archive => src/dusk}/entity/component/physics/entityphysics.h (100%) rename {archive => src/dusk}/entity/component/script/CMakeLists.txt (100%) rename {archive => src/dusk}/entity/component/trigger/CMakeLists.txt (100%) rename {archive => src/dusk}/entity/component/trigger/entitytrigger.c (100%) rename {archive => src/dusk}/entity/component/trigger/entitytrigger.h (100%) rename {archive => src/dusk}/entity/componentlist.h (100%) rename {archive => src/dusk}/entity/entity.c (100%) rename {archive => src/dusk}/entity/entity.h (100%) rename {archive => src/dusk}/entity/entitybase.h (100%) rename {archive => src/dusk}/entity/entitymanager.c (100%) rename {archive => src/dusk}/entity/entitymanager.h (100%) diff --git a/src/dusk/CMakeLists.txt b/src/dusk/CMakeLists.txt index 3b9db158..21bf7951 100644 --- a/src/dusk/CMakeLists.txt +++ b/src/dusk/CMakeLists.txt @@ -56,6 +56,7 @@ add_subdirectory(console) add_subdirectory(display) add_subdirectory(log) add_subdirectory(engine) +add_subdirectory(entity) add_subdirectory(error) add_subdirectory(input) add_subdirectory(locale) diff --git a/src/dusk/engine/engine.c b/src/dusk/engine/engine.c index d055883b..32649669 100644 --- a/src/dusk/engine/engine.c +++ b/src/dusk/engine/engine.c @@ -17,6 +17,8 @@ #include "ui/ui.h" #include "ui/uitextbox.h" #include "assert/assert.h" +#include "entity/entitymanager.h" +#include "entity/component/physics/entityphysics.h" #include "physics/physicsmanager.h" #include "network/network.h" #include "system/system.h" @@ -48,6 +50,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { errorChain(cutsceneInit()); errorChain(sceneInit()); + entityManagerInit(); backpackInit(); physicsManagerInit(); errorChain(networkInit()); @@ -89,6 +92,7 @@ errorret_t engineDispose(void) { cutsceneDispose(); sceneDispose(); errorChain(networkDispose()); + entityManagerDispose(); localeManagerDispose(); uiDispose(); consoleDispose(); diff --git a/archive/entity/CMakeLists.txt b/src/dusk/entity/CMakeLists.txt similarity index 100% rename from archive/entity/CMakeLists.txt rename to src/dusk/entity/CMakeLists.txt diff --git a/archive/entity/component.c b/src/dusk/entity/component.c similarity index 100% rename from archive/entity/component.c rename to src/dusk/entity/component.c diff --git a/archive/entity/component.h b/src/dusk/entity/component.h similarity index 100% rename from archive/entity/component.h rename to src/dusk/entity/component.h diff --git a/archive/entity/component/CMakeLists.txt b/src/dusk/entity/component/CMakeLists.txt similarity index 100% rename from archive/entity/component/CMakeLists.txt rename to src/dusk/entity/component/CMakeLists.txt diff --git a/archive/entity/component/display/CMakeLists.txt b/src/dusk/entity/component/display/CMakeLists.txt similarity index 100% rename from archive/entity/component/display/CMakeLists.txt rename to src/dusk/entity/component/display/CMakeLists.txt diff --git a/archive/entity/component/display/entitycamera.c b/src/dusk/entity/component/display/entitycamera.c similarity index 100% rename from archive/entity/component/display/entitycamera.c rename to src/dusk/entity/component/display/entitycamera.c diff --git a/archive/entity/component/display/entitycamera.h b/src/dusk/entity/component/display/entitycamera.h similarity index 100% rename from archive/entity/component/display/entitycamera.h rename to src/dusk/entity/component/display/entitycamera.h diff --git a/archive/entity/component/display/entityposition.c b/src/dusk/entity/component/display/entityposition.c similarity index 100% rename from archive/entity/component/display/entityposition.c rename to src/dusk/entity/component/display/entityposition.c diff --git a/archive/entity/component/display/entityposition.h b/src/dusk/entity/component/display/entityposition.h similarity index 100% rename from archive/entity/component/display/entityposition.h rename to src/dusk/entity/component/display/entityposition.h diff --git a/archive/entity/component/display/entityrenderable.c b/src/dusk/entity/component/display/entityrenderable.c similarity index 100% rename from archive/entity/component/display/entityrenderable.c rename to src/dusk/entity/component/display/entityrenderable.c diff --git a/archive/entity/component/display/entityrenderable.h b/src/dusk/entity/component/display/entityrenderable.h similarity index 100% rename from archive/entity/component/display/entityrenderable.h rename to src/dusk/entity/component/display/entityrenderable.h diff --git a/archive/entity/component/physics/CMakeLists.txt b/src/dusk/entity/component/physics/CMakeLists.txt similarity index 100% rename from archive/entity/component/physics/CMakeLists.txt rename to src/dusk/entity/component/physics/CMakeLists.txt diff --git a/archive/entity/component/physics/entityphysics.c b/src/dusk/entity/component/physics/entityphysics.c similarity index 100% rename from archive/entity/component/physics/entityphysics.c rename to src/dusk/entity/component/physics/entityphysics.c diff --git a/archive/entity/component/physics/entityphysics.h b/src/dusk/entity/component/physics/entityphysics.h similarity index 100% rename from archive/entity/component/physics/entityphysics.h rename to src/dusk/entity/component/physics/entityphysics.h diff --git a/archive/entity/component/script/CMakeLists.txt b/src/dusk/entity/component/script/CMakeLists.txt similarity index 100% rename from archive/entity/component/script/CMakeLists.txt rename to src/dusk/entity/component/script/CMakeLists.txt diff --git a/archive/entity/component/trigger/CMakeLists.txt b/src/dusk/entity/component/trigger/CMakeLists.txt similarity index 100% rename from archive/entity/component/trigger/CMakeLists.txt rename to src/dusk/entity/component/trigger/CMakeLists.txt diff --git a/archive/entity/component/trigger/entitytrigger.c b/src/dusk/entity/component/trigger/entitytrigger.c similarity index 100% rename from archive/entity/component/trigger/entitytrigger.c rename to src/dusk/entity/component/trigger/entitytrigger.c diff --git a/archive/entity/component/trigger/entitytrigger.h b/src/dusk/entity/component/trigger/entitytrigger.h similarity index 100% rename from archive/entity/component/trigger/entitytrigger.h rename to src/dusk/entity/component/trigger/entitytrigger.h diff --git a/archive/entity/componentlist.h b/src/dusk/entity/componentlist.h similarity index 100% rename from archive/entity/componentlist.h rename to src/dusk/entity/componentlist.h diff --git a/archive/entity/entity.c b/src/dusk/entity/entity.c similarity index 100% rename from archive/entity/entity.c rename to src/dusk/entity/entity.c diff --git a/archive/entity/entity.h b/src/dusk/entity/entity.h similarity index 100% rename from archive/entity/entity.h rename to src/dusk/entity/entity.h diff --git a/archive/entity/entitybase.h b/src/dusk/entity/entitybase.h similarity index 100% rename from archive/entity/entitybase.h rename to src/dusk/entity/entitybase.h diff --git a/archive/entity/entitymanager.c b/src/dusk/entity/entitymanager.c similarity index 100% rename from archive/entity/entitymanager.c rename to src/dusk/entity/entitymanager.c diff --git a/archive/entity/entitymanager.h b/src/dusk/entity/entitymanager.h similarity index 100% rename from archive/entity/entitymanager.h rename to src/dusk/entity/entitymanager.h diff --git a/src/dusk/overworld/mapchunk.c b/src/dusk/overworld/mapchunk.c index 36c45822..a7fa78f3 100644 --- a/src/dusk/overworld/mapchunk.c +++ b/src/dusk/overworld/mapchunk.c @@ -7,12 +7,16 @@ #include "mapchunk.h" #include "map.h" +#include "entity/entitymanager.h" #include "util/memory.h" #include "util/string.h" #include "asset/asset.h" #include "console/console.h" errorret_t mapChunkLoad(mapchunk_t *chunk) { + chunk->entityCount = 0; + memoryZero(chunk->entities, sizeof(chunk->entities)); + if(MAP.handle[0] == '\0') errorOk(); char_t path[ASSET_FILE_NAME_MAX]; @@ -44,4 +48,9 @@ void mapChunkUnload(mapchunk_t *chunk) { (int)chunk->position.y, (int)chunk->position.z ); + + for(uint8_t i = 0; i < chunk->entityCount; i++) { + entityDispose(chunk->entities[i]); + } + chunk->entityCount = 0; } diff --git a/src/dusk/overworld/mapchunk.h b/src/dusk/overworld/mapchunk.h index dc66ea0c..7513220f 100644 --- a/src/dusk/overworld/mapchunk.h +++ b/src/dusk/overworld/mapchunk.h @@ -7,12 +7,15 @@ #pragma once #include "maptypes.h" +#include "entity/entitybase.h" #include "error/error.h" #define MAP_CHUNK_ENTITY_COUNT_MAX 64 typedef struct { chunkpos_t position; + entityid_t entities[MAP_CHUNK_ENTITY_COUNT_MAX]; + uint8_t entityCount; } mapchunk_t; /** diff --git a/src/dusk/physics/physicsworld.c b/src/dusk/physics/physicsworld.c index a1b81362..02e24ec7 100644 --- a/src/dusk/physics/physicsworld.c +++ b/src/dusk/physics/physicsworld.c @@ -8,8 +8,8 @@ #include "physicsworld.h" #include "assert/assert.h" #include "util/memory.h" -// #include "entity/entity.h" -// #include "entity/component.h" +#include "entity/entity.h" +#include "entity/component.h" #include "physicstest.h" physicsworld_t PHYSICS_WORLD; @@ -23,129 +23,129 @@ void physicsWorldInit() { } void physicsWorldStep(const float_t dt) { - // assertTrue(dt > 0.0f, "Delta time must be positive"); + assertTrue(dt > 0.0f, "Delta time must be positive"); - // entityid_t physEnts[ENTITY_COUNT_MAX]; - // componentid_t physComps[ENTITY_COUNT_MAX]; - // entityid_t physCount = componentGetEntitiesWithComponent( - // COMPONENT_TYPE_PHYSICS, physEnts, physComps - // ); + entityid_t physEnts[ENTITY_COUNT_MAX]; + componentid_t physComps[ENTITY_COUNT_MAX]; + entityid_t physCount = componentGetEntitiesWithComponent( + COMPONENT_TYPE_PHYSICS, physEnts, physComps + ); - // /* Pre-fetch all position and physics pointers once. */ - // entityposition_t *positions[ENTITY_COUNT_MAX]; - // entityphysics_t *physBodies[ENTITY_COUNT_MAX]; - // for(entityid_t i = 0; i < physCount; i++) { - // componentid_t posComp = entityGetComponent( - // physEnts[i], COMPONENT_TYPE_POSITION - // ); - // positions[i] = (posComp != 0xFF) - // ? entityPositionGet(physEnts[i], posComp) - // : NULL; - // physBodies[i] = entityPhysicsGet(physEnts[i], physComps[i]); - // } + /* Pre-fetch all position and physics pointers once. */ + entityposition_t *positions[ENTITY_COUNT_MAX]; + entityphysics_t *physBodies[ENTITY_COUNT_MAX]; + for(entityid_t i = 0; i < physCount; i++) { + componentid_t posComp = entityGetComponent( + physEnts[i], COMPONENT_TYPE_POSITION + ); + positions[i] = (posComp != 0xFF) + ? entityPositionGet(physEnts[i], posComp) + : NULL; + physBodies[i] = entityPhysicsGet(physEnts[i], physComps[i]); + } - // /* Phase 1: integrate dynamic bodies (gravity + velocity → position). - // * Writes directly to pos->position, matrix rebuilt at end. */ - // for(entityid_t i = 0; i < physCount; i++) { - // if(!positions[i]) continue; - // entityphysics_t *phys = physBodies[i]; - // if(phys->type != PHYSICS_BODY_DYNAMIC) continue; + /* Phase 1: integrate dynamic bodies (gravity + velocity → position). + * Writes directly to pos->position, matrix rebuilt at end. */ + for(entityid_t i = 0; i < physCount; i++) { + if(!positions[i]) continue; + entityphysics_t *phys = physBodies[i]; + if(phys->type != PHYSICS_BODY_DYNAMIC) continue; - // phys->onGround = false; + phys->onGround = false; - // phys->velocity[0] += PHYSICS_WORLD.gravity[0] * phys->gravityScale * dt; - // phys->velocity[1] += PHYSICS_WORLD.gravity[1] * phys->gravityScale * dt; - // phys->velocity[2] += PHYSICS_WORLD.gravity[2] * phys->gravityScale * dt; + phys->velocity[0] += PHYSICS_WORLD.gravity[0] * phys->gravityScale * dt; + phys->velocity[1] += PHYSICS_WORLD.gravity[1] * phys->gravityScale * dt; + phys->velocity[2] += PHYSICS_WORLD.gravity[2] * phys->gravityScale * dt; - // float_t *pos = positions[i]->position; - // pos[0] += phys->velocity[0] * dt; - // pos[1] += phys->velocity[1] * dt; - // pos[2] += phys->velocity[2] * dt; - // } + float_t *pos = positions[i]->position; + pos[0] += phys->velocity[0] * dt; + pos[1] += phys->velocity[1] * dt; + pos[2] += phys->velocity[2] * dt; + } - // /* Phase 2: dynamic vs static/kinematic. */ - // for(entityid_t i = 0; i < physCount; i++) { - // if(!positions[i]) continue; - // entityphysics_t *phys = physBodies[i]; - // if(phys->type != PHYSICS_BODY_DYNAMIC) continue; + /* Phase 2: dynamic vs static/kinematic. */ + for(entityid_t i = 0; i < physCount; i++) { + if(!positions[i]) continue; + entityphysics_t *phys = physBodies[i]; + if(phys->type != PHYSICS_BODY_DYNAMIC) continue; - // float_t *pos = positions[i]->position; + float_t *pos = positions[i]->position; - // for(entityid_t j = 0; j < physCount; j++) { - // if(i == j || !positions[j]) continue; - // entityphysics_t *otherPhys = physBodies[j]; - // if(otherPhys->type == PHYSICS_BODY_DYNAMIC) continue; + for(entityid_t j = 0; j < physCount; j++) { + if(i == j || !positions[j]) continue; + entityphysics_t *otherPhys = physBodies[j]; + if(otherPhys->type == PHYSICS_BODY_DYNAMIC) continue; - // vec3 normal; float_t depth; - // if(!physicsTestShapeVsShape( - // pos, phys->shape, - // positions[j]->position, otherPhys->shape, - // normal, &depth - // )) continue; + vec3 normal; float_t depth; + if(!physicsTestShapeVsShape( + pos, phys->shape, + positions[j]->position, otherPhys->shape, + normal, &depth + )) continue; - // pos[0] += normal[0] * depth; - // pos[1] += normal[1] * depth; - // pos[2] += normal[2] * depth; + pos[0] += normal[0] * depth; + pos[1] += normal[1] * depth; + pos[2] += normal[2] * depth; - // float_t vn = glm_vec3_dot(phys->velocity, normal); - // if(vn < 0.0f) { - // phys->velocity[0] -= vn * normal[0]; - // phys->velocity[1] -= vn * normal[1]; - // phys->velocity[2] -= vn * normal[2]; - // } + float_t vn = glm_vec3_dot(phys->velocity, normal); + if(vn < 0.0f) { + phys->velocity[0] -= vn * normal[0]; + phys->velocity[1] -= vn * normal[1]; + phys->velocity[2] -= vn * normal[2]; + } - // if(normal[1] > PHYSICS_GROUND_THRESHOLD) phys->onGround = true; - // } - // } + if(normal[1] > PHYSICS_GROUND_THRESHOLD) phys->onGround = true; + } + } - // /* Phase 3: dynamic vs dynamic. */ - // for(entityid_t i = 0; i < physCount; i++) { - // if(!positions[i]) continue; - // entityphysics_t *physA = physBodies[i]; - // if(physA->type != PHYSICS_BODY_DYNAMIC) continue; + /* Phase 3: dynamic vs dynamic. */ + for(entityid_t i = 0; i < physCount; i++) { + if(!positions[i]) continue; + entityphysics_t *physA = physBodies[i]; + if(physA->type != PHYSICS_BODY_DYNAMIC) continue; - // float_t *posA = positions[i]->position; + float_t *posA = positions[i]->position; - // for(entityid_t j = i + 1; j < physCount; j++) { - // if(!positions[j]) continue; - // entityphysics_t *physB = physBodies[j]; - // if(physB->type != PHYSICS_BODY_DYNAMIC) continue; + for(entityid_t j = i + 1; j < physCount; j++) { + if(!positions[j]) continue; + entityphysics_t *physB = physBodies[j]; + if(physB->type != PHYSICS_BODY_DYNAMIC) continue; - // float_t *posB = positions[j]->position; + float_t *posB = positions[j]->position; - // vec3 normal; float_t depth; - // if(!physicsTestShapeVsShape( - // posA, physA->shape, posB, physB->shape, normal, &depth - // )) continue; + vec3 normal; float_t depth; + if(!physicsTestShapeVsShape( + posA, physA->shape, posB, physB->shape, normal, &depth + )) continue; - // posA[0] += normal[0] * depth * 0.5f; - // posA[1] += normal[1] * depth * 0.5f; - // posA[2] += normal[2] * depth * 0.5f; + posA[0] += normal[0] * depth * 0.5f; + posA[1] += normal[1] * depth * 0.5f; + posA[2] += normal[2] * depth * 0.5f; - // posB[0] -= normal[0] * depth * 0.5f; - // posB[1] -= normal[1] * depth * 0.5f; - // posB[2] -= normal[2] * depth * 0.5f; + posB[0] -= normal[0] * depth * 0.5f; + posB[1] -= normal[1] * depth * 0.5f; + posB[2] -= normal[2] * depth * 0.5f; - // float_t v_rel = glm_vec3_dot(physA->velocity, normal) - // - glm_vec3_dot(physB->velocity, normal); - // if(v_rel < 0.0f) { - // physA->velocity[0] -= v_rel * normal[0]; - // physA->velocity[1] -= v_rel * normal[1]; - // physA->velocity[2] -= v_rel * normal[2]; - // physB->velocity[0] += v_rel * normal[0]; - // physB->velocity[1] += v_rel * normal[1]; - // physB->velocity[2] += v_rel * normal[2]; - // } + float_t v_rel = glm_vec3_dot(physA->velocity, normal) + - glm_vec3_dot(physB->velocity, normal); + if(v_rel < 0.0f) { + physA->velocity[0] -= v_rel * normal[0]; + physA->velocity[1] -= v_rel * normal[1]; + physA->velocity[2] -= v_rel * normal[2]; + physB->velocity[0] += v_rel * normal[0]; + physB->velocity[1] += v_rel * normal[1]; + physB->velocity[2] += v_rel * normal[2]; + } - // if( normal[1] > PHYSICS_GROUND_THRESHOLD) physA->onGround = true; - // if(-normal[1] > PHYSICS_GROUND_THRESHOLD) physB->onGround = true; - // } - // } + if( normal[1] > PHYSICS_GROUND_THRESHOLD) physA->onGround = true; + if(-normal[1] > PHYSICS_GROUND_THRESHOLD) physB->onGround = true; + } + } - // /* Rebuild transforms for all dynamic bodies once, after all phases. */ - // for(entityid_t i = 0; i < physCount; i++) { - // if(!positions[i]) continue; - // if(physBodies[i]->type != PHYSICS_BODY_DYNAMIC) continue; - // entityPositionRebuild(positions[i]); - // } + /* Rebuild transforms for all dynamic bodies once, after all phases. */ + for(entityid_t i = 0; i < physCount; i++) { + if(!positions[i]) continue; + if(physBodies[i]->type != PHYSICS_BODY_DYNAMIC) continue; + entityPositionRebuild(positions[i]); + } } diff --git a/src/dusk/scene/scene.c b/src/dusk/scene/scene.c index c215dc19..0473eca5 100644 --- a/src/dusk/scene/scene.c +++ b/src/dusk/scene/scene.c @@ -9,9 +9,12 @@ #include "log/log.h" #include "time/time.h" #include "display/screen/screen.h" +#include "entity/entitymanager.h" +#include "entity/component/display/entityrenderable.h" #include "display/shader/shaderunlit.h" #include "display/spritebatch/spritebatch.h" #include "display/screen/screen.h" +#include "console/console.h" #include "util/string.h" #include "ui/ui.h"