-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwiLoadingScreen_BindLua.cpp
More file actions
328 lines (309 loc) · 9.79 KB
/
Copy pathwiLoadingScreen_BindLua.cpp
File metadata and controls
328 lines (309 loc) · 9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#include "wiLoadingScreen_BindLua.h"
#include "wiScene_BindLua.h"
#include "wiTexture_BindLua.h"
#include "wiApplication_BindLua.h"
#include "wiRenderPath3D_BindLua.h"
#include <mutex>
using namespace wi::lua::scene;
using namespace wi::scene;
using namespace wi::ecs;
namespace wi::lua
{
Luna<LoadingScreen_BindLua>::FunctionType LoadingScreen_BindLua::methods[] = {
lunamethod(RenderPath2D_BindLua, AddSprite),
lunamethod(RenderPath2D_BindLua, AddFont),
lunamethod(RenderPath2D_BindLua, RemoveSprite),
lunamethod(RenderPath2D_BindLua, RemoveFont),
lunamethod(RenderPath2D_BindLua, ClearSprites),
lunamethod(RenderPath2D_BindLua, ClearFonts),
lunamethod(RenderPath2D_BindLua, GetSpriteOrder),
lunamethod(RenderPath2D_BindLua, GetFontOrder),
lunamethod(RenderPath2D_BindLua, AddLayer),
lunamethod(RenderPath2D_BindLua, GetLayers),
lunamethod(RenderPath2D_BindLua, SetLayerOrder),
lunamethod(RenderPath2D_BindLua, SetSpriteOrder),
lunamethod(RenderPath2D_BindLua, SetFontOrder),
lunamethod(RenderPath_BindLua, GetLayerMask),
lunamethod(RenderPath_BindLua, SetLayerMask),
lunamethod(LoadingScreen_BindLua, AddLoadModelTask),
lunamethod(LoadingScreen_BindLua, AddRenderPathActivationTask),
lunamethod(LoadingScreen_BindLua, IsFinished),
lunamethod(LoadingScreen_BindLua, GetProgress),
lunamethod(LoadingScreen_BindLua, SetBackgroundTexture),
lunamethod(LoadingScreen_BindLua, GetBackgroundTexture),
lunamethod(LoadingScreen_BindLua, SetBackgroundMode),
lunamethod(LoadingScreen_BindLua, GetBackgroundMode),
{ NULL, NULL }
};
Luna<LoadingScreen_BindLua>::PropertyType LoadingScreen_BindLua::properties[] = {
{ NULL, NULL }
};
int LoadingScreen_BindLua::AddLoadModelTask(lua_State* L)
{
LoadingScreen* loading = static_cast<LoadingScreen*>(component);
if (loading == nullptr)
{
wi::lua::SError(L, "AddLoadModelTask(Scene scene, string fileName, opt Matrix transform): loading screen is invalid!");
return 0;
}
int argc = wi::lua::SGetArgCount(L);
if (argc > 0)
{
Scene_BindLua* custom_scene = Luna<Scene_BindLua>::lightcheck(L, 1);
if (custom_scene)
{
// Overload 1: thread safe version
if (argc > 1)
{
std::string fileName = wi::lua::SGetString(L, 2);
XMMATRIX transform = XMMatrixIdentity();
if (argc > 2)
{
Matrix_BindLua* matrix = Luna<Matrix_BindLua>::lightcheck(L, 3);
if (matrix != nullptr)
{
transform = XMLoadFloat4x4(&matrix->data);
}
else
{
wi::lua::SError(L, "AddLoadModelTask(Scene scene, string fileName, opt Matrix transform) argument is not a matrix!");
}
}
Entity root = CreateEntity();
loading->addLoadingFunction([=](wi::jobsystem::JobArgs args) {
Scene scene;
wi::scene::LoadModel2(scene, fileName, transform, root);
// Note: we lock the scene for merging from multiple loading screen tasks
// Because we don't have fine control over thread execution in lua, and this significantly
// simplifies loading into scene from loadingscreen
std::scoped_lock lck(custom_scene->scene->locker);
custom_scene->scene->Merge(scene);
});
wi::lua::SSetLongLong(L, root);
return 1;
}
else
{
wi::lua::SError(L, "AddLoadModelTask(Scene scene, string fileName, opt Matrix transform) not enough arguments!");
return 0;
}
}
else
{
// Overload 2: global scene version
std::string fileName = wi::lua::SGetString(L, 1);
XMMATRIX transform = XMMatrixIdentity();
if (argc > 1)
{
Matrix_BindLua* matrix = Luna<Matrix_BindLua>::lightcheck(L, 2);
if (matrix != nullptr)
{
transform = XMLoadFloat4x4(&matrix->data);
}
else
{
wi::lua::SError(L, "AddLoadModelTask(string fileName, opt Matrix transform) argument is not a matrix!");
}
}
Entity root = CreateEntity();
loading->addLoadingFunction([=](wi::jobsystem::JobArgs args) {
Scene scene;
wi::scene::LoadModel2(scene, fileName, transform, root);
// Note: we lock the scene for merging from multiple loading screen tasks
// Because we don't have fine control over thread execution in lua, and this significantly
// simplifies loading into scene from loadingscreen
std::scoped_lock lck(GetGlobalScene()->locker);
GetGlobalScene()->Merge(scene);
});
wi::lua::SSetLongLong(L, root);
return 1;
}
}
else
{
wi::lua::SError(L, "AddLoadModelTask(string fileName, opt Matrix transform) not enough arguments!");
}
return 0;
}
int LoadingScreen_BindLua::AddRenderPathActivationTask(lua_State* L)
{
LoadingScreen* loading = static_cast<LoadingScreen*>(component);
if (loading == nullptr)
{
wi::lua::SError(L, "AddRenderPathActivationTask(RenderPath path, opt float fadeSeconds = 0, opt int fadeR = 0,fadeG = 0,fadeB = 0, opt FadeType fadetype = FadeType.FadeToColor): loading screen is invalid!");
return 0;
}
int argc = wi::lua::SGetArgCount(L);
if (argc < 2)
{
wi::lua::SError(L, "AddRenderPathActivationTask(RenderPath path, Application app, opt float fadeSeconds = 0, opt int fadeR = 0,fadeG = 0,fadeB = 0, opt FadeType fadetype = FadeType.FadeToColor): not enough arguments!");
return 0;
}
RenderPath* path = nullptr;
RenderPath3D_BindLua* comp3D = Luna<RenderPath3D_BindLua>::lightcheck(L, 1);
if (comp3D == nullptr)
{
RenderPath2D_BindLua* comp2D = Luna<RenderPath2D_BindLua>::lightcheck(L, 1);
if (comp2D == nullptr)
{
LoadingScreen_BindLua* compLoading = Luna<LoadingScreen_BindLua>::lightcheck(L, 1);
if (compLoading == nullptr)
{
RenderPath_BindLua* comp = Luna<RenderPath_BindLua>::lightcheck(L, 1);
if (comp == nullptr)
{
wi::lua::SError(L, "AddRenderPathActivationTask(RenderPath path, Application app, opt float fadeSeconds = 0, opt int fadeR = 0,fadeG = 0,fadeB = 0, opt FadeType fadetype = FadeType.FadeToColor): first argument is not a RenderPath!");
return 0;
}
else
{
path = comp->component;
}
}
else
{
path = compLoading->component;
}
}
else
{
path = comp2D->component;
}
}
else
{
path = comp3D->component;
}
Application_BindLua* app = Luna<Application_BindLua>::lightcheck(L, 2);
if (app == nullptr)
{
wi::lua::SError(L, "AddRenderPathActivationTask(RenderPath path, Application app, opt float fadeSeconds = 0, opt int fadeR = 0,fadeG = 0,fadeB = 0, opt FadeType fadetype = FadeType.FadeToColor): second argument is not an Application!");
return 0;
}
float fadeSeconds = 0;
wi::Color fadeColor = wi::Color::Black();
wi::FadeManager::FadeType fadetype = wi::FadeManager::FadeType::FadeToColor;
if (argc > 2)
{
fadeSeconds = wi::lua::SGetFloat(L, 3);
if (argc > 3)
{
fadeColor.setR((uint8_t)wi::lua::SGetInt(L, 4));
if (argc > 4)
{
fadeColor.setG((uint8_t)wi::lua::SGetInt(L, 5));
if (argc > 5)
{
fadeColor.setB((uint8_t)wi::lua::SGetInt(L, 6));
if (argc > 6)
{
fadetype = (wi::FadeManager::FadeType)wi::lua::SGetInt(L, 7);
}
}
}
}
}
loading->addLoadingComponent(path, app->component, fadeSeconds, fadeColor, fadetype);
return 0;
}
int LoadingScreen_BindLua::IsFinished(lua_State* L)
{
LoadingScreen* loading = static_cast<LoadingScreen*>(component);
if (loading != nullptr)
{
wi::lua::SSetBool(L, loading->isFinished());
return 1;
}
wi::lua::SError(L, "IsFinished(): loading screen is invalid!");
return 0;
}
int LoadingScreen_BindLua::GetProgress(lua_State* L)
{
LoadingScreen* loading = static_cast<LoadingScreen*>(component);
if (loading != nullptr)
{
wi::lua::SSetInt(L, loading->getProgress());
return 1;
}
wi::lua::SError(L, "GetProgress(): loading screen is invalid!");
return 0;
}
int LoadingScreen_BindLua::SetBackgroundTexture(lua_State* L)
{
LoadingScreen* loading = static_cast<LoadingScreen*>(component);
if (loading == nullptr)
{
wi::lua::SError(L, "SetBackgroundTexture(Texture tex): loading screen is not valid!");
return 0;
}
int argc = wi::lua::SGetArgCount(L);
if (argc < 1)
{
wi::lua::SError(L, "SetBackgroundTexture(Texture tex): not enough arguments!");
return 0;
}
Texture_BindLua* tex = Luna<Texture_BindLua>::lightcheck(L, 1);
if (tex == nullptr)
{
wi::lua::SError(L, "SetBackgroundTexture(Texture tex): argument is not a Texture!");
return 0;
}
loading->backgroundTexture = tex->resource;
return 0;
}
int LoadingScreen_BindLua::GetBackgroundTexture(lua_State* L)
{
LoadingScreen* loading = static_cast<LoadingScreen*>(component);
if (loading == nullptr)
{
wi::lua::SError(L, "GetBackgroundTexture(): loading screen is not valid!");
return 0;
}
Luna<Texture_BindLua>::push(L, loading->backgroundTexture);
return 1;
}
int LoadingScreen_BindLua::SetBackgroundMode(lua_State* L)
{
LoadingScreen* loading = static_cast<LoadingScreen*>(component);
if (loading == nullptr)
{
wi::lua::SError(L, "SetBackgroundMode(int mode): loading screen is not valid!");
return 0;
}
int argc = wi::lua::SGetArgCount(L);
if (argc < 1)
{
wi::lua::SError(L, "SetBackgroundMode(int mode): not enough arguments!");
return 0;
}
loading->background_mode = (LoadingScreen::BackgroundMode)wi::lua::SGetInt(L, 1);
return 0;
}
int LoadingScreen_BindLua::GetBackgroundMode(lua_State* L)
{
LoadingScreen* loading = static_cast<LoadingScreen*>(component);
if (loading == nullptr)
{
wi::lua::SError(L, "GetBackgroundMode(): loading screen is not valid!");
return 0;
}
wi::lua::SSetInt(L, (int)loading->background_mode);
return 1;
}
void LoadingScreen_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<LoadingScreen_BindLua>::Register(wi::lua::GetLuaState());
wi::lua::RunText(R"(
BackgroundMode = {
Fill = 0,
Fit = 1,
Stretch = 2
}
)");
}
}
}