diff --git a/src/client/Client.cpp b/src/client/Client.cpp index a6a2796..6d1874c 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -80,6 +80,7 @@ int32_t ClientIdle(const void* data, void* param) { void ClientInitializeGame(uint32_t mapId, C3Vector position) { // TODO + ClntObjMgrInitializeShared(); ClntObjMgrInitializeStd(mapId); // TODO diff --git a/src/object/Types.hpp b/src/object/Types.hpp index 9db5ede..0997b17 100644 --- a/src/object/Types.hpp +++ b/src/object/Types.hpp @@ -38,6 +38,31 @@ enum INVENTORY_SLOTS { NUM_BAG_SLOTS = INVSLOT_BAGLAST - INVSLOT_BAGFIRST + 1, }; +enum OBJECT_TYPE { + TYPE_OBJECT = 0x1, + TYPE_ITEM = 0x2, + TYPE_CONTAINER = 0x4, + TYPE_UNIT = 0x8, + TYPE_PLAYER = 0x10, + TYPE_GAMEOBJECT = 0x20, + TYPE_DYNAMICOBJECT = 0x40, + TYPE_CORPSE = 0x80, + // TODO +}; + +enum OBJECT_TYPE_ID { + ID_OBJECT = 0, + ID_ITEM = 1, + ID_CONTAINER = 2, + ID_UNIT = 3, + ID_PLAYER = 4, + ID_GAMEOBJECT = 5, + ID_DYNAMICOBJECT = 6, + ID_CORPSE = 7, + NUM_CLIENT_OBJECT_TYPES, + // TODO +}; + enum SHEATHE_TYPE { SHEATHE_0 = 0, SHEATHE_1 = 1, diff --git a/src/object/client/ObjMgr.cpp b/src/object/client/ObjMgr.cpp index 95d50d2..88bbcbf 100644 --- a/src/object/client/ObjMgr.cpp +++ b/src/object/client/ObjMgr.cpp @@ -1,15 +1,69 @@ #include "object/client/ObjMgr.hpp" #include "client/ClientServices.hpp" +#include "console/Command.hpp" #include "net/Connection.hpp" +#include "object/client/CGContainer_C.hpp" +#include "object/client/CGCorpse_C.hpp" +#include "object/client/CGDynamicObject_C.hpp" +#include "object/client/CGGameObject_C.hpp" +#include "object/client/CGItem_C.hpp" +#include "object/client/CGObject_C.hpp" +#include "object/client/CGPlayer_C.hpp" +#include "object/client/CGUnit_C.hpp" +#include "util/Unimplemented.hpp" +#include #include +static bool s_heapsAllocated; +static uint32_t s_objHeapId[8]; +static ClntObjMgr* s_savMgr; + #if defined(WHOA_SYSTEM_WIN) static thread_local ClntObjMgr* s_curMgr; #else static ClntObjMgr* s_curMgr; #endif -static ClntObjMgr* s_savMgr; +static uint32_t s_objTotalSize[] = { + static_cast(sizeof(CGObject_C) + sizeof(CGObjectData) + (sizeof(uint32_t) * CGObject::TotalFieldsSaved())), + static_cast(sizeof(CGItem_C) + sizeof(CGItemData) + (sizeof(uint32_t) * CGItem::TotalFieldsSaved())), + static_cast(sizeof(CGContainer_C) + sizeof(CGContainerData) + (sizeof(uint32_t) * CGContainer::TotalFieldsSaved())), + static_cast(sizeof(CGUnit_C) + sizeof(CGUnitData) + (sizeof(uint32_t) * CGUnit::TotalFieldsSaved())), + static_cast(sizeof(CGPlayer_C) + sizeof(CGPlayerData) + (sizeof(uint32_t) * CGPlayer::TotalFieldsSaved())), + static_cast(sizeof(CGGameObject_C) + sizeof(CGGameObjectData) + (sizeof(uint32_t) * CGGameObject::TotalFieldsSaved())), + static_cast(sizeof(CGDynamicObject_C) + sizeof(CGDynamicObjectData) + (sizeof(uint32_t) * CGDynamicObject::TotalFieldsSaved())), + static_cast(sizeof(CGCorpse_C) + sizeof(CGCorpseData) + (sizeof(uint32_t) * CGCorpse::TotalFieldsSaved())), +}; + +static const char* s_objNames[] = { + "CGObject_C", + "CGItem_C", + "CGContainer_C", + "CGUnit_C", + "CGPlayer_C", + "CGGameObject_C", + "CGDynamicObject_C", + "CGCorpse_C", +}; + +static uint32_t s_heapSizes[] = { + 0, + 512, + 32, + 64, + 64, + 64, + 32, + 32, +}; + +int32_t CCommand_ObjUsage(const char* command, const char* arguments) { + WHOA_UNIMPLEMENTED(0); +} + +void MirrorInitialize() { + // TODO +} uint64_t ClntObjMgrGetActivePlayer() { if (!s_curMgr) { @@ -31,6 +85,20 @@ uint32_t ClntObjMgrGetMapID() { return s_curMgr->m_mapID; } +void ClntObjMgrInitializeShared() { + if (!s_heapsAllocated) { + for (int32_t i = ID_ITEM; i < NUM_CLIENT_OBJECT_TYPES; i++) { + s_objHeapId[i] = ObjectAllocAddHeap(s_objTotalSize[i], s_heapSizes[i], s_objNames[i], true); + } + + s_heapsAllocated = true; + } + + MirrorInitialize(); + + ConsoleCommandRegister("ObjUsage", &CCommand_ObjUsage, GAME, nullptr); +} + void ClntObjMgrInitializeStd(uint32_t mapID) { // TODO last instance time diff --git a/src/object/client/ObjMgr.hpp b/src/object/client/ObjMgr.hpp index 33a2a08..b0a392c 100644 --- a/src/object/client/ObjMgr.hpp +++ b/src/object/client/ObjMgr.hpp @@ -10,6 +10,8 @@ ClntObjMgr* ClntObjMgrGetCurrent(); uint32_t ClntObjMgrGetMapID(); +void ClntObjMgrInitializeShared(); + void ClntObjMgrInitializeStd(uint32_t mapID); void ClntObjMgrPop();