Skip to content

Commit

Permalink
Very WIP fix of xrSE_Factory. Maybe something will spoil or break.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr committed Dec 29, 2017
1 parent 365f327 commit d58139f
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 251 deletions.
4 changes: 2 additions & 2 deletions src/utils/xrLCUtil/LevelCompilerLoggerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void LevelCompilerLoggerWindow::Initialize(const char* name)
InitCommonControls();
Sleep(150);
xr_strcpy(this->name, name);
thread_spawn(LogThreadProc, "log-update", 1024 * 1024, 0);
thread_spawn(LogThreadProc, "log-update", 1024 * 1024, this);
while (!logWindow)
Sleep(150);
initialized = true;
Expand Down Expand Up @@ -56,7 +56,7 @@ void LevelCompilerLoggerWindow::LogThreadProc()
{
SetProcessPriorityBoost(GetCurrentProcess(), TRUE);
logWindow =
CreateDialog(HINSTANCE(GetModuleHandle(0)), MAKEINTRESOURCE(IDD_LOG), 0, LevelCompilerLoggerWindowDlgProc);
CreateDialog(HINSTANCE(GetModuleHandle("xrLCUtil")), MAKEINTRESOURCE(IDD_LOG), 0, LevelCompilerLoggerWindowDlgProc);
if (!logWindow)
R_CHK(GetLastError());
SetWindowText(logWindow, name);
Expand Down
43 changes: 38 additions & 5 deletions src/utils/xrSE_Factory/ai_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,52 @@
#include "stdafx.h"
#include "ai_space.h"
#include "xrScriptEngine/script_engine.hpp"
#include "xrServerEntities/object_factory.h"

CAI_Space* g_ai_space = nullptr;

CAI_Space::CAI_Space() { m_script_engine = nullptr; }

void CAI_Space::RegisterScriptClasses()
{
#ifdef DBG_DISABLE_SCRIPTS
return;
#else
string_path S;
FS.update_path(S, "$game_config$", "script.ltx");
CInifile* l_tpIniFile = new CInifile(S);
R_ASSERT(l_tpIniFile);
if (!l_tpIniFile->section_exist("common"))
{
xr_delete(l_tpIniFile);
return;
}
shared_str registrators = READ_IF_EXISTS(l_tpIniFile, r_string, "common", "class_registrators", "");
xr_delete(l_tpIniFile);
u32 registratorCount = _GetItemCount(*registrators);
string256 I;
for (u32 i = 0; i < registratorCount; i++)
{
_GetItem(*registrators, i, I);
luabind::functor<void> result;
if (!script_engine().functor(I, result))
{
script_engine().script_log(LuaMessageType::Error, "Cannot load class registrator %s!", I);
continue;
}
result(const_cast<CObjectFactory*>(&object_factory()));
}
#endif
}

void CAI_Space::init()
{
VERIFY(!m_script_engine);
m_script_engine = new CScriptEngine();
m_script_engine->init();
#error additional initialization is required here: RegisterScriptClasses + object_factory().register_script()
// RegisterScriptClasses();
// object_factory().register_script();
// LoadCommonScripts(); // for game only
XRay::ScriptExporter::Reset(); // mark all nodes as undone
m_script_engine->init(XRay::ScriptExporter::Export, true);
RegisterScriptClasses();
object_factory().register_script();
}

CAI_Space::~CAI_Space() { xr_delete(m_script_engine); }
2 changes: 2 additions & 0 deletions src/utils/xrSE_Factory/ai_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CAI_Space
private:
CScriptEngine* m_script_engine;

void RegisterScriptClasses();

public:
CAI_Space();
virtual ~CAI_Space();
Expand Down
8 changes: 4 additions & 4 deletions src/utils/xrSE_Factory/properties_list_helper_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ SCRIPT_EXPORT(
.def("vector_on_after_edit", &CScriptPropertiesListHelper::FvectorRDOnAfterEdit)
.def("vector_on_before_edit", &CScriptPropertiesListHelper::FvectorRDOnBeforeEdit)
// .def("vector_on_draw", &CScriptPropertiesListHelper::FvectorRDOnDraw)
.def("float_on_after_edit", &CScriptPropertiesListHelper::floatRDOnAfterEdit)
.def("float_on_before_edit", &CScriptPropertiesListHelper::floatRDOnBeforeEdit)
.def("float_on_after_edit", &CScriptPropertiesListHelper::floatRDOnAfterEdit, luabind::policy::out_value<3>())
.def("float_on_before_edit", &CScriptPropertiesListHelper::floatRDOnBeforeEdit, luabind::policy::out_value<3>())
// .def("float_on_draw", &CScriptPropertiesListHelper::floatRDOnDraw)
.def("name_after_edit", &CScriptPropertiesListHelper::NameAfterEdit)
.def("name_before_edit", &CScriptPropertiesListHelper::NameBeforeEdit)
.def("name_after_edit", &CScriptPropertiesListHelper::NameAfterEdit, luabind::policy::pure_out_value<3>())
.def("name_before_edit", &CScriptPropertiesListHelper::NameBeforeEdit, luabind::policy::pure_out_value<3>())
// .def("name_on_draw", &CScriptPropertiesListHelper::NameDraw)

.def("create_caption", &CScriptPropertiesListHelper::CreateCaption)
Expand Down
51 changes: 37 additions & 14 deletions src/utils/xrSE_Factory/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,52 @@

#pragma once

#include "Common/Common.hpp"
#include "xrCore/xrCore.h"

#define ENGINE_API
#define ECORE_API
#define DLL_API XR_EXPORT
//#define DLL_API XR_EXPORT
#define XRSCRIPTENGINE_EXPORTS
//#define XRGAME_EXPORTS

#include "clsid_game.h"
#include "Common/Common.hpp"
#include "xrCore/xrCore.h"
#include "xrScriptEngine/xrScriptEngine.hpp"
#include "xrCDB/xrCDB.h"
#include "xrCore/_fbox.h"
#include "xrCore/_quaternion.h"

namespace std
{
class exception;
}
namespace boost
{
void throw_exception(std::exception const& A);
}
#include "clsid_game.h"

#include "smart_cast.h"

#define READ_IF_EXISTS(ltx, method, section, name, default_value) \
#define READ_IF_EXISTS(ltx, method, section, name, default_value)\
(ltx->line_exist(section, name)) ? ltx->method(section, name) : default_value

#if XRAY_EXCEPTIONS
IC xr_string string2xr_string(LPCSTR s) { return s ? s : ""; }
#define THROW(xpr)\
if (!(xpr))\
{\
throw __FILE__LINE__ "\"" #xpr "\"";\
}
#define THROW2(xpr, msg0)\
if (!(xpr))\
{\
throw *shared_str(\
xr_string(__FILE__LINE__).append(" \"").append(#xpr).append(string2xr_string(msg0)).c_str());\
}
#define THROW3(xpr, msg0, msg1)\
if (!(xpr))\
{\
throw *shared_str(xr_string(__FILE__LINE__)\
.append(" \"")\
.append(#xpr)\
.append(string2xr_string(msg0))\
.append(", ")\
.append(string2xr_string(msg1))\
.c_str());\
}
#else
#define THROW VERIFY
#define THROW2 VERIFY2
#define THROW3 VERIFY3
#endif
17 changes: 9 additions & 8 deletions src/utils/xrSE_Factory/xrSE_Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
// Description : Precompiled header creatore
////////////////////////////////////////////////////////////////////////////

#include "pch_script.h"
#include "stdafx.h"
#include "xrSE_Factory.h"
#include "ai_space.h"
#include "xrScriptEngine/script_engine.hpp"
#include "object_factory.h"
#include "xrEProps.h"
#include "xrSE_Factory_import_export.h"
#include "script_properties_list_helper.h"
#include "xrCore/ModuleLookup.hpp"

#include "character_info.h"
#include "specific_character.h"

extern CSE_Abstract* F_entity_Create(LPCSTR section);

extern CScriptPropertiesListHelper* g_property_list_helper;
extern HMODULE prop_helper_module;
extern std::unique_ptr<XRay::Module> prop_helper_module;

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

// !!!!!!! Very ugly fix !!!!!!!
XRay::ScriptExporter::Node* XRay::ScriptExporter::Node::firstNode;
XRay::ScriptExporter::Node* XRay::ScriptExporter::Node::lastNode;
size_t XRay::ScriptExporter::Node::nodeCount;

// typedef void DUMMY_STUFF (const void*,const u32&,void*);
// XRCORE_API DUMMY_STUFF *g_temporary_stuff;

void setup_luabind_allocator();

//#define TRIVIAL_ENCRYPTOR_DECODER

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

setup_luabind_allocator();

CCharacterInfo::InitInternal();
CSpecificCharacter::InitInternal();

Expand All @@ -74,7 +75,7 @@ BOOL APIENTRY DllMain(HANDLE module_handle, DWORD call_reason, LPVOID reserved)
xr_delete(g_ai_space);
xr_delete(g_object_factory);
if (prop_helper_module)
FreeLibrary(prop_helper_module);
prop_helper_module->close();
Core._destroy();
break;
}
Expand Down
Loading

0 comments on commit d58139f

Please sign in to comment.