Skip to content

Commit d7aff22

Browse files
author
nitrocaster
committed
xrScriptEngine: remove GlobalEnv.ScriptEngine dependency.
1 parent 7651718 commit d7aff22

16 files changed

+269
-136
lines changed

src/xrEngine/x_ray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static void InitEngineExt()
190190
Engine.External.Initialize();
191191
// once all libraries got loaded, instantiate and initialize script engine
192192
GlobalEnv.ScriptEngine = xr_new<CScriptEngine>();
193-
GlobalEnv.ScriptEngine->init();
193+
GlobalEnv.ScriptEngine->init(XRay::ScriptExporter::Export);
194194
}
195195

196196
struct path_excluder_predicate

src/xrGame/Level_load.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,14 @@ bool CLevel::Load_GameSpecific_After()
138138

139139
if (!g_dedicated_server) {
140140
// loading scripts
141-
ai().script_engine().remove_script_process(ScriptProcessor::Level);
142-
141+
auto &scriptEngine = ai().script_engine();
142+
scriptEngine.remove_script_process(ScriptProcessor::Level);
143+
shared_str scripts;
143144
if (pLevel->section_exist("level_scripts") && pLevel->line_exist("level_scripts","script"))
144-
ai().script_engine().add_script_process(ScriptProcessor::Level,xr_new<CScriptProcess>("level",pLevel->r_string("level_scripts","script")));
145+
scripts = pLevel->r_string("level_scripts","script");
145146
else
146-
ai().script_engine().add_script_process(ScriptProcessor::Level,xr_new<CScriptProcess>("level",""));
147+
scripts = "";
148+
scriptEngine.add_script_process(ScriptProcessor::Level, scriptEngine.CreateScriptProcess("level", scripts));
147149
}
148150

149151
BlockCheatLoad();

src/xrGame/alife_simulator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void restart_all ()
3636
destroy_lua_wpn_params ();
3737
MainMenu()->DestroyInternal (true);
3838
xr_delete (g_object_factory);
39-
ai().script_engine().init ();
39+
ai().script_engine().init (XRay::ScriptExporter::Export); // XXX: reset node 'done' flags before export
4040

4141
#ifdef DEBUG
4242
ai().moving_objects().clear ();

src/xrGame/game_sv_base.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,22 @@ void game_sv_GameState::Create (shared_str &options)
440440
if (!g_dedicated_server)
441441
{
442442
// loading scripts
443-
ai().script_engine().remove_script_process(ScriptProcessor::Game);
443+
auto &scriptEngine = ai().script_engine();
444+
scriptEngine.remove_script_process(ScriptProcessor::Game);
444445
string_path S;
445446
FS.update_path (S,"$game_config$","script.ltx");
446447
CInifile *l_tpIniFile = xr_new<CInifile>(S);
447448
R_ASSERT (l_tpIniFile);
448449

449-
if( l_tpIniFile->section_exist( type_name() ) )
450-
if (l_tpIniFile->r_string(type_name(),"script"))
451-
ai().script_engine().add_script_process(ScriptProcessor::Game,xr_new<CScriptProcess>("game",l_tpIniFile->r_string(type_name(),"script")));
452-
else
453-
ai().script_engine().add_script_process(ScriptProcessor::Game,xr_new<CScriptProcess>("game",""));
454-
450+
if (l_tpIniFile->section_exist(type_name()))
451+
{
452+
shared_str scripts;
453+
if (l_tpIniFile->r_string(type_name(), "script"))
454+
scripts = l_tpIniFile->r_string(type_name(), "script");
455+
else
456+
scripts = "";
457+
scriptEngine.add_script_process(ScriptProcessor::Game, scriptEngine.CreateScriptProcess("game", scripts));
458+
}
455459
xr_delete (l_tpIniFile);
456460
}
457461

src/xrScriptEngine/script_debugger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ LRESULT CScriptDebugger::DebugMessage(UINT nMsg, WPARAM wParam, LPARAM lParam)
117117

118118
BOOL CScriptDebugger::Active() { return m_bIdePresent; }
119119

120-
CScriptDebugger::CScriptDebugger()
120+
CScriptDebugger::CScriptDebugger(CScriptEngine *scriptEngine)
121121
{
122-
m_threads = xr_new<CDbgScriptThreads>(this);
122+
this->scriptEngine = scriptEngine;
123+
m_threads = xr_new<CDbgScriptThreads>(scriptEngine, this);
123124
m_callStack = xr_new<CScriptCallStack>(this);
124125
m_lua = xr_new<CDbgLuaHelper>(this);
125126
ZeroMemory(m_curr_connected_mslot,sizeof(m_curr_connected_mslot));

src/xrScriptEngine/script_debugger.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class XRSCRIPTENGINE_API CScriptDebugger
5555
void UnPrepareLua(lua_State *l, int idx);
5656
BOOL PrepareLuaBind();
5757

58-
CScriptDebugger();
58+
CScriptDebugger(CScriptEngine *scriptEngine);
5959
virtual ~CScriptDebugger();
6060

6161
void Go();
@@ -85,6 +85,7 @@ class XRSCRIPTENGINE_API CScriptDebugger
8585
bool TranslateIdeMessage(CMailSlotMsg *);
8686
void SendMessageToIde(CMailSlotMsg &);
8787

88+
CScriptEngine *scriptEngine;
8889
CDbgScriptThreads *m_threads;
8990
CDbgLuaHelper *m_lua;
9091
CScriptCallStack *m_callStack;

src/xrScriptEngine/script_debugger_threads.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
u32 CDbgScriptThreads::Fill()
1010
{
1111
u32 res = 0;
12-
if (!GlobalEnv.ScriptEngine)
12+
if (!scriptEngine)
1313
return res;
14-
CScriptProcess* sp = GlobalEnv.ScriptEngine->script_process(ScriptProcessor::Game);
14+
CScriptProcess* sp = scriptEngine->script_process(ScriptProcessor::Game);
1515
if (sp)
1616
res += FillFrom(sp);
17-
sp = GlobalEnv.ScriptEngine->script_process(ScriptProcessor::Level);
17+
sp = scriptEngine->script_process(ScriptProcessor::Level);
1818
if (sp)
1919
res += FillFrom(sp);
2020
return res;

src/xrScriptEngine/script_debugger_threads.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ struct lua_State;
1010
class XRSCRIPTENGINE_API CDbgScriptThreads
1111
{
1212
private:
13+
CScriptEngine *scriptEngine;
1314
xr_vector<SScriptThread> m_threads;
1415
public:
1516
CScriptDebugger *m_debugger;
1617

17-
CDbgScriptThreads(CScriptDebugger *d) { m_debugger = nullptr; }
18+
CDbgScriptThreads(CScriptEngine *scriptEngine, CScriptDebugger *debugger)
19+
{
20+
this->scriptEngine = scriptEngine;
21+
m_debugger = debugger;
22+
}
1823
~CDbgScriptThreads() {};
1924
u32 FillFrom(CScriptProcess *);
2025
u32 Fill();

0 commit comments

Comments
 (0)