Skip to content

Commit d58139f

Browse files
committed
Very WIP fix of xrSE_Factory. Maybe something will spoil or break.
1 parent 365f327 commit d58139f

13 files changed

+172
-251
lines changed

src/utils/xrLCUtil/LevelCompilerLoggerWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void LevelCompilerLoggerWindow::Initialize(const char* name)
1919
InitCommonControls();
2020
Sleep(150);
2121
xr_strcpy(this->name, name);
22-
thread_spawn(LogThreadProc, "log-update", 1024 * 1024, 0);
22+
thread_spawn(LogThreadProc, "log-update", 1024 * 1024, this);
2323
while (!logWindow)
2424
Sleep(150);
2525
initialized = true;
@@ -56,7 +56,7 @@ void LevelCompilerLoggerWindow::LogThreadProc()
5656
{
5757
SetProcessPriorityBoost(GetCurrentProcess(), TRUE);
5858
logWindow =
59-
CreateDialog(HINSTANCE(GetModuleHandle(0)), MAKEINTRESOURCE(IDD_LOG), 0, LevelCompilerLoggerWindowDlgProc);
59+
CreateDialog(HINSTANCE(GetModuleHandle("xrLCUtil")), MAKEINTRESOURCE(IDD_LOG), 0, LevelCompilerLoggerWindowDlgProc);
6060
if (!logWindow)
6161
R_CHK(GetLastError());
6262
SetWindowText(logWindow, name);

src/utils/xrSE_Factory/ai_space.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,52 @@
99
#include "stdafx.h"
1010
#include "ai_space.h"
1111
#include "xrScriptEngine/script_engine.hpp"
12+
#include "xrServerEntities/object_factory.h"
1213

1314
CAI_Space* g_ai_space = nullptr;
1415

1516
CAI_Space::CAI_Space() { m_script_engine = nullptr; }
17+
18+
void CAI_Space::RegisterScriptClasses()
19+
{
20+
#ifdef DBG_DISABLE_SCRIPTS
21+
return;
22+
#else
23+
string_path S;
24+
FS.update_path(S, "$game_config$", "script.ltx");
25+
CInifile* l_tpIniFile = new CInifile(S);
26+
R_ASSERT(l_tpIniFile);
27+
if (!l_tpIniFile->section_exist("common"))
28+
{
29+
xr_delete(l_tpIniFile);
30+
return;
31+
}
32+
shared_str registrators = READ_IF_EXISTS(l_tpIniFile, r_string, "common", "class_registrators", "");
33+
xr_delete(l_tpIniFile);
34+
u32 registratorCount = _GetItemCount(*registrators);
35+
string256 I;
36+
for (u32 i = 0; i < registratorCount; i++)
37+
{
38+
_GetItem(*registrators, i, I);
39+
luabind::functor<void> result;
40+
if (!script_engine().functor(I, result))
41+
{
42+
script_engine().script_log(LuaMessageType::Error, "Cannot load class registrator %s!", I);
43+
continue;
44+
}
45+
result(const_cast<CObjectFactory*>(&object_factory()));
46+
}
47+
#endif
48+
}
49+
1650
void CAI_Space::init()
1751
{
1852
VERIFY(!m_script_engine);
1953
m_script_engine = new CScriptEngine();
20-
m_script_engine->init();
21-
#error additional initialization is required here: RegisterScriptClasses + object_factory().register_script()
22-
// RegisterScriptClasses();
23-
// object_factory().register_script();
24-
// LoadCommonScripts(); // for game only
54+
XRay::ScriptExporter::Reset(); // mark all nodes as undone
55+
m_script_engine->init(XRay::ScriptExporter::Export, true);
56+
RegisterScriptClasses();
57+
object_factory().register_script();
2558
}
2659

2760
CAI_Space::~CAI_Space() { xr_delete(m_script_engine); }

src/utils/xrSE_Factory/ai_space.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class CAI_Space
1515
private:
1616
CScriptEngine* m_script_engine;
1717

18+
void RegisterScriptClasses();
19+
1820
public:
1921
CAI_Space();
2022
virtual ~CAI_Space();

src/utils/xrSE_Factory/properties_list_helper_script.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ SCRIPT_EXPORT(
9999
.def("vector_on_after_edit", &CScriptPropertiesListHelper::FvectorRDOnAfterEdit)
100100
.def("vector_on_before_edit", &CScriptPropertiesListHelper::FvectorRDOnBeforeEdit)
101101
// .def("vector_on_draw", &CScriptPropertiesListHelper::FvectorRDOnDraw)
102-
.def("float_on_after_edit", &CScriptPropertiesListHelper::floatRDOnAfterEdit)
103-
.def("float_on_before_edit", &CScriptPropertiesListHelper::floatRDOnBeforeEdit)
102+
.def("float_on_after_edit", &CScriptPropertiesListHelper::floatRDOnAfterEdit, luabind::policy::out_value<3>())
103+
.def("float_on_before_edit", &CScriptPropertiesListHelper::floatRDOnBeforeEdit, luabind::policy::out_value<3>())
104104
// .def("float_on_draw", &CScriptPropertiesListHelper::floatRDOnDraw)
105-
.def("name_after_edit", &CScriptPropertiesListHelper::NameAfterEdit)
106-
.def("name_before_edit", &CScriptPropertiesListHelper::NameBeforeEdit)
105+
.def("name_after_edit", &CScriptPropertiesListHelper::NameAfterEdit, luabind::policy::pure_out_value<3>())
106+
.def("name_before_edit", &CScriptPropertiesListHelper::NameBeforeEdit, luabind::policy::pure_out_value<3>())
107107
// .def("name_on_draw", &CScriptPropertiesListHelper::NameDraw)
108108

109109
.def("create_caption", &CScriptPropertiesListHelper::CreateCaption)

src/utils/xrSE_Factory/stdafx.h

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,52 @@
88

99
#pragma once
1010

11-
#include "Common/Common.hpp"
12-
#include "xrCore/xrCore.h"
13-
1411
#define ENGINE_API
1512
#define ECORE_API
16-
#define DLL_API XR_EXPORT
13+
//#define DLL_API XR_EXPORT
14+
#define XRSCRIPTENGINE_EXPORTS
15+
//#define XRGAME_EXPORTS
1716

18-
#include "clsid_game.h"
17+
#include "Common/Common.hpp"
18+
#include "xrCore/xrCore.h"
19+
#include "xrScriptEngine/xrScriptEngine.hpp"
20+
#include "xrCDB/xrCDB.h"
21+
#include "xrCore/_fbox.h"
22+
#include "xrCore/_quaternion.h"
1923

20-
namespace std
21-
{
22-
class exception;
23-
}
24-
namespace boost
25-
{
26-
void throw_exception(std::exception const& A);
27-
}
24+
#include "clsid_game.h"
2825

2926
#include "smart_cast.h"
3027

31-
#define READ_IF_EXISTS(ltx, method, section, name, default_value) \
28+
#define READ_IF_EXISTS(ltx, method, section, name, default_value)\
3229
(ltx->line_exist(section, name)) ? ltx->method(section, name) : default_value
3330

3431
#if XRAY_EXCEPTIONS
3532
IC xr_string string2xr_string(LPCSTR s) { return s ? s : ""; }
33+
#define THROW(xpr)\
34+
if (!(xpr))\
35+
{\
36+
throw __FILE__LINE__ "\"" #xpr "\"";\
37+
}
38+
#define THROW2(xpr, msg0)\
39+
if (!(xpr))\
40+
{\
41+
throw *shared_str(\
42+
xr_string(__FILE__LINE__).append(" \"").append(#xpr).append(string2xr_string(msg0)).c_str());\
43+
}
44+
#define THROW3(xpr, msg0, msg1)\
45+
if (!(xpr))\
46+
{\
47+
throw *shared_str(xr_string(__FILE__LINE__)\
48+
.append(" \"")\
49+
.append(#xpr)\
50+
.append(string2xr_string(msg0))\
51+
.append(", ")\
52+
.append(string2xr_string(msg1))\
53+
.c_str());\
54+
}
55+
#else
56+
#define THROW VERIFY
57+
#define THROW2 VERIFY2
58+
#define THROW3 VERIFY3
3659
#endif

src/utils/xrSE_Factory/xrSE_Factory.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
// Description : Precompiled header creatore
77
////////////////////////////////////////////////////////////////////////////
88

9-
#include "pch_script.h"
9+
#include "stdafx.h"
1010
#include "xrSE_Factory.h"
1111
#include "ai_space.h"
1212
#include "xrScriptEngine/script_engine.hpp"
1313
#include "object_factory.h"
14-
#include "xrEProps.h"
1514
#include "xrSE_Factory_import_export.h"
1615
#include "script_properties_list_helper.h"
16+
#include "xrCore/ModuleLookup.hpp"
1717

1818
#include "character_info.h"
1919
#include "specific_character.h"
2020

2121
extern CSE_Abstract* F_entity_Create(LPCSTR section);
2222

2323
extern CScriptPropertiesListHelper* g_property_list_helper;
24-
extern HMODULE prop_helper_module;
24+
extern std::unique_ptr<XRay::Module> prop_helper_module;
2525

2626
extern "C" {
2727
FACTORY_API IServerEntity* __stdcall create_entity(LPCSTR section) { return F_entity_Create(section); }
@@ -33,11 +33,14 @@ FACTORY_API void __stdcall destroy_entity(IServerEntity*& abstract)
3333
}
3434
};
3535

36+
// !!!!!!! Very ugly fix !!!!!!!
37+
XRay::ScriptExporter::Node* XRay::ScriptExporter::Node::firstNode;
38+
XRay::ScriptExporter::Node* XRay::ScriptExporter::Node::lastNode;
39+
size_t XRay::ScriptExporter::Node::nodeCount;
40+
3641
// typedef void DUMMY_STUFF (const void*,const u32&,void*);
3742
// XRCORE_API DUMMY_STUFF *g_temporary_stuff;
3843

39-
void setup_luabind_allocator();
40-
4144
//#define TRIVIAL_ENCRYPTOR_DECODER
4245

4346
BOOL APIENTRY DllMain(HANDLE module_handle, DWORD call_reason, LPVOID reserved)
@@ -53,8 +56,6 @@ BOOL APIENTRY DllMain(HANDLE module_handle, DWORD call_reason, LPVOID reserved)
5356
FS.update_path(SYSTEM_LTX, "$game_config$", "system.ltx");
5457
pSettings = new CInifile(SYSTEM_LTX);
5558

56-
setup_luabind_allocator();
57-
5859
CCharacterInfo::InitInternal();
5960
CSpecificCharacter::InitInternal();
6061

@@ -74,7 +75,7 @@ BOOL APIENTRY DllMain(HANDLE module_handle, DWORD call_reason, LPVOID reserved)
7475
xr_delete(g_ai_space);
7576
xr_delete(g_object_factory);
7677
if (prop_helper_module)
77-
FreeLibrary(prop_helper_module);
78+
prop_helper_module->close();
7879
Core._destroy();
7980
break;
8081
}

0 commit comments

Comments
 (0)