Add the main loop and remove the now useless startup and debug files
This commit is contained in:
parent
994f7c33c4
commit
7e9ed2c1ac
5 changed files with 70 additions and 75 deletions
|
|
@ -11,6 +11,5 @@
|
|||
:stoe/core/thread
|
||||
:stoe/core/containers
|
||||
:stoe/core/modules
|
||||
:stoe/core/debug
|
||||
:stoe/core/jobs
|
||||
:stoe/core/file))
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
#|
|
||||
This file is a part of stoe project.
|
||||
Copyright (c) 2014 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|
||||
|#
|
||||
|
||||
(uiop:define-package :stoe/core/debug
|
||||
(:use :cl :stoe/core/utils :stoe/core/thread)
|
||||
(:import-from :stoe/core/modules
|
||||
#:defmodule))
|
||||
(in-package :stoe/core/debug)
|
||||
|
||||
(defvar *swank-server-port* 4006)
|
||||
(defvar *frames-per-second* 0.0)
|
||||
|
||||
(defun initialize (&optional argv)
|
||||
"Initialize the debug module.
|
||||
Check if the current thread is named `repl-thread' and if not,
|
||||
start the swank server to accept remote connection."
|
||||
(declare (ignore argv))
|
||||
(format t "Initialize Debug module~%")
|
||||
(when (not (string= (thread-name (current-thread)) "repl-thread"))
|
||||
#+swank
|
||||
(swank:create-server :port *swank-server-port* :dont-close nil)))
|
||||
|
||||
(defun finalize ()
|
||||
"Finalize the debug module."
|
||||
(format t "Finalize Debug module~%")
|
||||
(when (not (string= (thread-name (current-thread)) "repl-thread"))
|
||||
#+swank
|
||||
(swank:stop-server *swank-server-port*)))
|
||||
|
||||
(let ((time-counter 0.0)
|
||||
(frames-counter 0))
|
||||
(defun update (delta-time)
|
||||
"Eval the repl each frame."
|
||||
#+swank
|
||||
(let ((conn (or swank::*emacs-connection*
|
||||
(swank::default-connection))))
|
||||
(when conn
|
||||
(swank::handle-requests conn t)))
|
||||
(incf time-counter delta-time)
|
||||
(incf frames-counter)
|
||||
(when (> time-counter 1000000.0)
|
||||
(setf *frames-per-second* frames-counter)
|
||||
(setf time-counter 0.0)
|
||||
(setf frames-counter 0))))
|
||||
|
||||
(defmodule stoe/core/debug)
|
||||
25
startup.lisp
25
startup.lisp
|
|
@ -1,25 +0,0 @@
|
|||
(uiop:define-package :startup
|
||||
(:use :cl :maths :core :engine :shader))
|
||||
(in-package :startup)
|
||||
|
||||
(defun startup ()
|
||||
(world-initialize)
|
||||
(load-cube)
|
||||
(stoe/engine/render::initialize))
|
||||
|
||||
(defun quit ()
|
||||
(stoe/engine/render::finalize))
|
||||
|
||||
(defun load-cube ()
|
||||
(with-lock-held ((scene-lock (get-world)))
|
||||
(with-accessors ((scene world-scene) (camera world-camera) (scenes scenes)) (get-world)
|
||||
(push (import-graphic-assets #P"data/Cube.dae") scenes)
|
||||
(setf scene (first scenes))
|
||||
(setf camera (make-camera 90 (/ 16 9) 1.0 1000.0)))))
|
||||
|
||||
(defun load-tie ()
|
||||
(with-lock-held ((scene-lock (get-world)))
|
||||
(with-accessors ((scene world-scene) (camera world-camera) (scenes scenes)) (get-world)
|
||||
(push (import-graphic-assets #P"data/TieFighter.dae") scenes)
|
||||
(setf scene (first scenes))
|
||||
(setf camera (make-camera 90 (/ 16 9) 1.0 1000.0)))))
|
||||
2
stoe.asd
2
stoe.asd
|
|
@ -50,7 +50,7 @@
|
|||
"stoe/maths/all"
|
||||
"stoe/engine/all"
|
||||
"stoe/shader/all")
|
||||
:components ((:file "startup"))
|
||||
:components ((:file "stoe"))
|
||||
:in-order-to ((test-op (load-op stoe/test))))
|
||||
|
||||
(defsystem stoe/test
|
||||
|
|
|
|||
69
stoe.lisp
Normal file
69
stoe.lisp
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#|
|
||||
This file is a part of stoe project.
|
||||
Copyright (c) 2015 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|
||||
|#
|
||||
|
||||
(uiop:define-package :stoe
|
||||
(:use :cl :maths :core :engine :shader)
|
||||
(:reexport :maths :core :engine :shader)
|
||||
(:export #:main #:quit))
|
||||
(in-package :stoe)
|
||||
|
||||
(defvar *argv* nil)
|
||||
(defvar *swank-server-port* 4006)
|
||||
|
||||
(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.")
|
||||
|
||||
(defun initialize (&optional argv)
|
||||
"Initialize all the modules passing the optional argv."
|
||||
(initialize-modules argv))
|
||||
|
||||
(defun finalize ()
|
||||
"Finalize all the modules."
|
||||
(finalize-modules))
|
||||
|
||||
(defun update (delta-time)
|
||||
"Update all the modules passing the delta time since the last frame."
|
||||
(update-modules delta-time))
|
||||
|
||||
(let (exit-main-loop)
|
||||
(defun main-loop ()
|
||||
"Run the protected main-loop. An error will be catched with the possibility to continue."
|
||||
(setf exit-main-loop nil)
|
||||
(let ((clock (make-clock)))
|
||||
(loop until exit-main-loop
|
||||
for remaining-time = 0 then delta-time
|
||||
for delta-time = (clock-delta clock) then (+ (clock-delta clock) remaining-time)
|
||||
do (progn
|
||||
(loop while (> delta-time +loop-step-time+)
|
||||
do (restartable
|
||||
(update +loop-step-time+)
|
||||
(decf delta-time +loop-step-time+)))
|
||||
(update-clock clock)))))
|
||||
|
||||
(defun quit ()
|
||||
"Quit the main loop."
|
||||
(setf exit-main-loop t)))
|
||||
|
||||
(defun startup-stoe (argv)
|
||||
(initialize argv)
|
||||
(unwind-protect
|
||||
(main-loop)
|
||||
(finalize)))
|
||||
|
||||
(defun main (&optional argv)
|
||||
"Run the game."
|
||||
(setf *argv* argv)
|
||||
(if (string-equal (thread-name (current-thread)) "repl-thread")
|
||||
(make-thread (lambda () (startup-stoe *argv*)) :name "Main Thread")
|
||||
(progn
|
||||
#+swank
|
||||
(swank:create-server :port *swank-server-port* :dont-close nil)
|
||||
(startup-stoe argv)
|
||||
#+swank
|
||||
(swank:stop-server *swank-server-port*))))
|
||||
Loading…
Add table
Reference in a new issue