Fixed disconnect with many enemies and editor redo/undo bug

This commit is contained in:
Anuken
2018-01-14 11:37:23 -05:00
parent 487424f047
commit e545b7cca7
17 changed files with 88 additions and 33 deletions

View File

@@ -18,6 +18,8 @@ import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.net.Syncable;
import io.anuke.mindustry.net.Syncable.Interpolator;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Recipes;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
@@ -125,7 +127,6 @@ public class NetClient extends Module {
Syncable sync = ((Syncable)entity);
if(sync == null){
Gdx.app.error("Mindustry", "Unknown entity ID: " + id + " " + (i >= packet.enemyStart ? "(enemy)" : "(player)"));
if(!requests.contains(id)){
requests.add(id);
Gdx.app.error("Mindustry", "Sending entity request: " + id);
@@ -150,7 +151,11 @@ public class NetClient extends Module {
});
Net.handle(PlacePacket.class, packet -> {
Gdx.app.postRunnable(() -> Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false));
Gdx.app.postRunnable(() ->{
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
if(recipe != null) Vars.control.removeItems(recipe.requirements);
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
});
});
Net.handle(BreakPacket.class, packet -> {
@@ -229,8 +234,9 @@ public class NetClient extends Module {
Gdx.app.postRunnable(() -> {
try {
long timestamp = stream.readLong();
float elapsed = TimeUtils.timeSinceMillis(timestamp) / 1000f * 60f;
float time = stream.readFloat();
float elapsed = Timers.time() - time;
while (stream.available() > 0) {
int pos = stream.readInt();
@@ -241,10 +247,13 @@ public class NetClient extends Module {
byte times = stream.readByte();
for (int i = 0; i < times; i++) {
tile.entity.timer.getTimes()[i] = stream.readFloat() + elapsed;
tile.entity.timer.getTimes()[i] = stream.readFloat();
}
tile.entity.read(stream);
short data = stream.readShort();
tile.setPackedData(data);
tile.entity.readNetwork(stream, elapsed);
}
} catch (IOException e) {
throw new RuntimeException(e);
@@ -325,6 +334,10 @@ public class NetClient extends Module {
}
}
public void beginConnecting(){
connecting = true;
}
public void disconnectQuietly(){
kicked = true;
Net.disconnect();

View File

@@ -336,7 +336,7 @@ public class NetServer extends Module{
try {
DataOutputStream stream = new DataOutputStream(bs);
stream.writeLong(TimeUtils.millis());
stream.writeFloat(Timers.time());
for (int rx = -viewx / 2; rx <= viewx / 2; rx++) {
for (int ry = -viewy / 2; ry <= viewy / 2; ry++) {
@@ -359,6 +359,8 @@ public class NetServer extends Module{
stream.writeFloat(tile.entity.timer.getTimes()[i]);
}
stream.writeShort(tile.getPackedData());
tile.entity.write(stream);
}
}

View File

@@ -53,6 +53,10 @@ public class TileEntity extends Entity{
public void read(DataInputStream stream) throws IOException{
}
public void readNetwork(DataInputStream stream, float elapsed) throws IOException{
read(stream);
}
public void onDeath(){
onDeath(false);

View File

@@ -19,7 +19,7 @@ import io.anuke.ucore.entities.Entities;
import java.io.*;
public class NetworkIO {
private static final int fileVersionID = 14;
private static final int fileVersionID = 15;
public static void write(int playerID, ByteArray upgrades, OutputStream os){
@@ -106,7 +106,7 @@ public class NetworkIO {
}
if(tile.entity != null){
stream.writeByte(tile.getRotation()); //placerot
stream.writeShort(tile.getPackedData());
stream.writeShort(tile.entity.health); //health
//items
@@ -240,11 +240,11 @@ public class NetworkIO {
}
if(tile.entity != null){
byte rotation = stream.readByte();
short data = stream.readShort();
short health = stream.readShort();
tile.entity.health = health;
tile.setRotation(rotation);
tile.setPackedData(data);
for(int j = 0; j < tile.entity.items.length; j ++){
tile.entity.items[j] = stream.readInt();

View File

@@ -24,7 +24,7 @@ public class MapGenerateDialog extends FloatingDialog{
private boolean loading;
public MapGenerateDialog(MapEditor editor) {
super("$text.generate");
super("$text.editor.generate");
this.editor = editor;
Stack stack = new Stack();

View File

@@ -143,7 +143,7 @@ public class MapView extends Element implements GestureListener{
if(op == null) op = new DrawOperation(editor.pixmap());
Pixmap next = Pixmaps.copy(editor.pixmap());
op.add(current, next);
current = next;
current = null;
stack.add(op);
op = null;
}

View File

@@ -214,6 +214,7 @@ public class JoinDialog extends FloatingDialog {
Timers.runTask(2f, () -> {
try{
Vars.netClient.beginConnecting();
Net.connect(ip, port);
hide();
join.hide();

View File

@@ -9,6 +9,7 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.builders.imagebutton;
import io.anuke.ucore.scene.builders.label;
@@ -155,6 +156,8 @@ public class HudFragment implements Fragment{
row();
new label(() -> "[orange]noclip: " + Vars.noclip).left();
row();
new label(() -> "[purple]time: " + (int)(Timers.time() / 10f) % 50).left();
row();
new label("[red]DEBUG MODE").scale(0.5f).left();
}}.end();
}

View File

@@ -186,7 +186,7 @@ public class Block{
i++;
i %= 4;
}
tile.setDump((byte)pdump);
tile.setDump(pdump);
handleItem(item, tile, tile);
}

View File

@@ -154,6 +154,14 @@ public class Tile{
return Bits.getRightByte(Bits.getRightByte(data));
}
public short getPackedData(){
return data;
}
public void setPackedData(short data){
this.data = data;
}
public boolean passable(){
Block block = block();
Block floor = floor();

View File

@@ -92,6 +92,8 @@ public class Conveyor extends Block{
removals.clear();
float shift = entity.elapsed * speed;
for(int i = 0; i < entity.convey.size; i ++){
int value = entity.convey.get(i);
ItemPos pos = pos1.set(value);
@@ -100,7 +102,7 @@ public class Conveyor extends Block{
!(pos2.set(entity.convey.get(i + 1)).y - pos.y < itemSpace * Timers.delta());
if(canmove){
pos.y += Math.max(speed * Timers.delta(), 1f/252f); //TODO fix precision issues when at high FPS?
pos.y += Math.max(speed * Timers.delta() + shift, 1f/252f); //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);
@@ -119,6 +121,8 @@ public class Conveyor extends Block{
}
}
entity.elapsed = 0f;
entity.convey.removeAll(removals);
}
@@ -174,7 +178,7 @@ public class Conveyor extends Block{
*/
public static class ConveyorEntity extends TileEntity{
IntArray convey = new IntArray();
float minitem = 1;
float minitem = 1, elapsed;
@Override
public void write(DataOutputStream stream) throws IOException{
@@ -197,6 +201,12 @@ public class Conveyor extends Block{
sort(convey.items, convey.size);
}
@Override
public void readNetwork(DataInputStream stream, float elapsed) throws IOException{
read(stream);
this.elapsed = elapsed;
}
}
private static void sort(int[] elements, int length){