aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/love/love.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-13 17:01:40 +1000
committerDavid Walter Seikel2014-05-13 17:01:40 +1000
commitb0e2903acf2c0d926b134c3a165f0160e85e87bc (patch)
tree323265729ff8e03e28054d769d822364e956c15e /src/love/love.c
parentTODO++ (diff)
downloadSledjHamr-b0e2903acf2c0d926b134c3a165f0160e85e87bc.zip
SledjHamr-b0e2903acf2c0d926b134c3a165f0160e85e87bc.tar.gz
SledjHamr-b0e2903acf2c0d926b134c3a165f0160e85e87bc.tar.bz2
SledjHamr-b0e2903acf2c0d926b134c3a165f0160e85e87bc.tar.xz
Add a TCP link between love and extantz, and have love pass on some of the commands that go to the viewer.
Diffstat (limited to '')
-rw-r--r--src/love/love.c245
1 files changed, 205 insertions, 40 deletions
diff --git a/src/love/love.c b/src/love/love.c
index 6a3cdaa..4d78a8c 100644
--- a/src/love/love.c
+++ b/src/love/love.c
@@ -31,7 +31,9 @@ typedef struct _gameGlobals
31 Evas *canvas; // The canvas for drawing directly onto. 31 Evas *canvas; // The canvas for drawing directly onto.
32 Evas_Object *bg; // Our background edje, also the game specific stuff. 32 Evas_Object *bg; // Our background edje, also the game specific stuff.
33 Evas_Object *edje; // The edje of the background. 33 Evas_Object *edje; // The edje of the background.
34 Ecore_Con_Server *serverLuaSL;
34 Ecore_Con_Server *server; 35 Ecore_Con_Server *server;
36 Ecore_Con_Client *client; // TODO - Really should be a bunch of these.
35 Eina_Hash *scripts; 37 Eina_Hash *scripts;
36 const char *address; 38 const char *address;
37 int port; 39 int port;
@@ -50,6 +52,8 @@ typedef struct _script
50 52
51 53
52int logDom; // Our logging domain. 54int logDom; // Our logging domain.
55//static int CPUs = 4;
56static Eina_Strbuf *LuaSLStream;
53static Eina_Strbuf *clientStream; 57static Eina_Strbuf *clientStream;
54static int scriptCount = 0; 58static int scriptCount = 0;
55static int compiledCount = 0; 59static int compiledCount = 0;
@@ -91,7 +95,6 @@ static float timeDiff(struct timeval *now, struct timeval *then)
91 return 0.0; 95 return 0.0;
92} 96}
93 97
94
95static void 98static void
96_edje_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source) 99_edje_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
97{ 100{
@@ -166,7 +169,7 @@ static void dirList_compile(const char *name, const char *path, void *data)
166 snprintf(me->SID, sizeof(me->SID), "%08lx-%04lx-%04lx-%04lx-%012lx", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); 169 snprintf(me->SID, sizeof(me->SID), "%08lx-%04lx-%04lx-%04lx-%012lx", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random());
167 snprintf(me->fileName, sizeof(me->fileName), "%s/%s", path, name); 170 snprintf(me->fileName, sizeof(me->fileName), "%s/%s", path, name);
168 eina_hash_add(ourGlobals->scripts, me->SID, me); 171 eina_hash_add(ourGlobals->scripts, me->SID, me);
169 sendForth(ourGlobals->server, me->SID, "compile(%s)", me->fileName); 172 sendForth(ourGlobals->serverLuaSL, me->SID, "compile(%s)", me->fileName);
170 } 173 }
171 } 174 }
172} 175}
@@ -177,25 +180,39 @@ static Eina_Bool _timer_cb(void *data)
177 Eina_Iterator *scripts; 180 Eina_Iterator *scripts;
178 script *me; 181 script *me;
179 boolean exit = FALSE; 182 boolean exit = FALSE;
183 char buf[PATH_MAX];
184
185 if (5 == timedEvent)
186 {
187 gettimeofday(&startTime, NULL);
188 snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR);
189 eina_file_dir_list(buf, EINA_TRUE, dirList_compile, ourGlobals);
190 }
191
192 if (5 >= timedEvent)
193 {
194 timedEvent++;
195 return ECORE_CALLBACK_RENEW;
196 }
180 197
181 scripts = eina_hash_iterator_data_new(ourGlobals->scripts); 198 scripts = eina_hash_iterator_data_new(ourGlobals->scripts);
182 while(eina_iterator_next(scripts, (void **) &me)) 199 while(eina_iterator_next(scripts, (void **) &me))
183 { 200 {
184 switch (timedEvent) 201 switch (timedEvent)
185 { 202 {
186 case 5 : 203 case 10 :
187 { 204 {
188 sendForth(ourGlobals->server, me->SID, "events.detectedKeys({\"%s\"})", ownerKey); 205 sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedKeys({\"%s\"})", ownerKey);
189 sendForth(ourGlobals->server, me->SID, "events.detectedNames({\"%s\"})", ownerName); 206 sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedNames({\"%s\"})", ownerName);
190 sendForth(ourGlobals->server, me->SID, "events.touch_start(1)"); 207 sendForth(ourGlobals->serverLuaSL, me->SID, "events.touch_start(1)");
191 break; 208 break;
192 } 209 }
193 case 9 : 210 case 15 :
194 { 211 {
195 sendForth(ourGlobals->server, me->SID, "quit()"); 212 sendForth(ourGlobals->serverLuaSL, me->SID, "quit()");
196 break; 213 break;
197 } 214 }
198 case 11 : 215 case 20 :
199 { 216 {
200 exit = TRUE; 217 exit = TRUE;
201 break; 218 break;
@@ -206,28 +223,24 @@ static Eina_Bool _timer_cb(void *data)
206 223
207 if (exit) 224 if (exit)
208 { 225 {
209 sendForth(ourGlobals->server, ownerKey, "exit()"); 226 sendForth(ourGlobals->serverLuaSL, ownerKey, "exit()");
210 ecore_main_loop_quit(); 227 ecore_main_loop_quit();
211 return ECORE_CALLBACK_CANCEL; 228 return ECORE_CALLBACK_CANCEL;
212 } 229 }
213 return ECORE_CALLBACK_RENEW; 230 return ECORE_CALLBACK_RENEW;
214} 231}
215 232
216static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev) 233static Eina_Bool _addLuaSL(void *data, int type, Ecore_Con_Event_Server_Add *ev)
217{ 234{
218 gameGlobals *ourGlobals = data; 235 gameGlobals *ourGlobals = data;
219 char buf[PATH_MAX];
220 236
221 ourGlobals->server = ev->server; 237 ourGlobals->serverLuaSL = ev->server;
222 gettimeofday(&startTime, NULL); 238 // Wait a while, then start sending events for testing.
223 snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR);
224 eina_file_dir_list(buf, EINA_TRUE, dirList_compile, ourGlobals);
225 // Wait awhile, then start sending events for testing.
226 ecore_timer_add(0.5, _timer_cb, ourGlobals); 239 ecore_timer_add(0.5, _timer_cb, ourGlobals);
227 return ECORE_CALLBACK_RENEW; 240 return ECORE_CALLBACK_RENEW;
228} 241}
229 242
230static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev) 243static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *ev)
231{ 244{
232 gameGlobals *ourGlobals = data; 245 gameGlobals *ourGlobals = data;
233 246
@@ -236,15 +249,15 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
236 const char *command; 249 const char *command;
237 char *ext; 250 char *ext;
238 251
239 eina_strbuf_append_length(clientStream, ev->data, ev->size); 252 eina_strbuf_append_length(LuaSLStream, ev->data, ev->size);
240 command = eina_strbuf_string_get(clientStream); 253 command = eina_strbuf_string_get(LuaSLStream);
241 while ((ext = index(command, '\n'))) 254 while ((ext = index(command, '\n')))
242 { 255 {
243 int length = ext - command; 256 int length = ext - command;
244 257
245 strncpy(SID, command, length + 1); 258 strncpy(SID, command, length + 1);
246 SID[length] = '\0'; 259 SID[length] = '\0';
247 eina_strbuf_remove(clientStream, 0, length + 1); 260 eina_strbuf_remove(LuaSLStream, 0, length + 1);
248 ext = index(SID, '.'); 261 ext = index(SID, '.');
249 if (ext) 262 if (ext)
250 { 263 {
@@ -320,50 +333,71 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
320 PD("TOTAL compile speed is %f scripts per second", compiledCount / timeDiff(&now, &startTime)); 333 PD("TOTAL compile speed is %f scripts per second", compiledCount / timeDiff(&now, &startTime));
321 } 334 }
322// PD("The compile of %s worked, running it now.", SID); 335// PD("The compile of %s worked, running it now.", SID);
323 sendForth(ourGlobals->server, SID, "run()"); 336 sendForth(ourGlobals->serverLuaSL, SID, "run()");
324 } 337 }
325 else 338 else
326 { 339 {
327 // Send back some random or fixed values for testing. 340 // Send back some random or fixed values for testing.
328 if (0 == strcmp(command, "llGetKey()")) 341 if (0 == strcmp(command, "llGetKey()"))
329 sendForth(ourGlobals->server, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); 342 sendForth(ourGlobals->serverLuaSL, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random());
330 else if (0 == strcmp(command, "llGetOwner()")) 343 else if (0 == strcmp(command, "llGetOwner()"))
331 sendForth(ourGlobals->server, SID, "return \"%s\"", ownerKey); 344 sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey);
332 else if (0 == strcmp(command, "llGetPos()")) 345 else if (0 == strcmp(command, "llGetPos()"))
333 sendForth(ourGlobals->server, SID, "return {x=128.0, y=128.0, z=128.0}"); 346 sendForth(ourGlobals->serverLuaSL, SID, "return {x=128.0, y=128.0, z=128.0}");
334 else if (0 == strcmp(command, "llGetRot()")) 347 else if (0 == strcmp(command, "llGetRot()"))
335 sendForth(ourGlobals->server, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}"); 348 sendForth(ourGlobals->serverLuaSL, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}");
336 else if (0 == strcmp(command, "llGetObjectDesc()")) 349 else if (0 == strcmp(command, "llGetObjectDesc()"))
337 sendForth(ourGlobals->server, SID, "return \"\""); 350 sendForth(ourGlobals->serverLuaSL, SID, "return \"\"");
338 else if (0 == strncmp(command, "llGetAlpha(", 11)) 351 else if (0 == strncmp(command, "llGetAlpha(", 11))
339 sendForth(ourGlobals->server, SID, "return 1.0"); 352 sendForth(ourGlobals->serverLuaSL, SID, "return 1.0");
340 else if (0 == strcmp(command, "llGetInventoryNumber(7)")) 353 else if (0 == strcmp(command, "llGetInventoryNumber(7)"))
341 sendForth(ourGlobals->server, SID, "return 3"); 354 sendForth(ourGlobals->serverLuaSL, SID, "return 3");
342 else if (0 == strcmp(command, "llGetInventoryName(7, 2)")) 355 else if (0 == strcmp(command, "llGetInventoryName(7, 2)"))
343 sendForth(ourGlobals->server, SID, "return \".readme\""); 356 sendForth(ourGlobals->serverLuaSL, SID, "return \".readme\"");
344 else if (0 == strcmp(command, "llGetInventoryName(7, 1)")) 357 else if (0 == strcmp(command, "llGetInventoryName(7, 1)"))
345 sendForth(ourGlobals->server, SID, "return \".POSITIONS\""); 358 sendForth(ourGlobals->serverLuaSL, SID, "return \".POSITIONS\"");
346 else if (0 == strcmp(command, "llGetInventoryName(7, 0)")) 359 else if (0 == strcmp(command, "llGetInventoryName(7, 0)"))
347 sendForth(ourGlobals->server, SID, "return \".MENUITEMS\""); 360 sendForth(ourGlobals->serverLuaSL, SID, "return \".MENUITEMS\"");
361 // Send "back" stuff on to the one and only client.
362 else if (0 == strncmp(command, "llOwnerSay(", 11))
363 {
364 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
365 }
366 else if (0 == strncmp(command, "llWhisper(", 10))
367 {
368 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
369 }
370 else if (0 == strncmp(command, "llSay(", 6))
371 {
372 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
373 }
374 else if (0 == strncmp(command, "llShout(", 8))
375 {
376 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
377 }
378 else if (0 == strncmp(command, "llDialog(", 9))
379 {
380 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
381 }
348 else 382 else
349 PI("Script %s sent command %s", SID, command); 383 PI("Script %s sent command %s", SID, command);
350 } 384 }
351 } 385 }
352 386
353 // Get the next blob to check it. 387 // Get the next blob to check it.
354 command = eina_strbuf_string_get(clientStream); 388 command = eina_strbuf_string_get(LuaSLStream);
355 } 389 }
356 390
357 return ECORE_CALLBACK_RENEW; 391 return ECORE_CALLBACK_RENEW;
358} 392}
359 393
360static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) 394static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev)
361{ 395{
362 gameGlobals *ourGlobals = data; 396 gameGlobals *ourGlobals = data;
363 397
364 if (ev->server) 398 if (ev->server)
365 { 399 {
366 ourGlobals->server = NULL; 400 ourGlobals->serverLuaSL = NULL;
367 ecore_con_server_del(ev->server); 401 ecore_con_server_del(ev->server);
368 if (!ourGlobals->ui) 402 if (!ourGlobals->ui)
369 ecore_main_loop_quit(); 403 ecore_main_loop_quit();
@@ -372,6 +406,118 @@ static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev)
372 return ECORE_CALLBACK_RENEW; 406 return ECORE_CALLBACK_RENEW;
373} 407}
374 408
409
410static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev)
411{
412 gameGlobals *ourGlobals = data;
413
414 ourGlobals->client = ev->client;
415 ecore_con_client_timeout_set(ev->client, 0);
416 return ECORE_CALLBACK_RENEW;
417}
418
419static Eina_Bool _dataClient(void *data, int type, Ecore_Con_Event_Client_Data *ev)
420{
421// gameGlobals *ourGlobals = data;
422// char buf[PATH_MAX];
423 char SID[PATH_MAX];
424 const char *command;
425 char *ext;
426
427 eina_strbuf_append_length(clientStream, ev->data, ev->size);
428 command = eina_strbuf_string_get(clientStream);
429 while ((ext = index(command, '\n')))
430 {
431 int length = ext - command;
432
433 strncpy(SID, command, length + 1);
434 SID[length] = '\0';
435 eina_strbuf_remove(clientStream, 0, length + 1);
436 ext = index(SID, '.');
437 if (ext)
438 {
439 ext[0] = '\0';
440 command = ext + 1;
441
442#if 0 // Replace this with code to parse what viewers send.
443 if (0 == strncmp(command, "compile(", 8))
444 {
445 char *temp;
446 char *file;
447
448 strcpy(buf, &command[8]);
449 temp = buf;
450 file = temp;
451 while (')' != temp[0])
452 temp++;
453 temp[0] = '\0';
454
455 PD("Compiling %s, %s.", SID, file);
456 if (compileLSL(ourGlobals, ev->client, SID, file, FALSE))
457 {
458 script *me = calloc(1, sizeof(script));
459
460 gettimeofday(&me->startTime, NULL);
461 strncpy(me->SID, SID, sizeof(me->SID));
462 strncpy(me->fileName, file, sizeof(me->fileName));
463 me->game = ourGlobals;
464 me->client = ev->client;
465 eina_hash_add(ourGlobals->scripts, me->SID, me);
466 eina_hash_add(ourGlobals->names, me->fileName, me);
467 sendBack(ev->client, SID, "compiled(true)");
468 }
469 else
470 sendBack(ev->client, SID, "compiled(false)");
471 }
472 else if (0 == strcmp(command, "run()"))
473 {
474 script *me;
475 char buf[PATH_MAX];
476
477 me = eina_hash_find(ourGlobals->scripts, SID);
478 if (me)
479 {
480 sprintf(buf, "%s.lua.out", me->fileName);
481 newProc(buf, TRUE, me);
482 }
483 }
484 else if (0 == strcmp(command, "exit()"))
485 {
486 PD("Told to exit.");
487 ecore_main_loop_quit();
488 }
489 else
490 {
491 const char *status = NULL;
492
493 status = sendToChannel(ourGlobals, SID, command);
494 if (status)
495 PE("Error sending command %s to script %s : %s", command, SID, status);
496 }
497#endif
498
499 }
500
501 // Get the next blob to check it.
502 command = eina_strbuf_string_get(clientStream);
503 }
504
505 return ECORE_CALLBACK_RENEW;
506}
507
508static Eina_Bool _delClient(void *data, int type, Ecore_Con_Event_Client_Del *ev)
509{
510// gameGlobals *ourGlobals = data;
511
512 if (ev->client)
513 {
514 PD("No more clients, exiting.");
515 ecore_con_client_del(ev->client);
516 ecore_main_loop_quit();
517 }
518 return ECORE_CALLBACK_RENEW;
519}
520
375int main(int argc, char **argv) 521int main(int argc, char **argv)
376{ 522{
377 /* put here any init specific to this app like parsing args etc. */ 523 /* put here any init specific to this app like parsing args etc. */
@@ -396,12 +542,26 @@ int main(int argc, char **argv)
396 542
397 if (ecore_con_init()) 543 if (ecore_con_init())
398 { 544 {
399 if ((ourGlobals.server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port, &ourGlobals))) 545 if ((ourGlobals.serverLuaSL = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port, &ourGlobals)))
400 { 546 {
401 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals); 547 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) _addLuaSL, &ourGlobals);
402 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb) _data, &ourGlobals); 548 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb) _dataLuaSL, &ourGlobals);
403 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb) _del, &ourGlobals); 549 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb) _delLuaSL, &ourGlobals);
404 clientStream = eina_strbuf_new(); 550 LuaSLStream = eina_strbuf_new();
551
552 if ((ourGlobals.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port + 1, &ourGlobals)))
553 {
554// int i;
555
556 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) _addClient, &ourGlobals);
557 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb) _dataClient, &ourGlobals);
558 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _delClient, &ourGlobals);
559 ecore_con_server_timeout_set(ourGlobals.server, 0);
560 ecore_con_server_client_limit_set(ourGlobals.server, -1, 0);
561 ecore_con_server_timeout_set(ourGlobals.server, 10);
562 ecore_con_server_client_limit_set(ourGlobals.server, 3, 0);
563 clientStream = eina_strbuf_new();
564
405 565
406 if (ecore_evas_init()) 566 if (ecore_evas_init())
407 { 567 {
@@ -530,6 +690,11 @@ int main(int argc, char **argv)
530 } 690 }
531 else 691 else
532 PC("Failed to init ecore_evas!"); 692 PC("Failed to init ecore_evas!");
693
694 }
695 else
696 PC("Failed to add server!");
697
533 } 698 }
534 else 699 else
535 PC("Failed to connect to server!"); 700 PC("Failed to connect to server!");