Skip to content

Commit

Permalink
Cap physics step
Browse files Browse the repository at this point in the history
  • Loading branch information
borodust committed Apr 24, 2017
1 parent 11eab86 commit f5dda29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 5 additions & 3 deletions client/src/arena.lisp
Expand Up @@ -58,11 +58,13 @@




(defun shoot-ball (player) (defun shoot-ball (player)
(let ((pos (position-of player))) (let ((pos (position-of player))
(gaze (gaze-of player)))
(run (>> (assembly-flow 'ball-model (run (>> (assembly-flow 'ball-model
:owner player :owner player
:position (vec3 (+ (x pos) 1.0) 10.0 (- (y pos))) ;; fixme: translate by +x to center ball at mortar
:force (mult (gaze-of player) 20000)) :position (vec3 (x pos) 8.2 (- (y pos)))
:force (mult gaze 20000))
(-> ((mortar-combat)) (ball) (-> ((mortar-combat)) (ball)
(let ((group (find-node (root-of (scene-of *system*)) :ball-group))) (let ((group (find-node (root-of (scene-of *system*)) :ball-group)))
(adopt group ball))))))) (adopt group ball)))))))
Expand Down
17 changes: 11 additions & 6 deletions client/src/main.lisp
@@ -1,7 +1,7 @@
(in-package :mortar-combat) (in-package :mortar-combat)




(define-constant +framestep+ 0.017) (define-constant +world-step+ 0.016)
(defvar *main-latch* (mt:make-latch)) (defvar *main-latch* (mt:make-latch))




Expand Down Expand Up @@ -212,22 +212,27 @@
scenegraph-root)) scenegraph-root))
(let ((board (find-node (root-of scene) :ui))) (let ((board (find-node (root-of scene) :ui)))
(make-ui board)) (make-ui board))
(let ((accumulated-time 0) (let ((accumulated-packet-time 0)
(accumulated-step-time 0)
start looped-flow) start looped-flow)
(setf looped-flow (setf looped-flow
(>> (instantly () (>> (instantly ()
(setf start (real-time-seconds)) (setf start (real-time-seconds))
(let ((*system* this)) (let ((*system* this))
(drain task-queue)) (drain task-queue))
(when (> accumulated-time 0.05) (when (> accumulated-packet-time 0.05)
(send-client-data this) (send-client-data this)
(broadcast-arena-state this) (broadcast-arena-state this)
(setf accumulated-time 0))) (setf accumulated-packet-time 0)))
(-> ((physics)) () (-> ((physics)) ()
(observe-universe +framestep+)) (when (> accumulated-step-time (- +world-step+ 0.02))
(observe-universe +world-step+)
(setf accumulated-step-time 0)))
(scene-processing-flow scene) (scene-processing-flow scene)
(instantly () (instantly ()
(incf accumulated-time (- (real-time-seconds) start)) (let ((delta (- (real-time-seconds) start)))
(incf accumulated-packet-time delta)
(incf accumulated-step-time delta))
(when (enabledp this) (when (enabledp this)
(run looped-flow))))) (run looped-flow)))))
(run looped-flow))))))) (run looped-flow)))))))
Expand Down

0 comments on commit f5dda29

Please sign in to comment.