More fixes to conveyor corruption and extra settings

This commit is contained in:
Anuken
2018-02-01 17:31:21 -05:00
parent c62af31401
commit 714965329c
3 changed files with 45 additions and 40 deletions
+1 -1
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 = 'dae4fac' uCoreVersion = 'f8a3b56'
} }
repositories { repositories {
@@ -113,15 +113,22 @@ public class SettingsMenuDialog extends SettingsDialog{
game.sliderPref("sensitivity", 100, 10, 300, i -> i + "%"); game.sliderPref("sensitivity", 100, 10, 300, i -> i + "%");
game.sliderPref("saveinterval", 90, 10, 5*120, i -> Bundles.format("setting.seconds", i)); game.sliderPref("saveinterval", 90, 10, 5*120, i -> Bundles.format("setting.seconds", i));
graphics.checkPref("fps", false); if(!android && !gwt) {
graphics.checkPref("vsync", true, b -> Gdx.graphics.setVSync(b)); graphics.checkPref("vsync", true, b -> Gdx.graphics.setVSync(b));
graphics.checkPref("fullscreen", false, b -> { graphics.checkPref("fullscreen", false, b -> {
if(b){ if (b) {
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
} else {
Gdx.graphics.setWindowedMode(600, 480);
}
});
Gdx.graphics.setVSync(Settings.getBool("vsync"));
if(Settings.getBool("fullscreen")){
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
}else{
Gdx.graphics.setWindowedMode(600, 480);
} }
}); }
graphics.checkPref("fps", false);
graphics.checkPref("lasers", true); graphics.checkPref("lasers", true);
graphics.checkPref("indicators", true); graphics.checkPref("indicators", true);
graphics.checkPref("healthbars", true); graphics.checkPref("healthbars", true);
@@ -140,11 +147,6 @@ public class SettingsMenuDialog extends SettingsDialog{
} }
renderer.setPixelate(b); renderer.setPixelate(b);
}); });
Gdx.graphics.setVSync(Settings.getBool("vsync"));
if(!gwt && Settings.getBool("fullscreen")){
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
}
} }
private void back(){ private void back(){
@@ -185,7 +185,6 @@ 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{
private static ItemPos writePos = new ItemPos();
LongArray convey = new LongArray(); LongArray convey = new LongArray();
float minitem = 1, elapsed; float minitem = 1, elapsed;
@@ -195,7 +194,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(writePos.toInt(convey.get(i))); stream.writeInt(ItemPos.toInt(convey.get(i)));
} }
} }
@@ -206,7 +205,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(writePos.getValue(stream.readInt())); convey.add(ItemPos.toLong(stream.readInt()));
} }
sort(convey.items, convey.size); sort(convey.items, convey.size);
@@ -251,26 +250,15 @@ public class Conveyor extends Block{
//Container class. Do not instantiate. //Container class. Do not instantiate.
static class ItemPos{ static class ItemPos{
private static short[] writeShort = new short[4];
private static byte[] writeByte = new byte[4];
Item item; Item item;
float x, y; float x, y;
byte seed; byte seed;
private ItemPos(){} private ItemPos(){}
ItemPos set(int value){
byte[] values = Bits.getBytes(value);
if(values[0] >= Item.getAllItems().size || values[0] < 0)
item = null;
else
item = Item.getAllItems().get(values[0]);
x = values[1] / 127f;
y = ((int)values[2] + 128) / 255f;
seed = values[3];
return this;
}
ItemPos set(long lvalue){ ItemPos set(long lvalue){
short[] values = Bits.getShorts(lvalue); short[] values = Bits.getShorts(lvalue);
@@ -290,7 +278,7 @@ public class Conveyor extends Block{
} }
static long 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); short[] shorts = Bits.getShorts();
shorts[0] = (short)item.id; shorts[0] = (short)item.id;
shorts[1] = (short)(x*Short.MAX_VALUE); shorts[1] = (short)(x*Short.MAX_VALUE);
shorts[2] = (short)((y - 1f)*Short.MAX_VALUE); shorts[2] = (short)((y - 1f)*Short.MAX_VALUE);
@@ -298,22 +286,37 @@ public class Conveyor extends Block{
return Bits.packLong(shorts); return Bits.packLong(shorts);
} }
static int packItemInt(Item item, float x, float y, byte seed){ static int toInt(long value){
byte[] bytes = Bits.getBytes(0); short[] values = Bits.getShorts(value, writeShort);
bytes[0] = (byte)item.id;
short itemid = values[0];
float x = values[1] / (float)Short.MAX_VALUE;
float y = ((float)values[2]) / Short.MAX_VALUE + 1f;
byte seed = (byte)values[3];
byte[] bytes = writeByte;
bytes[0] = (byte)itemid;
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;
return Bits.packInt(bytes); return Bits.packInt(bytes);
} }
int toInt(long value){ static long toLong(int value){
set(value); byte[] values = Bits.getBytes(value, writeByte);
return packItemInt(item, x, y, seed);
}
long getValue(int value){ byte itemid = values[0];
return set(value).pack(); float x = values[1] / 127f;
float y = ((int)values[2] + 128) / 255f;
byte seed = values[3];
short[] shorts = writeShort;
shorts[0] = (short)itemid;
shorts[1] = (short)(x*Short.MAX_VALUE);
shorts[2] = (short)((y - 1f)*Short.MAX_VALUE);
shorts[3] = seed;
return Bits.packLong(shorts);
} }
} }
} }