diff --git a/server/assets/wasm/maze-wars.wasm b/server/assets/wasm/maze-wars.wasm index 8b5a769..7081a25 100755 Binary files a/server/assets/wasm/maze-wars.wasm and b/server/assets/wasm/maze-wars.wasm differ diff --git a/server/new.go b/server/new.go index 82489c4..89b6582 100644 --- a/server/new.go +++ b/server/new.go @@ -173,28 +173,28 @@ func wsHandler(s *Store) func(http.ResponseWriter, *http.Request) { } func startLoop(ctx context.Context, s *Store) { + secondTicker := time.NewTicker(time.Second) stateTicker := time.NewTicker(time.Second / 4) - incomeTicker := time.NewTicker(time.Second) // The default TPS on of Ebiten client if 60 so to // emulate that we trigger the move action every TPS - moveTicker := time.NewTicker(time.Second / 60) + tpsTicker := time.NewTicker(time.Second / 60) usersTicker := time.NewTicker(5 * time.Second) for { select { case <-stateTicker.C: actionDispatcher.SyncState(s.Rooms) - case <-incomeTicker.C: + case <-secondTicker.C: actionDispatcher.IncomeTick(s.Rooms) actionDispatcher.WaitRoomCountdownTick() actionDispatcher.SyncWaitingRoom(s.Rooms) - case <-moveTicker.C: + case <-tpsTicker.C: actionDispatcher.TPS(s.Rooms) case <-usersTicker.C: actionDispatcher.SyncUsers(s.Users) case <-ctx.Done(): stateTicker.Stop() - incomeTicker.Stop() - moveTicker.Stop() + secondTicker.Stop() + tpsTicker.Stop() usersTicker.Stop() goto FINISH } diff --git a/server/rooms.go b/server/rooms.go index 60ac0af..216bf7e 100644 --- a/server/rooms.go +++ b/server/rooms.go @@ -179,16 +179,17 @@ func (rs *RoomsStore) Reduce(state, a interface{}) interface{} { rs.mxRooms.Lock() defer rs.mxRooms.Unlock() - if r, ok := rstate.Rooms[act.Room]; ok { - r.Game.Dispatch(act) - } // If no room means that is a broadcast if act.Room == "" { for _, r := range rstate.Rooms { if r.Name != rstate.CurrentWaitingRoom { - r.Game.Dispatch(act) + go r.Game.Dispatch(act) } } + } else { + if r, ok := rstate.Rooms[act.Room]; ok { + go r.Game.Dispatch(act) + } } } diff --git a/store/unit_astar.go b/store/unit_astar.go index f5c3ce6..98ae005 100644 --- a/store/unit_astar.go +++ b/store/unit_astar.go @@ -2,7 +2,7 @@ package store import ( "container/heap" - "fmt" + "strconv" "github.com/xescugc/maze-wars/utils" ) @@ -121,7 +121,7 @@ func straightPathToEnd(m *Map, lid int, s utils.Step) utils.Object { } func calculateObjectKey(o utils.Object) string { - return fmt.Sprintf("%.0f%.0f", o.X, o.Y) + return strconv.FormatFloat(o.X, 'x', -1, 64) + strconv.FormatFloat(o.Y, 'x', -1, 64) } type queueItem struct { diff --git a/store/units.go b/store/units.go index a52bd98..9601f3f 100644 --- a/store/units.go +++ b/store/units.go @@ -248,8 +248,19 @@ func (us *Units) Reduce(state, a interface{}) interface{} { for id, u := range act.SyncState.Units.Units { delete(uids, id) nu := Unit(*u) - + ou, ok := ustate.Units[id] + + if ok { + //If the unit already exists and have the same Hash then ignore the server + //coordinates and path + if ou.HashPath == nu.HashPath { + nu.Path = ou.Path + nu.X = ou.X + nu.Y = ou.Y + } + } ustate.Units[id] = &nu + } for id := range uids { delete(ustate.Units, id)