Fixed bugs with FPS and map sending
This commit is contained in:
@@ -124,7 +124,7 @@ public class Pathfind{
|
||||
//go through each spawnpoint, and if it's not found a path yet, update it
|
||||
for(SpawnPoint point : world.getSpawns()){
|
||||
if(point.request == null || point.finder == null){
|
||||
resetPathFor(point);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!point.request.pathFound){
|
||||
|
||||
@@ -38,7 +38,6 @@ public class Control extends Module{
|
||||
private Tutorial tutorial = new Tutorial();
|
||||
private boolean hiscore = false;
|
||||
|
||||
private boolean shouldUpdateItems = false;
|
||||
private boolean wasPaused = false;
|
||||
|
||||
private Saves saves;
|
||||
@@ -304,9 +303,9 @@ public class Control extends Module{
|
||||
|
||||
saves.update();
|
||||
|
||||
if(shouldUpdateItems && (Timers.get("updateItems", 8) || state.is(State.paused))){
|
||||
if(state.inventory.isUpdated() && (Timers.get("updateItems", 8) || state.is(State.paused))){
|
||||
ui.hudfrag.updateItems();
|
||||
shouldUpdateItems = false;
|
||||
state.inventory.setUpdated(false);
|
||||
}
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
|
||||
@@ -9,8 +9,18 @@ import static io.anuke.mindustry.Vars.debug;
|
||||
|
||||
public class Inventory {
|
||||
private final int[] items = new int[Item.getAllItems().size];
|
||||
private boolean updated;
|
||||
|
||||
public boolean isUpdated(){
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(boolean updated){
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public void clearItems(){
|
||||
updated = true;
|
||||
Arrays.fill(items, 0);
|
||||
|
||||
addItem(Item.stone, 40);
|
||||
@@ -29,6 +39,7 @@ public class Inventory {
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
updated = true;
|
||||
items[item.id] += amount;
|
||||
}
|
||||
|
||||
@@ -47,24 +58,29 @@ public class Inventory {
|
||||
}
|
||||
|
||||
public boolean hasItem(ItemStack req){
|
||||
updated = true;
|
||||
return items[req.item.id] >= req.amount;
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item, int amount){
|
||||
updated = true;
|
||||
return items[item.id] >= amount;
|
||||
}
|
||||
|
||||
public void removeItem(ItemStack req){
|
||||
updated = true;
|
||||
items[req.item.id] -= req.amount;
|
||||
if(items[req.item.id] < 0) items[req.item.id] = 0; //prevents negative item glitches in multiplayer
|
||||
}
|
||||
|
||||
public void removeItems(ItemStack... reqs){
|
||||
updated = true;
|
||||
for(ItemStack req : reqs)
|
||||
removeItem(req);
|
||||
}
|
||||
|
||||
public int[] getItems(){
|
||||
updated = true;
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class NetworkIO {
|
||||
}
|
||||
}
|
||||
|
||||
if(id == -1) id = 0;
|
||||
if(id == -1) id = 2;
|
||||
stream.writeByte((byte)(length > 127 ? length - 256 : length));
|
||||
stream.writeByte(id);
|
||||
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
@@ -13,6 +8,10 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LiquidBlock extends Block implements LiquidAcceptor{
|
||||
protected final int timerFlow = timers++;
|
||||
|
||||
@@ -57,7 +56,7 @@ public class LiquidBlock extends Block implements LiquidAcceptor{
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.liquidAmount > 0.01f && entity.timer.get(timerFlow, 3)){
|
||||
if(entity.liquidAmount > 0.01f && entity.timer.get(timerFlow, 1)){
|
||||
tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
import com.badlogic.gdx.utils.LongArray;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
@@ -26,7 +26,7 @@ import static io.anuke.mindustry.Vars.tilesize;
|
||||
public class Conveyor extends Block{
|
||||
private static ItemPos pos1 = new ItemPos();
|
||||
private static ItemPos pos2 = new ItemPos();
|
||||
private static IntArray removals = new IntArray();
|
||||
private static LongArray removals = new LongArray();
|
||||
private static final float itemSpace = 0.135f;
|
||||
private static final float offsetScl = 128f*3f;
|
||||
private static final float itemSize = 4f;
|
||||
@@ -96,7 +96,7 @@ public class Conveyor extends Block{
|
||||
float shift = entity.elapsed * speed;
|
||||
|
||||
for(int i = 0; i < entity.convey.size; i ++){
|
||||
int value = entity.convey.get(i);
|
||||
long value = entity.convey.get(i);
|
||||
ItemPos pos = pos1.set(value);
|
||||
|
||||
if(pos.item == null){
|
||||
@@ -105,10 +105,12 @@ public class Conveyor extends Block{
|
||||
}
|
||||
|
||||
boolean canmove = i == entity.convey.size - 1 ||
|
||||
!(pos2.set(entity.convey.get(i + 1)).y - pos.y < itemSpace * Timers.delta());
|
||||
|
||||
!(pos2.set(entity.convey.get(i + 1)).y - pos.y < itemSpace);
|
||||
|
||||
float minmove = 1f / (Short.MAX_VALUE - 2);
|
||||
|
||||
if(canmove){
|
||||
pos.y += Math.max(speed * Timers.delta() + shift, 1f/252f); //TODO fix precision issues when at high FPS?
|
||||
pos.y += Math.max(speed * Timers.delta() + shift, minmove); //TODO fix precision issues when at high FPS?
|
||||
pos.x = Mathf.lerpDelta(pos.x, 0, 0.06f);
|
||||
}else{
|
||||
pos.x = Mathf.lerpDelta(pos.x, pos.seed/offsetScl, 0.1f);
|
||||
@@ -157,7 +159,7 @@ public class Conveyor extends Block{
|
||||
float y = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0;
|
||||
|
||||
ConveyorEntity entity = tile.entity();
|
||||
int result = ItemPos.packItem(item, y*0.9f, pos, (byte)Mathf.random(255));
|
||||
long result = ItemPos.packItem(item, y*0.9f, pos, (byte)Mathf.random(255));
|
||||
boolean inserted = false;
|
||||
|
||||
for(int i = 0; i < entity.convey.size; i ++){
|
||||
@@ -183,7 +185,7 @@ public class Conveyor extends Block{
|
||||
* Size is 4 bytes, or one int.
|
||||
*/
|
||||
public static class ConveyorEntity extends TileEntity{
|
||||
IntArray convey = new IntArray();
|
||||
LongArray convey = new LongArray();
|
||||
float minitem = 1, elapsed;
|
||||
|
||||
@Override
|
||||
@@ -191,7 +193,7 @@ public class Conveyor extends Block{
|
||||
stream.writeInt(convey.size);
|
||||
|
||||
for(int i = 0; i < convey.size; i ++){
|
||||
stream.writeInt(convey.get(i));
|
||||
stream.writeInt(pos1.toInt(convey.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +204,7 @@ public class Conveyor extends Block{
|
||||
convey.ensureCapacity(amount);
|
||||
|
||||
for(int i = 0; i < amount; i ++){
|
||||
convey.add(stream.readInt());
|
||||
convey.add(pos1.getValue(stream.readInt()));
|
||||
}
|
||||
|
||||
sort(convey.items, convey.size);
|
||||
@@ -215,11 +217,11 @@ public class Conveyor extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
private static void sort(int[] elements, int length){
|
||||
List<Integer> wrapper = new AbstractList<Integer>() {
|
||||
private static void sort(long[] elements, int length){
|
||||
List<Long> wrapper = new AbstractList<Long>() {
|
||||
|
||||
@Override
|
||||
public Integer get(int index) {
|
||||
public Long get(int index) {
|
||||
return elements[index];
|
||||
}
|
||||
|
||||
@@ -229,8 +231,8 @@ public class Conveyor extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer set(int index, Integer element) {
|
||||
int v = elements[index];
|
||||
public Long set(int index, Long element) {
|
||||
long v = elements[index];
|
||||
elements[index] = element;
|
||||
return v;
|
||||
}
|
||||
@@ -239,7 +241,7 @@ public class Conveyor extends Block{
|
||||
Collections.sort(wrapper, Conveyor::compareItems);
|
||||
}
|
||||
|
||||
private static int compareItems(Integer a, Integer b){
|
||||
private static int compareItems(Long a, Long b){
|
||||
pos1.set(a);
|
||||
pos2.set(b);
|
||||
return Float.compare(pos1.y, pos2.y);
|
||||
@@ -266,20 +268,50 @@ public class Conveyor extends Block{
|
||||
seed = values[3];
|
||||
return this;
|
||||
}
|
||||
|
||||
ItemPos set(long lvalue){
|
||||
short[] values = Bits.getShorts(lvalue);
|
||||
|
||||
if(values[0] >= Item.getAllItems().size || values[0] < 0)
|
||||
item = null;
|
||||
else
|
||||
item = Item.getAllItems().get(values[0]);
|
||||
|
||||
x = values[1] / (float)Short.MAX_VALUE;
|
||||
y = ((float)values[2]) / Short.MAX_VALUE + 1f;
|
||||
seed = (byte)values[3];
|
||||
return this;
|
||||
}
|
||||
|
||||
int pack(){
|
||||
long pack(){
|
||||
return packItem(item, x, y, seed);
|
||||
}
|
||||
|
||||
static int packItem(Item item, float x, float y, byte seed){
|
||||
static long packItem(Item item, float x, float y, byte seed){
|
||||
short[] shorts = Bits.getShorts(0);
|
||||
shorts[0] = (short)item.id;
|
||||
shorts[1] = (short)(x*Short.MAX_VALUE);
|
||||
shorts[2] = (short)((y - 1f)*Short.MAX_VALUE);
|
||||
shorts[3] = seed;
|
||||
return Bits.packLong(shorts);
|
||||
}
|
||||
|
||||
static int packItemInt(Item item, float x, float y, byte seed){
|
||||
byte[] bytes = Bits.getBytes(0);
|
||||
bytes[0] = (byte)item.id;
|
||||
bytes[1] = (byte)(x*127);
|
||||
bytes[2] = (byte)(y*255-128);
|
||||
bytes[3] = seed;
|
||||
//UCore.log("Packing item: ", item, x, y, seed, "\n", Arrays.toString(bytes));
|
||||
//UCore.log(Arrays.toString(Bits.getBytes(Bits.packInt(bytes))));
|
||||
return Bits.packInt(bytes);
|
||||
}
|
||||
|
||||
int toInt(long value){
|
||||
set(value);
|
||||
return packItemInt(item, x, y, seed);
|
||||
}
|
||||
|
||||
long getValue(int value){
|
||||
return set(value).pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,19 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
|
||||
public class LiquidRouter extends Conduit{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
public LiquidRouter(String name) {
|
||||
super(name);
|
||||
rotate = false;
|
||||
solid = true;
|
||||
flowfactor = 2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerDump, 2) && entity.liquidAmount > 0){
|
||||
if(entity.liquidAmount > 0){
|
||||
if(tile.getExtra() != tile.getRotation()){
|
||||
tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
@@ -20,6 +19,8 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class NuclearReactor extends LiquidPowerGenerator{
|
||||
protected final int timerFuel = timers++;
|
||||
|
||||
@@ -65,7 +66,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
float fullness = (float)fuel / itemCapacity;
|
||||
|
||||
if(fuel > 0){
|
||||
entity.heat += fullness * heating;
|
||||
entity.heat += fullness * heating * Timers.delta();
|
||||
entity.power += powerMultiplier * fullness * Timers.delta();
|
||||
entity.power = Mathf.clamp(entity.power, 0f, powerCapacity);
|
||||
if(entity.timer.get(timerFuel, fuelUseTime)){
|
||||
|
||||
@@ -73,12 +73,12 @@ public class Pump extends LiquidBlock{
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(tile.floor().liquidDrop != null){
|
||||
float maxPump = Math.min(liquidCapacity - entity.liquidAmount, pumpAmount);
|
||||
float maxPump = Math.min(liquidCapacity - entity.liquidAmount, pumpAmount * Timers.delta());
|
||||
entity.liquid = tile.floor().liquidDrop;
|
||||
entity.liquidAmount += maxPump;
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDump, 2)){
|
||||
if(entity.timer.get(timerDump, 1)){
|
||||
tryDumpLiquid(tile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user