mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Fix grouped region updating. Will need to account for re-adding StaticObjects after they have been removed from the game world. Also commented out some broken functionality in bootstrap involving first/second/third/etc message handlers. Should revisit with fix.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package org.apollo.game.message.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apollo.game.message.Message;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.area.RegionCoordinates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A {@link Message} sent to the client that contains multiple
|
||||
*
|
||||
@@ -14,9 +14,9 @@ import org.apollo.game.model.area.RegionCoordinates;
|
||||
public final class GroupedRegionUpdateMessage extends Message {
|
||||
|
||||
/**
|
||||
* The Position of the Player.
|
||||
* The last known region Position of the Player.
|
||||
*/
|
||||
private final Position player;
|
||||
private final Position lastKnownRegion;
|
||||
|
||||
/**
|
||||
* The Position of the Region being updated.
|
||||
@@ -31,12 +31,12 @@ public final class GroupedRegionUpdateMessage extends Message {
|
||||
/**
|
||||
* Creates the GroupedRegionUpdateMessage.
|
||||
*
|
||||
* @param player The {@link Position} of the Player.
|
||||
* @param lastKnownRegion The last known region {@link Position} of the Player.
|
||||
* @param coordinates The {@link RegionCoordinates} of the Region being updated.
|
||||
* @param messages The {@link List} of {@link RegionUpdateMessage}s.
|
||||
*/
|
||||
public GroupedRegionUpdateMessage(Position player, RegionCoordinates coordinates, List<RegionUpdateMessage> messages) {
|
||||
this.player = player;
|
||||
public GroupedRegionUpdateMessage(Position lastKnownRegion, RegionCoordinates coordinates, List<RegionUpdateMessage> messages) {
|
||||
this.lastKnownRegion = lastKnownRegion;
|
||||
this.region = new Position(coordinates.getAbsoluteX(), coordinates.getAbsoluteY());
|
||||
this.messages = messages;
|
||||
}
|
||||
@@ -46,8 +46,8 @@ public final class GroupedRegionUpdateMessage extends Message {
|
||||
*
|
||||
* @return The Position.
|
||||
*/
|
||||
public Position getPlayerPosition() {
|
||||
return player;
|
||||
public Position getLastKnownRegion() {
|
||||
return lastKnownRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
package org.apollo.game.sync.task;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apollo.game.message.impl.ClearRegionMessage;
|
||||
import org.apollo.game.message.impl.GroupedRegionUpdateMessage;
|
||||
import org.apollo.game.message.impl.RegionChangeMessage;
|
||||
@@ -17,7 +11,7 @@ import org.apollo.game.model.area.RegionCoordinates;
|
||||
import org.apollo.game.model.area.RegionRepository;
|
||||
import org.apollo.game.model.entity.Player;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A {@link SynchronizationTask} which does pre-synchronization work for the specified {@link Player}.
|
||||
@@ -181,7 +175,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
player.send(new ClearRegionMessage(position, coordinates));
|
||||
}
|
||||
|
||||
Optional<GroupedRegionUpdateMessage> message = toUpdateMessage(local, position, coordinates, repository);
|
||||
Optional<GroupedRegionUpdateMessage> message = toUpdateMessage(local, player.getLastKnownRegion(), coordinates, repository);
|
||||
if (message.isPresent()) {
|
||||
messages.add(message.get());
|
||||
}
|
||||
@@ -216,12 +210,12 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
* {@link Optional#empty()} if no update message is required.
|
||||
*
|
||||
* @param mode The RegionUpdateMode for the Message.
|
||||
* @param position The {@link Position} of the Player.
|
||||
* @param lastKnownRegion The last known region {@link Position} of the Player.
|
||||
* @param coordinates The {@link RegionCoordinates} of the {@link Region}.
|
||||
* @param repository The {@link RegionRepository} containing the Regions.
|
||||
* @return The Optional containing the GroupedRegionUpdateMessage.
|
||||
*/
|
||||
private Optional<GroupedRegionUpdateMessage> toUpdateMessage(RegionUpdateMode mode, Position position, RegionCoordinates coordinates, RegionRepository repository) {
|
||||
private Optional<GroupedRegionUpdateMessage> toUpdateMessage(RegionUpdateMode mode, Position lastKnownRegion, RegionCoordinates coordinates, RegionRepository repository) {
|
||||
List<RegionUpdateMessage> messages;
|
||||
|
||||
/*
|
||||
@@ -237,7 +231,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
messages = updates.get(coordinates);
|
||||
if (messages == null) {
|
||||
synchronized (updates) {
|
||||
messages = updates.computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(position.getHeight()));
|
||||
messages = updates.computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(lastKnownRegion.getHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +240,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
messages = snapshots.get(coordinates);
|
||||
if (messages == null) {
|
||||
synchronized (snapshots) {
|
||||
messages = snapshots.computeIfAbsent(coordinates, coords -> repository.get(coords).getSnapshot(position.getHeight()));
|
||||
messages = snapshots.computeIfAbsent(coordinates, coords -> repository.get(coords).getSnapshot(lastKnownRegion.getHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +249,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
throw new IllegalArgumentException("Unrecognised RegionUpdateMode " + mode + ".");
|
||||
}
|
||||
|
||||
return messages.isEmpty() ? Optional.empty() : Optional.of(new GroupedRegionUpdateMessage(position, coordinates, messages));
|
||||
return messages.isEmpty() ? Optional.empty() : Optional.of(new GroupedRegionUpdateMessage(lastKnownRegion, coordinates, messages));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,11 +35,11 @@ public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder<Grou
|
||||
@Override
|
||||
public GamePacket encode(GroupedRegionUpdateMessage message) {
|
||||
GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.VARIABLE_SHORT);
|
||||
Position player = message.getPlayerPosition(), region = message.getRegionPosition();
|
||||
Position lastKnownRegion = message.getLastKnownRegion(), region = message.getRegionPosition();
|
||||
|
||||
builder.put(DataType.BYTE, player.getLocalY(region));
|
||||
System.out.println("Grum: local x: " + player.getLocalX(region) + ", local y: " + player.getLocalY(region));
|
||||
builder.put(DataType.BYTE, DataTransformation.NEGATE, player.getLocalX(region));
|
||||
builder.put(DataType.BYTE, region.getLocalY(lastKnownRegion));
|
||||
builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(lastKnownRegion));
|
||||
System.out.println("Grum: local x: " + lastKnownRegion.getLocalX(region) + ", local y: " + lastKnownRegion.getLocalY(region));
|
||||
|
||||
for (RegionUpdateMessage update : message.getMessages()) {
|
||||
System.out.println("==== Sending " + update + " as part of grum");
|
||||
|
||||
@@ -39,7 +39,7 @@ public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder<Grou
|
||||
@Override
|
||||
public GamePacket encode(GroupedRegionUpdateMessage message) {
|
||||
GamePacketBuilder builder = new GamePacketBuilder(183, PacketType.VARIABLE_SHORT);
|
||||
Position base = message.getPlayerPosition(), region = message.getRegionPosition();
|
||||
Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
|
||||
|
||||
builder.put(DataType.BYTE, region.getLocalX(base));
|
||||
builder.put(DataType.BYTE, DataTransformation.ADD, region.getLocalY(base));
|
||||
|
||||
Reference in New Issue
Block a user