62 lines
1.9 KiB
Common Lisp
62 lines
1.9 KiB
Common Lisp
#|
|
|
This file is a part of stoe project.
|
|
Copyright (c) 2015 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|
|
|#
|
|
|
|
(uiop:define-package :stoe/game/game
|
|
(:use :cl :stoe/engine/object :stoe/engine/scene)
|
|
(:export #:get-world-origin
|
|
#:get-current-camera)
|
|
(:import-from :stoe/core/modules
|
|
#:defmodule)
|
|
(:import-from :stoe/engine/camera
|
|
#:make-camera #:update-view)
|
|
(:import-from :stoe/core/input
|
|
#:initialize-input #:finalize-input
|
|
#:update-input))
|
|
(in-package :stoe/game/game)
|
|
|
|
(defconstant +loop-step-time+ 16000.0
|
|
"The length of one game loop frame.")
|
|
|
|
(defvar *last-frame-remaining-time* 0.0
|
|
"The game loop advance +loop-step-time+ at a time but when the delta time doesn't correspond
|
|
we need to keep the remaining time.")
|
|
|
|
(defvar *current-camera* nil
|
|
"The camera used to render the scene.")
|
|
|
|
(defvar *world-origin* nil
|
|
"The origin node of the scene.")
|
|
|
|
(defun initialize (&optional argv)
|
|
"Initialize the game module."
|
|
(declare (ignore argv))
|
|
(format t "Initialize Game module~%")
|
|
(initialize-input)
|
|
(setf *world-origin* (make-object))
|
|
(setf *current-camera* (make-camera 90 (/ 16 9) 1.0 1000.0))
|
|
(attach *current-camera* *world-origin*))
|
|
|
|
(defun finalize ()
|
|
"Finalize the game module."
|
|
(setf *current-camera* nil)
|
|
(setf *world-origin* nil)
|
|
(finalize-input))
|
|
|
|
(defun update (delta-time)
|
|
"Update the game module.
|
|
Advance the world by `delta-time', +loop-step-time+ at a time."
|
|
(setf delta-time (+ delta-time *last-frame-remaining-time*))
|
|
(loop while (> delta-time +loop-step-time+)
|
|
do (progn
|
|
(when *current-camera*
|
|
(update-view *current-camera*))
|
|
(update-input +loop-step-time+)
|
|
(decf delta-time +loop-step-time+)))
|
|
(setf *last-frame-remaining-time* delta-time))
|
|
|
|
(defmodule stoe/game/game)
|
|
|
|
(defun get-world-origin () *world-origin*)
|
|
(defun get-current-camera () *current-camera*)
|