From 923cdbef0a76190006a1a175b97836d0c3444214 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 2 Jun 2014 00:18:32 +1000 Subject: Load and rez stuffs in an idler, also fix some bugs in that part. --- src/extantz/Evas_3D_demo.c | 96 ------------------------------ src/extantz/extantz.c | 5 +- src/extantz/extantz.h | 35 +++++------ src/extantz/scenri.c | 141 ++++++++++++++++++++++++++++++++++++++++++++- src/libraries/love.h | 2 +- 5 files changed, 159 insertions(+), 120 deletions(-) delete mode 100644 src/extantz/Evas_3D_demo.c (limited to 'src') diff --git a/src/extantz/Evas_3D_demo.c b/src/extantz/Evas_3D_demo.c deleted file mode 100644 index e9265da..0000000 --- a/src/extantz/Evas_3D_demo.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "extantz.h" - - -static void _animateCube(ExtantzStuffs *stuffs) -{ - static float angle = 0.0f; - static int frame = 0; - static int inc = 1; - Evas_3D_Mesh *m; - - eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m); - - angle += 0.5; - if (angle > 360.0) angle -= 360.0f; - - frame += inc; - if (frame >= 20) inc = -1; - else if (frame <= 0) inc = 1; - - eo_do(stuffs->mesh_node, - evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0), - evas_3d_node_mesh_frame_set(m, frame) - ); -} - -static void _animateSphere(ExtantzStuffs *stuffs) -{ - static float earthAngle = 0.0f; - - earthAngle += 0.3; - if (earthAngle > 360.0) earthAngle -= 360.0f; - eo_do(stuffs->mesh_node, - evas_3d_node_orientation_angle_axis_set(earthAngle, 0.0, 1.0, 0.0) - ); -} - -static void _animateSonic(ExtantzStuffs *stuffs) -{ - static int sonicFrame = 0; - Evas_3D_Mesh *m; - - eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m); - sonicFrame += 32; - if (sonicFrame > 256 * 50) sonicFrame = 0; - eo_do(stuffs->mesh_node, - evas_3d_node_mesh_frame_set(m, sonicFrame) - ); -} - -void Evas_3D_Demo_add(globals *ourGlobals) -{ - char buf[PATH_MAX]; - ExtantzStuffs *eStuffs; - - ourGlobals->scene = scenriAdd(ourGlobals->win); - - // TODO - For now lets just pretend we got stuffs sent from our love. - sprintf(buf, FAKE_UUID); - eStuffs = addStuffs(buf, "onefang's test bed", - "Just a pretend bed with MLP scripts for testing SledjHamr.", - "12345678-1234-4321-abcd-0123456789ab", - "onefang%%27s%%20test%%20bed.omg", - MT_CUBE, - 0.0, 4.0, 10.0, - 1.0, 0.0, 0.0, 0.0 - ); - addMaterial(eStuffs, -1, TT_NORMAL, "normal_lego.png"); - eStuffs->animateStuffs = (aniStuffs) _animateCube; - stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 1); - - sprintf(buf, FAKE_UUID); - eStuffs = addStuffs(buf, "onefang's left testicle", - "Just a pretend world for testing SledjHamr.", - "12345678-1234-4321-abcd-0123456789ab", - "earth.omg", - MT_SPHERE, - 0.0, 0.0, 0.0, - 1.0, 0.0, 0.0, 0.0 - ); - addMaterial(eStuffs, 1, TT_FACE, "EarthDiffuse.png"); - eStuffs->animateStuffs = (aniStuffs) _animateSphere; - stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 2); - - sprintf(buf, FAKE_UUID); - eStuffs = addStuffs(buf, "Sonic the bed hog.", - "Just a pretend avatar for testing SledjHamr.", - "12345678-1234-4321-abcd-0123456789ab", - "sonic.md2", - MT_MESH, - 0.0, 0.0, 0.0, - -0.7071067811865475, 0.0, 0.0, 0.7071067811865475 - ); - addMaterial(eStuffs, -1, TT_FACE, "sonic.png"); - eStuffs->animateStuffs = (aniStuffs) _animateSonic; - stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 3); -} diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index e102165..7c90b8a 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -108,6 +108,7 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev) // TODO - For now, assume it's a file:// URL. t += 7; //strcat(t, "/index.omg"); + strcpy(ourGlobals->scene->sim, t); PI("Loading local sim from %s", t); // TODO - Later do the same with eet files in C code, but keep both implementations. @@ -118,8 +119,8 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev) lua_remove(ourGlobals->scene->L, -2); // Removes "loaded" scenriLua = lua_gettop(ourGlobals->scene->L); - push_lua(ourGlobals->scene->L, "@ ( $ $ )", scenriLua, "loadSim", t); -// Evas_3D_Demo_add(ourGlobals, t); + push_lua(ourGlobals->scene->L, "@ ( $ )", scenriLua, "loadSim", t, 0); + PI("Loaded local sim from %s", t); } else { diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index 1526626..5882e10 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h @@ -141,26 +141,9 @@ typedef struct _Scene_Data Evas_3D_Light *light; - Eina_Clist stuffs; -/* - Evas_3D_Mesh *mesh; - Evas_3D_Node *mesh_node; - Evas_3D_Material *material0; - Evas_3D_Material *material1; - Evas_3D_Texture *texture0; - Evas_3D_Texture *texture1; - Evas_3D_Texture *texture_normal; - - Evas_3D_Mesh *mesh2; - Evas_3D_Node *mesh2_node; - Evas_3D_Material *material2; - Evas_3D_Texture *texture2; - - Evas_3D_Mesh *mesh3; - Evas_3D_Node *mesh3_node; - Evas_3D_Material *material3; - Evas_3D_Texture *texture_diffuse; -*/ + char sim[PATH_MAX]; + Eina_Clist stuffs, loading; + cameraMove *move; Evas_Object_Event_Cb clickCb; @@ -169,6 +152,16 @@ typedef struct _Scene_Data typedef void (* aniStuffs)(void *stuffs); +typedef enum +{ + ES_NORMAL = -1, + ES_PRE = 1, + ES_PART, + ES_LOADED, + ES_RENDERED, + ES_TRASHED +} ES_Stages; + typedef struct _extantzStuffs { Stuffs stuffs; @@ -183,6 +176,8 @@ typedef struct _extantzStuffs Eina_Accessor *aTexture; aniStuffs animateStuffs; Eina_Clist node; + ES_Stages stage; + int fake; } ExtantzStuffs; 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 @@ #define THINGASM "thingasm" +static Ecore_Idle_Enterer *idler; + static void _animateCube(ExtantzStuffs *stuffs) { @@ -173,6 +175,101 @@ static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void } +static int _preallocateStuffs(lua_State *L) +{ + ExtantzStuffs *result = NULL; + Scene_Data *scene = NULL; + int count, i; + + pull_lua(L, 1, "%", &count); + lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); + scene = (Scene_Data *) lua_touserdata(L, -1); + + result = calloc(count, sizeof(ExtantzStuffs)); + + for (i = 0; i < count; i++) + { + // TODO - using Eina arrays of any sort seems a bit heavy, might be better to just count and realloc? + result[i].materials = eina_array_new(3); + result[i].mesh = eina_array_new(3); + result[i].textures = eina_array_new(3); + result[i].aMaterial = eina_array_accessor_new(result[i].materials); + result[i].aMesh = eina_array_accessor_new(result[i].mesh); + result[i].aTexture = eina_array_accessor_new(result[i].textures); + result[i].stuffs.details.mesh = calloc(1, sizeof(Mesh)); + result[i].stuffs.details.mesh->materials = eina_inarray_new(sizeof(Material), 1); + result[i].stuffs.details.mesh->parts = eina_inarray_new(sizeof(Mesh), 1); + result[i].scene = scene; + result[i].stage = ES_PRE; + eina_clist_add_head(&(scene->loading), &(result[i].node)); + } + + return 0; +} + +static int _partFillStuffs(lua_State *L) +{ + ExtantzStuffs *result = NULL; + Scene_Data *scene = NULL; + char *name, *file; + double px, py, pz, rx, ry, rz, rw; + + pull_lua(L, 1, "$ $ # # # # # # #", &name, &file, &px, &py, &pz, &rx, &ry, &rz, &rw); + lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); + scene = (Scene_Data *) lua_touserdata(L, -1); + + EINA_CLIST_FOR_EACH_ENTRY(result, &(scene->loading), ExtantzStuffs, node) + { + if (ES_PRE == result->stage) + { + strcpy(result->stuffs.name, name); + + strcpy(result->stuffs.file, file); + result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; + 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; + result->stage = ES_PART; + break; + } + } + + return 0; +} + +static int _finishStuffs(lua_State *L) +{ + ExtantzStuffs *result = NULL; + Scene_Data *scene = NULL; + char *uuid, *name, *file, *description, *owner, *mesh; + int type, fake; + + pull_lua(L, 1, "$ $ $ $ $ $ % % ", &uuid, &name, &file, &description, &owner, &mesh, &type, &fake); + lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); + scene = (Scene_Data *) lua_touserdata(L, -1); + + EINA_CLIST_FOR_EACH_ENTRY(result, &(scene->loading), ExtantzStuffs, node) + { + if (strcmp(file, result->stuffs.name) == 0) + { + strcpy(result->stuffs.UUID, uuid); + strcpy(result->stuffs.name, name); + strcpy(result->stuffs.description, description); + strcpy(result->stuffs.owner, owner); + strcpy(result->stuffs.details.mesh->fileName, mesh); + + result->stuffs.details.mesh->type = type; + result->fake = fake; + result->stage = ES_LOADED; + + lua_pushlightuserdata(L, (void *) result); + + PI("LOADED %s", name); + return 1; + } + } + + return 0; +} + static int _addStuffsL(lua_State *L) { ExtantzStuffs *result = NULL; @@ -219,6 +316,38 @@ static int _stuffsSetupL(lua_State *L) return 0; } +static Eina_Bool _stuffsLoader(void *data) +{ + ExtantzStuffs *result = NULL, *e1; + Scene_Data *scene = data; + + // TODO - If there's lots of them, only do some. + EINA_CLIST_FOR_EACH_ENTRY_SAFE(result, e1, &(scene->loading), ExtantzStuffs, node) + { + if (ES_PART == result->stage) + { + int scenriLua; + + lua_getglobal(scene->L, "package"); + lua_getfield(scene->L, lua_gettop(scene->L), "loaded"); + lua_remove(scene->L, -2); // Removes "package" + lua_getfield(scene->L, lua_gettop(scene->L), "scenriLua"); + lua_remove(scene->L, -2); // Removes "loaded" + scenriLua = lua_gettop(scene->L); + + push_lua(scene->L, "@ ( $ $ )", scenriLua, "finishLoadStuffs", scene->sim, result->stuffs.file, 0); + } + if (ES_LOADED == result->stage) + { + eina_clist_remove(&(result->node)); + stuffsSetup(result, result->scene, result->fake); + result->stage = ES_RENDERED; + } + } + + return ECORE_CALLBACK_RENEW; +} + Scene_Data *scenriAdd(Evas_Object *win) { Scene_Data *scene; @@ -230,6 +359,7 @@ Scene_Data *scenriAdd(Evas_Object *win) scene = calloc(1, sizeof(Scene_Data)); scene->evas = evas; eina_clist_init(&(scene->stuffs)); + eina_clist_init(&(scene->loading)); scene->root_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE)); @@ -308,6 +438,12 @@ Scene_Data *scenriAdd(Evas_Object *win) scenriLua = lua_gettop(scene->L); // Define our functions. + push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "preallocateStuffs", "preallocate a bunch of stuffs.", _preallocateStuffs, + "number", 0); + push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "partFillStuffs", "Put some info into a stuffs.", _partFillStuffs, + "string,string,number,number,number,number,number,number,number", 0); + push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "finishStuffs", "Put rest of info into a stuffs.", _finishStuffs, + "string,string,string,string,string,number,number,number,number,number,number,number,number", 0); push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addStuffs", "Add an in world stuffs.", _addStuffsL, "string,string,string,string,string,number,number,number,number,number,number,number,number", 0); 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) doLuaString(scene->L, buf, "scenriLua"); } + idler = ecore_idler_add(_stuffsLoader, scene); + return scene; } @@ -575,7 +713,6 @@ static void _sphere_init(int precision) } } - void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) { char buf[PATH_MAX]; @@ -584,6 +721,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) Evas_3D_Material *mi, *mj; Evas_3D_Mesh *me; + PI("REZZING %s", stuffs->stuffs.name); // TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format. // So just fake it for now, and expand the data format later. @@ -774,6 +912,7 @@ ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner, result->stuffs.details.mesh->type = type; result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; 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; + result->stage = ES_NORMAL; return result; } diff --git a/src/libraries/love.h b/src/libraries/love.h index e2cfcb4..be82758 100644 --- a/src/libraries/love.h +++ b/src/libraries/love.h @@ -143,7 +143,7 @@ typedef struct _mesh typedef struct _stuffs { - char UUID[45], name[PATH_MAX], description[PATH_MAX], owner[45]; + char UUID[45], name[PATH_MAX], description[PATH_MAX], owner[45], file[PATH_MAX]; //type union { -- cgit v1.1