aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/LuaSL_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/LuaSL_test.c')
-rw-r--r--LuaSL/LuaSL_test.c467
1 files changed, 0 insertions, 467 deletions
diff --git a/LuaSL/LuaSL_test.c b/LuaSL/LuaSL_test.c
deleted file mode 100644
index 58d6225..0000000
--- a/LuaSL/LuaSL_test.c
+++ /dev/null
@@ -1,467 +0,0 @@
1
2#include "LuaSL.h"
3
4
5static Eina_Strbuf *clientStream;
6static int scriptCount = 0;
7static int compiledCount = 0;
8static float compileTime = 0.0;
9static struct timeval startTime;
10static int timedEvent = 0;
11static char *ownerKey = "12345678-1234-4321-abcd-0123456789ab";
12static char *ownerName = "onefang rejected";
13
14static const char *names[] =
15{
16 "bub1", "sh1",
17 "bub2", "sh2",
18 "bub3", "sh3",
19};
20
21
22static void
23_edje_signal_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source)
24{
25// gameGlobals *ourGlobals = data;
26}
27
28static
29Eina_Bool anim(void *data)
30{
31 gameGlobals *ourGlobals = data;
32 Evas_Object *bub, *sh;
33 Evas_Coord x, y, w, h, vw, vh;
34 double t, xx, yy, zz, r, fac;
35 double lx, ly;
36 unsigned int i;
37
38 evas_output_viewport_get(ourGlobals->canvas, 0, 0, &vw, &vh);
39 r = 48;
40 t = ecore_loop_time_get();
41 fac = 2.0 / (double)((sizeof(names) / sizeof(char *) / 2));
42 evas_pointer_canvas_xy_get(ourGlobals->canvas, &x, &y);
43 lx = x;
44 ly = y;
45
46 for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++)
47 {
48 bub = evas_object_data_get(ourGlobals->bg, names[i * 2]);
49 sh = evas_object_data_get(ourGlobals->bg, names[(i * 2) + 1]);
50 zz = (((2 + sin(t * 6 + (M_PI * (i * fac)))) / 3) * 64) * 2;
51 xx = (cos(t * 4 + (M_PI * (i * fac))) * r) * 2;
52 yy = (sin(t * 6 + (M_PI * (i * fac))) * r) * 2;
53
54 w = zz;
55 h = zz;
56 x = (vw / 2) + xx - (w / 2);
57 y = (vh / 2) + yy - (h / 2);
58
59 evas_object_move(bub, x, y);
60 evas_object_resize(bub, w, h);
61
62 x = x - ((lx - (x + (w / 2))) / 4);
63 y = y - ((ly - (y + (h / 2))) / 4);
64
65 evas_object_move(sh, x, y);
66 evas_object_resize(sh, w, h);
67 evas_object_raise(sh);
68 evas_object_raise(bub);
69 }
70 return ECORE_CALLBACK_RENEW;
71}
72
73static void
74_on_delete(Ecore_Evas *ee __UNUSED__)
75{
76 ecore_main_loop_quit();
77}
78
79static void dirList_compile(const char *name, const char *path, void *data)
80{
81 gameGlobals *ourGlobals = data;
82
83 char *ext = rindex(name, '.');
84
85 if (ext)
86 {
87 if (0 == strcmp(ext, ".lsl"))
88 {
89 script *me = calloc(1, sizeof(script));
90
91 scriptCount++;
92 gettimeofday(&me->startTime, NULL);
93 snprintf(me->SID, sizeof(me->SID), "%08lx-%04lx-%04lx-%04lx-%012lx", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random());
94 snprintf(me->fileName, sizeof(me->fileName), "%s/%s", path, name);
95 eina_hash_add(ourGlobals->scripts, me->SID, me);
96 sendForth(ourGlobals, me->SID, "compile(%s)", me->fileName);
97 }
98 }
99}
100
101static Eina_Bool _timer_cb(void *data)
102{
103 gameGlobals *ourGlobals = data;
104 Eina_Iterator *scripts;
105 script *me;
106 boolean exit = FALSE;
107
108 scripts = eina_hash_iterator_data_new(ourGlobals->scripts);
109 while(eina_iterator_next(scripts, (void **) &me))
110 {
111 switch (timedEvent)
112 {
113 case 5 :
114 {
115 sendForth(ourGlobals, me->SID, "events.detectedKeys({\"%s\"})", ownerKey);
116 sendForth(ourGlobals, me->SID, "events.detectedNames({\"%s\"})", ownerName);
117 sendForth(ourGlobals, me->SID, "events.touch_start(1)");
118 break;
119 }
120 case 9 :
121 {
122 sendForth(ourGlobals, me->SID, "quit()");
123 break;
124 }
125 case 11 :
126 {
127 exit = TRUE;
128 break;
129 }
130 }
131 }
132 timedEvent++;
133
134 if (exit)
135 {
136 sendForth(ourGlobals, ownerKey, "exit()");
137 ecore_main_loop_quit();
138 return ECORE_CALLBACK_CANCEL;
139 }
140 return ECORE_CALLBACK_RENEW;
141}
142
143static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Server_Add *ev)
144{
145 gameGlobals *ourGlobals = data;
146 char buf[PATH_MAX];
147
148 ourGlobals->server = ev->server;
149 gettimeofday(&startTime, NULL);
150 snprintf(buf, sizeof(buf), "%s/media/Test sim/objects", PACKAGE_DATA_DIR);
151 eina_file_dir_list(buf, EINA_TRUE, dirList_compile, ourGlobals);
152 // Wait awhile, then start sending events for testing.
153 ecore_timer_add(0.5, _timer_cb, ourGlobals);
154 return ECORE_CALLBACK_RENEW;
155}
156
157static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_Data *ev)
158{
159 gameGlobals *ourGlobals = data;
160
161 char buf[PATH_MAX];
162 char SID[PATH_MAX];
163 const char *command;
164 char *ext;
165
166 eina_strbuf_append_length(clientStream, ev->data, ev->size);
167 command = eina_strbuf_string_get(clientStream);
168 while ((ext = index(command, '\n')))
169 {
170 int length = ext - command;
171
172 strncpy(SID, command, length + 1);
173 SID[length] = '\0';
174 eina_strbuf_remove(clientStream, 0, length + 1);
175 ext = index(SID, '.');
176 if (ext)
177 {
178 script *me;
179
180 ext[0] = '\0';
181 command = ext + 1;
182 me = eina_hash_find(ourGlobals->scripts, SID);
183 if (0 == strncmp(command, "compilerWarning(", 16))
184 {
185 char *temp;
186 char *line;
187 char *column;
188 char *text;
189
190 strcpy(buf, &command[16]);
191 temp = buf;
192 line = temp;
193 while (',' != temp[0])
194 temp++;
195 temp[0] = '\0';
196 column = ++temp;
197 while (',' != temp[0])
198 temp++;
199 temp[0] = '\0';
200 text = ++temp;
201 while (')' != temp[0])
202 temp++;
203 temp[0] = '\0';
204 PW("%s @ line %s, column %s.", text, line, column);
205 if (me)
206 me->warnings++;
207 }
208 else if (0 == strncmp(command, "compilerError(", 14))
209 {
210 char *temp;
211 char *line;
212 char *column;
213 char *text;
214
215 strcpy(buf, &command[14]);
216 temp = buf;
217 line = temp;
218 while (',' != temp[0])
219 temp++;
220 temp[0] = '\0';
221 column = ++temp;
222 while (',' != temp[0])
223 temp++;
224 temp[0] = '\0';
225 text = ++temp;
226 while (')' != temp[0])
227 temp++;
228 temp[0] = '\0';
229 PE("%s @ line %s, column %s.", text, line, column);
230 if (me)
231 me->bugs++;
232 }
233 else if (0 == strcmp(command, "compiled(false)"))
234 PE("The compile of %s failed!", SID);
235 else if (0 == strcmp(command, "compiled(true)"))
236 {
237 if (me)
238 {
239 struct timeval now;
240
241 me->compileTime = timeDiff(&now, &me->startTime);
242 me->running = TRUE;
243 compiledCount++;
244 compileTime += me->compileTime;
245// PD("Average compile speed is %f scripts per second", compiledCount / compileTime);
246 if (compiledCount == scriptCount)
247 PD("TOTAL compile speed is %f scripts per second", compiledCount / timeDiff(&now, &startTime));
248 }
249// PD("The compile of %s worked, running it now.", SID);
250 sendForth(ourGlobals, SID, "run()");
251 }
252 else
253 {
254 // Send back some random or fixed values for testing.
255 if (0 == strcmp(command, "llGetKey()"))
256 sendForth(ourGlobals, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random());
257 else if (0 == strcmp(command, "llGetOwner()"))
258 sendForth(ourGlobals, SID, "return \"%s\"", ownerKey);
259 else if (0 == strcmp(command, "llGetPos()"))
260 sendForth(ourGlobals, SID, "return {x=128.0, y=128.0, z=128.0}");
261 else if (0 == strcmp(command, "llGetRot()"))
262 sendForth(ourGlobals, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}");
263 else if (0 == strcmp(command, "llGetObjectDesc()"))
264 sendForth(ourGlobals, SID, "return \"\"");
265 else if (0 == strncmp(command, "llGetAlpha(", 11))
266 sendForth(ourGlobals, SID, "return 1.0");
267 else if (0 == strcmp(command, "llGetInventoryNumber(7)"))
268 sendForth(ourGlobals, SID, "return 3");
269 else if (0 == strcmp(command, "llGetInventoryName(7, 2)"))
270 sendForth(ourGlobals, SID, "return \".readme\"");
271 else if (0 == strcmp(command, "llGetInventoryName(7, 1)"))
272 sendForth(ourGlobals, SID, "return \".POSITIONS\"");
273 else if (0 == strcmp(command, "llGetInventoryName(7, 0)"))
274 sendForth(ourGlobals, SID, "return \".MENUITEMS\"");
275 else
276 PI("Script %s sent command %s", SID, command);
277 }
278 }
279
280 // Get the next blob to check it.
281 command = eina_strbuf_string_get(clientStream);
282 }
283
284 return ECORE_CALLBACK_RENEW;
285}
286
287static Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Server_Del *ev)
288{
289 gameGlobals *ourGlobals = data;
290
291 if (ev->server)
292 {
293 ourGlobals->server = NULL;
294 ecore_con_server_del(ev->server);
295 if (!ourGlobals->ui)
296 ecore_main_loop_quit();
297 }
298
299 return ECORE_CALLBACK_RENEW;
300}
301
302int main(int argc, char **argv)
303{
304 /* put here any init specific to this app like parsing args etc. */
305 gameGlobals ourGlobals;
306 char *programName = argv[0];
307 boolean badArgs = FALSE;
308 int result = EXIT_FAILURE;
309
310 memset(&ourGlobals, 0, sizeof(gameGlobals));
311 ourGlobals.address = "127.0.0.1";
312 ourGlobals.port = 8211;
313
314 if (eina_init())
315 {
316 ourGlobals.logDom = loggingStartup("LuaSL_test", ourGlobals.logDom);
317 ourGlobals.scripts = eina_hash_string_superfast_new(NULL);
318
319 if (ecore_con_init())
320 {
321 if ((ourGlobals.server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port, &ourGlobals)))
322 {
323 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals);
324 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb) _data, &ourGlobals);
325 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb) _del, &ourGlobals);
326 clientStream = eina_strbuf_new();
327
328 if (ecore_evas_init())
329 {
330 if (edje_init())
331 {
332 // get the arguments passed in
333 while (--argc > 0 && *++argv != '\0')
334 {
335 if (*argv[0] == '-')
336 {
337 // point to the characters after the '-' sign
338 char *s = argv[0] + 1;
339
340 switch (*s)
341 {
342 case 'u':
343 {
344 ourGlobals.ui = TRUE;
345 break;
346 }
347 default:
348 badArgs = TRUE;
349 }
350 }
351 else
352 badArgs = TRUE;
353 }
354
355 if (badArgs)
356 {
357 // display the program usage to the user as they have it wrong
358 printf("Usage: %s [-u]\n", programName);
359 printf(" -u: Show the test UI.\n");
360 }
361 else
362 // else if ((ourGlobals.config) && (ourGlobals.data))
363 {
364 unsigned int i;
365 Evas_Object *bub, *sh;
366 Ecore_Animator *ani;
367 char *group = "main";
368 char buf[PATH_MAX];
369
370 if (ourGlobals.ui)
371 {
372 /* this will give you a window with an Evas canvas under the first engine available */
373 ourGlobals.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
374 if (!ourGlobals.ee)
375 {
376 PEm("You got to have at least one evas engine built and linked up to ecore-evas for this example to run properly.");
377 edje_shutdown();
378 ecore_evas_shutdown();
379 return -1;
380 }
381 ourGlobals.canvas = ecore_evas_get(ourGlobals.ee);
382 ecore_evas_title_set(ourGlobals.ee, "LuaSL test harness");
383 ecore_evas_show(ourGlobals.ee);
384
385 ourGlobals.bg = evas_object_rectangle_add(ourGlobals.canvas);
386 evas_object_color_set(ourGlobals.bg, 255, 255, 255, 255); /* white bg */
387 evas_object_move(ourGlobals.bg, 0, 0); /* at canvas' origin */
388 evas_object_size_hint_weight_set(ourGlobals.bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
389 evas_object_resize(ourGlobals.bg, WIDTH, HEIGHT); /* covers full canvas */
390 evas_object_show(ourGlobals.bg);
391 ecore_evas_object_associate(ourGlobals.ee, ourGlobals.bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
392 evas_object_focus_set(ourGlobals.bg, EINA_TRUE);
393
394 ourGlobals.edje = edje_object_add(ourGlobals.canvas);
395 snprintf(buf, sizeof(buf), "%s/media/%s.edj", PACKAGE_DATA_DIR, "LuaSL");
396 if (!edje_object_file_set(ourGlobals.edje, buf, group))
397 {
398 int err = edje_object_load_error_get(ourGlobals.edje);
399 const char *errmsg = edje_load_error_str(err);
400 PEm("Could not load '%s' from %s: %s\n", group, buf, errmsg);
401
402 evas_object_del(ourGlobals.edje);
403 ecore_evas_free(ourGlobals.ee);
404 edje_shutdown();
405 ecore_evas_shutdown();
406 return -2;
407 }
408 evas_object_move(ourGlobals.edje, 0, 0);
409 evas_object_resize(ourGlobals.edje, WIDTH, HEIGHT);
410 evas_object_show(ourGlobals.edje);
411
412 snprintf(buf, sizeof(buf), "%s/media/bubble_sh.png", PACKAGE_DATA_DIR);
413 for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++)
414 {
415 sh = evas_object_image_filled_add(ourGlobals.canvas);
416 evas_object_image_file_set(sh, buf, NULL);
417 evas_object_resize(sh, 64, 64);
418 evas_object_show(sh);
419 evas_object_data_set(ourGlobals.bg, names[(i * 2) + 1], sh);
420 }
421
422 snprintf(buf, sizeof(buf), "%s/media/bubble.png", PACKAGE_DATA_DIR);
423 for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++)
424 {
425 bub = evas_object_image_filled_add(ourGlobals.canvas);
426 evas_object_image_file_set(bub, buf, NULL);
427 evas_object_resize(bub, 64, 64);
428 evas_object_show(bub);
429 evas_object_data_set(ourGlobals.bg, names[(i * 2)], bub);
430 }
431 ani = ecore_animator_add(anim, &ourGlobals);
432 evas_object_data_set(ourGlobals.bg, "animator", ani);
433
434 // Setup our callbacks.
435 ecore_evas_callback_delete_request_set(ourGlobals.ee, _on_delete);
436 edje_object_signal_callback_add(ourGlobals.edje, "*", "game_*", _edje_signal_cb, &ourGlobals);
437 }
438
439 ecore_main_loop_begin();
440 if (ourGlobals.ui)
441 {
442 ecore_animator_del(ani);
443 ecore_evas_free(ourGlobals.ee);
444 }
445 }
446
447 edje_shutdown();
448 }
449 else
450 PCm("Failed to init edje!");
451 ecore_evas_shutdown();
452 }
453 else
454 PCm("Failed to init ecore_evas!");
455 }
456 else
457 PCm("Failed to connect to server!");
458 ecore_con_shutdown();
459 }
460 else
461 PCm("Failed to init ecore_con!");
462 }
463 else
464 fprintf(stderr, "Failed to init eina!");
465
466 return result;
467}