mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-01 00:02:45 +03:00
feat(object): add GarbageCollect
This commit is contained in:
parent
553a59c808
commit
012e97f410
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,10 @@ CGObject_C* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid) {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClntObjMgrFreeObject(CGObject_C* object) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
WOWGUID ClntObjMgrGetActivePlayer() {
|
WOWGUID ClntObjMgrGetActivePlayer() {
|
||||||
if (!s_curMgr) {
|
if (!s_curMgr) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -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();
|
||||||
|
|||||||
@ -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;
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user