fix game
Some checks failed
Dynamic Branch Deploy / build-and-deploy (push) Has been cancelled
Some checks failed
Dynamic Branch Deploy / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -371,6 +371,19 @@ func (g *Game) DrawGame(screen *ebiten.Image) {
|
||||
effectiveCamX := g.camX / viewScale
|
||||
g.RenderGround(screen, effectiveCamX)
|
||||
|
||||
// Prediction-Snapshot VOR dem stateMutex holen (verhindert Deadlock:
|
||||
// DrawGame würde sonst stateMutex→predictionMutex halten, während
|
||||
// ReconcileWithServer predictionMutex→stateMutex hält)
|
||||
g.predictionMutex.Lock()
|
||||
snapPrevX := g.prevPredictedX
|
||||
snapPrevY := g.prevPredictedY
|
||||
snapPredX := g.predictedX
|
||||
snapPredY := g.predictedY
|
||||
snapOffX := g.correctionOffsetX
|
||||
snapOffY := g.correctionOffsetY
|
||||
snapPhysTime := g.lastPhysicsTime
|
||||
g.predictionMutex.Unlock()
|
||||
|
||||
// State Locken für Datenzugriff
|
||||
g.stateMutex.Lock()
|
||||
defer g.stateMutex.Unlock()
|
||||
@@ -434,15 +447,13 @@ func (g *Game) DrawGame(screen *ebiten.Image) {
|
||||
// Für lokalen Spieler: Client-Prediction mit Interpolation zwischen Physics-Steps
|
||||
// Physics läuft bei 20/sec, Draw bei 60fps → alpha interpoliert dazwischen
|
||||
if p.Name == g.playerName {
|
||||
g.predictionMutex.Lock()
|
||||
// Interpolations-Alpha: wie weit sind wir zwischen letztem und nächstem Physics-Step?
|
||||
alpha := float64(time.Since(g.lastPhysicsTime)) / float64(50*time.Millisecond)
|
||||
alpha := float64(time.Since(snapPhysTime)) / float64(50*time.Millisecond)
|
||||
if alpha > 1 {
|
||||
alpha = 1
|
||||
}
|
||||
posX = g.prevPredictedX + (g.predictedX-g.prevPredictedX)*alpha + g.correctionOffsetX
|
||||
posY = g.prevPredictedY + (g.predictedY-g.prevPredictedY)*alpha + g.correctionOffsetY
|
||||
g.predictionMutex.Unlock()
|
||||
posX = snapPrevX + (snapPredX-snapPrevX)*alpha + snapOffX
|
||||
posY = snapPrevY + (snapPredY-snapPrevY)*alpha + snapOffY
|
||||
}
|
||||
|
||||
// Wähle Sprite basierend auf Sprung-Status
|
||||
|
||||
Reference in New Issue
Block a user