Add sequence numbers to server broadcasts and client state handling for out-of-order update detection.
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 9m53s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 9m53s
This commit is contained in:
@@ -85,6 +85,13 @@ func (g *Game) wsReadPump() {
|
||||
payloadBytes, _ := json.Marshal(msg.Payload)
|
||||
var state game.GameState
|
||||
if err := json.Unmarshal(payloadBytes, &state); err == nil {
|
||||
// Out-of-Order-Erkennung: Ignoriere alte Updates
|
||||
if state.Sequence > 0 && state.Sequence <= g.lastRecvSeq {
|
||||
// Alte Nachricht - ignorieren
|
||||
continue
|
||||
}
|
||||
g.lastRecvSeq = state.Sequence
|
||||
|
||||
// Server Reconciliation für lokalen Spieler (VOR dem Lock)
|
||||
for _, p := range state.Players {
|
||||
if p.Name == g.playerName {
|
||||
|
||||
@@ -72,6 +72,13 @@ func (g *Game) connectToServer() {
|
||||
payloadBytes, _ := json.Marshal(msg.Payload)
|
||||
var state game.GameState
|
||||
if err := json.Unmarshal(payloadBytes, &state); err == nil {
|
||||
// Out-of-Order-Erkennung: Ignoriere alte Updates
|
||||
if state.Sequence > 0 && state.Sequence <= g.lastRecvSeq {
|
||||
// Alte Nachricht - ignorieren
|
||||
return nil
|
||||
}
|
||||
g.lastRecvSeq = state.Sequence
|
||||
|
||||
// Server Reconciliation für lokalen Spieler (VOR dem Lock)
|
||||
for _, p := range state.Players {
|
||||
if p.Name == g.playerName {
|
||||
|
||||
@@ -92,6 +92,7 @@ type Game struct {
|
||||
pendingInputs map[uint32]InputState // Noch nicht bestätigte Inputs
|
||||
lastServerSeq uint32 // Letzte vom Server bestätigte Sequenz
|
||||
predictionMutex sync.Mutex // Mutex für pendingInputs
|
||||
lastRecvSeq uint32 // Letzte empfangene Server-Sequenznummer (für Out-of-Order-Erkennung)
|
||||
|
||||
// Smooth Correction
|
||||
correctionX float64 // Verbleibende Korrektur in X
|
||||
|
||||
Reference in New Issue
Block a user