Skip to content

Commit

Permalink
Cleanup global variables in xrGame
Browse files Browse the repository at this point in the history
That change in UIStatsIcon looks somewhat ugly and can cause questions for other peers that would look at that code.
This and previous commits in a row are needed to make xrGame work when it's linked directly to xr_3da (originally it was loaded dynamically).
  • Loading branch information
Xottab-DUTY committed May 4, 2024
1 parent e409001 commit a914f65
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/xrGame/Level_bullet_manager_firetrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void CBulletManager::DynamicObjectHit(CBulletManager::_event& E)
}

#ifdef DEBUG
xr_vector<Fvector> g_hit[3]; // XXX: can cause crash on launch (if build statically) and exit
xr_vector<Fvector> g_hit[3];
#endif

extern void random_dir(Fvector& tgt_dir, const Fvector& src_dir, float dispersion);
Expand Down
19 changes: 15 additions & 4 deletions src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#define WEAPON_REMOVE_TIME 60000
#define ROTATION_TIME 0.25f

constexpr pcstr WPN_SCOPE = "wpn_scope";
constexpr pcstr WPN_SILENCER = "wpn_silencer";
constexpr pcstr WPN_GRENADE_LAUNCHER = "wpn_launcher";

BOOL b_toggle_weapon_aim = FALSE;

static class CUIWpnScopeXmlManager : public pureUIReset, public pureAppEnd
Expand Down Expand Up @@ -1278,12 +1282,15 @@ bool CWeapon::IsSilencerAttached() const
bool CWeapon::GrenadeLauncherAttachable() { return (ALife::eAddonAttachable == m_eGrenadeLauncherStatus); }
bool CWeapon::ScopeAttachable() { return (ALife::eAddonAttachable == m_eScopeStatus); }
bool CWeapon::SilencerAttachable() { return (ALife::eAddonAttachable == m_eSilencerStatus); }
shared_str wpn_scope = "wpn_scope";
shared_str wpn_silencer = "wpn_silencer";
shared_str wpn_grenade_launcher = "wpn_launcher";


void CWeapon::UpdateHUDAddonsVisibility()
{ // actor only
{
static shared_str wpn_scope = WPN_SCOPE;
static shared_str wpn_silencer = WPN_SILENCER;
static shared_str wpn_grenade_launcher = WPN_GRENADE_LAUNCHER;

// actor only
if (!GetHUDmode())
return;

Expand Down Expand Up @@ -1326,6 +1333,10 @@ void CWeapon::UpdateHUDAddonsVisibility()

void CWeapon::UpdateAddonsVisibility()
{
static shared_str wpn_scope = WPN_SCOPE;
static shared_str wpn_silencer = WPN_SILENCER;
static shared_str wpn_grenade_launcher = WPN_GRENADE_LAUNCHER;

IKinematics* pWeaponVisual = smart_cast<IKinematics*>(Visual());
R_ASSERT(pWeaponVisual);

Expand Down
5 changes: 0 additions & 5 deletions src/xrGame/ai/stalker/ai_stalker_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,11 +1594,6 @@ static void draw_animation_bones(
#endif // #ifdef DEBUG_RENDER
}

Fvector g_debug_position_0 = Fvector().set(0.f, 0.f, 0.f);
Fvector g_debug_position_1 = Fvector().set(0.f, 0.f, 0.f);
Fvector g_debug_position_2 = Fvector().set(0.f, 0.f, 0.f);
Fvector g_debug_position_3 = Fvector().set(0.f, 0.f, 0.f);

void CAI_Stalker::OnRender()
{
#if 0
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/alife_storage_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "saved_game_wrapper.h"
#include "xrEngine/IGame_Persistent.h"
#include "autosave_manager.h"
XRCORE_API string_path g_bug_report_file;

using namespace ALife;

Expand Down
7 changes: 0 additions & 7 deletions src/xrGame/ui/Restrictions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ u32 get_rank(const shared_str& section)
return res;
}

CRestrictions::CRestrictions()
{
m_rank = 0;
m_bInited = false;
}

CRestrictions::~CRestrictions() {}
void CRestrictions::InitGroups()
{
if (m_bInited)
Expand Down
8 changes: 4 additions & 4 deletions src/xrGame/ui/Restrictions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ typedef struct
class CRestrictions
{
public:
CRestrictions();
~CRestrictions();
CRestrictions() = default;
~CRestrictions() = default;

void InitGroups();
const u32 GetRank() const { return m_rank; }
Expand All @@ -38,8 +38,8 @@ class CRestrictions
void AddRestriction4rank(u32 rank, const shared_str& lst);
RESTR GetRestr(const shared_str& item);

u32 m_rank;
bool m_bInited;
u32 m_rank{};
bool m_bInited{};

using group_items = xr_vector<shared_str>;
using Groups = xr_map<shared_str, group_items>;
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/ui/UIOptConCom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
xr_token g_GameModes[] = {{"st_deathmatch", eGameIDDeathmatch}, {"st_team_deathmatch", eGameIDTeamDeathmatch},
{"st_artefacthunt", eGameIDArtefactHunt}, {"st_capture_the_artefact", eGameIDCaptureTheArtefact}, {0, 0}};

CUIOptConCom::CUIOptConCom() { xr_strcpy(m_playerName, ""); }
class CCC_UserName : public CCC_String
{
public:
Expand Down
22 changes: 11 additions & 11 deletions src/xrGame/ui/UIOptConCom.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

class CUIOptConCom
{
private:
string64 reinforcementType;
string64 reinforcementType{};

public:
CUIOptConCom() = default;

void Init();
CUIOptConCom();

protected:
enum
Expand All @@ -25,14 +25,14 @@ class CUIOptConCom
fl_wo_ff = (1 << 4),
fl_listen = (1 << 5),
};
int m_iMaxPlayers;
Flags32 m_uNetSrvParams;
Flags32 m_uNetFilter;
u32 m_curGameMode;
string64 m_playerName;
string64 m_serverName;
int m_iNetConSpectator;
float m_fNetWeatherRate;
int m_iMaxPlayers{};
Flags32 m_uNetSrvParams{};
Flags32 m_uNetFilter{};
u32 m_curGameMode{};
string64 m_playerName{};
string64 m_serverName{};
int m_iNetConSpectator{};
float m_fNetWeatherRate{};

void ReadPlayerNameFromRegistry();
void WritePlayerNameToRegistry();
Expand Down
59 changes: 31 additions & 28 deletions src/xrGame/ui/UIStatsIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "Include/xrRender/UIShader.h"

CUIStatsIcon::TEX_INFO CUIStatsIcon::m_tex_info[MAX_DEF_TEX][2];

CUIStatsIcon::CUIStatsIcon()
: CUIStatic("CUIStatsIcon")
{
Expand All @@ -16,19 +14,22 @@ CUIStatsIcon::CUIStatsIcon()

void CUIStatsIcon::InitTexInfo()
{
if (m_tex_info[RANK_0][0].sh->inited())
if (m_tex_info)
return;

m_tex_info = xr_new<tex_info_data>();

// ranks
string128 rank_tex;
for (int i = RANK_0; i <= RANK_4; i++)
{
xr_sprintf(rank_tex, "ui_hud_status_green_0%d", i + 1);
CUITextureMaster::GetTextureShader(rank_tex, m_tex_info[i][0].sh);
m_tex_info[i][0].rect = CUITextureMaster::GetTextureRect(rank_tex);
CUITextureMaster::GetTextureShader(rank_tex, (*m_tex_info)[i][0].sh);
(*m_tex_info)[i][0].rect = CUITextureMaster::GetTextureRect(rank_tex);

xr_sprintf(rank_tex, "ui_hud_status_blue_0%d", i + 1);
CUITextureMaster::GetTextureShader(rank_tex, m_tex_info[i][1].sh);
m_tex_info[i][1].rect = CUITextureMaster::GetTextureRect(rank_tex);
CUITextureMaster::GetTextureShader(rank_tex, (*m_tex_info)[i][1].sh);
(*m_tex_info)[i][1].rect = CUITextureMaster::GetTextureRect(rank_tex);
}

// artefact
Expand All @@ -38,33 +39,35 @@ void CUIStatsIcon::InitTexInfo()
float fXPos = pSettings->r_float(artefact_name, "inv_grid_x");
float fYPos = pSettings->r_float(artefact_name, "inv_grid_y");

m_tex_info[ARTEFACT][0].sh = InventoryUtilities::GetEquipmentIconsShader();
m_tex_info[ARTEFACT][0].rect.set(fXPos * INV_GRID_WIDTH, fYPos * INV_GRID_HEIGHT,
(*m_tex_info)[ARTEFACT][0].sh = InventoryUtilities::GetEquipmentIconsShader();
(*m_tex_info)[ARTEFACT][0].rect.set(fXPos * INV_GRID_WIDTH, fYPos * INV_GRID_HEIGHT,
fXPos * INV_GRID_WIDTH + fGridWidth * INV_GRID_WIDTH, fYPos * INV_GRID_HEIGHT + fGridHeight * INV_GRID_HEIGHT);

m_tex_info[ARTEFACT][1] = m_tex_info[ARTEFACT][0];
(*m_tex_info)[ARTEFACT][1] = (*m_tex_info)[ARTEFACT][0];

// death
m_tex_info[DEATH][0].sh->create("hud" DELIMITER "default", "ui" DELIMITER "ui_mp_icon_kill");
m_tex_info[DEATH][1] = m_tex_info[DEATH][0];
m_tex_info[DEATH][0].rect.x1 = 32;
m_tex_info[DEATH][0].rect.y1 = 202;
m_tex_info[DEATH][0].rect.x2 = m_tex_info[DEATH][0].rect.x1 + 30;
m_tex_info[DEATH][0].rect.y2 = m_tex_info[DEATH][0].rect.y1 + 30;
(*m_tex_info)[DEATH][0].sh->create("hud" DELIMITER "default", "ui" DELIMITER "ui_mp_icon_kill");
(*m_tex_info)[DEATH][1] = (*m_tex_info)[DEATH][0];
(*m_tex_info)[DEATH][0].rect.x1 = 32;
(*m_tex_info)[DEATH][0].rect.y1 = 202;
(*m_tex_info)[DEATH][0].rect.x2 = (*m_tex_info)[DEATH][0].rect.x1 + 30;
(*m_tex_info)[DEATH][0].rect.y2 = (*m_tex_info)[DEATH][0].rect.y1 + 30;
}

void CUIStatsIcon::FreeTexInfo()
{
// ranks
for (int i = RANK_0; i <= RANK_4; i++)
{
m_tex_info[i][0].sh->destroy();
m_tex_info[i][1].sh->destroy();
(*m_tex_info)[i][0].sh->destroy();
(*m_tex_info)[i][1].sh->destroy();
}
m_tex_info[ARTEFACT][0].sh->destroy();
m_tex_info[ARTEFACT][1].sh->destroy();
m_tex_info[DEATH][0].sh->destroy();
m_tex_info[DEATH][1].sh->destroy();
(*m_tex_info)[ARTEFACT][0].sh->destroy();
(*m_tex_info)[ARTEFACT][1].sh->destroy();
(*m_tex_info)[DEATH][0].sh->destroy();
(*m_tex_info)[DEATH][1].sh->destroy();

xr_delete(m_tex_info);
}

void CUIStatsIcon::SetValue(LPCSTR str)
Expand All @@ -85,18 +88,18 @@ void CUIStatsIcon::SetValue(LPCSTR str)

const int rank = atoi(strchr(str, '0')) - 1;

SetShader(m_tex_info[rank][team].sh);
SetTextureRect(m_tex_info[rank][team].rect);
SetShader((*m_tex_info)[rank][team].sh);
SetTextureRect((*m_tex_info)[rank][team].rect);
}
else if (0 == xr_strcmp(str, "death"))
{
SetShader(m_tex_info[DEATH][0].sh);
SetTextureRect(m_tex_info[DEATH][0].rect);
SetShader((*m_tex_info)[DEATH][0].sh);
SetTextureRect((*m_tex_info)[DEATH][0].rect);
}
else if (0 == xr_strcmp(str, "artefact"))
{
SetShader(m_tex_info[ARTEFACT][0].sh);
SetTextureRect(m_tex_info[ARTEFACT][0].rect);
SetShader((*m_tex_info)[ARTEFACT][0].sh);
SetTextureRect((*m_tex_info)[ARTEFACT][0].rect);
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion src/xrGame/ui/UIStatsIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ class CUIStatsIcon final : public CUIStatic

static void InitTexInfo();
static void FreeTexInfo();
static TEX_INFO m_tex_info[MAX_DEF_TEX][2];

using tex_info_data = std::array<TEX_INFO[2], MAX_DEF_TEX>;

inline static tex_info_data* m_tex_info;
};

0 comments on commit a914f65

Please sign in to comment.