#include "gacela_FTGL.h"
+// Generic variables
+int ctrl_c = 0;
+
static int
find_matching_paren (int k)
{
ctrl_c_handler (int signum)
{
printf ("ERROR: User interrupt\nABORT: (signal)\n");
+ ctrl_c = 1;
}
static void
while (1) {
line = readline ("gacela> ");
+ ctrl_c = 0;
if (!line) break;
if (line && *line)
{
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);
}
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
(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?
(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)
(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)))))
(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)))