fix id allocation and marble nan

This commit is contained in:
RandomityGuy 2024-05-31 19:06:34 +05:30
parent 2a28e70af8
commit 5370b0e207
2 changed files with 43 additions and 1 deletions

View file

@ -760,6 +760,8 @@ class Marble extends GameObject {
}
function computeMoveForces(m:Move, aControl:Vector, desiredOmega:Vector) {
if (this.currentUp == null)
this.currentUp = new Vector(0, 0, 1);
var currentGravityDir = this.currentUp.multiply(-1);
var R = currentGravityDir.multiply(-this._radius);
var rollVelocity = this.omega.cross(R);
@ -1608,6 +1610,11 @@ class Marble extends GameObject {
lastMove = m;
}
if (m == null) {
m = new Move();
m.d = new Vector();
}
if (this.blastTicks < (30000 >> 5))
this.blastTicks += 1;
@ -1670,6 +1677,16 @@ class Marble extends GameObject {
stoppedPaths = this.velocityCancel(timeState.currentAttemptTime, timeStep, isCentered, false, stoppedPaths, pathedInteriors);
var A = this.getExternalForces(tempState, m);
var a = this.applyContactForces(timeStep, m, isCentered, aControl, desiredOmega, A);
// NaN check so OpenAL doesn't freak out
if (Math.isNaN(A.lengthSq())) {
A.set(0, 0, 0);
}
if (Math.isNaN(a.lengthSq())) {
a.set(0, 0, 0);
}
this.velocity.set(this.velocity.x + A.x * timeStep, this.velocity.y + A.y * timeStep, this.velocity.z + A.z * timeStep);
this.omega.set(this.omega.x + a.x * timeStep, this.omega.y + a.y * timeStep, this.omega.z + a.z * timeStep);
if (this.mode == Start) {

View file

@ -74,6 +74,7 @@ class Net {
public static var lobbyClientReady:Bool;
public static var hostReady:Bool;
static var clientIdAllocs:Int = 1;
public static var clientId:Int;
public static var networkRNG:Float;
public static var clients:Map<RTCPeerConnection, GameConnection> = [];
@ -348,6 +349,7 @@ class Net {
Net.client = null;
Net.clientDatachannel = null;
Net.clientId = 0;
Net.clientIdAllocs = 1;
Net.clients.clear();
Net.clientIdMap.clear();
Net.clientConnection = null;
@ -366,6 +368,7 @@ class Net {
Net.isClient = false;
Net.isHost = false;
Net.clientId = 0;
Net.clientIdAllocs = 1;
Net.clients.clear();
Net.clientIdMap.clear();
MasterServerClient.disconnectFromMasterServer();
@ -440,7 +443,11 @@ class Net {
}
static function onClientConnect(c:RTCPeerConnection, dc:RTCDataChannel, dcu:RTCDataChannel, joiningPrivate:Bool) {
clientId += 1;
var clientId = allocateClientId();
if (clientId == -1) {
c.close();
return; // Failed to allocate ID
}
var cc = new ClientConnection(clientId, c, dc, dcu);
clients.set(c, cc);
cc.isPrivate = joiningPrivate;
@ -528,6 +535,10 @@ class Net {
return;
NetCommands.clientDisconnected(cc.id);
if (cc.id != 0) {
freeClientId(cc.id);
}
serverInfo.players = 1;
for (k => v in clientIdMap) { // Recount
serverInfo.players++;
@ -734,6 +745,20 @@ class Net {
}
}
static function allocateClientId() {
for (id in 0...32) {
if (Net.clientIdAllocs & (1 << id) == 0) {
Net.clientIdAllocs |= (1 << id);
return id;
}
}
return -1;
}
static function freeClientId(id:Int) {
Net.clientIdAllocs &= ~(1 << id);
}
public static function sendPacketToAll(packetData:OutputBitStream) {
var bytes = packetData.getBytes();
for (c => v in clients) {