Skip to content

Commit 4898eba

Browse files
author
nitrocaster
committed
Render and game use separate script engines.
1 parent d7aff22 commit 4898eba

File tree

15 files changed

+243
-244
lines changed

15 files changed

+243
-244
lines changed

src/Layers/xrRender/ResourceManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shader.h"
1010
#include "tss_def.h"
1111
#include "TextureDescrManager.h"
12+
#include "xrScriptEngine/script_engine.hpp"
1213
// refs
1314
struct lua_State;
1415

@@ -87,8 +88,10 @@ class ECORE_API CResourceManager
8788
//. CInifile* m_textures_description;
8889
xr_vector<std::pair<shared_str,R_constant_setup*> > v_constant_setup;
8990
BOOL bDeferredLoad;
91+
CScriptEngine ScriptEngine;
9092
private:
9193
void LS_Load ();
94+
void LS_Unload();
9295
public:
9396
// Miscelaneous
9497
void _ParseList (sh_list& dest, LPCSTR names);

src/Layers/xrRender/ResourceManager_Loader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ void CResourceManager::OnDeviceDestroy(BOOL )
4141
xr_delete (_t->second.cs);
4242
}
4343
m_td.clear ();
44+
#ifndef _EDITOR
45+
LS_Unload();
46+
#endif
4447
}
4548

4649
void CResourceManager::OnDeviceCreate (IReader* F)

src/Layers/xrRender/ResourceManager_Scripting.cpp

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -79,89 +79,95 @@ class adopt_blend
7979
// export
8080
void CResourceManager::LS_Load ()
8181
{
82-
module(GlobalEnv.ScriptEngine->lua())
83-
[
84-
class_<adopt_sampler>("_sampler")
85-
.def( constructor<const adopt_sampler&>())
86-
.def("texture", &adopt_sampler::_texture ,return_reference_to(_1))
87-
.def("project", &adopt_sampler::_projective ,return_reference_to(_1))
88-
.def("clamp", &adopt_sampler::_clamp ,return_reference_to(_1))
89-
.def("wrap", &adopt_sampler::_wrap ,return_reference_to(_1))
90-
.def("mirror", &adopt_sampler::_mirror ,return_reference_to(_1))
91-
.def("f_anisotropic", &adopt_sampler::_f_anisotropic ,return_reference_to(_1))
92-
.def("f_trilinear", &adopt_sampler::_f_trilinear ,return_reference_to(_1))
93-
.def("f_bilinear", &adopt_sampler::_f_bilinear ,return_reference_to(_1))
94-
.def("f_linear", &adopt_sampler::_f_linear ,return_reference_to(_1))
95-
.def("f_none", &adopt_sampler::_f_none ,return_reference_to(_1))
96-
.def("fmin_none", &adopt_sampler::_fmin_none ,return_reference_to(_1))
97-
.def("fmin_point", &adopt_sampler::_fmin_point ,return_reference_to(_1))
98-
.def("fmin_linear", &adopt_sampler::_fmin_linear ,return_reference_to(_1))
99-
.def("fmin_aniso", &adopt_sampler::_fmin_aniso ,return_reference_to(_1))
100-
.def("fmip_none", &adopt_sampler::_fmip_none ,return_reference_to(_1))
101-
.def("fmip_point", &adopt_sampler::_fmip_point ,return_reference_to(_1))
102-
.def("fmip_linear", &adopt_sampler::_fmip_linear ,return_reference_to(_1))
103-
.def("fmag_none", &adopt_sampler::_fmag_none ,return_reference_to(_1))
104-
.def("fmag_point", &adopt_sampler::_fmag_point ,return_reference_to(_1))
105-
.def("fmag_linear", &adopt_sampler::_fmag_linear ,return_reference_to(_1)),
82+
auto exporterFunc = [](lua_State *luaState)
83+
{
84+
module(luaState)
85+
[
86+
class_<adopt_sampler>("_sampler")
87+
.def( constructor<const adopt_sampler&>())
88+
.def("texture", &adopt_sampler::_texture ,return_reference_to(_1))
89+
.def("project", &adopt_sampler::_projective ,return_reference_to(_1))
90+
.def("clamp", &adopt_sampler::_clamp ,return_reference_to(_1))
91+
.def("wrap", &adopt_sampler::_wrap ,return_reference_to(_1))
92+
.def("mirror", &adopt_sampler::_mirror ,return_reference_to(_1))
93+
.def("f_anisotropic", &adopt_sampler::_f_anisotropic ,return_reference_to(_1))
94+
.def("f_trilinear", &adopt_sampler::_f_trilinear ,return_reference_to(_1))
95+
.def("f_bilinear", &adopt_sampler::_f_bilinear ,return_reference_to(_1))
96+
.def("f_linear", &adopt_sampler::_f_linear ,return_reference_to(_1))
97+
.def("f_none", &adopt_sampler::_f_none ,return_reference_to(_1))
98+
.def("fmin_none", &adopt_sampler::_fmin_none ,return_reference_to(_1))
99+
.def("fmin_point", &adopt_sampler::_fmin_point ,return_reference_to(_1))
100+
.def("fmin_linear", &adopt_sampler::_fmin_linear ,return_reference_to(_1))
101+
.def("fmin_aniso", &adopt_sampler::_fmin_aniso ,return_reference_to(_1))
102+
.def("fmip_none", &adopt_sampler::_fmip_none ,return_reference_to(_1))
103+
.def("fmip_point", &adopt_sampler::_fmip_point ,return_reference_to(_1))
104+
.def("fmip_linear", &adopt_sampler::_fmip_linear ,return_reference_to(_1))
105+
.def("fmag_none", &adopt_sampler::_fmag_none ,return_reference_to(_1))
106+
.def("fmag_point", &adopt_sampler::_fmag_point ,return_reference_to(_1))
107+
.def("fmag_linear", &adopt_sampler::_fmag_linear ,return_reference_to(_1)),
106108

107-
class_<adopt_compiler>("_compiler")
108-
.def( constructor<const adopt_compiler&>())
109-
.def("begin", &adopt_compiler::_pass ,return_reference_to(_1))
110-
.def("sorting", &adopt_compiler::_options ,return_reference_to(_1))
111-
.def("emissive", &adopt_compiler::_o_emissive ,return_reference_to(_1))
112-
.def("distort", &adopt_compiler::_o_distort ,return_reference_to(_1))
113-
.def("wmark", &adopt_compiler::_o_wmark ,return_reference_to(_1))
114-
.def("fog", &adopt_compiler::_fog ,return_reference_to(_1))
115-
.def("zb", &adopt_compiler::_ZB ,return_reference_to(_1))
116-
.def("blend", &adopt_compiler::_blend ,return_reference_to(_1))
117-
.def("aref", &adopt_compiler::_aref ,return_reference_to(_1))
118-
.def("color_write_enable", &adopt_compiler::_color_write_enable,return_reference_to(_1))
119-
.def("sampler", &adopt_compiler::_sampler ), // returns sampler-object
120-
121-
class_<adopt_blend>("blend")
122-
.enum_("blend")
123-
[
124-
value("zero", int(D3DBLEND_ZERO)),
125-
value("one", int(D3DBLEND_ONE)),
126-
value("srccolor", int(D3DBLEND_SRCCOLOR)),
127-
value("invsrccolor", int(D3DBLEND_INVSRCCOLOR)),
128-
value("srcalpha", int(D3DBLEND_SRCALPHA)),
129-
value("invsrcalpha", int(D3DBLEND_INVSRCALPHA)),
130-
value("destalpha", int(D3DBLEND_DESTALPHA)),
131-
value("invdestalpha", int(D3DBLEND_INVDESTALPHA)),
132-
value("destcolor", int(D3DBLEND_DESTCOLOR)),
133-
value("invdestcolor", int(D3DBLEND_INVDESTCOLOR)),
134-
value("srcalphasat", int(D3DBLEND_SRCALPHASAT))
135-
]
136-
];
109+
class_<adopt_compiler>("_compiler")
110+
.def( constructor<const adopt_compiler&>())
111+
.def("begin", &adopt_compiler::_pass ,return_reference_to(_1))
112+
.def("sorting", &adopt_compiler::_options ,return_reference_to(_1))
113+
.def("emissive", &adopt_compiler::_o_emissive ,return_reference_to(_1))
114+
.def("distort", &adopt_compiler::_o_distort ,return_reference_to(_1))
115+
.def("wmark", &adopt_compiler::_o_wmark ,return_reference_to(_1))
116+
.def("fog", &adopt_compiler::_fog ,return_reference_to(_1))
117+
.def("zb", &adopt_compiler::_ZB ,return_reference_to(_1))
118+
.def("blend", &adopt_compiler::_blend ,return_reference_to(_1))
119+
.def("aref", &adopt_compiler::_aref ,return_reference_to(_1))
120+
.def("color_write_enable", &adopt_compiler::_color_write_enable,return_reference_to(_1))
121+
.def("sampler", &adopt_compiler::_sampler ), // returns sampler-object
137122

123+
class_<adopt_blend>("blend")
124+
.enum_("blend")
125+
[
126+
value("zero", int(D3DBLEND_ZERO)),
127+
value("one", int(D3DBLEND_ONE)),
128+
value("srccolor", int(D3DBLEND_SRCCOLOR)),
129+
value("invsrccolor", int(D3DBLEND_INVSRCCOLOR)),
130+
value("srcalpha", int(D3DBLEND_SRCALPHA)),
131+
value("invsrcalpha", int(D3DBLEND_INVSRCALPHA)),
132+
value("destalpha", int(D3DBLEND_DESTALPHA)),
133+
value("invdestalpha", int(D3DBLEND_INVDESTALPHA)),
134+
value("destcolor", int(D3DBLEND_DESTCOLOR)),
135+
value("invdestcolor", int(D3DBLEND_INVDESTCOLOR)),
136+
value("srcalphasat", int(D3DBLEND_SRCALPHASAT))
137+
]
138+
];
139+
};
140+
ScriptEngine.init(exporterFunc, false);
138141
// load shaders
139-
xr_vector<char*>* folder = FS.file_list_open ("$game_shaders$",GlobalEnv.Render->getShaderPath(),FS_ListFiles|FS_RootOnly);
142+
const char *shaderPath = RImplementation.getShaderPath();
143+
xr_vector<char*>* folder = FS.file_list_open ("$game_shaders$", shaderPath, FS_ListFiles|FS_RootOnly);
140144
VERIFY (folder);
141145
for (u32 it=0; it<folder->size(); it++) {
142146
string_path namesp,fn;
143147
xr_strcpy (namesp,(*folder)[it]);
144148
if (0==strext(namesp) || 0!=xr_strcmp(strext(namesp),".s")) continue;
145149
*strext (namesp)=0;
146-
if (0==namesp[0]) xr_strcpy (namesp, GlobalEnv.ScriptEngine->GlobalNamespace);
147-
strconcat (sizeof(fn),fn,GlobalEnv.Render->getShaderPath(),(*folder)[it]);
150+
if (0==namesp[0]) xr_strcpy (namesp, ScriptEngine.GlobalNamespace);
151+
strconcat (sizeof(fn), fn, shaderPath, (*folder)[it]);
148152
FS.update_path (fn,"$game_shaders$",fn);
149-
GlobalEnv.ScriptEngine->load_file_into_namespace(fn, namesp);
153+
ScriptEngine.load_file_into_namespace(fn, namesp);
150154
}
151155
FS.file_list_close (folder);
152156
}
153157

158+
void CResourceManager::LS_Unload() { ScriptEngine.unload(); }
159+
154160
BOOL CResourceManager::_lua_HasShader (LPCSTR s_shader)
155161
{
156162
string256 undercorated;
157163
for (int i=0, l=xr_strlen(s_shader)+1; i<l; i++)
158164
undercorated[i]=('\\'==s_shader[i])?'_':s_shader[i];
159165

160166
#ifdef _EDITOR
161-
return GlobalEnv.ScriptEngine->object(undercorated,"editor",LUA_TFUNCTION);
167+
return ScriptEngine.object(undercorated,"editor",LUA_TFUNCTION);
162168
#else
163-
return GlobalEnv.ScriptEngine->object(undercorated,"normal",LUA_TFUNCTION) ||
164-
GlobalEnv.ScriptEngine->object(undercorated,"l_special",LUA_TFUNCTION);
169+
return ScriptEngine.object(undercorated,"normal",LUA_TFUNCTION) ||
170+
ScriptEngine.object(undercorated,"l_special",LUA_TFUNCTION);
165171
#endif
166172
}
167173

@@ -187,7 +193,7 @@ Shader* CResourceManager::_lua_Create (LPCSTR d_shader, LPCSTR s_textures)
187193
C.detail_scaler = NULL;
188194

189195
// Compile element (LOD0 - HQ)
190-
if (GlobalEnv.ScriptEngine->object(s_shader,"normal_hq",LUA_TFUNCTION))
196+
if (ScriptEngine.object(s_shader,"normal_hq",LUA_TFUNCTION))
191197
{
192198
// Analyze possibility to detail this shader
193199
C.iElement = 0;
@@ -196,7 +202,7 @@ Shader* CResourceManager::_lua_Create (LPCSTR d_shader, LPCSTR s_textures)
196202
if (C.bDetail) S.E[0] = C._lua_Compile(s_shader,"normal_hq");
197203
else S.E[0] = C._lua_Compile(s_shader,"normal");
198204
} else {
199-
if (GlobalEnv.ScriptEngine->object(s_shader,"normal",LUA_TFUNCTION))
205+
if (ScriptEngine.object(s_shader,"normal",LUA_TFUNCTION))
200206
{
201207
C.iElement = 0;
202208
C.bDetail = RImplementation.Resources->m_textures_description.GetDetailTexture(C.L_textures[0],C.detail_texture,C.detail_scaler);
@@ -205,31 +211,31 @@ Shader* CResourceManager::_lua_Create (LPCSTR d_shader, LPCSTR s_textures)
205211
}
206212

207213
// Compile element (LOD1)
208-
if (GlobalEnv.ScriptEngine->object(s_shader,"normal",LUA_TFUNCTION))
214+
if (ScriptEngine.object(s_shader,"normal",LUA_TFUNCTION))
209215
{
210216
C.iElement = 1;
211217
C.bDetail = RImplementation.Resources->m_textures_description.GetDetailTexture(C.L_textures[0],C.detail_texture,C.detail_scaler);
212218
S.E[1] = C._lua_Compile(s_shader,"normal");
213219
}
214220

215221
// Compile element
216-
if (GlobalEnv.ScriptEngine->object(s_shader,"l_point",LUA_TFUNCTION))
222+
if (ScriptEngine.object(s_shader,"l_point",LUA_TFUNCTION))
217223
{
218224
C.iElement = 2;
219225
C.bDetail = FALSE;
220226
S.E[2] = C._lua_Compile(s_shader,"l_point");;
221227
}
222228

223229
// Compile element
224-
if (GlobalEnv.ScriptEngine->object(s_shader,"l_spot",LUA_TFUNCTION))
230+
if (ScriptEngine.object(s_shader,"l_spot",LUA_TFUNCTION))
225231
{
226232
C.iElement = 3;
227233
C.bDetail = FALSE;
228234
S.E[3] = C._lua_Compile(s_shader,"l_spot");;
229235
}
230236

231237
// Compile element
232-
if (GlobalEnv.ScriptEngine->object(s_shader,"l_special",LUA_TFUNCTION))
238+
if (ScriptEngine.object(s_shader,"l_special",LUA_TFUNCTION))
233239
{
234240
C.iElement = 4;
235241
C.bDetail = FALSE;
@@ -257,7 +263,7 @@ ShaderElement* CBlender_Compile::_lua_Compile (LPCSTR namesp, LPCSTR name)
257263
LPCSTR t_0 = *L_textures[0] ? *L_textures[0] : "null";
258264
LPCSTR t_1 = (L_textures.size() > 1) ? *L_textures[1] : "null";
259265
LPCSTR t_d = detail_texture ? detail_texture : "null" ;
260-
object shader = GlobalEnv.ScriptEngine->name_space(namesp);
266+
object shader = RImplementation.Resources->ScriptEngine.name_space(namesp);
261267
functor<void> element = object_cast<functor<void> >(shader[name]);
262268
adopt_compiler ac = adopt_compiler(this);
263269
element (ac,t_0,t_1,t_d);

0 commit comments

Comments
 (0)