(define-module (gacela engine)
+ #:use-module (gacela misc)
#:use-module (gacela system)
#:use-module (ice-9 receive)
#:use-module (ice-9 threads)
;;; Engine Inner Properties
-(define (default-delay) 0.1)
+(define (default-step) 0.1)
(define (default-engine-inner-properties)
- `(engine-inner-properties (delay . ,(default-delay))))
+ `(engine-inner-properties (step . ,(default-step))))
;;; Engine definitions
(cond ((not (engine-running? engine))
(with-mutex (engine-running-mutex engine)
(let loop ()
- (let ((delay 0))
+ (let ((t (current-utime))
+ (delay 0))
(with-engine engine
(receive (e c) ((apply (engine-system engine) (engine-entities engine)))
(set-engine-entities! engine (list e c)))
- (set! delay (get-property '(engine-inner-properties delay))))
- (usleep (inexact->exact (* delay 1000000))))
+ (set! delay (- (inexact->exact (* (get-property '(engine-inner-properties step)) 1000000))
+ (- (current-utime) t))))
+ (cond ((> delay 0)
+ (usleep delay))))
(if (not (engine-stopping? engine #:clean #t))
(loop)))))))
--- /dev/null
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2014 by Javier Sancho Fernandez <jsf at jsancho dot org>
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+(define-module (gacela misc))
+
+
+(define (current-utime)
+ (let ((t (gettimeofday)))
+ (+ (* (car t) 1000000) (cdr t))))
+
+(export current-utime)