From dcd11c8d2b399ce1309637bd756c680db0aec1af Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 17 May 2014 10:54:52 +1000 Subject: Use the new server connector, and some related movements. --- src/GuiLua/GuiLua.c | 7 ++-- src/GuiLua/GuiLua.h | 4 +-- src/GuiLua/skang.c | 2 +- src/extantz/extantz.c | 92 +++++++++++++++++++++++++++++---------------------- src/extantz/extantz.h | 3 +- src/purkle/purkle.c | 12 +++++-- 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"); return 1; } -GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, Ecore_Con_Server *server, EPhysics_World *world) +GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, EPhysics_World *world) { GuiLua *result; lua_State *L; @@ -379,7 +379,6 @@ GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, Ecore_Con_Server *serve result = calloc(1, sizeof(GuiLua)); result->parent = parent; - result->server = server; result->world = world; L = luaL_newstate(); @@ -434,13 +433,13 @@ GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, Ecore_Con_Server *serve return result; } -GuiLua *GuiLuaLoad(char *module, winFang *parent, Ecore_Con_Server *server, EPhysics_World *world) +GuiLua *GuiLuaLoad(char *module, winFang *parent, EPhysics_World *world) { GuiLua *result; char *args[] = {"GuiLUa", "-l", ""}; args[2] = module; - result = GuiLuaDo(3, args, parent, server, world); + result = GuiLuaDo(3, args, parent, world); result->name = module; return result; } 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 extern const char *glName; -GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, Ecore_Con_Server *server, EPhysics_World *world); -GuiLua *GuiLuaLoad(char *module, winFang *parent, Ecore_Con_Server *server, EPhysics_World *world); +GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, EPhysics_World *world); +GuiLua *GuiLuaLoad(char *module, winFang *parent, EPhysics_World *world); void GuiLuaDel(GuiLua *gl); #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 @@ EAPI_MAIN int elm_main(int argc, char **argv) { HamrTime(elm_main, "GuiLua"); - GuiLuaDo(argc, argv, NULL, NULL, NULL); + GuiLuaDo(argc, argv, NULL, NULL); return 0; } 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 @@ #include "LumbrJack.h" +static void _onWorldClick(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo); +static void on_pixels(void *data, Evas_Object *obj); + + static int logDom; // Our logging domain. globals ourGlobals; static Eina_Strbuf *serverStream; @@ -15,7 +19,19 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev) { globals *ourGlobals = data; + PI("Server connected."); ourGlobals->server = ev->server; + if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server; + if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server; + + Evas_3D_Demo_add(ourGlobals); + // TODO - Just a temporary hack so Irrlicht and Evas_3D can share the camera move. + ourGlobals->gld.move = ourGlobals->scene->move; + evas_object_data_set(elm_image_object_get(ourGlobals->scene->image), "glob", ourGlobals); + evas_object_image_pixels_get_callback_set(elm_image_object_get(ourGlobals->scene->image), on_pixels, ourGlobals); + // Setup our callback for clicking in world. + ourGlobals->scene->clickCb = _onWorldClick; + return ECORE_CALLBACK_RENEW; } @@ -46,25 +62,33 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev) || (0 == strncmp(command, "llSay(", 6)) || (0 == strncmp(command, "llShout(", 8))) { - int _P; -// char *name = "that's me"; - - lua_getfield(ourGlobals->purkle->L, LUA_REGISTRYINDEX, ourGlobals->purkle->name); - _P = lua_gettop(ourGlobals->purkle->L); sprintf(buf, "%s: %s", SID, command); - push_lua(ourGlobals->purkle->L, "@ ( $ )", _P, "append", buf, 0); -// push_lua(ourGlobals->purkle->L, "@ ( $ % $ $ $ )", _P, "say", _P, name, SID, buf, 0); + if (ourGlobals->purkle) + { + int _P; + + lua_getfield(ourGlobals->purkle->L, LUA_REGISTRYINDEX, ourGlobals->purkle->name); + _P = lua_gettop(ourGlobals->purkle->L); + push_lua(ourGlobals->purkle->L, "@ ( $ )", _P, "append", buf, 0); + } + else + PW("No purkle to put - %s", buf); } else if (0 == strncmp(command, "llDialog(", 9)) { - int _M; + if (ourGlobals->LSLGuiMess) + { + int _M; - lua_getfield(ourGlobals->LSLGuiMess->L, LUA_REGISTRYINDEX, ourGlobals->LSLGuiMess->name); - _M = lua_gettop(ourGlobals->LSLGuiMess->L); + lua_getfield(ourGlobals->LSLGuiMess->L, LUA_REGISTRYINDEX, ourGlobals->LSLGuiMess->name); + _M = lua_gettop(ourGlobals->LSLGuiMess->L); - // TODO - Somewhere in the chain the new lines that MLP likes to put into llDialog's message munge things. Fix that. - push_lua(ourGlobals->LSLGuiMess->L, "@ ( $ )", _M, "doLua", command, 0); + // TODO - Somewhere in the chain the new lines that MLP likes to put into llDialog's message munge things. Fix that. + push_lua(ourGlobals->LSLGuiMess->L, "@ ( $ )", _M, "doLua", command, 0); + } + else + PE("No LSLGuiMess to send - %s", command); } else @@ -86,11 +110,16 @@ static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) if (ev->server) { - ecore_con_server_del(ourGlobals->server); + ecore_con_server_del(ev->server); ourGlobals->server = NULL; + if (ourGlobals->running) + { + PW("Server dropped out, trying to reconnect."); + 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); + } } - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_CANCEL; } static void _onWorldClick(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo) @@ -317,7 +346,7 @@ static Eina_Bool doFrame(void *data) // Either way, _draw_gl gets called eventully. if (gld->elmGl) elm_glview_changed_set(gld->elmGl); - else if (ourGlobals->scene->image) + else if ((ourGlobals->scene) && (ourGlobals->scene->image)) { // evas_object_image_pixels_dirty_set(elm_image_object_get(ourGlobals->scene->image), EINA_TRUE); _draw_gl(elm_image_object_get(ourGlobals->scene->image)); @@ -534,6 +563,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) fprintf(stdout, "locale directory is: %s\n", elm_app_locale_dir_get()); logDom = loggingStartup("extantz", logDom); + ourGlobals.running = 1; // Add extras, so we can run test.lua later. env = getenv("LUA_CPATH"); @@ -638,12 +668,6 @@ EAPI_MAIN int elm_main(int argc, char **argv) init_evas_gl(&ourGlobals); - Evas_3D_Demo_add(&ourGlobals); - // TODO - Just a temporary hack so Irrlicht and Evas_3D can share the camera move. - ourGlobals.gld.move = ourGlobals.scene->move; - evas_object_data_set(elm_image_object_get(ourGlobals.scene->image), "glob", &ourGlobals); - evas_object_image_pixels_get_callback_set(elm_image_object_get(ourGlobals.scene->image), on_pixels, &ourGlobals); - // Gotta do this after adding the windows, otherwise the menu renders under the window. // This sucks, gotta redefine this menu each time we create a new window? // Also, GL focus gets lost when any menu is used. sigh @@ -651,36 +675,24 @@ EAPI_MAIN int elm_main(int argc, char **argv) ourGlobals.world = ephysicsAdd(&ourGlobals); - // Try to connect to the love server we started before. - ourGlobals.address = "127.0.0.1"; - ourGlobals.port = 8211; - sleep(2); - if ((ourGlobals.server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port + 1, &ourGlobals))) - { - ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals); - ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb) _data, &ourGlobals); - ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb) _del, &ourGlobals); - serverStream = eina_strbuf_new(); - } - else - PC("Failed to connect to server!"); - // overlay_add(&ourGlobals); // GuiLuaLoad("test", ourGlobals.mainWindow, ourGlobals.world); woMan_add(&ourGlobals); - ourGlobals.LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals.mainWindow, ourGlobals.server, ourGlobals.world); - ourGlobals.purkle = GuiLuaLoad("purkle", ourGlobals.mainWindow, ourGlobals.server, ourGlobals.world); + ourGlobals.purkle = GuiLuaLoad("purkle", ourGlobals.mainWindow, ourGlobals.world); + ourGlobals.LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals.mainWindow, ourGlobals.world); ourGlobals.files = filesAdd(&ourGlobals, (char *) elm_app_data_dir_get(), EINA_TRUE, EINA_FALSE); + // Try to connect to the love server we started before. + serverStream = eina_strbuf_new(); + reachOut("127.0.0.1", 8211 + 1, &ourGlobals, (Ecore_Event_Handler_Cb) _add, (Ecore_Event_Handler_Cb) _data, (Ecore_Event_Handler_Cb) _del); + // Bump the top toolbar above the windows. evas_object_raise(ourGlobals.tb); _on_resize(&ourGlobals, NULL, NULL, NULL); - // Setup our callback for clicking in world. - ourGlobals.scene->clickCb = _onWorldClick; - elm_run(); + ourGlobals.running = 0; ephysics_world_del(ourGlobals.world); 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 int scr_w, scr_h; // The size of the screen. int win_w, win_h; // The size of the window. int win_x, win_y; // The position of the window. + int running : 1; Ecore_Animator *animator; @@ -233,8 +234,6 @@ typedef struct _globals GuiLua *LSLGuiMess; Ecore_Con_Server *server; - const char *address; - int port; } globals; 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 @@ -//#include "LumbrJack.h" #include "GuiLua.h" #include "Runnr.h" #include "SledjHamr.h" @@ -8,7 +7,6 @@ static const char *ourName = "purkle"; static int skang, _M; static Widget *entry, *history; static winFang *me; -static Ecore_Con_Server *server; static winFang *purkleAdd(winFang *parent, int w, int h, EPhysics_World *world) { @@ -60,7 +58,16 @@ static int say(lua_State *L) pull_lua(L, 1, "%channel $name $id $text", &channel, &name, &id, &text); if (id && text) { + GuiLua *gl; + Ecore_Con_Server *server = NULL; + snprintf(buf, sizeof(buf), "events.listen(%d, '%s', '%s', '%s')", channel, name, id, text); + // We do this rather than caching it, coz the server might change out from under us. + lua_getfield(L, LUA_REGISTRYINDEX, glName); + gl = lua_touserdata(L, -1); + lua_pop(L, 1); + if (gl) + server = gl->server; if (server) sendForth(server, id, buf); else @@ -97,7 +104,6 @@ int luaopen_purkle(lua_State *L) { parent = gl->parent; world = gl->world; - server = gl->server; } if (!me) me = purkleAdd(parent, 500, 420, world); -- cgit v1.1