Skip to content

Commit 62055f2

Browse files
committed
New field for GEnv: CurrentRenderer
Used instead of g_current_renderer. Improvements for previous commits
1 parent f28b8a9 commit 62055f2

File tree

10 files changed

+29
-34
lines changed

10 files changed

+29
-34
lines changed

src/Include/xrAPI/xrAPI.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,22 @@ class XRAPI_API EngineGlobalEnvironment
1616
{
1717
using SupportCheck = bool(*)();
1818
using SetupEnv = void(*)();
19+
1920
public:
20-
#ifdef _EDITOR
21-
CRender* Render;
22-
#else
2321
IRender* Render;
2422
IDebugRender* DRender;
2523
CDUInterface* DU;
2624
xr_token* vid_mode_token;
2725
IUIRender* UIRender;
2826
CGameMtlLibrary* PGMLib;
29-
#endif
3027
IRenderFactory* RenderFactory;
3128
CScriptEngine* ScriptEngine;
3229
AISpaceBase* AISpace;
3330
ISoundManager* Sound;
3431

3532
bool isDedicatedServer;
3633

34+
int CurrentRenderer;
3735
SupportCheck CheckR2;
3836
SupportCheck CheckR3;
3937
SupportCheck CheckR4;

src/Layers/xrRender/HW.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ D3DFORMAT CHW::selectDepthStencil(D3DFORMAT fTarget)
106106
{
107107
// R2 hack
108108
#pragma todo("R2 need to specify depth format")
109-
if (psDeviceFlags.test(rsR2))
109+
if (GEnv.CurrentRenderer == 2)
110110
return D3DFMT_D24S8;
111111

112112
// R1 usual

src/Layers/xrRender/Texture.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void fix_texture_name(LPSTR fn)
2020
}
2121
}
2222

23-
ENGINE_API int g_current_renderer;
2423
#ifndef _EDITOR
2524
ENGINE_API bool is_enough_address_space_available();
2625
#else
@@ -44,7 +43,7 @@ int get_texture_load_lod(LPCSTR fn)
4443
{
4544
if (psTextureLOD < 1)
4645
{
47-
if (enough_address_space_available || (g_current_renderer < 2))
46+
if (enough_address_space_available || GEnv.CurrentRenderer < 2)
4847
return 0;
4948
else
5049
return 1;
@@ -58,7 +57,7 @@ int get_texture_load_lod(LPCSTR fn)
5857

5958
if (psTextureLOD < 2)
6059
{
61-
//if (enough_address_space_available || g_current_renderer<2)
60+
//if (enough_address_space_available || GEnv.CurrentRenderer < 2)
6261
return 0;
6362
//else
6463
// return 1;

src/Layers/xrRenderPC_R1/xrRender_R1.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ void SetupEnvR1()
1818
}
1919

2020
// This must not be optimized by compiler
21-
#pragma optimize("", off)
2221
static const volatile class GEnvHelper
2322
{
2423
public:
2524
GEnvHelper()
2625
{
2726
GEnv.SetupR1 = SetupEnvR1;
2827
}
28+
~GEnvHelper()
29+
{
30+
GEnv.SetupR1 = nullptr;
31+
}
2932
} helper;
30-
#pragma optimize("", on)
31-

src/Layers/xrRenderPC_R2/xrRender_R2.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ bool SupportsAdvancedRendering()
3333
}
3434

3535
// This must not be optimized by compiler
36-
#pragma optimize("", off)
3736
static const volatile class GEnvHelper
3837
{
3938
public:
@@ -42,5 +41,9 @@ static const volatile class GEnvHelper
4241
GEnv.CheckR2 = SupportsAdvancedRendering;
4342
GEnv.SetupR2 = SetupEnvR2;
4443
}
44+
~GEnvHelper()
45+
{
46+
GEnv.CheckR2 = nullptr;
47+
GEnv.SetupR2 = nullptr;
48+
}
4549
} helper;
46-
#pragma optimize("", on)

src/Layers/xrRenderPC_R3/xrRender_R3.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ bool SupportsDX10Rendering()
3636
}
3737

3838
// This must not be optimized by compiler
39-
#pragma optimize("", off)
4039
static const volatile class GEnvHelper
4140
{
4241
public:
@@ -45,5 +44,9 @@ static const volatile class GEnvHelper
4544
GEnv.CheckR3 = SupportsDX10Rendering;
4645
GEnv.SetupR3 = SetupEnvR3;
4746
}
47+
~GEnvHelper()
48+
{
49+
GEnv.CheckR3 = nullptr;
50+
GEnv.SetupR3 = nullptr;
51+
}
4852
} helper;
49-
#pragma optimize("", on)

src/Layers/xrRenderPC_R4/xrRender_R4.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ bool SupportsDX11Rendering()
3737
}
3838

3939
// This must not be optimized by compiler
40-
#pragma optimize("", off)
4140
static const volatile class GEnvHelper
4241
{
4342
public:
@@ -46,5 +45,9 @@ static const volatile class GEnvHelper
4645
GEnv.CheckR4 = SupportsDX11Rendering;
4746
GEnv.SetupR4 = SetupEnvR4;
4847
}
48+
~GEnvHelper()
49+
{
50+
GEnv.CheckR4 = nullptr;
51+
GEnv.SetupR4 = nullptr;
52+
}
4953
} helper;
50-
#pragma optimize("", on)

src/utils/xrAI/xrAI.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ void execute(LPSTR cmd)
123123

124124
const auto hFactory = std::make_unique<XRay::Module>("xrSE_Factory");
125125

126-
if (!hFactory->exist())
127-
R_CHK(GetLastError());
128126
R_ASSERT2(hFactory->exist(), "Factory DLL raised exception during loading or there is no factory DLL at all");
129127

130128
#ifdef XR_X64

src/xrEngine/EngineAPI.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ CEngineAPI::~CEngineAPI()
4141
}
4242

4343
extern u32 renderer_value; // con cmd
44-
ENGINE_API int g_current_renderer = 0;
4544

4645
bool is_enough_address_space_available()
4746
{
@@ -54,26 +53,23 @@ void CEngineAPI::InitializeNotDedicated()
5453
{
5554
if (psDeviceFlags.test(rsR4))
5655
{
57-
5856
if (hRenderR4->exist())
5957
{
60-
g_current_renderer = 4;
58+
GEnv.CurrentRenderer = 4;
6159
GEnv.SetupCurrentRenderer = GEnv.SetupR4;
6260
}
6361
else
6462
{
6563
psDeviceFlags.set(rsR4, false);
6664
psDeviceFlags.set(rsR3, true);
6765
}
68-
69-
7066
}
7167

7268
if (psDeviceFlags.test(rsR3))
7369
{
7470
if (hRenderR3->exist())
7571
{
76-
g_current_renderer = 3;
72+
GEnv.CurrentRenderer = 3;
7773
GEnv.SetupCurrentRenderer = GEnv.SetupR3;
7874
}
7975
else
@@ -85,10 +81,9 @@ void CEngineAPI::InitializeNotDedicated()
8581

8682
if (psDeviceFlags.test(rsR2))
8783
{
88-
8984
if (hRenderR2->exist())
9085
{
91-
g_current_renderer = 2;
86+
GEnv.CurrentRenderer = 2;
9287
GEnv.SetupCurrentRenderer = GEnv.SetupR2;
9388
}
9489
else
@@ -105,7 +100,7 @@ void CEngineAPI::InitializeRenderers()
105100
{
106101
R_ASSERT(hRenderR1);
107102
renderer_value = 0; // con cmd
108-
g_current_renderer = 1;
103+
GEnv.CurrentRenderer = 1;
109104
GEnv.SetupCurrentRenderer = GEnv.SetupR1;
110105
}
111106

@@ -117,9 +112,6 @@ void CEngineAPI::InitializeRenderers()
117112
void CEngineAPI::Initialize(void)
118113
{
119114
hGame = std::make_unique<XRay::Module>("xrGame");
120-
121-
if (!hGame->exist())
122-
R_CHK(GetLastError());
123115
R_ASSERT2(hGame, "Game DLL raised exception during loading or there is no game DLL at all");
124116

125117
pCreate = (Factory_Create*)hGame->getProcAddress("xrFactory_Create");

src/xrGame/Torch.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ static const float OPTIMIZATION_DISTANCE = 100.f;
2828

2929
static bool stalker_use_dynamic_lights = false;
3030

31-
ENGINE_API int g_current_renderer;
32-
3331
CTorch::CTorch(void)
3432
{
3533
light_render = GEnv.Render->light_create();
@@ -50,7 +48,7 @@ CTorch::CTorch(void)
5048

5149
// Disabling shift by x and z axes for 1st render,
5250
// because we don't have dynamic lighting in it.
53-
if (g_current_renderer == 1)
51+
if (GEnv.CurrentRenderer == 1)
5452
{
5553
TORCH_OFFSET.x = 0;
5654
TORCH_OFFSET.z = 0;

0 commit comments

Comments
 (0)