From 7ff2e984201c00e4cf20733cad81c31af65545b4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 3 Jul 2020 16:41:06 -0400 Subject: [PATCH] Cleanup --- .../src/main/resources/classids.properties | 1 + core/src/mindustry/ai/Pathfinder.java | 5 --- core/src/mindustry/core/ContentLoader.java | 16 +++---- .../mindustry/entities/comp/BuilderComp.java | 4 +- .../mindustry/entities/comp/MinerComp.java | 4 +- .../mindustry/graphics/IndexedRenderer.java | 43 +++++++++---------- core/src/mindustry/io/SaveVersion.java | 4 +- .../mindustry/ui/dialogs/DatabaseDialog.java | 2 +- core/src/mindustry/world/Tile.java | 6 +-- .../world/blocks/defense/ForceProjector.java | 2 +- .../world/blocks/distribution/MassDriver.java | 2 +- 11 files changed, 42 insertions(+), 47 deletions(-) diff --git a/annotations/src/main/resources/classids.properties b/annotations/src/main/resources/classids.properties index 94542d6270..ffdedc8374 100644 --- a/annotations/src/main/resources/classids.properties +++ b/annotations/src/main/resources/classids.properties @@ -23,6 +23,7 @@ mindustry.world.blocks.campaign.CoreLauncher.LaunchCoreComp=13 mindustry.world.blocks.campaign.LaunchPad.LaunchPayloadComp=14 oculon=15 phantom=16 +spirit=27 tau=17 trident=18 vanguard=19 diff --git a/core/src/mindustry/ai/Pathfinder.java b/core/src/mindustry/ai/Pathfinder.java index 00fc4567d3..fed6acd16f 100644 --- a/core/src/mindustry/ai/Pathfinder.java +++ b/core/src/mindustry/ai/Pathfinder.java @@ -86,11 +86,6 @@ public class Pathfinder implements Runnable{ queue.clear(); } - //public int debugValue(Team team, int x, int y){ - // if(pathMap[team.id][FlagTarget.enemyCores.ordinal()] == null) return 0; - // return pathMap[team.id][FlagTarget.enemyCores.ordinal()].weights[x][y]; - //} - /** Update a tile in the internal pathfinding grid. * Causes a complete pathfinding reclaculation. Main thread only. */ public void updateTile(Tile tile){ diff --git a/core/src/mindustry/core/ContentLoader.java b/core/src/mindustry/core/ContentLoader.java index 16897778c1..604d04059c 100644 --- a/core/src/mindustry/core/ContentLoader.java +++ b/core/src/mindustry/core/ContentLoader.java @@ -22,8 +22,8 @@ import static mindustry.Vars.mods; */ @SuppressWarnings("unchecked") public class ContentLoader{ - private ObjectMap[] contentNameMap = new ObjectMap[ContentType.values().length]; - private Seq[] contentMap = new Seq[ContentType.values().length]; + private ObjectMap[] contentNameMap = new ObjectMap[ContentType.all.length]; + private Seq[] contentMap = new Seq[ContentType.all.length]; private MappableContent[][] temporaryMapper; private @Nullable LoadedMod currentMod; private @Nullable Content lastAdded; @@ -48,11 +48,11 @@ public class ContentLoader{ /** Clears all initialized content.*/ public void clear(){ - contentNameMap = new ObjectMap[ContentType.values().length]; - contentMap = new Seq[ContentType.values().length]; + contentNameMap = new ObjectMap[ContentType.all.length]; + contentMap = new Seq[ContentType.all.length]; initialization = new ObjectSet<>(); - for(ContentType type : ContentType.values()){ + for(ContentType type : ContentType.all){ contentMap[type.ordinal()] = new Seq<>(); contentNameMap[type.ordinal()] = new ObjectMap<>(); } @@ -87,9 +87,9 @@ public class ContentLoader{ Log.debug("--- CONTENT INFO ---"); for(int k = 0; k < contentMap.length; k++){ - Log.debug("[@]: loaded @", ContentType.values()[k].name(), contentMap[k].size); + Log.debug("[@]: loaded @", ContentType.all[k].name(), contentMap[k].size); } - Log.debug("Total content loaded: @", Seq.with(ContentType.values()).mapInt(c -> contentMap[c.ordinal()].size).sum()); + Log.debug("Total content loaded: @", Seq.with(ContentType.all).mapInt(c -> contentMap[c.ordinal()].size).sum()); Log.debug("-------------------"); } @@ -107,7 +107,7 @@ public class ContentLoader{ private void initialize(Cons callable){ if(initialization.contains(callable)) return; - for(ContentType type : ContentType.values()){ + for(ContentType type : ContentType.all){ for(Content content : contentMap[type.ordinal()]){ try{ callable.get(content); diff --git a/core/src/mindustry/entities/comp/BuilderComp.java b/core/src/mindustry/entities/comp/BuilderComp.java index 07dca1da8e..7fb4bb4345 100644 --- a/core/src/mindustry/entities/comp/BuilderComp.java +++ b/core/src/mindustry/entities/comp/BuilderComp.java @@ -72,11 +72,11 @@ abstract class BuilderComp implements Unitc{ BuildPlan current = buildPlan(); - if(dst(current.tile()) > finalPlaceDst) return; + if(!within(current.tile(), finalPlaceDst)) return; Tile tile = world.tile(current.x, current.y); - if(dst(tile) <= finalPlaceDst){ + if(!within(tile, finalPlaceDst)){ rotation = Mathf.slerpDelta(rotation, angleTo(tile), 0.4f); } diff --git a/core/src/mindustry/entities/comp/MinerComp.java b/core/src/mindustry/entities/comp/MinerComp.java index 1797c8d9ee..9e83ece02e 100644 --- a/core/src/mindustry/entities/comp/MinerComp.java +++ b/core/src/mindustry/entities/comp/MinerComp.java @@ -40,7 +40,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{ public void update(){ Building core = closestCore(); - if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && dst(core) < mineTransferRange){ + if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && within(core, mineTransferRange)){ int accepted = core.acceptStack(item(), stack().amount, this); if(accepted > 0){ Call.transferItemTo(item(), accepted, @@ -63,7 +63,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{ if(mineTimer >= 50f + item.hardness*10f){ mineTimer = 0; - if(dst(core) < mineTransferRange && core.acceptStack(item, 1, this) == 1 && offloadImmediately()){ + if(within(core, mineTransferRange) && core.acceptStack(item, 1, this) == 1 && offloadImmediately()){ Call.transferItemTo(item, 1, mineTile.worldx() + Mathf.range(tilesize / 2f), mineTile.worldy() + Mathf.range(tilesize / 2f), core.tile()); diff --git a/core/src/mindustry/graphics/IndexedRenderer.java b/core/src/mindustry/graphics/IndexedRenderer.java index a82080cd34..60eeace8ed 100644 --- a/core/src/mindustry/graphics/IndexedRenderer.java +++ b/core/src/mindustry/graphics/IndexedRenderer.java @@ -12,29 +12,28 @@ public class IndexedRenderer implements Disposable{ private final static int vsize = 5; private Shader program = new Shader( - Strings.join("\n", - "attribute vec4 " + Shader.positionAttribute + ";", - "attribute vec4 " + Shader.colorAttribute + ";", - "attribute vec2 " + Shader.texcoordAttribute + "0;", - "uniform mat4 u_projTrans;", - "varying vec4 v_color;", - "varying vec2 v_texCoords;", - "", - "void main(){", - " v_color = " + Shader.colorAttribute + ";", - " v_color.a = v_color.a * (255.0/254.0);", - " v_texCoords = " + Shader.texcoordAttribute + "0;", - " gl_Position = u_projTrans * " + Shader.positionAttribute + ";", - "}"), - Strings.join("\n", - "varying lowp vec4 v_color;", - "varying vec2 v_texCoords;", - "uniform sampler2D u_texture;", - "", - "void main(){", - " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);", + "attribute vec4 a_position;\n" + + "attribute vec4 a_color;\n" + + "attribute vec2 a_texCoord0;\n" + + "uniform mat4 u_projTrans;\n" + + "varying vec4 v_color;\n" + + "varying vec2 v_texCoords;\n" + + + "void main(){\n" + + " v_color = a_color;\n" + + " v_color.a = v_color.a * (255.0/254.0);\n" + + " v_texCoords = a_texCoord0;\n" + + " gl_Position = u_projTrans * a_position;\n" + + "}", + + "varying lowp vec4 v_color;\n" + + "varying vec2 v_texCoords;\n" + + "uniform sampler2D u_texture;\n" + + + "void main(){\n" + + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}" - )); + ); private Mesh mesh; private float[] tmpVerts = new float[vsize * 6]; private float[] vertices; diff --git a/core/src/mindustry/io/SaveVersion.java b/core/src/mindustry/io/SaveVersion.java index c2e4ce88e1..6b88bacb1b 100644 --- a/core/src/mindustry/io/SaveVersion.java +++ b/core/src/mindustry/io/SaveVersion.java @@ -327,10 +327,10 @@ public abstract class SaveVersion extends SaveFileReader{ public void readContentHeader(DataInput stream) throws IOException{ byte mapped = stream.readByte(); - MappableContent[][] map = new MappableContent[ContentType.values().length][0]; + MappableContent[][] map = new MappableContent[ContentType.all.length][0]; for(int i = 0; i < mapped; i++){ - ContentType type = ContentType.values()[stream.readByte()]; + ContentType type = ContentType.all[stream.readByte()]; short total = stream.readShort(); map[type.ordinal()] = new MappableContent[total]; diff --git a/core/src/mindustry/ui/dialogs/DatabaseDialog.java b/core/src/mindustry/ui/dialogs/DatabaseDialog.java index 9e2af57df8..3a12350a19 100644 --- a/core/src/mindustry/ui/dialogs/DatabaseDialog.java +++ b/core/src/mindustry/ui/dialogs/DatabaseDialog.java @@ -37,7 +37,7 @@ public class DatabaseDialog extends BaseDialog{ Seq[] allContent = Vars.content.getContentMap(); for(int j = 0; j < allContent.length; j++){ - ContentType type = ContentType.values()[j]; + ContentType type = ContentType.all[j]; Seq array = allContent[j].select(c -> c instanceof UnlockableContent && !((UnlockableContent)c).isHidden()); if(array.size == 0) continue; diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index 2406f4c269..c47769f7ef 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -360,8 +360,8 @@ public class Tile implements Position, QuadTreeObject, Displayable{ } /** - * Returns the list of all tiles linked to this multiblock, or just itself if it's not a multiblock. - * This array contains all linked tiles, including this tile itself. + * Iterates through the list of all tiles linked to this multiblock, or just itself if it's not a multiblock. + * The result contains all linked tiles, including this tile itself. */ public void getLinkedTiles(Cons cons){ if(block.isMultiblock()){ @@ -391,7 +391,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{ /** * Returns the list of all tiles linked to this multiblock if it were this block. - * This array contains all linked tiles, including this tile itself. + * The result contains all linked tiles, including this tile itself. */ public Seq getLinkedTilesAs(Block block, Seq tmpArray){ tmpArray.clear(); diff --git a/core/src/mindustry/world/blocks/defense/ForceProjector.java b/core/src/mindustry/world/blocks/defense/ForceProjector.java index bb3106c907..669cb750f0 100644 --- a/core/src/mindustry/world/blocks/defense/ForceProjector.java +++ b/core/src/mindustry/world/blocks/defense/ForceProjector.java @@ -32,7 +32,7 @@ public class ForceProjector extends Block{ public @Load("@-top") TextureRegion topRegion; private static ForceProjectorEntity paramEntity; - private static Cons shieldConsumer = trait -> { + private static final Cons shieldConsumer = trait -> { if(trait.team() != paramEntity.team() && Intersector.isInsideHexagon(paramEntity.x, paramEntity.y, paramEntity.realRadius() * 2f, trait.x(), trait.y())){ trait.absorb(); Fx.absorb.at(trait); diff --git a/core/src/mindustry/world/blocks/distribution/MassDriver.java b/core/src/mindustry/world/blocks/distribution/MassDriver.java index 51316aab57..43d5140be7 100644 --- a/core/src/mindustry/world/blocks/distribution/MassDriver.java +++ b/core/src/mindustry/world/blocks/distribution/MassDriver.java @@ -58,7 +58,7 @@ public class MassDriver extends Block{ //check if a mass driver is selected while placing this driver if(!control.input.frag.config.isShown()) return; Building selected = control.input.frag.config.getSelectedTile(); - if(selected == null || !(selected.block() instanceof MassDriver) || !(selected.dst(x * tilesize, y * tilesize) <= range)) return; + if(selected == null || !(selected.block() instanceof MassDriver) || !(selected.within(x * tilesize, y * tilesize, range))) return; //if so, draw a dotted line towards it while it is in range float sin = Mathf.absin(Time.time(), 6f, 1f);