Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Oct 16, 2023
1 parent 1c2c215 commit bff9390
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 125 deletions.
2 changes: 1 addition & 1 deletion Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ void CCore::SetConnected(bool bConnected)
discord->SetPresenceDetails("");

if (bConnected)
discord->SetPresenceStartTimestamp(time(nullptr));
discord->SetPresenceStartTimestamp(GetTickCount64_());
}
}

Expand Down
124 changes: 62 additions & 62 deletions Client/core/CCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,30 @@ class CDiscordInterface;
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

#define BLUE_VERSION_STRING "Multi Theft Auto v" MTA_DM_BUILDTAG_LONG
#define BLUE_COPYRIGHT_STRING "Copyright (C) 2003 - %BUILD_YEAR% Multi Theft Auto"
#define BLUE_VERSION_STRING "Multi Theft Auto v" MTA_DM_BUILDTAG_LONG
#define BLUE_COPYRIGHT_STRING "Copyright (C) 2003 - %BUILD_YEAR% Multi Theft Auto"

// Configuration file path (relative to MTA install directory)
#define MTA_CONFIG_PATH "mta/config/coreconfig.xml"
#define MTA_SERVER_CACHE_PATH "mta/config/servercache.xml"
#define MTA_CONSOLE_LOG_PATH "mta/logs/console.log"
#define MTA_CONSOLE_INPUT_LOG_PATH "mta/logs/console-input.log"
#define CONFIG_ROOT "mainconfig"
#define CONFIG_NODE_CVARS "settings" // cvars node
#define CONFIG_NODE_KEYBINDS "binds" // keybinds node
#define CONFIG_NODE_JOYPAD "joypad"
#define CONFIG_NODE_UPDATER "updater"
#define CONFIG_NODE_SERVER_INT "internet_servers" // backup of last successful master server list query
#define CONFIG_NODE_SERVER_FAV "favourite_servers" // favourite servers list node
#define CONFIG_NODE_SERVER_REC "recently_played_servers" // recently played servers list node
#define CONFIG_NODE_SERVER_OPTIONS "serverbrowser_options" // saved options for the server browser
#define CONFIG_NODE_SERVER_SAVED "server_passwords" // This contains saved passwords (as appose to save_server_passwords which is a setting)
#define CONFIG_NODE_SERVER_HISTORY "connect_history"
#define CONFIG_INTERNET_LIST_TAG "internet_server"
#define CONFIG_FAVOURITE_LIST_TAG "favourite_server"
#define CONFIG_RECENT_LIST_TAG "recently_played_server"
#define CONFIG_HISTORY_LIST_TAG "connected_server"
#define IDT_TIMER1 1234
#define MTA_CONFIG_PATH "mta/config/coreconfig.xml"
#define MTA_SERVER_CACHE_PATH "mta/config/servercache.xml"
#define MTA_CONSOLE_LOG_PATH "mta/logs/console.log"
#define MTA_CONSOLE_INPUT_LOG_PATH "mta/logs/console-input.log"
#define CONFIG_ROOT "mainconfig"
#define CONFIG_NODE_CVARS "settings" // cvars node
#define CONFIG_NODE_KEYBINDS "binds" // keybinds node
#define CONFIG_NODE_JOYPAD "joypad"
#define CONFIG_NODE_UPDATER "updater"
#define CONFIG_NODE_SERVER_INT "internet_servers" // backup of last successful master server list query
#define CONFIG_NODE_SERVER_FAV "favourite_servers" // favourite servers list node
#define CONFIG_NODE_SERVER_REC "recently_played_servers" // recently played servers list node
#define CONFIG_NODE_SERVER_OPTIONS "serverbrowser_options" // saved options for the server browser
#define CONFIG_NODE_SERVER_SAVED "server_passwords" // This contains saved passwords (as appose to save_server_passwords which is a setting)
#define CONFIG_NODE_SERVER_HISTORY "connect_history"
#define CONFIG_INTERNET_LIST_TAG "internet_server"
#define CONFIG_FAVOURITE_LIST_TAG "favourite_server"
#define CONFIG_RECENT_LIST_TAG "recently_played_server"
#define CONFIG_HISTORY_LIST_TAG "connected_server"
#define IDT_TIMER1 1234

extern class CCore* g_pCore;
extern class CGraphics* g_pGraphics;
Expand All @@ -84,26 +84,26 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
~CCore();

// Subsystems (query)
eCoreVersion GetVersion();
CConsoleInterface* GetConsole();
CCommandsInterface* GetCommands();
CConnectManager* GetConnectManager() { return m_pConnectManager; };
CGame* GetGame();
CGUI* GetGUI();
CGraphicsInterface* GetGraphics();
CModManagerInterface* GetModManager();
CMultiplayer* GetMultiplayer();
CNet* GetNetwork();
CXML* GetXML() { return m_pXML; };
CXMLNode* GetConfig();
CClientVariables* GetCVars() { return &m_ClientVariables; };
CKeyBindsInterface* GetKeyBinds();
CMouseControl* GetMouseControl() { return m_pMouseControl; };
CLocalGUI* GetLocalGUI();
CLocalizationInterface* GetLocalization() { return g_pLocalization; };
CWebCoreInterface* GetWebCore();
CTrayIconInterface* GetTrayIcon() { return m_pTrayIcon; };
std::shared_ptr<CDiscordInterface> GetDiscord();
eCoreVersion GetVersion();
CConsoleInterface* GetConsole();
CCommandsInterface* GetCommands();
CConnectManager* GetConnectManager() { return m_pConnectManager; };
CGame* GetGame();
CGUI* GetGUI();
CGraphicsInterface* GetGraphics();
CModManagerInterface* GetModManager();
CMultiplayer* GetMultiplayer();
CNet* GetNetwork();
CXML* GetXML() { return m_pXML; };
CXMLNode* GetConfig();
CClientVariables* GetCVars() { return &m_ClientVariables; };
CKeyBindsInterface* GetKeyBinds();
CMouseControl* GetMouseControl() { return m_pMouseControl; };
CLocalGUI* GetLocalGUI();
CLocalizationInterface* GetLocalization() { return g_pLocalization; };
CWebCoreInterface* GetWebCore();
CTrayIconInterface* GetTrayIcon() { return m_pTrayIcon; };
std::shared_ptr<CDiscordInterface> GetDiscord();

void SaveConfig(bool bWaitUntilFinished = false);

Expand Down Expand Up @@ -286,8 +286,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
bool IsUsingCustomStreamingMemorySize();
size_t GetStreamingMemory();

SString GetLastConnectedServerName() const { return m_strLastConnectedServerName; }
void SetLastConnectedServerName(SString strServerName) { m_strLastConnectedServerName = strServerName; }
const SString& GetLastConnectedServerName() { return m_strLastConnectedServerName; }
void SetLastConnectedServerName(const SString& strServerName) { m_strLastConnectedServerName = strServerName; }

private:
void ApplyCoreInitSettings();
Expand All @@ -303,11 +303,11 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
CModelCacheManager* m_pModelCacheManager;

// Instances (put new classes here!)
CXMLFile* m_pConfigFile;
CClientVariables m_ClientVariables;
CWebCoreInterface* m_pWebCore = nullptr;
CTrayIcon* m_pTrayIcon;
std::shared_ptr<CDiscordRichPresence> m_pDiscordRichPresence;
CXMLFile* m_pConfigFile;
CClientVariables m_ClientVariables;
CWebCoreInterface* m_pWebCore = nullptr;
CTrayIcon* m_pTrayIcon;
std::shared_ptr<CDiscordRichPresence> m_pDiscordRichPresence;

// Hook interfaces.
CMessageLoopHook* m_pMessageLoopHook;
Expand Down Expand Up @@ -373,22 +373,22 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
EDiagnosticDebugType m_DiagnosticDebug;

// Below 2 are used for the UI only
float m_fMinStreamingMemory{};
float m_fMaxStreamingMemory{};
float m_fMinStreamingMemory{};
float m_fMaxStreamingMemory{};

// Custom streaming memory limit set by `engineStreamingSetMemorySize` - Reset on server connects (= set to 0), or by the scripter
// `0` means "not set" [so the value should be ignored]
size_t m_CustomStreamingMemoryLimitBytes{};

bool m_bGettingIdleCallsFromMultiplayer;
bool m_bWindowsTimerEnabled;
bool m_bModulesLoaded;
int m_iDummyProgressValue;
HANDLE m_DummyProgressTimerHandle;
SString m_strDummyProgressType;
bool m_bDummyProgressUpdateAlways;
bool m_bIsRenderingGrass;
bool m_bFakeLagCommandEnabled;
size_t m_CustomStreamingMemoryLimitBytes{};

bool m_bGettingIdleCallsFromMultiplayer;
bool m_bWindowsTimerEnabled;
bool m_bModulesLoaded;
int m_iDummyProgressValue;
HANDLE m_DummyProgressTimerHandle;
SString m_strDummyProgressType;
bool m_bDummyProgressUpdateAlways;
bool m_bIsRenderingGrass;
bool m_bFakeLagCommandEnabled;

SString m_strLastConnectedServerName{};

Expand Down
8 changes: 4 additions & 4 deletions Client/core/CDiscordRichPresence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ void CDiscordRichPresence::SetAsset(const char* szAsset, const char* szAssetText
{
if (isLarge)
{
m_strDiscordAppAsset = (std::string(szAsset).length() > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET;
m_strDiscordAppAssetText = (std::string(szAssetText).length() > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_TEXT;
m_strDiscordAppAsset = (std::strlen(szAsset) > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET;
m_strDiscordAppAssetText = (std::strlen(szAssetText) > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_TEXT;
}
else
{
m_strDiscordAppAssetSmall = (std::string(szAsset).length() > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET_SMALL;
m_strDiscordAppAssetSmallText = (std::string(szAssetText).length() > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_SMALL_TEXT;
m_strDiscordAppAssetSmall = (std::strlen(szAsset) > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET_SMALL;
m_strDiscordAppAssetSmallText = (std::strlen(szAssetText) > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_SMALL_TEXT;
}
m_bUpdateRichPresence = true;
}
Expand Down
18 changes: 10 additions & 8 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ void CClientGame::DoPulsePostFrame()
}

// Check if we need to update the Discord Rich Presence state
if (time(nullptr) > m_timeLastDiscordStateUpdate + m_timeDiscordUpdateRate)
if (GetTickCount64_() > m_timeLastDiscordStateUpdate + m_timeDiscordUpdateRate)
{
auto discord = g_pCore->GetDiscord();

Expand Down Expand Up @@ -994,10 +994,10 @@ void CClientGame::DoPulsePostFrame()

// Check for states which match our primary task
std::vector<STaskState> taskStates{};
for (auto it = g_playerTaskStates.begin(); it != g_playerTaskStates.end(); it++)
for (const auto& [task, state] : g_playerTaskStates)
{
if (it->first == taskType)
taskStates.push_back(it->second);
if (task == taskType)
taskStates.push_back(state);
}

// Check for non-matching sub/secondary tasks and remove them
Expand Down Expand Up @@ -1029,7 +1029,7 @@ void CClientGame::DoPulsePostFrame()
int stateCount = taskStates.size();
if (stateCount > 0)
{
std::srand(time(nullptr));
std::srand(GetTickCount64_());
int index = (std::rand() % stateCount);
auto taskState = taskStates[index];

Expand All @@ -1048,7 +1048,7 @@ void CClientGame::DoPulsePostFrame()
discord->SetPresenceState("In-game", false);
}

m_timeLastDiscordStateUpdate = time(nullptr);
m_timeLastDiscordStateUpdate = GetTickCount64_();
}
}

Expand Down Expand Up @@ -5653,8 +5653,10 @@ void CClientGame::DoWastedCheck(ElementID damagerID, unsigned char ucWeapon, uns
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
std::vector<std::string> states{"In a ditch", "En-route to hospital", "Meeting their maker", "Regretting their decisions", "Wasted"};
std::string state = states[rand() % states.size()];
static const std::vector<std::string> states{"In a ditch", "En-route to hospital", "Meeting their maker", "Regretting their decisions",
"Wasted"};

const std::string& state = states[rand() % states.size()];
discord->SetPresenceState(state.c_str(), false);
}
}
Expand Down
37 changes: 19 additions & 18 deletions Client/mods/deathmatch/logic/CClientGame.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*****************************************************************************
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
Expand Down Expand Up @@ -45,8 +46,8 @@
#include "CSingularFileDownloadManager.h"
#include "CObjectRespawner.h"

#define HeliKill_List_Clear_Rate 500
#define MIN_PUSH_ANTISPAM_RATE 1500
#define HeliKill_List_Clear_Rate 500
#define MIN_PUSH_ANTISPAM_RATE 1500
#define INVALID_DOWNLOAD_PRIORITY_GROUP (INT_MIN)

class CClientModelCacheManager;
Expand Down Expand Up @@ -315,15 +316,15 @@ class CClientGame
void ShowEaeg(bool bShow);
void ShowFPS(bool bShow) { m_bShowFPS = bShow; };

#if defined (MTA_DEBUG) || defined (MTA_BETA)
#if defined(MTA_DEBUG) || defined(MTA_BETA)
void ShowSyncingInfo(bool bShow) { m_bShowSyncingInfo = bShow; };
#endif
#endif

#ifdef MTA_WEPSYNCDBG
void ShowWepdata(const char* szNick);
#endif

#ifdef MTA_DEBUG
#ifdef MTA_DEBUG
void ShowWepdata(const char* szNick);
void ShowTasks(const char* szNick);
void ShowPlayer(const char* szNick);
Expand All @@ -332,7 +333,7 @@ class CClientGame
void SetDoPaintballs(bool bDoPaintballs) { m_bDoPaintballs = bDoPaintballs; }
void ShowInterpolation(bool bShow) { m_bShowInterpolation = bShow; }
bool IsShowingInterpolation() const { return m_bShowInterpolation; }
#endif
#endif

CEntity* GetTargetedGameEntity() { return m_pTargetedGameEntity; }
CClientEntity* GetTargetedEntity() { return m_pTargetedEntity; }
Expand Down Expand Up @@ -476,17 +477,17 @@ class CClientGame

void DrawFPS();

#ifdef MTA_DEBUG
#ifdef MTA_DEBUG
void DrawTasks(CClientPlayer* pPlayer);
void DrawPlayerDetails(CClientPlayer* pPlayer);
void UpdateMimics();
void DoPaintballs();
void DrawWeaponsyncData(CClientPlayer* pPlayer);
#endif
#endif

#ifdef MTA_WEPSYNCDBG
#ifdef MTA_WEPSYNCDBG
void DrawWeaponsyncData(CClientPlayer* pPlayer);
#endif
#endif

void DownloadSingularResourceFiles();

Expand Down Expand Up @@ -791,11 +792,11 @@ class CClientGame
std::map<CEntitySAInterface*, CClientEntity*> m_CachedCollisionMap;
bool m_BuiltCollisionMapThisFrame;

#if defined (MTA_DEBUG) || defined (MTA_BETA)
#if defined(MTA_DEBUG) || defined(MTA_BETA)
bool m_bShowSyncingInfo;
#endif
#endif

#ifdef MTA_DEBUG
#ifdef MTA_DEBUG
CClientPlayer* m_pShowPlayerTasks;
CClientPlayer* m_pShowPlayer;
std::list<CClientPlayer*> m_Mimics;
Expand All @@ -807,10 +808,10 @@ class CClientGame
CVector m_vecLastMimicRot;
bool m_bDoPaintballs;
bool m_bShowInterpolation;
#endif
bool m_bDevelopmentMode;
bool m_bShowCollision;
bool m_bShowSound;
#endif
bool m_bDevelopmentMode;
bool m_bShowCollision;
bool m_bShowSound;

// Debug class. Empty in release.
public:
Expand Down Expand Up @@ -850,7 +851,7 @@ class CClientGame
RunNamedAnimTask_type m_mapOfRunNamedAnimTasks;

const time_t m_timeDiscordUpdateRate = 15;
time_t m_timeLastDiscordStateUpdate;
time_t m_timeLastDiscordStateUpdate;
};

extern CClientGame* g_pClientGame;
10 changes: 5 additions & 5 deletions Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ enum eClientVehicleType
CLIENTVEHICLE_TRAILER
};

static constexpr int NUM_VEHICLE_TYPES = 11;

enum eDelayedSyncVehicleData
{
DELAYEDSYNC_VEHICLE_KEYSYNC,
Expand Down Expand Up @@ -145,11 +147,9 @@ struct SVehicleComponentData
bool m_bVisible;
};

static const std::map<eClientVehicleType, std::string> g_vehicleTypePrefixes{
{CLIENTVEHICLE_CAR, "Cruising around"}, {CLIENTVEHICLE_PLANE, "Flying around"}, {CLIENTVEHICLE_BIKE, "Riding around"},
{CLIENTVEHICLE_HELI, "Flying around"}, {CLIENTVEHICLE_BOAT, "Riding the waves of"}, {CLIENTVEHICLE_TRAIN, "Riding the train in"},
{CLIENTVEHICLE_TRAILER, "Doing weird stuff in"}, {CLIENTVEHICLE_BMX, "Bunny hopping around"}, {CLIENTVEHICLE_MONSTERTRUCK, "Monster truckin' around"},
{CLIENTVEHICLE_QUADBIKE, "Quaddin' around"}};
static const std::array<std::string, NUM_VEHICLE_TYPES> g_vehicleTypePrefixes = {
"Flying a UFO around", "Cruising around", "Flying around", "Riding around", "Flying around", "Riding the waves of",
"Riding the train in", "Doing weird stuff in", "Bunny hopping around", "Monster truckin' around", "Quaddin' around"};

class CClientVehicle : public CClientStreamElement
{
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool CLuaDiscordDefs::SetDetails(std::string strDetails)

bool CLuaDiscordDefs::SetStartTime(unsigned long ulTime)
{
unsigned long ulSecondsSinceEpoch = time(nullptr) + ulTime;
unsigned long ulSecondsSinceEpoch = GetTickCount64_() + ulTime;

if (ulTime == 0)
ulSecondsSinceEpoch = 0;
Expand All @@ -142,7 +142,7 @@ bool CLuaDiscordDefs::SetStartTime(unsigned long ulTime)

bool CLuaDiscordDefs::SetEndTime(unsigned long ulTime)
{
unsigned long ulSecondsSinceEpoch = time(nullptr) + ulTime;
unsigned long ulSecondsSinceEpoch = GetTickCount64_() + ulTime;

if (ulTime == 0)
ulSecondsSinceEpoch = 0;
Expand Down
Loading

0 comments on commit bff9390

Please sign in to comment.