From 9e0b29b3dd82241c07d5a2cdc6b636006900ebba Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 24 Sep 2020 18:11:10 -0400 Subject: [PATCH] Cleanup --- core/assets/bundles/bundle.properties | 8 ---- core/assets/scripts/global.js | 1 - core/src/mindustry/async/PhysicsProcess.java | 46 +++++++++++++------ core/src/mindustry/content/UnitTypes.java | 1 + core/src/mindustry/core/GameState.java | 2 +- core/src/mindustry/entities/Lightning.java | 6 +-- core/src/mindustry/game/Stats.java | 1 + core/src/mindustry/type/Sector.java | 2 +- .../mindustry/ui/dialogs/GameOverDialog.java | 4 +- .../mindustry/ui/dialogs/ResearchDialog.java | 1 + .../src/mindustry/desktop/steam/SStats.java | 2 +- 11 files changed, 43 insertions(+), 31 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index c01deba56a..d308127f39 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -473,16 +473,8 @@ requirement.wave = Reach Wave {0} in {1} requirement.core = Destroy Enemy Core in {0} requirement.research = Research {0} requirement.capture = Capture {0} -resume = Resume Zone:\n[lightgray]{0} bestwave = [lightgray]Best Wave: {0} -#TODO fix/remove this -launch = < LAUNCH > launch.text = Launch -launch.title = Launch Successful -launch.next = [lightgray]next opportunity at wave {0} -launch.unable2 = [scarlet]Unable to LAUNCH.[] -launch.confirm = This will launch all resources in your core.\nYou will not be able to return to this base. -launch.skip.confirm = If you skip now, you will not be able to launch until later waves. campaign.multiplayer = While playing multiplayer in campaign, you can only research using items from [accent]your[] sectors, [scarlet]not[] the host's sector that you are on right now.\n\nTo get items to [accent]your[] sectors in multiplayer, use a [accent]launch pad[]. uncover = Uncover configure = Configure Loadout diff --git a/core/assets/scripts/global.js b/core/assets/scripts/global.js index 7d395c8378..8910dbd2a9 100755 --- a/core/assets/scripts/global.js +++ b/core/assets/scripts/global.js @@ -154,7 +154,6 @@ const SaveLoadEvent = Packages.mindustry.game.EventType.SaveLoadEvent const MapPublishEvent = Packages.mindustry.game.EventType.MapPublishEvent const MapMakeEvent = Packages.mindustry.game.EventType.MapMakeEvent const ResizeEvent = Packages.mindustry.game.EventType.ResizeEvent -const LaunchEvent = Packages.mindustry.game.EventType.LaunchEvent const LoseEvent = Packages.mindustry.game.EventType.LoseEvent const WinEvent = Packages.mindustry.game.EventType.WinEvent const Trigger = Packages.mindustry.game.EventType.Trigger diff --git a/core/src/mindustry/async/PhysicsProcess.java b/core/src/mindustry/async/PhysicsProcess.java index c78b0b5769..9a075f8f40 100644 --- a/core/src/mindustry/async/PhysicsProcess.java +++ b/core/src/mindustry/async/PhysicsProcess.java @@ -10,10 +10,16 @@ import mindustry.async.PhysicsProcess.PhysicsWorld.*; import mindustry.gen.*; public class PhysicsProcess implements AsyncProcess{ + private static final int + layers = 3, + layerGround = 0, + layerLegs = 1, + layerFlying = 2; + private PhysicsWorld physics; private Seq refs = new Seq<>(false); //currently only enabled for units - private EntityGroup group = Groups.unit; + private EntityGroup group = Groups.unit; @Override public void begin(){ @@ -29,9 +35,8 @@ public class PhysicsProcess implements AsyncProcess{ return false; }); - //find entities without bodies and assign them - for(Physicsc entity : group){ - boolean grounded = entity.isGrounded(); + //find Unit without bodies and assign them + for(Unit entity : group){ if(entity.physref() == null){ PhysicsBody body = new PhysicsBody(); @@ -39,7 +44,6 @@ public class PhysicsProcess implements AsyncProcess{ body.y = entity.y(); body.mass = entity.mass(); body.radius = entity.hitSize() / 2f; - body.flag = grounded ? 1 : 0; PhysicRef ref = new PhysicRef(entity, body); refs.add(ref); @@ -52,7 +56,9 @@ public class PhysicsProcess implements AsyncProcess{ //save last position PhysicRef ref = entity.physref(); - ref.body.flag = grounded ? 1 : 0; + ref.body.layer = + entity.type().allowLegStep ? layerLegs : + entity.isGrounded() ? layerGround : layerFlying; ref.x = entity.x(); ref.y = entity.y(); } @@ -116,13 +122,16 @@ public class PhysicsProcess implements AsyncProcess{ //how much to soften movement by private static final float scl = 1.25f; - private final QuadTree tree; + private final QuadTree[] trees = new QuadTree[layers]; private final Seq bodies = new Seq<>(false, 16, PhysicsBody.class); + private final Seq seq = new Seq<>(PhysicsBody.class); private final Rect rect = new Rect(); private final Vec2 vec = new Vec2(); public PhysicsWorld(Rect bounds){ - tree = new QuadTree<>(new Rect(bounds)); + for(int i = 0; i < layers; i++){ + trees[i] = new QuadTree<>(new Rect(bounds)); + } } public void add(PhysicsBody body){ @@ -134,18 +143,27 @@ public class PhysicsProcess implements AsyncProcess{ } public void update(){ - tree.clear(); + for(int i = 0; i < layers; i++){ + trees[i].clear(); + } + for(int i = 0; i < bodies.size; i++){ PhysicsBody body = bodies.items[i]; body.collided = false; - tree.insert(body); + trees[body.layer].insert(body); } for(int i = 0; i < bodies.size; i++){ PhysicsBody body = bodies.items[i]; body.hitbox(rect); - tree.intersect(rect, other -> { - if(other.flag != body.flag || other == body || other.collided) return; + + seq.size = 0; + trees[body.layer].intersect(rect, seq); + + for(int j = 0; j < seq.size; j++){ + PhysicsBody other = seq.items[j]; + + if(other == body || other.collided) continue; float rs = body.radius + other.radius; float dst = Mathf.dst(body.x, body.y, other.x, other.y); @@ -160,14 +178,14 @@ public class PhysicsProcess implements AsyncProcess{ other.x -= vec.x * m2 / scl; other.y -= vec.y * m2 / scl; } - }); + } body.collided = true; } } public static class PhysicsBody implements QuadTreeObject{ public float x, y, radius, mass; - public int flag = 0; + public int layer = 0; public boolean collided = false; @Override diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 83965387a0..739f0a13da 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -463,6 +463,7 @@ public class UnitTypes implements ContentList{ visualElevation = 0.2f; allowLegStep = true; ammoType = AmmoTypes.powerHigh; + groundLayer = Layer.legUnit; speed = 0.3f; diff --git a/core/src/mindustry/core/GameState.java b/core/src/mindustry/core/GameState.java index ac827fbfae..15061641e0 100644 --- a/core/src/mindustry/core/GameState.java +++ b/core/src/mindustry/core/GameState.java @@ -17,7 +17,7 @@ public class GameState{ /** Wave countdown in ticks. */ public float wavetime; /** Whether the game is in game over state. */ - public boolean gameOver = false, launched = false, serverPaused = false, wasTimeout; + public boolean gameOver = false, serverPaused = false, wasTimeout; /** Map that is currently being played on. */ public @NonNull Map map = emptyMap; /** The current game rules. */ diff --git a/core/src/mindustry/entities/Lightning.java b/core/src/mindustry/entities/Lightning.java index dbc7f616c9..b693239061 100644 --- a/core/src/mindustry/entities/Lightning.java +++ b/core/src/mindustry/entities/Lightning.java @@ -24,17 +24,17 @@ public class Lightning{ /** Create a lighting branch at a location. Use Team.derelict to damage everyone. */ public static void create(Team team, Color color, float damage, float x, float y, float targetAngle, int length){ - createLightingInternal(null, lastSeed++, team, color, damage, x, y, targetAngle, length); + createLightningInternal(null, lastSeed++, team, color, damage, x, y, targetAngle, length); } /** Create a lighting branch at a location. Uses bullet parameters. */ public static void create(Bullet bullet, Color color, float damage, float x, float y, float targetAngle, int length){ - createLightingInternal(bullet, lastSeed++, bullet.team, color, damage, x, y, targetAngle, length); + createLightningInternal(bullet, lastSeed++, bullet.team, color, damage, x, y, targetAngle, length); } //TODO remote method //@Remote(called = Loc.server, unreliable = true) - private static void createLightingInternal(Bullet hitter, int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){ + private static void createLightningInternal(Bullet hitter, int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){ random.setSeed(seed); hit.clear(); diff --git a/core/src/mindustry/game/Stats.java b/core/src/mindustry/game/Stats.java index 9cea3b582f..1d175607ba 100644 --- a/core/src/mindustry/game/Stats.java +++ b/core/src/mindustry/game/Stats.java @@ -22,6 +22,7 @@ public class Stats{ /** Friendly buildings destroyed. */ public int buildingsDestroyed; + //TODO fix public RankResult calculateRank(Sector zone, boolean launched){ float score = 0; diff --git a/core/src/mindustry/type/Sector.java b/core/src/mindustry/type/Sector.java index 67bff0b396..5fb65ce091 100644 --- a/core/src/mindustry/type/Sector.java +++ b/core/src/mindustry/type/Sector.java @@ -97,7 +97,7 @@ public class Sector{ public boolean isBeingPlayed(){ //after the launch dialog, a sector is no longer considered being played - return Vars.state.isGame() && Vars.state.rules.sector == this && !Vars.state.launched && !Vars.state.gameOver; + return Vars.state.isGame() && Vars.state.rules.sector == this && !Vars.state.gameOver; } public boolean isCaptured(){ diff --git a/core/src/mindustry/ui/dialogs/GameOverDialog.java b/core/src/mindustry/ui/dialogs/GameOverDialog.java index b53627b835..b9967e6564 100644 --- a/core/src/mindustry/ui/dialogs/GameOverDialog.java +++ b/core/src/mindustry/ui/dialogs/GameOverDialog.java @@ -29,7 +29,7 @@ public class GameOverDialog extends BaseDialog{ } void rebuild(){ - title.setText(state.launched ? "@launch.title" : "@gameover"); + title.setText("@gameover"); buttons.clear(); cont.clear(); @@ -79,7 +79,7 @@ public class GameOverDialog extends BaseDialog{ } if(state.hasSector()){ - RankResult result = state.stats.calculateRank(state.getSector(), state.launched); + RankResult result = state.stats.calculateRank(state.getSector(), true); t.add(Core.bundle.format("stat.rank", result.rank + result.modifier)); t.row(); } diff --git a/core/src/mindustry/ui/dialogs/ResearchDialog.java b/core/src/mindustry/ui/dialogs/ResearchDialog.java index 16f7243b12..cad0498130 100644 --- a/core/src/mindustry/ui/dialogs/ResearchDialog.java +++ b/core/src/mindustry/ui/dialogs/ResearchDialog.java @@ -168,6 +168,7 @@ public class ResearchDialog extends BaseDialog{ Core.app.post(() -> { if(net.client()){ //TODO make this not display every time + //TODO rework this in the future ui.showInfo("campaign.multiplayer"); } }); diff --git a/desktop/src/mindustry/desktop/steam/SStats.java b/desktop/src/mindustry/desktop/steam/SStats.java index cd927030a8..7e7c9ecef3 100644 --- a/desktop/src/mindustry/desktop/steam/SStats.java +++ b/desktop/src/mindustry/desktop/steam/SStats.java @@ -243,7 +243,7 @@ public class SStats implements SteamUserStatsCallback{ SStat.attacksWon.add(); } - RankResult result = state.stats.calculateRank(state.getSector(), state.launched); + RankResult result = state.stats.calculateRank(state.getSector(), true); if(result.rank == Rank.S) earnSRank.complete(); if(result.rank == Rank.SS) earnSSRank.complete(); }