Skip to content

Commit

Permalink
Refactor renderers loading system
Browse files Browse the repository at this point in the history
Engine anyway loads all 4 renderers and hold them in memory..
  • Loading branch information
Xottab-DUTY committed Jan 9, 2018
1 parent 71181ab commit d533f5b
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 96 deletions.
11 changes: 11 additions & 0 deletions src/Include/xrAPI/xrAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ISoundManager;

class XRAPI_API EngineGlobalEnvironment
{
using SupportCheck = bool(*)();
using SetupEnv = void(*)();
public:
#ifdef _EDITOR
CRender* Render;
Expand All @@ -31,6 +33,15 @@ class XRAPI_API EngineGlobalEnvironment
ISoundManager* Sound;

bool isDedicatedServer;

SupportCheck CheckR2;
SupportCheck CheckR3;
SupportCheck CheckR4;
SetupEnv SetupR1;
SetupEnv SetupR2;
SetupEnv SetupR3;
SetupEnv SetupR4;
SetupEnv SetupCurrentRenderer;
};

extern XRAPI_API EngineGlobalEnvironment GEnv;
17 changes: 15 additions & 2 deletions src/Layers/xrRenderPC_R1/xrRender_R1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma comment(lib, "xrEngine.lib")

extern "C" void XR_EXPORT SetupEnv()
void SetupEnvR1()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -14,5 +14,18 @@ extern "C" void XR_EXPORT SetupEnv()
#ifdef DEBUG
GEnv.DRender = &DebugRenderImpl;
#endif
xrRender_initconsole(); // XXX: Xottab_DUTY: move somewhere
xrRender_initconsole();
}

// This must not be optimized by compiler
#pragma optimize("", off)
static const volatile class GEnvHelper
{
public:
GEnvHelper()
{
GEnv.SetupR1 = SetupEnvR1;
}
} helper;
#pragma optimize("", on)

19 changes: 16 additions & 3 deletions src/Layers/xrRenderPC_R2/xrRender_R2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma comment(lib, "xrEngine.lib")

extern "C" void XR_EXPORT SetupEnv()
void SetupEnvR2()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -14,10 +14,10 @@ extern "C" void XR_EXPORT SetupEnv()
#ifdef DEBUG
GEnv.DRender = &DebugRenderImpl;
#endif
xrRender_initconsole(); // XXX: Xottab_DUTY: move somewhere
xrRender_initconsole();
}

extern "C" bool XR_EXPORT SupportsAdvancedRendering()
bool SupportsAdvancedRendering()
{
D3DCAPS9 caps;
CHW _HW;
Expand All @@ -31,3 +31,16 @@ extern "C" bool XR_EXPORT SupportsAdvancedRendering()
else
return true;
}

// This must not be optimized by compiler
#pragma optimize("", off)
static const volatile class GEnvHelper
{
public:
GEnvHelper()
{
GEnv.CheckR2 = SupportsAdvancedRendering;
GEnv.SetupR2 = SetupEnvR2;
}
} helper;
#pragma optimize("", on)
19 changes: 16 additions & 3 deletions src/Layers/xrRenderPC_R3/xrRender_R3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma comment(lib, "xrEngine.lib")

extern "C" void XR_EXPORT SetupEnv()
void SetupEnvR3()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -14,10 +14,10 @@ extern "C" void XR_EXPORT SetupEnv()
#ifdef DEBUG
GEnv.DRender = &DebugRenderImpl;
#endif
xrRender_initconsole(); // XXX: Xottab_DUTY: move somewhere
xrRender_initconsole();
}

extern "C" bool XR_EXPORT SupportsDX10Rendering()
bool SupportsDX10Rendering()
{
return xrRender_test_hw() ? true : false;
/*
Expand All @@ -34,3 +34,16 @@ extern "C" bool XR_EXPORT SupportsDX10Rendering()
return true;
*/
}

// This must not be optimized by compiler
#pragma optimize("", off)
static const volatile class GEnvHelper
{
public:
GEnvHelper()
{
GEnv.CheckR3 = SupportsDX10Rendering;
GEnv.SetupR3 = SetupEnvR3;
}
} helper;
#pragma optimize("", on)
20 changes: 17 additions & 3 deletions src/Layers/xrRenderPC_R4/xrRender_R4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#include "Layers/xrRender/dxRenderFactory.h"
#include "Layers/xrRender/dxUIRender.h"
#include "Layers/xrRender/dxDebugRender.h"
#include "Include/xrAPI/xrAPI.h"

#pragma comment(lib, "xrEngine.lib")

extern "C" void XR_EXPORT SetupEnv()
void SetupEnvR4()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -14,10 +15,10 @@ extern "C" void XR_EXPORT SetupEnv()
#ifdef DEBUG
GEnv.DRender = &DebugRenderImpl;
#endif
xrRender_initconsole(); // XXX: Xottab_DUTY: move somewhere
xrRender_initconsole();
}

extern "C" bool XR_EXPORT SupportsDX11Rendering()
bool SupportsDX11Rendering()
{
return xrRender_test_hw() ? true : false;
/*
Expand All @@ -34,3 +35,16 @@ extern "C" bool XR_EXPORT SupportsDX11Rendering()
return true;
*/
}

// This must not be optimized by compiler
#pragma optimize("", off)
static const volatile class GEnvHelper
{
public:
GEnvHelper()
{
GEnv.CheckR4 = SupportsDX11Rendering;
GEnv.SetupR4 = SetupEnvR4;
}
} helper;
#pragma optimize("", on)
Loading

0 comments on commit d533f5b

Please sign in to comment.