aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LuaSL_main.c')
-rw-r--r--LuaSL/src/LuaSL_main.c329
1 files changed, 81 insertions, 248 deletions
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c
index d6485df..621aad2 100644
--- a/LuaSL/src/LuaSL_main.c
+++ b/LuaSL/src/LuaSL_main.c
@@ -2,295 +2,128 @@
2#include "LuaSL.h" 2#include "LuaSL.h"
3 3
4 4
5static int scriptCount; 5Eina_Strbuf *clientStream;
6
7static const char *names[] =
8{
9 "bub1", "sh1",
10 "bub2", "sh2",
11 "bub3", "sh3",
12};
13 6
14 7
15static void 8Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev)
16_edje_signal_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source)
17{ 9{
18// gameGlobals *game = data; 10 ecore_con_client_timeout_set(ev->client, 0);
11 return ECORE_CALLBACK_RENEW;
19} 12}
20 13
21static 14Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Del *ev)
22Eina_Bool anim(void *data)
23{ 15{
24 gameGlobals *game = data; 16 gameGlobals *game = data;
25 Evas_Object *bub, *sh;
26 Evas_Coord x, y, w, h, vw, vh;
27 double t, xx, yy, zz, r, fac;
28 double lx, ly;
29 unsigned int i;
30 17
31 evas_output_viewport_get(game->canvas, 0, 0, &vw, &vh); 18 if (ev->client)
32 r = 48;
33 t = ecore_loop_time_get();
34 fac = 2.0 / (double)((sizeof(names) / sizeof(char *) / 2));
35 evas_pointer_canvas_xy_get(game->canvas, &x, &y);
36 lx = x;
37 ly = y;
38
39 for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++)
40 { 19 {
41 bub = evas_object_data_get(game->bg, names[i * 2]); 20 PD("No more clients, exiting.");
42 sh = evas_object_data_get(game->bg, names[(i * 2) + 1]); 21 ecore_con_client_del(ev->client);
43 zz = (((2 + sin(t * 6 + (M_PI * (i * fac)))) / 3) * 64) * 2; 22 ecore_main_loop_quit();
44 xx = (cos(t * 4 + (M_PI * (i * fac))) * r) * 2;
45 yy = (sin(t * 6 + (M_PI * (i * fac))) * r) * 2;
46
47 w = zz;
48 h = zz;
49 x = (vw / 2) + xx - (w / 2);
50 y = (vh / 2) + yy - (h / 2);
51
52 evas_object_move(bub, x, y);
53 evas_object_resize(bub, w, h);
54
55 x = x - ((lx - (x + (w / 2))) / 4);
56 y = y - ((ly - (y + (h / 2))) / 4);
57
58 evas_object_move(sh, x, y);
59 evas_object_resize(sh, w, h);
60 evas_object_raise(sh);
61 evas_object_raise(bub);
62 } 23 }
63 return ECORE_CALLBACK_RENEW; 24 return ECORE_CALLBACK_RENEW;
64} 25}
65 26
66static void 27Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Data *ev)
67_on_delete(Ecore_Evas *ee __UNUSED__)
68{
69 ecore_main_loop_quit();
70}
71
72static void dirList_compile(const char *name, const char *path, void *data)
73{ 28{
74 gameGlobals *game = data; 29 gameGlobals *game = data;
75 char buf[PATH_MAX]; 30 char SID[PATH_MAX];
76 char *ext = rindex(name, '.'); 31 const char *command;
32 char *ext;
77 33
78 if (ext) 34 eina_strbuf_append_length(clientStream, ev->data, ev->size);
35 command = eina_strbuf_string_get(clientStream);
36 while ((ext = index(command, '\n')))
79 { 37 {
80 if ((!LUASL_DEBUG) || (0 == scriptCount)) 38 int length = ext - command;
39
40 strncpy(SID, command, length + 1);
41 SID[length] = '\0';
42 eina_strbuf_remove(clientStream, 0, length + 1);
43 ext = rindex(SID, '.');
44 if (ext)
81 { 45 {
82 if (0 == strcmp(ext, ".lsl")) 46 ext[0] = '\0';
47 command = ext + 1;
48 if (0 == strcmp(command, "compile()"))
83 { 49 {
84 scriptCount++; 50 if (compileLSL(game, SID, FALSE))
85 snprintf(buf, sizeof(buf), "%s/%s", path, name); 51 PD("The compile of %s worked.", SID);
86 if (compileLSL(game, buf, FALSE))
87 PD("The compile of %s worked,", buf);
88 else 52 else
89 PE("The compile of %s failed!", buf); 53 PE("The compile of %s failed!", SID);
90 } 54 }
91 } 55 else if (0 == strcmp(command, "start()"))
92 } 56 {
93} 57 runLuaFile(game, SID);
94 58 }
95static void dirList_run(const char *name, const char *path, void *data) 59 else if (0 == strcmp(command, "exit()"))
96{ 60 {
97 gameGlobals *game = data; 61 PD("Told to exit.");
98 char buf[PATH_MAX]; 62 ecore_main_loop_quit();
99 char *ext = rindex(name, '.'); 63 }
64 else
65 {
66 char temp[PATH_MAX];
67 const char *status = NULL;
100 68
101 if (ext) 69 snprintf(temp, sizeof(temp), "%s.events", SID);
102 { 70 status = sendToChannel(temp, command, NULL, NULL);
103 if (0 == strcmp(ext, ".out")) 71 if (status)
104 { 72 PE("Error sending command %s to script %s : %s", command, temp, status);
105 snprintf(buf, sizeof(buf), "%s/%s", path, name); 73 }
106// PD("Running Lua script %s", buf);
107 runLuaFile(game, buf);
108 } 74 }
109 }
110}
111 75
112static void dirList_quit(const char *name, const char *path, void *data) 76 // Get the next blob to check it.
113{ 77 command = eina_strbuf_string_get(clientStream);
114 gameGlobals *game = data;
115 char buf[PATH_MAX];
116 char *ext = rindex(name, '.');
117
118 if (ext)
119 {
120 if (0 == strcmp(ext, ".out"))
121 {
122 const char *status = NULL;
123
124 snprintf(buf, sizeof(buf), "%s/%s.events", path, name);
125// PD("Quitting Lua script %s", buf);
126 status = sendToChannel(buf, "quit()", NULL, NULL);
127 if (status)
128 PE("Error trying to kill script %s : %s", buf, status);
129 }
130 } 78 }
79
80 return ECORE_CALLBACK_RENEW;
131} 81}
132 82
133int 83int main(int argc, char **argv)
134main(int argc, char **argv)
135{ 84{
136 /* put here any init specific to this app like parsing args etc. */
137 gameGlobals game; 85 gameGlobals game;
138 char *programName = argv[0]; 86 int result = EXIT_FAILURE;
139 boolean badArgs = FALSE;
140
141 if (!ecore_evas_init())
142 return EXIT_FAILURE;
143
144 if (!edje_init())
145 {
146 ecore_evas_shutdown();
147 return EXIT_FAILURE;
148 }
149 87
150 memset(&game, 0, sizeof(gameGlobals)); 88 memset(&game, 0, sizeof(gameGlobals));
89 game.address = "127.0.01";
90 game.port = 8211;
151 91
152 loggingStartup(&game); 92 if (eina_init())
153
154 // get the arguments passed in
155 while (--argc > 0 && *++argv != '\0')
156 { 93 {
157 if (*argv[0] == '-') 94 loggingStartup(&game);
95 if (ecore_con_init())
158 { 96 {
159 // point to the characters after the '-' sign 97 if ((game.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, game.address, game.port, &game)))
160 char *s = argv[0] + 1;
161
162 switch (*s)
163 { 98 {
164 case 'u': 99 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) _add, &game);
100 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _del, &game);
101 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb) _data, &game);
102 ecore_con_server_timeout_set(game.server, 0);
103 ecore_con_server_client_limit_set(game.server, -1, 0);
104 clientStream = eina_strbuf_new();
105
106 if (edje_init())
165 { 107 {
166 game.ui = TRUE; 108 result = 0;
167 break; 109 compilerSetup(&game);
110 runnerSetup(&game);
111 ecore_main_loop_begin();
112 runnerTearDown(&game);
113 edje_shutdown();
168 } 114 }
169 default: 115 else
170 badArgs = TRUE; 116 PCm("Failed to init edje!");
171 } 117 }
118 else
119 PCm("Failed to add server!");
120 ecore_con_shutdown();
172 } 121 }
173 else 122 else
174 badArgs = TRUE; 123 PCm("Failed to init ecore_con!");
175 }
176
177
178 if (badArgs)
179 {
180 // display the program usage to the user as they have it wrong
181 printf("Usage: %s [-u]\n", programName);
182 printf(" -u: Show the test UI.\n");
183 } 124 }
184 else 125 else
185// else if ((game.config) && (game.data)) 126 fprintf(stderr, "Failed to init eina!");
186 {
187 unsigned int i;
188 Evas_Object *bub, *sh;
189 Ecore_Animator *ani;
190 char *group = "main";
191 char buf[PATH_MAX];
192 struct timeval lastTime2;
193 struct timeval thisTime2;
194 float diff;
195
196 if (game.ui)
197 {
198 /* this will give you a window with an Evas canvas under the first engine available */
199 game.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
200 if (!game.ee)
201 {
202 PEm("You got to have at least one evas engine built and linked up to ecore-evas for this example to run properly.");
203 edje_shutdown();
204 ecore_evas_shutdown();
205 return -1;
206 }
207 game.canvas = ecore_evas_get(game.ee);
208 ecore_evas_title_set(game.ee, "LuaSL test harness");
209 ecore_evas_show(game.ee);
210
211 game.bg = evas_object_rectangle_add(game.canvas);
212 evas_object_color_set(game.bg, 255, 255, 255, 255); /* white bg */
213 evas_object_move(game.bg, 0, 0); /* at canvas' origin */
214 evas_object_size_hint_weight_set(game.bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
215 evas_object_resize(game.bg, WIDTH, HEIGHT); /* covers full canvas */
216 evas_object_show(game.bg);
217 ecore_evas_object_associate(game.ee, game.bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
218 evas_object_focus_set(game.bg, EINA_TRUE);
219
220 game.edje = edje_object_add(game.canvas);
221 snprintf(buf, sizeof(buf), "%s/%s.edj", PACKAGE_DATA_DIR, "LuaSL");
222 if (!edje_object_file_set(game.edje, buf, group))
223 {
224 int err = edje_object_load_error_get(game.edje);
225 const char *errmsg = edje_load_error_str(err);
226 PEm("Could not load '%s' from %s: %s\n", group, buf, errmsg);
227
228 evas_object_del(game.edje);
229 ecore_evas_free(game.ee);
230 edje_shutdown();
231 ecore_evas_shutdown();
232 return -2;
233 }
234 evas_object_move(game.edje, 0, 0);
235 evas_object_resize(game.edje, WIDTH, HEIGHT);
236 evas_object_show(game.edje);
237
238 snprintf(buf, sizeof(buf), "%s/images/bubble_sh.png", PACKAGE_DATA_DIR);
239 for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++)
240 {
241 sh = evas_object_image_filled_add(game.canvas);
242 evas_object_image_file_set(sh, buf, NULL);
243 evas_object_resize(sh, 64, 64);
244 evas_object_show(sh);
245 evas_object_data_set(game.bg, names[(i * 2) + 1], sh);
246 }
247
248 snprintf(buf, sizeof(buf), "%s/images/bubble.png", PACKAGE_DATA_DIR);
249 for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++)
250 {
251 bub = evas_object_image_filled_add(game.canvas);
252 evas_object_image_file_set(bub, buf, NULL);
253 evas_object_resize(bub, 64, 64);
254 evas_object_show(bub);
255 evas_object_data_set(game.bg, names[(i * 2)], bub);
256 }
257 ani = ecore_animator_add(anim, &game);
258 evas_object_data_set(game.bg, "animator", ani);
259
260 // Setup our callbacks.
261 ecore_evas_callback_delete_request_set(game.ee, _on_delete);
262 edje_object_signal_callback_add(game.edje, "*", "game_*", _edje_signal_cb, &game);
263 }
264
265 // Do the compiles.
266 scriptCount = 0;
267 compilerSetup(&game);
268 runnerSetup(&game);
269 gettimeofday(&lastTime2, 0);
270 snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR);
271 eina_file_dir_list(buf, EINA_TRUE, dirList_compile, &game);
272 diff = timeDiff(&thisTime2, &lastTime2);
273 printf("Compiling %d LSL scripts took %f seconds, that's %f scripts per second.\n", scriptCount, diff, scriptCount / diff);
274 eina_file_dir_list(buf, EINA_TRUE, dirList_run, &game);
275
276 if (game.ui)
277 {
278 ecore_main_loop_begin();
279 ecore_animator_del(ani);
280 ecore_evas_free(game.ee);
281 }
282 else
283 {
284 // Wait awhile, then quit all scripts we started, for testing.
285 sleep(2);
286 snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR);
287 eina_file_dir_list(buf, EINA_TRUE, dirList_quit, &game);
288 }
289
290 runnerTearDown(&game);
291 edje_shutdown();
292 ecore_evas_shutdown();
293 }
294 127
295 return 0; 128 return result;
296} 129}