Skip to content


Browse files Browse the repository at this point in the history
Relay movement state
  • Loading branch information
borodust committed Apr 23, 2017
1 parent 91065e3 commit c05401c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 16 deletions.
3 changes: 2 additions & 1 deletion client/src/arena.lisp
Expand Up @@ -39,7 +39,8 @@
(update-proxy dude
(sequence->vec2 (getf dude-state :position))
(sequence->vec2(getf dude-state :rotation))
(getf dude-state :movement)))))))))

(defun shoot-ball (player)
Expand Down
29 changes: 25 additions & 4 deletions client/src/dude.lisp
@@ -1,6 +1,8 @@
(in-package :mortar-combat)

(define-constant +animation-overlap+ 0.15)

(defvar *dude-bounds-initial-position* (vec4 0.0 7.5 0.0 1.0))
(defvar *dude-bounds-initial-rotation* (euler-angles->mat4 (vec4 (/ pi 2) 0.0 0.0)))

Expand Down Expand Up @@ -77,6 +79,7 @@
(defclass dude-model (model)
((mesh :initform nil)
(movement-listener :initform nil)
(body :initform nil)
(player :initarg :player)
(program :initform nil)
Expand All @@ -91,8 +94,9 @@

(defmethod initialization-flow ((this dude-model) &key)
(with-slots (mesh animation skeleton program body
strafe-animation run-animation rest-animation)
(with-slots (mesh animation skeleton program body (dude player)
strafe-animation run-animation rest-animation
(>> (resource-flow "mesh.Dude" "Stickman"
Expand All @@ -108,11 +112,28 @@
program p))
(-> ((physics)) ()
(setf body (make-instance 'dude-body)))
(instantly ()
(let ((ani-player (find-node (model-root-of this) :dude-animation)))
(setf movement-listener
(subscribe-body-to (movement-changed (player direction)) (events)
(run (-> ((mortar-combat)) ()
(when (eq dude player)
(case direction
(:north (play-node-animation ani-player
(:east (play-node-animation ani-player
(t (play-node-animation ani-player

(defmethod discard-node ((this dude-model))
(with-slots (body) this
(with-slots (body movement-listener) this
(unsubscribe-from 'movement-changed movement-listener (events))
(dispose body)))

Expand Down
2 changes: 1 addition & 1 deletion client/src/events.lisp
Expand Up @@ -38,7 +38,7 @@

(defevent movement-changed ()
(player direction))

(defevent trigger-pulled () ())
1 change: 1 addition & 0 deletions client/src/game-client.lisp
Expand Up @@ -24,6 +24,7 @@
:no-reply t
:name (name-of player)
:timestamp (real-time-seconds)
:movement (movement-of player)
:position (list (x pos) (y pos))
:rotation (list (x rot) (y rot)))
Expand Down
11 changes: 8 additions & 3 deletions client/src/game-server.lisp
Expand Up @@ -22,9 +22,13 @@

(defmethod process-command ((command (eql :player-info)) message)
(with-slots (arena) *connector*
(with-message (name position rotation timestamp) message
(with-message (name position rotation timestamp movement) message
(when-let ((player (find-dude arena name)))
(update-proxy player (sequence->vec2 position) (sequence->vec2 rotation) timestamp))))
(update-proxy player
(sequence->vec2 position)
(sequence->vec2 rotation)

Expand All @@ -35,7 +39,8 @@
(rot (rotation-of p)))
(list :name (name-of p)
:position (list (x pos) (y pos))
:rotation (list (x rot) (y rot))))))
:rotation (list (x rot) (y rot))
:movement (movement-of p)))))
(let ((proxies (mapcar #'player-info (cons (player-of arena) (dudes-of arena)))))
(run (-> (server :command :game-state
:no-reply t
Expand Down
5 changes: 3 additions & 2 deletions client/src/main.lisp
Expand Up @@ -104,7 +104,7 @@

(defmethod initialize-system :after ((this mortar-combat))
(with-slots (scene keymap task-queue game-client identity) this
(with-slots (scene keymap task-queue game-client identity arena) this
(register-resource-loader (make-resource-loader (asset-path "font.brf")
(asset-path "dude-and-mortar.brf")))
(register-event-classes (events)
Expand Down Expand Up @@ -144,7 +144,8 @@
('(:w :d) :north-east)
('(:s :a) :south-west)
('(:s :d) :south-east))))))
(post (make-movement-changed direction) eve))))
(when arena
(post (make-movement-changed (player-of arena) direction) eve)))))
(update-buttons (button)
(lambda (state)
(case state
Expand Down
3 changes: 2 additions & 1 deletion client/src/player.lisp
Expand Up @@ -69,7 +69,8 @@

(defmethod initialize-instance :after ((this player) &key)
(flet ((update-movement (ev)
(setf (movement-of this) (direction-from ev)))
(when (eq (player-from ev) this)
(setf (movement-of this) (direction-from ev))))
(update-rotation (ev)
(look-at this (ax-from ev) (ay-from ev))))
(register-event-handler 'camera-rotated #'update-rotation)
Expand Down
13 changes: 9 additions & 4 deletions client/src/proxy.lisp
Expand Up @@ -3,7 +3,7 @@

(defclass proxy ()
((name :initarg :name :initform (error ":name missing") :reader name-of)
(movement :initform nil)
(movement :initform nil :reader movement-of)
(position :initform (vec2)) ; f(x,y) field space = f(x,-z) global space
(rotation :initform (vec2) :reader rotation-of)
(updated-at :initform (real-time-seconds))
Expand Down Expand Up @@ -32,10 +32,15 @@
(lerp rotation next-rotation (proxy-lerp-factor this))))

(defun update-proxy (proxy pos rot timestamp)
(with-slots (next-position next-at position updated-at
correction rotation next-rotation)
(defun update-proxy (proxy pos rot timestamp movement)
(with-slots (next-position
next-at position updated-at
correction rotation next-rotation
(this-movement movement))
(unless (eq this-movement movement)
(setf this-movement movement)
(post (make-movement-changed proxy movement) (events)))
(setf correction (- (real-time-seconds) timestamp)

position (position-of proxy)
Expand Down

0 comments on commit c05401c

Please sign in to comment.