Skip to content

Commit

Permalink
Add different script export container for xrFS_Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
mnelenpridumivat committed Dec 18, 2024
1 parent d6885c9 commit 9967720
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/utils/xrSE_Factory/stdafx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
// Description : Precompiled header creator
////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "stdafx.h"
1 change: 1 addition & 0 deletions src/utils/xrSE_Factory/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "../../xrCore/xrCore.h"
#include "xrServer_ScriptContainer.h"
#include "../../xrScripts/stdafx.h"

#define STRINGIZE(a) #a
Expand Down
8 changes: 8 additions & 0 deletions src/utils/xrSE_Factory/xrServer_ScriptContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "stdafx.h"
#include "xrServer_ScriptContainer.h"

/*xr_hash_map<script_exporter_key_base, script_exporter_data*>& get_script_export_container_xrSE_Factory()
{
static xr_hash_map<script_exporter_key_base, script_exporter_data*> script_exporter_container;
return script_exporter_container;
}*/
7 changes: 7 additions & 0 deletions src/utils/xrSE_Factory/xrServer_ScriptContainer.h
Original file line number Diff line number Diff line change
@@ -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<script_exporter_key_base, script_exporter_data*>& get_script_export_container_xrSE_Factory();*/
1 change: 1 addition & 0 deletions src/xrGame/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/xrGame/xrGame_Script_container.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "stdafx.h"
#include "xrGame_Script_container.h"

/*xr_hash_map<script_exporter_key_base, script_exporter_data*>& get_script_export_container_xrGame()
{
static xr_hash_map<script_exporter_key_base, script_exporter_data*> script_exporter_container;
return script_exporter_container;
}*/
7 changes: 7 additions & 0 deletions src/xrGame/xrGame_Script_container.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

/*#define SCRIPT_EXPORT_CONTAINER get_script_export_container_xrGame()
#include "../xrScripts/script_export_space.h"
xr_hash_map<script_exporter_key_base, script_exporter_data*>& get_script_export_container_xrGame();*/
16 changes: 14 additions & 2 deletions src/xrScripts/script_export_space.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#include "stdafx.h"
#include "script_export_space.h"

SCRIPTS_API xr_hash_map<script_exporter_key_base, script_exporter_data*>& get_script_export_container()
SCRIPTS_API script_export_hashmap& get_script_export_container()
{
static xr_hash_map<script_exporter_key_base, script_exporter_data*> 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;
}
31 changes: 25 additions & 6 deletions src/xrScripts/script_export_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,23 @@ struct script_exporter_data {
script_exporter_base* exporter = nullptr;
};

SCRIPTS_API xr_hash_map<script_exporter_key_base, script_exporter_data*>& get_script_export_container();
using script_export_hashmap = xr_hash_map<script_exporter_key_base, script_exporter_data*>;

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> x##_exporter = script_exporter1<x>::GetInstance(#x);
#define SCRIPT_EXPORT2(x, x1) script_exporter2<x, x1> x##_exporter = script_exporter2<x, x1>::GetInstance(#x, #x1);
Expand All @@ -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<T>::GetKey(vT), data });
auto& Container = SCRIPT_EXPORT_CONTAINER;
auto ElemPos = Container.find(script_exporter_key<T>::GetKey(vT));
VERIFY(ElemPos == Container.end());
SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key<T>::GetKey(vT), data });
}

public:
Expand All @@ -129,7 +148,7 @@ class script_exporter2 : public script_exporter_base {
data->exporter = this;
data->dependencies = {};
data->dependencies.push_back(script_exporter_key<A1>::GetKey(vA1));
get_script_export_container().insert({ script_exporter_key<T>::GetKey(vT), data });
SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key<T>::GetKey(vT), data });
}

public:
Expand All @@ -153,7 +172,7 @@ class script_exporter3 : public script_exporter_base {
data->dependencies = {};
data->dependencies.push_back(script_exporter_key<A1>::GetKey(vA1));
data->dependencies.push_back(script_exporter_key<A2>::GetKey(vA2));
get_script_export_container().insert({ script_exporter_key<T>::GetKey(vT), data });
SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key<T>::GetKey(vT), data });
}

public:
Expand All @@ -178,7 +197,7 @@ class script_exporter4 : public script_exporter_base {
data->dependencies.push_back(script_exporter_key<A1>::GetKey(vA1));
data->dependencies.push_back(script_exporter_key<A2>::GetKey(vA2));
data->dependencies.push_back(script_exporter_key<A3>::GetKey(vA3));
get_script_export_container().insert({ script_exporter_key<T>::GetKey(vT), data });
SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key<T>::GetKey(vT), data });
}

public:
Expand All @@ -204,7 +223,7 @@ class script_exporter5 : public script_exporter_base {
data->dependencies.push_back(script_exporter_key<A2>::GetKey(vA2));
data->dependencies.push_back(script_exporter_key<A3>::GetKey(vA3));
data->dependencies.push_back(script_exporter_key<A4>::GetKey(vA4));
get_script_export_container().insert({ script_exporter_key<T>::GetKey(vT), data });
SCRIPT_EXPORT_CONTAINER.insert({ script_exporter_key<T>::GetKey(vT), data });
}

public:
Expand Down
4 changes: 2 additions & 2 deletions src/xrServerEntities/object_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/xrServerEntities/object_factory_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
4 changes: 2 additions & 2 deletions src/xrServerEntities/object_item_abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
5 changes: 4 additions & 1 deletion src/xrServerEntities/object_item_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/xrServerEntities/object_item_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
4 changes: 2 additions & 2 deletions src/xrServerEntities/object_item_single.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
4 changes: 2 additions & 2 deletions src/xrServerEntities/object_item_single_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions src/xrServerEntities/script_engine_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 9967720

Please sign in to comment.