mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Move MapFileDecoder to the cache module.
This commit is contained in:
+3
-4
@@ -1,4 +1,4 @@
|
||||
package org.apollo.game.fs.decoder;
|
||||
package org.apollo.cache.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -8,7 +8,6 @@ import java.util.Map;
|
||||
import org.apollo.cache.IndexedFileSystem;
|
||||
import org.apollo.cache.archive.Archive;
|
||||
import org.apollo.cache.archive.ArchiveEntry;
|
||||
import org.apollo.game.model.area.Region;
|
||||
|
||||
/**
|
||||
* Decodes {@link MapDefinition}s from the {@link IndexedFileSystem}.
|
||||
@@ -21,7 +20,7 @@ public final class MapFileDecoder {
|
||||
/**
|
||||
* The width (and length) of a map file, in tiles.
|
||||
*/
|
||||
public static final int MAP_FILE_WIDTH = Region.SIZE * Region.SIZE;
|
||||
public static final int MAP_FILE_WIDTH = 64;
|
||||
|
||||
/**
|
||||
* The file id of the versions archive.
|
||||
@@ -35,7 +34,7 @@ public final class MapFileDecoder {
|
||||
* @return A {@link Map} of packed coordinates to their MapDefinitions.
|
||||
* @throws IOException If there is an error reading or decoding the Archive.
|
||||
*/
|
||||
protected static Map<Integer, MapDefinition> decode(IndexedFileSystem fs) throws IOException {
|
||||
public static Map<Integer, MapDefinition> decode(IndexedFileSystem fs) throws IOException {
|
||||
Archive archive = Archive.decode(fs.getFile(0, VERSIONS_ARCHIVE_FILE_ID));
|
||||
ArchiveEntry entry = archive.getEntry("map_index");
|
||||
Map<Integer, MapDefinition> definitions = new HashMap<>();
|
||||
@@ -9,8 +9,9 @@ import java.util.Map.Entry;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.apollo.cache.IndexedFileSystem;
|
||||
import org.apollo.cache.decoder.MapFileDecoder;
|
||||
import org.apollo.cache.decoder.MapFileDecoder.MapDefinition;
|
||||
import org.apollo.cache.def.ObjectDefinition;
|
||||
import org.apollo.game.fs.decoder.MapFileDecoder.MapDefinition;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Region;
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.apollo.game.model.area.collision.CollisionMatrix;
|
||||
import org.apollo.game.model.area.update.UpdateOperation;
|
||||
import org.apollo.game.model.entity.Entity;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
import org.apollo.game.model.entity.obj.GameObject;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
@@ -31,302 +30,300 @@ import com.google.common.collect.ImmutableSet;
|
||||
*/
|
||||
public final class Region {
|
||||
|
||||
/**
|
||||
* A {@link RegionListener} for {@link UpdateOperation}s.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
private static final class UpdateRegionListener implements RegionListener {
|
||||
/**
|
||||
* A {@link RegionListener} for {@link UpdateOperation}s.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
private static final class UpdateRegionListener implements RegionListener {
|
||||
|
||||
@Override
|
||||
public void execute(Region region, Entity entity, EntityUpdateType update) {
|
||||
EntityType type = entity.getEntityType();
|
||||
if (type != EntityType.PLAYER && type != EntityType.NPC) {
|
||||
region.record(entity, update);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void execute(Region region, Entity entity, EntityUpdateType update) {
|
||||
EntityType type = entity.getEntityType();
|
||||
if (type != EntityType.PLAYER && type != EntityType.NPC) {
|
||||
region.record(entity, update);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The width and length of a Region, in tiles.
|
||||
*/
|
||||
public static final int SIZE = 8;
|
||||
/**
|
||||
* The width and length of a Region, in tiles.
|
||||
*/
|
||||
public static final int SIZE = 8;
|
||||
|
||||
static final long start = System.currentTimeMillis();
|
||||
/**
|
||||
* The default size of newly-created sets, to reduce memory usage.
|
||||
*/
|
||||
private static final int DEFAULT_SET_SIZE = 2;
|
||||
|
||||
/**
|
||||
* The default size of newly-created sets, to reduce memory usage.
|
||||
*/
|
||||
private static final int DEFAULT_SET_SIZE = 2;
|
||||
/**
|
||||
* The RegionCoordinates of this Region.
|
||||
*/
|
||||
private final RegionCoordinates coordinates;
|
||||
|
||||
/**
|
||||
* The RegionCoordinates of this Region.
|
||||
*/
|
||||
private final RegionCoordinates coordinates;
|
||||
/**
|
||||
* The Map of Positions to Entities in that Position.
|
||||
*/
|
||||
private final Map<Position, Set<Entity>> entities = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The Map of Positions to Entities in that Position.
|
||||
*/
|
||||
private final Map<Position, Set<Entity>> entities = new HashMap<>();
|
||||
/**
|
||||
* A List of RegionListeners registered to this Region.
|
||||
*/
|
||||
private final List<RegionListener> listeners = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A List of RegionListeners registered to this Region.
|
||||
*/
|
||||
private final List<RegionListener> listeners = new ArrayList<>();
|
||||
/**
|
||||
* The CollisionMatrix.
|
||||
*/
|
||||
private final CollisionMatrix[] matrices = CollisionMatrix.createMatrices(Position.HEIGHT_LEVELS, SIZE, SIZE);
|
||||
|
||||
/**
|
||||
* The CollisionMatrix.
|
||||
*/
|
||||
private final CollisionMatrix[] matrices = CollisionMatrix.createMatrices(Position.HEIGHT_LEVELS, SIZE, SIZE);
|
||||
/**
|
||||
* The Set containing RegionUpdateMessages which can be sent to add every non-Mob Entity in this Region.
|
||||
*/
|
||||
private final List<Map<Entity, RegionUpdateMessage>> snapshots = new ArrayList<>(Position.HEIGHT_LEVELS);
|
||||
|
||||
/**
|
||||
* The Set containing RegionUpdateMessages which can be sent to add every non-Mob Entity in this Region.
|
||||
*/
|
||||
private final List<Map<Entity, RegionUpdateMessage>> snapshots = new ArrayList<>(Position.HEIGHT_LEVELS);
|
||||
/**
|
||||
* The Set containing UpdateOperations.
|
||||
*/
|
||||
private final List<List<RegionUpdateMessage>> updates = new ArrayList<>(Position.HEIGHT_LEVELS);
|
||||
|
||||
/**
|
||||
* The Set containing UpdateOperations.
|
||||
*/
|
||||
private final List<List<RegionUpdateMessage>> updates = new ArrayList<>(Position.HEIGHT_LEVELS);
|
||||
/**
|
||||
* Creates a new Region.
|
||||
*
|
||||
* @param x The x coordinate of the Region.
|
||||
* @param y The y coordinate of the Region.
|
||||
*/
|
||||
public Region(int x, int y) {
|
||||
this(new RegionCoordinates(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Region.
|
||||
*
|
||||
* @param x The x coordinate of the Region.
|
||||
* @param y The y coordinate of the Region.
|
||||
*/
|
||||
public Region(int x, int y) {
|
||||
this(new RegionCoordinates(x, y));
|
||||
}
|
||||
/**
|
||||
* Creates a new Region with the specified {@link RegionCoordinates}.
|
||||
*
|
||||
* @param coordinates The coordinates.
|
||||
*/
|
||||
public Region(RegionCoordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
listeners.add(new UpdateRegionListener());
|
||||
|
||||
/**
|
||||
* Creates a new Region with the specified {@link RegionCoordinates}.
|
||||
*
|
||||
* @param coordinates The coordinates.
|
||||
*/
|
||||
public Region(RegionCoordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
listeners.add(new UpdateRegionListener());
|
||||
for (int height = 0; height < Position.HEIGHT_LEVELS; height++) {
|
||||
snapshots.add(new HashMap<>());
|
||||
updates.add(new ArrayList<>(DEFAULT_SET_SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
for (int height = 0; height < Position.HEIGHT_LEVELS; height++) {
|
||||
snapshots.add(new HashMap<>());
|
||||
updates.add(new ArrayList<>(DEFAULT_SET_SIZE));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds a {@link Entity} to the Region. Note that this does not spawn the Entity, or do any other action other than
|
||||
* register it to this Region.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @param notify A flag indicating whether the {@link RegionListener}s for this Region should be notified.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this Region.
|
||||
*/
|
||||
public void addEntity(Entity entity, boolean notify) {
|
||||
Position position = entity.getPosition();
|
||||
checkPosition(position);
|
||||
|
||||
/**
|
||||
* Adds a {@link Entity} to the Region. Note that this does not spawn the Entity, or do any other action other than
|
||||
* register it to this Region.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @param notify A flag indicating whether the {@link RegionListener}s for this Region should be notified.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this Region.
|
||||
*/
|
||||
public void addEntity(Entity entity, boolean notify) {
|
||||
Position position = entity.getPosition();
|
||||
checkPosition(position);
|
||||
Set<Entity> local = entities.computeIfAbsent(position, key -> new HashSet<>(DEFAULT_SET_SIZE));
|
||||
local.add(entity);
|
||||
|
||||
Set<Entity> local = entities.computeIfAbsent(position, key -> new HashSet<>(DEFAULT_SET_SIZE));
|
||||
local.add(entity);
|
||||
if (notify) {
|
||||
notifyListeners(entity, EntityUpdateType.ADD);
|
||||
}
|
||||
}
|
||||
|
||||
if ((System.currentTimeMillis() - start) / 1000 > 10 && (entity instanceof GameObject)) {
|
||||
System.out.println("Adding entity " + entity + " to " + entity.getPosition());
|
||||
}
|
||||
/**
|
||||
* Adds a {@link Entity} to the Region. Note that this does not spawn the Entity, or do any other action other than
|
||||
* register it to this Region.
|
||||
* <p/>
|
||||
* By default, this method notifies RegionListeners for this region of the addition.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this Region.
|
||||
*/
|
||||
public void addEntity(Entity entity) {
|
||||
addEntity(entity, true);
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
notifyListeners(entity, EntityUpdateType.ADD);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks if this Region contains the specified Entity.
|
||||
* <p/>
|
||||
* This method operates in constant time.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @return {@code true} if this Region contains the Entity, otherwise {@code false}.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds a {@link Entity} to the Region. Note that this does not spawn the Entity, or do any other action other than
|
||||
* register it to this Region.
|
||||
* <p/>
|
||||
* By default, this method notifies RegionListeners for this region of the addition.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this Region.
|
||||
*/
|
||||
public void addEntity(Entity entity) {
|
||||
addEntity(entity, true);
|
||||
}
|
||||
public boolean contains(Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
Set<Entity> local = entities.get(position);
|
||||
|
||||
/**
|
||||
* Checks if this Region contains the specified Entity.
|
||||
* <p/>
|
||||
* This method operates in constant time.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @return {@code true} if this Region contains the Entity, otherwise {@code false}.
|
||||
*/
|
||||
return local != null && local.contains(entity);
|
||||
}
|
||||
|
||||
public boolean contains(Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
Set<Entity> local = entities.get(position);
|
||||
/**
|
||||
* Gets this Region's {@link RegionCoordinates}.
|
||||
*
|
||||
* @return The Region coordinates.
|
||||
*/
|
||||
public RegionCoordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
return local != null && local.contains(entity);
|
||||
}
|
||||
/**
|
||||
* Gets a shallow copy of the {@link Set} of {@link Entity} objects at the specified {@link Position}. The returned
|
||||
* type will be immutable.
|
||||
*
|
||||
* @param position The position containing the entities.
|
||||
* @return The list.
|
||||
*/
|
||||
public Set<Entity> getEntities(Position position) {
|
||||
Set<Entity> set = entities.get(position);
|
||||
return (set == null) ? ImmutableSet.of() : ImmutableSet.copyOf(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this Region's {@link RegionCoordinates}.
|
||||
*
|
||||
* @return The Region coordinates.
|
||||
*/
|
||||
public RegionCoordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
/**
|
||||
* Gets a shallow copy of the {@link Set} of {@link Entity}s with the specified {@link EntityType}(s). The returned
|
||||
* type will be immutable. Type will be inferred from the call, so ensure that the Entity type and the reference
|
||||
* correspond, or this method will fail at runtime.
|
||||
*
|
||||
* @param position The {@link Position} containing the entities.
|
||||
* @param types The {@link EntityType}s.
|
||||
* @return The set of entities.
|
||||
*/
|
||||
public <T extends Entity> Set<T> getEntities(Position position, EntityType... types) {
|
||||
Set<Entity> local = entities.get(position);
|
||||
if (local == null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a shallow copy of the {@link Set} of {@link Entity} objects at the specified {@link Position}. The returned
|
||||
* type will be immutable.
|
||||
*
|
||||
* @param position The position containing the entities.
|
||||
* @return The list.
|
||||
*/
|
||||
public Set<Entity> getEntities(Position position) {
|
||||
Set<Entity> set = entities.get(position);
|
||||
return (set == null) ? ImmutableSet.of() : ImmutableSet.copyOf(set);
|
||||
}
|
||||
Set<EntityType> set = new HashSet<>(Arrays.asList(types));
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<T> filtered = (Set<T>) local.stream().filter(entity -> set.contains(entity.getEntityType()))
|
||||
.collect(Collectors.toSet());
|
||||
return ImmutableSet.copyOf(filtered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a shallow copy of the {@link Set} of {@link Entity}s with the specified {@link EntityType}(s). The returned
|
||||
* type will be immutable. Type will be inferred from the call, so ensure that the Entity type and the reference
|
||||
* correspond, or this method will fail at runtime.
|
||||
*
|
||||
* @param position The {@link Position} containing the entities.
|
||||
* @param types The {@link EntityType}s.
|
||||
* @return The set of entities.
|
||||
*/
|
||||
public <T extends Entity> Set<T> getEntities(Position position, EntityType... types) {
|
||||
Set<Entity> local = entities.get(position);
|
||||
if (local == null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
/**
|
||||
* Gets the {@link CollisionMatrix} at the specified height level.
|
||||
*
|
||||
* @param height The height level.
|
||||
* @return The CollisionMatrix.
|
||||
*/
|
||||
public CollisionMatrix getMatrix(int height) {
|
||||
Preconditions.checkElementIndex(height, matrices.length, "Matrix height level must be [0, " + matrices.length
|
||||
+ ").");
|
||||
return matrices[height];
|
||||
}
|
||||
|
||||
Set<EntityType> set = new HashSet<>(Arrays.asList(types));
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<T> filtered = (Set<T>) local.stream().filter(entity -> set.contains(entity.getEntityType())).collect(Collectors.toSet());
|
||||
return ImmutableSet.copyOf(filtered);
|
||||
}
|
||||
/**
|
||||
* Gets a {@link Set} containing {@link RegionUpdateMessage}s that add every {@link Entity} in this Region.
|
||||
*
|
||||
* @param height The height level to get the Set of RegionUpdateMessages for.
|
||||
* @return The Set of RegionUpdateMessages.
|
||||
*/
|
||||
public List<RegionUpdateMessage> getSnapshot(int height) {
|
||||
List<RegionUpdateMessage> copy = new ArrayList<>(snapshots.get(height).values());
|
||||
Collections.sort(copy);
|
||||
return ImmutableList.copyOf(copy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link CollisionMatrix} at the specified height level.
|
||||
*
|
||||
* @param height The height level.
|
||||
* @return The CollisionMatrix.
|
||||
*/
|
||||
public CollisionMatrix getMatrix(int height) {
|
||||
Preconditions.checkElementIndex(height, matrices.length, "Matrix height level must be [0, " + matrices.length + ").");
|
||||
return matrices[height];
|
||||
}
|
||||
/**
|
||||
* Gets the updates that have occurred in the last tick in this Region, as a {@link Set} of
|
||||
* {@link RegionUpdateMessage}s.
|
||||
*
|
||||
* @param height The height level to get the Set of RegionUpdateMessages for.
|
||||
* @return The Set of RegionUpdateMessages.
|
||||
*/
|
||||
public List<RegionUpdateMessage> getUpdates(int height) {
|
||||
List<RegionUpdateMessage> original = this.updates.get(height);
|
||||
List<RegionUpdateMessage> updates = new ArrayList<>(original);
|
||||
original.clear();
|
||||
|
||||
/**
|
||||
* Gets a {@link Set} containing {@link RegionUpdateMessage}s that add every {@link Entity} in this Region.
|
||||
*
|
||||
* @param height The height level to get the Set of RegionUpdateMessages for.
|
||||
* @return The Set of RegionUpdateMessages.
|
||||
*/
|
||||
public List<RegionUpdateMessage> getSnapshot(int height) {
|
||||
List<RegionUpdateMessage> copy = new ArrayList<>(snapshots.get(height).values());
|
||||
Collections.sort(copy);
|
||||
return ImmutableList.copyOf(copy);
|
||||
}
|
||||
Collections.sort(updates);
|
||||
return ImmutableList.copyOf(updates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the updates that have occurred in the last tick in this Region, as a {@link Set} of
|
||||
* {@link RegionUpdateMessage}s.
|
||||
*
|
||||
* @param height The height level to get the Set of RegionUpdateMessages for.
|
||||
* @return The Set of RegionUpdateMessages.
|
||||
*/
|
||||
public List<RegionUpdateMessage> getUpdates(int height) {
|
||||
List<RegionUpdateMessage> original = this.updates.get(height);
|
||||
List<RegionUpdateMessage> updates = new ArrayList<>(original);
|
||||
original.clear();
|
||||
/**
|
||||
* Notifies the {@link RegionListener}s registered to this Region that an update has occurred.
|
||||
*
|
||||
* @param entity The {@link Entity} that was updated.
|
||||
* @param type The {@link EntityUpdateType} that occurred.
|
||||
*/
|
||||
public void notifyListeners(Entity entity, EntityUpdateType type) {
|
||||
listeners.forEach(listener -> listener.execute(this, entity, type));
|
||||
}
|
||||
|
||||
Collections.sort(updates);
|
||||
return ImmutableList.copyOf(updates);
|
||||
}
|
||||
/**
|
||||
* Removes a {@link Entity} from this Region.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this Region, or if it was never added.
|
||||
*/
|
||||
public void removeEntity(Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
checkPosition(position);
|
||||
|
||||
/**
|
||||
* Notifies the {@link RegionListener}s registered to this Region that an update has occurred.
|
||||
*
|
||||
* @param entity The {@link Entity} that was updated.
|
||||
* @param type The {@link EntityUpdateType} that occurred.
|
||||
*/
|
||||
public void notifyListeners(Entity entity, EntityUpdateType type) {
|
||||
listeners.forEach(listener -> listener.execute(this, entity, type));
|
||||
}
|
||||
Set<Entity> local = entities.get(position);
|
||||
|
||||
/**
|
||||
* Removes a {@link Entity} from this Region.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this Region, or if it was never added.
|
||||
*/
|
||||
public void removeEntity(Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
checkPosition(position);
|
||||
if (local == null || !local.remove(entity)) {
|
||||
throw new IllegalArgumentException("Entity (" + entity + ") belongs in this Region (" + this
|
||||
+ ") but does not exist.");
|
||||
}
|
||||
|
||||
Set<Entity> local = entities.get(position);
|
||||
notifyListeners(entity, EntityUpdateType.REMOVE);
|
||||
}
|
||||
|
||||
if (local == null || !local.remove(entity)) {
|
||||
throw new IllegalArgumentException("Entity belongs in this Region (" + this + ") but does not exist.");
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("coordinates", coordinates).toString();
|
||||
}
|
||||
|
||||
notifyListeners(entity, EntityUpdateType.REMOVE);
|
||||
}
|
||||
/**
|
||||
* Returns whether or not an Entity of the specified {@link EntityType type} can traverse the tile at the specified
|
||||
* coordinate pair.
|
||||
*
|
||||
* @param position The {@link Position} of the tile.
|
||||
* @param entity The {@link EntityType}.
|
||||
* @param direction The {@link Direction} the Entity is approaching from.
|
||||
* @return {@code true} if the tile at the specified coordinate pair is traversable, {@code false} if not.
|
||||
*/
|
||||
public boolean traversable(Position position, EntityType entity, Direction direction) {
|
||||
CollisionMatrix matrix = matrices[position.getHeight()];
|
||||
int x = position.getX(), y = position.getY();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("coordinates", coordinates).toString();
|
||||
}
|
||||
return !matrix.untraversable(x % SIZE, y % SIZE, entity, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not an Entity of the specified {@link EntityType type} can traverse the tile at the specified
|
||||
* coordinate pair.
|
||||
*
|
||||
* @param position The {@link Position} of the tile.
|
||||
* @param entity The {@link EntityType}.
|
||||
* @param direction The {@link Direction} the Entity is approaching from.
|
||||
* @return {@code true} if the tile at the specified coordinate pair is traversable, {@code false} if not.
|
||||
*/
|
||||
public boolean traversable(Position position, EntityType entity, Direction direction) {
|
||||
CollisionMatrix matrix = matrices[position.getHeight()];
|
||||
int x = position.getX(), y = position.getY();
|
||||
/**
|
||||
* Checks that the specified {@link Position} is included in this Region.
|
||||
*
|
||||
* @param position The position.
|
||||
* @throws IllegalArgumentException If the specified position is not included in this Region.
|
||||
*/
|
||||
private void checkPosition(Position position) {
|
||||
Preconditions.checkArgument(coordinates.equals(RegionCoordinates.fromPosition(position)),
|
||||
"Position is not included in this Region.");
|
||||
}
|
||||
|
||||
return !matrix.untraversable(x % SIZE, y % SIZE, entity, direction);
|
||||
}
|
||||
/**
|
||||
* Records the specified {@link Entity} as being updated this pulse.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @param type The {@link EntityUpdateType}.
|
||||
* @throws UnsupportedOperationException If the specified Entity cannot be operated on in this manner.
|
||||
*/
|
||||
private void record(Entity entity, EntityUpdateType type) {
|
||||
RegionUpdateMessage message = entity.toUpdateOperation(this, type).toMessage();
|
||||
int height = entity.getPosition().getHeight();
|
||||
|
||||
/**
|
||||
* Checks that the specified {@link Position} is included in this Region.
|
||||
*
|
||||
* @param position The position.
|
||||
* @throws IllegalArgumentException If the specified position is not included in this Region.
|
||||
*/
|
||||
private void checkPosition(Position position) {
|
||||
Preconditions.checkArgument(coordinates.equals(RegionCoordinates.fromPosition(position)), "Position is not included in this Region.");
|
||||
}
|
||||
updates.get(height).add(message);
|
||||
snapshots.get(height).remove(entity);
|
||||
|
||||
/**
|
||||
* Records the specified {@link Entity} as being updated this pulse.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @param type The {@link EntityUpdateType}.
|
||||
* @throws UnsupportedOperationException If the specified Entity cannot be operated on in this manner.
|
||||
*/
|
||||
private void record(Entity entity, EntityUpdateType type) {
|
||||
RegionUpdateMessage message = entity.toUpdateOperation(this, type).toMessage();
|
||||
int height = entity.getPosition().getHeight();
|
||||
|
||||
updates.get(height).add(message);
|
||||
snapshots.get(height).remove(entity);
|
||||
|
||||
if ((entity.getEntityType() == EntityType.STATIC_OBJECT && type == EntityUpdateType.REMOVE) ||
|
||||
(entity.getEntityType() != EntityType.STATIC_OBJECT && type == EntityUpdateType.ADD)) {
|
||||
snapshots.get(height).put(entity, message);
|
||||
}
|
||||
}
|
||||
if ((entity.getEntityType() == EntityType.STATIC_OBJECT && type == EntityUpdateType.REMOVE)
|
||||
|| (entity.getEntityType() != EntityType.STATIC_OBJECT && type == EntityUpdateType.ADD)) {
|
||||
snapshots.get(height).put(entity, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,12 +39,14 @@ public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder<Grou
|
||||
|
||||
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));
|
||||
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");
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageEncoder<RegionUpdateMessage> encoder = (MessageEncoder<RegionUpdateMessage>) release.getMessageEncoder(update.getClass());
|
||||
MessageEncoder<RegionUpdateMessage> encoder = (MessageEncoder<RegionUpdateMessage>) release
|
||||
.getMessageEncoder(update.getClass());
|
||||
|
||||
GamePacket packet = encoder.encode(update);
|
||||
builder.put(DataType.BYTE, packet.getOpcode());
|
||||
|
||||
Reference in New Issue
Block a user