Compare commits

..

18 Commits

Author SHA1 Message Date
Tristan 'Natrist' Cormier
6262f1fa52
Merge 4a102c6ace into 553a59c808 2026-01-18 06:33:10 +01:00
fallenoak
553a59c808
chore(object): tidy up return type for ClntObjMgrAllocObject
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-17 20:34:46 -06:00
fallenoak
2efef87898
feat(object): set disable time in CGObject_C::Disable 2026-01-17 20:29:40 -06:00
fallenoak
c92f1b8de8
feat(world): add time handling functions to CWorld 2026-01-17 19:20:30 -06:00
fallenoak
c9aaa245c9
feat(event): dispatch tick events in main processing loop
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-16 19:33:17 -06:00
fallenoak
43dcfae6b0
feat(object): add type-specific cleanup queues to ClntObjMgr 2026-01-16 16:56:27 -06:00
fallenoak
0b0b7927aa
feat(object): set disabled flag in CGObject_C::Disable
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-16 08:41:50 -06:00
fallenoak
de2bea7129
feat(object): implement UpdateOutOfRangeObjects 2026-01-15 22:49:24 -06:00
fallenoak
ccca191048
feat(object): implement OnObjectDestroy 2026-01-15 21:41:06 -06:00
fallenoak
cd3585ca42
feat(object): add HandleObjectOutOfRangePass2 2026-01-15 21:24:45 -06:00
fallenoak
13ec1d7eef
feat(object): add HandleObjectOutOfRangePass1 2026-01-15 21:04:43 -06:00
fallenoak
f4ca99ac15
feat(object): add OUT_OF_RANGE_TYPE 2026-01-15 20:15:29 -06:00
fallenoak
ca3888f38e
feat(object): add CGObject_C::SetObjectLocked 2026-01-15 16:31:42 -06:00
fallenoak
a1541725f2
feat(object): add CGObject_C::IsObjectLocked 2026-01-15 16:27:40 -06:00
fallenoak
ba0baf1688
feat(object): add CGObject_C::IsInReenable 2026-01-15 16:24:45 -06:00
fallenoak
a43ab56644
feat(object): partially implement CGObject_C::Reenable 2026-01-15 16:21:41 -06:00
fallenoak
e2bfef907a
chore(object): rename parameter for clarity 2026-01-15 16:00:30 -06:00
fallenoak
361d327f30
feat(object): implement CGObject_C::SetDisablePending 2026-01-15 15:57:17 -06:00
16 changed files with 303 additions and 32 deletions

View File

@ -520,8 +520,9 @@ void WowClientDestroy() {
} }
void WowClientInit() { void WowClientInit() {
EventRegister(EVENT_ID_TICK, reinterpret_cast<EVENTHANDLERFUNC>(&CWorld::OnTick));
// TODO // TODO
// EventRegister(EVENT_ID_5, (int)sub_4020E0);
// _cfltcvt_init_0(); // _cfltcvt_init_0();
ClientRegisterConsoleCommands(); ClientRegisterConsoleCommands();

View File

@ -286,12 +286,10 @@ int32_t SchedulerThreadProcProcess(uint32_t a1) {
} }
} }
uint32_t v9 = (currTime - context->m_schedLastIdle); float elapsedSec = (currTime - context->m_schedLastIdle) * 0.001;
context->m_schedLastIdle = currTime; context->m_schedLastIdle = currTime;
double elapsedSec = v9 * 0.001;
// TODO SynthesizeTick(context, currTime, elapsedSec);
// FrameTime::Update(currTime, elapsedSec);
IEvtTimerDispatch(context); IEvtTimerDispatch(context);

View File

@ -91,3 +91,17 @@ void SynthesizePoll(EvtContext* context) {
IEvtQueueDispatch(context, EVENT_ID_POLL, nullptr); IEvtQueueDispatch(context, EVENT_ID_POLL, nullptr);
} }
void SynthesizeTick(EvtContext* context, uint32_t currTime, float elapsedSec) {
context->m_critsect.Enter();
bool closed = context->m_schedState == EvtContext::SCHEDSTATE_CLOSED;
context->m_critsect.Leave();
if (closed) {
return;
}
EVENT_DATA_TICK data = { elapsedSec, currTime };
IEvtQueueDispatch(context, EVENT_ID_TICK, &data);
}

View File

@ -15,4 +15,6 @@ void SynthesizePaint(EvtContext* context);
void SynthesizePoll(EvtContext* context); void SynthesizePoll(EvtContext* context);
void SynthesizeTick(EvtContext* context, uint32_t currTime, float elapsedSec);
#endif #endif

View File

@ -12,7 +12,7 @@ enum EVENTID {
EVENT_ID_FOCUS = 2, EVENT_ID_FOCUS = 2,
EVENT_ID_CLOSE = 3, EVENT_ID_CLOSE = 3,
EVENT_ID_DESTROY = 4, EVENT_ID_DESTROY = 4,
EVENT_ID_5 = 5, EVENT_ID_TICK = 5,
EVENT_ID_IDLE = 6, EVENT_ID_IDLE = 6,
EVENT_ID_POLL = 7, EVENT_ID_POLL = 7,
EVENT_ID_INITIALIZE = 8, EVENT_ID_INITIALIZE = 8,
@ -259,4 +259,9 @@ struct EVENT_DATA_SIZE {
int32_t h; int32_t h;
}; };
struct EVENT_DATA_TICK {
float tickTimeSec;
uint32_t curTimeMs;
};
#endif #endif

View File

@ -72,6 +72,12 @@ enum OBJECT_TYPE_ID {
// TODO // TODO
}; };
enum OUT_OF_RANGE_TYPE {
OUT_OF_RANGE_0 = 0,
OUT_OF_RANGE_1 = 1,
OUT_OF_RANGE_2 = 2,
};
enum SHEATHE_TYPE { enum SHEATHE_TYPE {
SHEATHE_0 = 0, SHEATHE_0 = 0,
SHEATHE_1 = 1, SHEATHE_1 = 1,

View File

@ -1,9 +1,19 @@
#include "object/client/CGObject_C.hpp" #include "object/client/CGObject_C.hpp"
#include "object/client/ObjMgr.hpp" #include "object/client/ObjMgr.hpp"
#include "world/World.hpp"
CGObject_C::CGObject_C(uint32_t time, CClientObjCreate& objCreate) { CGObject_C::CGObject_C(uint32_t time, CClientObjCreate& objCreate) {
// TODO // TODO
this->m_lockCount = 0;
this->m_disabled = false;
this->m_inReenable = false;
this->m_postInited = false;
this->m_flag19 = false;
this->m_disablePending = false;
// TODO
ClntObjMgrLinkInNewObject(this); ClntObjMgrLinkInNewObject(this);
// TODO // TODO
@ -13,7 +23,27 @@ void CGObject_C::AddWorldObject() {
// TODO // TODO
} }
void CGObject_C::Disable() {
// TODO
this->m_disabled = true;
// TODO other flag manipulation
this->m_disableTimeMs = CWorld::GetCurTimeMs();
}
int32_t CGObject_C::IsInReenable() {
return this->m_inReenable;
}
int32_t CGObject_C::IsObjectLocked() {
return this->m_lockCount != 0;
}
void CGObject_C::Reenable() { void CGObject_C::Reenable() {
this->m_disabled = false;
this->m_inReenable = true;
// TODO // TODO
} }
@ -23,7 +53,23 @@ void CGObject_C::SetBlock(uint32_t block, uint32_t value) {
} }
void CGObject_C::SetDisablePending(int32_t pending) { void CGObject_C::SetDisablePending(int32_t pending) {
// TODO if (pending) {
this->m_disablePending = true;
} else {
this->m_disablePending = false;
}
}
void CGObject_C::SetObjectLocked(int32_t locked) {
if (locked) {
if (this->m_lockCount != 0xFFFF) {
this->m_lockCount++;
}
} else {
if (this->m_lockCount != 0) {
this->m_lockCount--;
}
}
} }
void CGObject_C::SetStorage(uint32_t* storage, uint32_t* saved) { void CGObject_C::SetStorage(uint32_t* storage, uint32_t* saved) {

View File

@ -12,14 +12,33 @@ class CGObject_C : public CGObject, public TSHashObject<CGObject_C, CHashKeyGUID
public: public:
// Public member variables // Public member variables
TSLink<CGObject_C> m_link; TSLink<CGObject_C> m_link;
uint32_t m_disableTimeMs;
// TODO
uint32_t m_lockCount : 16;
uint32_t m_disabled : 1;
uint32_t m_inReenable : 1;
uint32_t m_postInited : 1;
uint32_t m_flag19 : 1;
uint32_t m_disablePending : 1;
// TODO
// Virtual public member functions
// TODO
virtual void Disable();
// TODO
virtual void HandleOutOfRange(OUT_OF_RANGE_TYPE type) {};
// TODO
// Public member functions // Public member functions
CGObject_C() = default; CGObject_C() = default;
CGObject_C(uint32_t time, CClientObjCreate& objCreate); CGObject_C(uint32_t time, CClientObjCreate& objCreate);
void AddWorldObject(); void AddWorldObject();
int32_t IsInReenable();
int32_t IsObjectLocked();
void Reenable(); void Reenable();
void SetBlock(uint32_t block, uint32_t value); void SetBlock(uint32_t block, uint32_t value);
void SetDisablePending(int32_t pending); void SetDisablePending(int32_t pending);
void SetObjectLocked(int32_t locked);
void SetStorage(uint32_t* storage, uint32_t* saved); void SetStorage(uint32_t* storage, uint32_t* saved);
void SetTypeID(OBJECT_TYPE_ID typeID); void SetTypeID(OBJECT_TYPE_ID typeID);
}; };

View File

@ -13,7 +13,7 @@ class ClntObjMgr {
// Member variables // Member variables
TSHashTable<CGObject_C, CHashKeyGUID> m_objects; TSHashTable<CGObject_C, CHashKeyGUID> m_objects;
TSHashTable<CGObject_C, CHashKeyGUID> m_lazyCleanupObjects; TSHashTable<CGObject_C, CHashKeyGUID> m_lazyCleanupObjects;
// TODO STORM_EXPLICIT_LIST(CGObject_C, m_link) m_lazyCleanupFifo[NUM_CLIENT_OBJECT_TYPES - 1];
STORM_EXPLICIT_LIST(CGObject_C, m_link) m_visibleObjects; STORM_EXPLICIT_LIST(CGObject_C, m_link) m_visibleObjects;
STORM_EXPLICIT_LIST(CGObject_C, m_link) m_reenabledObjects; STORM_EXPLICIT_LIST(CGObject_C, m_link) m_reenabledObjects;
// TODO // TODO

View File

@ -34,22 +34,65 @@ int32_t SkipPartialObjectUpdate(CDataStore* msg) {
} }
void UpdateOutOfRangeObjects(CDataStore* msg) { void UpdateOutOfRangeObjects(CDataStore* msg) {
WHOA_UNIMPLEMENTED(); uint32_t count;
msg->Get(count);
// TODO CVehiclePassenger_C::StartAddingPendingRescueTransitions();
auto startPos = msg->Tell();
// Pass 1
for (int32_t i = 0; i < count; i++) {
SmartGUID guid;
*msg >> guid;
if (guid == ClntObjMgrGetActivePlayer()) {
continue;
}
auto object = FindActiveObject(guid);
if (object) {
HandleObjectOutOfRangePass1(object, OUT_OF_RANGE_0);
}
}
msg->Seek(startPos);
// Pass 2
for (int32_t i = 0; i < count; i++) {
SmartGUID guid;
*msg >> guid;
if (guid == ClntObjMgrGetActivePlayer()) {
continue;
}
auto object = FindActiveObject(guid);
if (object && !object->IsObjectLocked()) {
HandleObjectOutOfRangePass2(object);
}
}
// TODO CVehiclePassenger_C::ExecutePendingRescueTransitions();
} }
int32_t UpdateObject(CDataStore* msg) { int32_t UpdateObject(CDataStore* msg) {
SmartGUID guid; SmartGUID guid;
*msg >> guid; *msg >> guid;
int32_t reenabled; int32_t reenable;
auto object = GetUpdateObject(guid, &reenabled); auto object = GetUpdateObject(guid, &reenable);
if (object) { if (object) {
if (!FillInPartialObjectData(object, object->m_obj->m_guid, msg, false, false)) { if (!FillInPartialObjectData(object, object->m_obj->m_guid, msg, false, false)) {
return 0; return 0;
} }
if (reenabled) { if (reenable) {
object->Reenable(); object->Reenable();
} }
@ -167,8 +210,8 @@ int32_t CreateObject(CDataStore* msg, uint32_t time) {
msg->Get(_typeID); msg->Get(_typeID);
auto typeID = static_cast<OBJECT_TYPE_ID>(_typeID); auto typeID = static_cast<OBJECT_TYPE_ID>(_typeID);
int32_t reenabled; int32_t reenable;
auto existingObject = GetUpdateObject(guid, &reenabled); auto existingObject = GetUpdateObject(guid, &reenable);
if (existingObject) { if (existingObject) {
CClientObjCreate::Skip(msg); CClientObjCreate::Skip(msg);
@ -177,7 +220,7 @@ int32_t CreateObject(CDataStore* msg, uint32_t time) {
return 0; return 0;
} }
if (reenabled) { if (reenable) {
existingObject->Reenable(); existingObject->Reenable();
} }
@ -193,7 +236,7 @@ int32_t CreateObject(CDataStore* msg, uint32_t time) {
ClntObjMgrSetActivePlayer(guid); ClntObjMgrSetActivePlayer(guid);
} }
auto newObject = static_cast<CGObject_C*>(ClntObjMgrAllocObject(typeID, guid)); auto newObject = ClntObjMgrAllocObject(typeID, guid);
SetupObjectStorage(typeID, newObject, guid); SetupObjectStorage(typeID, newObject, guid);
@ -219,10 +262,10 @@ void UpdateInRangeObjects(CDataStore* msg) {
*msg >> guid; *msg >> guid;
if (guid != ClntObjMgrGetActivePlayer()) { if (guid != ClntObjMgrGetActivePlayer()) {
int32_t reenabled; int32_t reenable;
auto object = GetUpdateObject(guid, &reenabled); auto object = GetUpdateObject(guid, &reenable);
if (object && reenabled) { if (object && reenable) {
object->Reenable(); object->Reenable();
} }
} }
@ -368,5 +411,21 @@ int32_t ObjectUpdateHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataS
} }
int32_t OnObjectDestroy(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { int32_t OnObjectDestroy(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) {
WHOA_UNIMPLEMENTED(0); WOWGUID guid;
msg->Get(guid);
uint8_t dead;
msg->Get(dead);
auto object = FindActiveObject(guid);
if (object) {
// TODO handle unit death
if (HandleObjectOutOfRangePass1(object, OUT_OF_RANGE_1)) {
HandleObjectOutOfRangePass2(object);
}
}
return 1;
} }

View File

@ -67,12 +67,12 @@ void MirrorInitialize() {
// TODO // TODO
} }
void* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid) { CGObject_C* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid) {
auto playerGUID = ClntObjMgrGetActivePlayer(); auto playerGUID = ClntObjMgrGetActivePlayer();
// Heap allocate player object for current player // Heap allocate player object for current player
if (guid == playerGUID) { if (guid == playerGUID) {
return 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); // TODO GarbageCollect(typeID, 10000);
@ -85,9 +85,10 @@ void* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid) {
} }
// TODO pointer should be fetched via ObjectPtr // TODO pointer should be fetched via ObjectPtr
static_cast<CGObject_C*>(mem)->m_memHandle = memHandle; auto object = static_cast<CGObject_C*>(mem);
object->m_memHandle = memHandle;
return mem; return object;
} }
WOWGUID ClntObjMgrGetActivePlayer() { WOWGUID ClntObjMgrGetActivePlayer() {

View File

@ -6,7 +6,7 @@
#include "object/Types.hpp" #include "object/Types.hpp"
#include <cstdint> #include <cstdint>
void* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid); CGObject_C* ClntObjMgrAllocObject(OBJECT_TYPE_ID typeID, WOWGUID guid);
WOWGUID ClntObjMgrGetActivePlayer(); WOWGUID ClntObjMgrGetActivePlayer();

View File

@ -14,8 +14,8 @@ CGObject_C* FindActiveObject(WOWGUID guid) {
return ClntObjMgrGetCurrent()->m_objects.Ptr(guid, CHashKeyGUID(guid)); return ClntObjMgrGetCurrent()->m_objects.Ptr(guid, CHashKeyGUID(guid));
} }
CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenabled) { CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenable) {
*reenabled = false; *reenable = false;
// Active object // Active object
@ -44,7 +44,7 @@ CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenabled) {
!ClntObjMgrGetCurrent()->m_visibleObjects.IsLinked(disabledObject) !ClntObjMgrGetCurrent()->m_visibleObjects.IsLinked(disabledObject)
&& !ClntObjMgrGetCurrent()->m_reenabledObjects.IsLinked(disabledObject) && !ClntObjMgrGetCurrent()->m_reenabledObjects.IsLinked(disabledObject)
) { ) {
*reenabled = true; *reenable = true;
ClntObjMgrGetCurrent()->m_reenabledObjects.LinkToTail(disabledObject); ClntObjMgrGetCurrent()->m_reenabledObjects.LinkToTail(disabledObject);
} }
@ -56,6 +56,36 @@ CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenabled) {
return nullptr; return nullptr;
} }
int32_t HandleObjectOutOfRangePass1(CGObject_C* object, OUT_OF_RANGE_TYPE type) {
// TODO arena unit out of range handling
object->HandleOutOfRange(type);
if (object->IsObjectLocked()) {
object->SetDisablePending(true);
return false;
}
object->SetDisablePending(false);
object->Disable();
return true;
}
void HandleObjectOutOfRangePass2(CGObject_C* object) {
// TODO ClearObjectMirrorHandlers(object);
ClntObjMgrGetCurrent()->m_objects.Unlink(object);
if (ClntObjMgrGetCurrent()->m_visibleObjects.IsLinked(object)) {
ClntObjMgrGetCurrent()->m_visibleObjects.UnlinkNode(object);
}
ClntObjMgrGetCurrent()->m_lazyCleanupObjects.Insert(object, object->m_hashval, CHashKeyGUID(object->m_key));
ClntObjMgrGetCurrent()->m_lazyCleanupFifo[object->m_typeID - 1].LinkToTail(object);
}
void InitObject(CGObject_C* object, uint32_t time, CClientObjCreate& objCreate) { void InitObject(CGObject_C* object, uint32_t time, CClientObjCreate& objCreate) {
switch (object->m_typeID) { switch (object->m_typeID) {
case ID_ITEM: { case ID_ITEM: {

View File

@ -1,6 +1,7 @@
#ifndef OBJECT_CLIENT_UTIL_HPP #ifndef OBJECT_CLIENT_UTIL_HPP
#define OBJECT_CLIENT_UTIL_HPP #define OBJECT_CLIENT_UTIL_HPP
#include "object/Types.hpp"
#include "util/GUID.hpp" #include "util/GUID.hpp"
#include <cstdint> #include <cstdint>
@ -9,7 +10,11 @@ class CGObject_C;
CGObject_C* FindActiveObject(WOWGUID guid); CGObject_C* FindActiveObject(WOWGUID guid);
CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenabled); CGObject_C* GetUpdateObject(WOWGUID guid, int32_t* reenable);
int32_t HandleObjectOutOfRangePass1(CGObject_C* object, OUT_OF_RANGE_TYPE type);
void HandleObjectOutOfRangePass2(CGObject_C* object);
void InitObject(CGObject_C* object, uint32_t time, CClientObjCreate& objCreate); void InitObject(CGObject_C* object, uint32_t time, CClientObjCreate& objCreate);

View File

@ -6,10 +6,49 @@
#include "world/Weather.hpp" #include "world/Weather.hpp"
#include <storm/Memory.hpp> #include <storm/Memory.hpp>
uint32_t CWorld::s_curTimeMs;
float CWorld::s_curTimeSec;
uint32_t CWorld::s_enables; uint32_t CWorld::s_enables;
uint32_t CWorld::s_enables2; uint32_t CWorld::s_enables2;
uint32_t CWorld::s_gameTimeFixed;
float CWorld::s_gameTimeSec;
uint32_t CWorld::s_tickTimeFixed;
uint32_t CWorld::s_tickTimeMs;
float CWorld::s_tickTimeSec;
Weather* CWorld::s_weather; Weather* CWorld::s_weather;
uint32_t CWorld::GetCurTimeMs() {
return CWorld::s_curTimeMs;
}
float CWorld::GetCurTimeSec() {
return CWorld::s_curTimeSec;
}
uint32_t CWorld::GetFixedPrecisionTime(float timeSec) {
return static_cast<uint32_t>(timeSec * 1024.0f);
}
uint32_t CWorld::GetGameTimeFixed() {
return CWorld::s_gameTimeFixed;
}
float CWorld::GetGameTimeSec() {
return CWorld::s_gameTimeSec;
}
uint32_t CWorld::GetTickTimeFixed() {
return CWorld::s_tickTimeFixed;
}
uint32_t CWorld::GetTickTimeMs() {
return CWorld::s_tickTimeMs;
}
float CWorld::GetTickTimeSec() {
return CWorld::s_tickTimeSec;
}
void CWorld::Initialize() { void CWorld::Initialize() {
CWorld::s_enables |= CWorld::s_enables |=
Enables::Enable_1 Enables::Enable_1
@ -26,6 +65,9 @@ void CWorld::Initialize() {
| Enables::Enable_Particulates | Enables::Enable_Particulates
| Enables::Enable_LowDetail; | Enables::Enable_LowDetail;
CWorld::s_gameTimeFixed = 0;
CWorld::s_gameTimeSec = 0.0f;
// TODO // TODO
if (GxCaps().m_shaderTargets[GxSh_Pixel] > GxShPS_none) { if (GxCaps().m_shaderTargets[GxSh_Pixel] > GxShPS_none) {
@ -58,3 +100,23 @@ void CWorld::LoadMap(const char* mapName, const C3Vector& position, int32_t zone
// TODO // TODO
} }
int32_t CWorld::OnTick(const EVENT_DATA_TICK* data, void* param) {
CWorld::SetUpdateTime(data->tickTimeSec, data->curTimeMs);
return 1;
}
void CWorld::SetUpdateTime(float tickTimeSec, uint32_t curTimeMs) {
auto tickTimeFixed = CWorld::GetFixedPrecisionTime(tickTimeSec);
CWorld::s_curTimeMs = curTimeMs;
CWorld::s_curTimeSec = static_cast<float>(curTimeMs) * 0.001f;
CWorld::s_gameTimeFixed += tickTimeFixed;
CWorld::s_gameTimeSec += tickTimeSec;
CWorld::s_tickTimeFixed = tickTimeFixed;
CWorld::s_tickTimeMs = static_cast<uint32_t>(tickTimeSec * 1000.0f);
CWorld::s_tickTimeSec = tickTimeSec;
}

View File

@ -1,6 +1,7 @@
#ifndef WORLD_C_WORLD_HPP #ifndef WORLD_C_WORLD_HPP
#define WORLD_C_WORLD_HPP #define WORLD_C_WORLD_HPP
#include "event/Event.hpp"
#include <tempest/Vector.hpp> #include <tempest/Vector.hpp>
#include <cstdint> #include <cstdint>
@ -44,14 +45,36 @@ class CWorld {
Enable_HwPcf = 0x2 Enable_HwPcf = 0x2
}; };
// Static variables // Public static variables
static uint32_t s_enables; static uint32_t s_enables;
static uint32_t s_enables2; static uint32_t s_enables2;
static Weather* s_weather; static Weather* s_weather;
// Static functions // Public static functions
static void Initialize(void); static uint32_t GetCurTimeMs();
static float GetCurTimeSec();
static uint32_t GetGameTimeFixed();
static float GetGameTimeSec();
static uint32_t GetTickTimeFixed();
static uint32_t GetTickTimeMs();
static float GetTickTimeSec();
static void Initialize();
static void LoadMap(const char* mapName, const C3Vector& position, int32_t zoneID); static void LoadMap(const char* mapName, const C3Vector& position, int32_t zoneID);
static int32_t OnTick(const EVENT_DATA_TICK* data, void* param);
static void SetUpdateTime(float tickTimeSec, uint32_t curTimeMs);
private:
// Private static variables
static uint32_t s_curTimeMs;
static float s_curTimeSec;
static uint32_t s_gameTimeFixed;
static float s_gameTimeSec;
static uint32_t s_tickTimeFixed;
static uint32_t s_tickTimeMs;
static float s_tickTimeSec;
// Private static functions
static uint32_t GetFixedPrecisionTime(float timeSec);
}; };
#endif #endif