use of org.apollo.game.message.impl.GroupedRegionUpdateMessage in project apollo by apollo-rsps.
the class GroupedRegionUpdateMessageEncoder method encode.
@Override
public GamePacket encode(GroupedRegionUpdateMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.VARIABLE_SHORT);
Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
builder.put(DataType.BYTE, region.getLocalY(base));
builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(base));
for (RegionUpdateMessage update : message.getMessages()) {
@SuppressWarnings("unchecked") MessageEncoder<RegionUpdateMessage> encoder = (MessageEncoder<RegionUpdateMessage>) release.getMessageEncoder(update.getClass());
GamePacket packet = encoder.encode(update);
builder.put(DataType.BYTE, packet.getOpcode());
builder.putBytes(packet.getPayload());
}
return builder.toGamePacket();
}
use of org.apollo.game.message.impl.GroupedRegionUpdateMessage in project apollo by apollo-rsps.
the class GroupedRegionUpdateMessageEncoder method encode.
@Override
public GamePacket encode(GroupedRegionUpdateMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(183, PacketType.VARIABLE_SHORT);
Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
builder.put(DataType.BYTE, region.getLocalX(base));
builder.put(DataType.BYTE, DataTransformation.ADD, region.getLocalY(base));
for (RegionUpdateMessage update : message.getMessages()) {
@SuppressWarnings("unchecked") MessageEncoder<RegionUpdateMessage> encoder = (MessageEncoder<RegionUpdateMessage>) release.getMessageEncoder(update.getClass());
GamePacket packet = encoder.encode(update);
builder.put(DataType.BYTE, packet.getOpcode());
builder.putBytes(packet.getPayload());
}
return builder.toGamePacket();
}
use of org.apollo.game.message.impl.GroupedRegionUpdateMessage in project apollo by apollo-rsps.
the class PrePlayerSynchronizationTask method sendUpdates.
/**
* Sends the updates for a {@link Region}
*
* @param position The {@link Position} of the last known region.
* @param differences The {@link Set} of {@link RegionCoordinates} of Regions that changed.
* @param full The {@link Set} of {@link RegionCoordinates} of Regions that require a full update.
*/
private void sendUpdates(Position position, Set<RegionCoordinates> differences, Set<RegionCoordinates> full) {
RegionRepository repository = player.getWorld().getRegionRepository();
int height = position.getHeight();
for (RegionCoordinates coordinates : differences) {
Set<RegionUpdateMessage> messages = updates.computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(height));
if (!messages.isEmpty()) {
player.send(new GroupedRegionUpdateMessage(position, coordinates, messages));
}
}
for (RegionCoordinates coordinates : full) {
Set<RegionUpdateMessage> messages = encodes.computeIfAbsent(coordinates, coords -> repository.get(coords).encode(height));
if (!messages.isEmpty()) {
player.send(new ClearRegionMessage(position, coordinates));
player.send(new GroupedRegionUpdateMessage(position, coordinates, messages));
}
}
}
Aggregations