From 6375862a716465c4b4d7faaed9f30a3630415148 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 12 Jul 2018 09:11:28 -0400 Subject: [PATCH] Fixed deadlock / Crafter fixes / Autotile fixes / Low FPS ship fixes --- .../content/blocks/CraftingBlocks.java | 5 ++-- .../anuke/mindustry/core/ThreadHandler.java | 15 ++++++++---- core/src/io/anuke/mindustry/core/UI.java | 2 +- core/src/io/anuke/mindustry/core/World.java | 23 +++++++++++++++++++ .../io/anuke/mindustry/entities/Player.java | 13 ++++++----- .../mindustry/world/blocks/BuildBlock.java | 2 +- .../world/blocks/distribution/Conduit.java | 12 +++++----- .../blocks/power/ItemLiquidGenerator.java | 4 ++-- .../world/blocks/power/TurbineGenerator.java | 11 +++++++++ .../world/blocks/production/Fracker.java | 5 ++++ .../world/blocks/production/Pump.java | 5 ---- .../world/blocks/production/SolidPump.java | 10 +++++--- .../world/consumers/ConsumeLiquidFilter.java | 3 --- .../world/mapgen/WorldGenerator.java | 2 ++ 14 files changed, 79 insertions(+), 33 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java b/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java index 945a15ef36..ac9ce03f19 100644 --- a/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java @@ -153,7 +153,7 @@ public class CraftingBlocks extends BlockList implements ContentList { melter = new PowerCrafter("melter") {{ health = 200; outputLiquid = Liquids.lava; - outputLiquidAmount = 0.05f; + outputLiquidAmount = 0.75f; itemCapacity = 50; craftTime = 10f; hasLiquids = hasPower = true; @@ -212,7 +212,7 @@ public class CraftingBlocks extends BlockList implements ContentList { itemCapacity = 50; craftTime = 25f; outputLiquid = Liquids.oil; - outputLiquidAmount = 0.1f; + outputLiquidAmount = 0.14f; size = 2; health = 320; hasLiquids = true; @@ -238,6 +238,7 @@ public class CraftingBlocks extends BlockList implements ContentList { liquidCapacity = 21f; craftTime = 14; output = Items.stone; + itemCapacity = 20; health = 80; craftEffect = BlockFx.purifystone; hasLiquids = hasItems = true; diff --git a/core/src/io/anuke/mindustry/core/ThreadHandler.java b/core/src/io/anuke/mindustry/core/ThreadHandler.java index 66baa64fa2..e87203a1a9 100644 --- a/core/src/io/anuke/mindustry/core/ThreadHandler.java +++ b/core/src/io/anuke/mindustry/core/ThreadHandler.java @@ -115,11 +115,18 @@ public class ThreadHandler { while (true) { long time = TimeUtils.nanoTime(); - synchronized (toRun) { - for(Runnable r : toRun){ - r.run(); + while(true){ + Runnable r; + synchronized (toRun){ + if(toRun.size > 0){ + r = toRun.pop(); + }else{ + r = null; + } } - toRun.clear(); + + if(r == null) break; + r.run(); } logic.doUpdate = true; diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index 53e5497a1b..821ea28cff 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -225,7 +225,7 @@ public class UI extends SceneModule{ public void loadAnd(String text, Callable call){ loadfrag.show(text); - Timers.runTask(6f, () -> { + Timers.runTask(7f, () -> { call.run(); loadfrag.hide(); }); diff --git a/core/src/io/anuke/mindustry/core/World.java b/core/src/io/anuke/mindustry/core/World.java index 1859dd94b1..73a03e013b 100644 --- a/core/src/io/anuke/mindustry/core/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -10,6 +10,7 @@ import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.game.EventType.TileChangeEvent; import io.anuke.mindustry.game.EventType.WorldLoadEvent; +import io.anuke.mindustry.game.Team; import io.anuke.mindustry.io.*; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; @@ -267,6 +268,28 @@ public class World extends Module{ } } + public void setBlock(Tile tile, Block block, Team team){ + tile.setBlock(block); + if (block.isMultiblock()) { + int offsetx = -(block.size - 1) / 2; + int offsety = -(block.size - 1) / 2; + + for (int dx = 0; dx < block.size; dx++) { + for (int dy = 0; dy < block.size; dy++) { + int worldx = dx + offsetx + tile.x; + int worldy = dy + offsety + tile.y; + if (!(worldx == tile.x && worldy == tile.y)) { + Tile toplace = world.tile(worldx, worldy); + if (toplace != null) { + toplace.setLinked((byte) (dx + offsetx), (byte) (dy + offsety)); + toplace.setTeam(team); + } + } + } + } + } + } + /**Raycast, but with world coordinates.*/ public GridPoint2 raycastWorld(float x, float y, float x2, float y2){ return raycast(Mathf.scl2(x, tilesize), Mathf.scl2(y, tilesize), diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 77af915292..2775aa3438 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -599,18 +599,13 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra } movement.set(targetX - x, targetY - y).limit(mech.speed); - movement.setAngle(Mathf.slerpDelta(movement.angle(), velocity.angle(), 0.05f)); + movement.setAngle(Mathf.slerp(movement.angle(), velocity.angle(), 0.05f)); if(distanceTo(targetX, targetY) < attractDst){ movement.setZero(); } velocity.add(movement); - updateVelocityStatus(mech.drag, mech.maxSpeed); - - //hovering effect - x += Mathf.sin(Timers.time() + id * 999, 25f, 0.08f); - y += Mathf.cos(Timers.time() + id * 999, 25f, 0.08f); if(velocity.len() <= 0.2f){ rotation += Mathf.sin(Timers.time() + id * 99, 10f, 1f); @@ -618,6 +613,12 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len()/10f); } + updateVelocityStatus(mech.drag, mech.maxSpeed); + + //hovering effect + x += Mathf.sin(Timers.time() + id * 999, 25f, 0.08f); + y += Mathf.cos(Timers.time() + id * 999, 25f, 0.08f); + //update shooting if not building, not mining and there's ammo left if(!isBuilding() && inventory.hasAmmo() && getMineTile() == null){ diff --git a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java index ab692b560a..3e30dbedc4 100644 --- a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java @@ -161,7 +161,7 @@ public class BuildBlock extends Block { @Remote(called = Loc.server, in = In.blocks) public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team){ - tile.setBlock(block); + world.setBlock(tile, block, team); tile.setRotation(rotation); tile.setTeam(team); Effects.effect(Fx.placeBlock, tile.drawx(), tile.drawy(), block.size); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java index e5bcdbf84f..7aa7c3eac9 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java @@ -40,15 +40,15 @@ public class Conduit extends LiquidBlock { ConduitEntity entity = tile.entity(); entity.blendbits = 0; - if(blends(tile, 0)){ + if(blends(tile, 1) && blends(tile, 2)) { + entity.blendbits = 2; + }else if(blends(tile, 3) && blends(tile, 2)) { + entity.blendbits = 4; + }else if(blends(tile, 0)){ if(blends(tile, 2) && blends(tile, 1) && blends(tile, 3)) { entity.blendbits = 3; }else if(blends(tile, 1) && blends(tile, 3)) { - entity.blendbits = 6; - }else if(blends(tile, 1) && blends(tile, 2)) { - entity.blendbits = 2; - }else if(blends(tile, 3) && blends(tile, 2)) { - entity.blendbits = 4; + entity.blendbits = 6; }else if(blends(tile, 1)) { entity.blendbits = 5; }else if(blends(tile, 3)) { diff --git a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java index cb290d8f25..a5333f80be 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java @@ -31,7 +31,7 @@ public abstract class ItemLiquidGenerator extends ItemGenerator { ItemGeneratorEntity entity = tile.entity(); //liquid takes priority over solids - if(entity.liquids.currentAmount() >= 0.001f){ + if(entity.liquids.currentAmount() >= 0.001f && entity.cons.valid()){ float powerPerLiquid = getLiquidEfficiency(entity.liquids.current())*this.powerPerLiquid; float used = Math.min(entity.liquids.currentAmount(), maxLiquidGenerate * Timers.delta()); used = Math.min(used, (powerCapacity - entity.power.amount)/powerPerLiquid); @@ -47,7 +47,7 @@ public abstract class ItemLiquidGenerator extends ItemGenerator { float maxPower = Math.min(powerCapacity - entity.power.amount, powerOutput * Timers.delta()) * entity.efficiency; float mfract = maxPower / (powerOutput); - if (entity.generateTime > 0f) { + if (entity.generateTime > 0f && entity.cons.valid()) { entity.generateTime -= 1f / itemDuration * mfract; entity.power.amount += maxPower; entity.generateTime = Mathf.clamp(entity.generateTime); diff --git a/core/src/io/anuke/mindustry/world/blocks/power/TurbineGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/TurbineGenerator.java index 8efd90fbc9..99e679557a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/TurbineGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/TurbineGenerator.java @@ -1,10 +1,21 @@ package io.anuke.mindustry.world.blocks.power; +import io.anuke.mindustry.type.Liquid; +import io.anuke.mindustry.world.Tile; +import io.anuke.mindustry.world.consumers.ConsumeLiquid; + //TODO public class TurbineGenerator extends BurnerGenerator { public TurbineGenerator(String name) { super(name); singleLiquid = false; + + consumes.require(ConsumeLiquid.class); + } + + @Override + public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ + return super.acceptLiquid(tile, source, liquid, amount) || liquid == consumes.liquid() && tile.entity.liquids.get(consumes.liquid()) < liquidCapacity; } } diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java b/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java index 5a2700bcb1..25507dcb32 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java @@ -81,6 +81,11 @@ public class Fracker extends SolidPump { return new FrackerEntity(); } + @Override + public float typeLiquid(Tile tile) { + return tile.entity.liquids.get(result); + } + public static class FrackerEntity extends SolidPumpEntity{ public float accumulator; } diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Pump.java b/core/src/io/anuke/mindustry/world/blocks/production/Pump.java index cbfff62e71..97c6129e32 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Pump.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Pump.java @@ -42,11 +42,6 @@ public class Pump extends LiquidBlock{ stats.add(BlockStat.liquidOutput, 60f*pumpAmount, StatUnit.liquidSecond); } - @Override - public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ - return false; - } - @Override public void draw(Tile tile){ Draw.rect(name(), tile.drawx(), tile.drawy()); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java b/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java index ac852972e0..76993b79ad 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java @@ -74,8 +74,8 @@ public class SolidPump extends Pump { if(isValid(tile)) fraction = 1f; } - if(tile.entity.cons.valid() && tile.entity.liquids.total() < liquidCapacity - 0.001f){ - float maxPump = Math.min(liquidCapacity - tile.entity.liquids.total(), pumpAmount * Timers.delta() * fraction); + if(tile.entity.cons.valid() && typeLiquid(tile) < liquidCapacity - 0.001f){ + float maxPump = Math.min(liquidCapacity - typeLiquid(tile), pumpAmount * Timers.delta() * fraction); tile.entity.liquids.add(result, maxPump); entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f); if(Mathf.chance(Timers.delta() * updateEffectChance)) @@ -86,7 +86,7 @@ public class SolidPump extends Pump { entity.pumpTime += entity.warmup * Timers.delta(); - tryDumpLiquid(tile, entity.liquids.current()); + tryDumpLiquid(tile, result); } @Override @@ -113,6 +113,10 @@ public class SolidPump extends Pump { return new SolidPumpEntity(); } + public float typeLiquid(Tile tile){ + return tile.entity.liquids.total(); + } + public static class SolidPumpEntity extends TileEntity{ public float warmup; public float pumpTime; diff --git a/core/src/io/anuke/mindustry/world/consumers/ConsumeLiquidFilter.java b/core/src/io/anuke/mindustry/world/consumers/ConsumeLiquidFilter.java index 8ad414f22a..c6e818dbdc 100644 --- a/core/src/io/anuke/mindustry/world/consumers/ConsumeLiquidFilter.java +++ b/core/src/io/anuke/mindustry/world/consumers/ConsumeLiquidFilter.java @@ -11,7 +11,6 @@ import io.anuke.mindustry.world.meta.values.LiquidFilterValue; import io.anuke.ucore.core.Timers; import io.anuke.ucore.function.Predicate; import io.anuke.ucore.scene.ui.layout.Table; -import io.anuke.ucore.util.Strings; public class ConsumeLiquidFilter extends Consume{ private final Predicate filter; @@ -43,8 +42,6 @@ public class ConsumeLiquidFilter extends Consume{ table.add("/"); } } - - table.add("x" + Strings.toFixed(use * 60f, 1)); } @Override diff --git a/core/src/io/anuke/mindustry/world/mapgen/WorldGenerator.java b/core/src/io/anuke/mindustry/world/mapgen/WorldGenerator.java index 453764efe2..8d53a33c0d 100644 --- a/core/src/io/anuke/mindustry/world/mapgen/WorldGenerator.java +++ b/core/src/io/anuke/mindustry/world/mapgen/WorldGenerator.java @@ -1,6 +1,7 @@ package io.anuke.mindustry.world.mapgen; import com.badlogic.gdx.math.GridPoint2; +import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.IntArray; @@ -144,6 +145,7 @@ public class WorldGenerator { } public static void generateMap(Tile[][] tiles, int seed){ + MathUtils.random.setSeed((long)(Math.random() * 99999999)); Simplex sim = new Simplex(Mathf.random(99999)); Simplex sim2 = new Simplex(Mathf.random(99999)); Simplex sim3 = new Simplex(Mathf.random(99999));