From: jsancho Date: Fri, 8 Jul 2011 12:48:00 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=c4dbd17a165312f189ec5211069dab4d039d5471;p=gacela.git --- diff --git a/src/gacela.c b/src/gacela.c index cb464a5..f6c970b 100644 --- a/src/gacela.c +++ b/src/gacela.c @@ -179,18 +179,38 @@ load_scheme_files (char *path) scm_primitive_load_path (scm_from_locale_string ("gacela_loader.scm")); } +void +start_single (int argc, char *argv[]) +{ + scm_with_guile (&init_gacela, NULL); + load_scheme_files (dirname (argv[0])); + scm_shell (argc, argv); +} + +void +start_server (int argc, char *argv[]) +{ + scm_with_guile (&init_gacela, NULL); + load_scheme_files (dirname (argv[0])); + scm_c_eval_string ("(start-server 1234)"); + scm_c_eval_string ("(game-loop)"); +} + +void +start_client (void) +{ + scm_init_guile (); + gacela_client (); +} + int main (int argc, char *argv[]) { - if (fork () == 0) { - scm_with_guile (&init_gacela, NULL); - load_scheme_files (dirname (argv[0])); - //scm_shell (argc, argv); - scm_c_eval_string ("(start-server 1234)"); - scm_c_eval_string ("(run-game)"); - } - else { - scm_init_guile (); - gacela_client (); - } + start_single (argc, argv); + /* + if (fork () == 0) + start_server (); + else + start_client (); + */ } diff --git a/src/gacela.scm b/src/gacela.scm index ff28dbb..569edc3 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -26,6 +26,7 @@ ;;; SDL Initialization Subsystem (define init-sdl #f) +(define sdl-on? #f) (define quit-sdl #f) (let ((initialized #f)) @@ -34,6 +35,10 @@ (cond ((not initialized) (SDL_Init SDL_INIT_EVERYTHING) (set! initialized #t)) (else initialized)))) + (set! sdl-on? + (lambda () + (if initialized #t #f))) + (set! quit-sdl (lambda () (SDL_Quit) @@ -237,19 +242,20 @@ (set! running #t) (quit? #f) (do () ((quit?)) - (init-frame-time) -; (check-connections) -; (eval-from-clients) - (process-events) - (cond ((not (quit?)) - (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) - (render-mobs mobs) - (SDL_GL_SwapBuffers) - (delay-frame)))) + (if (sdl-on?) (init-frame-time)) + (check-connections) + (eval-from-clients) + (cond ((sdl-on?) + (process-events) + (cond ((not (quit?)) + (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) + (render-mobs mobs) + (SDL_GL_SwapBuffers) + (delay-frame)))))) (set! running #f))) (set! game-running? diff --git a/src/gacela_server.scm b/src/gacela_server.scm index a95ec9d..f58c8b6 100644 --- a/src/gacela_server.scm +++ b/src/gacela_server.scm @@ -24,7 +24,7 @@ (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))) +; (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))) @@ -32,7 +32,10 @@ (set! check-connections (lambda () (catch #t - (lambda () (set! clients (cons (accept server-socket) clients))) +; (lambda () (set! clients (cons (accept server-socket) clients))) + (lambda () + (cond ((char-ready? server-socket) + (set! clients (cons (accept server-socket) clients))))) (lambda (key . args) #f)))) (set! eval-from-clients @@ -42,7 +45,7 @@ (let ((sock (car cli))) (cond ((char-ready? sock) (catch #t - (lambda () (eval (read sock))) + (lambda () (display (primitive-eval (read sock)) sock)) (lambda (key . args) #f)))))) clients)))