mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
dynamic queue production and consumption
This commit is contained in:
parent
43181b687c
commit
ca852396e5
4 changed files with 25 additions and 20 deletions
|
|
@ -243,7 +243,6 @@ class Marble extends GameObject {
|
|||
public var contacts:Array<CollisionInfo> = [];
|
||||
public var bestContact:CollisionInfo;
|
||||
public var contactEntities:Array<CollisionEntity> = [];
|
||||
public var collidingMarbles:Array<Marble> = [];
|
||||
|
||||
var queuedContacts:Array<CollisionInfo> = [];
|
||||
var appliedImpulses:Array<{impulse:Vector, contactImpulse:Bool}> = [];
|
||||
|
|
@ -296,7 +295,6 @@ class Marble extends GameObject {
|
|||
var connection:net.Net.ClientConnection;
|
||||
var moveMotionDir:Vector;
|
||||
var isNetUpdate:Bool = false;
|
||||
var collisionToken:Int = 0;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
|
@ -529,11 +527,6 @@ class Marble extends GameObject {
|
|||
this.contacts = queuedContacts;
|
||||
var c = collisiomWorld.sphereIntersection(this.collider, timeState);
|
||||
this.contactEntities = c.foundEntities;
|
||||
this.collidingMarbles = [];
|
||||
for (e in this.contacts) {
|
||||
if (e.collider is SphereCollisionEntity)
|
||||
this.collidingMarbles.push(cast(e.collider, SphereCollisionEntity).marble);
|
||||
}
|
||||
contacts = contacts.concat(c.contacts);
|
||||
}
|
||||
|
||||
|
|
@ -1689,6 +1682,7 @@ class Marble extends GameObject {
|
|||
marbleUpdate.velocity = this.velocity;
|
||||
marbleUpdate.omega = this.omega;
|
||||
marbleUpdate.move = move;
|
||||
marbleUpdate.moveQueueSize = this.connection != null ? this.connection.moveManager.getQueueSize() : 255;
|
||||
marbleUpdate.serialize(b);
|
||||
return b.getBytes();
|
||||
}
|
||||
|
|
@ -1707,6 +1701,16 @@ class Marble extends GameObject {
|
|||
this.collider.transform.setPosition(p.position);
|
||||
this.velocity = p.velocity;
|
||||
this.omega = p.omega;
|
||||
if (this.controllable && Net.isClient) {
|
||||
// We are client, need to do something about the queue
|
||||
var mm = Net.clientConnection.moveManager;
|
||||
// trace('Queue size: ${mm.getQueueSize()}, server: ${p.moveQueueSize}');
|
||||
if (mm.getQueueSize() / p.moveQueueSize < 2) {
|
||||
mm.stall = true;
|
||||
} else {
|
||||
mm.stall = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1745,11 +1749,6 @@ class Marble extends GameObject {
|
|||
}
|
||||
playedSounds = [];
|
||||
advancePhysics(timeState, move.move, collisionWorld, pathedInteriors);
|
||||
for (marble in this.collidingMarbles) {
|
||||
marble.collisionToken = timeState.ticks;
|
||||
}
|
||||
if (this.collidingMarbles.length != 0)
|
||||
this.collisionToken = timeState.ticks;
|
||||
physicsAccumulator = 0;
|
||||
return move;
|
||||
// if (Net.isHost) {
|
||||
|
|
|
|||
|
|
@ -1072,7 +1072,7 @@ class MarbleWorld extends Scheduler {
|
|||
ackLag = ourQueuedMoves.length;
|
||||
|
||||
if (mvStored != null) {
|
||||
trace('ACK Lag: ${timeState.ticks - mvStored.timeState.ticks} ${ourQueuedMoves.length}');
|
||||
// trace('ACK Lag: ${timeState.ticks - mvStored.timeState.ticks} ${ourQueuedMoves.length}');
|
||||
}
|
||||
|
||||
// Tick the remaining moves (ours)
|
||||
|
|
@ -1087,10 +1087,10 @@ class MarbleWorld extends Scheduler {
|
|||
for (client => arr in lastMoves.otherMarbleUpdates) {
|
||||
if (arr.length > 0) {
|
||||
var m = arr[0];
|
||||
if (m.serverTicks == ourLastMoveTime) {
|
||||
if (m.serverTicks <= ourLastMoveTime) {
|
||||
var marbleToUpdate = clientMarbles[Net.clientIdMap[client]];
|
||||
Debug.drawSphere(@:privateAccess marbleToUpdate.newPos, marbleToUpdate._radius);
|
||||
m.calculationTicks = Std.int(ackLag / 2);
|
||||
m.calculationTicks = Std.int(ackLag);
|
||||
marblesToTick.set(client, m);
|
||||
arr.shift();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ class MoveManager {
|
|||
|
||||
var maxMoves = 45;
|
||||
|
||||
public var stall = false;
|
||||
|
||||
public function new(connection:ClientConnection) {
|
||||
queuedMoves = [];
|
||||
nextMoveId = 0;
|
||||
|
|
@ -46,7 +48,7 @@ class MoveManager {
|
|||
}
|
||||
|
||||
public function recordMove(motionDir:Vector, timeState:TimeState) {
|
||||
if (queuedMoves.length >= maxMoves)
|
||||
if (queuedMoves.length >= maxMoves || stall)
|
||||
return queuedMoves[queuedMoves.length - 1];
|
||||
var move = new Move();
|
||||
move.d = new Vector();
|
||||
|
|
@ -154,6 +156,10 @@ class MoveManager {
|
|||
}
|
||||
}
|
||||
|
||||
public function getQueueSize() {
|
||||
return queuedMoves.length;
|
||||
}
|
||||
|
||||
public function acknowledgeMove(m:Int, timeState:TimeState) {
|
||||
if (m == 65535 || m == -1)
|
||||
return null;
|
||||
|
|
@ -170,7 +176,7 @@ class MoveManager {
|
|||
delta = queuedMoves[0].id - lastAckMoveId;
|
||||
mv = queuedMoves.shift();
|
||||
ackRTT = timeState.ticks - mv.timeState.ticks;
|
||||
maxMoves = Std.int(ackRTT * 1.5);
|
||||
maxMoves = ackRTT + 2;
|
||||
}
|
||||
lastAckMoveId = m;
|
||||
return mv;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class MarbleUpdatePacket implements NetPacket {
|
|||
var position:Vector;
|
||||
var velocity:Vector;
|
||||
var omega:Vector;
|
||||
var collisionToken:Int;
|
||||
var moveQueueSize:Int;
|
||||
|
||||
public function new() {}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ class MarbleUpdatePacket implements NetPacket {
|
|||
b.writeUInt16(clientId);
|
||||
MoveManager.packMove(move, b);
|
||||
b.writeUInt16(serverTicks);
|
||||
b.writeUInt16(collisionToken);
|
||||
b.writeByte(moveQueueSize);
|
||||
b.writeFloat(position.x);
|
||||
b.writeFloat(position.y);
|
||||
b.writeFloat(position.z);
|
||||
|
|
@ -62,7 +62,7 @@ class MarbleUpdatePacket implements NetPacket {
|
|||
clientId = b.readUInt16();
|
||||
move = MoveManager.unpackMove(b);
|
||||
serverTicks = b.readUInt16();
|
||||
collisionToken = b.readUInt16();
|
||||
moveQueueSize = b.readByte();
|
||||
position = new Vector(b.readFloat(), b.readFloat(), b.readFloat());
|
||||
velocity = new Vector(b.readFloat(), b.readFloat(), b.readFloat());
|
||||
omega = new Vector(b.readFloat(), b.readFloat(), b.readFloat());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue