Condense some unnecessarily-long variable names

This commit is contained in:
Major
2017-05-25 02:32:20 +01:00
parent 8393dd8322
commit f4c08995b5
9 changed files with 152 additions and 137 deletions
+4 -6
View File
@@ -1,22 +1,20 @@
package org.apollo.cache; package org.apollo.cache;
import com.google.common.base.Preconditions;
import org.apollo.cache.archive.Archive;
import java.io.Closeable; import java.io.Closeable;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import com.google.common.base.Preconditions;
import org.apollo.cache.archive.Archive;
/** /**
* A file system based on top of the operating system's file system. It consists of a data file and index files. Index * A file system based on top of the operating system's file system. It consists of a data file and index files. Index
* files point to blocks in the data file, which contains the actual data. * files point to blocks in the data file, which contains the actual data.
@@ -274,7 +272,7 @@ public final class IndexedFileSystem implements Closeable {
} }
} }
if (indexCount <= 0) { if (indexCount <= 0) {
throw new FileNotFoundException("No index file(s) present."); throw new FileNotFoundException("No index file(s) present in " + base + ".");
} }
Path resources = base.resolve("main_file_cache.dat"); Path resources = base.resolve("main_file_cache.dat");
@@ -89,7 +89,7 @@ public final class WorldMapDecoder implements Runnable {
Position position = new Position(mapX + x, mapY + y, plane.getLevel()); Position position = new Position(mapX + x, mapY + y, plane.getLevel());
if ((tile.getAttributes() & BLOCKED_TILE) == BLOCKED_TILE) { if ((tile.getAttributes() & BLOCKED_TILE) == BLOCKED_TILE) {
collisionManager.markBlocked(position); collisionManager.block(position);
} }
if ((tile.getAttributes() & BRIDGE_TILE) == BRIDGE_TILE) { if ((tile.getAttributes() & BRIDGE_TILE) == BRIDGE_TILE) {
@@ -18,7 +18,7 @@ import org.apollo.game.io.EquipmentDefinitionParser;
import org.apollo.game.model.area.Region; import org.apollo.game.model.area.Region;
import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.RegionRepository;
import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.game.model.area.collision.CollisionManager;
import org.apollo.game.model.area.collision.GameObjectCollisionUpdateListener; import org.apollo.game.model.area.collision.CollisionUpdateListener;
import org.apollo.game.model.entity.Entity; import org.apollo.game.model.entity.Entity;
import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.EntityType;
import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.MobRepository;
@@ -239,7 +239,7 @@ public final class World {
// Build collision matrices for the first time // Build collision matrices for the first time
collisionManager.build(false); collisionManager.build(false);
regions.addRegionListener(new GameObjectCollisionUpdateListener(collisionManager)); regions.addRegionListener(new CollisionUpdateListener(collisionManager));
npcMovement = new NpcMovementTask(collisionManager); // Must be exactly here because of ordering issues. npcMovement = new NpcMovementTask(collisionManager); // Must be exactly here because of ordering issues.
scheduler.schedule(npcMovement); scheduler.schedule(npcMovement);
@@ -1,5 +1,18 @@
package org.apollo.game.model.area; package org.apollo.game.model.area;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import org.apollo.game.message.impl.RegionUpdateMessage;
import org.apollo.game.model.Direction;
import org.apollo.game.model.Position;
import org.apollo.game.model.area.collision.CollisionMatrix;
import org.apollo.game.model.area.update.GroupableEntity;
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.DynamicGameObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
@@ -10,21 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apollo.game.message.impl.RegionUpdateMessage;
import org.apollo.game.model.Direction;
import org.apollo.game.model.Position;
import org.apollo.game.model.area.collision.CollisionMatrix;
import org.apollo.game.model.area.update.GroupableEntity;
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.Mob;
import org.apollo.game.model.entity.obj.DynamicGameObject;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
/** /**
* An 8x8 area of the map. * An 8x8 area of the map.
* *
@@ -34,8 +32,6 @@ public final class Region {
/** /**
* A {@link RegionListener} for {@link UpdateOperation}s. * A {@link RegionListener} for {@link UpdateOperation}s.
*
* @author Major
*/ */
private static final class UpdateRegionListener implements RegionListener { private static final class UpdateRegionListener implements RegionListener {
@@ -49,6 +45,11 @@ public final class Region {
} }
/**
* The message of the exception thrown when a CollisionMatrix with an illegal height is requested.
*/
private static final String ILLEGAL_MATRIX_HEIGHT = "Matrix height level must be [0, %d), received %d.";
/** /**
* The width and length of a Region, in tiles. * The width and length of a Region, in tiles.
*/ */
@@ -269,8 +270,8 @@ public final class Region {
} }
/** /**
* Gets the {@link Set} of {@link RegionCoordinates} of Regions that are * Gets the {@link Set} of {@link RegionCoordinates} of Regions that are viewable from the specified
* viewable from the specified {@link Position}. * {@link Position}.
* *
* @return The Set of RegionCoordinates. * @return The Set of RegionCoordinates.
*/ */
@@ -295,13 +296,12 @@ public final class Region {
* @return The CollisionMatrix. * @return The CollisionMatrix.
*/ */
public CollisionMatrix getMatrix(int height) { public CollisionMatrix getMatrix(int height) {
Preconditions.checkElementIndex(height, matrices.length, "Matrix height level must be [0, " + matrices.length Preconditions.checkElementIndex(height, matrices.length, String.format(ILLEGAL_MATRIX_HEIGHT, matrices.length, height));
+ "), received " + height + ".");
return matrices[height]; return matrices[height];
} }
/** /**
* Gets all {@link CollisionMatrix}'s in this {@code Region}. * Gets all of the {@link CollisionMatrix} objects in this {@code Region}.
* *
* @return The collision matrices of this region. * @return The collision matrices of this region.
*/ */
@@ -411,10 +411,10 @@ public final class Region {
if (update == EntityUpdateType.REMOVE) { if (update == EntityUpdateType.REMOVE) {
removedObjects.get(height).add(message); removedObjects.get(height).add(message);
} else { // TODO should this really be possible? } else { // TODO should this really be possible?
removedObjects.get(height).remove(operation.inverse()); removedObjects.get(height).remove(inverse);
} }
} else if (update == EntityUpdateType.REMOVE && !type.isTransient()) { } else if (update == EntityUpdateType.REMOVE && !type.isTransient()) {
updates.remove(operation.inverse()); updates.remove(inverse);
} }
updates.add(message); updates.add(message);
@@ -9,15 +9,23 @@ import org.apollo.game.model.area.collision.CollisionUpdate.DirectionFlag;
import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.EntityType;
import org.apollo.game.model.entity.obj.GameObject; import org.apollo.game.model.entity.obj.GameObject;
import java.util.*; import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import static org.apollo.game.model.entity.EntityType.DYNAMIC_OBJECT;
import static org.apollo.game.model.entity.EntityType.STATIC_OBJECT;
/** /**
* Manages applying {@link CollisionUpdate}s to the respective {@link CollisionMatrix} instances, and keeping * Manages applying {@link CollisionUpdate}s to the appropriate {@link CollisionMatrix}, and keeping
* a record of collision state (i.e., which tiles are bridged). * a record of collision state (i.e., which tiles are bridged).
*/ */
public final class CollisionManager { public final class CollisionManager {
/** /**
* A comparator which sorts {@link Position}s by their X coordinate, then Y, then height. * A comparator that sorts {@link Position}s by their X coordinate, then Y, then height.
*/ */
private static final Comparator<Position> POSITION_COMPARATOR = private static final Comparator<Position> POSITION_COMPARATOR =
Comparator.comparingInt(Position::getX).thenComparingInt(Position::getY).thenComparingInt(Position::getHeight); Comparator.comparingInt(Position::getX).thenComparingInt(Position::getY).thenComparingInt(Position::getHeight);
@@ -25,71 +33,66 @@ public final class CollisionManager {
/** /**
* A {@code SortedSet} of positions where the tile is part of a bridged structure. * A {@code SortedSet} of positions where the tile is part of a bridged structure.
*/ */
private final SortedSet<Position> bridgeTiles = new TreeSet<>(POSITION_COMPARATOR); private final SortedSet<Position> bridges = new TreeSet<>(POSITION_COMPARATOR);
/** /**
* A {@code SortedSet} of positions where the tile is completely blocked. * A {@code SortedSet} of positions where the tile is completely blocked.
*/ */
private final SortedSet<Position> blockedTiles = new TreeSet<>(POSITION_COMPARATOR); private final SortedSet<Position> blocked = new TreeSet<>(POSITION_COMPARATOR);
/** /**
* The {@link RegionRepository} containing {@link Region}s, used to lookup {@link CollisionMatrix}'s. * The {@link RegionRepository} used to lookup {@link CollisionMatrix} objects.
*/ */
private final RegionRepository regionRepository; private final RegionRepository regions;
/** /**
* Creates a new {@code CollisionManager}. * Creates the {@code CollisionManager}.
* *
* @param regionRepository The {@link RegionRepository} to lookup {@link Region} and {@link CollisionMatrix} instances * @param regions The {@link RegionRepository} to retrieve {@link CollisionMatrix} objects from.
* from.
*/ */
public CollisionManager(RegionRepository regionRepository) { public CollisionManager(RegionRepository regions) {
this.regionRepository = regionRepository; this.regions = regions;
} }
/** /**
* Apples the first initial {@link CollisionUpdate} to the {@link CollisionMatrix}es for all objects and tiles loaded from * Applies the initial {@link CollisionUpdate} to the {@link CollisionMatrix}es for all objects and tiles loaded
* the cache. * from the cache.
* *
* @param rebuilding A flag indicating whether {@link CollisionMatrix}es are being rebuilt, or built for the first time. * @param rebuilding A flag indicating whether or not {@link CollisionMatrix}es are being rebuilt.
*/ */
public void build(boolean rebuilding) { public void build(boolean rebuilding) {
if (rebuilding) { if (rebuilding) {
for (Region region : regionRepository.getRegions()) { for (Region region : regions.getRegions()) {
for (CollisionMatrix matrix : region.getMatrices()) { for (CollisionMatrix matrix : region.getMatrices()) {
matrix.reset(); matrix.reset();
} }
} }
} }
CollisionUpdate.Builder tileUpdateBuilder = new CollisionUpdate.Builder(); CollisionUpdate.Builder builder = new CollisionUpdate.Builder();
tileUpdateBuilder.type(CollisionUpdateType.ADDING); builder.type(CollisionUpdateType.ADDING);
for (Position tile : blockedTiles) { for (Position tile : blocked) {
int x = tile.getX(), y = tile.getY(); int x = tile.getX(), y = tile.getY();
int height = tile.getHeight(); int height = tile.getHeight();
if (bridgeTiles.contains(new Position(x, y, 1))) { if (bridges.contains(new Position(x, y, 1))) {
height--; height--;
} }
if (height >= 0) { if (height >= 0) {
tileUpdateBuilder.tile(new Position(x, y, height), false, Direction.NESW); builder.tile(new Position(x, y, height), false, Direction.NESW);
} }
} }
CollisionUpdate tileUpdate = tileUpdateBuilder.build(); apply(builder.build());
apply(tileUpdate);
for (Region region : regionRepository.getRegions()) { for (Region region : regions.getRegions()) {
CollisionUpdate.Builder regionObjectsUpdateBuilder = new CollisionUpdate.Builder(); CollisionUpdate.Builder objects = new CollisionUpdate.Builder();
regionObjectsUpdateBuilder.type(CollisionUpdateType.ADDING); objects.type(CollisionUpdateType.ADDING);
region.getEntities(EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT) region.getEntities(STATIC_OBJECT, DYNAMIC_OBJECT).forEach(entity -> objects.object((GameObject) entity));
.forEach(entity -> regionObjectsUpdateBuilder.object((GameObject) entity)); apply(objects.build());
CollisionUpdate regionObjectsUpdate = regionObjectsUpdateBuilder.build();
apply(regionObjectsUpdate);
} }
} }
@@ -102,37 +105,37 @@ public final class CollisionManager {
Region prev = null; Region prev = null;
CollisionUpdateType type = update.getType(); CollisionUpdateType type = update.getType();
Map<Position, Collection<DirectionFlag>> flags = update.getFlags().asMap(); Map<Position, Collection<DirectionFlag>> map = update.getFlags().asMap();
for (Map.Entry<Position, Collection<DirectionFlag>> flag : flags.entrySet()) { for (Map.Entry<Position, Collection<DirectionFlag>> entry : map.entrySet()) {
Position position = flag.getKey(); Position position = entry.getKey();
Collection<DirectionFlag> directionFlags = flag.getValue();
int height = position.getHeight(); int height = position.getHeight();
if (bridgeTiles.contains(new Position(position.getX(), position.getY(), 1))) { if (bridges.contains(new Position(position.getX(), position.getY(), 1))) {
if (--height < 0) { if (--height < 0) {
continue; continue;
} }
} }
if (prev == null || !prev.contains(position)) { if (prev == null || !prev.contains(position)) {
prev = regionRepository.fromPosition(position); prev = regions.fromPosition(position);
} }
int localX = position.getX() % Region.SIZE, localY = position.getY() % Region.SIZE; int localX = position.getX() % Region.SIZE;
int localY = position.getY() % Region.SIZE;
CollisionMatrix matrix = prev.getMatrix(height); CollisionMatrix matrix = prev.getMatrix(height);
CollisionFlag[] mobs = CollisionFlag.mobs(); CollisionFlag[] mobs = CollisionFlag.mobs();
CollisionFlag[] projectiles = CollisionFlag.projectiles(); CollisionFlag[] projectiles = CollisionFlag.projectiles();
for (DirectionFlag directionFlag : directionFlags) { for (DirectionFlag flag : entry.getValue()) {
Direction direction = directionFlag.getDirection(); Direction direction = flag.getDirection();
if (direction == Direction.NONE) { if (direction == Direction.NONE) {
continue; continue;
} }
int orientation = direction.toInteger(); int orientation = direction.toInteger();
if (directionFlag.isImpenetrable()) { if (flag.isImpenetrable()) {
flag(type, matrix, localX, localY, projectiles[orientation]); flag(type, matrix, localX, localY, projectiles[orientation]);
} }
@@ -189,7 +192,10 @@ public final class CollisionManager {
float derror = Math.abs(dy / (float) dx); float derror = Math.abs(dy / (float) dx);
float error = 0; float error = 0;
int y = y0, currX, currY, lastX = 0, lastY = 0; int y = y0;
int currX, currY;
int lastX = 0, lastY = 0;
boolean first = true; boolean first = true;
for (int x = x0; x <= x1; x++) { for (int x = x0; x <= x1; x++) {
@@ -213,9 +219,9 @@ public final class CollisionManager {
} }
Direction direction = Direction.fromDeltas(currX - lastX, currY - lastY); Direction direction = Direction.fromDeltas(currX - lastX, currY - lastY);
Position lastPosition = new Position(lastX, lastY, start.getHeight()); Position last = new Position(lastX, lastY, start.getHeight());
if (!traversable(lastPosition, EntityType.PROJECTILE, direction)) { if (!traversable(last, EntityType.PROJECTILE, direction)) {
return false; return false;
} }
@@ -233,7 +239,7 @@ public final class CollisionManager {
* @param matrix The matrix the update is being applied to. * @param matrix The matrix the update is being applied to.
* @param localX The local X position of the tile the flag represents. * @param localX The local X position of the tile the flag represents.
* @param localY The local Y position of the tile the flag represents. * @param localY The local Y position of the tile the flag represents.
* @param flag The flag to update. * @param flag The {@link CollisionFlag} to update.
*/ */
private void flag(CollisionUpdateType type, CollisionMatrix matrix, int localX, int localY, CollisionFlag flag) { private void flag(CollisionUpdateType type, CollisionMatrix matrix, int localX, int localY, CollisionFlag flag) {
if (type == CollisionUpdateType.ADDING) { if (type == CollisionUpdateType.ADDING) {
@@ -248,8 +254,8 @@ public final class CollisionManager {
* *
* @param position The {@link Position} of the tile. * @param position The {@link Position} of the tile.
*/ */
public void markBlocked(Position position) { public void block(Position position) {
blockedTiles.add(position); blocked.add(position);
} }
/** /**
@@ -258,7 +264,7 @@ public final class CollisionManager {
* @param position The {@link Position} of the tile. * @param position The {@link Position} of the tile.
*/ */
public void markBridged(Position position) { public void markBridged(Position position) {
bridgeTiles.add(position); bridges.add(position);
} }
/** /**
@@ -272,7 +278,7 @@ public final class CollisionManager {
*/ */
public boolean traversable(Position position, EntityType type, Direction direction) { public boolean traversable(Position position, EntityType type, Direction direction) {
Position next = position.step(1, direction); Position next = position.step(1, direction);
Region region = regionRepository.fromPosition(next); Region region = regions.fromPosition(next);
if (!region.traversable(next, type, direction)) { if (!region.traversable(next, type, direction)) {
return false; return false;
@@ -283,7 +289,7 @@ public final class CollisionManager {
next = position.step(1, component); next = position.step(1, component);
if (!region.contains(next)) { if (!region.contains(next)) {
region = regionRepository.fromPosition(next); region = regions.fromPosition(next);
} }
if (!region.traversable(next, type, component)) { if (!region.traversable(next, type, component)) {
@@ -1,29 +1,40 @@
package org.apollo.game.model.area.collision; package org.apollo.game.model.area.collision;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.*; import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.Multimaps;
import org.apollo.cache.def.ObjectDefinition; import org.apollo.cache.def.ObjectDefinition;
import org.apollo.game.model.Direction; import org.apollo.game.model.Direction;
import org.apollo.game.model.Position; import org.apollo.game.model.Position;
import org.apollo.game.model.entity.obj.GameObject; import org.apollo.game.model.entity.obj.GameObject;
import org.apollo.game.model.entity.obj.ObjectType;
import java.util.Objects;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.apollo.game.model.entity.obj.ObjectType.*;
/** /**
* A global update to the collision matrices. * A global update to the collision matrices.
*/ */
public final class CollisionUpdate { public final class CollisionUpdate {
/** /**
* The type of this update. * The type of this update.
*/ */
private final CollisionUpdateType type; private final CollisionUpdateType type;
/** /**
* A mapping of {@link Position}s to a set of their {@link DirectionFlag}s. * A mapping of {@link Position}s to their {@link DirectionFlag}s.
*/ */
private final Multimap<Position, DirectionFlag> flags; private final Multimap<Position, DirectionFlag> flags;
/**
* Creates the CollisionUpdate.
*
* @param type The {@link CollisionUpdateType} of this update.
* @param flags A {@link Multimap} of {@link Position}s to their {@link DirectionFlag}s.
*/
public CollisionUpdate(CollisionUpdateType type, Multimap<Position, DirectionFlag> flags) { public CollisionUpdate(CollisionUpdateType type, Multimap<Position, DirectionFlag> flags) {
this.type = type; this.type = type;
this.flags = flags; this.flags = flags;
@@ -52,6 +63,7 @@ public final class CollisionUpdate {
* that tile is impenetrable as well as untraversable. * that tile is impenetrable as well as untraversable.
*/ */
public static final class DirectionFlag { public static final class DirectionFlag {
private final boolean impenetrable; private final boolean impenetrable;
private final Direction direction; private final Direction direction;
@@ -61,22 +73,19 @@ public final class CollisionUpdate {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object obj) {
if (this == o) return true; if (obj instanceof DirectionFlag) {
if (o == null || getClass() != o.getClass()) return false; DirectionFlag other = (DirectionFlag) obj;
return impenetrable == other.impenetrable && direction == other.direction;
}
DirectionFlag that = (DirectionFlag) o; return false;
if (impenetrable != that.impenetrable) return false;
return direction == that.direction;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = (impenetrable ? 1 : 0); return Objects.hash(impenetrable, direction);
result = 31 * result + direction.hashCode();
return result;
} }
/** /**
@@ -96,9 +105,14 @@ public final class CollisionUpdate {
public Direction getDirection() { public Direction getDirection() {
return direction; return direction;
} }
} }
public static class Builder { /**
* A builder for CollisionUpdates.
*/
public static final class Builder {
private final Multimap<Position, DirectionFlag> flags; private final Multimap<Position, DirectionFlag> flags;
private CollisionUpdateType type; private CollisionUpdateType type;
@@ -159,7 +173,6 @@ public final class CollisionUpdate {
*/ */
public void largeCornerWall(Position position, boolean impenetrable, Direction orientation) { public void largeCornerWall(Position position, boolean impenetrable, Direction orientation) {
Direction[] directions = Direction.diagonalComponents(orientation); Direction[] directions = Direction.diagonalComponents(orientation);
tile(position, impenetrable, directions); tile(position, impenetrable, directions);
for (Direction direction : directions) { for (Direction direction : directions) {
@@ -192,22 +205,21 @@ public final class CollisionUpdate {
length = definition.getWidth(); length = definition.getWidth();
} }
if (type == ObjectType.FLOOR_DECORATION.getValue()) { if (type == FLOOR_DECORATION.getValue()) {
if (definition.isInteractive() && definition.isSolid()) { if (definition.isInteractive() && definition.isSolid()) {
tile(new Position(x, y, height), impenetrable, Direction.NESW); tile(new Position(x, y, height), impenetrable, Direction.NESW);
} }
} else if (type >= ObjectType.DIAGONAL_WALL.getValue() && type < ObjectType.FLOOR_DECORATION.getValue()) { } else if (type >= DIAGONAL_WALL.getValue() && type < FLOOR_DECORATION.getValue()) {
for (int dx = 0; dx < width; dx++) { for (int dx = 0; dx < width; dx++) {
for (int dy = 0; dy < length; dy++) { for (int dy = 0; dy < length; dy++) {
tile(new Position(x + dx, y + dy, height), impenetrable, Direction.NESW); tile(new Position(x + dx, y + dy, height), impenetrable, Direction.NESW);
} }
} }
} else if (type == ObjectType.LENGTHWISE_WALL.getValue()) { } else if (type == LENGTHWISE_WALL.getValue()) {
wall(position, impenetrable, Direction.WNES[orientation]); wall(position, impenetrable, Direction.WNES[orientation]);
} else if (type == ObjectType.TRIANGULAR_CORNER.getValue() } else if (type == TRIANGULAR_CORNER.getValue() || type == RECTANGULAR_CORNER.getValue()) {
|| type == ObjectType.RECTANGULAR_CORNER.getValue()) {
wall(position, impenetrable, Direction.WNES_DIAGONAL[orientation]); wall(position, impenetrable, Direction.WNES_DIAGONAL[orientation]);
} else if (type == ObjectType.WALL_CORNER.getValue()) { } else if (type == WALL_CORNER.getValue()) {
largeCornerWall(position, impenetrable, Direction.WNES_DIAGONAL[orientation]); largeCornerWall(position, impenetrable, Direction.WNES_DIAGONAL[orientation]);
} }
} }
@@ -221,6 +233,7 @@ public final class CollisionUpdate {
Preconditions.checkNotNull(type, "update type must not be null"); Preconditions.checkNotNull(type, "update type must not be null");
return new CollisionUpdate(type, Multimaps.unmodifiableMultimap(flags)); return new CollisionUpdate(type, Multimaps.unmodifiableMultimap(flags));
} }
} }
/** /**
@@ -232,17 +245,16 @@ public final class CollisionUpdate {
* @return {@code true} iff the tile(s) the object is on should be blocked. * @return {@code true} iff the tile(s) the object is on should be blocked.
*/ */
private static boolean unwalkable(ObjectDefinition definition, int type) { private static boolean unwalkable(ObjectDefinition definition, int type) {
boolean isSolidFloorDecoration = type == ObjectType.FLOOR_DECORATION.getValue() && definition.isInteractive(); boolean isSolidFloorDecoration = type == FLOOR_DECORATION.getValue() && definition.isInteractive();
boolean isRoof = type > DIAGONAL_INTERACTABLE.getValue() && type < FLOOR_DECORATION.getValue();
boolean isWall = type >= ObjectType.LENGTHWISE_WALL.getValue() boolean isWall = type >= LENGTHWISE_WALL.getValue() && type <= RECTANGULAR_CORNER.getValue() ||
&& type <= ObjectType.RECTANGULAR_CORNER.getValue() || type == ObjectType.DIAGONAL_WALL.getValue(); type == DIAGONAL_WALL.getValue();
boolean isRoof = type > ObjectType.DIAGONAL_INTERACTABLE.getValue() boolean isSolidInteractable = (type == DIAGONAL_INTERACTABLE.getValue() ||
&& type < ObjectType.FLOOR_DECORATION.getValue(); type == INTERACTABLE.getValue()) && definition.isSolid();
boolean isSolidInteractable = (type == ObjectType.DIAGONAL_INTERACTABLE.getValue()
|| type == ObjectType.INTERACTABLE.getValue()) && definition.isSolid();
return isWall || isRoof || isSolidInteractable || isSolidFloorDecoration; return isWall || isRoof || isSolidInteractable || isSolidFloorDecoration;
} }
} }
@@ -8,21 +8,21 @@ import org.apollo.game.model.entity.EntityType;
import org.apollo.game.model.entity.obj.GameObject; import org.apollo.game.model.entity.obj.GameObject;
/** /**
* A {@link RegionListener} which listens on object addition / removal events and applies * A {@link RegionListener} that listens to object addition/removals and applies the respective {@link CollisionUpdate}.
* the respective {@link CollisionUpdate}.
*/ */
public final class GameObjectCollisionUpdateListener implements RegionListener { public final class CollisionUpdateListener implements RegionListener {
/** /**
* The {@link CollisionManager} to apply updates to. * The {@link CollisionManager} to apply updates to.
*/ */
private CollisionManager collisionManager; private CollisionManager collisionManager;
/** /**
* Create a new {@link GameObjectCollisionUpdateListener}. * Create a new {@link CollisionUpdateListener}.
* *
* @param collisionManager The {@link CollisionManager} that collision updates will be applied to. * @param collisionManager The {@link CollisionManager} that collision updates will be applied to.
*/ */
public GameObjectCollisionUpdateListener(CollisionManager collisionManager) { public CollisionUpdateListener(CollisionManager collisionManager) {
this.collisionManager = collisionManager; this.collisionManager = collisionManager;
} }
@@ -34,16 +34,14 @@ public final class GameObjectCollisionUpdateListener implements RegionListener {
return; return;
} }
CollisionUpdate.Builder objectUpdateBuilder = new CollisionUpdate.Builder(); CollisionUpdate.Builder builder = new CollisionUpdate.Builder();
if (type == EntityUpdateType.ADD) { if (type == EntityUpdateType.ADD) {
objectUpdateBuilder.type(CollisionUpdateType.ADDING); builder.type(CollisionUpdateType.ADDING);
} else { } else {
objectUpdateBuilder.type(CollisionUpdateType.REMOVING); builder.type(CollisionUpdateType.REMOVING);
} }
objectUpdateBuilder.object((GameObject) entity); builder.object((GameObject) entity);
collisionManager.apply(builder.build());
CollisionUpdate objectUpdate = objectUpdateBuilder.build();
collisionManager.apply(objectUpdate);
} }
} }
@@ -4,6 +4,7 @@ package org.apollo.game.model.area.collision;
* An enum which represents the type of a {@link CollisionUpdate}. * An enum which represents the type of a {@link CollisionUpdate}.
*/ */
public enum CollisionUpdateType { public enum CollisionUpdateType {
/** /**
* Indicates that a {@link CollisionUpdate} will be adding new flags to collision matrices. * Indicates that a {@link CollisionUpdate} will be adding new flags to collision matrices.
*/ */
@@ -13,4 +14,5 @@ public enum CollisionUpdateType {
* Indicates that a {@link CollisionUpdate} will be clearing existing flags from collision matrices. * Indicates that a {@link CollisionUpdate} will be clearing existing flags from collision matrices.
*/ */
REMOVING REMOVING
} }
@@ -47,8 +47,7 @@ public enum EntityType {
} }
/** /**
* Returns whether or not this EntityType should be short-lived (i.e. not added to its {@link Region}s * Returns whether or not this EntityType should be short-lived (i.e. not added to its regions local objects).
* local objects).
* *
* @return {@code true} if this EntityType is short-lived. * @return {@code true} if this EntityType is short-lived.
*/ */