Merge branch 'revert-dynamic-region-changes' into 'master'

Revert the dynamic region based parts of sc-backports, which seem to have...

See merge request 2009scape/2009scape!378
This commit is contained in:
Ceikry 2022-01-02 21:36:00 +00:00
commit 11eaa9f3a8
8 changed files with 51 additions and 98 deletions

View file

@ -389,16 +389,17 @@ public final class HouseManager {
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) { for (int y = 0; y < 8; y++) {
if(z == 3){ if(z == 3){
region.replaceChunk(z, x, y, defaultSkyChunk/*.copy(region.getPlanes()[z])*/, from); region.replaceChunk(z, x, y, defaultSkyChunk.copy(region.getPlanes()[z]), from);
continue; continue;
} }
Room room = rooms[z][x][y]; Room room = rooms[z][x][y];
if (room != null) { if (room != null) {
if (room.getProperties().isRoof() && buildingMode) { if (room.getProperties().isRoof() && buildingMode) {
continue; continue;
} }
region.replaceChunk(z, x, y, room.getChunk(), from); BuildRegionChunk copy = room.getChunk().copy(region.getPlanes()[z]);
room.loadDecorations(z, (BuildRegionChunk)region.getPlanes()[z].getChunks()[x][y], this); region.replaceChunk(z, x, y, copy, from);
room.loadDecorations(z, copy, this);
} else { } else {
region.replaceChunk(z, x, y, z != 0 ? defaultSkyChunk.copy(region.getPlanes()[z]) : defaultChunk.copy(region.getPlanes()[0]), from); region.replaceChunk(z, x, y, z != 0 ? defaultSkyChunk.copy(region.getPlanes()[z]) : defaultChunk.copy(region.getPlanes()[0]), from);
} }

View file

@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import kotlin.Pair;
/** /**
* Represents a region. * Represents a region.
@ -46,7 +45,7 @@ public class Region {
/** /**
* The region planes. * The region planes.
*/ */
protected final RegionPlane[] planes = new RegionPlane[4]; private final RegionPlane[] planes = new RegionPlane[4];
/** /**
* The activity pulse. * The activity pulse.
@ -227,15 +226,6 @@ public class Region {
return true; return true;
} }
public void sendUpdateSceneGraph(boolean login) {
for (int z = 0; z < 4; z++) {
for (Player p : this.getPlanes()[z].getPlayers()) {
p.updateSceneGraph(login);
}
}
}
/** /**
* Checks if this region has the inactivity flagging pulse running. * Checks if this region has the inactivity flagging pulse running.
* @return {@code True} if so. * @return {@code True} if so.
@ -556,10 +546,4 @@ public class Region {
public void setUpdateAllPlanes(boolean updateAllPlanes) { public void setUpdateAllPlanes(boolean updateAllPlanes) {
this.updateAllPlanes = updateAllPlanes; this.updateAllPlanes = updateAllPlanes;
} }
public void transformAllSceneryById(Pair<Integer, Integer>[] ids, boolean clip, boolean permanent) {
for(RegionPlane rp : getPlanes()) {
rp.transformAllSceneryById(ids, clip, permanent);
}
}
} }

View file

@ -4,7 +4,6 @@ import core.game.node.entity.player.Player;
import core.game.node.item.GroundItem; import core.game.node.item.GroundItem;
import core.game.node.item.Item; import core.game.node.item.Item;
import core.game.node.scenery.Scenery; import core.game.node.scenery.Scenery;
import core.game.node.scenery.SceneryBuilder;
import rs09.game.system.SystemLogger; import rs09.game.system.SystemLogger;
import core.game.world.map.build.DynamicRegion; import core.game.world.map.build.DynamicRegion;
import core.game.world.map.build.LandscapeParser; import core.game.world.map.build.LandscapeParser;
@ -16,9 +15,7 @@ import core.net.packet.out.ConstructScenery;
import core.net.packet.out.UpdateAreaPosition; import core.net.packet.out.UpdateAreaPosition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.function.Function;
import java.util.List; import java.util.List;
import kotlin.Pair;
/** /**
* Represents a region chunk. * Represents a region chunk.
@ -368,38 +365,4 @@ public class RegionChunk {
this.currentBase = currentBase; this.currentBase = currentBase;
} }
public void transformAllSceneryById(Pair<Integer, Integer>[] ids, boolean clip, boolean permanent) {
/*for(int i = 0; i < 8; i++) {
for(int j = 0; j < 8; j++) {
for(Scenery s : getObjects(i, j)) {
for(Pair<Integer, Integer> id : ids) {
if(s != null && s.getId() == id.getFirst()) {
SceneryBuilder.replace(s, s.transform(id.getSecond()), clip, permanent);
}
}
}
}
}*/
transformAllSceneryByFunction(clip, permanent, (Scenery s) -> {
for(Pair<Integer, Integer> id : ids) {
if(s != null && s.getId() == id.getFirst()) {
return s.transform(id.getSecond());
}
}
return s;
});
}
public void transformAllSceneryByFunction(boolean clip, boolean permanent, Function<Scenery, Scenery> f) {
for(int i = 0; i < 8; i++) {
for(int j = 0; j < 8; j++) {
for(Scenery s : getObjects(i, j)) {
Scenery t = f.apply(s);
if(s != t) {
SceneryBuilder.replace(s, t, clip, permanent);
}
}
}
}
}
} }

View file

@ -19,7 +19,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import kotlin.Pair;
/** /**
* Represents one of the 4 planes of a region. * Represents one of the 4 planes of a region.
@ -419,12 +418,4 @@ public final class RegionPlane {
return chunks; return chunks;
} }
public void transformAllSceneryById(Pair<Integer, Integer>[] ids, boolean clip, boolean permanent) {
for(int x = 0; x < 8; x++) {
for(int y = 0; y < 8; y++) {
RegionChunk rc = getChunks()[x][y];
rc.transformAllSceneryById(ids, clip, permanent);
}
}
}
} }

View file

@ -34,6 +34,11 @@ public final class DynamicRegion extends Region {
*/ */
private final int regionId; private final int regionId;
/**
* The region chunks.
*/
private final RegionChunk[][][] chunks;
/** /**
* The zone borders. * The zone borders.
*/ */
@ -70,6 +75,7 @@ public final class DynamicRegion extends Region {
public DynamicRegion(int regionId, int x, int y) { public DynamicRegion(int regionId, int x, int y) {
super(x, y); super(x, y);
this.regionId = regionId; this.regionId = regionId;
this.chunks = new RegionChunk[4][SIZE >> 3][SIZE >> 3];
} }
/** /**
@ -89,12 +95,12 @@ public final class DynamicRegion extends Region {
* @param regionTwo The second/last region. * @param regionTwo The second/last region.
* @return The new region. * @return The new region.
*/ */
public static DynamicRegion[] create(int regionOne, int regionTwo) { public static DynamicRegion create(int regionOne, int regionTwo) {
int x = (regionOne >> 8) << 6; int x = (regionOne >> 8) << 6;
int y = (regionOne & 0xFF) << 6; int y = (regionOne & 0xFF) << 6;
int x1 = (regionTwo >> 8) << 6; int x1 = (regionTwo >> 8) << 6;
int y1 = (regionTwo & 0xFF) << 6; int y1 = (regionTwo & 0xFF) << 6;
return create(new ZoneBorders(x, y, x1 + SIZE, y1 + SIZE)); return create(new ZoneBorders(x, y, x1 + SIZE, y1 + SIZE))[0];
} }
/** /**
@ -128,7 +134,11 @@ public final class DynamicRegion extends Region {
} }
} }
for (Region r : regions) { for (Region r : regions) {
r.sendUpdateSceneGraph(false); for (int z = 0; z < 4; z++) {
for (Player p : r.getPlanes()[z].getPlayers()) {
p.updateSceneGraph(false);
}
}
} }
return regions.toArray(new DynamicRegion[regions.size()]); return regions.toArray(new DynamicRegion[regions.size()]);
} }
@ -201,13 +211,12 @@ public final class DynamicRegion extends Region {
int x = regionX + (offsetX << 3); int x = regionX + (offsetX << 3);
int y = regionY + (offsetY << 3); int y = regionY + (offsetY << 3);
for (int plane = 0; plane < 4; plane++) { for (int plane = 0; plane < 4; plane++) {
RegionChunk c = region.planes[plane].getChunks()[offsetX][offsetY]; RegionChunk c = region.chunks[plane][offsetX][offsetY];
if (c == null) { if (c == null) {
region.planes[plane].getChunks()[offsetX][offsetY] = c = new RegionChunk(Location.create(0, 0, 0), 0, region.getPlanes()[plane]); region.chunks[plane][offsetX][offsetY] = c = new RegionChunk(Location.create(0, 0, 0), 0, region.getPlanes()[plane]);
} }
c.setRotation(0); c.setRotation(0);
c.setBase(Location.create(x, y, plane)); c.setBase(Location.create(x, y, plane));
c.setCurrentBase(region.getBaseLocation().transform(offsetX << 3, offsetY << 3, 0));
} }
} }
} }
@ -258,10 +267,10 @@ public final class DynamicRegion extends Region {
*/ */
public void rotate() { public void rotate() {
for (int z = 0; z < 4; z++) { for (int z = 0; z < 4; z++) {
RegionChunk[][] c = Arrays.copyOf(planes[z].getChunks(), 8); RegionChunk[][] c = Arrays.copyOf(chunks[z], 8);
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) { for (int y = 0; y < 8; y++) {
RegionChunk r = planes[z].getChunks()[x][y] = c[8 - y - 1][x].copy(planes[z]); RegionChunk r = chunks[z][x][y] = c[8 - y - 1][x];
if (r != null) { if (r != null) {
r.setRotation(r.getRotation() + 1); r.setRotation(r.getRotation() + 1);
} }
@ -278,7 +287,8 @@ public final class DynamicRegion extends Region {
* @param chunk The chunk to set. * @param chunk The chunk to set.
*/ */
public void setChunk(int z, int x, int y, RegionChunk chunk) { public void setChunk(int z, int x, int y, RegionChunk chunk) {
planes[z].getChunks()[x][y] = chunk.copy(planes[z]); chunks[z][x][y] = chunk;
getPlanes()[z].getChunks()[x][y] = chunk;
if (chunk != null) { if (chunk != null) {
chunk.setCurrentBase(getBaseLocation().transform(x << 3, y << 3, 0)); chunk.setCurrentBase(getBaseLocation().transform(x << 3, y << 3, 0));
} }
@ -293,18 +303,16 @@ public final class DynamicRegion extends Region {
* @param fromRegion The region the chunk is copied from. * @param fromRegion The region the chunk is copied from.
*/ */
public void replaceChunk(int z, int x, int y, RegionChunk chunk, Region fromRegion) { public void replaceChunk(int z, int x, int y, RegionChunk chunk, Region fromRegion) {
if(fromRegion instanceof DynamicRegion) {
fromRegion = RegionManager.forId(fromRegion.getRegionId());
}
Region.load(DynamicRegion.this); Region.load(DynamicRegion.this);
RegionPlane p = planes[z]; RegionPlane p = getPlanes()[z];
chunks[z][x][y] = chunk;
p.getChunks()[x][y] = chunk;
if (chunk == null) { if (chunk == null) {
p.getChunks()[x][y] = null;
for (int i = x << 3; i < (x + 1) << 3; i++) { for (int i = x << 3; i < (x + 1) << 3; i++) {
for (int j = y << 3; j < (y + 1) << 3; j++) { for (int j = y << 3; j < (y + 1) << 3; j++) {
p.getFlags().getClippingFlags()[i][j] = -1; p.getFlags().getClippingFlags()[i][j] = -1;
p.getProjectileFlags().getClippingFlags()[i][j] = -1; p.getProjectileFlags().getClippingFlags()[i][j] = -1;
Scenery object = p.getChunkObject(i, j); Scenery object = p.getObjects()[i][j];
if (object != null) { if (object != null) {
LandscapeParser.removeScenery(object); LandscapeParser.removeScenery(object);
} else { } else {
@ -313,11 +321,10 @@ public final class DynamicRegion extends Region {
} }
} }
} else { } else {
RegionChunk newChunk = p.getChunks()[x][y] = chunk.copy(p); chunk.clear();
newChunk.clear();
Region.load(fromRegion); Region.load(fromRegion);
Location l = newChunk.getBase(); Location l = chunk.getBase();
newChunk.setCurrentBase(getBaseLocation().transform(x << 3, y << 3, 0)); chunk.setCurrentBase(getBaseLocation().transform(x << 3, y << 3, 0));
Location regionBase = fromRegion.getBaseLocation(); Location regionBase = fromRegion.getBaseLocation();
RegionPlane rp = fromRegion.getPlanes()[l.getZ()]; RegionPlane rp = fromRegion.getPlanes()[l.getZ()];
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
@ -372,7 +379,7 @@ public final class DynamicRegion extends Region {
NPC npc = plane.getNpcs().get(0); NPC npc = plane.getNpcs().get(0);
npc.clear(); npc.clear();
} }
for (RegionChunk[] chunks : getPlanes()[plane.getPlane()].getChunks()) { for (RegionChunk[] chunks : getChunks()[plane.getPlane()]) {
for (RegionChunk chunk : chunks) { for (RegionChunk chunk : chunks) {
if (chunk != null) { if (chunk != null) {
for (Iterator<GroundItem> it = chunk.getItems().iterator(); it.hasNext();) { for (Iterator<GroundItem> it = chunk.getItems().iterator(); it.hasNext();) {
@ -399,6 +406,14 @@ public final class DynamicRegion extends Region {
return regionId; return regionId;
} }
/**
* Gets the chunks.
* @return The chunks.
*/
public RegionChunk[][][] getChunks() {
return chunks;
}
/** /**
* Gets the borders. * Gets the borders.
* @return The borders. * @return The borders.

View file

@ -75,8 +75,7 @@ public final class LandscapeParser {
*/ */
public static void addScenery(Scenery object, boolean landscape) { public static void addScenery(Scenery object, boolean landscape) {
Location l = object.getLocation(); Location l = object.getLocation();
RegionPlane rp = RegionManager.getRegionPlane(l); flagScenery(RegionManager.getRegionPlane(l), l.getLocalX(), l.getLocalY(), object, landscape, false);
flagScenery(rp, l.getLocalX(), l.getLocalY(), object, landscape, false);
} }
/** /**

View file

@ -39,7 +39,7 @@ public final class BuildDynamicScene implements OutgoingPacket<DynamicSceneConte
r = RegionManager.forId((x >> 3) << 8 | (y >> 3)); r = RegionManager.forId((x >> 3) << 8 | (y >> 3));
if (r instanceof DynamicRegion) { if (r instanceof DynamicRegion) {
DynamicRegion dr = (DynamicRegion) r; DynamicRegion dr = (DynamicRegion) r;
chunks[z][x - baseX][y - baseY] = dr.getPlanes()[z].getChunks()[x - (dr.getX() << 3)][y - (dr.getY() << 3)]; chunks[z][x - baseX][y - baseY] = dr.getChunks()[z][x - (dr.getX() << 3)][y - (dr.getY() << 3)];
} }
} }
} }