mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-26 12:41:40 +00:00
fix marble bumper sounds and make marble update order deterministic
This commit is contained in:
parent
4326a6778e
commit
7c2cd6d738
2 changed files with 54 additions and 8 deletions
|
|
@ -721,7 +721,11 @@ class Marble extends GameObject {
|
||||||
if (contact.force != 0 && !forceObjects.contains(contact.otherObject)) {
|
if (contact.force != 0 && !forceObjects.contains(contact.otherObject)) {
|
||||||
if (contact.otherObject is RoundBumper) {
|
if (contact.otherObject is RoundBumper) {
|
||||||
if (!level.isReplayingMovement && !playedSounds.contains("data/sound/bumperding1.wav") && !this.isNetUpdate) {
|
if (!level.isReplayingMovement && !playedSounds.contains("data/sound/bumperding1.wav") && !this.isNetUpdate) {
|
||||||
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumperding1.wav", ResourceLoader.getAudio, this.soundResources));
|
if (level.marble == cast this)
|
||||||
|
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumperding1.wav", ResourceLoader.getAudio, this.soundResources));
|
||||||
|
else
|
||||||
|
AudioManager.playSound(ResourceLoader.getResource("data/sound/bumperding1.wav", ResourceLoader.getAudio, this.soundResources),
|
||||||
|
this.getAbsPos().getPosition());
|
||||||
playedSounds.push("data/sound/bumperding1.wav");
|
playedSounds.push("data/sound/bumperding1.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2505,6 +2509,14 @@ class Marble extends GameObject {
|
||||||
this.setPosition(x, y, z);
|
this.setPosition(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public inline function getConnectionId() {
|
||||||
|
if (this.connection == null) {
|
||||||
|
return Net.isHost ? 0 : Net.clientId;
|
||||||
|
} else {
|
||||||
|
return this.connection.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override function reset() {
|
public override function reset() {
|
||||||
this.velocity = new Vector();
|
this.velocity = new Vector();
|
||||||
this.collider.velocity = new Vector();
|
this.collider.velocity = new Vector();
|
||||||
|
|
|
||||||
|
|
@ -518,6 +518,13 @@ class MarbleWorld extends Scheduler {
|
||||||
NetCommands.clientIsReady(Net.clientId);
|
NetCommands.clientIsReady(Net.clientId);
|
||||||
if (this.isMultiplayer && Net.isHost) {
|
if (this.isMultiplayer && Net.isHost) {
|
||||||
NetCommands.clientIsReady(-1);
|
NetCommands.clientIsReady(-1);
|
||||||
|
|
||||||
|
// Sort all the marbles so that they are updated in a deterministic order
|
||||||
|
this.marbles.sort((a, b) -> @:privateAccess {
|
||||||
|
var aId = a.connection != null ? a.connection.id : 0; // Must be a host
|
||||||
|
var bId = b.connection != null ? b.connection.id : 0; // Must be a host
|
||||||
|
return (aId > bId) ? 1 : (aId < bId) ? -1 : 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
var cc = 0;
|
var cc = 0;
|
||||||
for (client in Net.clients)
|
for (client in Net.clients)
|
||||||
|
|
@ -535,6 +542,13 @@ class MarbleWorld extends Scheduler {
|
||||||
this.restart(addedMarble); // spawn it
|
this.restart(addedMarble); // spawn it
|
||||||
this.playGui.addPlayer(cc.id, cc.getName(), false);
|
this.playGui.addPlayer(cc.id, cc.getName(), false);
|
||||||
this.playGui.redrawPlayerList();
|
this.playGui.redrawPlayerList();
|
||||||
|
|
||||||
|
// Sort all the marbles so that they are updated in a deterministic order
|
||||||
|
this.marbles.sort((a, b) -> @:privateAccess {
|
||||||
|
var aId = a.getConnectionId();
|
||||||
|
var bId = b.getConnectionId();
|
||||||
|
return (aId > bId) ? 1 : (aId < bId) ? -1 : 0;
|
||||||
|
});
|
||||||
onAdded();
|
onAdded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -545,6 +559,13 @@ class MarbleWorld extends Scheduler {
|
||||||
this.restart(addedMarble); // spawn it
|
this.restart(addedMarble); // spawn it
|
||||||
this.playGui.addPlayer(cc.id, cc.getName(), false);
|
this.playGui.addPlayer(cc.id, cc.getName(), false);
|
||||||
this.playGui.redrawPlayerList();
|
this.playGui.redrawPlayerList();
|
||||||
|
|
||||||
|
// Sort all the marbles so that they are updated in a deterministic order
|
||||||
|
this.marbles.sort((a, b) -> @:privateAccess {
|
||||||
|
var aId = a.getConnectionId();
|
||||||
|
var bId = b.getConnectionId();
|
||||||
|
return (aId > bId) ? 1 : (aId < bId) ? -1 : 0;
|
||||||
|
});
|
||||||
onAdded();
|
onAdded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1627,11 +1648,17 @@ class MarbleWorld extends Scheduler {
|
||||||
fixedDt.dt = 0.032;
|
fixedDt.dt = 0.032;
|
||||||
tickAccumulator -= 0.032;
|
tickAccumulator -= 0.032;
|
||||||
var packets = [];
|
var packets = [];
|
||||||
var myMove = marble.updateServer(fixedDt, collisionWorld, pathedInteriors);
|
|
||||||
var otherMoves = [];
|
var otherMoves = [];
|
||||||
for (client => marble in clientMarbles) {
|
var myMove = null;
|
||||||
otherMoves.push(marble.updateServer(fixedDt, collisionWorld, pathedInteriors));
|
|
||||||
|
for (marble in marbles) {
|
||||||
|
var move = marble.updateServer(fixedDt, collisionWorld, pathedInteriors);
|
||||||
|
if (marble == this.marble)
|
||||||
|
myMove = move;
|
||||||
|
else
|
||||||
|
otherMoves.push(move);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myMove != null && Net.isClient) {
|
if (myMove != null && Net.isClient) {
|
||||||
this.predictions.storeState(marble, myMove.timeState.ticks);
|
this.predictions.storeState(marble, myMove.timeState.ticks);
|
||||||
for (client => marble in clientMarbles) {
|
for (client => marble in clientMarbles) {
|
||||||
|
|
@ -1639,11 +1666,18 @@ class MarbleWorld extends Scheduler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Net.isHost) {
|
if (Net.isHost) {
|
||||||
for (client => othermarble in clientMarbles) { // Oh no!
|
packets.push(marble.packUpdate(myMove, fixedDt));
|
||||||
var mv = otherMoves.shift();
|
for (othermarble in marbles) {
|
||||||
packets.push(marble.packUpdate(myMove, fixedDt));
|
if (othermarble != this.marble) {
|
||||||
packets.push(othermarble.packUpdate(mv, fixedDt));
|
var mv = otherMoves.shift();
|
||||||
|
packets.push(othermarble.packUpdate(mv, fixedDt));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// for (client => othermarble in clientMarbles) { // Oh no!
|
||||||
|
// var mv = otherMoves.shift();
|
||||||
|
// packets.push(marble.packUpdate(myMove, fixedDt));
|
||||||
|
// packets.push(othermarble.packUpdate(mv, fixedDt));
|
||||||
|
// }
|
||||||
var allRecv = true;
|
var allRecv = true;
|
||||||
for (client => marble in clientMarbles) { // Oh no!
|
for (client => marble in clientMarbles) { // Oh no!
|
||||||
// var pktClone = packets.copy();
|
// var pktClone = packets.copy();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue