Client & network general improvement

This commit is contained in:
Thomas
2020-08-31 15:51:18 +02:00
parent 6ea4249ed9
commit 14be55df67
11 changed files with 125 additions and 117 deletions

View File

@@ -6,9 +6,7 @@ const state = {
targetAngle: 0,
color: 'red'
},
players: {
},
updates: [],
settings: {
playerSize: 10,
playerSpeed: 2,
@@ -22,11 +20,20 @@ const state = {
}
const getters = {
// Interpolation position des joueurs
currentPlayers: state => {
if (state.updates.length < 2) return state.updates[0].players
else {
const dt = state.updates[0].time - state.updates[1].time
return state.updates[1].players.map(player => interpolatePlayer(player, dt))
}
}
}
const actions = {
socketConnected ({ commit }) {
commit('SET_CONNECTED')
commit('CLEAR_UPDATE')
},
login ({ commit }, player) {
commit('SET_PLAYER', player)
@@ -35,10 +42,11 @@ const actions = {
commit('SET_SETTINGS', settings)
},
update ({ commit }, update) {
commit('SET_PLAYERS', update)
commit('ADD_UPDATE', update)
},
dead ({ commit }, player) {
commit('SET_PLAYER', player)
commit('CLEAR_UPDATE')
},
error ({ commit }, error) {
alert('Error: ' + error)
@@ -60,9 +68,23 @@ const mutations = {
},
SET_CONNECTED (state) {
state.socketConnected = !state.socketConnected
},
ADD_UPDATE (state, update) {
if (state.updates.length > 2) {
state.updates.shift()
}
update.time = update.time.epochSecond
state.updates.push(update)
},
CLEAR_UPDATE (state) {
state.updates = []
}
}
function interpolatePlayer (player, dt) {
return player
}
export default {
namespaced: true,
state,