Compare commits

..

6 Commits

Author SHA1 Message Date
Tristan 'Natrist' Cormier
fd1f1eaf22
Merge b902b5484e into 0bb3ac157f 2026-01-29 09:47:59 -05:00
fallenoak
0bb3ac157f
feat(client): implement ReceiveNewTimeSpeed 2026-01-29 08:47:19 -06:00
fallenoak
53b26169f3
feat(util): add CGameTime::GameTimeSetMinutesPerSecond 2026-01-29 08:46:57 -06:00
fallenoak
6e7c267d3e
feat(client): add ClientInitializeGameTime 2026-01-29 07:52:43 -06:00
fallenoak
50a24e8564
feat(ui): implement Script_GetGameTime 2026-01-29 07:37:43 -06:00
fallenoak
efd3f8e8f4
feat(client): add ClientGameTimeTickHandler 2026-01-29 07:33:50 -06:00
7 changed files with 116 additions and 9 deletions

View File

@ -30,6 +30,8 @@ CVar* Client::g_accountNameVar;
CVar* Client::g_accountListVar; CVar* Client::g_accountListVar;
HEVENTCONTEXT Client::g_clientEventContext; HEVENTCONTEXT Client::g_clientEventContext;
CGameTime g_clientGameTime;
static CVar* s_desktopGammaCvar; static CVar* s_desktopGammaCvar;
static CVar* s_gammaCvar; static CVar* s_gammaCvar;
static CVar* s_textureCacheSizeCvar; static CVar* s_textureCacheSizeCvar;
@ -70,10 +72,28 @@ void BaseInitializeGlobal() {
PropInitialize(); PropInitialize();
} }
int32_t ClientGameTimeTickHandler(const void* data, void* param) {
STORM_ASSERT(data);
g_clientGameTime.GameTimeUpdate(static_cast<const EVENT_DATA_IDLE*>(data)->elapsedSec);
return 1;
}
void ClientInitializeGameTime() {
ClientServices::SetMessageHandler(SMSG_GAME_SPEED_SET, &ReceiveNewGameSpeed, nullptr);
ClientServices::SetMessageHandler(SMSG_LOGIN_SET_TIME_SPEED, &ReceiveNewTimeSpeed, nullptr);
ClientServices::SetMessageHandler(SMSG_GAME_TIME_UPDATE, &ReceiveGameTimeUpdate, nullptr);
ClientServices::SetMessageHandler(SMSG_SERVERTIME, &ReceiveServerTime, nullptr);
ClientServices::SetMessageHandler(SMSG_GAME_TIME_SET, &ReceiveNewGameTime, nullptr);
// TODO initialize s_forcedChangeCallbacks
}
int32_t ClientIdle(const void* data, void* param) { int32_t ClientIdle(const void* data, void* param) {
// TODO ClientGameTimeTickHandler(data, nullptr);
// ClientGameTimeTickHandler(data, param);
// Player_C_ZoneUpdateHandler(data, param); // TODO Player_C_ZoneUpdateHandler(data, nullptr);
return 1; return 1;
} }
@ -91,6 +111,7 @@ void ClientInitializeGame(uint32_t mapId, C3Vector position) {
// TODO // TODO
EventRegister(EVENT_ID_IDLE, ClientIdle); EventRegister(EVENT_ID_IDLE, ClientIdle);
ClientInitializeGameTime();
// TODO // TODO

View File

@ -2,6 +2,7 @@
#define CLIENT_CLIENT_HPP #define CLIENT_CLIENT_HPP
#include "event/Event.hpp" #include "event/Event.hpp"
#include "util/Time.hpp"
#include <tempest/Vector.hpp> #include <tempest/Vector.hpp>
class CVar; class CVar;
@ -12,6 +13,8 @@ namespace Client {
extern HEVENTCONTEXT g_clientEventContext; extern HEVENTCONTEXT g_clientEventContext;
} }
extern CGameTime g_clientGameTime;
void ClientInitializeGame(uint32_t mapId, C3Vector position); void ClientInitializeGame(uint32_t mapId, C3Vector position);
void ClientPostClose(int32_t a1); void ClientPostClose(int32_t a1);

View File

@ -1,11 +1,14 @@
#include "client/ClientHandlers.hpp" #include "client/ClientHandlers.hpp"
#include "Client.hpp"
#include "console/Console.hpp" #include "console/Console.hpp"
#include "db/Db.hpp" #include "db/Db.hpp"
#include "object/Client.hpp" #include "object/Client.hpp"
#include "util/Time.hpp"
#include "util/Unimplemented.hpp"
#include "world/World.hpp" #include "world/World.hpp"
#include <common/DataStore.hpp> #include <common/DataStore.hpp>
#include <tempest/Vector.hpp>
#include <cstdint> #include <cstdint>
#include <tempest/Vector.hpp>
static float s_newFacing; static float s_newFacing;
static C3Vector s_newPosition; static C3Vector s_newPosition;
@ -77,6 +80,56 @@ int32_t PlayedTimeHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataSto
return 0; return 0;
} }
int32_t ReceiveGameTimeUpdate(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) {
WHOA_UNIMPLEMENTED(0);
}
int32_t ReceiveNewGameSpeed(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) {
WHOA_UNIMPLEMENTED(0);
}
int32_t ReceiveNewGameTime(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) {
WHOA_UNIMPLEMENTED(0);
}
int32_t ReceiveNewTimeSpeed(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) {
uint32_t encodedTime;
msg->Get(encodedTime);
float newSpeed;
msg->Get(newSpeed);
uint32_t holidayOffset;
msg->Get(holidayOffset);
if (!msg->IsRead()) {
STORM_ASSERT(msg->IsFinal());
// TODO ConsoleWriteA("Malformed message received: Id = %d, Len = %d, Read = %d\n", DEFAULT_COLOR, msgId, msg->Size(), msg->Tell());
return 0;
}
WowTime newTime;
WowTime::WowDecodeTime(encodedTime, &newTime);
newTime.m_holidayOffset = holidayOffset;
g_clientGameTime.GameTimeSetTime(newTime, true);
// TODO UpdateTime();
auto oldSpeed = g_clientGameTime.GameTimeSetMinutesPerSecond(newSpeed);
char logStr[256];
SStrPrintf(logStr, sizeof(logStr), "Gamespeed set from %.03f to %.03f", oldSpeed, newSpeed);
ConsoleWrite(logStr, DEFAULT_COLOR);
return 1;
}
int32_t ReceiveServerTime(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) {
WHOA_UNIMPLEMENTED(0);
}
int32_t TransferAbortedHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { int32_t TransferAbortedHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) {
// TODO // TODO

View File

@ -14,6 +14,16 @@ int32_t NotifyHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore*
int32_t PlayedTimeHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); int32_t PlayedTimeHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg);
int32_t ReceiveGameTimeUpdate(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg);
int32_t ReceiveNewGameSpeed(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg);
int32_t ReceiveNewGameTime(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg);
int32_t ReceiveNewTimeSpeed(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg);
int32_t ReceiveServerTime(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg);
int32_t TransferAbortedHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); int32_t TransferAbortedHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg);
int32_t TransferPendingHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); int32_t TransferPendingHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg);

View File

@ -1,4 +1,5 @@
#include "ui/FrameScript.hpp" #include "ui/FrameScript.hpp"
#include "client/Client.hpp"
#include "ui/ScriptFunctionsShared.hpp" #include "ui/ScriptFunctionsShared.hpp"
#include "ui/Types.hpp" #include "ui/Types.hpp"
#include "util/Lua.hpp" #include "util/Lua.hpp"
@ -14,10 +15,10 @@ int32_t Script_GetTime(lua_State* L) {
} }
int32_t Script_GetGameTime(lua_State* L) { int32_t Script_GetGameTime(lua_State* L) {
// TODO real implementation lua_pushnumber(L, g_clientGameTime.m_hour);
lua_pushnumber(L, 1.0); lua_pushnumber(L, g_clientGameTime.m_minute);
lua_pushnumber(L, 15.0);
WHOA_UNIMPLEMENTED(2); return 2;
} }
int32_t Script_ConsoleExec(lua_State* L) { int32_t Script_ConsoleExec(lua_State* L) {

View File

@ -1,6 +1,20 @@
#include "util/time/CGameTime.hpp" #include "util/time/CGameTime.hpp"
#include "common/Time.hpp" #include "common/Time.hpp"
float CGameTime::GameTimeSetMinutesPerSecond(float minutesPerSec) {
float oldMinutesPerSec = this->m_gameMinutesPerRealSecond;
if (minutesPerSec > CGameTime::MAX_SPEED) {
minutesPerSec = CGameTime::MAX_SPEED;
} else if (minutesPerSec < CGameTime::MIN_SPEED) {
minutesPerSec = CGameTime::MIN_SPEED;
}
this->m_gameMinutesPerRealSecond = minutesPerSec;
return oldMinutesPerSec;
}
void CGameTime::GameTimeSetTime(const WowTime& time, bool shouldTick) { void CGameTime::GameTimeSetTime(const WowTime& time, bool shouldTick) {
WowTime biasTime = time; WowTime biasTime = time;

View File

@ -5,7 +5,12 @@
class CGameTime : public WowTime { class CGameTime : public WowTime {
public: public:
// Public static variables
static constexpr float MIN_SPEED = 1.0f / 60.0f;
static constexpr float MAX_SPEED = 60.0f;
// Public member functions // Public member functions
float GameTimeSetMinutesPerSecond(float minutesPerSec);
void GameTimeSetTime(const WowTime& time, bool shouldTick); void GameTimeSetTime(const WowTime& time, bool shouldTick);
void GameTimeUpdate(float elapsedSec); void GameTimeUpdate(float elapsedSec);
@ -15,7 +20,7 @@ class CGameTime : public WowTime {
int32_t m_timeBias = 0; int32_t m_timeBias = 0;
int32_t m_dateBias = 0; int32_t m_dateBias = 0;
uint32_t m_gameMinutesElapsed = 0; uint32_t m_gameMinutesElapsed = 0;
float m_gameMinutesPerRealSecond = 1.0f / 60.0f; float m_gameMinutesPerRealSecond = MIN_SPEED;
float m_gameMinutesThisTick = 0.0f; float m_gameMinutesThisTick = 0.0f;
uint32_t m_timeDifferential = 0; uint32_t m_timeDifferential = 0;
uint32_t m_lastTickMinute = 0; uint32_t m_lastTickMinute = 0;