Fix vsync timestep???

This commit is contained in:
RandomityGuy 2021-07-02 16:50:00 +05:30
parent da04499211
commit e69a83f2c6
3 changed files with 10 additions and 8 deletions

Binary file not shown.

View file

@ -34,7 +34,7 @@ class Main extends hxd.App {
override function update(dt:Float) { override function update(dt:Float) {
super.update(dt); super.update(dt);
marbleGame.update(dt); marbleGame.update(hxd.Timer.dt);
// world.update(dt); // world.update(dt);
fpsCounter.text = 'FPS: ${this.engine.fps}'; fpsCounter.text = 'FPS: ${this.engine.fps}';
} }

View file

@ -484,11 +484,12 @@ class Marble extends GameObject {
var soFar = 0.0; var soFar = 0.0;
for (k in 0...contacts.length) { for (k in 0...contacts.length) {
var dist = this._radius - contacts[k].contactDistance; var dist = this._radius - contacts[k].contactDistance;
var timeToSeparate = 0.064;
if (dist >= 0) { if (dist >= 0) {
var f1 = this.velocity.sub(contacts[k].velocity).add(dir.multiply(soFar)).dot(contacts[k].normal); var f1 = this.velocity.sub(contacts[k].velocity).add(dir.multiply(soFar)).dot(contacts[k].normal);
var f2 = 0.1 * f1; var f2 = timeToSeparate * f1;
if (f2 < dist) { if (f2 < dist) {
var f3 = (dist - f2) / 0.1; var f3 = (dist - f2) / timeToSeparate;
soFar += f3 / contacts[k].normal.dot(dir); soFar += f3 / contacts[k].normal.dot(dir);
} }
} }
@ -800,24 +801,25 @@ class Marble extends GameObject {
_bounceYet = false; _bounceYet = false;
var contactTime = 0.0; var contactTime = 0.0;
var it = 0;
do { do {
if (timeRemaining <= 0) if (timeRemaining <= 0)
break; break;
var timeStep = 0.008; var timeStep = 0.008;
if (timeRemaining < 0.008) if (timeRemaining < timeStep)
timeStep = timeRemaining; timeStep = timeRemaining;
var tempState = timeState.clone(); var tempState = timeState.clone();
tempState.dt = timeStep; tempState.dt = timeStep;
it++;
if (this.controllable) { if (this.controllable) {
for (interior in pathedInteriors) { for (interior in pathedInteriors) {
interior.pushTickState(); interior.pushTickState();
var l1 = interior.velocity.length();
interior.recomputeVelocity(piTime + timeStep * 2, timeStep * 2); interior.recomputeVelocity(piTime + timeStep * 2, timeStep * 2);
var l2 = interior.velocity.length();
} }
} }
@ -843,7 +845,7 @@ class Marble extends GameObject {
var intersectT = this.getIntersectionTime(timeStep, velocity); var intersectT = this.getIntersectionTime(timeStep, velocity);
if (intersectT < timeStep && intersectT > 0.000001) { if (intersectT < timeStep && intersectT > 0.000001) {
intersectT *= 0.8; // We uh tick the shit to not actually at the contact time cause bruh // intersectT *= 0.8; // We uh tick the shit to not actually at the contact time cause bruh
// intersectT /= 2; // intersectT /= 2;
var diff = timeStep - intersectT; var diff = timeStep - intersectT;
this.velocity = this.velocity.sub(A.multiply(diff)); this.velocity = this.velocity.sub(A.multiply(diff));
@ -908,7 +910,7 @@ class Marble extends GameObject {
contactTime += timeStep; contactTime += timeStep;
timeRemaining -= timeStep; timeRemaining -= timeStep;
} while (true); } while (it <= 10);
this.queuedContacts = []; this.queuedContacts = [];
this.updateRollSound(contactTime / timeState.dt, this._slipAmount); this.updateRollSound(contactTime / timeState.dt, this._slipAmount);