diff options
Diffstat (limited to 'src/extantz/scenri.c')
-rw-r--r-- | src/extantz/scenri.c | 141 |
1 files changed, 140 insertions, 1 deletions
diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c index e7d30c4..2a02996 100644 --- a/src/extantz/scenri.c +++ b/src/extantz/scenri.c | |||
@@ -28,6 +28,8 @@ | |||
28 | #define THINGASM "thingasm" | 28 | #define THINGASM "thingasm" |
29 | 29 | ||
30 | 30 | ||
31 | static Ecore_Idle_Enterer *idler; | ||
32 | |||
31 | 33 | ||
32 | static void _animateCube(ExtantzStuffs *stuffs) | 34 | static void _animateCube(ExtantzStuffs *stuffs) |
33 | { | 35 | { |
@@ -173,6 +175,101 @@ static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void | |||
173 | 175 | ||
174 | } | 176 | } |
175 | 177 | ||
178 | static int _preallocateStuffs(lua_State *L) | ||
179 | { | ||
180 | ExtantzStuffs *result = NULL; | ||
181 | Scene_Data *scene = NULL; | ||
182 | int count, i; | ||
183 | |||
184 | pull_lua(L, 1, "%", &count); | ||
185 | lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); | ||
186 | scene = (Scene_Data *) lua_touserdata(L, -1); | ||
187 | |||
188 | result = calloc(count, sizeof(ExtantzStuffs)); | ||
189 | |||
190 | for (i = 0; i < count; i++) | ||
191 | { | ||
192 | // TODO - using Eina arrays of any sort seems a bit heavy, might be better to just count and realloc? | ||
193 | result[i].materials = eina_array_new(3); | ||
194 | result[i].mesh = eina_array_new(3); | ||
195 | result[i].textures = eina_array_new(3); | ||
196 | result[i].aMaterial = eina_array_accessor_new(result[i].materials); | ||
197 | result[i].aMesh = eina_array_accessor_new(result[i].mesh); | ||
198 | result[i].aTexture = eina_array_accessor_new(result[i].textures); | ||
199 | result[i].stuffs.details.mesh = calloc(1, sizeof(Mesh)); | ||
200 | result[i].stuffs.details.mesh->materials = eina_inarray_new(sizeof(Material), 1); | ||
201 | result[i].stuffs.details.mesh->parts = eina_inarray_new(sizeof(Mesh), 1); | ||
202 | result[i].scene = scene; | ||
203 | result[i].stage = ES_PRE; | ||
204 | eina_clist_add_head(&(scene->loading), &(result[i].node)); | ||
205 | } | ||
206 | |||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static int _partFillStuffs(lua_State *L) | ||
211 | { | ||
212 | ExtantzStuffs *result = NULL; | ||
213 | Scene_Data *scene = NULL; | ||
214 | char *name, *file; | ||
215 | double px, py, pz, rx, ry, rz, rw; | ||
216 | |||
217 | pull_lua(L, 1, "$ $ # # # # # # #", &name, &file, &px, &py, &pz, &rx, &ry, &rz, &rw); | ||
218 | lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); | ||
219 | scene = (Scene_Data *) lua_touserdata(L, -1); | ||
220 | |||
221 | EINA_CLIST_FOR_EACH_ENTRY(result, &(scene->loading), ExtantzStuffs, node) | ||
222 | { | ||
223 | if (ES_PRE == result->stage) | ||
224 | { | ||
225 | strcpy(result->stuffs.name, name); | ||
226 | |||
227 | strcpy(result->stuffs.file, file); | ||
228 | result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; | ||
229 | result->stuffs.details.mesh->rot.x = rx; result->stuffs.details.mesh->rot.y = ry; result->stuffs.details.mesh->rot.z = rz; result->stuffs.details.mesh->rot.w = rw; | ||
230 | result->stage = ES_PART; | ||
231 | break; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | return 0; | ||
236 | } | ||
237 | |||
238 | static int _finishStuffs(lua_State *L) | ||
239 | { | ||
240 | ExtantzStuffs *result = NULL; | ||
241 | Scene_Data *scene = NULL; | ||
242 | char *uuid, *name, *file, *description, *owner, *mesh; | ||
243 | int type, fake; | ||
244 | |||
245 | pull_lua(L, 1, "$ $ $ $ $ $ % % ", &uuid, &name, &file, &description, &owner, &mesh, &type, &fake); | ||
246 | lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); | ||
247 | scene = (Scene_Data *) lua_touserdata(L, -1); | ||
248 | |||
249 | EINA_CLIST_FOR_EACH_ENTRY(result, &(scene->loading), ExtantzStuffs, node) | ||
250 | { | ||
251 | if (strcmp(file, result->stuffs.name) == 0) | ||
252 | { | ||
253 | strcpy(result->stuffs.UUID, uuid); | ||
254 | strcpy(result->stuffs.name, name); | ||
255 | strcpy(result->stuffs.description, description); | ||
256 | strcpy(result->stuffs.owner, owner); | ||
257 | strcpy(result->stuffs.details.mesh->fileName, mesh); | ||
258 | |||
259 | result->stuffs.details.mesh->type = type; | ||
260 | result->fake = fake; | ||
261 | result->stage = ES_LOADED; | ||
262 | |||
263 | lua_pushlightuserdata(L, (void *) result); | ||
264 | |||
265 | PI("LOADED %s", name); | ||
266 | return 1; | ||
267 | } | ||
268 | } | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
176 | static int _addStuffsL(lua_State *L) | 273 | static int _addStuffsL(lua_State *L) |
177 | { | 274 | { |
178 | ExtantzStuffs *result = NULL; | 275 | ExtantzStuffs *result = NULL; |
@@ -219,6 +316,38 @@ static int _stuffsSetupL(lua_State *L) | |||
219 | return 0; | 316 | return 0; |
220 | } | 317 | } |
221 | 318 | ||
319 | static Eina_Bool _stuffsLoader(void *data) | ||
320 | { | ||
321 | ExtantzStuffs *result = NULL, *e1; | ||
322 | Scene_Data *scene = data; | ||
323 | |||
324 | // TODO - If there's lots of them, only do some. | ||
325 | EINA_CLIST_FOR_EACH_ENTRY_SAFE(result, e1, &(scene->loading), ExtantzStuffs, node) | ||
326 | { | ||
327 | if (ES_PART == result->stage) | ||
328 | { | ||
329 | int scenriLua; | ||
330 | |||
331 | lua_getglobal(scene->L, "package"); | ||
332 | lua_getfield(scene->L, lua_gettop(scene->L), "loaded"); | ||
333 | lua_remove(scene->L, -2); // Removes "package" | ||
334 | lua_getfield(scene->L, lua_gettop(scene->L), "scenriLua"); | ||
335 | lua_remove(scene->L, -2); // Removes "loaded" | ||
336 | scenriLua = lua_gettop(scene->L); | ||
337 | |||
338 | push_lua(scene->L, "@ ( $ $ )", scenriLua, "finishLoadStuffs", scene->sim, result->stuffs.file, 0); | ||
339 | } | ||
340 | if (ES_LOADED == result->stage) | ||
341 | { | ||
342 | eina_clist_remove(&(result->node)); | ||
343 | stuffsSetup(result, result->scene, result->fake); | ||
344 | result->stage = ES_RENDERED; | ||
345 | } | ||
346 | } | ||
347 | |||
348 | return ECORE_CALLBACK_RENEW; | ||
349 | } | ||
350 | |||
222 | Scene_Data *scenriAdd(Evas_Object *win) | 351 | Scene_Data *scenriAdd(Evas_Object *win) |
223 | { | 352 | { |
224 | Scene_Data *scene; | 353 | Scene_Data *scene; |
@@ -230,6 +359,7 @@ Scene_Data *scenriAdd(Evas_Object *win) | |||
230 | scene = calloc(1, sizeof(Scene_Data)); | 359 | scene = calloc(1, sizeof(Scene_Data)); |
231 | scene->evas = evas; | 360 | scene->evas = evas; |
232 | eina_clist_init(&(scene->stuffs)); | 361 | eina_clist_init(&(scene->stuffs)); |
362 | eina_clist_init(&(scene->loading)); | ||
233 | 363 | ||
234 | scene->root_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE)); | 364 | scene->root_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE)); |
235 | 365 | ||
@@ -308,6 +438,12 @@ Scene_Data *scenriAdd(Evas_Object *win) | |||
308 | scenriLua = lua_gettop(scene->L); | 438 | scenriLua = lua_gettop(scene->L); |
309 | 439 | ||
310 | // Define our functions. | 440 | // Define our functions. |
441 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "preallocateStuffs", "preallocate a bunch of stuffs.", _preallocateStuffs, | ||
442 | "number", 0); | ||
443 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "partFillStuffs", "Put some info into a stuffs.", _partFillStuffs, | ||
444 | "string,string,number,number,number,number,number,number,number", 0); | ||
445 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "finishStuffs", "Put rest of info into a stuffs.", _finishStuffs, | ||
446 | "string,string,string,string,string,number,number,number,number,number,number,number,number", 0); | ||
311 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addStuffs", "Add an in world stuffs.", _addStuffsL, | 447 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addStuffs", "Add an in world stuffs.", _addStuffsL, |
312 | "string,string,string,string,string,number,number,number,number,number,number,number,number", 0); | 448 | "string,string,string,string,string,number,number,number,number,number,number,number,number", 0); |
313 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addMaterial", "Add a material to an in world stuffs.", _addMaterialL, | 449 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addMaterial", "Add a material to an in world stuffs.", _addMaterialL, |
@@ -322,6 +458,8 @@ Scene_Data *scenriAdd(Evas_Object *win) | |||
322 | doLuaString(scene->L, buf, "scenriLua"); | 458 | doLuaString(scene->L, buf, "scenriLua"); |
323 | } | 459 | } |
324 | 460 | ||
461 | idler = ecore_idler_add(_stuffsLoader, scene); | ||
462 | |||
325 | return scene; | 463 | return scene; |
326 | } | 464 | } |
327 | 465 | ||
@@ -575,7 +713,6 @@ static void _sphere_init(int precision) | |||
575 | } | 713 | } |
576 | } | 714 | } |
577 | 715 | ||
578 | |||
579 | void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) | 716 | void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) |
580 | { | 717 | { |
581 | char buf[PATH_MAX]; | 718 | char buf[PATH_MAX]; |
@@ -584,6 +721,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) | |||
584 | Evas_3D_Material *mi, *mj; | 721 | Evas_3D_Material *mi, *mj; |
585 | Evas_3D_Mesh *me; | 722 | Evas_3D_Mesh *me; |
586 | 723 | ||
724 | PI("REZZING %s", stuffs->stuffs.name); | ||
587 | // TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format. | 725 | // TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format. |
588 | // So just fake it for now, and expand the data format later. | 726 | // So just fake it for now, and expand the data format later. |
589 | 727 | ||
@@ -774,6 +912,7 @@ ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner, | |||
774 | result->stuffs.details.mesh->type = type; | 912 | result->stuffs.details.mesh->type = type; |
775 | result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; | 913 | result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; |
776 | result->stuffs.details.mesh->rot.x = rx; result->stuffs.details.mesh->rot.y = ry; result->stuffs.details.mesh->rot.z = rz; result->stuffs.details.mesh->rot.w = rw; | 914 | result->stuffs.details.mesh->rot.x = rx; result->stuffs.details.mesh->rot.y = ry; result->stuffs.details.mesh->rot.z = rz; result->stuffs.details.mesh->rot.w = rw; |
915 | result->stage = ES_NORMAL; | ||
777 | 916 | ||
778 | return result; | 917 | return result; |
779 | } | 918 | } |