aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-17 10:54:52 +1000
committerDavid Walter Seikel2014-05-17 10:54:52 +1000
commitdcd11c8d2b399ce1309637bd756c680db0aec1af (patch)
tree79017fd75d8005bab37771d15612fde2215e72f0 /src
parentAdd a smarter server connect function. (diff)
downloadSledjHamr-dcd11c8d2b399ce1309637bd756c680db0aec1af.zip
SledjHamr-dcd11c8d2b399ce1309637bd756c680db0aec1af.tar.gz
SledjHamr-dcd11c8d2b399ce1309637bd756c680db0aec1af.tar.bz2
SledjHamr-dcd11c8d2b399ce1309637bd756c680db0aec1af.tar.xz
Use the new server connector, and some related movements.
Diffstat (limited to 'src')
-rw-r--r--src/GuiLua/GuiLua.c7
-rw-r--r--src/GuiLua/GuiLua.h4
-rw-r--r--src/GuiLua/skang.c2
-rw-r--r--src/extantz/extantz.c92
-rw-r--r--src/extantz/extantz.h3
-rw-r--r--src/purkle/purkle.c12
6 files changed, 68 insertions, 52 deletions
diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c
index 92254ea..0fc27f4 100644
--- a/src/GuiLua/GuiLua.c
+++ b/src/GuiLua/GuiLua.c
@@ -371,7 +371,7 @@ PD("GuiLua 3");
371 return 1; 371 return 1;
372} 372}
373 373
374GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, Ecore_Con_Server *server, EPhysics_World *world) 374GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, EPhysics_World *world)
375{ 375{
376 GuiLua *result; 376 GuiLua *result;
377 lua_State *L; 377 lua_State *L;
@@ -379,7 +379,6 @@ GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, Ecore_Con_Server *serve
379 379
380 result = calloc(1, sizeof(GuiLua)); 380 result = calloc(1, sizeof(GuiLua));
381 result->parent = parent; 381 result->parent = parent;
382 result->server = server;
383 result->world = world; 382 result->world = world;
384 383
385 L = luaL_newstate(); 384 L = luaL_newstate();
@@ -434,13 +433,13 @@ GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, Ecore_Con_Server *serve
434 return result; 433 return result;
435} 434}
436 435
437GuiLua *GuiLuaLoad(char *module, winFang *parent, Ecore_Con_Server *server, EPhysics_World *world) 436GuiLua *GuiLuaLoad(char *module, winFang *parent, EPhysics_World *world)
438{ 437{
439 GuiLua *result; 438 GuiLua *result;
440 char *args[] = {"GuiLUa", "-l", ""}; 439 char *args[] = {"GuiLUa", "-l", ""};
441 440
442 args[2] = module; 441 args[2] = module;
443 result = GuiLuaDo(3, args, parent, server, world); 442 result = GuiLuaDo(3, args, parent, world);
444 result->name = module; 443 result->name = module;
445 return result; 444 return result;
446} 445}
diff --git a/src/GuiLua/GuiLua.h b/src/GuiLua/GuiLua.h
index 9911ec5..d82d244 100644
--- a/src/GuiLua/GuiLua.h
+++ b/src/GuiLua/GuiLua.h
@@ -32,8 +32,8 @@ typedef struct _GuiLua
32 32
33extern const char *glName; 33extern const char *glName;
34 34
35GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, Ecore_Con_Server *server, EPhysics_World *world); 35GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, EPhysics_World *world);
36GuiLua *GuiLuaLoad(char *module, winFang *parent, Ecore_Con_Server *server, EPhysics_World *world); 36GuiLua *GuiLuaLoad(char *module, winFang *parent, EPhysics_World *world);
37void GuiLuaDel(GuiLua *gl); 37void GuiLuaDel(GuiLua *gl);
38 38
39#endif 39#endif
diff --git a/src/GuiLua/skang.c b/src/GuiLua/skang.c
index 967a354..c116f30 100644
--- a/src/GuiLua/skang.c
+++ b/src/GuiLua/skang.c
@@ -5,7 +5,7 @@
5EAPI_MAIN int elm_main(int argc, char **argv) 5EAPI_MAIN int elm_main(int argc, char **argv)
6{ 6{
7 HamrTime(elm_main, "GuiLua"); 7 HamrTime(elm_main, "GuiLua");
8 GuiLuaDo(argc, argv, NULL, NULL, NULL); 8 GuiLuaDo(argc, argv, NULL, NULL);
9 9
10 return 0; 10 return 0;
11} 11}
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c
index 3da9643..07fe817 100644
--- a/src/extantz/extantz.c
+++ b/src/extantz/extantz.c
@@ -5,6 +5,10 @@
5#include "LumbrJack.h" 5#include "LumbrJack.h"
6 6
7 7
8static void _onWorldClick(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo);
9static void on_pixels(void *data, Evas_Object *obj);
10
11
8static int logDom; // Our logging domain. 12static int logDom; // Our logging domain.
9globals ourGlobals; 13globals ourGlobals;
10static Eina_Strbuf *serverStream; 14static Eina_Strbuf *serverStream;
@@ -15,7 +19,19 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
15{ 19{
16 globals *ourGlobals = data; 20 globals *ourGlobals = data;
17 21
22 PI("Server connected.");
18 ourGlobals->server = ev->server; 23 ourGlobals->server = ev->server;
24 if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server;
25 if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server;
26
27 Evas_3D_Demo_add(ourGlobals);
28 // TODO - Just a temporary hack so Irrlicht and Evas_3D can share the camera move.
29 ourGlobals->gld.move = ourGlobals->scene->move;
30 evas_object_data_set(elm_image_object_get(ourGlobals->scene->image), "glob", ourGlobals);
31 evas_object_image_pixels_get_callback_set(elm_image_object_get(ourGlobals->scene->image), on_pixels, ourGlobals);
32 // Setup our callback for clicking in world.
33 ourGlobals->scene->clickCb = _onWorldClick;
34
19 return ECORE_CALLBACK_RENEW; 35 return ECORE_CALLBACK_RENEW;
20} 36}
21 37
@@ -46,25 +62,33 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
46 || (0 == strncmp(command, "llSay(", 6)) 62 || (0 == strncmp(command, "llSay(", 6))
47 || (0 == strncmp(command, "llShout(", 8))) 63 || (0 == strncmp(command, "llShout(", 8)))
48 { 64 {
49 int _P;
50// char *name = "that's me";
51
52 lua_getfield(ourGlobals->purkle->L, LUA_REGISTRYINDEX, ourGlobals->purkle->name);
53 _P = lua_gettop(ourGlobals->purkle->L);
54 65
55 sprintf(buf, "%s: %s", SID, command); 66 sprintf(buf, "%s: %s", SID, command);
56 push_lua(ourGlobals->purkle->L, "@ ( $ )", _P, "append", buf, 0); 67 if (ourGlobals->purkle)
57// push_lua(ourGlobals->purkle->L, "@ ( $ % $ $ $ )", _P, "say", _P, name, SID, buf, 0); 68 {
69 int _P;
70
71 lua_getfield(ourGlobals->purkle->L, LUA_REGISTRYINDEX, ourGlobals->purkle->name);
72 _P = lua_gettop(ourGlobals->purkle->L);
73 push_lua(ourGlobals->purkle->L, "@ ( $ )", _P, "append", buf, 0);
74 }
75 else
76 PW("No purkle to put - %s", buf);
58 } 77 }
59 else if (0 == strncmp(command, "llDialog(", 9)) 78 else if (0 == strncmp(command, "llDialog(", 9))
60 { 79 {
61 int _M; 80 if (ourGlobals->LSLGuiMess)
81 {
82 int _M;
62 83
63 lua_getfield(ourGlobals->LSLGuiMess->L, LUA_REGISTRYINDEX, ourGlobals->LSLGuiMess->name); 84 lua_getfield(ourGlobals->LSLGuiMess->L, LUA_REGISTRYINDEX, ourGlobals->LSLGuiMess->name);
64 _M = lua_gettop(ourGlobals->LSLGuiMess->L); 85 _M = lua_gettop(ourGlobals->LSLGuiMess->L);
65 86
66 // TODO - Somewhere in the chain the new lines that MLP likes to put into llDialog's message munge things. Fix that. 87 // TODO - Somewhere in the chain the new lines that MLP likes to put into llDialog's message munge things. Fix that.
67 push_lua(ourGlobals->LSLGuiMess->L, "@ ( $ )", _M, "doLua", command, 0); 88 push_lua(ourGlobals->LSLGuiMess->L, "@ ( $ )", _M, "doLua", command, 0);
89 }
90 else
91 PE("No LSLGuiMess to send - %s", command);
68 92
69 } 93 }
70 else 94 else
@@ -86,11 +110,16 @@ static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev)
86 110
87 if (ev->server) 111 if (ev->server)
88 { 112 {
89 ecore_con_server_del(ourGlobals->server); 113 ecore_con_server_del(ev->server);
90 ourGlobals->server = NULL; 114 ourGlobals->server = NULL;
115 if (ourGlobals->running)
116 {
117 PW("Server dropped out, trying to reconnect.");
118 ourGlobals->server = reachOut("127.0.0.1", 8211 + 1, ourGlobals, (Ecore_Event_Handler_Cb) _add, (Ecore_Event_Handler_Cb) _data, (Ecore_Event_Handler_Cb) _del);
119 }
91 } 120 }
92 121
93 return ECORE_CALLBACK_RENEW; 122 return ECORE_CALLBACK_CANCEL;
94} 123}
95 124
96static void _onWorldClick(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo) 125static void _onWorldClick(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
@@ -317,7 +346,7 @@ static Eina_Bool doFrame(void *data)
317 // Either way, _draw_gl gets called eventully. 346 // Either way, _draw_gl gets called eventully.
318 if (gld->elmGl) 347 if (gld->elmGl)
319 elm_glview_changed_set(gld->elmGl); 348 elm_glview_changed_set(gld->elmGl);
320 else if (ourGlobals->scene->image) 349 else if ((ourGlobals->scene) && (ourGlobals->scene->image))
321 { 350 {
322// evas_object_image_pixels_dirty_set(elm_image_object_get(ourGlobals->scene->image), EINA_TRUE); 351// evas_object_image_pixels_dirty_set(elm_image_object_get(ourGlobals->scene->image), EINA_TRUE);
323 _draw_gl(elm_image_object_get(ourGlobals->scene->image)); 352 _draw_gl(elm_image_object_get(ourGlobals->scene->image));
@@ -534,6 +563,7 @@ EAPI_MAIN int elm_main(int argc, char **argv)
534 fprintf(stdout, "locale directory is: %s\n", elm_app_locale_dir_get()); 563 fprintf(stdout, "locale directory is: %s\n", elm_app_locale_dir_get());
535 564
536 logDom = loggingStartup("extantz", logDom); 565 logDom = loggingStartup("extantz", logDom);
566 ourGlobals.running = 1;
537 567
538 // Add extras, so we can run test.lua later. 568 // Add extras, so we can run test.lua later.
539 env = getenv("LUA_CPATH"); 569 env = getenv("LUA_CPATH");
@@ -638,12 +668,6 @@ EAPI_MAIN int elm_main(int argc, char **argv)
638 668
639 init_evas_gl(&ourGlobals); 669 init_evas_gl(&ourGlobals);
640 670
641 Evas_3D_Demo_add(&ourGlobals);
642 // TODO - Just a temporary hack so Irrlicht and Evas_3D can share the camera move.
643 ourGlobals.gld.move = ourGlobals.scene->move;
644 evas_object_data_set(elm_image_object_get(ourGlobals.scene->image), "glob", &ourGlobals);
645 evas_object_image_pixels_get_callback_set(elm_image_object_get(ourGlobals.scene->image), on_pixels, &ourGlobals);
646
647 // Gotta do this after adding the windows, otherwise the menu renders under the window. 671 // Gotta do this after adding the windows, otherwise the menu renders under the window.
648 // This sucks, gotta redefine this menu each time we create a new window? 672 // This sucks, gotta redefine this menu each time we create a new window?
649 // Also, GL focus gets lost when any menu is used. sigh 673 // Also, GL focus gets lost when any menu is used. sigh
@@ -651,36 +675,24 @@ EAPI_MAIN int elm_main(int argc, char **argv)
651 675
652 ourGlobals.world = ephysicsAdd(&ourGlobals); 676 ourGlobals.world = ephysicsAdd(&ourGlobals);
653 677
654 // Try to connect to the love server we started before.
655 ourGlobals.address = "127.0.0.1";
656 ourGlobals.port = 8211;
657 sleep(2);
658 if ((ourGlobals.server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port + 1, &ourGlobals)))
659 {
660 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals);
661 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb) _data, &ourGlobals);
662 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb) _del, &ourGlobals);
663 serverStream = eina_strbuf_new();
664 }
665 else
666 PC("Failed to connect to server!");
667
668// overlay_add(&ourGlobals); 678// overlay_add(&ourGlobals);
669// GuiLuaLoad("test", ourGlobals.mainWindow, ourGlobals.world); 679// GuiLuaLoad("test", ourGlobals.mainWindow, ourGlobals.world);
670 woMan_add(&ourGlobals); 680 woMan_add(&ourGlobals);
671 ourGlobals.LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals.mainWindow, ourGlobals.server, ourGlobals.world); 681 ourGlobals.purkle = GuiLuaLoad("purkle", ourGlobals.mainWindow, ourGlobals.world);
672 ourGlobals.purkle = GuiLuaLoad("purkle", ourGlobals.mainWindow, ourGlobals.server, ourGlobals.world); 682 ourGlobals.LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals.mainWindow, ourGlobals.world);
673 ourGlobals.files = filesAdd(&ourGlobals, (char *) elm_app_data_dir_get(), EINA_TRUE, EINA_FALSE); 683 ourGlobals.files = filesAdd(&ourGlobals, (char *) elm_app_data_dir_get(), EINA_TRUE, EINA_FALSE);
674 684
685 // Try to connect to the love server we started before.
686 serverStream = eina_strbuf_new();
687 reachOut("127.0.0.1", 8211 + 1, &ourGlobals, (Ecore_Event_Handler_Cb) _add, (Ecore_Event_Handler_Cb) _data, (Ecore_Event_Handler_Cb) _del);
688
675 // Bump the top toolbar above the windows. 689 // Bump the top toolbar above the windows.
676 evas_object_raise(ourGlobals.tb); 690 evas_object_raise(ourGlobals.tb);
677 691
678 _on_resize(&ourGlobals, NULL, NULL, NULL); 692 _on_resize(&ourGlobals, NULL, NULL, NULL);
679 693
680 // Setup our callback for clicking in world.
681 ourGlobals.scene->clickCb = _onWorldClick;
682
683 elm_run(); 694 elm_run();
695 ourGlobals.running = 0;
684 696
685 ephysics_world_del(ourGlobals.world); 697 ephysics_world_del(ourGlobals.world);
686 ephysics_shutdown(); 698 ephysics_shutdown();
diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h
index 9a8f2bf..d77c764 100644
--- a/src/extantz/extantz.h
+++ b/src/extantz/extantz.h
@@ -220,6 +220,7 @@ typedef struct _globals
220 int scr_w, scr_h; // The size of the screen. 220 int scr_w, scr_h; // The size of the screen.
221 int win_w, win_h; // The size of the window. 221 int win_w, win_h; // The size of the window.
222 int win_x, win_y; // The position of the window. 222 int win_x, win_y; // The position of the window.
223 int running : 1;
223 224
224 Ecore_Animator *animator; 225 Ecore_Animator *animator;
225 226
@@ -233,8 +234,6 @@ typedef struct _globals
233 GuiLua *LSLGuiMess; 234 GuiLua *LSLGuiMess;
234 235
235 Ecore_Con_Server *server; 236 Ecore_Con_Server *server;
236 const char *address;
237 int port;
238 237
239} globals; 238} globals;
240 239
diff --git a/src/purkle/purkle.c b/src/purkle/purkle.c
index 6770ff4..9cafe01 100644
--- a/src/purkle/purkle.c
+++ b/src/purkle/purkle.c
@@ -1,4 +1,3 @@
1//#include "LumbrJack.h"
2#include "GuiLua.h" 1#include "GuiLua.h"
3#include "Runnr.h" 2#include "Runnr.h"
4#include "SledjHamr.h" 3#include "SledjHamr.h"
@@ -8,7 +7,6 @@ static const char *ourName = "purkle";
8static int skang, _M; 7static int skang, _M;
9static Widget *entry, *history; 8static Widget *entry, *history;
10static winFang *me; 9static winFang *me;
11static Ecore_Con_Server *server;
12 10
13static winFang *purkleAdd(winFang *parent, int w, int h, EPhysics_World *world) 11static winFang *purkleAdd(winFang *parent, int w, int h, EPhysics_World *world)
14{ 12{
@@ -60,7 +58,16 @@ static int say(lua_State *L)
60 pull_lua(L, 1, "%channel $name $id $text", &channel, &name, &id, &text); 58 pull_lua(L, 1, "%channel $name $id $text", &channel, &name, &id, &text);
61 if (id && text) 59 if (id && text)
62 { 60 {
61 GuiLua *gl;
62 Ecore_Con_Server *server = NULL;
63
63 snprintf(buf, sizeof(buf), "events.listen(%d, '%s', '%s', '%s')", channel, name, id, text); 64 snprintf(buf, sizeof(buf), "events.listen(%d, '%s', '%s', '%s')", channel, name, id, text);
65 // We do this rather than caching it, coz the server might change out from under us.
66 lua_getfield(L, LUA_REGISTRYINDEX, glName);
67 gl = lua_touserdata(L, -1);
68 lua_pop(L, 1);
69 if (gl)
70 server = gl->server;
64 if (server) 71 if (server)
65 sendForth(server, id, buf); 72 sendForth(server, id, buf);
66 else 73 else
@@ -97,7 +104,6 @@ int luaopen_purkle(lua_State *L)
97 { 104 {
98 parent = gl->parent; 105 parent = gl->parent;
99 world = gl->world; 106 world = gl->world;
100 server = gl->server;
101 } 107 }
102 108
103 if (!me) me = purkleAdd(parent, 500, 420, world); 109 if (!me) me = purkleAdd(parent, 500, 420, world);