Permalink
Browse files

Relay movement state

  • Loading branch information...
borodust committed Apr 23, 2017
1 parent 91065e3 commit c05401cbae3ad80e276413180d5fc4a02f8d306d
@@ -39,7 +39,8 @@
(update-proxy dude
(sequence->vec2 (getf dude-state :position))
(sequence->vec2(getf dude-state :rotation))
timestamp))))))))
timestamp
(getf dude-state :movement)))))))))
(defun shoot-ball (player)
@@ -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)))
@@ -77,6 +79,7 @@
;;;
(defclass dude-model (model)
((mesh :initform nil)
(movement-listener :initform nil)
(body :initform nil)
(player :initarg :player)
(program :initform nil)
@@ -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
movement-listener)
this
(>> (resource-flow "mesh.Dude" "Stickman"
"animation.Resting"
@@ -108,11 +112,28 @@
program p))
(-> ((physics)) ()
(setf body (make-instance 'dude-body)))
(call-next-method))))
(call-next-method)
(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
run-animation
+animation-overlap+))
(:east (play-node-animation ani-player
strafe-animation
+animation-overlap+))
(t (play-node-animation ani-player
rest-animation
+animation-overlap+)))))))))))))
(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)))
@@ -38,7 +38,7 @@
(defevent movement-changed ()
(direction))
(player direction))
(defevent trigger-pulled () ())
@@ -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)))
()))))
@@ -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)
timestamp
movement))))
nil)
@@ -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
@@ -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)
@@ -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
@@ -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)
@@ -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))
@@ -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))
proxy
(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)

0 comments on commit c05401c

Please sign in to comment.