target FPS

This commit is contained in:
BirDt_ 2026-04-04 14:36:40 +08:00
parent 1ce9c49086
commit 6f9e0a934f
2 changed files with 11 additions and 1 deletions

View file

@ -172,15 +172,18 @@ Functions for evaluating the render queues. ~evaluate-render-queue~ evaluates a
#+begin_src
*window-size*
*window-title*
*target-fps*
#+end_src
~*window-size*~ is a parameter that expects a cons pair of two integers, where the first integer is the window width, and the second is the window height.
~*window-title*~ is a parameter that expects a string, which is used for the window title.
~*target-fps*~ is a parameter that expects an integer, which specifies the desired frames per second to run at.
#+begin_src scheme
(create-window process: (next-frame) close-predicate: (window-should-close?))
#+end_src
~create-window~ creates a window using the window parameters described above, then enters a loop which runs the ~process:~ function (~next-frame~ by default) on each frame, unless ~close-predicate:~ (Raylib's ~window-should-close~ function by default) returns true, in which case the window is closed.
~create-window~ creates a window using the window parameters described above, sets the target frames per second, then enters a loop which runs the ~process:~ function (~next-frame~ by default) on each frame, unless ~close-predicate:~ (Raylib's ~window-should-close~ function by default) returns true, in which case the window is closed.
* Dependencies
The following Chicken dependencies are required:

View file

@ -111,6 +111,7 @@
(hash-table-ref world id))
;; Create an entity in the world and return it's ID
;; TODO: consider whether we want to use a hash-table for the entity list. I'm not sure yet how punishing O(n) lookup will be here, so it might be sometihng to look at once we start handling entity execution
(define (create-named-entity id . components)
(assert (symbol? id))
(assert (every record? components))
@ -443,8 +444,14 @@
(define *window-title* (guarded-parameter "imugi"
string?))
;; Desired FPS count
(define *target-fps* (guarded-parameter 60
integer?))
;; Make a window with the above parameters and default processing and predicate
(define (create-window #!key (process next-frame) (close-predicate window-should-close?))
(init-window (car (*window-size*)) (cdr (*window-size*)) (*window-title*))
(set-target-fps (*target-fps*))
(let loop ()
(process)
(unless (close-predicate)