Skip to content

Commit c099b90

Browse files
committed
Simplify module handle usage
1 parent 7502e1d commit c099b90

File tree

14 files changed

+54
-41
lines changed

14 files changed

+54
-41
lines changed

src/Layers/xrRender/HW.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void CHW::CreateD3D()
8484
{
8585
const pcstr _name = GEnv.isDedicatedServer ? "xrD3D9-Null" : "d3d9.dll";
8686

87-
hD3D = std::make_unique<XRay::Module>(_name);
87+
hD3D = XRay::LoadModule(_name);
8888

8989
R_ASSERT2(hD3D->exist(), "Can't find 'd3d9.dll'\nPlease install latest version of DirectX before running this program");
9090
typedef IDirect3D9* WINAPI _Direct3DCreate9(UINT SDKVersion);

src/Layers/xrRender/HW.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CHW
8989
D3D_FEATURE_LEVEL FeatureLevel;
9090
#else
9191
private:
92-
std::unique_ptr<XRay::Module> hD3D;
92+
XRay::Module hD3D;
9393

9494
public:
9595
IDirect3D9* pD3D; // D3D

src/Layers/xrRenderPC_R4/r2_test_hw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef HRESULT(__stdcall* FuncPtrD3D11CreateDeviceAndSwapChain)(IDXGIAdapter* p
1313

1414
bool TestDX11Present()
1515
{
16-
const auto hD3D11 = std::make_unique<XRay::Module>("d3d11.dll");
16+
const auto hD3D11 = XRay::LoadModule("d3d11.dll");
1717

1818
if (!hD3D11->exist())
1919
{

src/utils/xrAI/xrAI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void execute(LPSTR cmd)
102102
char* no_separator_check = strstr(cmd, "-no_separator_check");
103103
clear_temp_folder();
104104

105-
const auto hFactory = std::make_unique<XRay::Module>("xrSE_Factory");
105+
const auto hFactory = XRay::LoadModule("xrSE_Factory");
106106

107107
R_ASSERT2(hFactory->exist(), "Factory DLL raised exception during loading or there is no factory DLL at all");
108108

src/utils/xrLC/xrLC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void Startup(LPSTR lpCmdLine)
9393
if (bModifyOptions)
9494
{
9595
Logger.Phase("Project options...");
96-
const auto L = std::make_unique<XRay::Module>("xrLC_Options");
96+
const auto L = XRay::LoadModule("xrLC_Options");
9797

9898
const auto O = (xrOptions*)L->getProcAddress("_frmScenePropertiesRun");
9999
R_ASSERT(O);

src/utils/xrSE_Factory/properties_list_helper_script.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ struct CChooseType
2121
{
2222
};
2323

24-
typedef IPropHelper&(__stdcall* TPHelper)();
24+
using TPHelper = IPropHelper&(__stdcall* )();
2525

2626
TPHelper _PHelper = nullptr;
27-
std::unique_ptr<XRay::Module> prop_helper_module;
27+
XRay::Module prop_helper_module;
2828
constexpr pcstr prop_helper_library = "xrEPropsB", prop_helper_func = "PHelper";
2929
CScriptPropertiesListHelper* g_property_list_helper = nullptr;
3030

3131
void load_prop_helper()
3232
{
33-
prop_helper_module = std::make_unique<XRay::Module>(prop_helper_library);
33+
prop_helper_module = XRay::LoadModule(prop_helper_library);
3434
if (!prop_helper_module->exist())
3535
{
3636
Msg("! Cannot find library %s", prop_helper_library);

src/utils/xrSE_Factory/xrSE_Factory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
extern CSE_Abstract* F_entity_Create(LPCSTR section);
2121

2222
extern CScriptPropertiesListHelper* g_property_list_helper;
23-
extern std::unique_ptr<XRay::Module> prop_helper_module;
23+
extern XRay::Module prop_helper_module;
2424

2525
extern "C" {
2626
FACTORY_API IServerEntity* __stdcall create_entity(LPCSTR section) { return F_entity_Create(section); }

src/xrCore/ModuleLookup.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
namespace XRay
66
{
7-
Module::Module(const bool dontUnload) : handle(nullptr), dontUnload(dontUnload) {}
7+
ModuleHandle::ModuleHandle(const bool dontUnload) : handle(nullptr), dontUnload(dontUnload) {}
88

9-
Module::Module(pcstr moduleName, bool dontUnload /*= false*/) : handle(nullptr), dontUnload(dontUnload)
9+
ModuleHandle::ModuleHandle(pcstr moduleName, bool dontUnload /*= false*/) : handle(nullptr), dontUnload(dontUnload)
1010
{
1111
open(moduleName);
1212
}
1313

14-
Module::~Module()
14+
ModuleHandle::~ModuleHandle()
1515
{
1616
close();
1717
}
1818

19-
void* Module::open(pcstr moduleName)
19+
void* ModuleHandle::open(pcstr moduleName)
2020
{
2121
if (exist())
2222
close();
@@ -31,7 +31,7 @@ void* Module::open(pcstr moduleName)
3131
return handle;
3232
}
3333

34-
void Module::close()
34+
void ModuleHandle::close()
3535
{
3636
if (dontUnload)
3737
return;
@@ -40,18 +40,18 @@ void Module::close()
4040
handle = nullptr;
4141
}
4242

43-
bool Module::exist() const
43+
bool ModuleHandle::exist() const
4444
{
4545
return handle != nullptr;
4646
}
4747

48-
void* Module::operator()() const
48+
void* ModuleHandle::operator()() const
4949
{
5050
return handle;
5151
}
5252

53-
void* Module::getProcAddress(pcstr procName) const
53+
void* ModuleHandle::getProcAddress(pcstr procName) const
5454
{
55-
return ::GetProcAddress(static_cast<HMODULE>(handle), procName);
55+
return GetProcAddress(static_cast<HMODULE>(handle), procName);
5656
}
5757
}

src/xrCore/ModuleLookup.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#pragma once
2+
#include <memory>
23

34
namespace XRay
45
{
5-
class XRCORE_API Module
6+
class XRCORE_API ModuleHandle
67
{
78
void* handle;
89
bool dontUnload;
910

1011
public:
11-
Module(const bool dontUnload = false);
12-
Module(pcstr moduleName, bool dontUnload = false);
13-
~Module();
12+
ModuleHandle(const bool dontUnload = false);
13+
ModuleHandle(pcstr moduleName, bool dontUnload = false);
14+
~ModuleHandle();
1415

1516
void* open(pcstr moduleName);
1617
void close();
@@ -21,4 +22,16 @@ class XRCORE_API Module
2122

2223
void* getProcAddress(pcstr procName) const;
2324
};
25+
26+
using Module = std::unique_ptr<ModuleHandle>;
27+
28+
inline auto LoadModule(bool dontUnload = false)
29+
{
30+
return std::make_unique<ModuleHandle>(dontUnload);
31+
}
32+
33+
inline auto LoadModule(pcstr moduleName, bool dontUnload = false)
34+
{
35+
return std::make_unique<ModuleHandle>(moduleName, dontUnload);
36+
}
2437
}

src/xrEngine/Device_Initialize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
1010

1111
void CRenderDevice::initialize_editor()
1212
{
13-
m_editor_module = std::make_unique<XRay::Module>("xrWeatherEditor");
13+
m_editor_module = XRay::LoadModule("xrWeatherEditor");
1414
if (!m_editor_module->exist())
1515
return;
1616

0 commit comments

Comments
 (0)