Updated uCore, fixed GWT build, better client snapshot system
This commit is contained in:
@@ -15,10 +15,6 @@ public class EditLog {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String info() {
|
||||
return String.format("Player: %s, Block: %s, Rotation: %s, Edit Action: %s", playername, block.name(), rotation, action.toString());
|
||||
}
|
||||
|
||||
public enum EditAction {
|
||||
PLACE, BREAK
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap.Entry;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@@ -36,6 +37,14 @@ public class NetworkIO {
|
||||
stream.writeByte(state.mode.ordinal()); //gamemode
|
||||
stream.writeUTF(world.getMap().name); //map name
|
||||
|
||||
//write tags
|
||||
ObjectMap<String, String> tags = world.getMap().meta.tags;
|
||||
stream.writeByte(tags.size);
|
||||
for(Entry<String, String> entry : tags.entries()){
|
||||
stream.writeUTF(entry.key);
|
||||
stream.writeUTF(entry.value);
|
||||
}
|
||||
|
||||
stream.writeInt(state.wave); //wave
|
||||
stream.writeFloat(state.wavetime); //wave countdown
|
||||
|
||||
@@ -109,6 +118,14 @@ public class NetworkIO {
|
||||
//general state
|
||||
byte mode = stream.readByte();
|
||||
String map = stream.readUTF();
|
||||
ObjectMap<String, String> tags = new ObjectMap<>();
|
||||
|
||||
byte tagSize = stream.readByte();
|
||||
for (int i = 0; i < tagSize; i++) {
|
||||
String key = stream.readUTF();
|
||||
String value = stream.readUTF();
|
||||
tags.put(key, value);
|
||||
}
|
||||
|
||||
int wave = stream.readInt();
|
||||
float wavetime = stream.readFloat();
|
||||
@@ -135,6 +152,8 @@ public class NetworkIO {
|
||||
//TODO send advanced map meta such as author, etc
|
||||
//TODO scan for cores
|
||||
Map currentMap = new Map(map, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null);
|
||||
currentMap.meta.tags.clear();
|
||||
currentMap.meta.tags.putAll(tags);
|
||||
world.setMap(currentMap);
|
||||
|
||||
Tile[][] tiles = world.createTiles(width, height);
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||
import io.anuke.ucore.io.ByteBufferInput;
|
||||
import io.anuke.ucore.io.ByteBufferOutput;
|
||||
import io.anuke.ucore.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**Class for storing all packets.*/
|
||||
@@ -96,54 +94,38 @@ public class Packets {
|
||||
}
|
||||
|
||||
public static class ClientSnapshotPacket implements Packet{
|
||||
/**For writing only.*/
|
||||
public Player player;
|
||||
|
||||
//snapshot meta
|
||||
public int lastSnapshot;
|
||||
public int snapid;
|
||||
public int length;
|
||||
public long timeSent;
|
||||
|
||||
public byte[] bytes;
|
||||
public ByteBuffer result;
|
||||
public ByteBufferInput in;
|
||||
//player snapshot data
|
||||
public float x, y, rotation, baseRotation;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
ByteBufferOutput out = new ByteBufferOutput(buffer);
|
||||
Player player = Vars.players[0];
|
||||
|
||||
buffer.putInt(lastSnapshot);
|
||||
buffer.putInt(snapid);
|
||||
buffer.putLong(TimeUtils.millis());
|
||||
|
||||
int position = buffer.position();
|
||||
try {
|
||||
player.write(out);
|
||||
length = buffer.position() - position;
|
||||
buffer.position(position);
|
||||
buffer.putInt(length);
|
||||
player.write(out);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
buffer.putFloat(player.x);
|
||||
buffer.putFloat(player.y);
|
||||
//saving 4 bytes, yay?
|
||||
buffer.putShort((short)(player.rotation*2));
|
||||
buffer.putShort((short)(player.baseRotation*2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
|
||||
lastSnapshot = buffer.getInt();
|
||||
snapid = buffer.getInt();
|
||||
timeSent = buffer.getLong();
|
||||
length = buffer.getInt();
|
||||
|
||||
if(bytes == null || bytes.length != length){
|
||||
bytes = new byte[length];
|
||||
result = ByteBuffer.wrap(bytes);
|
||||
in = new ByteBufferInput(result);
|
||||
}
|
||||
|
||||
buffer.get(bytes);
|
||||
result.position(0);
|
||||
x = buffer.getFloat();
|
||||
y = buffer.getFloat();
|
||||
rotation = buffer.getShort()/2f;
|
||||
baseRotation = buffer.getShort()/2f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user