From a169823fa6bb1924bc6e0a4c67c1faaeb57e9e7b Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:41:06 +0530 Subject: [PATCH] netcode tweaks --- src/MarbleWorld.hx | 22 ++++++++++++---------- src/net/MarblePredictionStore.hx | 4 ++-- src/net/MarbleUpdateQueue.hx | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 678442b2..9dff9920 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1099,7 +1099,7 @@ class MarbleWorld extends Scheduler { if (otherPred.getError(lastMove) > 0.1) { Debug.drawSphere(@:privateAccess clientMarbles[Net.clientIdMap[client]].newPos, 0.2, 0.5); // trace('Prediction error: ${otherPred.getError(lastMove)}'); - trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); + // trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); clientMarbles[Net.clientIdMap[client]].unpackUpdate(lastMove); needsPrediction |= 1 << client; arr.packets.insert(0, lastMove); @@ -1107,7 +1107,7 @@ class MarbleWorld extends Scheduler { } } else { Debug.drawSphere(@:privateAccess clientMarbles[Net.clientIdMap[client]].newPos, 0.2, 0.5); - trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); + // trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); clientMarbles[Net.clientIdMap[client]].unpackUpdate(lastMove); needsPrediction |= 1 << client; arr.packets.insert(0, lastMove); @@ -1115,7 +1115,7 @@ class MarbleWorld extends Scheduler { } } else { Debug.drawSphere(@:privateAccess clientMarbles[Net.clientIdMap[client]].newPos, 0.2, 0.5); - trace('Desync in General'); + // trace('Desync in General'); clientMarbles[Net.clientIdMap[client]].unpackUpdate(lastMove); needsPrediction |= 1 << client; arr.packets.insert(0, lastMove); @@ -1130,19 +1130,19 @@ class MarbleWorld extends Scheduler { var ourPred = predictions.retrieveState(marble, ourMoveStruct.timeState.ticks); if (ourPred != null) { if (ourPred.getError(ourMove) > 0.1) { - trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); + // 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 for tick ${ourMoveStruct.timeState.ticks}'); marble.unpackUpdate(ourMove); needsPrediction |= 1 << Net.clientId; predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); } } else { - trace('Desync in General'); + // trace('Desync in General'); marble.unpackUpdate(ourMove); needsPrediction |= 1 << Net.clientId; // predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); @@ -1168,7 +1168,7 @@ class MarbleWorld extends Scheduler { advanceTimeState.dt = 0.032; advanceTimeState.ticks = ourLastMoveTime; - if (marbleNeedsPrediction > 0) { + if (marbleNeedsPrediction & (1 << Net.clientId) > 0) { // Only for our clients pls // if (qm != null) { // var mvs = qm.powerupStates.copy(); for (pw in marble.level.powerUps) { @@ -1202,7 +1202,7 @@ class MarbleWorld extends Scheduler { var marbleToUpdate = clientMarbles[Net.clientIdMap[client]]; // Debug.drawSphere(@:privateAccess marbleToUpdate.newPos, marbleToUpdate._radius); - var distFromUs = @:privateAccess marbleToUpdate.newPos.distance(this.marble.newPos); + // var distFromUs = @:privateAccess marbleToUpdate.newPos.distance(this.marble.newPos); // if (distFromUs < 5) m.calculationTicks = ourQueuedMoves.length; // else @@ -1237,7 +1237,7 @@ class MarbleWorld extends Scheduler { @:privateAccess marbleToUpdate.isNetUpdate = true; @:privateAccess marbleToUpdate.moveMotionDir = m.move.motionDir; @:privateAccess marbleToUpdate.advancePhysics(advanceTimeState, mv, this.collisionWorld, this.pathedInteriors); - this.predictions.storeState(marbleToUpdate, move.timeState.ticks); + this.predictions.storeState(marbleToUpdate, @:privateAccess marbleToUpdate.serverTicks); @:privateAccess marbleToUpdate.isNetUpdate = false; m.calculationTicks--; } @@ -1475,7 +1475,7 @@ class MarbleWorld extends Scheduler { } this.predictions.storeState(marble, myMove.timeState.ticks); for (client => marble in clientMarbles) { - this.predictions.storeState(marble, myMove.timeState.ticks); + this.predictions.storeState(marble, @:privateAccess marble.serverTicks); } if (Net.isHost) { for (client => othermarble in clientMarbles) { // Oh no! @@ -1554,6 +1554,8 @@ class MarbleWorld extends Scheduler { if (this.playGui != null && _ready) this.playGui.render(e); if (_instancesNeedsUpdate) { + if (this.radar != null) + this.radar.render(); ProfilerUI.measure("updateInstances"); this.instanceManager.render(); if (this.marble != null && this.marble.cubemapRenderer != null) { diff --git a/src/net/MarblePredictionStore.hx b/src/net/MarblePredictionStore.hx index b31fc401..7f7da41a 100644 --- a/src/net/MarblePredictionStore.hx +++ b/src/net/MarblePredictionStore.hx @@ -30,8 +30,8 @@ class MarblePrediction { if (p.netFlags != 0) subs += 1; // if (p.powerUpId != powerupItemId) - if (tick % 10 == 0) - subs += 1; // temp + // if (tick % 10 == 0) + // subs += 1; // temp // if (isControl) // subs += Math.abs(blastAmount - p.blastAmount); return subs; diff --git a/src/net/MarbleUpdateQueue.hx b/src/net/MarbleUpdateQueue.hx index fae750ec..42c9a18c 100644 --- a/src/net/MarbleUpdateQueue.hx +++ b/src/net/MarbleUpdateQueue.hx @@ -26,8 +26,8 @@ class MarbleUpdateQueue { public function enqueue(update:MarbleUpdatePacket) { var cc = update.clientId; if (cc != Net.clientId) { - if (myMarbleUpdate != null && update.serverTicks > myMarbleUpdate.serverTicks) - ourMoveApplied = true; + // if (myMarbleUpdate != null && update.serverTicks > myMarbleUpdate.serverTicks) + // ourMoveApplied = true; if (otherMarbleUpdates.exists(cc)) { var otherUpdate = otherMarbleUpdates[cc]; var ourList = otherUpdate.packets;