Skip to content

Commit a914f65

Browse files
committed
Cleanup global variables in xrGame
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).
1 parent e409001 commit a914f65

10 files changed

Lines changed: 66 additions & 63 deletions

src/xrGame/Level_bullet_manager_firetrace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void CBulletManager::DynamicObjectHit(CBulletManager::_event& E)
364364
}
365365

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

370370
extern void random_dir(Fvector& tgt_dir, const Fvector& src_dir, float dispersion);

src/xrGame/Weapon.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#define WEAPON_REMOVE_TIME 60000
3232
#define ROTATION_TIME 0.25f
3333

34+
constexpr pcstr WPN_SCOPE = "wpn_scope";
35+
constexpr pcstr WPN_SILENCER = "wpn_silencer";
36+
constexpr pcstr WPN_GRENADE_LAUNCHER = "wpn_launcher";
37+
3438
BOOL b_toggle_weapon_aim = FALSE;
3539

3640
static class CUIWpnScopeXmlManager : public pureUIReset, public pureAppEnd
@@ -1278,12 +1282,15 @@ bool CWeapon::IsSilencerAttached() const
12781282
bool CWeapon::GrenadeLauncherAttachable() { return (ALife::eAddonAttachable == m_eGrenadeLauncherStatus); }
12791283
bool CWeapon::ScopeAttachable() { return (ALife::eAddonAttachable == m_eScopeStatus); }
12801284
bool CWeapon::SilencerAttachable() { return (ALife::eAddonAttachable == m_eSilencerStatus); }
1281-
shared_str wpn_scope = "wpn_scope";
1282-
shared_str wpn_silencer = "wpn_silencer";
1283-
shared_str wpn_grenade_launcher = "wpn_launcher";
1285+
12841286

12851287
void CWeapon::UpdateHUDAddonsVisibility()
1286-
{ // actor only
1288+
{
1289+
static shared_str wpn_scope = WPN_SCOPE;
1290+
static shared_str wpn_silencer = WPN_SILENCER;
1291+
static shared_str wpn_grenade_launcher = WPN_GRENADE_LAUNCHER;
1292+
1293+
// actor only
12871294
if (!GetHUDmode())
12881295
return;
12891296

@@ -1326,6 +1333,10 @@ void CWeapon::UpdateHUDAddonsVisibility()
13261333

13271334
void CWeapon::UpdateAddonsVisibility()
13281335
{
1336+
static shared_str wpn_scope = WPN_SCOPE;
1337+
static shared_str wpn_silencer = WPN_SILENCER;
1338+
static shared_str wpn_grenade_launcher = WPN_GRENADE_LAUNCHER;
1339+
13291340
IKinematics* pWeaponVisual = smart_cast<IKinematics*>(Visual());
13301341
R_ASSERT(pWeaponVisual);
13311342

src/xrGame/ai/stalker/ai_stalker_debug.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,11 +1594,6 @@ static void draw_animation_bones(
15941594
#endif // #ifdef DEBUG_RENDER
15951595
}
15961596

1597-
Fvector g_debug_position_0 = Fvector().set(0.f, 0.f, 0.f);
1598-
Fvector g_debug_position_1 = Fvector().set(0.f, 0.f, 0.f);
1599-
Fvector g_debug_position_2 = Fvector().set(0.f, 0.f, 0.f);
1600-
Fvector g_debug_position_3 = Fvector().set(0.f, 0.f, 0.f);
1601-
16021597
void CAI_Stalker::OnRender()
16031598
{
16041599
#if 0

src/xrGame/alife_storage_manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "saved_game_wrapper.h"
2121
#include "xrEngine/IGame_Persistent.h"
2222
#include "autosave_manager.h"
23-
XRCORE_API string_path g_bug_report_file;
2423

2524
using namespace ALife;
2625

src/xrGame/ui/Restrictions.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ u32 get_rank(const shared_str& section)
4141
return res;
4242
}
4343

44-
CRestrictions::CRestrictions()
45-
{
46-
m_rank = 0;
47-
m_bInited = false;
48-
}
49-
50-
CRestrictions::~CRestrictions() {}
5144
void CRestrictions::InitGroups()
5245
{
5346
if (m_bInited)

src/xrGame/ui/Restrictions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ typedef struct
1313
class CRestrictions
1414
{
1515
public:
16-
CRestrictions();
17-
~CRestrictions();
16+
CRestrictions() = default;
17+
~CRestrictions() = default;
1818

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

41-
u32 m_rank;
42-
bool m_bInited;
41+
u32 m_rank{};
42+
bool m_bInited{};
4343

4444
using group_items = xr_vector<shared_str>;
4545
using Groups = xr_map<shared_str, group_items>;

src/xrGame/ui/UIOptConCom.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
xr_token g_GameModes[] = {{"st_deathmatch", eGameIDDeathmatch}, {"st_team_deathmatch", eGameIDTeamDeathmatch},
1313
{"st_artefacthunt", eGameIDArtefactHunt}, {"st_capture_the_artefact", eGameIDCaptureTheArtefact}, {0, 0}};
1414

15-
CUIOptConCom::CUIOptConCom() { xr_strcpy(m_playerName, ""); }
1615
class CCC_UserName : public CCC_String
1716
{
1817
public:

src/xrGame/ui/UIOptConCom.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
class CUIOptConCom
44
{
5-
private:
6-
string64 reinforcementType;
5+
string64 reinforcementType{};
76

87
public:
8+
CUIOptConCom() = default;
9+
910
void Init();
10-
CUIOptConCom();
1111

1212
protected:
1313
enum
@@ -25,14 +25,14 @@ class CUIOptConCom
2525
fl_wo_ff = (1 << 4),
2626
fl_listen = (1 << 5),
2727
};
28-
int m_iMaxPlayers;
29-
Flags32 m_uNetSrvParams;
30-
Flags32 m_uNetFilter;
31-
u32 m_curGameMode;
32-
string64 m_playerName;
33-
string64 m_serverName;
34-
int m_iNetConSpectator;
35-
float m_fNetWeatherRate;
28+
int m_iMaxPlayers{};
29+
Flags32 m_uNetSrvParams{};
30+
Flags32 m_uNetFilter{};
31+
u32 m_curGameMode{};
32+
string64 m_playerName{};
33+
string64 m_serverName{};
34+
int m_iNetConSpectator{};
35+
float m_fNetWeatherRate{};
3636

3737
void ReadPlayerNameFromRegistry();
3838
void WritePlayerNameToRegistry();

src/xrGame/ui/UIStatsIcon.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
#include "Include/xrRender/UIShader.h"
77

8-
CUIStatsIcon::TEX_INFO CUIStatsIcon::m_tex_info[MAX_DEF_TEX][2];
9-
108
CUIStatsIcon::CUIStatsIcon()
119
: CUIStatic("CUIStatsIcon")
1210
{
@@ -16,19 +14,22 @@ CUIStatsIcon::CUIStatsIcon()
1614

1715
void CUIStatsIcon::InitTexInfo()
1816
{
19-
if (m_tex_info[RANK_0][0].sh->inited())
17+
if (m_tex_info)
2018
return;
19+
20+
m_tex_info = xr_new<tex_info_data>();
21+
2122
// ranks
2223
string128 rank_tex;
2324
for (int i = RANK_0; i <= RANK_4; i++)
2425
{
2526
xr_sprintf(rank_tex, "ui_hud_status_green_0%d", i + 1);
26-
CUITextureMaster::GetTextureShader(rank_tex, m_tex_info[i][0].sh);
27-
m_tex_info[i][0].rect = CUITextureMaster::GetTextureRect(rank_tex);
27+
CUITextureMaster::GetTextureShader(rank_tex, (*m_tex_info)[i][0].sh);
28+
(*m_tex_info)[i][0].rect = CUITextureMaster::GetTextureRect(rank_tex);
2829

2930
xr_sprintf(rank_tex, "ui_hud_status_blue_0%d", i + 1);
30-
CUITextureMaster::GetTextureShader(rank_tex, m_tex_info[i][1].sh);
31-
m_tex_info[i][1].rect = CUITextureMaster::GetTextureRect(rank_tex);
31+
CUITextureMaster::GetTextureShader(rank_tex, (*m_tex_info)[i][1].sh);
32+
(*m_tex_info)[i][1].rect = CUITextureMaster::GetTextureRect(rank_tex);
3233
}
3334

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

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

45-
m_tex_info[ARTEFACT][1] = m_tex_info[ARTEFACT][0];
46+
(*m_tex_info)[ARTEFACT][1] = (*m_tex_info)[ARTEFACT][0];
4647

4748
// death
48-
m_tex_info[DEATH][0].sh->create("hud" DELIMITER "default", "ui" DELIMITER "ui_mp_icon_kill");
49-
m_tex_info[DEATH][1] = m_tex_info[DEATH][0];
50-
m_tex_info[DEATH][0].rect.x1 = 32;
51-
m_tex_info[DEATH][0].rect.y1 = 202;
52-
m_tex_info[DEATH][0].rect.x2 = m_tex_info[DEATH][0].rect.x1 + 30;
53-
m_tex_info[DEATH][0].rect.y2 = m_tex_info[DEATH][0].rect.y1 + 30;
49+
(*m_tex_info)[DEATH][0].sh->create("hud" DELIMITER "default", "ui" DELIMITER "ui_mp_icon_kill");
50+
(*m_tex_info)[DEATH][1] = (*m_tex_info)[DEATH][0];
51+
(*m_tex_info)[DEATH][0].rect.x1 = 32;
52+
(*m_tex_info)[DEATH][0].rect.y1 = 202;
53+
(*m_tex_info)[DEATH][0].rect.x2 = (*m_tex_info)[DEATH][0].rect.x1 + 30;
54+
(*m_tex_info)[DEATH][0].rect.y2 = (*m_tex_info)[DEATH][0].rect.y1 + 30;
5455
}
5556

5657
void CUIStatsIcon::FreeTexInfo()
5758
{
5859
// ranks
5960
for (int i = RANK_0; i <= RANK_4; i++)
6061
{
61-
m_tex_info[i][0].sh->destroy();
62-
m_tex_info[i][1].sh->destroy();
62+
(*m_tex_info)[i][0].sh->destroy();
63+
(*m_tex_info)[i][1].sh->destroy();
6364
}
64-
m_tex_info[ARTEFACT][0].sh->destroy();
65-
m_tex_info[ARTEFACT][1].sh->destroy();
66-
m_tex_info[DEATH][0].sh->destroy();
67-
m_tex_info[DEATH][1].sh->destroy();
65+
(*m_tex_info)[ARTEFACT][0].sh->destroy();
66+
(*m_tex_info)[ARTEFACT][1].sh->destroy();
67+
(*m_tex_info)[DEATH][0].sh->destroy();
68+
(*m_tex_info)[DEATH][1].sh->destroy();
69+
70+
xr_delete(m_tex_info);
6871
}
6972

7073
void CUIStatsIcon::SetValue(LPCSTR str)
@@ -85,18 +88,18 @@ void CUIStatsIcon::SetValue(LPCSTR str)
8588

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

88-
SetShader(m_tex_info[rank][team].sh);
89-
SetTextureRect(m_tex_info[rank][team].rect);
91+
SetShader((*m_tex_info)[rank][team].sh);
92+
SetTextureRect((*m_tex_info)[rank][team].rect);
9093
}
9194
else if (0 == xr_strcmp(str, "death"))
9295
{
93-
SetShader(m_tex_info[DEATH][0].sh);
94-
SetTextureRect(m_tex_info[DEATH][0].rect);
96+
SetShader((*m_tex_info)[DEATH][0].sh);
97+
SetTextureRect((*m_tex_info)[DEATH][0].rect);
9598
}
9699
else if (0 == xr_strcmp(str, "artefact"))
97100
{
98-
SetShader(m_tex_info[ARTEFACT][0].sh);
99-
SetTextureRect(m_tex_info[ARTEFACT][0].rect);
101+
SetShader((*m_tex_info)[ARTEFACT][0].sh);
102+
SetTextureRect((*m_tex_info)[ARTEFACT][0].rect);
100103
}
101104
else
102105
{

src/xrGame/ui/UIStatsIcon.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ class CUIStatsIcon final : public CUIStatic
3434

3535
static void InitTexInfo();
3636
static void FreeTexInfo();
37-
static TEX_INFO m_tex_info[MAX_DEF_TEX][2];
37+
38+
using tex_info_data = std::array<TEX_INFO[2], MAX_DEF_TEX>;
39+
40+
inline static tex_info_data* m_tex_info;
3841
};

0 commit comments

Comments
 (0)