netcode tweaks

This commit is contained in:
RandomityGuy 2024-03-20 18:41:06 +05:30
parent c94fddb4b2
commit a108e01873
3 changed files with 16 additions and 14 deletions

View file

@ -1100,7 +1100,7 @@ class MarbleWorld extends Scheduler {
if (otherPred.getError(lastMove) > 0.1) { if (otherPred.getError(lastMove) > 0.1) {
Debug.drawSphere(@:privateAccess clientMarbles[Net.clientIdMap[client]].newPos, 0.2, 0.5); Debug.drawSphere(@:privateAccess clientMarbles[Net.clientIdMap[client]].newPos, 0.2, 0.5);
// trace('Prediction error: ${otherPred.getError(lastMove)}'); // 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); clientMarbles[Net.clientIdMap[client]].unpackUpdate(lastMove);
needsPrediction |= 1 << client; needsPrediction |= 1 << client;
arr.packets.insert(0, lastMove); arr.packets.insert(0, lastMove);
@ -1108,7 +1108,7 @@ class MarbleWorld extends Scheduler {
} }
} else { } else {
Debug.drawSphere(@:privateAccess clientMarbles[Net.clientIdMap[client]].newPos, 0.2, 0.5); 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); clientMarbles[Net.clientIdMap[client]].unpackUpdate(lastMove);
needsPrediction |= 1 << client; needsPrediction |= 1 << client;
arr.packets.insert(0, lastMove); arr.packets.insert(0, lastMove);
@ -1116,7 +1116,7 @@ class MarbleWorld extends Scheduler {
} }
} else { } else {
Debug.drawSphere(@:privateAccess clientMarbles[Net.clientIdMap[client]].newPos, 0.2, 0.5); 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); clientMarbles[Net.clientIdMap[client]].unpackUpdate(lastMove);
needsPrediction |= 1 << client; needsPrediction |= 1 << client;
arr.packets.insert(0, lastMove); arr.packets.insert(0, lastMove);
@ -1131,19 +1131,19 @@ class MarbleWorld extends Scheduler {
var ourPred = predictions.retrieveState(marble, ourMoveStruct.timeState.ticks); var ourPred = predictions.retrieveState(marble, ourMoveStruct.timeState.ticks);
if (ourPred != null) { if (ourPred != null) {
if (ourPred.getError(ourMove) > 0.1) { if (ourPred.getError(ourMove) > 0.1) {
trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); // trace('Desync for tick ${ourMoveStruct.timeState.ticks}');
marble.unpackUpdate(ourMove); marble.unpackUpdate(ourMove);
needsPrediction |= 1 << Net.clientId; needsPrediction |= 1 << Net.clientId;
predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks);
} }
} else { } else {
trace('Desync for tick ${ourMoveStruct.timeState.ticks}'); // trace('Desync for tick ${ourMoveStruct.timeState.ticks}');
marble.unpackUpdate(ourMove); marble.unpackUpdate(ourMove);
needsPrediction |= 1 << Net.clientId; needsPrediction |= 1 << Net.clientId;
predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks);
} }
} else { } else {
trace('Desync in General'); // trace('Desync in General');
marble.unpackUpdate(ourMove); marble.unpackUpdate(ourMove);
needsPrediction |= 1 << Net.clientId; needsPrediction |= 1 << Net.clientId;
// predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks); // predictions.clearStatesAfterTick(marble, ourMoveStruct.timeState.ticks);
@ -1169,7 +1169,7 @@ class MarbleWorld extends Scheduler {
advanceTimeState.dt = 0.032; advanceTimeState.dt = 0.032;
advanceTimeState.ticks = ourLastMoveTime; advanceTimeState.ticks = ourLastMoveTime;
if (marbleNeedsPrediction > 0) { if (marbleNeedsPrediction & (1 << Net.clientId) > 0) { // Only for our clients pls
// if (qm != null) { // if (qm != null) {
// var mvs = qm.powerupStates.copy(); // var mvs = qm.powerupStates.copy();
for (pw in marble.level.powerUps) { for (pw in marble.level.powerUps) {
@ -1203,7 +1203,7 @@ class MarbleWorld extends Scheduler {
var marbleToUpdate = clientMarbles[Net.clientIdMap[client]]; var marbleToUpdate = clientMarbles[Net.clientIdMap[client]];
// Debug.drawSphere(@:privateAccess marbleToUpdate.newPos, marbleToUpdate._radius); // 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) // if (distFromUs < 5)
m.calculationTicks = ourQueuedMoves.length; m.calculationTicks = ourQueuedMoves.length;
// else // else
@ -1238,7 +1238,7 @@ class MarbleWorld extends Scheduler {
@:privateAccess marbleToUpdate.isNetUpdate = true; @:privateAccess marbleToUpdate.isNetUpdate = true;
@:privateAccess marbleToUpdate.moveMotionDir = m.move.motionDir; @:privateAccess marbleToUpdate.moveMotionDir = m.move.motionDir;
@:privateAccess marbleToUpdate.advancePhysics(advanceTimeState, mv, this.collisionWorld, this.pathedInteriors); @: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; @:privateAccess marbleToUpdate.isNetUpdate = false;
m.calculationTicks--; m.calculationTicks--;
} }
@ -1476,7 +1476,7 @@ class MarbleWorld extends Scheduler {
} }
this.predictions.storeState(marble, myMove.timeState.ticks); this.predictions.storeState(marble, myMove.timeState.ticks);
for (client => marble in clientMarbles) { for (client => marble in clientMarbles) {
this.predictions.storeState(marble, myMove.timeState.ticks); this.predictions.storeState(marble, @:privateAccess marble.serverTicks);
} }
if (Net.isHost) { if (Net.isHost) {
for (client => othermarble in clientMarbles) { // Oh no! for (client => othermarble in clientMarbles) { // Oh no!
@ -1555,6 +1555,8 @@ class MarbleWorld extends Scheduler {
if (this.playGui != null && _ready) if (this.playGui != null && _ready)
this.playGui.render(e); this.playGui.render(e);
if (_instancesNeedsUpdate) { if (_instancesNeedsUpdate) {
if (this.radar != null)
this.radar.render();
ProfilerUI.measure("updateInstances"); ProfilerUI.measure("updateInstances");
this.instanceManager.render(); this.instanceManager.render();
if (this.marble != null && this.marble.cubemapRenderer != null && _ready) { if (this.marble != null && this.marble.cubemapRenderer != null && _ready) {

View file

@ -30,8 +30,8 @@ class MarblePrediction {
if (p.netFlags != 0) if (p.netFlags != 0)
subs += 1; subs += 1;
// if (p.powerUpId != powerupItemId) // if (p.powerUpId != powerupItemId)
if (tick % 10 == 0) // if (tick % 10 == 0)
subs += 1; // temp // subs += 1; // temp
// if (isControl) // if (isControl)
// subs += Math.abs(blastAmount - p.blastAmount); // subs += Math.abs(blastAmount - p.blastAmount);
return subs; return subs;

View file

@ -26,8 +26,8 @@ class MarbleUpdateQueue {
public function enqueue(update:MarbleUpdatePacket) { public function enqueue(update:MarbleUpdatePacket) {
var cc = update.clientId; var cc = update.clientId;
if (cc != Net.clientId) { if (cc != Net.clientId) {
if (myMarbleUpdate != null && update.serverTicks > myMarbleUpdate.serverTicks) // if (myMarbleUpdate != null && update.serverTicks > myMarbleUpdate.serverTicks)
ourMoveApplied = true; // ourMoveApplied = true;
if (otherMarbleUpdates.exists(cc)) { if (otherMarbleUpdates.exists(cc)) {
var otherUpdate = otherMarbleUpdates[cc]; var otherUpdate = otherMarbleUpdates[cc];
var ourList = otherUpdate.packets; var ourList = otherUpdate.packets;