From 533037f95bf618f87a81e0a9e382de61ae7f5735 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sat, 6 May 2023 23:32:50 +0530 Subject: [PATCH] fix rewind particles --- src/MarbleWorld.hx | 7 ++++++- src/ParticleSystem.hx | 4 ++-- src/Settings.hx | 7 ++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index ca64e481..84c49c39 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -931,6 +931,8 @@ class MarbleWorld extends Scheduler { } } + var realDt = dt; + if (Key.isDown(Key.R)) { this.rewinding = true; } else { @@ -965,7 +967,10 @@ class MarbleWorld extends Scheduler { ProfilerUI.measure("updateInstances"); this.instanceManager.update(dt); ProfilerUI.measure("updateParticles"); - this.particleManager.update(1000 * timeState.timeSinceLoad, dt); + if (this.rewinding) { + this.particleManager.update(1000 * timeState.timeSinceLoad, -realDt); + } else + this.particleManager.update(1000 * timeState.timeSinceLoad, dt); ProfilerUI.measure("updatePlayGui"); this.playGui.update(timeState); ProfilerUI.measure("updateAudio"); diff --git a/src/ParticleSystem.hx b/src/ParticleSystem.hx index e4be8ed1..3d66375e 100644 --- a/src/ParticleSystem.hx +++ b/src/ParticleSystem.hx @@ -75,13 +75,13 @@ class Particle { var elapsed = time - this.spawnTime; var completion = Util.clamp(elapsed / this.lifeTime, 0, 1); - if (currentAge > this.lifeTime) // Again, rewind needs this + if (currentAge > this.lifeTime || currentAge < 0) // Again, rewind needs this { this.manager.removeParticle(this.data, this); return; } - if (completion == 1) { + if (completion == 1 || completion < 0) { // The particle can die this.manager.removeParticle(this.data, this); return; diff --git a/src/Settings.hx b/src/Settings.hx index 2f3044ec..8919e150 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -50,6 +50,7 @@ typedef ControlsSettings = { var alwaysFreeLook:Bool; var cameraSensitivity:Float; var invertYAxis:Bool; + var rewind:Int; } typedef TouchSettings = { @@ -108,7 +109,8 @@ class Settings { freelook: Key.MOUSE_RIGHT, alwaysFreeLook: true, cameraSensitivity: 0.6, - invertYAxis: false + invertYAxis: false, + rewind: Key.R, }; public static var touchSettings:TouchSettings = { @@ -254,6 +256,9 @@ class Settings { if (json.gamepad != null) { gamepadSettings = json.gamepad; } + if (controlsSettings.rewind == null) { + controlsSettings.rewind = Key.R; + } progression = json.progression; highscoreName = json.highscoreName; } else {