Attempts at fixing desync for blocks

This commit is contained in:
Anuken
2018-01-13 18:15:58 -05:00
parent dfda83004e
commit 487424f047
3 changed files with 15 additions and 8 deletions

View File

@@ -158,13 +158,16 @@ public class NetClient extends Module {
});
Net.handle(StateSyncPacket.class, packet -> {
System.arraycopy(packet.items, 0, Vars.control.items, 0, packet.items.length);
Gdx.app.postRunnable(() -> {
Vars.control.setWaveData(packet.enemies, packet.wave, packet.countdown);
System.arraycopy(packet.items, 0, Vars.control.items, 0, packet.items.length);
Timers.resetTime(packet.time + (float)(TimeUtils.timeSinceMillis(packet.timestamp) / 1000.0 * 60.0));
Vars.control.setWaveData(packet.enemies, packet.wave, packet.countdown);
Gdx.app.postRunnable(Vars.ui.hudfrag::updateItems);
Timers.resetTime(packet.time + (float) (TimeUtils.timeSinceMillis(packet.timestamp) / 1000.0 * 60.0));
Gdx.app.postRunnable(Vars.ui.hudfrag::updateItems);
});
});
Net.handle(EnemySpawnPacket.class, spawn -> {
@@ -226,6 +229,9 @@ public class NetClient extends Module {
Gdx.app.postRunnable(() -> {
try {
long timestamp = stream.readLong();
float elapsed = TimeUtils.timeSinceMillis(timestamp) / 1000f * 60f;
while (stream.available() > 0) {
int pos = stream.readInt();
@@ -235,7 +241,7 @@ public class NetClient extends Module {
byte times = stream.readByte();
for (int i = 0; i < times; i++) {
tile.entity.timer.getTimes()[i] = stream.readFloat();
tile.entity.timer.getTimes()[i] = stream.readFloat() + elapsed;
}
tile.entity.read(stream);

View File

@@ -336,6 +336,8 @@ public class NetServer extends Module{
try {
DataOutputStream stream = new DataOutputStream(bs);
stream.writeLong(TimeUtils.millis());
for (int rx = -viewx / 2; rx <= viewx / 2; rx++) {
for (int ry = -viewy / 2; ry <= viewy / 2; ry++) {
Tile tile = Vars.world.tile(x + rx, y + ry);

View File

@@ -137,8 +137,7 @@ public class JoinDialog extends FloatingDialog {
server.content.add("[lightgray]" + Bundles.format("text.server.hostname", host.name)).pad(4);
server.content.row();
server.content.add("[lightgray]" + (host.players != 1 ? Bundles.format("text.players", host.players) :
Bundles.format("text.players.single", host.players))).left();
Bundles.format("text.players.single", host.players)));
}, e -> {
server.content.clear();
server.content.add("$text.host.invalid");
@@ -179,7 +178,7 @@ public class JoinDialog extends FloatingDialog {
content().row();
content().add(pane).width(w).pad(0);
content().row();
content().addButton("$text.server.add", "clear", () -> {
content().addCenteredImageTextButton("$text.server.add", "icon-add", "clear", 14*3, () -> {
renaming = null;
join.show();
}).width(w).height(80f);