Skip to content

Commit f6d34ae

Browse files
committed
refactor: convert Landscape to an instance, make a child of Scene
1 parent 133a41e commit f6d34ae

File tree

9 files changed

+36
-35
lines changed

9 files changed

+36
-35
lines changed

src/main/java/org/runejs/OldEngine/MapDecompressor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static void spawnObject(int objectId, int x, int y, int z, int rotation,
132132
class20 = groundData[plane];
133133
}
134134
if(localY > 0 && localX > 0 && localY < 103 && localX < 103) {
135-
Landscape.addObject(objectId, localX, localY, z, rotation, type, Game.currentScene, class20);
135+
Game.currentScene.landscape.addObject(objectId, localX, localY, z, rotation, type, Game.currentScene, class20);
136136
}
137137
}
138138

src/main/java/org/runejs/OldEngine/ObjectDecompressor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static void spawnObject(int objectId, int x, int y, int z, int rotation,
135135
class20 = groundData[plane];
136136
}
137137
if(localY > 0 && localX > 0 && localY < 103 && localX < 103) {
138-
Landscape.addObject(objectId, localX, localY, z, rotation, type, Game.currentScene, class20);
138+
Game.currentScene.landscape.addObject(objectId, localX, localY, z, rotation, type, Game.currentScene, class20);
139139
}
140140
}
141141

src/main/java/org/runejs/client/Game.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ else if (MovedStatics.obfuscatedKeyStatus[99] && !Console.console.consoleOpen)
20382038
int i_7_ = Player.worldLevel;
20392039
if (i_7_ < 3 && (0x2 & MovedStatics.tile_flags[1][i_5_][i_6_]) == 2)
20402040
i_7_++;
2041-
int i_8_ = i_4_ + -Landscape.tile_height[i_7_][i_5_][i_6_];
2041+
int i_8_ = i_4_ + -currentScene.landscape.tile_height[i_7_][i_5_][i_6_];
20422042
if (i_8_ > i_3_)
20432043
i_3_ = i_8_;
20442044
}
@@ -2171,7 +2171,7 @@ public void processGameLoop() {
21712171
Class60.updateLogin();
21722172
handleLoginScreenActions();
21732173
} else if (gameStatusCode == 25)
2174-
Landscape.loadRegion();
2174+
currentScene.landscape.loadRegion();
21752175
if (gameStatusCode == 30) {
21762176
ScreenController.refreshFrameSize();
21772177
updateGame();

src/main/java/org/runejs/client/Landscape.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public class Landscape {
4747
public static byte[][] terrainData;
4848
public static boolean loadGeneratedMap = false;
4949
public static int[] terrainDataIds;
50-
public static int[][][] tile_height = new int[4][105][105];
50+
public int[][][] tile_height = new int[4][105][105];
5151
public static int randomiserLightness = -16 + (int) (Math.random() * 33.0);
5252
public static int randomiserHue = -8 + (int) (17.0 * Math.random());
5353
private static int lowestPlane = 99;
5454

55-
public static void loadRegion() {
55+
public void loadRegion() {
5656
method364(false);
5757
Game.anInt874 = 0;
5858
boolean bool = true;
@@ -254,7 +254,7 @@ public static void loadRegion() {
254254

255255
}
256256

257-
private static void loadTerrainSubblock(int y, int drawX, int drawingPlane, int currentPlane, int x, int drawY, int rotation, byte[] terrainData, CollisionMap[] collisionMaps) {
257+
private void loadTerrainSubblock(int y, int drawX, int drawingPlane, int currentPlane, int x, int drawY, int rotation, byte[] terrainData, CollisionMap[] collisionMaps) {
258258
for(int i = 0; i < 8; i++) {
259259
for(int yIdx = 0; yIdx < 8; yIdx++) {
260260
if(x + i > 0 && i + x < 103 && y + yIdx > 0 && yIdx + y < 103)
@@ -297,7 +297,7 @@ private static int getRotatedTileY(int x, int y, int rotation) {
297297

298298
}
299299

300-
private static void constructMapRegionObjects(int drawX, int drawY, int drawingPlane, int orientation, int x, int y, int plane, Scene scene, byte[] objectData, CollisionMap[] collisionMaps) {
300+
private void constructMapRegionObjects(int drawX, int drawY, int drawingPlane, int orientation, int x, int y, int plane, Scene scene, byte[] objectData, CollisionMap[] collisionMaps) {
301301
Buffer objectBuffer = new Buffer(objectData);
302302
int i = -1;
303303
for(; ; ) {
@@ -367,7 +367,7 @@ private static int getRotatedObjectY(int x, int y, int sizeX, int sizeY, int ori
367367
return x;
368368
}
369369

370-
private static void createRegion(Scene scene, CollisionMap[] collisionMaps) {
370+
private void createRegion(Scene scene, CollisionMap[] collisionMaps) {
371371
for(int plane = 0; plane < 4; plane++) {
372372
for(int x = 0; x < 104; x++) {
373373
for(int y = 0; y < 104; y++) {
@@ -743,7 +743,7 @@ private static void method1020() {
743743
tile_underlayids = new byte[4][104][104];
744744
}
745745

746-
private static void loadTerrainBlock(CollisionMap[] collisions, int regionX_maybe, byte[] blockData, int offsetX, int offsetY, int regionY_maybe) {
746+
private void loadTerrainBlock(CollisionMap[] collisions, int regionX_maybe, byte[] blockData, int offsetX, int offsetY, int regionY_maybe) {
747747
for(int i = 0; i < 4; i++) {
748748
for(int i_1_ = 0; i_1_ < 64; i_1_++) {
749749
for(int i_2_ = 0; i_2_ < 64; i_2_++) {
@@ -763,7 +763,7 @@ private static void loadTerrainBlock(CollisionMap[] collisions, int regionX_mayb
763763
}
764764
}
765765

766-
private static void method922(int x, int arg1, Buffer fileData, int y, int regionY, int regionX, int level) {
766+
private void method922(int x, int arg1, Buffer fileData, int y, int regionY, int regionX, int level) {
767767
if(x >= 0 && x < 104 && y >= 0 && y < 104) {
768768
MovedStatics.tile_flags[level][x][y] = (byte) 0;
769769
for(; ; ) {
@@ -936,7 +936,7 @@ else if(lightness > 126)
936936
return lightness + (hsl & 0xff80);
937937
}
938938

939-
private static void loadObjectBlock(int block_x, Scene scene, CollisionMap[] collisionMaps, byte[] block_data, int block_z) {
939+
private void loadObjectBlock(int block_x, Scene scene, CollisionMap[] collisionMaps, byte[] block_data, int block_z) {
940940
Buffer buffer = new Buffer(block_data);
941941
int object_id = -1;
942942
for(; ; ) {
@@ -971,7 +971,7 @@ private static void loadObjectBlock(int block_x, Scene scene, CollisionMap[] col
971971
}
972972
}
973973

974-
public static void addObject(int objectId, int localX, int localY, int plane, int face, int type, Scene scene, CollisionMap collisionMap) {
974+
public void addObject(int objectId, int localX, int localY, int plane, int face, int type, Scene scene, CollisionMap collisionMap) {
975975
if(!VertexNormal.lowMemory || (0x2 & MovedStatics.tile_flags[0][localX][localY]) != 0 || (0x10 & MovedStatics.tile_flags[plane][localX][localY]) == 0 && MovedStatics.onBuildTimePlane == MovedStatics.getVisibilityPlaneFor(plane, localY, 0, localX)) {
976976
if(lowestPlane > plane)
977977
lowestPlane = plane;
@@ -1297,7 +1297,7 @@ private static void method364(boolean arg1) {
12971297
}
12981298
}
12991299

1300-
private static void initiateVertexHeights(int offsetY, int sizeY, int sizeX, int offsetX) {
1300+
private void initiateVertexHeights(int offsetY, int sizeY, int sizeX, int offsetX) {
13011301
for (int y = offsetY; y <= offsetY + sizeY; y++) {
13021302
for (int x = offsetX; sizeX + offsetX >= x; x++) {
13031303
if (x >= 0 && x < 104 && y >= 0 && y < 104) {
@@ -1315,7 +1315,7 @@ private static void initiateVertexHeights(int offsetY, int sizeY, int sizeX, int
13151315
}
13161316
}
13171317

1318-
private static void method455(int arg0, int arg1, int arg3) {
1318+
private void method455(int arg0, int arg1, int arg3) {
13191319
for (int i = 0; i < 8; i++) {
13201320
for (int i_0_ = 0; i_0_ < 8; i_0_++)
13211321
tile_height[arg1][arg3 + i][arg0 + i_0_] = 0;

src/main/java/org/runejs/client/MovedStatics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3390,7 +3390,7 @@ public static boolean method596(int arg0, int arg1, byte junk, int arg3) {
33903390

33913391
public static void startup() {
33923392
if (loadingPercent == 0) {
3393-
Game.currentScene = new Scene(Landscape.tile_height);
3393+
Game.currentScene = new Scene();
33943394
for (int i = 0; i < 4; i++)
33953395
Landscape.currentCollisionMap[i] = new CollisionMap(104, 104);
33963396
Minimap.minimapImage = new ImageRGB(512, 512);

src/main/java/org/runejs/client/message/handler/rs435/misc/TransformPlayerToObjectMessageHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public void handle(TransformPlayerToObjectInboundMessage message) {
3131
player = Player.localPlayer;
3232
if (player != null) {
3333
GameObjectDefinition gameObjectDefinition = GameObjectDefinition.getDefinition(message.objectId);
34-
int tileHeightX0Y0 = Landscape.tile_height[Player.worldLevel][x][y];
35-
int tileHeightX0Y1 = Landscape.tile_height[Player.worldLevel][x][1 + y];
36-
int tileHeightX1Y1 = Landscape.tile_height[Player.worldLevel][1 + x][1 + y];
37-
int tileHeightX1Y0 = Landscape.tile_height[Player.worldLevel][x + 1][y];
34+
int tileHeightX0Y0 = Game.currentScene.landscape.tile_height[Player.worldLevel][x][y];
35+
int tileHeightX0Y1 = Game.currentScene.landscape.tile_height[Player.worldLevel][x][1 + y];
36+
int tileHeightX1Y1 = Game.currentScene.landscape.tile_height[Player.worldLevel][1 + x][1 + y];
37+
int tileHeightX1Y0 = Game.currentScene.landscape.tile_height[Player.worldLevel][x + 1][y];
3838
Model model = gameObjectDefinition.createTerrainObjectModel(tileHeightX1Y1, tileHeightX0Y1, message.orientation, tileHeightX0Y0, typeKey, tileHeightX1Y0);
3939
if (model != null) {
4040
if (unknownXMax < unknownXMin) {

src/main/java/org/runejs/client/message/handler/rs435/world/object/RotateAnimateObjectMessageHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public void handle(RotateAnimateObjectInboundMessage message) {
2424
int animationId = message.animationId;
2525

2626
if (x >= 0 && y >= 0 && x < 103 && y < 103) {
27-
int tileHeightX0Y0 = Landscape.tile_height[Player.worldLevel][x][y];
28-
int tileHeightX1Y0 = Landscape.tile_height[Player.worldLevel][x + 1][y];
29-
int tileHeightX1Y1 = Landscape.tile_height[Player.worldLevel][1 + x][1 + y];
30-
int tileHeightX0Y1 = Landscape.tile_height[Player.worldLevel][x][y + 1];
27+
int tileHeightX0Y0 = Game.currentScene.landscape.tile_height[Player.worldLevel][x][y];
28+
int tileHeightX1Y0 = Game.currentScene.landscape.tile_height[Player.worldLevel][x + 1][y];
29+
int tileHeightX1Y1 = Game.currentScene.landscape.tile_height[Player.worldLevel][1 + x][1 + y];
30+
int tileHeightX0Y1 = Game.currentScene.landscape.tile_height[Player.worldLevel][x][y + 1];
3131
if (objectType == 0) {
3232
Wall wall = Game.currentScene.getWall(Player.worldLevel, x, y);
3333
if (wall != null) {

src/main/java/org/runejs/client/scene/Scene.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class Scene {
3737

3838
public static boolean lowMemory = true;
3939

40+
public final Landscape landscape = new Landscape();
41+
4042
public SceneTile[][][] tileArray;
4143
public int[][][] tileOcclusionCycles;
4244
public int sceneSpawnRequestsCacheCurrentPos = 0;
@@ -100,10 +102,10 @@ public class Scene {
100102
private Camera currentCamera;
101103
private CameraTileVisibility tileVisibilityInfo;
102104

103-
public Scene(int[][][] heightMap) {
105+
public Scene() {
104106
tileArray = new SceneTile[mapSizeZ][mapSizeX][mapSizeY];
105107
tileOcclusionCycles = new int[mapSizeZ][mapSizeX + 1][mapSizeY + 1];
106-
this.heightMap = heightMap;
108+
this.heightMap = this.landscape.tile_height;
107109
initToNull();
108110
}
109111

@@ -2036,11 +2038,10 @@ public boolean isMouseWithinTriangle(int mouseX, int mouseY, int pointAY, int po
20362038
* @param plane The current plane (or level) within the 3D space
20372039
* @param x The x coordinate in the 3D space
20382040
* @param y The y coordinate in the 3D space
2039-
* @param tileHeights A 3D array containing the heights of each tile
20402041
* @param tileFlags A 3D array containing the flags for each tile (e.g. whether it's a bridge)
20412042
* @return The height of the floor at the given x,y coordinate
20422043
*/
2043-
public int getFloorDrawHeight(int plane, int x, int y, int[][][] tileHeights, byte[][][] tileFlags) {
2044+
public int getFloorDrawHeight(int plane, int x, int y, byte[][][] tileFlags) {
20442045
// Convert x and y into 'tile space' by dividing by 128 (right shifting by 7 bits)
20452046
int groundX = x >> 7;
20462047
int groundY = y >> 7;
@@ -2063,11 +2064,11 @@ public int getFloorDrawHeight(int plane, int x, int y, int[][][] tileHeights, by
20632064

20642065
// Interpolate the height for the X-axis at Y position 'groundY' based on tile position X
20652066
// It's a weighted average between the height at groundX and groundX+1
2066-
int interpolatedHeightX1 = ((128 - tilePositionX) * tileHeights[groundZ][groundX][groundY] + tilePositionX * tileHeights[groundZ][groundX + 1][groundY]) >> 7;
2067+
int interpolatedHeightX1 = ((128 - tilePositionX) * landscape.tile_height[groundZ][groundX][groundY] + tilePositionX * landscape.tile_height[groundZ][groundX + 1][groundY]) >> 7;
20672068

20682069
// Interpolate the height for the X-axis at Y position 'groundY+1' based on tile position X
20692070
// Similar to above, but one step forward in the Y-axis
2070-
int interpolatedHeightX2 = (tilePositionX * tileHeights[groundZ][groundX + 1][groundY + 1] + tileHeights[groundZ][groundX][groundY + 1] * (128 - tilePositionX)) >> 7;
2071+
int interpolatedHeightX2 = (tilePositionX * landscape.tile_height[groundZ][groundX + 1][groundY + 1] + landscape.tile_height[groundZ][groundX][groundY + 1] * (128 - tilePositionX)) >> 7;
20712072

20722073
// Interpolate between the two interpolated X-axis heights, based on the tile position Y
20732074
// This results in a height that takes into account the position within the tile in both the X and Y directions
@@ -2076,6 +2077,6 @@ public int getFloorDrawHeight(int plane, int x, int y, int[][][] tileHeights, by
20762077
}
20772078

20782079
public int getFloorDrawHeight(int plane, int x, int y) {
2079-
return getFloorDrawHeight(plane, x, y, Landscape.tile_height, MovedStatics.tile_flags);
2080+
return getFloorDrawHeight(plane, x, y, MovedStatics.tile_flags);
20802081
}
20812082
}

src/main/java/org/runejs/client/scene/util/CollisionMap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public CollisionMap(int arg0, int arg1) {
2828
public void addObject(int arg1, int arg2, int arg3, int arg4, Scene arg5, int arg7, int arg8, int arg9) {
2929
CollisionMap arg0 = this;
3030

31-
int i = Landscape.tile_height[arg2][arg9][arg8];
32-
int i_0_ = Landscape.tile_height[arg2][1 + arg9][arg8];
33-
int i_1_ = Landscape.tile_height[arg2][arg9][1 + arg8];
34-
int i_2_ = Landscape.tile_height[arg2][arg9 + 1][arg8 + 1];
31+
int i = Game.currentScene.landscape.tile_height[arg2][arg9][arg8];
32+
int i_0_ = Game.currentScene.landscape.tile_height[arg2][1 + arg9][arg8];
33+
int i_1_ = Game.currentScene.landscape.tile_height[arg2][arg9][1 + arg8];
34+
int i_2_ = Game.currentScene.landscape.tile_height[arg2][arg9 + 1][arg8 + 1];
3535
GameObjectDefinition gameObjectDefinition = GameObjectDefinition.getDefinition(arg1);
3636
int i_3_ = i_2_ + i_0_ + i + i_1_ >> 2;
3737
int i_4_ = (arg7 << 6) + arg4;

0 commit comments

Comments
 (0)