Fixed bugs with FPS and map sending

This commit is contained in:
Anuken
2018-01-28 10:33:44 -05:00
parent 5cba3050b9
commit adfa66a73b
11 changed files with 87 additions and 39 deletions

1
.gitignore vendored
View File

@@ -10,6 +10,7 @@
/desktop/gifexport/ /desktop/gifexport/
/core/lib/ /core/lib/
/kryonet/build/ /kryonet/build/
/server/build/
/android/assets/mindustry-maps/ /android/assets/mindustry-maps/
/android/assets/mindustry-saves/ /android/assets/mindustry-saves/
/core/assets/gifexport/ /core/assets/gifexport/

View File

@@ -22,7 +22,7 @@ allprojects {
appName = "Mindustry" appName = "Mindustry"
gdxVersion = '1.9.8' gdxVersion = '1.9.8'
aiVersion = '1.8.1' aiVersion = '1.8.1'
uCoreVersion = '09bbb56' uCoreVersion = 'fe0b063'
} }
repositories { repositories {

View File

@@ -124,7 +124,7 @@ public class Pathfind{
//go through each spawnpoint, and if it's not found a path yet, update it //go through each spawnpoint, and if it's not found a path yet, update it
for(SpawnPoint point : world.getSpawns()){ for(SpawnPoint point : world.getSpawns()){
if(point.request == null || point.finder == null){ if(point.request == null || point.finder == null){
resetPathFor(point); continue;
} }
if(!point.request.pathFound){ if(!point.request.pathFound){

View File

@@ -38,7 +38,6 @@ public class Control extends Module{
private Tutorial tutorial = new Tutorial(); private Tutorial tutorial = new Tutorial();
private boolean hiscore = false; private boolean hiscore = false;
private boolean shouldUpdateItems = false;
private boolean wasPaused = false; private boolean wasPaused = false;
private Saves saves; private Saves saves;
@@ -304,9 +303,9 @@ public class Control extends Module{
saves.update(); 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(); ui.hudfrag.updateItems();
shouldUpdateItems = false; state.inventory.setUpdated(false);
} }
if(!state.is(State.menu)){ if(!state.is(State.menu)){

View File

@@ -9,8 +9,18 @@ import static io.anuke.mindustry.Vars.debug;
public class Inventory { public class Inventory {
private final int[] items = new int[Item.getAllItems().size]; 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(){ public void clearItems(){
updated = true;
Arrays.fill(items, 0); Arrays.fill(items, 0);
addItem(Item.stone, 40); addItem(Item.stone, 40);
@@ -29,6 +39,7 @@ public class Inventory {
} }
public void addItem(Item item, int amount){ public void addItem(Item item, int amount){
updated = true;
items[item.id] += amount; items[item.id] += amount;
} }
@@ -47,24 +58,29 @@ public class Inventory {
} }
public boolean hasItem(ItemStack req){ public boolean hasItem(ItemStack req){
updated = true;
return items[req.item.id] >= req.amount; return items[req.item.id] >= req.amount;
} }
public boolean hasItem(Item item, int amount){ public boolean hasItem(Item item, int amount){
updated = true;
return items[item.id] >= amount; return items[item.id] >= amount;
} }
public void removeItem(ItemStack req){ public void removeItem(ItemStack req){
updated = true;
items[req.item.id] -= req.amount; items[req.item.id] -= req.amount;
if(items[req.item.id] < 0) items[req.item.id] = 0; //prevents negative item glitches in multiplayer if(items[req.item.id] < 0) items[req.item.id] = 0; //prevents negative item glitches in multiplayer
} }
public void removeItems(ItemStack... reqs){ public void removeItems(ItemStack... reqs){
updated = true;
for(ItemStack req : reqs) for(ItemStack req : reqs)
removeItem(req); removeItem(req);
} }
public int[] getItems(){ public int[] getItems(){
updated = true;
return items; return items;
} }
} }

View File

@@ -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((byte)(length > 127 ? length - 256 : length));
stream.writeByte(id); stream.writeByte(id);

View File

@@ -1,11 +1,6 @@
package io.anuke.mindustry.world.blocks.types; 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 com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.resource.Liquid; import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Block; 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.graphics.Draw;
import io.anuke.ucore.util.Mathf; 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{ public class LiquidBlock extends Block implements LiquidAcceptor{
protected final int timerFlow = timers++; protected final int timerFlow = timers++;
@@ -57,7 +56,7 @@ public class LiquidBlock extends Block implements LiquidAcceptor{
public void update(Tile tile){ public void update(Tile tile){
LiquidEntity entity = tile.entity(); 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()]); tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]);
} }

View File

@@ -1,14 +1,14 @@
package io.anuke.mindustry.world.blocks.types.distribution; package io.anuke.mindustry.world.blocks.types.distribution;
import com.badlogic.gdx.utils.Array; 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.entities.TileEntity;
import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Layer; import io.anuke.mindustry.world.Layer;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Bits; import io.anuke.ucore.util.Bits;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Strings;
@@ -26,7 +26,7 @@ import static io.anuke.mindustry.Vars.tilesize;
public class Conveyor extends Block{ public class Conveyor extends Block{
private static ItemPos pos1 = new ItemPos(); private static ItemPos pos1 = new ItemPos();
private static ItemPos pos2 = 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 itemSpace = 0.135f;
private static final float offsetScl = 128f*3f; private static final float offsetScl = 128f*3f;
private static final float itemSize = 4f; private static final float itemSize = 4f;
@@ -96,7 +96,7 @@ public class Conveyor extends Block{
float shift = entity.elapsed * speed; float shift = entity.elapsed * speed;
for(int i = 0; i < entity.convey.size; i ++){ 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); ItemPos pos = pos1.set(value);
if(pos.item == null){ if(pos.item == null){
@@ -105,10 +105,12 @@ public class Conveyor extends Block{
} }
boolean canmove = i == entity.convey.size - 1 || 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){ 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); pos.x = Mathf.lerpDelta(pos.x, 0, 0.06f);
}else{ }else{
pos.x = Mathf.lerpDelta(pos.x, pos.seed/offsetScl, 0.1f); 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; float y = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0;
ConveyorEntity entity = tile.entity(); 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; boolean inserted = false;
for(int i = 0; i < entity.convey.size; i ++){ 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. * Size is 4 bytes, or one int.
*/ */
public static class ConveyorEntity extends TileEntity{ public static class ConveyorEntity extends TileEntity{
IntArray convey = new IntArray(); LongArray convey = new LongArray();
float minitem = 1, elapsed; float minitem = 1, elapsed;
@Override @Override
@@ -191,7 +193,7 @@ public class Conveyor extends Block{
stream.writeInt(convey.size); stream.writeInt(convey.size);
for(int i = 0; i < convey.size; i ++){ 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); convey.ensureCapacity(amount);
for(int i = 0; i < amount; i ++){ for(int i = 0; i < amount; i ++){
convey.add(stream.readInt()); convey.add(pos1.getValue(stream.readInt()));
} }
sort(convey.items, convey.size); sort(convey.items, convey.size);
@@ -215,11 +217,11 @@ public class Conveyor extends Block{
} }
} }
private static void sort(int[] elements, int length){ private static void sort(long[] elements, int length){
List<Integer> wrapper = new AbstractList<Integer>() { List<Long> wrapper = new AbstractList<Long>() {
@Override @Override
public Integer get(int index) { public Long get(int index) {
return elements[index]; return elements[index];
} }
@@ -229,8 +231,8 @@ public class Conveyor extends Block{
} }
@Override @Override
public Integer set(int index, Integer element) { public Long set(int index, Long element) {
int v = elements[index]; long v = elements[index];
elements[index] = element; elements[index] = element;
return v; return v;
} }
@@ -239,7 +241,7 @@ public class Conveyor extends Block{
Collections.sort(wrapper, Conveyor::compareItems); Collections.sort(wrapper, Conveyor::compareItems);
} }
private static int compareItems(Integer a, Integer b){ private static int compareItems(Long a, Long b){
pos1.set(a); pos1.set(a);
pos2.set(b); pos2.set(b);
return Float.compare(pos1.y, pos2.y); return Float.compare(pos1.y, pos2.y);
@@ -267,19 +269,49 @@ public class Conveyor extends Block{
return this; return this;
} }
int pack(){ 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;
}
long pack(){
return packItem(item, x, y, seed); 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); byte[] bytes = Bits.getBytes(0);
bytes[0] = (byte)item.id; bytes[0] = (byte)item.id;
bytes[1] = (byte)(x*127); bytes[1] = (byte)(x*127);
bytes[2] = (byte)(y*255-128); bytes[2] = (byte)(y*255-128);
bytes[3] = seed; 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); return Bits.packInt(bytes);
} }
int toInt(long value){
set(value);
return packItemInt(item, x, y, seed);
}
long getValue(int value){
return set(value).pack();
}
} }
} }

View File

@@ -5,19 +5,19 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
public class LiquidRouter extends Conduit{ public class LiquidRouter extends Conduit{
protected final int timerDump = timers++;
public LiquidRouter(String name) { public LiquidRouter(String name) {
super(name); super(name);
rotate = false; rotate = false;
solid = true; solid = true;
flowfactor = 2f;
} }
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
LiquidEntity entity = tile.entity(); LiquidEntity entity = tile.entity();
if(entity.timer.get(timerDump, 2) && entity.liquidAmount > 0){ if(entity.liquidAmount > 0){
if(tile.getExtra() != tile.getRotation()){ if(tile.getExtra() != tile.getRotation()){
tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]); tryMoveLiquid(tile, tile.getNearby()[tile.getRotation()]);
} }

View File

@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.effect.DamageArea; import io.anuke.mindustry.entities.effect.DamageArea;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
@@ -20,6 +19,8 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
public class NuclearReactor extends LiquidPowerGenerator{ public class NuclearReactor extends LiquidPowerGenerator{
protected final int timerFuel = timers++; protected final int timerFuel = timers++;
@@ -65,7 +66,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
float fullness = (float)fuel / itemCapacity; float fullness = (float)fuel / itemCapacity;
if(fuel > 0){ if(fuel > 0){
entity.heat += fullness * heating; entity.heat += fullness * heating * Timers.delta();
entity.power += powerMultiplier * fullness * Timers.delta(); entity.power += powerMultiplier * fullness * Timers.delta();
entity.power = Mathf.clamp(entity.power, 0f, powerCapacity); entity.power = Mathf.clamp(entity.power, 0f, powerCapacity);
if(entity.timer.get(timerFuel, fuelUseTime)){ if(entity.timer.get(timerFuel, fuelUseTime)){

View File

@@ -73,12 +73,12 @@ public class Pump extends LiquidBlock{
LiquidEntity entity = tile.entity(); LiquidEntity entity = tile.entity();
if(tile.floor().liquidDrop != null){ 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.liquid = tile.floor().liquidDrop;
entity.liquidAmount += maxPump; entity.liquidAmount += maxPump;
} }
if(entity.timer.get(timerDump, 2)){ if(entity.timer.get(timerDump, 1)){
tryDumpLiquid(tile); tryDumpLiquid(tile);
} }
} }