From 98b6781970bfd9bcb7deb0df58eaae8c58e62f69 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:44:49 +0530 Subject: [PATCH] slightly better explodables --- src/MarbleWorld.hx | 16 +++++++++++----- src/ParticleSystem.hx | 9 +++++++++ src/net/ExplodablePredictionStore.hx | 13 ++++++++++++- src/net/GemPredictionStore.hx | 6 ++++++ src/net/PowerupPredictionStore.hx | 6 ++++++ src/shapes/Explodable.hx | 11 ++++++++--- 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 74527df9..245c9228 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -148,6 +148,7 @@ class MarbleWorld extends Scheduler { public var powerUps:Array = []; public var forceObjects:Array = []; public var explodables:Array = []; + public var explodablesToTick:Array = []; public var triggers:Array = []; public var gems:Array = []; public var namedObjects:Map = []; @@ -278,7 +279,7 @@ class MarbleWorld extends Scheduler { predictions = new MarblePredictionStore(); powerupPredictions = new PowerupPredictionStore(); gemPredictions = new GemPredictionStore(); - explodablePredictions = new ExplodablePredictionStore(); + explodablePredictions = new ExplodablePredictionStore(cast this); } } @@ -616,9 +617,12 @@ class MarbleWorld extends Scheduler { startTime = 1e8; lastMoves = new MarbleUpdateQueue(); predictions = new MarblePredictionStore(); - powerupPredictions = new PowerupPredictionStore(); - gemPredictions = new GemPredictionStore(); - explodablePredictions = new ExplodablePredictionStore(); + powerupPredictions.reset(); + gemPredictions.reset(); + explodablePredictions.reset(); + for (exp in explodables) { + exp.lastContactTick = -100000; + } } } @@ -1506,9 +1510,11 @@ class MarbleWorld extends Scheduler { if (pw.pickupClient != -1 && marbleNeedsPrediction & (1 << pw.pickupClient) > 0) pw.lastPickUpTime = powerupPredictions.getState(pw.netIndex); } - for (exp in explodables) { + for (expT in explodablesToTick) { + var exp = explodables[expT]; exp.revertContactTicks(explodablePredictions.getState(exp.netId)); } + explodablesToTick = []; var huntMode:HuntMode = cast this.gameMode; if (@:privateAccess huntMode.activeGemSpawnGroup != null) { for (activeGem in @:privateAccess huntMode.activeGemSpawnGroup) { diff --git a/src/ParticleSystem.hx b/src/ParticleSystem.hx index ba53a797..fe2b2b92 100644 --- a/src/ParticleSystem.hx +++ b/src/ParticleSystem.hx @@ -221,6 +221,8 @@ class ParticleEmitter { var getPos:Void->Vector; var spawnSphereSquish:Vector; + var emittedParticles:Array = []; + public function new(options:ParticleEmitterOptions, data:ParticleData, manager:ParticleManager, ?getPos:Void->Vector, ?spawnSphereSquish:Vector) { this.o = options; this.manager = manager; @@ -270,6 +272,7 @@ class ParticleEmitter { // .add(this.o.ambientVelocity); var particle = new Particle(this.o.particleOptions, this.manager, this.data, time, pos, vel); this.manager.addParticle(data, particle); + this.emittedParticles.push(particle); } /** Computes the interpolated emitter position at a point in time. */ @@ -361,6 +364,12 @@ class ParticleManager { this.emitters.remove(emitter); } + public function removeEmitterWithParticles(emitter:ParticleEmitter) { + this.removeEmitter(emitter); + for (particle in emitter.emittedParticles) + this.removeParticle(particle.data, particle); + } + public function removeEverything() { for (ident => particles in this.particleGroups) { particles.remove(); diff --git a/src/net/ExplodablePredictionStore.hx b/src/net/ExplodablePredictionStore.hx index bd22f5b0..a1d2d7ac 100644 --- a/src/net/ExplodablePredictionStore.hx +++ b/src/net/ExplodablePredictionStore.hx @@ -1,14 +1,17 @@ package net; +import src.MarbleWorld; import net.NetPacket.ExplodableUpdatePacket; import src.TimeState; import net.NetPacket.PowerupPickupPacket; class ExplodablePredictionStore { + var world:MarbleWorld; var predictions:Array; - public inline function new() { + public inline function new(world:MarbleWorld) { predictions = []; + this.world = world; } public inline function alloc() { @@ -21,5 +24,13 @@ class ExplodablePredictionStore { public inline function acknowledgeExplodableUpdate(packet:ExplodableUpdatePacket) { predictions[packet.explodableId] = packet.serverTicks; + if (!world.explodablesToTick.contains(packet.explodableId)) + world.explodablesToTick.push(packet.explodableId); + } + + public inline function reset() { + for (i in 0...predictions.length) { + predictions[i] = -100000; + } } } diff --git a/src/net/GemPredictionStore.hx b/src/net/GemPredictionStore.hx index 476796ba..b39991fd 100644 --- a/src/net/GemPredictionStore.hx +++ b/src/net/GemPredictionStore.hx @@ -26,4 +26,10 @@ class GemPredictionStore { for (gemId in packet.gemIds) predictions[gemId] = false; } + + public inline function reset() { + for (i in 0...predictions.length) { + predictions[i] = true; + } + } } diff --git a/src/net/PowerupPredictionStore.hx b/src/net/PowerupPredictionStore.hx index 2bcb4923..72f0af41 100644 --- a/src/net/PowerupPredictionStore.hx +++ b/src/net/PowerupPredictionStore.hx @@ -21,4 +21,10 @@ class PowerupPredictionStore { public inline function acknowledgePowerupPickup(packet:PowerupPickupPacket, timeState:TimeState, futureTicks:Int) { predictions[packet.powerupItemId] = timeState.currentAttemptTime - futureTicks * 0.032; // Approximate } + + public inline function reset() { + for (i in 0...predictions.length) { + predictions[i] = Math.NEGATIVE_INFINITY; + } + } } diff --git a/src/shapes/Explodable.hx b/src/shapes/Explodable.hx index a077bc29..bbea5c8f 100644 --- a/src/shapes/Explodable.hx +++ b/src/shapes/Explodable.hx @@ -98,6 +98,11 @@ abstract class Explodable extends DtsObject { emitter3 = this.level.particleManager.createEmitter(sparksParticle, sparkParticleData, this.getAbsPos().getPosition()); } + if (Net.isClient) { + if (!level.explodablesToTick.contains(netId)) + level.explodablesToTick.push(netId); + } + // var minePos = this.getAbsPos().getPosition(); // var off = marble.getAbsPos().getPosition().sub(minePos); @@ -134,17 +139,17 @@ abstract class Explodable extends DtsObject { this.lastContactTick = ticks; if (level.timeState.ticks >= this.lastContactTick + (renewTime >> 5) || level.timeState.ticks < this.lastContactTick) { if (emitter1 != null) { - this.level.particleManager.removeEmitter(emitter1); + this.level.particleManager.removeEmitterWithParticles(emitter1); emitter1 = null; } if (emitter2 != null) { - this.level.particleManager.removeEmitter(emitter2); + this.level.particleManager.removeEmitterWithParticles(emitter2); emitter2 = null; } if (emitter3 != null) { - this.level.particleManager.removeEmitter(emitter3); + this.level.particleManager.removeEmitterWithParticles(emitter3); emitter3 = null; } }