Better conveyor physics / Performance test maps / Unit inventory begin

This commit is contained in:
Anuken
2018-04-09 20:25:08 -04:00
parent 6967093689
commit 5b11875a5a
17 changed files with 59 additions and 26 deletions

View File

@@ -18,6 +18,7 @@ public abstract class Unit extends SyncEntity {
public static final float hitDuration = 9f;
public StatusController status = new StatusController();
public UnitInventory inventory = new UnitInventory();
public Team team = Team.blue;
public Vector2 velocity = new Vector2();
public float hitTime;

View File

@@ -0,0 +1,10 @@
package io.anuke.mindustry.entities;
import io.anuke.mindustry.resource.*;
public class UnitInventory {
public final AmmoEntry ammo = new AmmoEntry(AmmoType.getByID(0), 0);
public final ItemStack item = new ItemStack(Item.getByID(0), 0);
public final LiquidStack liquid = new LiquidStack(Liquid.getByID(0), 0);
public float power = 0f;
}

View File

@@ -26,8 +26,9 @@ public abstract class GroundUnitType extends UnitType{
public GroundUnitType(String name) {
super(name);
maxVelocity = 2f;
maxVelocity = 1.1f;
speed = 0.05f;
drag = 0.4f;
}
@Override

View File

@@ -43,7 +43,7 @@ public abstract class InputHandler extends InputAdapter{
}
public boolean cursorNear(){
return Vector2.dst(player.x, player.y, getBlockX() * tilesize, getBlockY() * tilesize) <= placerange;
return Vector2.dst(player.x, player.y, getBlockX() * tilesize, getBlockY() * tilesize) <= placerange || debug;
}
public boolean tryPlaceBlock(int x, int y, boolean sound){

View File

@@ -109,7 +109,7 @@ public enum PlaceMode{
}
},
areaDelete{
int maxlen = 20;
int maxlen = debug ? 999999: 20;
int tilex;
int tiley;
int endx;

View File

@@ -17,7 +17,7 @@ import static io.anuke.mindustry.Vars.mapExtension;
public class Maps implements Disposable{
/**List of all built-in maps.*/
private static final String[] defaultMapNames = {"test", "trinity"};
private static final String[] defaultMapNames = {"test", "trinity", "routerhell", "conveyorhell"};
/**Tile format version.*/
private static final int version = 0;

View File

@@ -0,0 +1,11 @@
package io.anuke.mindustry.resource;
public class AmmoEntry{
public AmmoType type;
public int amount;
public AmmoEntry(AmmoType type, int amount) {
this.type = type;
this.amount = amount;
}
}

View File

@@ -53,7 +53,7 @@ public class AmmoType {
return allTypes;
}
public static AmmoType getByID(byte id){
public static AmmoType getByID(int id){
return allTypes.get(id);
}
}

View File

@@ -3,7 +3,6 @@ package io.anuke.mindustry.resource;
public class ItemStack{
public Item item;
public int amount;
public float pos;
public ItemStack(Item item, int amount){
this.item = item;

View File

@@ -0,0 +1,15 @@
package io.anuke.mindustry.resource;
public class LiquidStack {
public Liquid liquid;
public float amount;
public LiquidStack(Liquid liquid, float amount){
this.liquid = liquid;
this.amount = amount;
}
public boolean equals(LiquidStack other){
return other != null && other.liquid == liquid && other.amount == amount;
}
}

View File

@@ -162,7 +162,6 @@ public abstract class BaseBlock {
}
}
i = (byte)((i + 1) % nearby.length);
tile.setDump(i);
}

View File

@@ -6,6 +6,7 @@ import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.resource.AmmoEntry;
import io.anuke.mindustry.resource.AmmoType;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.BlockGroup;
@@ -252,16 +253,6 @@ public abstract class Turret extends Block{
public TileEntity getEntity(){
return new TurretEntity();
}
public static class AmmoEntry{
public final AmmoType type;
public int amount;
public AmmoEntry(AmmoType type, int amount) {
this.type = type;
this.amount = amount;
}
}
public static class TurretEntity extends TileEntity{
public TileEntity blockTarget;

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.world.blocks.types.defense.turrets;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.resource.AmmoEntry;
import io.anuke.mindustry.resource.AmmoType;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.BarType;

View File

@@ -96,20 +96,25 @@ public class Conveyor extends Block{
public void unitOn(Tile tile, Unit unit) {
ConveyorEntity entity = tile.entity();
float angle = tile.getRotation() * 90f;
float speed = this.speed * tilesize / 1.5f;
float tx = Angles.trnsx(angle, 1f), ty = Angles.trnsy(angle, 1f);
unit.velocity.add(tx * speed * Timers.delta(), ty * speed * Timers.delta());
float speed = this.speed * tilesize / 2.3f;
float tx = Geometry.d4[tile.getRotation()].x, ty = Geometry.d4[tile.getRotation()].y;
float min;
if(Math.abs(tx) > Math.abs(ty)){
float rx = tile.worldx() + tx/2f*tilesize;
entity.minCarry = Math.min(entity.minCarry, Mathf.clamp((entity.x - rx) * tx / tilesize));
float rx = tile.worldx() - tx/2f*tilesize;
min = Mathf.clamp((unit.x - rx) * tx / tilesize);
}else{
float ry = tile.worldy() + ty/2f*tilesize;
entity.minCarry = Math.min(entity.minCarry, Mathf.clamp((entity.y - ry) * ty / tilesize));
float ry = tile.worldy() - ty/2f*tilesize;
min = Mathf.clamp((unit.y - ry) * ty / tilesize);
}
entity.minCarry = Math.min(entity.minCarry, min);
entity.carrying += unit.getMass();
if(entity.convey.size * itemSpace < 0.9f){
unit.velocity.add(tx * speed * Timers.delta(), ty * speed * Timers.delta());
}
}
@Override