more perf

This commit is contained in:
RandomityGuy 2024-04-30 12:39:05 +05:30
parent 10c1eb5650
commit 9774d6d9a2
5 changed files with 51 additions and 38 deletions

View file

@ -1612,8 +1612,8 @@ class Marble extends GameObject {
tdiff = diff; tdiff = diff;
} }
var expectedPos = finalPosData.position; var expectedPos = finalPosData.position;
// var newPos = expectedPos; var newPos = expectedPos;
var newPos = nudgeToContacts(expectedPos, _radius, finalPosData.foundContacts, finalPosData.foundMarbles); // var newPos = nudgeToContacts(expectedPos, _radius, finalPosData.foundContacts, finalPosData.foundMarbles);
if (this.velocity.lengthSq() > 1e-8) { if (this.velocity.lengthSq() > 1e-8) {
var posDiff = newPos.sub(expectedPos); var posDiff = newPos.sub(expectedPos);

View file

@ -94,14 +94,16 @@ class ProfilerUI {
lastSentMove = @:privateAccess Net.clientConnection.moveManager.queuedMoves[Net.clientConnection.moveManager.queuedMoves.length - 1].id; lastSentMove = @:privateAccess Net.clientConnection.moveManager.queuedMoves[Net.clientConnection.moveManager.queuedMoves.length - 1].id;
} }
instance.networkStats.text = 'Client World Ticks: ${MarbleGame.instance.world.timeState.ticks}\n' if (Net.isClient) {
+ 'Client Marble Ticks: ${@:privateAccess MarbleGame.instance.world.marble.serverTicks}\n' instance.networkStats.text = 'Client World Ticks: ${MarbleGame.instance.world.timeState.ticks}\n'
+ 'Server Ticks: ${@:privateAccess MarbleGame.instance.world.lastMoves.myMarbleUpdate.serverTicks}\n' + 'Client Marble Ticks: ${@:privateAccess MarbleGame.instance.world.marble.serverTicks}\n'
+ 'Client Move Queue Size: ${Net.isClient ? Net.clientConnection.getQueuedMovesLength() : 0}\n' + 'Server Ticks: ${@:privateAccess MarbleGame.instance.world.lastMoves.myMarbleUpdate.serverTicks}\n'
+ 'Server Move Queue Size: ${Net.isClient ? @:privateAccess MarbleGame.instance.world.lastMoves.myMarbleUpdate.moveQueueSize : 0}\n' + 'Client Move Queue Size: ${Net.isClient ? Net.clientConnection.getQueuedMovesLength() : 0}\n'
+ 'Last Sent Move: ${Net.isClient ? lastSentMove : 0}\n' + 'Server Move Queue Size: ${Net.isClient ? @:privateAccess MarbleGame.instance.world.lastMoves.myMarbleUpdate.moveQueueSize : 0}\n'
+ 'Last Ack Move: ${Net.isClient ? @:privateAccess Net.clientConnection.moveManager.lastAckMoveId : 0}\n' + 'Last Sent Move: ${Net.isClient ? lastSentMove : 0}\n'
+ 'Move Ack RTT: ${Net.isClient ? @:privateAccess Net.clientConnection.moveManager.ackRTT : 0}'; + 'Last Ack Move: ${Net.isClient ? @:privateAccess Net.clientConnection.moveManager.lastAckMoveId : 0}\n'
+ 'Move Ack RTT: ${Net.isClient ? @:privateAccess Net.clientConnection.moveManager.ackRTT : 0}';
}
} else { } else {
instance.networkStats.text = ""; instance.networkStats.text = "";
} }

View file

@ -21,7 +21,6 @@ class CollisionWorld {
public var entities:Array<CollisionEntity> = []; public var entities:Array<CollisionEntity> = [];
public var dynamicEntities:Array<CollisionEntity> = []; public var dynamicEntities:Array<CollisionEntity> = [];
public var dynamicOctree:Octree; public var dynamicOctree:Octree;
public var sap:SAP;
public var marbleEntities:Array<SphereCollisionEntity> = []; public var marbleEntities:Array<SphereCollisionEntity> = [];
@ -31,7 +30,6 @@ class CollisionWorld {
this.octree = new Octree(); this.octree = new Octree();
this.dynamicOctree = new Octree(); this.dynamicOctree = new Octree();
this.staticWorld = new CollisionEntity(null); this.staticWorld = new CollisionEntity(null);
this.sap = new SAP();
} }
public function sphereIntersection(spherecollision:SphereCollisionEntity, timeState:TimeState):SphereIntersectionResult { public function sphereIntersection(spherecollision:SphereCollisionEntity, timeState:TimeState):SphereIntersectionResult {
@ -46,40 +44,43 @@ class CollisionWorld {
box.transform(rotQuat.toMatrix()); box.transform(rotQuat.toMatrix());
box.offset(position.x, position.y, position.z); box.offset(position.x, position.y, position.z);
// box.addSpherePos(position.x + velocity.x * timeState.dt, position.y + velocity.y * timeState.dt, position.z + velocity.z * timeState.dt, radius); // box.addSpherePos(position.x + velocity.x * timeState.dt, position.y + velocity.y * timeState.dt, position.z + velocity.z * timeState.dt, radius);
// var intersections = this.octree.boundingSearch(box); var intersections = this.octree.boundingSearch(box);
// var intersections = this.rtree.search([box.xMin, box.yMax, box.zMin], [box.xSize, box.ySize, box.zSize]); // var intersections = this.rtree.search([box.xMin, box.yMax, box.zMin], [box.xSize, box.ySize, box.zSize]);
var contacts = []; var contacts = [];
var foundEntities = []; var foundEntities = [];
// for (obj in intersections) { for (obj in intersections) {
// var entity:CollisionEntity = cast obj; var entity:CollisionEntity = cast obj;
// foundEntities.push(entity); foundEntities.push(entity);
// if (entity.go.isCollideable) { if (entity.go.isCollideable) {
// contacts = contacts.concat(entity.sphereIntersection(spherecollision, timeState)); contacts = contacts.concat(entity.sphereIntersection(spherecollision, timeState));
// }
// }
sap.recompute();
var sapCollisions = sap.getIntersections(spherecollision);
for (obj in sapCollisions) {
if (obj.boundingBox.collide(box) && obj.go.isCollideable) {
contacts = contacts.concat(obj.sphereIntersection(spherecollision, timeState));
} }
} }
// contacts = contacts.concat(this.staticWorld.sphereIntersection(spherecollision, timeState)); // if (marbleEntities.length > 1) {
// marbleSap.recompute();
// var dynSearch = dynamicOctree.boundingSearch(box).map(x -> cast(x, CollisionEntity)); // var sapCollisions = marbleSap.getIntersections(spherecollision);
// for (obj in dynSearch) { // for (obj in sapCollisions) {
// if (obj != spherecollision) { // if (obj.go.isCollideable) {
// if (obj.boundingBox.collide(box) && obj.go.isCollideable)
// contacts = contacts.concat(obj.sphereIntersection(spherecollision, timeState)); // contacts = contacts.concat(obj.sphereIntersection(spherecollision, timeState));
// }
// } // }
// } // }
// contacts = contacts.concat(this.staticWorld.sphereIntersection(spherecollision, timeState));
var dynSearch = dynamicOctree.boundingSearch(box);
for (obj in dynSearch) {
if (obj != spherecollision) {
var col = cast(obj, CollisionEntity);
if (col.boundingBox.collide(box) && col.go.isCollideable)
contacts = contacts.concat(col.sphereIntersection(spherecollision, timeState));
}
}
// for (marb in marbleEntities) { // for (marb in marbleEntities) {
// if (marb != spherecollision) { // if (marb != spherecollision) {
// if (spherecollision.go.isCollideable) { // if (spherecollision.go.isCollideable) {
@ -145,7 +146,6 @@ class CollisionWorld {
public function addEntity(entity:CollisionEntity) { public function addEntity(entity:CollisionEntity) {
this.octree.insert(entity); this.octree.insert(entity);
this.entities.push(entity); this.entities.push(entity);
this.sap.addEntity(entity);
// this.rtree.insert([entity.boundingBox.xMin, entity.boundingBox.yMin, entity.boundingBox.zMin], // this.rtree.insert([entity.boundingBox.xMin, entity.boundingBox.yMin, entity.boundingBox.zMin],
// [entity.boundingBox.xSize, entity.boundingBox.ySize, entity.boundingBox.zSize], entity); // [entity.boundingBox.xSize, entity.boundingBox.ySize, entity.boundingBox.zSize], entity);
@ -163,7 +163,6 @@ class CollisionWorld {
this.dynamicEntities.push(entity); this.dynamicEntities.push(entity);
this.dynamicOctree.insert(entity); this.dynamicOctree.insert(entity);
this.dynamicEntitySet.set(entity, true); this.dynamicEntitySet.set(entity, true);
this.sap.addEntity(entity);
} }
public function removeMovingEntity(entity:CollisionEntity) { public function removeMovingEntity(entity:CollisionEntity) {
@ -171,7 +170,6 @@ class CollisionWorld {
} }
public function updateTransform(entity:CollisionEntity) { public function updateTransform(entity:CollisionEntity) {
this.sap.update(entity);
if (!dynamicEntitySet.exists(entity)) { if (!dynamicEntitySet.exists(entity)) {
this.octree.update(entity); this.octree.update(entity);
} else { } else {

View file

@ -27,8 +27,9 @@ class SphereCollisionEntity extends CollisionEntity {
public override function generateBoundingBox() { public override function generateBoundingBox() {
var boundingBox = new Bounds(); var boundingBox = new Bounds();
var pos = transform.getPosition(); var pos = transform.getPosition();
boundingBox.addSpherePos(pos.x, pos.y, pos.z, radius); boundingBox.addSpherePos(0, 0, 0, radius);
boundingBox.transform3x3(transform); boundingBox.transform(transform);
this.boundingBox = boundingBox; this.boundingBox = boundingBox;
if (Debug.drawBounds) { if (Debug.drawBounds) {

View file

@ -19,10 +19,14 @@ class CubemapRenderer {
var scene:Scene; var scene:Scene;
var nextFaceToRender:Int; var nextFaceToRender:Int;
var facesPerRender:Int = 2; var facesPerRender:Int = 2;
var updateFps:Float = 360.0;
var lastRenderTime:Float = 0;
var usingSky:Bool = false;
public function new(scene:Scene, sky:Sky, useSky = false) { public function new(scene:Scene, sky:Sky, useSky = false) {
this.scene = scene; this.scene = scene;
this.sky = sky; this.sky = sky;
this.usingSky = useSky;
if (useSky) if (useSky)
this.cubemap = sky.cubemap; this.cubemap = sky.cubemap;
else { else {
@ -35,10 +39,18 @@ class CubemapRenderer {
} }
public function render(e:Engine) { public function render(e:Engine) {
if (usingSky)
return;
var start = haxe.Timer.stamp();
if (start - lastRenderTime > 1.0 / updateFps) {
lastRenderTime = start;
} else {
return;
}
var scenecam = scene.camera; var scenecam = scene.camera;
scene.camera = camera; scene.camera = camera;
var start = haxe.Timer.stamp();
var renderedFaces = 0; var renderedFaces = 0;
Renderer.cubemapPass = true; Renderer.cubemapPass = true;
for (i in 0...facesPerRender) { for (i in 0...facesPerRender) {