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