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 ();
+ */
}
;;; SDL Initialization Subsystem
(define init-sdl #f)
+(define sdl-on? #f)
(define quit-sdl #f)
(let ((initialized #f))
(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)
(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?
(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)))
(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
(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)))