gamebox-frame-manager

A manager for frames within a game loop.

Overview

This is a simple manager for frame updates within a main game loop. After creating a simple frame manager, one can just call a function every iteration of the main game loop, and have it handle the desired physics updates at the correct times. It also provides a logging feature to show the game's current frame rate, and other useful information.

Install

(ql:quickload :gamebox-frame-manager)

Usage

First, create a FRAME-MANAGER object with your desired delta time:

(defparameter *frame-manager* (make-instance 'frame-manager :delta (/ 1 30.0)))

Instead, you can also sub-class FRAME-MANAGER:

(defclass my-game (frame-manager)
  ((delta :initform (/ 1 30.0))))

(defparameter *my-game* (make-instance 'my-game))

You will likely want the frame rate logged to the REPL during development of your game. In that case, set the current logging level to :DEBUG:

(setf simple-logger:*current-level* :debug)

Then call the TICK method every step of the main game loop, with the correct value for your monitor's refresh rate, and a custom physics update function to apply.

(tick *frame-manager* 60 #'step-func)

This will call STEP-FUNC, a function you define that takes no arguments, only when needed - that is, enough time has passed between the last physics update based on the frame manager's target delta time. Within your STEP-FUNC, you have access to the reader method (ALPHA FRAME-MANAGER) to obtain the interpolation coefficient that can be used to blend the previous and current frames.

With the current log message level set to :DEBUG, you should see the frame rate printed every 5 seconds.

License

Copyright © 2014-2018 Michael Fiano.

Licensed under the MIT License.

Package Index

    BOX.FRAME

    • class

      FRAME-MANAGER

      An object which keeps track of all the game frame state.
    • function (

      TICK

      FRAME-MANAGER REFRESH-RATE STEP-FUNC &KEY PERIODIC-FUNC)
      This is designed to be called each iteration of a main game loop, which calls STEP-FUNC to update
      the physics when necessary, based on the DELTA of the frame manager. PERIODIC-FUNC is a function to
      be called periodically, controlled by the PERIOD-INTERVAL slot of FRAME-MANAGER.
    • generic (

      ALPHA

      OBJECT)
      The interpolation factor for the blending of the current frame with the last.
    • generic (

      DELTA

      OBJECT)
      The fraction denoting the desired duration in seconds for a frame.
    • generic (

      FRAME-TIME

      OBJECT)
      The actual duration in seconds of the current frame.
    • generic (

      TOTAL-TIME

      OBJECT)
      The total duration in seconds of all frames that have elapsed.