From 1386cfb20db6259ed74f089f31109e88e21bb5b3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 4 Oct 2020 20:40:31 -0400 Subject: Add system module to fix circular reference. It's very bad that the node-2d module was depending on the kernel module. If the kernel includes a module that includes node-2d, a circular reference occurs and things get very strange very fast. Lots of weird compilation errors and stuff. --- Makefile.am | 1 + starling/kernel.scm | 8 +++----- starling/node-2d.scm | 5 ++--- starling/system.scm | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 starling/system.scm diff --git a/Makefile.am b/Makefile.am index bc2ff0d..503a280 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,6 +40,7 @@ godir=$(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache SOURCES = \ starling/config.scm \ starling/inotify.scm \ + starling/system.scm \ starling/asset.scm \ starling/node.scm \ starling/scene.scm \ diff --git a/starling/kernel.scm b/starling/kernel.scm index c50cd98..25b6917 100644 --- a/starling/kernel.scm +++ b/starling/kernel.scm @@ -41,6 +41,7 @@ #:use-module (starling node) #:use-module (starling repl) #:use-module (starling scene) + #:use-module (starling system) #:use-module ((sdl2 video) #:prefix sdl2:) #:use-module (system repl command) #:export ( @@ -57,7 +58,6 @@ avg-frame-time current-kernel boot-kernel - elapsed-time fps reboot-current-scene) #:re-export (abort-game)) @@ -248,9 +248,6 @@ (define-method (on-scenes-empty (kernel )) (abort-game)) -(define (elapsed-time) - (sdl-ticks)) - (define-method (fps kernel) (/ 1000.0 (avg-frame-time kernel))) @@ -285,7 +282,8 @@ (const #t) (lambda () (parameterize ((current-kernel kernel) - (current-gpu (make-gpu (gl-context kernel)))) + (current-gpu (make-gpu (gl-context kernel))) + (current-window (window kernel))) (activate kernel) (push-scene kernel (thunk)) (run-game* #:update (lambda (dt) (update-tree kernel dt)) diff --git a/starling/node-2d.scm b/starling/node-2d.scm index 709eeec..947e377 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -39,11 +39,10 @@ #:use-module (chickadee scripting) #:use-module (ice-9 match) #:use-module (oop goops) - #:use-module (sdl2 video) #:use-module (starling asset) - #:use-module (starling kernel) #:use-module (starling node) #:use-module (starling scene) + #:use-module (starling system) #:export ( target offset @@ -232,7 +231,7 @@ ;; more views. (define (make-default-views) - (match (window-size (window (current-kernel))) + (match (current-window-size) ((width height) (list (make diff --git a/starling/system.scm b/starling/system.scm new file mode 100644 index 0000000..f498aa4 --- /dev/null +++ b/starling/system.scm @@ -0,0 +1,15 @@ +(define-module (starling system) + #:use-module (oop goops) + #:use-module (sdl2) + #:use-module (sdl2 video) + #:export (elapsed-time + current-window + current-window-size)) + +(define (elapsed-time) + (sdl-ticks)) + +(define current-window (make-parameter #f)) + +(define (current-window-size) + (window-size (current-window))) -- cgit v1.2.3