mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Merge pull request #323 from Major-/sfix-literacy
Condense some unnecessarily-long variable names
This commit is contained in:
+5
-7
@@ -1,22 +1,20 @@
|
||||
package org.apollo.cache;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apollo.cache.archive.Archive;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
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
|
||||
* files point to blocks in the data file, which contains the actual data.
|
||||
@@ -95,7 +93,7 @@ public final class IndexedFileSystem implements Closeable {
|
||||
public Archive getArchive(int type, int file) throws IOException {
|
||||
FileDescriptor descriptor = new FileDescriptor(type, file);
|
||||
Archive cached = cache.get(descriptor);
|
||||
|
||||
|
||||
if (cached == null) {
|
||||
cached = Archive.decode(getFile(descriptor));
|
||||
|
||||
@@ -274,7 +272,7 @@ public final class IndexedFileSystem implements Closeable {
|
||||
}
|
||||
}
|
||||
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");
|
||||
|
||||
@@ -89,7 +89,7 @@ public final class WorldMapDecoder implements Runnable {
|
||||
Position position = new Position(mapX + x, mapY + y, plane.getLevel());
|
||||
|
||||
if ((tile.getAttributes() & BLOCKED_TILE) == BLOCKED_TILE) {
|
||||
collisionManager.markBlocked(position);
|
||||
collisionManager.block(position);
|
||||
}
|
||||
|
||||
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.RegionRepository;
|
||||
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.EntityType;
|
||||
import org.apollo.game.model.entity.MobRepository;
|
||||
@@ -239,7 +239,7 @@ public final class World {
|
||||
|
||||
// Build collision matrices for the first time
|
||||
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.
|
||||
scheduler.schedule(npcMovement);
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
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.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -10,21 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
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.
|
||||
*
|
||||
@@ -34,8 +32,6 @@ public final class Region {
|
||||
|
||||
/**
|
||||
* A {@link RegionListener} for {@link UpdateOperation}s.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@@ -199,10 +200,10 @@ public final class Region {
|
||||
*/
|
||||
public Set<RegionUpdateMessage> encode(int height) {
|
||||
Set<RegionUpdateMessage> additions = entities.values().stream()
|
||||
.flatMap(Set::stream) // TODO fix this to work for ground items + projectiles
|
||||
.filter(entity -> entity instanceof DynamicGameObject && entity.getPosition().getHeight() == height)
|
||||
.map(entity -> ((GroupableEntity) entity).toUpdateOperation(this, EntityUpdateType.ADD).toMessage())
|
||||
.collect(Collectors.toSet());
|
||||
.flatMap(Set::stream) // TODO fix this to work for ground items + projectiles
|
||||
.filter(entity -> entity instanceof DynamicGameObject && entity.getPosition().getHeight() == height)
|
||||
.map(entity -> ((GroupableEntity) entity).toUpdateOperation(this, EntityUpdateType.ADD).toMessage())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
ImmutableSet.Builder<RegionUpdateMessage> builder = ImmutableSet.builder();
|
||||
builder.addAll(additions).addAll(updates.get(height)).addAll(removedObjects.get(height));
|
||||
@@ -231,7 +232,7 @@ public final class Region {
|
||||
public <T extends Entity> Stream<T> getEntities(EntityType... types) {
|
||||
Set<EntityType> set = ImmutableSet.copyOf(types);
|
||||
return (Stream<T>) entities.values().stream().flatMap(Collection::stream)
|
||||
.filter(entity -> set.contains(entity.getEntityType()));
|
||||
.filter(entity -> set.contains(entity.getEntityType()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,13 +265,13 @@ public final class Region {
|
||||
Set<EntityType> set = ImmutableSet.copyOf(types);
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<T> filtered = (Set<T>) local.stream().filter(entity -> set.contains(entity.getEntityType()))
|
||||
.collect(Collectors.toSet());
|
||||
.collect(Collectors.toSet());
|
||||
return ImmutableSet.copyOf(filtered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Set} of {@link RegionCoordinates} of Regions that are
|
||||
* viewable from the specified {@link Position}.
|
||||
* Gets the {@link Set} of {@link RegionCoordinates} of Regions that are viewable from the specified
|
||||
* {@link Position}.
|
||||
*
|
||||
* @return The Set of RegionCoordinates.
|
||||
*/
|
||||
@@ -295,13 +296,12 @@ public final class Region {
|
||||
* @return The CollisionMatrix.
|
||||
*/
|
||||
public CollisionMatrix getMatrix(int height) {
|
||||
Preconditions.checkElementIndex(height, matrices.length, "Matrix height level must be [0, " + matrices.length
|
||||
+ "), received " + height + ".");
|
||||
Preconditions.checkElementIndex(height, matrices.length, String.format(ILLEGAL_MATRIX_HEIGHT, matrices.length, 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.
|
||||
*/
|
||||
@@ -388,7 +388,7 @@ public final class Region {
|
||||
*/
|
||||
private void checkPosition(Position position) {
|
||||
Preconditions.checkArgument(coordinates.equals(RegionCoordinates.fromPosition(position)),
|
||||
"Position is not included in this Region.");
|
||||
"Position is not included in this Region.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,10 +411,10 @@ public final class Region {
|
||||
if (update == EntityUpdateType.REMOVE) {
|
||||
removedObjects.get(height).add(message);
|
||||
} 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()) {
|
||||
updates.remove(operation.inverse());
|
||||
updates.remove(inverse);
|
||||
}
|
||||
|
||||
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.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).
|
||||
*/
|
||||
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 =
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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
|
||||
* from.
|
||||
* @param regions The {@link RegionRepository} to retrieve {@link CollisionMatrix} objects from.
|
||||
*/
|
||||
public CollisionManager(RegionRepository regionRepository) {
|
||||
this.regionRepository = regionRepository;
|
||||
public CollisionManager(RegionRepository regions) {
|
||||
this.regions = regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apples the first initial {@link CollisionUpdate} to the {@link CollisionMatrix}es for all objects and tiles loaded from
|
||||
* the cache.
|
||||
* Applies the initial {@link CollisionUpdate} to the {@link CollisionMatrix}es for all objects and tiles loaded
|
||||
* 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) {
|
||||
if (rebuilding) {
|
||||
for (Region region : regionRepository.getRegions()) {
|
||||
for (Region region : regions.getRegions()) {
|
||||
for (CollisionMatrix matrix : region.getMatrices()) {
|
||||
matrix.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CollisionUpdate.Builder tileUpdateBuilder = new CollisionUpdate.Builder();
|
||||
tileUpdateBuilder.type(CollisionUpdateType.ADDING);
|
||||
CollisionUpdate.Builder builder = new CollisionUpdate.Builder();
|
||||
builder.type(CollisionUpdateType.ADDING);
|
||||
|
||||
for (Position tile : blockedTiles) {
|
||||
for (Position tile : blocked) {
|
||||
int x = tile.getX(), y = tile.getY();
|
||||
int height = tile.getHeight();
|
||||
|
||||
if (bridgeTiles.contains(new Position(x, y, 1))) {
|
||||
if (bridges.contains(new Position(x, y, 1))) {
|
||||
height--;
|
||||
}
|
||||
|
||||
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(tileUpdate);
|
||||
apply(builder.build());
|
||||
|
||||
for (Region region : regionRepository.getRegions()) {
|
||||
CollisionUpdate.Builder regionObjectsUpdateBuilder = new CollisionUpdate.Builder();
|
||||
regionObjectsUpdateBuilder.type(CollisionUpdateType.ADDING);
|
||||
for (Region region : regions.getRegions()) {
|
||||
CollisionUpdate.Builder objects = new CollisionUpdate.Builder();
|
||||
objects.type(CollisionUpdateType.ADDING);
|
||||
|
||||
region.getEntities(EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)
|
||||
.forEach(entity -> regionObjectsUpdateBuilder.object((GameObject) entity));
|
||||
|
||||
CollisionUpdate regionObjectsUpdate = regionObjectsUpdateBuilder.build();
|
||||
apply(regionObjectsUpdate);
|
||||
region.getEntities(STATIC_OBJECT, DYNAMIC_OBJECT).forEach(entity -> objects.object((GameObject) entity));
|
||||
apply(objects.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,37 +105,37 @@ public final class CollisionManager {
|
||||
Region prev = null;
|
||||
|
||||
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()) {
|
||||
Position position = flag.getKey();
|
||||
Collection<DirectionFlag> directionFlags = flag.getValue();
|
||||
for (Map.Entry<Position, Collection<DirectionFlag>> entry : map.entrySet()) {
|
||||
Position position = entry.getKey();
|
||||
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
CollisionFlag[] mobs = CollisionFlag.mobs();
|
||||
CollisionFlag[] projectiles = CollisionFlag.projectiles();
|
||||
|
||||
for (DirectionFlag directionFlag : directionFlags) {
|
||||
Direction direction = directionFlag.getDirection();
|
||||
for (DirectionFlag flag : entry.getValue()) {
|
||||
Direction direction = flag.getDirection();
|
||||
if (direction == Direction.NONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int orientation = direction.toInteger();
|
||||
if (directionFlag.isImpenetrable()) {
|
||||
if (flag.isImpenetrable()) {
|
||||
flag(type, matrix, localX, localY, projectiles[orientation]);
|
||||
}
|
||||
|
||||
@@ -189,7 +192,10 @@ public final class CollisionManager {
|
||||
float derror = Math.abs(dy / (float) dx);
|
||||
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;
|
||||
|
||||
for (int x = x0; x <= x1; x++) {
|
||||
@@ -213,9 +219,9 @@ public final class CollisionManager {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -233,7 +239,7 @@ public final class CollisionManager {
|
||||
* @param matrix The matrix the update is being applied to.
|
||||
* @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 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) {
|
||||
if (type == CollisionUpdateType.ADDING) {
|
||||
@@ -248,8 +254,8 @@ public final class CollisionManager {
|
||||
*
|
||||
* @param position The {@link Position} of the tile.
|
||||
*/
|
||||
public void markBlocked(Position position) {
|
||||
blockedTiles.add(position);
|
||||
public void block(Position position) {
|
||||
blocked.add(position);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +264,7 @@ public final class CollisionManager {
|
||||
* @param position The {@link Position} of the tile.
|
||||
*/
|
||||
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) {
|
||||
Position next = position.step(1, direction);
|
||||
Region region = regionRepository.fromPosition(next);
|
||||
Region region = regions.fromPosition(next);
|
||||
|
||||
if (!region.traversable(next, type, direction)) {
|
||||
return false;
|
||||
@@ -283,7 +289,7 @@ public final class CollisionManager {
|
||||
next = position.step(1, component);
|
||||
|
||||
if (!region.contains(next)) {
|
||||
region = regionRepository.fromPosition(next);
|
||||
region = regions.fromPosition(next);
|
||||
}
|
||||
|
||||
if (!region.traversable(next, type, component)) {
|
||||
|
||||
@@ -1,29 +1,40 @@
|
||||
package org.apollo.game.model.area.collision;
|
||||
|
||||
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.game.model.Direction;
|
||||
import org.apollo.game.model.Position;
|
||||
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 static org.apollo.game.model.entity.obj.ObjectType.*;
|
||||
|
||||
/**
|
||||
* A global update to the collision matrices.
|
||||
*/
|
||||
public final class CollisionUpdate {
|
||||
|
||||
/**
|
||||
* The type of this update.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.type = type;
|
||||
this.flags = flags;
|
||||
@@ -48,10 +59,11 @@ public final class CollisionUpdate {
|
||||
}
|
||||
|
||||
/**
|
||||
* A directional flag in a {@code CollisionUpdate}. Consists of a {@code direction} and a flag indicating whether
|
||||
* A directional flag in a {@code CollisionUpdate}. Consists of a {@code direction} and a flag indicating whether
|
||||
* that tile is impenetrable as well as untraversable.
|
||||
*/
|
||||
public static final class DirectionFlag {
|
||||
|
||||
private final boolean impenetrable;
|
||||
private final Direction direction;
|
||||
|
||||
@@ -61,22 +73,19 @@ public final class CollisionUpdate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof DirectionFlag) {
|
||||
DirectionFlag other = (DirectionFlag) obj;
|
||||
return impenetrable == other.impenetrable && direction == other.direction;
|
||||
}
|
||||
|
||||
DirectionFlag that = (DirectionFlag) o;
|
||||
|
||||
if (impenetrable != that.impenetrable) return false;
|
||||
return direction == that.direction;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (impenetrable ? 1 : 0);
|
||||
result = 31 * result + direction.hashCode();
|
||||
return result;
|
||||
return Objects.hash(impenetrable, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,9 +105,14 @@ public final class CollisionUpdate {
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
/**
|
||||
* A builder for CollisionUpdates.
|
||||
*/
|
||||
public static final class Builder {
|
||||
|
||||
private final Multimap<Position, DirectionFlag> flags;
|
||||
private CollisionUpdateType type;
|
||||
|
||||
@@ -107,7 +121,7 @@ public final class CollisionUpdate {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of the {@link CollisionUpdate}. Can only be called once.
|
||||
* Set the type of the {@link CollisionUpdate}. Can only be called once.
|
||||
*
|
||||
* @param type The type of collision update to use.
|
||||
*/
|
||||
@@ -159,7 +173,6 @@ public final class CollisionUpdate {
|
||||
*/
|
||||
public void largeCornerWall(Position position, boolean impenetrable, Direction orientation) {
|
||||
Direction[] directions = Direction.diagonalComponents(orientation);
|
||||
|
||||
tile(position, impenetrable, directions);
|
||||
|
||||
for (Direction direction : directions) {
|
||||
@@ -192,22 +205,21 @@ public final class CollisionUpdate {
|
||||
length = definition.getWidth();
|
||||
}
|
||||
|
||||
if (type == ObjectType.FLOOR_DECORATION.getValue()) {
|
||||
if (type == FLOOR_DECORATION.getValue()) {
|
||||
if (definition.isInteractive() && definition.isSolid()) {
|
||||
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 dy = 0; dy < length; dy++) {
|
||||
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]);
|
||||
} else if (type == ObjectType.TRIANGULAR_CORNER.getValue()
|
||||
|| type == ObjectType.RECTANGULAR_CORNER.getValue()) {
|
||||
} else if (type == TRIANGULAR_CORNER.getValue() || type == RECTANGULAR_CORNER.getValue()) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
@@ -221,6 +233,7 @@ public final class CollisionUpdate {
|
||||
Preconditions.checkNotNull(type, "update type must not be null");
|
||||
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.
|
||||
*/
|
||||
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()
|
||||
&& type <= ObjectType.RECTANGULAR_CORNER.getValue() || type == ObjectType.DIAGONAL_WALL.getValue();
|
||||
boolean isWall = type >= LENGTHWISE_WALL.getValue() && type <= RECTANGULAR_CORNER.getValue() ||
|
||||
type == DIAGONAL_WALL.getValue();
|
||||
|
||||
boolean isRoof = type > ObjectType.DIAGONAL_INTERACTABLE.getValue()
|
||||
&& type < ObjectType.FLOOR_DECORATION.getValue();
|
||||
|
||||
boolean isSolidInteractable = (type == ObjectType.DIAGONAL_INTERACTABLE.getValue()
|
||||
|| type == ObjectType.INTERACTABLE.getValue()) && definition.isSolid();
|
||||
boolean isSolidInteractable = (type == DIAGONAL_INTERACTABLE.getValue() ||
|
||||
type == INTERACTABLE.getValue()) && definition.isSolid();
|
||||
|
||||
return isWall || isRoof || isSolidInteractable || isSolidFloorDecoration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-12
@@ -8,21 +8,21 @@ import org.apollo.game.model.entity.EntityType;
|
||||
import org.apollo.game.model.entity.obj.GameObject;
|
||||
|
||||
/**
|
||||
* A {@link RegionListener} which listens on object addition / removal events and applies
|
||||
* the respective {@link CollisionUpdate}.
|
||||
* A {@link RegionListener} that listens to object addition/removals and applies the respective {@link CollisionUpdate}.
|
||||
*/
|
||||
public final class GameObjectCollisionUpdateListener implements RegionListener {
|
||||
public final class CollisionUpdateListener implements RegionListener {
|
||||
|
||||
/**
|
||||
* The {@link CollisionManager} to apply updates to.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public GameObjectCollisionUpdateListener(CollisionManager collisionManager) {
|
||||
public CollisionUpdateListener(CollisionManager collisionManager) {
|
||||
this.collisionManager = collisionManager;
|
||||
}
|
||||
|
||||
@@ -34,16 +34,14 @@ public final class GameObjectCollisionUpdateListener implements RegionListener {
|
||||
return;
|
||||
}
|
||||
|
||||
CollisionUpdate.Builder objectUpdateBuilder = new CollisionUpdate.Builder();
|
||||
CollisionUpdate.Builder builder = new CollisionUpdate.Builder();
|
||||
if (type == EntityUpdateType.ADD) {
|
||||
objectUpdateBuilder.type(CollisionUpdateType.ADDING);
|
||||
builder.type(CollisionUpdateType.ADDING);
|
||||
} else {
|
||||
objectUpdateBuilder.type(CollisionUpdateType.REMOVING);
|
||||
builder.type(CollisionUpdateType.REMOVING);
|
||||
}
|
||||
|
||||
objectUpdateBuilder.object((GameObject) entity);
|
||||
|
||||
CollisionUpdate objectUpdate = objectUpdateBuilder.build();
|
||||
collisionManager.apply(objectUpdate);
|
||||
builder.object((GameObject) entity);
|
||||
collisionManager.apply(builder.build());
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package org.apollo.game.model.area.collision;
|
||||
* An enum which represents the type of a {@link CollisionUpdate}.
|
||||
*/
|
||||
public enum CollisionUpdateType {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
REMOVING
|
||||
|
||||
}
|
||||
|
||||
@@ -47,11 +47,10 @@ public enum EntityType {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this EntityType should be short-lived (i.e. not added to its {@link Region}s
|
||||
* local objects).
|
||||
* Returns whether or not this EntityType should be short-lived (i.e. not added to its regions local objects).
|
||||
*
|
||||
* @return {@code true} if this EntityType is short-lived.
|
||||
*/
|
||||
*/
|
||||
public boolean isTransient() {
|
||||
return this == PROJECTILE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user