Add platform-specific implementations for assets, audio, WebSocket, and rendering on Desktop and WebAssembly platforms. Introduce embedded assets for WebAssembly and native file handling for Desktop. Add platform-specific chunk loading and game state synchronization.
This commit is contained in:
@@ -63,20 +63,60 @@ func (g *Game) ReconcileWithServer(serverState game.PlayerState) {
|
||||
}
|
||||
}
|
||||
|
||||
// Setze vorhergesagte Position auf Server-Position
|
||||
g.predictedX = serverState.X
|
||||
g.predictedY = serverState.Y
|
||||
g.predictedVX = serverState.VX
|
||||
g.predictedVY = serverState.VY
|
||||
g.predictedGround = serverState.OnGround
|
||||
// Temporäre Position für Replay
|
||||
replayX := serverState.X
|
||||
replayY := serverState.Y
|
||||
replayVX := serverState.VX
|
||||
replayVY := serverState.VY
|
||||
replayGround := serverState.OnGround
|
||||
|
||||
// Replay alle noch nicht bestätigten Inputs
|
||||
// (Sortiert nach Sequenz)
|
||||
if len(g.pendingInputs) > 0 {
|
||||
for seq := g.lastServerSeq + 1; seq <= g.inputSequence; seq++ {
|
||||
if input, ok := g.pendingInputs[seq]; ok {
|
||||
// Temporär auf Replay-Position setzen
|
||||
oldX, oldY := g.predictedX, g.predictedY
|
||||
oldVX, oldVY := g.predictedVX, g.predictedVY
|
||||
oldGround := g.predictedGround
|
||||
|
||||
g.predictedX = replayX
|
||||
g.predictedY = replayY
|
||||
g.predictedVX = replayVX
|
||||
g.predictedVY = replayVY
|
||||
g.predictedGround = replayGround
|
||||
|
||||
g.ApplyInput(input)
|
||||
|
||||
replayX = g.predictedX
|
||||
replayY = g.predictedY
|
||||
replayVX = g.predictedVX
|
||||
replayVY = g.predictedVY
|
||||
replayGround = g.predictedGround
|
||||
|
||||
// Zurücksetzen
|
||||
g.predictedX = oldX
|
||||
g.predictedY = oldY
|
||||
g.predictedVX = oldVX
|
||||
g.predictedVY = oldVY
|
||||
g.predictedGround = oldGround
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Berechne Differenz zwischen aktueller Prediction und Server-Replay
|
||||
diffX := replayX - g.predictedX
|
||||
diffY := replayY - g.predictedY
|
||||
|
||||
// Nur korrigieren wenn Differenz signifikant (> 5 Pixel)
|
||||
const threshold = 5.0
|
||||
if diffX*diffX+diffY*diffY > threshold*threshold {
|
||||
// Speichere Korrektur für sanfte Interpolation
|
||||
g.correctionX = diffX
|
||||
g.correctionY = diffY
|
||||
}
|
||||
|
||||
// Velocity und Ground immer sofort übernehmen
|
||||
g.predictedVX = replayVX
|
||||
g.predictedVY = replayVY
|
||||
g.predictedGround = replayGround
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user