From c5c2998efcafc68551eee462c907823029a8f3b2 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 23 Jan 2026 08:04:10 -0600 Subject: [PATCH] feat(world): add CWorld::AddObject --- src/world/CWorld.cpp | 29 +++++++++++++++++++++++++++++ src/world/CWorld.hpp | 3 +++ src/world/map/CMap.hpp | 3 +-- src/world/map/CMapBaseObj.hpp | 6 ++++++ src/world/map/CMapEntity.cpp | 5 +++++ src/world/map/CMapEntity.hpp | 12 ++++++++++++ src/world/map/CMapStaticEntity.hpp | 9 +++++++++ 7 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/world/map/CMapEntity.cpp diff --git a/src/world/CWorld.cpp b/src/world/CWorld.cpp index fbe55a3..6163b42 100644 --- a/src/world/CWorld.cpp +++ b/src/world/CWorld.cpp @@ -17,6 +17,35 @@ uint32_t CWorld::s_tickTimeMs; float CWorld::s_tickTimeSec; Weather* CWorld::s_weather; +HWORLDOBJECT CWorld::AddObject(CM2Model* model, void* handler, void* handlerParam, uint64_t param64, uint32_t param32, uint32_t objFlags) { + auto entity = CMap::AllocEntity(objFlags & 0x8 ? true : false); + + entity->m_model = model; + entity->m_param64 = param64; + entity->m_param32 = param32; + + // TODO + + entity->m_dirLightScale = 1.0f; + entity->m_dirLightScaleTarget = 1.0f; + + // TODO + + entity->m_type |= CMapBaseObj::Type_200; + + // TODO + + entity->m_flags = 0x0; + + if (objFlags & 0x20) { + entity->m_flags = 0x20000; + } + + // TODO + + return reinterpret_cast(entity); +} + uint32_t CWorld::GetCurTimeMs() { return CWorld::s_curTimeMs; } diff --git a/src/world/CWorld.hpp b/src/world/CWorld.hpp index c3be35d..93cf9fc 100644 --- a/src/world/CWorld.hpp +++ b/src/world/CWorld.hpp @@ -2,9 +2,11 @@ #define WORLD_C_WORLD_HPP #include "event/Event.hpp" +#include "world/Types.hpp" #include #include +class CM2Model; class Weather; class CWorld { @@ -51,6 +53,7 @@ class CWorld { static Weather* s_weather; // Public static functions + static HWORLDOBJECT AddObject(CM2Model* model, void* handler, void* handlerParam, uint64_t param64, uint32_t param32, uint32_t objFlags); static uint32_t GetCurTimeMs(); static float GetCurTimeSec(); static uint32_t GetGameTimeFixed(); diff --git a/src/world/map/CMap.hpp b/src/world/map/CMap.hpp index 902d24f..c70177b 100644 --- a/src/world/map/CMap.hpp +++ b/src/world/map/CMap.hpp @@ -2,11 +2,10 @@ #define WORLD_MAP_C_MAP_HPP #include "world/map/CMapBaseObj.hpp" +#include "world/map/CMapEntity.hpp" #include #include -class CMapEntity; - class CMap { public: // Static variables diff --git a/src/world/map/CMapBaseObj.hpp b/src/world/map/CMapBaseObj.hpp index d9693c8..ca77666 100644 --- a/src/world/map/CMapBaseObj.hpp +++ b/src/world/map/CMapBaseObj.hpp @@ -18,6 +18,9 @@ class CMapBaseObjLink { }; class CMapBaseObj { + friend class CMap; + friend class CWorld; + public: // Enums enum { @@ -29,10 +32,13 @@ class CMapBaseObj { Type_Entity = 0x20, Type_DoodadDef = 0x40, Type_Light = 0x80, + Type_100 = 0x100, + Type_200 = 0x200, }; // Public member variables uint32_t m_memHandle; + uint32_t m_flags = 0x0; TSLink m_lameAssLink; STORM_EXPLICIT_LIST(CMapBaseObjLink, ownerLink) m_parentLinkList; diff --git a/src/world/map/CMapEntity.cpp b/src/world/map/CMapEntity.cpp new file mode 100644 index 0000000..90fb8a3 --- /dev/null +++ b/src/world/map/CMapEntity.cpp @@ -0,0 +1,5 @@ +#include "world/map/CMapEntity.hpp" + +CMapEntity::CMapEntity() { + this->m_type |= CMapBaseObj::Type_Entity; +} diff --git a/src/world/map/CMapEntity.hpp b/src/world/map/CMapEntity.hpp index 156c4fd..82a080e 100644 --- a/src/world/map/CMapEntity.hpp +++ b/src/world/map/CMapEntity.hpp @@ -2,10 +2,22 @@ #define WORLD_MAP_C_MAP_ENTITY_HPP #include "world/map/CMapStaticEntity.hpp" +#include class CMapEntity : public CMapStaticEntity { public: + // Member variables + void* m_handler = nullptr; + void* m_handlerParam = nullptr; + uint64_t m_param64 = 0; + uint32_t m_param32 = 0; // TODO + CImVector m_ambientTarget = { 0xFF, 0x00, 0x00, 0x00 }; + float m_dirLightScaleTarget = 0.0f; + // TODO + + // Member functions + CMapEntity(); }; #endif diff --git a/src/world/map/CMapStaticEntity.hpp b/src/world/map/CMapStaticEntity.hpp index 917ea7f..efb8bcb 100644 --- a/src/world/map/CMapStaticEntity.hpp +++ b/src/world/map/CMapStaticEntity.hpp @@ -2,10 +2,19 @@ #define WORLD_MAP_C_MAP_STATIC_ENTITY_HPP #include "world/map/CMapBaseObj.hpp" +#include + +class CM2Model; class CMapStaticEntity : public CMapBaseObj { public: + // Member variables // TODO + CM2Model* m_model = nullptr; + // TODO + CImVector m_ambient = {}; + CImVector m_interiorDirColor = {}; + float m_dirLightScale = 0.0f; }; #endif