aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--lib/scenriLua.lua62
-rw-r--r--media/Test%20sim/earth.omg9
-rw-r--r--media/Test%20sim/index.omg8
-rw-r--r--media/Test%20sim/onefang%27s%20test%20bed.omg23
-rw-r--r--media/Test%20sim/sonic.omg10
-rwxr-xr-xsrc/extantz/build.lua2
-rw-r--r--src/extantz/extantz.c58
-rw-r--r--src/extantz/extantz.h14
-rw-r--r--src/extantz/scenri.c213
-rw-r--r--src/libraries/love.h2
-rw-r--r--src/love/love.c15
11 files changed, 361 insertions, 55 deletions
diff --git a/lib/scenriLua.lua b/lib/scenriLua.lua
new file mode 100644
index 0000000..1b9f010
--- /dev/null
+++ b/lib/scenriLua.lua
@@ -0,0 +1,62 @@
1--[[ scenriLua - In world objects as skang Things.
2
3TODO - Yes I know this breaks our design goals,
4 but it's the easy way to quickly whip up in world object loading.
5 Later a C + eet version will be written to fit our design,
6 and this Lua based version will be kept.
7 The system should "compile" Lua based files to eet as well.
8 For now Lua based files is easier to debug.
9
10]]
11
12do
13 local skang = require 'skang'
14 -- This module has no default skin, it creates no windows.
15 local _M = skang.moduleBegin('scenriLua', nil, 'Copyright 2014 David Seikel', '0.1', '2014-06-01 13:23:00')
16
17 MeshType = {}
18 TextureType = {}
19
20 loadSim = function(sim)
21 local file = sim .. '/index.omg'
22 print('Loading sim from file ' .. file)
23
24 -- TODO - Stuffs should be local, but externally loaded functions can't access locals it seems.
25 Stuffs = {}
26 local simData, err = loadfile(file)
27
28 if simData then
29 setfenv(simData, getfenv(1))
30 simData()
31 if Stuffs.details and Stuffs.details.stuffs then
32 local simStuffs = Stuffs
33
34 for k, v in pairs(simStuffs.details.stuffs) do
35 file = sim .. '/' .. v.fileName
36 print('Rezzing ' .. file)
37 simData, err = loadfile(file)
38 if simData then
39 setfenv(simData, getfenv(1))
40 simData()
41 if Stuffs.details and Stuffs.details.Mesh then
42 local eStuffs = addStuffs(Stuffs.uuid, Stuffs.name, Stuffs.description,
43 Stuffs.owner, v.fileName, MeshType[Stuffs.details.Mesh.kind],
44 v.pos[1], v.pos[2], v.pos[3], v.rot[1], v.rot[2], v.rot[3], v.rot[4])
45 if eStuffs then
46 addMaterial(eStuffs, -1, TextureType[Stuffs.details.Mesh.materials[0].kind ], Stuffs.details.Mesh.materials[0].texture)
47 stuffsSetup(eStuffs, Stuffs.fake)
48 end
49 end
50 elseif 'cannot open ' ~= string.sub(err, 1, 12) then
51 print("ERROR - " .. err)
52 end
53 end
54 end
55 elseif 'cannot open ' ~= string.sub(err, 1, 12) then
56 print("ERROR - " .. err)
57 end
58 end
59 skang.thingasm('loadSim', 'Load a sim.', loadSim, 'string')
60
61 skang.moduleEnd(_M)
62end
diff --git a/media/Test%20sim/earth.omg b/media/Test%20sim/earth.omg
index 94d2672..88b8430 100644
--- a/media/Test%20sim/earth.omg
+++ b/media/Test%20sim/earth.omg
@@ -2,14 +2,19 @@ Stuffs =
2{ 2{
3 name = "onefang's left testicle", 3 name = "onefang's left testicle",
4 description = 'Just a pretend world for testing SledjHamr.', 4 description = 'Just a pretend world for testing SledjHamr.',
5-- owner = '12345678-1234-4321-abcd-0123456789ab', 5 fake = 2,
6 uuid = '12345678-1234-4321-abcd-012345sphere',
7 owner = '12345678-1234-4321-abcd-0123456789ab',
6 details = 8 details =
7 { 9 {
8 Mesh = 10 Mesh =
9 { 11 {
10 kind = 'sphere', 12 kind = 'sphere',
11-- insert prim parameters here 13-- insert prim parameters here
12 materials = {'EarthDiffuse.png'}, 14 materials =
15 {
16 [0] = {kind = 'face', texture = 'EarthDiffuse.png'},
17 },
13 }, 18 },
14 }, 19 },
15} 20}
diff --git a/media/Test%20sim/index.omg b/media/Test%20sim/index.omg
index 78148a1..c9d3b71 100644
--- a/media/Test%20sim/index.omg
+++ b/media/Test%20sim/index.omg
@@ -2,26 +2,26 @@ Stuffs =
2{ 2{
3 name = "Test sim", 3 name = "Test sim",
4 description = 'onefangs test SledjHamr sim.', 4 description = 'onefangs test SledjHamr sim.',
5-- owner = '12345678-1234-4321-abcd-0123456789ab', 5 owner = '12345678-1234-4321-abcd-0123456789ab',
6 details = 6 details =
7 { 7 {
8 stuffs = 8 stuffs =
9 { 9 {
10 Mesh = 10 ['onefang%27s%20test%20bed'] =
11 { 11 {
12 fileName = 'onefang%27s%20test%20bed.omg', 12 fileName = 'onefang%27s%20test%20bed.omg',
13 pos = {0.0, 4.0, 10.0}, 13 pos = {0.0, 4.0, 10.0},
14 size = {1.0, 1.0, 1.0}, 14 size = {1.0, 1.0, 1.0},
15 rot = {1.0, 0.0, 0.0, 0.0}, 15 rot = {1.0, 0.0, 0.0, 0.0},
16 }, 16 },
17 Mesh = 17 ['sonic'] =
18 { 18 {
19 fileName = 'sonic.omg', 19 fileName = 'sonic.omg',
20 pos = {0.0, 0.0, 0.0}, 20 pos = {0.0, 0.0, 0.0},
21 size = {1.0, 1.0, 1.0}, 21 size = {1.0, 1.0, 1.0},
22 rot = {-0.7071067811865475, 0.0, 0.0, 0.7071067811865475}, 22 rot = {-0.7071067811865475, 0.0, 0.0, 0.7071067811865475},
23 }, 23 },
24 Mesh = 24 ['earth'] =
25 { 25 {
26 fileName = 'earth.omg', 26 fileName = 'earth.omg',
27 pos = {0.0, 0.0, 0.0}, 27 pos = {0.0, 0.0, 0.0},
diff --git a/media/Test%20sim/onefang%27s%20test%20bed.omg b/media/Test%20sim/onefang%27s%20test%20bed.omg
index d1dcca0..1e86837 100644
--- a/media/Test%20sim/onefang%27s%20test%20bed.omg
+++ b/media/Test%20sim/onefang%27s%20test%20bed.omg
@@ -2,29 +2,40 @@ Stuffs =
2{ 2{
3 name = "onefang's test bed", 3 name = "onefang's test bed",
4 description = 'Just a pretend bed with MLP scripts for testing SledjHamr.', 4 description = 'Just a pretend bed with MLP scripts for testing SledjHamr.',
5-- owner = '12345678-1234-4321-abcd-0123456789ab', 5 fake = 1,
6 uuid = '12345678-1234-4321-abcd-01234567cube',
7 owner = '12345678-1234-4321-abcd-0123456789ab',
6 details = 8 details =
7 { 9 {
8 Mesh = 10 Mesh =
9 { 11 {
10 kind = 'cube', 12 kind = 'cube',
11 materials = {'normal_lego.png'}, 13 materials =
14 {
15 [0] = {kind = 'normal', texture = 'normal_lego.png'},
16 },
12--[[ 17--[[
13 parts = 18 parts =
14 { 19 {
15 Mesh = 20 ['sonic'] =
16 { 21 {
17 fileName = 'sonic.md2', 22 fileName = 'sonic.md2',
18 pos = {1.23, 4.56, 789.0}, 23 pos = {1.23, 4.56, 789.0},
19 rot = { , , , ,}, 24 rot = { , , , ,},
20 materials = {'sonic.png'}, 25 materials =
26 {
27 [0] = {kind = 'face', texture = 'sonic.png'},
28 },
21 }, 29 },
22 Mesh = 30 ['earth'] =
23 { 31 {
24 kind = 'earth', 32 kind = 'earth',
25 pos = {1.23, 4.56, 789.0}, 33 pos = {1.23, 4.56, 789.0},
26 rot = { , , , ,}, 34 rot = { , , , ,},
27 materials = {'EarthDiffuse.png'}, 35 materials =
36 {
37 [0] = {kind = 'face', texture = 'EarthDiffuse.png'},
38 },
28 }, 39 },
29 }, 40 },
30]] 41]]
diff --git a/media/Test%20sim/sonic.omg b/media/Test%20sim/sonic.omg
index fad5b11..1b33e4f 100644
--- a/media/Test%20sim/sonic.omg
+++ b/media/Test%20sim/sonic.omg
@@ -2,13 +2,19 @@ Stuffs =
2{ 2{
3 name = "Sonic the bed hog.", 3 name = "Sonic the bed hog.",
4 description = 'Just a pretend avatar for testing SledjHamr.', 4 description = 'Just a pretend avatar for testing SledjHamr.',
5-- owner = '12345678-1234-4321-abcd-0123456789ab', 5 fake = 3,
6 uuid = '12345678-1234-4321-abcd-0123456sonic',
7 owner = '12345678-1234-4321-abcd-0123456789ab',
6 details = 8 details =
7 { 9 {
8 Mesh = 10 Mesh =
9 { 11 {
10 fileName = 'sonic.md2', 12 fileName = 'sonic.md2',
11 materials = {'sonic.png'}, 13 kind = 'mesh',
14 materials =
15 {
16 [0] = {kind = 'face', texture = 'sonic.png'},
17 },
12 }, 18 },
13 }, 19 },
14} 20}
diff --git a/src/extantz/build.lua b/src/extantz/build.lua
index c2990ff..703b577 100755
--- a/src/extantz/build.lua
+++ b/src/extantz/build.lua
@@ -24,4 +24,4 @@ runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c crappissp
24runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS) 24runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS)
25runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS) 25runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS)
26CFLAGS = CFLAGS .. ' -Wl,-export-dynamic' 26CFLAGS = CFLAGS .. ' -Wl,-export-dynamic'
27compileFiles('../../extantz', dir, {'gears', 'ephysics_demo', 'camera', 'Evas_3D_demo', 'files', 'scenri', 'woMan', 'extantz'}, 'crappisspuke.o CDemo.o extantzCamera.o') 27compileFiles('../../extantz', dir, {'gears', 'ephysics_demo', 'camera', 'files', 'scenri', 'woMan', 'extantz'}, 'crappisspuke.o CDemo.o extantzCamera.o')
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c
index 835429f..e102165 100644
--- a/src/extantz/extantz.c
+++ b/src/extantz/extantz.c
@@ -11,7 +11,7 @@ static void on_pixels(void *data, Evas_Object *obj);
11int logDom = -1; // Our logging domain. 11int logDom = -1; // Our logging domain.
12globals ourGlobals; 12globals ourGlobals;
13static Eina_Strbuf *serverStream; 13static Eina_Strbuf *serverStream;
14static char *myKey = "12345678-1234-4321-abcd-0123456789ab"; 14//static char *myKey = "12345678-1234-4321-abcd-0123456789ab";
15//static char *myName = "onefang rejected"; 15//static char *myName = "onefang rejected";
16 16
17 17
@@ -22,20 +22,11 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
22 22
23 PI("Connected to love server."); 23 PI("Connected to love server.");
24 ourGlobals->server = ev->server; 24 ourGlobals->server = ev->server;
25
26 // Pretend we logged in.
27 strcpy(ourGlobals->uuid, myKey);
28
29 if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server; 25 if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server;
30 if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server; 26 if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server;
31 27
32 Evas_3D_Demo_add(ourGlobals); 28 // TODO - If this is not a local love server, we should attempt to log in here.
33 // TODO - Just a temporary hack so Irrlicht and Evas_3D can share the camera move. 29 // Or attempt a hypergrid style TP.
34 ourGlobals->gld.move = ourGlobals->scene->move;
35 evas_object_data_set(elm_image_object_get(ourGlobals->scene->image), "glob", ourGlobals);
36 evas_object_image_pixels_get_callback_set(elm_image_object_get(ourGlobals->scene->image), on_pixels, ourGlobals);
37 // Setup our callback for clicking in world.
38 ourGlobals->scene->clickCb = _onWorldClick;
39 30
40 return ECORE_CALLBACK_RENEW; 31 return ECORE_CALLBACK_RENEW;
41} 32}
@@ -96,6 +87,40 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
96 PE("No LSLGuiMess to send - %s", command); 87 PE("No LSLGuiMess to send - %s", command);
97 88
98 } 89 }
90 else if (0 == strncmp(command, "loadSim(", 8))
91 {
92 char *p, *t;
93 int scenriLua;
94
95 // Pretend we logged in. Actually in the case of a local love server, we realy have logged in now.
96 strcpy(ourGlobals->uuid, SID);
97 PI("Your UUID is %s.", ourGlobals->uuid);
98 strcpy(buf, &command[8]);
99 p = buf;
100 while ('"' == p[0])
101 p++;
102 while ('\'' == p[0])
103 p++;
104 t = p;
105 while (('"' != p[0]) && ('\'' != p[0]))
106 p++;
107 p[0] = '\0';
108 // TODO - For now, assume it's a file:// URL.
109 t += 7;
110 //strcat(t, "/index.omg");
111 PI("Loading local sim from %s", t);
112
113 // TODO - Later do the same with eet files in C code, but keep both implementations.
114 lua_getglobal(ourGlobals->scene->L, "package");
115 lua_getfield(ourGlobals->scene->L, lua_gettop(ourGlobals->scene->L), "loaded");
116 lua_remove(ourGlobals->scene->L, -2); // Removes "package"
117 lua_getfield(ourGlobals->scene->L, lua_gettop(ourGlobals->scene->L), "scenriLua");
118 lua_remove(ourGlobals->scene->L, -2); // Removes "loaded"
119 scenriLua = lua_gettop(ourGlobals->scene->L);
120
121 push_lua(ourGlobals->scene->L, "@ ( $ $ )", scenriLua, "loadSim", t);
122// Evas_3D_Demo_add(ourGlobals, t);
123 }
99 else 124 else
100 { 125 {
101 PI("Some random command %s", command); 126 PI("Some random command %s", command);
@@ -587,7 +612,6 @@ EAPI_MAIN int elm_main(int argc, char **argv)
587 if (!ephysics_init()) 612 if (!ephysics_init())
588 return 1; 613 return 1;
589 614
590 eina_clist_init(&(ourGlobals.stuffs));
591 gld = &ourGlobals.gld; 615 gld = &ourGlobals.gld;
592 gldata_init(gld); 616 gldata_init(gld);
593 617
@@ -662,6 +686,14 @@ EAPI_MAIN int elm_main(int argc, char **argv)
662 686
663 init_evas_gl(&ourGlobals); 687 init_evas_gl(&ourGlobals);
664 688
689 // Setup our Evas_3D stuff.
690 ourGlobals.scene = scenriAdd(ourGlobals.win);
691 // TODO - Just a temporary hack so Irrlicht and Evas_3D can share the camera move.
692 ourGlobals.gld.move = ourGlobals.scene->move;
693 evas_object_data_set(elm_image_object_get(ourGlobals.scene->image), "glob", &ourGlobals);
694 evas_object_image_pixels_get_callback_set(elm_image_object_get(ourGlobals.scene->image), on_pixels, &ourGlobals);
695 ourGlobals.scene->clickCb = _onWorldClick;
696
665 // Gotta do this after adding the windows, otherwise the menu renders under the window. 697 // Gotta do this after adding the windows, otherwise the menu renders under the window.
666 // This sucks, gotta redefine this menu each time we create a new window? 698 // This sucks, gotta redefine this menu each time we create a new window?
667 // Also, GL focus gets lost when any menu is used. sigh 699 // Also, GL focus gets lost when any menu is used. sigh
diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h
index 5095556..1526626 100644
--- a/src/extantz/extantz.h
+++ b/src/extantz/extantz.h
@@ -132,6 +132,7 @@ typedef struct
132 132
133typedef struct _Scene_Data 133typedef struct _Scene_Data
134{ 134{
135 Evas *evas;
135 Evas_Object *image; // Our Elm image. 136 Evas_Object *image; // Our Elm image.
136 Evas_3D_Scene *scene; 137 Evas_3D_Scene *scene;
137 Evas_3D_Node *root_node; 138 Evas_3D_Node *root_node;
@@ -140,6 +141,8 @@ typedef struct _Scene_Data
140 141
141 Evas_3D_Light *light; 142 Evas_3D_Light *light;
142 143
144 Eina_Clist stuffs;
145/*
143 Evas_3D_Mesh *mesh; 146 Evas_3D_Mesh *mesh;
144 Evas_3D_Node *mesh_node; 147 Evas_3D_Node *mesh_node;
145 Evas_3D_Material *material0; 148 Evas_3D_Material *material0;
@@ -157,10 +160,11 @@ typedef struct _Scene_Data
157 Evas_3D_Node *mesh3_node; 160 Evas_3D_Node *mesh3_node;
158 Evas_3D_Material *material3; 161 Evas_3D_Material *material3;
159 Evas_3D_Texture *texture_diffuse; 162 Evas_3D_Texture *texture_diffuse;
160 163*/
161 cameraMove *move; 164 cameraMove *move;
162 165
163 Evas_Object_Event_Cb clickCb; 166 Evas_Object_Event_Cb clickCb;
167 lua_State *L;
164} Scene_Data; 168} Scene_Data;
165 169
166typedef void (* aniStuffs)(void *stuffs); 170typedef void (* aniStuffs)(void *stuffs);
@@ -168,6 +172,7 @@ typedef void (* aniStuffs)(void *stuffs);
168typedef struct _extantzStuffs 172typedef struct _extantzStuffs
169{ 173{
170 Stuffs stuffs; 174 Stuffs stuffs;
175 Scene_Data *scene;
171 Evas_3D_Node *mesh_node; // Multiple Evas_3D_Mesh's can be in one Evas_3D_Node 176 Evas_3D_Node *mesh_node; // Multiple Evas_3D_Mesh's can be in one Evas_3D_Node
172 // Can't use in arrays here, can't find the element sizes of incomplete types. 177 // Can't use in arrays here, can't find the element sizes of incomplete types.
173 Eina_Array *mesh; // Evas_3D_Mesh 178 Eina_Array *mesh; // Evas_3D_Mesh
@@ -245,7 +250,6 @@ typedef struct _globals
245 250
246 GLData gld; 251 GLData gld;
247 Scene_Data *scene; 252 Scene_Data *scene;
248 Eina_Clist stuffs;
249 253
250 EPhysics_World *world; 254 EPhysics_World *world;
251 255
@@ -278,7 +282,7 @@ EAPI void finishIrr(globals *ourGlobals);
278 282
279void overlay_add(globals *ourGlobals); 283void overlay_add(globals *ourGlobals);
280 284
281EAPI void Evas_3D_Demo_add(globals *ourGlobals); 285EAPI void Evas_3D_Demo_add(globals *ourGlobals, char *file);
282Eina_Bool animateScene(globals *ourGlobals); 286Eina_Bool animateScene(globals *ourGlobals);
283void Evas_3D_Demo_fini(globals *ourGlobals); 287void Evas_3D_Demo_fini(globals *ourGlobals);
284 288
@@ -287,9 +291,9 @@ Evas_3D_Node *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *win);
287Eina_Bool animateCamera(Scene_Data *scene); 291Eina_Bool animateCamera(Scene_Data *scene);
288Eina_Bool animateScene(globals *ourGlobals); 292Eina_Bool animateScene(globals *ourGlobals);
289void scenriDel(Scene_Data *scene); 293void scenriDel(Scene_Data *scene);
290void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene, int fake); 294void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake);
291ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner, 295ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner,
292 char *file, MeshType type, float px, float py, float pz, float rx, float ry, float rz, float rw); 296 char *file, MeshType type, double px, double py, double pz, double rx, double ry, double rz, double rw);
293void addMaterial(ExtantzStuffs *e, int face, TextureType type, char *file); 297void addMaterial(ExtantzStuffs *e, int face, TextureType type, char *file);
294 298
295winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool save); 299winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool save);
diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c
index 4ebc64a..e7d30c4 100644
--- a/src/extantz/scenri.c
+++ b/src/extantz/scenri.c
@@ -1,11 +1,85 @@
1// scenri.c, deals with the in world scenery.
2
3/* TODO - I can see this growing to be very big, so should start to split it up at some point.
4 Base stuff -
5 scenriAdd/Del()
6 mouse hover showing tooltips
7 mouse click on objects
8 world animator that calls animators for stuffs
9 addStuffs/Materials() setupStuffs()
10
11 Scripting hooks
12 Lua hooks
13 LSL wrappers around Lua hooks
14 Lua file loader, maybe have this in libg3d?
15
16 Basic mesh stuff (likely just libg3d) -
17 create cube, sphere, etc
18 load meshes
19
20 In world editing
21
22*/
23
1#include "extantz.h" 24#include "extantz.h"
2 25
3 26
27#define SKANG "skang"
28#define THINGASM "thingasm"
29
30
31
32static void _animateCube(ExtantzStuffs *stuffs)
33{
34 static float angle = 0.0f;
35 static int frame = 0;
36 static int inc = 1;
37 Evas_3D_Mesh *m;
38
39 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m);
40
41 angle += 0.5;
42 if (angle > 360.0) angle -= 360.0f;
43
44 frame += inc;
45 if (frame >= 20) inc = -1;
46 else if (frame <= 0) inc = 1;
47
48 eo_do(stuffs->mesh_node,
49 evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0),
50 evas_3d_node_mesh_frame_set(m, frame)
51 );
52}
53
54static void _animateSphere(ExtantzStuffs *stuffs)
55{
56 static float earthAngle = 0.0f;
57
58 earthAngle += 0.3;
59 if (earthAngle > 360.0) earthAngle -= 360.0f;
60 eo_do(stuffs->mesh_node,
61 evas_3d_node_orientation_angle_axis_set(earthAngle, 0.0, 1.0, 0.0)
62 );
63}
64
65static void _animateSonic(ExtantzStuffs *stuffs)
66{
67 static int sonicFrame = 0;
68 Evas_3D_Mesh *m;
69
70 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m);
71 sonicFrame += 32;
72 if (sonicFrame > 256 * 50) sonicFrame = 0;
73 eo_do(stuffs->mesh_node,
74 evas_3d_node_mesh_frame_set(m, sonicFrame)
75 );
76}
77
4Eina_Bool animateScene(globals *ourGlobals) 78Eina_Bool animateScene(globals *ourGlobals)
5{ 79{
6 ExtantzStuffs *e; 80 ExtantzStuffs *e;
7 81
8 EINA_CLIST_FOR_EACH_ENTRY(e, &ourGlobals->stuffs, ExtantzStuffs, node) 82 EINA_CLIST_FOR_EACH_ENTRY(e, &ourGlobals->scene->stuffs, ExtantzStuffs, node)
9 { 83 {
10 if (e->animateStuffs) e->animateStuffs(e); 84 if (e->animateStuffs) e->animateStuffs(e);
11 } 85 }
@@ -99,6 +173,52 @@ static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void
99 173
100} 174}
101 175
176static int _addStuffsL(lua_State *L)
177{
178 ExtantzStuffs *result = NULL;
179 char *uuid, *name, *description, *owner, *file;
180 int type;
181 double px, py, pz, rx, ry, rz, rw;
182
183 pull_lua(L, 1, "$ $ $ $ $ % # # # # # # #", &uuid, &name, &description, &owner, &file, &type, &px, &py, &pz, &rx, &ry, &rz, &rw);
184 result = addStuffs(uuid, name, description, owner, file, type, px, py, pz, rx, ry, rz, rw);
185 if (result)
186 {
187 lua_getfield(L, LUA_REGISTRYINDEX, "sceneData");
188 result->scene = (Scene_Data *) lua_touserdata(L, -1);
189
190 lua_pushlightuserdata(L, (void *) result);
191 return 1;
192 }
193
194 return 0;
195}
196
197static int _addMaterialL(lua_State *L)
198{
199 ExtantzStuffs *e = NULL;
200 int face, type;
201 char *file;
202
203 pull_lua(L, 1, "* % % $", &e, &face, &type, &file);
204 if (e)
205 addMaterial(e, face, type, file);
206
207 return 0;
208}
209
210static int _stuffsSetupL(lua_State *L)
211{
212 ExtantzStuffs *e = NULL;
213 int fake;
214
215 pull_lua(L, 1, "* %", &e, &fake);
216 if (e)
217 stuffsSetup(e, e->scene, fake);
218
219 return 0;
220}
221
102Scene_Data *scenriAdd(Evas_Object *win) 222Scene_Data *scenriAdd(Evas_Object *win)
103{ 223{
104 Scene_Data *scene; 224 Scene_Data *scene;
@@ -108,6 +228,8 @@ Scene_Data *scenriAdd(Evas_Object *win)
108 evas = evas_object_evas_get(win); 228 evas = evas_object_evas_get(win);
109 eo_do(win, evas_obj_size_get(&w, &h)); 229 eo_do(win, evas_obj_size_get(&w, &h));
110 scene = calloc(1, sizeof(Scene_Data)); 230 scene = calloc(1, sizeof(Scene_Data));
231 scene->evas = evas;
232 eina_clist_init(&(scene->stuffs));
111 233
112 scene->root_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE)); 234 scene->root_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE));
113 235
@@ -152,11 +274,61 @@ Scene_Data *scenriAdd(Evas_Object *win)
152 274
153 elm_win_resize_object_add(win, scene->image); 275 elm_win_resize_object_add(win, scene->image);
154 276
277 scene->L = luaL_newstate();
278 if (scene->L)
279 {
280 char buf[PATH_MAX];
281 int skang, scenriLua;
282
283 luaL_openlibs(scene->L);
284 lua_getglobal(scene->L, "require");
285 lua_pushstring(scene->L, "scenriLua");
286 lua_call(scene->L, 1, 1);
287
288 // Shove our structure into the registry.
289 lua_pushlightuserdata(scene->L, scene);
290 lua_setfield(scene->L, LUA_REGISTRYINDEX, "sceneData");
291
292 // The skang module should have been loaded by now, so we can just grab it out of package.loaded[].
293 lua_getglobal(scene->L, "package");
294 lua_getfield(scene->L, lua_gettop(scene->L), "loaded");
295 lua_remove(scene->L, -2); // Removes "package"
296 lua_getfield(scene->L, lua_gettop(scene->L), SKANG);
297 lua_remove(scene->L, -2); // Removes "loaded"
298 lua_setfield(scene->L, LUA_REGISTRYINDEX, SKANG);
299 lua_getfield(scene->L, LUA_REGISTRYINDEX, SKANG); // Puts the skang table back on the stack.
300 skang = lua_gettop(scene->L);
301
302 // Same for the scenriLua module, we just loaded it.
303 lua_getglobal(scene->L, "package");
304 lua_getfield(scene->L, lua_gettop(scene->L), "loaded");
305 lua_remove(scene->L, -2); // Removes "package"
306 lua_getfield(scene->L, lua_gettop(scene->L), "scenriLua");
307 lua_remove(scene->L, -2); // Removes "loaded"
308 scenriLua = lua_gettop(scene->L);
309
310 // Define our functions.
311 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);
313 push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addMaterial", "Add a material to an in world stuffs.", _addMaterialL,
314 "userdata,number,number,string", 0);
315 push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "stuffsSetup", "Render the stuffs.", _stuffsSetupL,
316 "userdata,number", 0);
317
318 // Pass the enums to scenriLua.
319 sprintf(buf, "MeshType = {cube = %d, mesh = %d, sphere = %d}", MT_CUBE, MT_MESH, MT_SPHERE);
320 doLuaString(scene->L, buf, "scenriLua");
321 sprintf(buf, "TextureType = {face = %d, normal = %d}", TT_FACE, TT_NORMAL);
322 doLuaString(scene->L, buf, "scenriLua");
323 }
324
155 return scene; 325 return scene;
156} 326}
157 327
158void scenriDel(Scene_Data *scene) 328void scenriDel(Scene_Data *scene)
159{ 329{
330 lua_close(scene->L);
331
160 // TODO - I should probably free up all this Evas_3D stuff. Oddly Eo doesn't bitch about it, only valgrind. 332 // TODO - I should probably free up all this Evas_3D stuff. Oddly Eo doesn't bitch about it, only valgrind.
161 // Eo bitches if they are unref'd here. 333 // Eo bitches if they are unref'd here.
162 // So either Eo or valgrind bitches, depending on what I do. I'll leave them commented out, let valgrind bitch, and blame Evas_3D. 334 // So either Eo or valgrind bitches, depending on what I do. I'll leave them commented out, let valgrind bitch, and blame Evas_3D.
@@ -257,8 +429,8 @@ static vertex *sphere_vertices = NULL;
257static int index_count = 0; 429static int index_count = 0;
258static unsigned short *sphere_indices = NULL; 430static unsigned short *sphere_indices = NULL;
259 431
260static inline vec3 432
261_normalize(const vec3 *v) 433static inline vec3 _normalize(const vec3 *v)
262{ 434{
263 double l = sqrt(v->x * v->x + v->y * v->y + v->z * v->z); 435 double l = sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
264 vec3 vec; 436 vec3 vec;
@@ -270,7 +442,6 @@ _normalize(const vec3 *v)
270 return vec; 442 return vec;
271} 443}
272 444
273
274static void _sphere_init(int precision) 445static void _sphere_init(int precision)
275{ 446{
276 int i, j; 447 int i, j;
@@ -405,7 +576,7 @@ static void _sphere_init(int precision)
405} 576}
406 577
407 578
408void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene, int fake) 579void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake)
409{ 580{
410 char buf[PATH_MAX]; 581 char buf[PATH_MAX];
411 Material *m; 582 Material *m;
@@ -419,12 +590,12 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
419 // Textures 590 // Textures
420 if (1 == fake) 591 if (1 == fake)
421 { 592 {
422 t = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas, 593 t = eo_add(EVAS_3D_TEXTURE_CLASS, scene->evas,
423 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0]) 594 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0])
424 ); 595 );
425 eina_array_push(stuffs->textures, t); 596 eina_array_push(stuffs->textures, t);
426 597
427 t1 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas, 598 t1 = eo_add(EVAS_3D_TEXTURE_CLASS, scene->evas,
428 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0]) 599 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0])
429 ); 600 );
430 eina_array_push(stuffs->textures, t1); 601 eina_array_push(stuffs->textures, t1);
@@ -433,7 +604,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
433 EINA_INARRAY_FOREACH(stuffs->stuffs.details.mesh->materials, m) 604 EINA_INARRAY_FOREACH(stuffs->stuffs.details.mesh->materials, m)
434 { 605 {
435 snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), m->texture); 606 snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), m->texture);
436 ti = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas, 607 ti = eo_add(EVAS_3D_TEXTURE_CLASS, scene->evas,
437 evas_3d_texture_file_set(buf, NULL), 608 evas_3d_texture_file_set(buf, NULL),
438 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR), // Only for sphere originally. 609 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR), // Only for sphere originally.
439 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_NEAREST, EVAS_3D_TEXTURE_FILTER_NEAREST), // Only for sonic originally. 610 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_NEAREST, EVAS_3D_TEXTURE_FILTER_NEAREST), // Only for sonic originally.
@@ -446,7 +617,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
446 if (1 == fake) 617 if (1 == fake)
447 { 618 {
448 eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t); 619 eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t);
449 mi = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas, 620 mi = eo_add(EVAS_3D_MATERIAL_CLASS, scene->evas,
450 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE), 621 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
451 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE), 622 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
452 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE), 623 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
@@ -462,7 +633,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
462 633
463 eina_accessor_data_get(stuffs->aTexture, 1, (void **) &t1); 634 eina_accessor_data_get(stuffs->aTexture, 1, (void **) &t1);
464 eina_accessor_data_get(stuffs->aTexture, 2, (void **) &ti); 635 eina_accessor_data_get(stuffs->aTexture, 2, (void **) &ti);
465 mj = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas, 636 mj = eo_add(EVAS_3D_MATERIAL_CLASS, scene->evas,
466 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE), 637 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
467 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE), 638 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
468 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE), 639 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
@@ -481,7 +652,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
481 else 652 else
482 { 653 {
483 eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t); 654 eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t);
484 mi = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas, 655 mi = eo_add(EVAS_3D_MATERIAL_CLASS, scene->evas,
485 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t), 656 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t),
486 657
487 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE), 658 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
@@ -503,7 +674,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
503 { 674 {
504 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); 675 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
505 eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj); 676 eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj);
506 me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas, 677 me = eo_add(EVAS_3D_MESH_CLASS, scene->evas,
507 evas_3d_mesh_vertex_count_set(24), 678 evas_3d_mesh_vertex_count_set(24),
508 evas_3d_mesh_frame_add(0), 679 evas_3d_mesh_frame_add(0),
509 680
@@ -529,7 +700,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
529 _sphere_init(100); 700 _sphere_init(100);
530 701
531 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); 702 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
532 me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas, 703 me = eo_add(EVAS_3D_MESH_CLASS, scene->evas,
533 evas_3d_mesh_vertex_count_set(vertex_count), 704 evas_3d_mesh_vertex_count_set(vertex_count),
534 evas_3d_mesh_frame_add(0), 705 evas_3d_mesh_frame_add(0),
535 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, sizeof(vertex), &sphere_vertices[0].position), 706 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, sizeof(vertex), &sphere_vertices[0].position),
@@ -550,7 +721,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
550 { 721 {
551 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); 722 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
552 snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), stuffs->stuffs.details.mesh->fileName); 723 snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), stuffs->stuffs.details.mesh->fileName);
553 me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas, 724 me = eo_add(EVAS_3D_MESH_CLASS, scene->evas,
554 evas_3d_mesh_file_set(EVAS_3D_MESH_FILE_TYPE_MD2, buf, NULL), 725 evas_3d_mesh_file_set(EVAS_3D_MESH_FILE_TYPE_MD2, buf, NULL),
555 evas_3d_mesh_frame_material_set(0, mi), 726 evas_3d_mesh_frame_material_set(0, mi),
556 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG) 727 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG)
@@ -559,7 +730,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
559 } 730 }
560 731
561 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &me); 732 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &me);
562 stuffs->mesh_node = eo_add_custom(EVAS_3D_NODE_CLASS, ourGlobals->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH), 733 stuffs->mesh_node = eo_add_custom(EVAS_3D_NODE_CLASS, scene->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH),
563 eo_key_data_set("Name", stuffs->stuffs.name, NULL), 734 eo_key_data_set("Name", stuffs->stuffs.name, NULL),
564 evas_3d_node_position_set(stuffs->stuffs.details.mesh->pos.x, stuffs->stuffs.details.mesh->pos.y, stuffs->stuffs.details.mesh->pos.z), 735 evas_3d_node_position_set(stuffs->stuffs.details.mesh->pos.x, stuffs->stuffs.details.mesh->pos.y, stuffs->stuffs.details.mesh->pos.z),
565 evas_3d_node_orientation_set(stuffs->stuffs.details.mesh->rot.x, stuffs->stuffs.details.mesh->rot.y, stuffs->stuffs.details.mesh->rot.z, stuffs->stuffs.details.mesh->rot.w), 736 evas_3d_node_orientation_set(stuffs->stuffs.details.mesh->rot.x, stuffs->stuffs.details.mesh->rot.y, stuffs->stuffs.details.mesh->rot.z, stuffs->stuffs.details.mesh->rot.w),
@@ -567,11 +738,19 @@ void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene,
567 ); 738 );
568 739
569 eo_do(scene->root_node, evas_3d_node_member_add(stuffs->mesh_node)); 740 eo_do(scene->root_node, evas_3d_node_member_add(stuffs->mesh_node));
570 eina_clist_add_head(&(ourGlobals->stuffs), &(stuffs->node)); 741 eina_clist_add_head(&(scene->stuffs), &(stuffs->node));
742
743 if (1 == fake)
744 stuffs->animateStuffs = (aniStuffs) _animateCube;
745 else if (2 == fake)
746 stuffs->animateStuffs = (aniStuffs) _animateSphere;
747 else if (3 == fake)
748 stuffs->animateStuffs = (aniStuffs) _animateSonic;
749
571} 750}
572 751
573ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner, 752ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner,
574 char *file, MeshType type, float px, float py, float pz, float rx, float ry, float rz, float rw) 753 char *file, MeshType type, double px, double py, double pz, double rx, double ry, double rz, double rw)
575{ 754{
576 ExtantzStuffs *result = calloc(1, sizeof(ExtantzStuffs)); 755 ExtantzStuffs *result = calloc(1, sizeof(ExtantzStuffs));
577 756
diff --git a/src/libraries/love.h b/src/libraries/love.h
index e99f282..e2cfcb4 100644
--- a/src/libraries/love.h
+++ b/src/libraries/love.h
@@ -175,7 +175,7 @@ love server starts up
175Extantz client starts up 175Extantz client starts up
176 -> love login(name, password) 176 -> love login(name, password)
177 loads user details 177 loads user details
178 <- love this is your user uuid 178 <- love this is your user uuid and start sim
179 get sim details from lspace at this URL (or local disk directory file://) 179 get sim details from lspace at this URL (or local disk directory file://)
180 -> lspace gimme the sim (or just pick up the index.omg file from disk) 180 -> lspace gimme the sim (or just pick up the index.omg file from disk)
181 <- lspace index.omg 181 <- lspace index.omg
diff --git a/src/love/love.c b/src/love/love.c
index 7d50917..9c24cd3 100644
--- a/src/love/love.c
+++ b/src/love/love.c
@@ -506,11 +506,18 @@ static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev)
506 506
507static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev) 507static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev)
508{ 508{
509 gameGlobals *ourGlobals = data; 509 gameGlobals *ourGlobals = data;
510 510
511 ourGlobals->client = ev->client; 511 ourGlobals->client = ev->client;
512 ecore_con_client_timeout_set(ev->client, 0); 512 ecore_con_client_timeout_set(ev->client, 0);
513 return ECORE_CALLBACK_RENEW; 513
514 if (ourGlobals->client)
515 {
516 // TODO - Sending the currently hard coded ownerKey here, should actually deal with logging in / hypergrid TP style things instead.
517 sendBack(ourGlobals->client, ownerKey, "loadSim('file://%s/Test%%20sim')", prefix_data_get());
518 }
519
520 return ECORE_CALLBACK_RENEW;
514} 521}
515 522
516static Eina_Bool _dataClient(void *data, int type, Ecore_Con_Event_Client_Data *ev) 523static Eina_Bool _dataClient(void *data, int type, Ecore_Con_Event_Client_Data *ev)