diff --git a/src/utils/xrSE_Factory/stdafx.cpp b/src/utils/xrSE_Factory/stdafx.cpp index b253b2833b..db79825555 100644 --- a/src/utils/xrSE_Factory/stdafx.cpp +++ b/src/utils/xrSE_Factory/stdafx.cpp @@ -6,4 +6,4 @@ // Description : Precompiled header creator //////////////////////////////////////////////////////////////////////////// -#include "stdafx.h" +#include "stdafx.h" \ No newline at end of file diff --git a/src/utils/xrSE_Factory/stdafx.h b/src/utils/xrSE_Factory/stdafx.h index 02322a195e..4a7a41b56b 100644 --- a/src/utils/xrSE_Factory/stdafx.h +++ b/src/utils/xrSE_Factory/stdafx.h @@ -9,6 +9,7 @@ #pragma once #include "../../xrCore/xrCore.h" +#include "xrServer_ScriptContainer.h" #include "../../xrScripts/stdafx.h" #define STRINGIZE(a) #a diff --git a/src/utils/xrSE_Factory/xrServer_ScriptContainer.cpp b/src/utils/xrSE_Factory/xrServer_ScriptContainer.cpp new file mode 100644 index 0000000000..4e765d8eef --- /dev/null +++ b/src/utils/xrSE_Factory/xrServer_ScriptContainer.cpp @@ -0,0 +1,8 @@ +#include "stdafx.h" +#include "xrServer_ScriptContainer.h" + +/*xr_hash_map& get_script_export_container_xrSE_Factory() +{ + static xr_hash_map script_exporter_container; + return script_exporter_container; +}*/ diff --git a/src/utils/xrSE_Factory/xrServer_ScriptContainer.h b/src/utils/xrSE_Factory/xrServer_ScriptContainer.h new file mode 100644 index 0000000000..0da6b27d60 --- /dev/null +++ b/src/utils/xrSE_Factory/xrServer_ScriptContainer.h @@ -0,0 +1,7 @@ +#pragma once + +/*#define SCRIPT_EXPORT_CONTAINER get_script_export_container_xrSE_Factory() + +#include "../xrScripts/script_export_space.h" + +xr_hash_map& get_script_export_container_xrSE_Factory();*/ \ No newline at end of file diff --git a/src/xrGame/StdAfx.h b/src/xrGame/StdAfx.h index 3ce8bd4555..bd3261ec30 100644 --- a/src/xrGame/StdAfx.h +++ b/src/xrGame/StdAfx.h @@ -18,6 +18,7 @@ #pragma warning(disable:4995) #include "../xrUI/stdafx.h" #include "../xrScripts/stdafx.h" +#include "xrGame_Script_container.h" #pragma warning(default:4995) #include "../xrEngine/GameFont.h" diff --git a/src/xrGame/xrGame_Script_container.cpp b/src/xrGame/xrGame_Script_container.cpp new file mode 100644 index 0000000000..d70b42ad17 --- /dev/null +++ b/src/xrGame/xrGame_Script_container.cpp @@ -0,0 +1,8 @@ +#include "stdafx.h" +#include "xrGame_Script_container.h" + +/*xr_hash_map& get_script_export_container_xrGame() +{ + static xr_hash_map script_exporter_container; + return script_exporter_container; +}*/ diff --git a/src/xrGame/xrGame_Script_container.h b/src/xrGame/xrGame_Script_container.h new file mode 100644 index 0000000000..37a58a1712 --- /dev/null +++ b/src/xrGame/xrGame_Script_container.h @@ -0,0 +1,7 @@ +#pragma once + +/*#define SCRIPT_EXPORT_CONTAINER get_script_export_container_xrGame() + +#include "../xrScripts/script_export_space.h" + +xr_hash_map& get_script_export_container_xrGame();*/ \ No newline at end of file diff --git a/src/xrScripts/script_export_space.cpp b/src/xrScripts/script_export_space.cpp index c1113b4ed6..ff88afa90f 100644 --- a/src/xrScripts/script_export_space.cpp +++ b/src/xrScripts/script_export_space.cpp @@ -1,8 +1,20 @@ #include "stdafx.h" #include "script_export_space.h" -SCRIPTS_API xr_hash_map& get_script_export_container() +SCRIPTS_API script_export_hashmap& get_script_export_container() { - static xr_hash_map script_exporter_container; + static script_export_hashmap script_exporter_container; return script_exporter_container; } + +SCRIPTS_API script_export_hashmap& get_script_export_container_xrSE_Factory() +{ + static script_export_hashmap script_exporter_container; + return script_exporter_container; +} + +SCRIPTS_API script_export_hashmap& get_script_export_container_xrGame() +{ + static script_export_hashmap script_exporter_container; + return script_exporter_container; +} \ No newline at end of file diff --git a/src/xrScripts/script_export_space.h b/src/xrScripts/script_export_space.h index 1320b07fb3..297f76f353 100644 --- a/src/xrScripts/script_export_space.h +++ b/src/xrScripts/script_export_space.h @@ -88,7 +88,23 @@ struct script_exporter_data { script_exporter_base* exporter = nullptr; }; -SCRIPTS_API xr_hash_map& get_script_export_container(); +using script_export_hashmap = xr_hash_map; + +SCRIPTS_API script_export_hashmap& get_script_export_container(); +SCRIPTS_API script_export_hashmap& get_script_export_container_xrSE_Factory(); +SCRIPTS_API script_export_hashmap& get_script_export_container_xrGame(); + +#ifdef XRSE_FACTORY_EXPORTS +#define SCRIPT_EXPORT_CONTAINER get_script_export_container_xrSE_Factory() +#endif + +/*#ifdef XRGAME_EXPORTS +#define SCRIPT_EXPORT_CONTAINER get_script_export_container_xrGame() +#endif*/ + +#ifndef SCRIPT_EXPORT_CONTAINER +#define SCRIPT_EXPORT_CONTAINER get_script_export_container() +#endif #define SCRIPT_EXPORT1(x) script_exporter1 x##_exporter = script_exporter1::GetInstance(#x); #define SCRIPT_EXPORT2(x, x1) script_exporter2 x##_exporter = script_exporter2::GetInstance(#x, #x1); @@ -106,7 +122,10 @@ class script_exporter1 : public script_exporter_base { data->inited = false; data->exporter = this; data->dependencies = {}; - get_script_export_container().insert({ script_exporter_key::GetKey(vT), data }); + auto& Container = SCRIPT_EXPORT_CONTAINER; + auto ElemPos = Container.find(script_exporter_key::GetKey(vT)); + VERIFY(ElemPos == Container.end()); + SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key::GetKey(vT), data }); } public: @@ -129,7 +148,7 @@ class script_exporter2 : public script_exporter_base { data->exporter = this; data->dependencies = {}; data->dependencies.push_back(script_exporter_key::GetKey(vA1)); - get_script_export_container().insert({ script_exporter_key::GetKey(vT), data }); + SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key::GetKey(vT), data }); } public: @@ -153,7 +172,7 @@ class script_exporter3 : public script_exporter_base { data->dependencies = {}; data->dependencies.push_back(script_exporter_key::GetKey(vA1)); data->dependencies.push_back(script_exporter_key::GetKey(vA2)); - get_script_export_container().insert({ script_exporter_key::GetKey(vT), data }); + SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key::GetKey(vT), data }); } public: @@ -178,7 +197,7 @@ class script_exporter4 : public script_exporter_base { data->dependencies.push_back(script_exporter_key::GetKey(vA1)); data->dependencies.push_back(script_exporter_key::GetKey(vA2)); data->dependencies.push_back(script_exporter_key::GetKey(vA3)); - get_script_export_container().insert({ script_exporter_key::GetKey(vT), data }); + SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key::GetKey(vT), data }); } public: @@ -204,7 +223,7 @@ class script_exporter5 : public script_exporter_base { data->dependencies.push_back(script_exporter_key::GetKey(vA2)); data->dependencies.push_back(script_exporter_key::GetKey(vA3)); data->dependencies.push_back(script_exporter_key::GetKey(vA4)); - get_script_export_container().insert({ script_exporter_key::GetKey(vT), data }); + SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key::GetKey(vT), data }); } public: diff --git a/src/xrServerEntities/object_factory.h b/src/xrServerEntities/object_factory.h index dfd5627db5..de0e254333 100644 --- a/src/xrServerEntities/object_factory.h +++ b/src/xrServerEntities/object_factory.h @@ -19,10 +19,10 @@ class CObjectFactory: public IGame_ObjectFactory { public: -#ifndef NO_XR_GAME +//#ifndef NO_XR_GAME using CLIENT_BASE_CLASS = ObjectFactory::CLIENT_BASE_CLASS ; using CLIENT_SCRIPT_BASE_CLASS = ObjectFactory::CLIENT_SCRIPT_BASE_CLASS; -#endif +//#endif using SERVER_BASE_CLASS = ObjectFactory::SERVER_BASE_CLASS ; using SERVER_SCRIPT_BASE_CLASS = ObjectFactory::SERVER_SCRIPT_BASE_CLASS; diff --git a/src/xrServerEntities/object_factory_space.h b/src/xrServerEntities/object_factory_space.h index 5282ca81a8..0ab5fc3b30 100644 --- a/src/xrServerEntities/object_factory_space.h +++ b/src/xrServerEntities/object_factory_space.h @@ -19,14 +19,14 @@ class CSE_Abstract; namespace ObjectFactory { -#ifndef NO_XR_GAME +//#ifndef NO_XR_GAME typedef DLL_Pure CLIENT_BASE_CLASS; -#endif +//#endif typedef CSE_Abstract SERVER_BASE_CLASS; -#ifndef NO_XR_GAME +//#ifndef NO_XR_GAME typedef DLL_Pure CLIENT_SCRIPT_BASE_CLASS; -#endif +//#endif typedef CSE_Abstract SERVER_SCRIPT_BASE_CLASS; }; diff --git a/src/xrServerEntities/object_item_abstract.h b/src/xrServerEntities/object_item_abstract.h index f6fbc5bf65..3bca9398a3 100644 --- a/src/xrServerEntities/object_item_abstract.h +++ b/src/xrServerEntities/object_item_abstract.h @@ -22,9 +22,9 @@ class CObjectItemAbstract { IC CObjectItemAbstract (const CLASS_ID &clsid, LPCSTR script_clsid); IC const CLASS_ID &clsid () const; IC shared_str script_clsid () const; -#ifndef NO_XR_GAME +//#ifndef NO_XR_GAME virtual ObjectFactory::CLIENT_BASE_CLASS *client_object () const = 0; -#endif +//#endif virtual ObjectFactory::SERVER_BASE_CLASS *server_object (LPCSTR section) const = 0; }; diff --git a/src/xrServerEntities/object_item_script.cpp b/src/xrServerEntities/object_item_script.cpp index 9d522a2f77..ef0ac38307 100644 --- a/src/xrServerEntities/object_item_script.cpp +++ b/src/xrServerEntities/object_item_script.cpp @@ -26,7 +26,10 @@ ObjectFactory::CLIENT_BASE_CLASS *CObjectItemScript::client_object () const R_ASSERT (object); return (object->_construct()); } - +#else +ObjectFactory::CLIENT_BASE_CLASS* CObjectItemScript::client_object() const { + return nullptr; +} #endif ObjectFactory::SERVER_BASE_CLASS *CObjectItemScript::server_object (LPCSTR section) const diff --git a/src/xrServerEntities/object_item_script.h b/src/xrServerEntities/object_item_script.h index 4061bb1c98..dbf696345e 100644 --- a/src/xrServerEntities/object_item_script.h +++ b/src/xrServerEntities/object_item_script.h @@ -35,6 +35,8 @@ class CObjectItemScript : public CObjectItemAbstract { LPCSTR script_clsid ); virtual ObjectFactory::CLIENT_BASE_CLASS *client_object () const; +#else + virtual ObjectFactory::CLIENT_BASE_CLASS* client_object() const; #endif virtual ObjectFactory::SERVER_BASE_CLASS *server_object (LPCSTR section) const; }; diff --git a/src/xrServerEntities/object_item_single.h b/src/xrServerEntities/object_item_single.h index 73beea6ca6..716951bd2e 100644 --- a/src/xrServerEntities/object_item_single.h +++ b/src/xrServerEntities/object_item_single.h @@ -22,9 +22,9 @@ class CObjectItemSingle : public CObjectItemAbstract { public: IC CObjectItemSingle (const CLASS_ID &clsid, LPCSTR script_clsid); -#ifndef NO_XR_GAME +//#ifndef NO_XR_GAME virtual ObjectFactory::CLIENT_BASE_CLASS *client_object () const; -#endif +//#endif virtual ObjectFactory::SERVER_BASE_CLASS *server_object (LPCSTR section) const; }; diff --git a/src/xrServerEntities/object_item_single_inline.h b/src/xrServerEntities/object_item_single_inline.h index fa0adffbc6..a19c65d3e5 100644 --- a/src/xrServerEntities/object_item_single_inline.h +++ b/src/xrServerEntities/object_item_single_inline.h @@ -20,14 +20,14 @@ IC CSObjectItemSingle::CObjectItemSingle (const CLASS_ID &clsid, LPCSTR script_c { } -#ifndef NO_XR_GAME +//#ifndef NO_XR_GAME TEMPLATE_SPECIALIZATION ObjectFactory::CLIENT_BASE_CLASS *CSObjectItemSingle::client_object () const { FATAL ("Cannot instantiate client object, because client class is not declared!"); return (0); } -#endif +//#endif TEMPLATE_SPECIALIZATION ObjectFactory::SERVER_BASE_CLASS *CSObjectItemSingle::server_object (LPCSTR section) const diff --git a/src/xrServerEntities/script_engine_export.cpp b/src/xrServerEntities/script_engine_export.cpp index 1760ed03dd..c10fe6b442 100644 --- a/src/xrServerEntities/script_engine_export.cpp +++ b/src/xrServerEntities/script_engine_export.cpp @@ -28,18 +28,25 @@ # include "ui/UIActorMenu.h" #endif -void register_script_class_rec(script_exporter_key_base class_key, lua_State* L) { - auto& container = get_script_export_container(); +void register_script_class_rec(const script_export_hashmap& container, script_exporter_key_base class_key, lua_State* L) { + //auto& container = get_script_export_container(); auto data = container.find(class_key); VERIFY(data != container.end()); if (data->second->inited) { return; } for (auto& elem : data->second->dependencies) { - register_script_class_rec(elem, L); + register_script_class_rec(container, elem, L); } data->second->exporter->script_register(L); data->second->inited = true; +#ifdef XRSE_FACTORY_EXPORTS + auto nonse_container = get_script_export_container(); + auto nonse_data = nonse_container.find(class_key); + if (nonse_data != nonse_container.end() && nonse_data != data) { + nonse_data->second->inited = true; + } +#endif } void export_classes (lua_State *L) @@ -48,8 +55,17 @@ void export_classes (lua_State *L) for (auto& elem : container) { elem.second->inited = false; } +#ifdef XRSE_FACTORY_EXPORTS + auto se_container = get_script_export_container_xrSE_Factory(); + for (auto& elem : se_container) { + elem.second->inited = false; + } + for (auto& elem : se_container) { + register_script_class_rec(se_container, elem.first, L); + } +#endif for (auto& elem : container) { - register_script_class_rec(elem.first, L); + register_script_class_rec(container, elem.first, L); } //CScriptEngine::script_register(L);