From eb880ba2beb8e12d88d5bcdb6af6256cdb0078a4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 24 Apr 2022 23:12:28 -0400 Subject: [PATCH] Fixed low-FPS continuous bullets --- .../entities/bullet/ContinuousLaserBulletType.java | 4 ++-- core/src/mindustry/entities/comp/BulletComp.java | 9 ++++++++- .../world/blocks/defense/turrets/ContinuousTurret.java | 1 + .../world/blocks/defense/turrets/LaserTurret.java | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/entities/bullet/ContinuousLaserBulletType.java b/core/src/mindustry/entities/bullet/ContinuousLaserBulletType.java index c576715b83..7cd7dd04fc 100644 --- a/core/src/mindustry/entities/bullet/ContinuousLaserBulletType.java +++ b/core/src/mindustry/entities/bullet/ContinuousLaserBulletType.java @@ -14,7 +14,7 @@ public class ContinuousLaserBulletType extends ContinuousBulletType{ public float lightStroke = 40f; public int divisions = 11; public Color[] colors = {Color.valueOf("ec745855"), Color.valueOf("ec7458aa"), Color.valueOf("ff9c5a"), Color.white}; - public float strokeFrom = 2f, strokeTo = 0.5f; + public float strokeFrom = 2f, strokeTo = 0.5f, pointyScaling = 0.75f; public float backLength = 7f, frontLength = 35f; public float width = 9f, oscScl = 0.8f, oscMag = 1.5f; @@ -52,7 +52,7 @@ public class ContinuousLaserBulletType extends ContinuousBulletType{ float colorFin = i / (float)(colors.length - 1); float baseStroke = Mathf.lerp(strokeFrom, strokeTo, colorFin); float stroke = (width + Mathf.absin(Time.time, oscScl, oscMag)) * fout * baseStroke; - float ellipseLenScl = Mathf.lerp(1 - i / (float)(colors.length), 1f, 0.75f); + float ellipseLenScl = Mathf.lerp(1 - i / (float)(colors.length), 1f, pointyScaling); Lines.stroke(stroke); Lines.lineAngle(b.x, b.y, rot, length - frontLength, false); diff --git a/core/src/mindustry/entities/comp/BulletComp.java b/core/src/mindustry/entities/comp/BulletComp.java index a8258c78ea..bc0fe962a9 100644 --- a/core/src/mindustry/entities/comp/BulletComp.java +++ b/core/src/mindustry/entities/comp/BulletComp.java @@ -25,7 +25,7 @@ import static mindustry.Vars.*; abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{ @Import Team team; @Import Entityc owner; - @Import float x, y, damage, lastX, lastY; + @Import float x, y, damage, lastX, lastY, time, lifetime; @Import Vec2 vel; IntSeq collided = new IntSeq(6); @@ -37,6 +37,8 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw @ReadOnly private float rotation; + //setting this variable to true prevents lifetime from decreasing for a frame. + transient boolean keepAlive; transient @Nullable Tile aimTile; transient float originX, originY; transient @Nullable Mover mover; @@ -140,6 +142,11 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw hit = true; remove(); } + + if(keepAlive){ + time -= Time.delta; + keepAlive = false; + } } public void moveRelative(float x, float y){ diff --git a/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java b/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java index 92da51d6d3..88da5c3bb4 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java @@ -82,6 +82,7 @@ public class ContinuousTurret extends Turret{ if(isShooting() && hasAmmo()){ entry.bullet.time = entry.bullet.lifetime * entry.bullet.type.optimalLifeFract * shootWarmup; + entry.bullet.keepAlive = true; } } diff --git a/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java b/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java index cc3973486c..a2887944b0 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java @@ -60,6 +60,7 @@ public class LaserTurret extends PowerTurret{ entry.bullet.rotation(angle); entry.bullet.set(bulletX, bulletY); entry.bullet.time = entry.bullet.type.lifetime * entry.bullet.type.optimalLifeFract; + entry.bullet.keepAlive = true; entry.life -= Time.delta / Math.max(efficiency, 0.00001f); }