From 87ff14b6b8ee3a877c8de8aca7d0dce5d1080af2 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:21:45 +0530 Subject: [PATCH] fix spectate bug --- src/CameraController.hx | 2 +- src/Marble.hx | 5 ++++- src/MarbleWorld.hx | 28 +++++++++++++++++----------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/CameraController.hx b/src/CameraController.hx index 8b6d8880..7954b94f 100644 --- a/src/CameraController.hx +++ b/src/CameraController.hx @@ -389,7 +389,7 @@ class CameraController extends Object { return; } - var marblePosition = level.marbles[spectateMarbleIndex].getAbsPos().getPosition(); + var marblePosition = @:privateAccess level.marbles[spectateMarbleIndex].lastRenderPos; var up = new Vector(0, 0, 1); up.transform(orientationQuat.toMatrix()); var directionVector = new Vector(1, 0, 0); diff --git a/src/Marble.hx b/src/Marble.hx index 73e22214..2ec602ea 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -2123,7 +2123,10 @@ class Marble extends GameObject { } physicsAccumulator += timeState.dt; - if (this.controllable && this.level != null && !this.level.rewinding) { + if (this.controllable + && this.level != null + && !this.level.rewinding + && !(Net.clientSpectate || Net.hostSpectate)) { // Separately update the camera if spectate // this.camera.startCenterCamera(); this.camera.update(timeState.currentAttemptTime, timeState.dt); } diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index b9377728..633a3aba 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1506,26 +1506,28 @@ class MarbleWorld extends Scheduler { } // marble.unpackUpdate(ourMove); // needsPrediction |= 1 << Net.clientId; - if (ourMoveStruct != null) { - var ourPred = predictions.retrieveState(marble, ourMoveStruct.timeState.ticks); - if (ourPred != null) { - if (ourPred.getError(ourMove) > 0.01) { + if (!Net.clientSpectate) { + if (ourMoveStruct != null) { + var ourPred = predictions.retrieveState(marble, ourMoveStruct.timeState.ticks); + if (ourPred != null) { + if (ourPred.getError(ourMove) > 0.01) { + // trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); + marble.unpackUpdate(ourMove); + needsPrediction |= 1 << Net.clientId; + predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); + } + } else { // trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); marble.unpackUpdate(ourMove); needsPrediction |= 1 << Net.clientId; predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); } } else { - // trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); + // trace('Desync in General'); marble.unpackUpdate(ourMove); needsPrediction |= 1 << Net.clientId; - predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); + // predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); } - } else { - // trace('Desync in General'); - marble.unpackUpdate(ourMove); - needsPrediction |= 1 << Net.clientId; - // predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); } } } @@ -1968,6 +1970,10 @@ class MarbleWorld extends Scheduler { for (client => marble in clientMarbles) { marble.updateClient(timeState, this.pathedInteriors); } + if (Net.clientSpectate || Net.hostSpectate) { + // this.camera.startCenterCamera(); + marble.camera.update(timeState.currentAttemptTime, timeState.dt); + } } else { for (marble in marbles) { marble.update(timeState, collisionWorld, this.pathedInteriors);