Skip to content
Permalink
Browse files

Add naive position smoothing

  • Loading branch information
borodust committed Apr 22, 2017
1 parent 5311d42 commit 3f0762c606070a509a6377fac538b05dbd13fcfc
Showing with 59 additions and 12 deletions.
  1. +1 −0 client/src/game-client.lisp
  2. +3 −4 client/src/game-server.lisp
  3. +4 −2 client/src/main.lisp
  4. +5 −6 client/src/player.lisp
  5. +45 −0 client/src/proxy.lisp
  6. +1 −0 mortar-combat.asd
@@ -21,6 +21,7 @@
(rot (rotation-of player)))
(run (-> (client :command :player-info
:name name
:timestamp (real-time-seconds)
:position (list (x pos) (y pos))
:rotation (list (x rot) (y rot)))
()))))
@@ -15,17 +15,16 @@
(with-slots (players) *connector*
(with-message (name) message
(with-instance-lock-held (*connector*)
(let ((player (make-instance 'player)))
(let ((player (make-instance 'proxy)))
(setf (gethash name players) player)
(post (make-player-added-event player) (events))))))
nil)


(defmethod process-command ((command (eql :player-info)) message)
(with-slots (players) *connector*
(with-message (name position rotation) message
(with-message (name position rotation timestamp) message
(with-instance-lock-held (*connector*)
(when-let ((player (gethash name players)))
(setf (position-of player) (sequence->vec2 position)
(rotation-of player) (sequence->vec2 rotation))))))
(update-proxy player (sequence->vec2 position) (sequence->vec2 rotation) timestamp)))))
nil)
@@ -2,7 +2,6 @@


(define-constant +framestep+ 0.017)
(define-constant +player-speed+ 20.0)
(defvar *main-latch* (mt:make-latch))


@@ -187,7 +186,10 @@
(with-slots (remote-server game-client game-server) this
(dolist (server (list remote-server game-client game-server))
(when server
(disconnect-from-server server)))))
(disconnect-from-server server)))
(setf remote-server nil
game-client nil
game-server nil)))


(defun start (configuration-path)
@@ -1,9 +1,14 @@
(in-package :mortar-combat)

(define-constant +player-speed+ 20.0)

(defvar *forward-gaze* (vec3 0.0 0.0 -1.0))


(defgeneric position-of (player))
(defgeneric rotation-of (player))


(defclass player ()
((position :initform (vec2)) ; f(x,y) field space = f(x,-z) global space
(rotation :initform (vec2) :accessor rotation-of)
@@ -27,12 +32,6 @@
position))


(defmethod (setf position-of) ((value vec2) (this player))
(with-slots (position updated-at) this
(setf position value
updated-at (real-time-seconds))))


(defun gaze-of (player)
"In global coords"
(with-slots (rotation) player
@@ -0,0 +1,45 @@
(in-package :mortar-combat)


(defclass proxy ()
((position :initform (vec2)) ; f(x,y) field space = f(x,-z) global space
(rotation :initform (vec2) :accessor rotation-of)
(updated-at :initform (real-time-seconds))

(next-position :initform (vec2))
(next-rotation :initform (vec2))
(next-at :initform (real-time-seconds))

(correction :initform 0.0)))


(defun proxy-lerp-factor (proxy)
(with-slots (updated-at next-at correction) proxy
(let* ((now (- (real-time-seconds) correction))
(delta (- next-at updated-at)))
(if (= delta 0.0) 1.0 (/ (- now next-at) delta)))))


(defmethod position-of ((this proxy))
(with-slots (position next-position) this
(lerp position next-position (proxy-lerp-factor this))))


(defmethod rotation-of ((this proxy))
(with-slots (rotation next-rotation) this
(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)
proxy
(setf correction (- (real-time-seconds) timestamp)

position (position-of proxy)
rotation (rotation-of proxy)
updated-at next-at

next-position pos
next-rotation rot
next-at timestamp)))
@@ -30,6 +30,7 @@
(:file "utils")
(:file "keymap")
(:file "player")
(:file "proxy")
(:file "events")
(:file "camera")
(:file "room")

0 comments on commit 3f0762c

Please sign in to comment.
You can’t perform that action at this time.