From: jsancho Date: Thu, 14 Jul 2011 07:26:29 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=cd001a2c183f65f0894500569fea2ffcf7362f30;p=gacela.git --- diff --git a/src/gacela.c b/src/gacela.c index dc5795a..a350504 100644 --- a/src/gacela.c +++ b/src/gacela.c @@ -31,6 +31,9 @@ #include "gacela_FTGL.h" +// Generic variables +int ctrl_c = 0; + static int find_matching_paren (int k) { @@ -110,6 +113,7 @@ void ctrl_c_handler (int signum) { printf ("ERROR: User interrupt\nABORT: (signal)\n"); + ctrl_c = 1; } static void @@ -157,6 +161,7 @@ gacela_client (char *hostname, int port) while (1) { line = readline ("gacela> "); + ctrl_c = 0; if (!line) break; if (line && *line) { @@ -168,12 +173,18 @@ gacela_client (char *hostname, int port) error("ERROR writing to socket"); bzero (buffer, 256); - n = 0; - while (n == 0) - n = read (sockfd, buffer, 255); + n = read (sockfd, buffer, sizeof (buffer)); + while (n == 0) { + if (ctrl_c) break; + sleep (1); + n = read (sockfd, buffer, sizeof (buffer)); + } if (n < 0) error("ERROR reading from socket"); - printf ("%s\n", buffer); + if (ctrl_c) + ctrl_c = 0; + else + printf ("%s\n", buffer); } free (line); } @@ -231,7 +242,6 @@ start_server (char *working_path, int port) load_scheme_files (working_path); sprintf (start_server, "(start-server %d)", port); scm_c_eval_string (start_server); - scm_c_eval_string ("(game-loop)"); } void diff --git a/src/gacela.scm b/src/gacela.scm index c8c9fff..4f1a4dd 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -242,20 +242,21 @@ (set! running #t) (quit! #f) (do () ((quit?)) - (if (sdl-on?) (init-frame-time)) + (init-frame-time) (check-connections) (eval-from-clients) - (cond ((sdl-on?) - (process-events) - (cond ((not (quit?)) + (process-events) + (cond ((not (quit?)) + (cond ((video-mode-on?) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) - (to-origin) - (cond ((mobs-changed?) (set! mobs (get-active-mobs)))) - (if (procedure? game-code) (game-code)) - (run-mob-actions mobs) + (to-origin))) + (cond ((mobs-changed?) (set! mobs (get-active-mobs)))) + (if (procedure? game-code) (game-code)) + (run-mob-actions mobs) + (cond ((video-mode-on?) (render-mobs mobs) - (SDL_GL_SwapBuffers) - (delay-frame)))))) + (SDL_GL_SwapBuffers))) + (delay-frame)))) (set! running #f))) (set! game-running? diff --git a/src/gacela_server.scm b/src/gacela_server.scm index 978ea8c..1d926fd 100644 --- a/src/gacela_server.scm +++ b/src/gacela_server.scm @@ -25,10 +25,12 @@ (set! start-server (lambda (port) (set! server-socket (socket PF_INET SOCK_STREAM 0)) -; (fcntl server-socket F_SETFL (logior O_NONBLOCK (fcntl server-socket F_GETFL))) (setsockopt server-socket SOL_SOCKET SO_REUSEADDR 1) (bind server-socket AF_INET INADDR_ANY port) - (listen server-socket 5))) + (listen server-socket 5) + (cond ((not (game-running?)) + (game-loop))))) + (set! clean-closed-connections (lambda (conns) @@ -44,7 +46,6 @@ (lambda () (set! clients (clean-closed-connections clients)) (catch #t -; (lambda () (set! clients (cons (accept server-socket) clients))) (lambda () (cond ((char-ready? server-socket) (set! clients (cons (accept server-socket) clients))))) @@ -58,13 +59,13 @@ (cond ((char-ready? sock) (catch #t (lambda () - (let ((exp (car (read sock)))) + (let ((exp (read sock))) (format #t "~a~%" exp) (cond ((eof-object? exp) (close sock)) (else - (format #t "~a~%" (primitive-eval exp)) - (format sock "~a" (primitive-eval exp)))))) + (format #t "~a~%" (primitive-eval (car exp))) + (format sock "~a" (primitive-eval (car exp))))))) (lambda (key . args) (let ((fmt (string-concatenate (list (cadr args) "~%"))) (params (caddr args)))