Compare commits

...

12 Commits

Author SHA1 Message Date
Marco Tylus
84b71ff770
Merge 8935c520c0 into 5a8fb5e2d3 2026-01-19 14:40:45 +00:00
fallenoak
5a8fb5e2d3
feat(object): implement ClntObjMgrFreeObject
Some checks are pending
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:cl compiler_name:MSVC cxx:cl os:windows-latest system_name:Windows test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:clang compiler_name:Clang cxx:clang++ os:macos-latest system_name:macOS test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:gcc compiler_name:GCC cxx:g++ os:ubuntu-latest system_name:Linux test_path:WhoaTest]) (push) Waiting to run
2026-01-18 23:00:59 -06:00
fallenoak
305849b164
feat(object): add virtual dtors to base object classes 2026-01-18 23:00:34 -06:00
fallenoak
012e97f410
feat(object): add GarbageCollect 2026-01-18 19:50:07 -06:00
aomizu
8935c520c0 feat: Add texture matrix transform support to Metal shaders for animated textures 2025-12-26 17:03:37 +09:00
aomizu
7cf7127810 feat: Implement color animation in Metal shaders by using diffuse and emissive vertex constants for output color. 2025-12-25 15:11:18 +09:00
aomizu
8fb51991e0 revert: remove non-metal shader init from Client.cpp 2025-12-25 13:24:07 +09:00
aomizu
7fdd22545f feat: Convert GxTex_Argb4444 textures to RGBA8 during Metal upload to simplify handling 2025-12-25 13:10:25 +09:00
aomizu
15eafe92d7 feat: Implement fog and point size in Metal shaders and refine render state processing for textures and other states. 2025-12-25 13:10:25 +09:00
aomizu
1ad3679f90 feat: Implement initial Metal graphics device with comprehensive shader system and pipeline management. 2025-12-25 13:10:25 +09:00
aomizu
81970958a8 feat: Add debug rendering pipeline to draw a triangle in the Metal backend. 2025-12-25 13:10:25 +09:00
aomizu
a9cad5238d init metal backend 2025-12-25 13:10:25 +09:00
35 changed files with 2141 additions and 5 deletions

View File

@ -32,6 +32,8 @@ if(WHOA_SYSTEM_MAC)
"-framework AppKit" "-framework AppKit"
"-framework Carbon" "-framework Carbon"
"-framework IOKit" "-framework IOKit"
"-framework Metal"
"-framework QuartzCore"
) )
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mac/MainMenu.nib DESTINATION "bin") install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mac/MainMenu.nib DESTINATION "bin")

View File

@ -0,0 +1,9 @@
#ifndef APP_MAC_ENGINE_MTL_LAYER_VIEW_H
#define APP_MAC_ENGINE_MTL_LAYER_VIEW_H
#include "app/mac/EngineGLLayerView.h"
@interface EngineMTLLayerView : EngineGLLayerView
@end
#endif

View File

@ -0,0 +1,36 @@
#include "app/mac/EngineMTLLayerView.h"
#import <QuartzCore/CAMetalLayer.h>
@implementation EngineMTLLayerView
- (CALayer*)makeBackingLayer {
return [CAMetalLayer layer];
}
- (id)initWithFrame:(NSRect)frame glWindow:(GLWindow*)window {
self = [super initWithFrame:frame glWindow:window];
if (self) {
[self setWantsLayer:YES];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
// Rendering is driven by CGxDeviceMTL.
}
- (void)update {
[super update];
if (![self.layer isKindOfClass:[CAMetalLayer class]]) {
return;
}
CAMetalLayer* layer = (CAMetalLayer*)self.layer;
CGSize size = [self convertSizeToBacking:self.bounds.size];
layer.drawableSize = size;
}
@end

View File

@ -1,7 +1,9 @@
#include "app/mac/View.h" #include "app/mac/View.h"
#include "app/mac/EngineGLLayerView.h" #include "app/mac/EngineGLLayerView.h"
#include "app/mac/EngineMTLLayerView.h"
#include "app/mac/WindowCallbacks.h" #include "app/mac/WindowCallbacks.h"
#include "gx/gll/GLWindow.h" #include "gx/gll/GLWindow.h"
#include "gx/Device.hpp"
GLWindowCallbacks EngineViewCallbacks = { GLWindowCallbacks EngineViewCallbacks = {
&MacOnResized, &MacOnResized,
@ -23,5 +25,9 @@ void AssignEngineViewCallbacks(GLWindowCallbacks* callbacks) {
} }
Class GetEngineViewClass() { Class GetEngineViewClass() {
if (GxDevApi() == GxApi_Metal) {
return [EngineMTLLayerView class];
}
return [EngineGLLayerView class]; return [EngineGLLayerView class];
} }

View File

@ -2,6 +2,7 @@
#include "app/mac/MacClient.h" #include "app/mac/MacClient.h"
#include "event/Input.hpp" #include "event/Input.hpp"
#include "gx/gll/CGxDeviceGLL.hpp" #include "gx/gll/CGxDeviceGLL.hpp"
#include "gx/mtl/CGxDeviceMTL.hpp"
#include "gx/Device.hpp" #include "gx/Device.hpp"
#include "gx/Window.hpp" #include "gx/Window.hpp"
#include <bc/Debug.hpp> #include <bc/Debug.hpp>
@ -171,7 +172,11 @@ void MacOnResized(int32_t width, int32_t height, bool a3) {
return; return;
} }
static_cast<CGxDeviceGLL*>(g_theGxDevicePtr)->Resize(width, height); if (GxDevApi() == GxApi_GLL) {
static_cast<CGxDeviceGLL*>(g_theGxDevicePtr)->Resize(width, height);
} else if (GxDevApi() == GxApi_Metal) {
static_cast<CGxDeviceMTL*>(g_theGxDevicePtr)->Resize(width, height);
}
OsQueuePut(OS_INPUT_SIZE, width, height, 0, 0); OsQueuePut(OS_INPUT_SIZE, width, height, 0, 0);

View File

@ -6,6 +6,7 @@
#include "gx/Adapter.hpp" #include "gx/Adapter.hpp"
#include "gx/Device.hpp" #include "gx/Device.hpp"
#include <storm/Array.hpp> #include <storm/Array.hpp>
#include <cstdlib>
#include <cstring> #include <cstring>
static CGxDevice* s_device; static CGxDevice* s_device;
@ -417,6 +418,13 @@ void ConsoleDeviceInitialize(const char* title) {
api = GxApi_GLL; api = GxApi_GLL;
#endif #endif
#if defined(WHOA_SYSTEM_MAC)
const char* apiOverride = getenv("WHOA_GX_API");
if (apiOverride && !strcmp(apiOverride, "metal")) {
api = GxApi_Metal;
}
#endif
s_device = GxDevCreate(api, OsWindowProc, format); s_device = GxDevCreate(api, OsWindowProc, format);
// TODO // TODO

View File

@ -18,6 +18,7 @@
#if defined(WHOA_SYSTEM_MAC) #if defined(WHOA_SYSTEM_MAC)
#include "gx/gll/CGxDeviceGLL.hpp" #include "gx/gll/CGxDeviceGLL.hpp"
#include "gx/mtl/CGxDeviceMTL.hpp"
#include "gx/mac/Display.hpp" #include "gx/mac/Display.hpp"
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
#include <OpenGL/OpenGL.h> #include <OpenGL/OpenGL.h>
@ -117,6 +118,8 @@ int32_t CGxDevice::AdapterFormats(EGxApi api, TSGrowableArray<CGxFormat>& adapte
CGxDevice::OpenGlAdapterFormats(adapterFormats); CGxDevice::OpenGlAdapterFormats(adapterFormats);
} else if (api == GxApi_GLL) { } else if (api == GxApi_GLL) {
CGxDevice::GLLAdapterFormats(adapterFormats); CGxDevice::GLLAdapterFormats(adapterFormats);
} else if (api == GxApi_Metal) {
CGxDevice::OpenGlAdapterFormats(adapterFormats);
} }
#elif defined(WHOA_SYSTEM_LINUX) #elif defined(WHOA_SYSTEM_LINUX)
@ -228,6 +231,11 @@ CGxDevice* CGxDevice::NewGLL() {
auto m = SMemAlloc(sizeof(CGxDeviceGLL), __FILE__, __LINE__, 0x0); auto m = SMemAlloc(sizeof(CGxDeviceGLL), __FILE__, __LINE__, 0x0);
return new (m) CGxDeviceGLL(); return new (m) CGxDeviceGLL();
} }
CGxDevice* CGxDevice::NewMTL() {
auto m = SMemAlloc(sizeof(CGxDeviceMTL), __FILE__, __LINE__, 0x0);
return new (m) CGxDeviceMTL();
}
#endif #endif
CGxDevice* CGxDevice::NewOpenGl() { CGxDevice* CGxDevice::NewOpenGl() {

View File

@ -70,6 +70,7 @@ class CGxDevice {
#endif #endif
#if defined(WHOA_SYSTEM_MAC) #if defined(WHOA_SYSTEM_MAC)
static CGxDevice* NewGLL(); static CGxDevice* NewGLL();
static CGxDevice* NewMTL();
#endif #endif
static CGxDevice* NewOpenGl(); static CGxDevice* NewOpenGl();
static void OpenGlAdapterFormats(TSGrowableArray<CGxFormat>& adapterFormats); static void OpenGlAdapterFormats(TSGrowableArray<CGxFormat>& adapterFormats);

View File

@ -20,6 +20,7 @@ if(WHOA_SYSTEM_MAC)
file(GLOB MAC_SOURCES file(GLOB MAC_SOURCES
"gll/*.cpp" "gll/*.cpp"
"gll/*.mm" "gll/*.mm"
"mtl/*.mm"
"mac/*.cpp" "mac/*.cpp"
) )

View File

@ -24,6 +24,8 @@ CGxDevice* GxDevCreate(EGxApi api, int32_t (*windowProc)(void* window, uint32_t
device = CGxDevice::NewOpenGl(); device = CGxDevice::NewOpenGl();
} else if (api == GxApi_GLL) { } else if (api == GxApi_GLL) {
device = CGxDevice::NewGLL(); device = CGxDevice::NewGLL();
} else if (api == GxApi_Metal) {
device = CGxDevice::NewMTL();
} else { } else {
// Error // Error
} }

View File

@ -35,7 +35,8 @@ enum EGxApi {
GxApi_D3d10 = 3, GxApi_D3d10 = 3,
GxApi_D3d11 = 4, GxApi_D3d11 = 4,
GxApi_GLL = 5, GxApi_GLL = 5,
GxApis_Last = 6 GxApi_Metal = 6,
GxApis_Last = 7
}; };
enum EGxBlend { enum EGxBlend {

View File

@ -0,0 +1,81 @@
#ifndef GX_MTL_C_GX_DEVICE_MTL_HPP
#define GX_MTL_C_GX_DEVICE_MTL_HPP
#include "gx/CGxDevice.hpp"
#include "gx/gll/GLWindow.h"
class CGxBatch;
class CGxShader;
class CGxDeviceMTL : public CGxDevice {
public:
// Member variables
GLWindow m_window;
// Virtual member functions
void ITexMarkAsUpdated(CGxTex*) override;
void IRsSendToHw(EGxRenderState) override;
int32_t DeviceCreate(int32_t (*windowProc)(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam), const CGxFormat&) override;
int32_t DeviceSetFormat(const CGxFormat&) override;
void* DeviceWindow() override;
void DeviceWM(EGxWM wm, uintptr_t param1, uintptr_t param2) override {};
void CapsWindowSize(CRect&) override;
void CapsWindowSizeInScreenCoords(CRect& dst) override;
void ScenePresent() override;
void SceneClear(uint32_t, CImVector) override;
void Draw(CGxBatch* batch, int32_t indexed) override;
void PoolSizeSet(CGxPool*, uint32_t) override;
char* BufLock(CGxBuf*) override;
int32_t BufUnlock(CGxBuf*, uint32_t) override;
void BufData(CGxBuf* buf, const void* data, size_t size, uintptr_t offset) override;
void TexDestroy(CGxTex* texId) override;
void IShaderCreate(CGxShader*) override;
void ShaderCreate(CGxShader*[], EGxShTarget, const char*, const char*, int32_t) override;
int32_t StereoEnabled(void) override;
void XformSetProjection(const C44Matrix& matrix) override;
// Member functions
CGxDeviceMTL();
void Resize(uint32_t width, uint32_t height);
private:
void ISetCaps(const CGxFormat& format);
void EnsureLibrary();
void BeginFrame();
void* GetPipeline(EGxVertexBufferFormat format, bool useColor, bool useSkin, bool useTex, int32_t blendMode);
void* GetPoolBuffer(CGxPool* pool);
void ITexCreate(CGxTex* texId);
void ITexUpload(CGxTex* texId);
void* GetTexture(CGxTex* texId);
void* GetSampler(CGxTex* texId);
void EnsureFallbackTexture();
void EnsureDepthTexture(uint32_t width, uint32_t height);
void* GetDepthState(bool depthTest, bool depthWrite, uint32_t depthFunc);
void* m_device = nullptr;
void* m_commandQueue = nullptr;
void* m_layer = nullptr;
void* m_shaderLibrary = nullptr;
void* m_pipelineColor[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_pipelineSolid[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_pipelineSkin[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_pipelineColorTex[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_pipelineSolidTex[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_pipelineSkinTex[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_pipelineColorTex2[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_pipelineSolidTex2[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_pipelineSkinTex2[GxVertexBufferFormats_Last][GxBlends_Last] = {};
void* m_frameCommandBuffer = nullptr;
void* m_frameEncoder = nullptr;
void* m_frameDrawable = nullptr;
uint32_t m_frameHasDraw = 0;
uint32_t m_clearMask = 0;
uint32_t m_clearColor = 0;
void* m_fallbackTexture = nullptr;
void* m_fallbackSampler = nullptr;
void* m_depthTexture = nullptr;
uint32_t m_depthWidth = 0;
uint32_t m_depthHeight = 0;
void* m_depthStates[2][2][4] = {};
};
#endif

1855
src/gx/mtl/CGxDeviceMTL.mm Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,10 @@ CGContainer_C::CGContainer_C(uint32_t time, CClientObjCreate& objCreate) : CGIte
// TODO // TODO
} }
CGContainer_C::~CGContainer_C() {
// TODO
}
void CGContainer_C::SetStorage(uint32_t* storage, uint32_t* saved) { void CGContainer_C::SetStorage(uint32_t* storage, uint32_t* saved) {
this->CGItem_C::SetStorage(storage, saved); this->CGItem_C::SetStorage(storage, saved);

View File

@ -7,6 +7,9 @@
class CGContainer_C : public CGItem_C, public CGContainer { class CGContainer_C : public CGItem_C, public CGContainer {
public: public:
// Virtual public member functions
virtual ~CGContainer_C();
// Public member functions // Public member functions
CGContainer_C(uint32_t time, CClientObjCreate& objCreate); CGContainer_C(uint32_t time, CClientObjCreate& objCreate);
void SetStorage(uint32_t* storage, uint32_t* saved); void SetStorage(uint32_t* storage, uint32_t* saved);

View File

@ -4,6 +4,10 @@ CGCorpse_C::CGCorpse_C(uint32_t time, CClientObjCreate& objCreate) : CGObject_C(
// TODO // TODO
} }
CGCorpse_C::~CGCorpse_C() {
// TODO
}
void CGCorpse_C::SetStorage(uint32_t* storage, uint32_t* saved) { void CGCorpse_C::SetStorage(uint32_t* storage, uint32_t* saved) {
this->CGObject_C::SetStorage(storage, saved); this->CGObject_C::SetStorage(storage, saved);

View File

@ -7,6 +7,9 @@
class CGCorpse_C : public CGObject_C, public CGCorpse { class CGCorpse_C : public CGObject_C, public CGCorpse {
public: public:
// Virtual public member functions
virtual ~CGCorpse_C();
// Public member functions // Public member functions
CGCorpse_C(uint32_t time, CClientObjCreate& objCreate); CGCorpse_C(uint32_t time, CClientObjCreate& objCreate);
void SetStorage(uint32_t* storage, uint32_t* saved); void SetStorage(uint32_t* storage, uint32_t* saved);

View File

@ -4,6 +4,10 @@ CGDynamicObject_C::CGDynamicObject_C(uint32_t time, CClientObjCreate& objCreate)
// TODO // TODO
} }
CGDynamicObject_C::~CGDynamicObject_C() {
// TODO
}
void CGDynamicObject_C::SetStorage(uint32_t* storage, uint32_t* saved) { void CGDynamicObject_C::SetStorage(uint32_t* storage, uint32_t* saved) {
this->CGObject_C::SetStorage(storage, saved); this->CGObject_C::SetStorage(storage, saved);

View File

@ -7,6 +7,9 @@
class CGDynamicObject_C : public CGObject_C, public CGDynamicObject { class CGDynamicObject_C : public CGObject_C, public CGDynamicObject {
public: public:
// Virtual public member functions
virtual ~CGDynamicObject_C();
// Public member functions // Public member functions
CGDynamicObject_C(uint32_t time, CClientObjCreate& objCreate); CGDynamicObject_C(uint32_t time, CClientObjCreate& objCreate);
void SetStorage(uint32_t* storage, uint32_t* saved); void SetStorage(uint32_t* storage, uint32_t* saved);

View File

@ -4,6 +4,10 @@ CGGameObject_C::CGGameObject_C(uint32_t time, CClientObjCreate& objCreate) : CGO
// TODO // TODO
} }
CGGameObject_C::~CGGameObject_C() {
// TODO
}
void CGGameObject_C::SetStorage(uint32_t* storage, uint32_t* saved) { void CGGameObject_C::SetStorage(uint32_t* storage, uint32_t* saved) {
this->CGObject_C::SetStorage(storage, saved); this->CGObject_C::SetStorage(storage, saved);

View File

@ -7,6 +7,9 @@
class CGGameObject_C : public CGObject_C, public CGGameObject { class CGGameObject_C : public CGObject_C, public CGGameObject {
public: public:
// Virtual public member functions
virtual ~CGGameObject_C();
// Public member functions // Public member functions
CGGameObject_C(uint32_t time, CClientObjCreate& objCreate); CGGameObject_C(uint32_t time, CClientObjCreate& objCreate);
void SetStorage(uint32_t* storage, uint32_t* saved); void SetStorage(uint32_t* storage, uint32_t* saved);

View File

@ -4,6 +4,10 @@ CGItem_C::CGItem_C(uint32_t time, CClientObjCreate& objCreate) : CGObject_C(time
// TODO // TODO
} }
CGItem_C::~CGItem_C() {
// TODO
}
void CGItem_C::SetStorage(uint32_t* storage, uint32_t* saved) { void CGItem_C::SetStorage(uint32_t* storage, uint32_t* saved) {
this->CGObject_C::SetStorage(storage, saved); this->CGObject_C::SetStorage(storage, saved);

View File

@ -7,6 +7,9 @@
class CGItem_C : public CGObject_C, public CGItem { class CGItem_C : public CGObject_C, public CGItem {
public: public:
// Virtual public member functions
virtual ~CGItem_C();
// Public member functions // Public member functions
CGItem_C(uint32_t time, CClientObjCreate& objCreate); CGItem_C(uint32_t time, CClientObjCreate& objCreate);
void SetStorage(uint32_t* storage, uint32_t* saved); void SetStorage(uint32_t* storage, uint32_t* saved);

View File

@ -19,6 +19,10 @@ CGObject_C::CGObject_C(uint32_t time, CClientObjCreate& objCreate) {
// TODO // TODO
} }
CGObject_C::~CGObject_C() {
// TODO
}
void CGObject_C::AddWorldObject() { void CGObject_C::AddWorldObject() {
// TODO // TODO
} }

View File

@ -23,7 +23,7 @@ class CGObject_C : public CGObject, public TSHashObject<CGObject_C, CHashKeyGUID
// TODO // TODO
// Virtual public member functions // Virtual public member functions
// TODO virtual ~CGObject_C();
virtual void Disable(); virtual void Disable();
// TODO // TODO
virtual void HandleOutOfRange(OUT_OF_RANGE_TYPE type) {}; virtual void HandleOutOfRange(OUT_OF_RANGE_TYPE type) {};

View File

@ -7,6 +7,10 @@ CGPlayer_C::CGPlayer_C(uint32_t time, CClientObjCreate& objCreate) : CGUnit_C(ti
// TODO // TODO
} }
CGPlayer_C::~CGPlayer_C() {
// TODO
}
void CGPlayer_C::SetStorage(uint32_t* storage, uint32_t* saved) { void CGPlayer_C::SetStorage(uint32_t* storage, uint32_t* saved) {
this->CGUnit_C::SetStorage(storage, saved); this->CGUnit_C::SetStorage(storage, saved);

View File

@ -10,6 +10,9 @@ class CreatureModelDataRec;
class CGPlayer_C : public CGUnit_C, public CGPlayer { class CGPlayer_C : public CGUnit_C, public CGPlayer {
public: public:
// Virtual public member functions
virtual ~CGPlayer_C();
// Public member functions // Public member functions
CGPlayer_C(uint32_t time, CClientObjCreate& objCreate); CGPlayer_C(uint32_t time, CClientObjCreate& objCreate);
void SetStorage(uint32_t* storage, uint32_t* saved); void SetStorage(uint32_t* storage, uint32_t* saved);

View File

@ -93,6 +93,10 @@ CGUnit_C::CGUnit_C(uint32_t time, CClientObjCreate& objCreate) : CGObject_C(time
// TODO // TODO
} }
CGUnit_C::~CGUnit_C() {
// TODO
}
void CGUnit_C::SetStorage(uint32_t* storage, uint32_t* saved) { void CGUnit_C::SetStorage(uint32_t* storage, uint32_t* saved) {
this->CGObject_C::SetStorage(storage, saved); this->CGObject_C::SetStorage(storage, saved);

View File

@ -15,6 +15,9 @@ class CGUnit_C : public CGObject_C, public CGUnit {
static const char* GetDisplayClassNameFromRecord(const ChrClassesRec* classRec, UNIT_SEX sex, UNIT_SEX* displaySex); static const char* GetDisplayClassNameFromRecord(const ChrClassesRec* classRec, UNIT_SEX sex, UNIT_SEX* displaySex);
static const char* GetDisplayRaceNameFromRecord(const ChrRacesRec* raceRec, UNIT_SEX sex, UNIT_SEX* displaySex); static const char* GetDisplayRaceNameFromRecord(const ChrRacesRec* raceRec, UNIT_SEX sex, UNIT_SEX* displaySex);
// Virtual public member functions
virtual ~CGUnit_C();
// Public member functions // Public member functions
CGUnit_C(uint32_t time, CClientObjCreate& objCreate); CGUnit_C(uint32_t time, CClientObjCreate& objCreate);
void SetStorage(uint32_t* storage, uint32_t* saved); void SetStorage(uint32_t* storage, uint32_t* saved);

View File

@ -384,6 +384,8 @@ int32_t ObjectUpdateHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataS
uint32_t updateCount; uint32_t updateCount;
msg->Get(updateCount); msg->Get(updateCount);
// If first update type is out of range, handle it before continuing with normal processing
auto startPos = msg->Tell(); auto startPos = msg->Tell();
uint8_t firstUpdateType; uint8_t firstUpdateType;
@ -398,6 +400,8 @@ int32_t ObjectUpdateHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataS
msg->Seek(startPos); msg->Seek(startPos);
} }
// Process all updates in two passes (creates, updates and disables objects as appropriate)
int32_t result = 0; int32_t result = 0;
if (ObjectUpdateFirstPass(msg, time, updateIdx, updateCount)) { if (ObjectUpdateFirstPass(msg, time, updateIdx, updateCount)) {
@ -405,7 +409,11 @@ int32_t ObjectUpdateHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataS
result = ObjectUpdateSecondPass(msg, time, updateCount); result = ObjectUpdateSecondPass(msg, time, updateCount);
} }
// TODO // Garbage collect objects disabled more than 2 minutes ago (catch all)
for (int32_t typeID = ID_OBJECT; typeID < NUM_CLIENT_OBJECT_TYPES; typeID++) {
GarbageCollect(static_cast<OBJECT_TYPE_ID>(typeID), 120000);
}
return result; return result;
} }

View File

@ -75,7 +75,7 @@ CGObject_C* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid) {
return static_cast<CGObject_C*>(STORM_ALLOC(sizeof(CGPlayer_C) + CGPlayer::GetDataSize() + CGPlayer::GetDataSizeSaved())); return static_cast<CGObject_C*>(STORM_ALLOC(sizeof(CGPlayer_C) + CGPlayer::GetDataSize() + CGPlayer::GetDataSizeSaved()));
} }
// TODO GarbageCollect(typeID, 10000); GarbageCollect(typeID, 10000);
uint32_t memHandle; uint32_t memHandle;
void* mem; void* mem;
@ -91,6 +91,36 @@ CGObject_C* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid) {
return object; return object;
} }
void ClntObjMgrFreeObject(CGObject_C* object) {
auto playerGUID = ClntObjMgrGetActivePlayer();
auto isActivePlayer = object->m_obj->m_guid == playerGUID;
switch (object->m_obj->m_type) {
case TYPE_OBJECT:
case HIER_TYPE_ITEM:
case HIER_TYPE_CONTAINER:
case HIER_TYPE_UNIT:
case HIER_TYPE_PLAYER:
case HIER_TYPE_GAMEOBJECT:
case HIER_TYPE_DYNAMICOBJECT:
case HIER_TYPE_CORPSE: {
object->~CGObject_C();
break;
}
default: {
break;
}
}
if (isActivePlayer) {
STORM_FREE(object);
} else {
ObjectFree(s_objHeapId[object->m_typeID], object->m_memHandle);
}
}
WOWGUID ClntObjMgrGetActivePlayer() { WOWGUID ClntObjMgrGetActivePlayer() {
if (!s_curMgr) { if (!s_curMgr) {
return 0; return 0;

View File

@ -10,6 +10,8 @@ CGObject_C* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid);
WOWGUID ClntObjMgrGetActivePlayer(); WOWGUID ClntObjMgrGetActivePlayer();
void ClntObjMgrFreeObject(CGObject_C* object);
ClntObjMgr* ClntObjMgrGetCurrent(); ClntObjMgr* ClntObjMgrGetCurrent();
uint32_t ClntObjMgrGetMapID(); uint32_t ClntObjMgrGetMapID();

View File

@ -9,11 +9,35 @@
#include "object/client/CGPlayer_C.hpp" #include "object/client/CGPlayer_C.hpp"
#include "object/client/CGUnit_C.hpp" #include "object/client/CGUnit_C.hpp"
#include "object/client/ObjMgr.hpp" #include "object/client/ObjMgr.hpp"
#include <common/Time.hpp>
CGObject_C* FindActiveObject(WOWGUID guid) { CGObject_C* FindActiveObject(WOWGUID guid) {
return ClntObjMgrGetCurrent()->m_objects.Ptr(guid, CHashKeyGUID(guid)); return ClntObjMgrGetCurrent()->m_objects.Ptr(guid, CHashKeyGUID(guid));
} }
/**
* Given an object type and collection age, free the object at the head of that type's FIFO queue
* if it was disabled longer ago than the collection age. Only frees at most one object per call.
*/
void GarbageCollect(OBJECT_TYPE_ID typeID, uint32_t collectAgeMs) {
auto object = ClntObjMgrGetCurrent()->m_lazyCleanupFifo[typeID - 1].Head();
if (!object) {
return;
}
uint32_t disableAgeMs = OsGetAsyncTimeMsPrecise() - object->m_disableTimeMs;
if (disableAgeMs < collectAgeMs) {
return;
}
ClntObjMgrGetCurrent()->m_lazyCleanupObjects.Unlink(object);
object->m_link.Unlink();
ClntObjMgrFreeObject(object);
}
CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenable) { CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenable) {
*reenable = false; *reenable = false;

View File

@ -10,6 +10,8 @@ class CGObject_C;
CGObject_C* FindActiveObject(WOWGUID guid); CGObject_C* FindActiveObject(WOWGUID guid);
void GarbageCollect(OBJECT_TYPE_ID typeID, uint32_t collectAgeMs);
CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenable); CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenable);
int32_t HandleObjectOutOfRangePass1(CGObject_C* object, OUT_OF_RANGE_TYPE type); int32_t HandleObjectOutOfRangePass1(CGObject_C* object, OUT_OF_RANGE_TYPE type);

View File

@ -22,6 +22,8 @@ if(WHOA_SYSTEM_MAC)
"-framework AppKit" "-framework AppKit"
"-framework Carbon" "-framework Carbon"
"-framework IOKit" "-framework IOKit"
"-framework Metal"
"-framework QuartzCore"
) )
endif() endif()