Skip to content

Commit

Permalink
Send game updates every couple of frames
Browse files Browse the repository at this point in the history
  • Loading branch information
borodust committed Apr 23, 2017
1 parent af8617a commit b681885
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
21 changes: 11 additions & 10 deletions client/src/arena.lisp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@
(with-slots (dudes player) this (with-slots (dudes player) this
(dolist (dude-state (getf state :player-list)) (dolist (dude-state (getf state :player-list))
(with-instance-lock-held (this) (with-instance-lock-held (this)
(let* ((dude-name (getf dude-state :name)) (let* ((dude-name (getf dude-state :name)))
(dude (gethash dude-name dudes)))
(unless (equal dude-name (name-of player)) (unless (equal dude-name (name-of player))
(unless dude (let ((dude (gethash dude-name dudes)))
(setf dude (make-instance 'proxy :name dude-name)
(gethash dude-name dudes) dude) (unless dude
(post (make-player-added dude) (events))) (setf dude (make-instance 'proxy :name dude-name)
(update-proxy dude (gethash dude-name dudes) dude)
(sequence->vec2 (getf dude-state :position)) (post (make-player-added dude) (events)))
(sequence->vec2(getf dude-state :rotation)) (update-proxy dude
timestamp))))))) (sequence->vec2 (getf dude-state :position))
(sequence->vec2(getf dude-state :rotation))
timestamp))))))))




(defun shoot-ball (player) (defun shoot-ball (player)
Expand Down
30 changes: 18 additions & 12 deletions client/src/main.lisp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -171,18 +171,24 @@
(make-rendering-pass)) (make-rendering-pass))
scenegraph-root))) scenegraph-root)))
(concurrently () (concurrently ()
(let (looped-flow) (let ((accumulated-time 0)
(setf looped-flow (>> (instantly () start looped-flow)
(let ((*system* this)) (setf looped-flow
(drain task-queue)) (>> (instantly ()
(send-client-data this) (setf start (real-time-seconds))
(broadcast-arena-state this)) (let ((*system* this))
(-> ((physics)) () (drain task-queue))
(observe-universe +framestep+)) (when (> accumulated-time 0.05)
(scene-processing-flow scene) (send-client-data this)
(instantly () (broadcast-arena-state this)
(when (enabledp this) (setf accumulated-time 0)))
(run looped-flow))))) (-> ((physics)) ()
(observe-universe +framestep+))
(scene-processing-flow scene)
(instantly ()
(incf accumulated-time (- (real-time-seconds) start))
(when (enabledp this)
(run looped-flow)))))
(run looped-flow))))))) (run looped-flow)))))))




Expand Down

0 comments on commit b681885

Please sign in to comment.