Refactored Packets and most TickerTasks
This commit is contained in:
parent
fd0269f913
commit
eaea6fdad9
@ -7,9 +7,9 @@ import ru.windcorp.progressia.client.Client;
|
|||||||
import ru.windcorp.progressia.client.graphics.world.EntityAnchor;
|
import ru.windcorp.progressia.client.graphics.world.EntityAnchor;
|
||||||
import ru.windcorp.progressia.common.comms.CommsListener;
|
import ru.windcorp.progressia.common.comms.CommsListener;
|
||||||
import ru.windcorp.progressia.common.comms.packets.Packet;
|
import ru.windcorp.progressia.common.comms.packets.Packet;
|
||||||
import ru.windcorp.progressia.common.comms.packets.PacketSetLocalPlayer;
|
|
||||||
import ru.windcorp.progressia.common.comms.packets.PacketWorldChange;
|
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketSetLocalPlayer;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketWorldChange;
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||||
|
|
||||||
// TODO refactor with no mercy
|
// TODO refactor with no mercy
|
||||||
@ -34,14 +34,14 @@ public class DefaultClientCommsListener implements CommsListener {
|
|||||||
|
|
||||||
private void setLocalPlayer(PacketSetLocalPlayer packet) {
|
private void setLocalPlayer(PacketSetLocalPlayer packet) {
|
||||||
EntityData entity = getClient().getWorld().getData().getEntity(
|
EntityData entity = getClient().getWorld().getData().getEntity(
|
||||||
packet.getLocalPlayerEntityId()
|
packet.getEntityId()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
CrashReports.report(
|
CrashReports.report(
|
||||||
null,
|
null,
|
||||||
"Player entity with ID %s not found",
|
"Player entity with ID %s not found",
|
||||||
new String(StringUtil.toFullHex(packet.getLocalPlayerEntityId()))
|
new String(StringUtil.toFullHex(packet.getEntityId()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package ru.windcorp.progressia.common.comms.controls;
|
package ru.windcorp.progressia.common.comms.controls;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.comms.packets.Packet;
|
import ru.windcorp.progressia.common.comms.packets.Packet;
|
||||||
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
|
|
||||||
public class PacketControl extends Packet {
|
public class PacketControl extends Packet {
|
||||||
|
|
||||||
@ -15,4 +20,14 @@ public class PacketControl extends Packet {
|
|||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput input) throws IOException, DecodingException {
|
||||||
|
// TODO implement controls
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
// implement controls
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
package ru.windcorp.progressia.common.comms.packets;
|
package ru.windcorp.progressia.common.comms.packets;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Packet extends Namespaced {
|
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||||
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
|
|
||||||
|
public abstract class Packet extends Namespaced {
|
||||||
|
|
||||||
public Packet(String id) {
|
public Packet(String id) {
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void read(DataInput input) throws IOException, DecodingException;
|
||||||
|
public abstract void write(DataOutput output) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package ru.windcorp.progressia.common.comms.packets;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
|
||||||
import ru.windcorp.progressia.common.io.ChunkIO;
|
|
||||||
import ru.windcorp.progressia.common.util.DataBuffer;
|
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
|
||||||
import ru.windcorp.progressia.common.world.DecodingException;
|
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
|
||||||
|
|
||||||
public class PacketLoadChunk extends PacketWorldChange {
|
|
||||||
|
|
||||||
private final DataBuffer data = new DataBuffer();
|
|
||||||
private final Vec3i position = new Vec3i();
|
|
||||||
|
|
||||||
public PacketLoadChunk(String id) {
|
|
||||||
super(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply(WorldData world) {
|
|
||||||
try {
|
|
||||||
world.addChunk(ChunkIO.load(world, position, data.getInputStream()));
|
|
||||||
} catch (DecodingException | IOException e) {
|
|
||||||
CrashReports.report(e, "Could not load chunk");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec3i getPosition() {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataBuffer getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package ru.windcorp.progressia.common.comms.packets;
|
|
||||||
|
|
||||||
public class PacketSetLocalPlayer extends Packet {
|
|
||||||
|
|
||||||
private long localPlayerEntityId;
|
|
||||||
|
|
||||||
public PacketSetLocalPlayer(long entityId) {
|
|
||||||
this("Core:SetLocalPlayer", entityId);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected PacketSetLocalPlayer(String id, long entityId) {
|
|
||||||
super(id);
|
|
||||||
this.localPlayerEntityId = entityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLocalPlayerEntityId() {
|
|
||||||
return localPlayerEntityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocalPlayerEntityId(long localPlayerEntityId) {
|
|
||||||
this.localPlayerEntityId = localPlayerEntityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,13 @@
|
|||||||
|
package ru.windcorp.progressia.common.world;
|
||||||
|
|
||||||
|
import glm.vec._3.i.Vec3i;
|
||||||
|
|
||||||
|
public abstract class PacketChunkChange extends PacketWorldChange {
|
||||||
|
|
||||||
|
public PacketChunkChange(String id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void getAffectedChunk(Vec3i output);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package ru.windcorp.progressia.common.world;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import glm.vec._3.i.Vec3i;
|
||||||
|
import ru.windcorp.progressia.common.io.ChunkIO;
|
||||||
|
import ru.windcorp.progressia.common.util.DataBuffer;
|
||||||
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
|
|
||||||
|
public class PacketLoadChunk extends PacketChunkChange {
|
||||||
|
|
||||||
|
private final DataBuffer data = new DataBuffer();
|
||||||
|
private final Vec3i position = new Vec3i();
|
||||||
|
|
||||||
|
public PacketLoadChunk(String id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(ChunkData chunk) {
|
||||||
|
this.position.set(chunk.getX(), chunk.getY(), chunk.getZ());
|
||||||
|
|
||||||
|
try {
|
||||||
|
ChunkIO.save(chunk, this.data.getOutputStream());
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Impossible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput input) throws IOException {
|
||||||
|
this.position.set(input.readInt(), input.readInt(), input.readInt());
|
||||||
|
this.data.fill(input, input.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
output.writeInt(this.position.x);
|
||||||
|
output.writeInt(this.position.y);
|
||||||
|
output.writeInt(this.position.z);
|
||||||
|
output.writeInt(this.data.getSize());
|
||||||
|
this.data.flush(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(WorldData world) {
|
||||||
|
try {
|
||||||
|
world.addChunk(ChunkIO.load(world, position, data.getInputStream()));
|
||||||
|
} catch (DecodingException | IOException e) {
|
||||||
|
CrashReports.report(e, "Could not load chunk");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getAffectedChunk(Vec3i output) {
|
||||||
|
output.set(getPosition().x, getPosition().y, getPosition().z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3i getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataBuffer getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package ru.windcorp.progressia.common.world;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.common.comms.packets.Packet;
|
||||||
|
|
||||||
|
public class PacketSetLocalPlayer extends Packet {
|
||||||
|
|
||||||
|
private long entityId;
|
||||||
|
|
||||||
|
public PacketSetLocalPlayer() {
|
||||||
|
this("Core:SetLocalPlayer");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PacketSetLocalPlayer(String id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(long entityId) {
|
||||||
|
this.entityId = entityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput input) throws IOException, DecodingException {
|
||||||
|
this.entityId = input.readLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
output.writeLong(this.entityId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getEntityId() {
|
||||||
|
return entityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package ru.windcorp.progressia.common.comms.packets;
|
package ru.windcorp.progressia.common.world;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
import ru.windcorp.progressia.common.comms.packets.Packet;
|
||||||
|
|
||||||
public abstract class PacketWorldChange extends Packet {
|
public abstract class PacketWorldChange extends Packet {
|
||||||
|
|
@ -0,0 +1,56 @@
|
|||||||
|
package ru.windcorp.progressia.common.world.block;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import glm.vec._3.i.Vec3i;
|
||||||
|
import ru.windcorp.progressia.common.world.Coordinates;
|
||||||
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketChunkChange;
|
||||||
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
|
|
||||||
|
public class PacketSetBlock extends PacketChunkChange {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private final Vec3i blockInWorld = new Vec3i();
|
||||||
|
|
||||||
|
public PacketSetBlock() {
|
||||||
|
this("Core:SetBlock");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PacketSetBlock(String id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(BlockData block, Vec3i blockInWorld) {
|
||||||
|
this.id = block.getId();
|
||||||
|
this.blockInWorld.set(blockInWorld.x, blockInWorld.y, blockInWorld.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput input) throws IOException, DecodingException {
|
||||||
|
this.id = input.readUTF();
|
||||||
|
this.blockInWorld.set(input.readInt(), input.readInt(), input.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
output.writeUTF(this.id);
|
||||||
|
output.writeInt(this.blockInWorld.x);
|
||||||
|
output.writeInt(this.blockInWorld.y);
|
||||||
|
output.writeInt(this.blockInWorld.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(WorldData world) {
|
||||||
|
BlockData block = BlockDataRegistry.getInstance().get(id);
|
||||||
|
world.setBlock(blockInWorld, block, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getAffectedChunk(Vec3i output) {
|
||||||
|
Coordinates.convertInWorldToChunk(this.blockInWorld, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,10 +4,11 @@ import java.io.DataInput;
|
|||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.comms.packets.PacketWorldChange;
|
|
||||||
import ru.windcorp.progressia.common.state.IOContext;
|
import ru.windcorp.progressia.common.state.IOContext;
|
||||||
import ru.windcorp.progressia.common.util.DataBuffer;
|
import ru.windcorp.progressia.common.util.DataBuffer;
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketWorldChange;
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
|
|
||||||
public class PacketEntityChange extends PacketWorldChange {
|
public class PacketEntityChange extends PacketWorldChange {
|
||||||
@ -43,6 +44,28 @@ public class PacketEntityChange extends PacketWorldChange {
|
|||||||
return buffer.getWriter();
|
return buffer.getWriter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void set(EntityData entity) {
|
||||||
|
this.entityId = entity.getEntityId();
|
||||||
|
try {
|
||||||
|
entity.write(this.buffer.getWriter(), IOContext.COMMS);
|
||||||
|
} catch (IOException e) {
|
||||||
|
CrashReports.report(e, "Entity could not be written");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput input) throws IOException, DecodingException {
|
||||||
|
this.entityId = input.readLong();
|
||||||
|
this.buffer.fill(input, input.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
output.writeLong(this.entityId);
|
||||||
|
output.writeInt(this.buffer.getSize());
|
||||||
|
this.buffer.flush(output);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(WorldData world) {
|
public void apply(WorldData world) {
|
||||||
EntityData entity = world.getEntity(getEntityId());
|
EntityData entity = world.getEntity(getEntityId());
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package ru.windcorp.progressia.common.world.tile;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import glm.vec._3.i.Vec3i;
|
||||||
|
import ru.windcorp.progressia.common.world.Coordinates;
|
||||||
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketChunkChange;
|
||||||
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
|
import ru.windcorp.progressia.common.world.block.BlockFace;
|
||||||
|
|
||||||
|
public class PacketAddTile extends PacketChunkChange {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private final Vec3i blockInWorld = new Vec3i();
|
||||||
|
private BlockFace face;
|
||||||
|
|
||||||
|
public PacketAddTile() {
|
||||||
|
this("Core:AddTile");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PacketAddTile(String id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(TileData tile, Vec3i blockInWorld, BlockFace face) {
|
||||||
|
this.id = tile.getId();
|
||||||
|
this.blockInWorld.set(blockInWorld.x, blockInWorld.y, blockInWorld.z);
|
||||||
|
this.face = face;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput input) throws IOException, DecodingException {
|
||||||
|
this.id = input.readUTF();
|
||||||
|
this.blockInWorld.set(input.readInt(), input.readInt(), input.readInt());
|
||||||
|
this.face = BlockFace.getFaces().get(input.readByte());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
output.writeUTF(this.id);
|
||||||
|
output.writeInt(this.blockInWorld.x);
|
||||||
|
output.writeInt(this.blockInWorld.y);
|
||||||
|
output.writeInt(this.blockInWorld.z);
|
||||||
|
output.writeByte(this.face.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(WorldData world) {
|
||||||
|
TileData tile = TileDataRegistry.getInstance().get(id);
|
||||||
|
world.getTiles(blockInWorld, face).add(tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getAffectedChunk(Vec3i output) {
|
||||||
|
Coordinates.convertInWorldToChunk(this.blockInWorld, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package ru.windcorp.progressia.common.world.tile;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import glm.vec._3.i.Vec3i;
|
||||||
|
import ru.windcorp.progressia.common.world.Coordinates;
|
||||||
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketChunkChange;
|
||||||
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
|
import ru.windcorp.progressia.common.world.block.BlockFace;
|
||||||
|
|
||||||
|
public class PacketRemoveTile extends PacketChunkChange {
|
||||||
|
|
||||||
|
private final Vec3i blockInWorld = new Vec3i();
|
||||||
|
private BlockFace face;
|
||||||
|
private int tag;
|
||||||
|
|
||||||
|
public PacketRemoveTile() {
|
||||||
|
this("Core:RemoveTile");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PacketRemoveTile(String id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(Vec3i blockInWorld, BlockFace face, int tag) {
|
||||||
|
this.blockInWorld.set(blockInWorld.x, blockInWorld.y, blockInWorld.z);
|
||||||
|
this.face = face;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput input) throws IOException, DecodingException {
|
||||||
|
this.blockInWorld.set(input.readInt(), input.readInt(), input.readInt());
|
||||||
|
this.face = BlockFace.getFaces().get(input.readByte());
|
||||||
|
this.tag = input.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
output.writeInt(this.blockInWorld.x);
|
||||||
|
output.writeInt(this.blockInWorld.y);
|
||||||
|
output.writeInt(this.blockInWorld.z);
|
||||||
|
output.writeByte(this.face.getId());
|
||||||
|
output.writeInt(this.tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(WorldData world) {
|
||||||
|
TileDataStack stack = world.getTiles(blockInWorld, face);
|
||||||
|
stack.remove(stack.getIndexByTag(tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getAffectedChunk(Vec3i output) {
|
||||||
|
Coordinates.convertInWorldToChunk(this.blockInWorld, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,11 +11,11 @@ import gnu.trove.map.TIntObjectMap;
|
|||||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||||
import ru.windcorp.progressia.common.comms.CommsChannel.State;
|
import ru.windcorp.progressia.common.comms.CommsChannel.State;
|
||||||
import ru.windcorp.progressia.common.comms.packets.Packet;
|
import ru.windcorp.progressia.common.comms.packets.Packet;
|
||||||
import ru.windcorp.progressia.common.comms.packets.PacketLoadChunk;
|
|
||||||
import ru.windcorp.progressia.common.comms.packets.PacketSetLocalPlayer;
|
|
||||||
import ru.windcorp.progressia.common.io.ChunkIO;
|
import ru.windcorp.progressia.common.io.ChunkIO;
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketLoadChunk;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketSetLocalPlayer;
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||||
import ru.windcorp.progressia.server.Player;
|
import ru.windcorp.progressia.server.Player;
|
||||||
import ru.windcorp.progressia.server.Server;
|
import ru.windcorp.progressia.server.Server;
|
||||||
@ -88,7 +88,9 @@ public class ClientManager {
|
|||||||
client.sendPacket(packet);
|
client.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.sendPacket(new PacketSetLocalPlayer(entity.getEntityId()));
|
PacketSetLocalPlayer packet = new PacketSetLocalPlayer();
|
||||||
|
packet.set(entity.getEntityId());
|
||||||
|
client.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnectClient(Client client) {
|
public void disconnectClient(Client client) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ru.windcorp.progressia.server.comms;
|
package ru.windcorp.progressia.server.comms;
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import glm.vec._3.i.Vec3i;
|
||||||
import ru.windcorp.progressia.test.TestContent;
|
|
||||||
|
|
||||||
public abstract class ClientPlayer extends Client {
|
public abstract class ClientPlayer extends Client {
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ public abstract class ClientPlayer extends Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canSeeEntity(long entityId) {
|
public boolean canSeeEntity(long entityId) {
|
||||||
return entityId == TestContent.PLAYER_ENTITY_ID;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,59 +2,12 @@ package ru.windcorp.progressia.server.world.tasks;
|
|||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import ru.windcorp.progressia.common.world.tile.PacketAddTile;
|
||||||
import ru.windcorp.progressia.common.world.Coordinates;
|
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
|
||||||
import ru.windcorp.progressia.common.world.block.BlockFace;
|
|
||||||
import ru.windcorp.progressia.common.world.tile.TileData;
|
|
||||||
import ru.windcorp.progressia.common.world.tile.TileDataStack;
|
|
||||||
|
|
||||||
class AddTile extends CachedWorldChange {
|
class AddTile extends CachedChunkChange<PacketAddTile> {
|
||||||
|
|
||||||
private final Vec3i blockInWorld = new Vec3i();
|
|
||||||
private BlockFace face;
|
|
||||||
private TileData tile;
|
|
||||||
|
|
||||||
public AddTile(Consumer<? super CachedChange> disposer) {
|
public AddTile(Consumer<? super CachedChange> disposer) {
|
||||||
super(disposer, "Core:AddTile");
|
super(disposer, new PacketAddTile());
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize(
|
|
||||||
Vec3i position, BlockFace face,
|
|
||||||
TileData tile
|
|
||||||
) {
|
|
||||||
if (this.tile != null)
|
|
||||||
throw new IllegalStateException("Payload is not null. Current: " + this.tile + "; requested: " + tile);
|
|
||||||
|
|
||||||
this.blockInWorld.set(position.x, position.y, position.z);
|
|
||||||
this.face = face;
|
|
||||||
this.tile = tile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void affectCommon(WorldData world) {
|
|
||||||
TileDataStack tiles = world
|
|
||||||
.getChunkByBlock(blockInWorld)
|
|
||||||
.getTiles(Coordinates.convertInWorldToInChunk(blockInWorld, null), face);
|
|
||||||
|
|
||||||
tiles.add(tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getRelevantChunk(Vec3i output) {
|
|
||||||
Coordinates.convertInWorldToChunk(blockInWorld, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Vec3i getAffectedChunk(Vec3i output) {
|
|
||||||
getRelevantChunk(output);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
super.dispose();
|
|
||||||
this.tile = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package ru.windcorp.progressia.server.world.tasks;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import glm.vec._3.i.Vec3i;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketChunkChange;
|
||||||
|
|
||||||
|
public abstract class CachedChunkChange<P extends PacketChunkChange> extends CachedWorldChange<P> {
|
||||||
|
|
||||||
|
public CachedChunkChange(Consumer<? super CachedChange> disposer, P packet) {
|
||||||
|
super(disposer, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getRelevantChunk(Vec3i output) {
|
||||||
|
getPacket().getAffectedChunk(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,30 +3,30 @@ package ru.windcorp.progressia.server.world.tasks;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import glm.vec._3.i.Vec3i;
|
||||||
import ru.windcorp.progressia.common.comms.packets.PacketWorldChange;
|
|
||||||
import ru.windcorp.progressia.common.util.Vectors;
|
import ru.windcorp.progressia.common.util.Vectors;
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
import ru.windcorp.progressia.common.world.PacketWorldChange;
|
||||||
import ru.windcorp.progressia.server.Server;
|
import ru.windcorp.progressia.server.Server;
|
||||||
|
|
||||||
public abstract class CachedWorldChange extends CachedChange {
|
public abstract class CachedWorldChange<P extends PacketWorldChange> extends CachedChange {
|
||||||
|
|
||||||
private final PacketWorldChange packet;
|
private final P packet;
|
||||||
|
|
||||||
public CachedWorldChange(Consumer<? super CachedChange> disposer, String packetId) {
|
public CachedWorldChange(Consumer<? super CachedChange> disposer, P packet) {
|
||||||
super(disposer);
|
super(disposer);
|
||||||
|
this.packet = packet;
|
||||||
this.packet = new PacketWorldChange(packetId) {
|
|
||||||
@Override
|
|
||||||
public void apply(WorldData world) {
|
|
||||||
affectCommon(world);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void affect(Server server) {
|
public void affect(Server server) {
|
||||||
affectCommon(server.getWorld().getData());
|
affectLocal(server);
|
||||||
|
sendPacket(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void affectLocal(Server server) {
|
||||||
|
packet.apply(server.getWorld().getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendPacket(Server server) {
|
||||||
Vec3i v = Vectors.grab3i();
|
Vec3i v = Vectors.grab3i();
|
||||||
Vec3i chunkPos = getAffectedChunk(v);
|
Vec3i chunkPos = getAffectedChunk(v);
|
||||||
|
|
||||||
@ -43,10 +43,8 @@ public abstract class CachedWorldChange extends CachedChange {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public P getPacket() {
|
||||||
* Invoked by both Change and Packet.
|
return packet;
|
||||||
* @param world the world to affect
|
}
|
||||||
*/
|
|
||||||
protected abstract void affectCommon(WorldData world);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package ru.windcorp.progressia.server.world.tasks;
|
package ru.windcorp.progressia.server.world.tasks;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import glm.vec._3.i.Vec3i;
|
||||||
import ru.windcorp.progressia.common.state.IOContext;
|
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||||
import ru.windcorp.progressia.common.world.entity.PacketEntityChange;
|
import ru.windcorp.progressia.common.world.entity.PacketEntityChange;
|
||||||
import ru.windcorp.progressia.server.Server;
|
import ru.windcorp.progressia.server.Server;
|
||||||
@ -31,26 +28,15 @@ class ChangeEntity extends CachedChange {
|
|||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.change = change;
|
this.change = change;
|
||||||
|
|
||||||
packet.setEntityId(entity.getEntityId());
|
|
||||||
try {
|
|
||||||
entity.write(packet.getWriter(), IOContext.COMMS); // TODO wtf is this... (see whole file)
|
|
||||||
} catch (IOException e) {
|
|
||||||
CrashReports.report(e, "Could not write entity %s", entity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void affect(Server server) {
|
public void affect(Server server) {
|
||||||
((StateChange<EntityData>) change).change(entity);
|
((StateChange<EntityData>) change).change(entity);
|
||||||
|
packet.set(entity);
|
||||||
|
|
||||||
try {
|
server.getClientManager().broadcastLocal(packet, entity.getEntityId());
|
||||||
entity.write(packet.getWriter(), IOContext.COMMS); // ...and this doing at the same time? - javapony at 1 AM
|
|
||||||
} catch (IOException e) {
|
|
||||||
CrashReports.report(e, "Could not write entity %s", entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
server.getClientManager().broadcastLocal(packet, entity.getChunkCoords(null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,49 +2,12 @@ package ru.windcorp.progressia.server.world.tasks;
|
|||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import ru.windcorp.progressia.common.world.tile.PacketRemoveTile;
|
||||||
import ru.windcorp.progressia.common.world.Coordinates;
|
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
|
||||||
import ru.windcorp.progressia.common.world.block.BlockFace;
|
|
||||||
import ru.windcorp.progressia.common.world.tile.TileDataStack;
|
|
||||||
|
|
||||||
class RemoveTile extends CachedWorldChange {
|
class RemoveTile extends CachedChunkChange<PacketRemoveTile> {
|
||||||
|
|
||||||
private final Vec3i blockInWorld = new Vec3i();
|
|
||||||
private BlockFace face;
|
|
||||||
private int tag;
|
|
||||||
|
|
||||||
public RemoveTile(Consumer<? super CachedChange> disposer) {
|
public RemoveTile(Consumer<? super CachedChange> disposer) {
|
||||||
super(disposer, "Core:RemoveTile");
|
super(disposer, new PacketRemoveTile());
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize(
|
|
||||||
Vec3i position, BlockFace face,
|
|
||||||
int tag
|
|
||||||
) {
|
|
||||||
this.blockInWorld.set(position.x, position.y, position.z);
|
|
||||||
this.face = face;
|
|
||||||
this.tag = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void affectCommon(WorldData world) {
|
|
||||||
TileDataStack tiles = world
|
|
||||||
.getChunkByBlock(blockInWorld)
|
|
||||||
.getTiles(Coordinates.convertInWorldToInChunk(blockInWorld, null), face);
|
|
||||||
|
|
||||||
tiles.remove(tiles.getIndexByTag(tag));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getRelevantChunk(Vec3i output) {
|
|
||||||
Coordinates.convertInWorldToChunk(blockInWorld, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Vec3i getAffectedChunk(Vec3i output) {
|
|
||||||
getRelevantChunk(output);
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,50 +2,12 @@ package ru.windcorp.progressia.server.world.tasks;
|
|||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import ru.windcorp.progressia.common.world.block.PacketSetBlock;
|
||||||
import ru.windcorp.progressia.common.world.Coordinates;
|
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
|
||||||
import ru.windcorp.progressia.common.world.block.BlockData;
|
|
||||||
|
|
||||||
class SetBlock extends CachedWorldChange {
|
class SetBlock extends CachedChunkChange<PacketSetBlock> {
|
||||||
|
|
||||||
private final Vec3i blockInWorld = new Vec3i();
|
|
||||||
private BlockData block;
|
|
||||||
|
|
||||||
public SetBlock(Consumer<? super CachedChange> disposer) {
|
public SetBlock(Consumer<? super CachedChange> disposer) {
|
||||||
super(disposer, "Core:SetBlock");
|
super(disposer, new PacketSetBlock());
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize(Vec3i blockInWorld, BlockData block) {
|
|
||||||
if (this.block != null)
|
|
||||||
throw new IllegalStateException("Payload is not null. Current: " + this.block + "; requested: " + block);
|
|
||||||
|
|
||||||
this.blockInWorld.set(blockInWorld.x, blockInWorld.y, blockInWorld.z);
|
|
||||||
this.block = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void affectCommon(WorldData world) {
|
|
||||||
world
|
|
||||||
.getChunkByBlock(blockInWorld)
|
|
||||||
.setBlock(Coordinates.convertInWorldToInChunk(blockInWorld, null), block, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getRelevantChunk(Vec3i output) {
|
|
||||||
Coordinates.convertInWorldToChunk(blockInWorld, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Vec3i getAffectedChunk(Vec3i output) {
|
|
||||||
getRelevantChunk(output);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
super.dispose();
|
|
||||||
this.block = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -38,7 +38,7 @@ public class WorldAccessor {
|
|||||||
|
|
||||||
public void setBlock(Vec3i blockInWorld, BlockData block) {
|
public void setBlock(Vec3i blockInWorld, BlockData block) {
|
||||||
SetBlock change = cache.grab(SetBlock.class);
|
SetBlock change = cache.grab(SetBlock.class);
|
||||||
change.initialize(blockInWorld, block);
|
change.getPacket().set(block, blockInWorld);
|
||||||
server.requestChange(change);
|
server.requestChange(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public class WorldAccessor {
|
|||||||
|
|
||||||
public void addTile(Vec3i blockInWorld, BlockFace face, TileData tile) {
|
public void addTile(Vec3i blockInWorld, BlockFace face, TileData tile) {
|
||||||
AddTile change = cache.grab(AddTile.class);
|
AddTile change = cache.grab(AddTile.class);
|
||||||
change.initialize(blockInWorld, face, tile);
|
change.getPacket().set(tile, blockInWorld, face);
|
||||||
server.requestChange(change);
|
server.requestChange(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ public class WorldAccessor {
|
|||||||
|
|
||||||
public void removeTile(Vec3i blockInWorld, BlockFace face, int tag) {
|
public void removeTile(Vec3i blockInWorld, BlockFace face, int tag) {
|
||||||
RemoveTile change = cache.grab(RemoveTile.class);
|
RemoveTile change = cache.grab(RemoveTile.class);
|
||||||
change.initialize(blockInWorld, face, tag);
|
change.getPacket().set(blockInWorld, face, tag);
|
||||||
server.requestChange(change);
|
server.requestChange(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,11 @@ package ru.windcorp.progressia.test;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import glm.Glm;
|
import glm.Glm;
|
||||||
import ru.windcorp.progressia.common.comms.packets.PacketLoadChunk;
|
|
||||||
import ru.windcorp.progressia.common.comms.packets.PacketSetLocalPlayer;
|
|
||||||
import ru.windcorp.progressia.common.io.ChunkIO;
|
import ru.windcorp.progressia.common.io.ChunkIO;
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketLoadChunk;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketSetLocalPlayer;
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
import ru.windcorp.progressia.common.world.WorldDataListener;
|
import ru.windcorp.progressia.common.world.WorldDataListener;
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||||
@ -48,7 +48,10 @@ public class TestChunkSender implements WorldDataListener {
|
|||||||
|
|
||||||
if (Glm.equals(e.getChunkCoords(null), chunk.getPosition())) {
|
if (Glm.equals(e.getChunkCoords(null), chunk.getPosition())) {
|
||||||
System.out.printf("TestChunkSender: player found in (%d; %d; %d)\n", e.getChunkCoords(null).x, e.getChunkCoords(null).y, e.getChunkCoords(null).z);
|
System.out.printf("TestChunkSender: player found in (%d; %d; %d)\n", e.getChunkCoords(null).x, e.getChunkCoords(null).y, e.getChunkCoords(null).z);
|
||||||
server.getClientManager().broadcastToAllPlayers(new PacketSetLocalPlayer(e.getEntityId()));
|
|
||||||
|
PacketSetLocalPlayer packet = new PacketSetLocalPlayer();
|
||||||
|
packet.set(e.getEntityId());
|
||||||
|
server.getClientManager().broadcastToAllPlayers(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user