mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +00:00
Merge branch 'feature/region-update' of https://atomicint@bitbucket.org/Major-/apollo.git
Conflicts: src/org/apollo/game/model/World.java src/org/apollo/game/model/area/Region.java
This commit is contained in:
@@ -385,12 +385,12 @@ public final class World {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds entities to regions in the {@link RegionRepository}.
|
||||
* Adds entities to regions in the {@link RegionRepository}. By default, we do not notify listeners.
|
||||
*
|
||||
* @param entities The entities.
|
||||
*/
|
||||
private void placeEntities(Entity... entities) {
|
||||
Arrays.stream(entities).forEach(entity -> regions.fromPosition(entity.getPosition()).addEntity(entity));
|
||||
Arrays.stream(entities).forEach(entity -> regions.fromPosition(entity.getPosition()).addEntity(entity, false));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public final class Region {
|
||||
@Override
|
||||
public void execute(Region region, Entity entity, EntityUpdateType update) {
|
||||
EntityType type = entity.getEntityType();
|
||||
if (type != EntityType.PLAYER && type != EntityType.NPC && (type != EntityType.STATIC_OBJECT || update == EntityUpdateType.REMOVE)) {
|
||||
if (type != EntityType.PLAYER && type != EntityType.NPC) {
|
||||
region.record(entity, update);
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public final class Region {
|
||||
/**
|
||||
* The Set containing RegionUpdateMessages which can be sent to add every non-Mob Entity in this Region.
|
||||
*/
|
||||
private final List<List<RegionUpdateMessage>> snapshots = new ArrayList<>(Position.HEIGHT_LEVELS);
|
||||
private final List<Map<Entity, RegionUpdateMessage>> snapshots = new ArrayList<>(Position.HEIGHT_LEVELS);
|
||||
|
||||
/**
|
||||
* The Set containing UpdateOperations.
|
||||
@@ -110,40 +110,57 @@ public final class Region {
|
||||
listeners.add(new UpdateRegionListener());
|
||||
|
||||
for (int height = 0; height < Position.HEIGHT_LEVELS; height++) {
|
||||
snapshots.add(new ArrayList<>());
|
||||
snapshots.add(new HashMap<>());
|
||||
updates.add(new ArrayList<>(DEFAULT_SET_SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a {@link Entity} from to Region. Note that this does not spawn the Entity, or do any other action other than
|
||||
* 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) {
|
||||
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);
|
||||
|
||||
if ((System.currentTimeMillis() - start) / 1000 > 10 && entity instanceof GameObject) {
|
||||
if ((System.currentTimeMillis() - start) / 1000 > 10 && (entity instanceof GameObject)) {
|
||||
System.out.println("Adding entity " + entity + " to " + entity.getPosition());
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
notifyListeners(entity, EntityUpdateType.ADD);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this Region contains the specified Entity.
|
||||
* <p>
|
||||
* <p/>
|
||||
* This method operates in constant time.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @return {@code true} if this Region contains the Entity, otherwise {@code false}.
|
||||
*/
|
||||
|
||||
public boolean contains(Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
Set<Entity> local = entities.get(position);
|
||||
@@ -169,7 +186,7 @@ public final class Region {
|
||||
*/
|
||||
public Set<Entity> getEntities(Position position) {
|
||||
Set<Entity> set = entities.get(position);
|
||||
return set == null ? ImmutableSet.of() : ImmutableSet.copyOf(set);
|
||||
return (set == null) ? ImmutableSet.of() : ImmutableSet.copyOf(set);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,7 +228,7 @@ public final class Region {
|
||||
* @return The Set of RegionUpdateMessages.
|
||||
*/
|
||||
public List<RegionUpdateMessage> getSnapshot(int height) {
|
||||
List<RegionUpdateMessage> copy = new ArrayList<>(snapshots.get(height));
|
||||
List<RegionUpdateMessage> copy = new ArrayList<>(snapshots.get(height).values());
|
||||
Collections.sort(copy);
|
||||
return ImmutableList.copyOf(copy);
|
||||
}
|
||||
@@ -224,7 +241,7 @@ public final class Region {
|
||||
* @return The Set of RegionUpdateMessages.
|
||||
*/
|
||||
public List<RegionUpdateMessage> getUpdates(int height) {
|
||||
List<RegionUpdateMessage> original = updates.get(height);
|
||||
List<RegionUpdateMessage> original = this.updates.get(height);
|
||||
List<RegionUpdateMessage> updates = new ArrayList<>(original);
|
||||
original.clear();
|
||||
|
||||
@@ -304,7 +321,12 @@ public final class Region {
|
||||
int height = entity.getPosition().getHeight();
|
||||
|
||||
updates.get(height).add(message);
|
||||
snapshots.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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user