Skip to content

Commit 8ff9dcb

Browse files
committed
refactor: convert most Landscape methods to instance and private
1 parent f6d34ae commit 8ff9dcb

File tree

5 files changed

+38
-33
lines changed

5 files changed

+38
-33
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-
Game.currentScene.landscape.addObject(objectId, localX, localY, z, rotation, type, Game.currentScene, class20);
135+
Game.currentScene.landscape.addObject(objectId, localX, localY, z, rotation, type, 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-
Game.currentScene.landscape.addObject(objectId, localX, localY, z, rotation, type, Game.currentScene, class20);
138+
Game.currentScene.landscape.addObject(objectId, localX, localY, z, rotation, type, class20);
139139
}
140140
}
141141

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ public static void handleLoginScreenActions() {
17601760
MovedStatics.gameServerSocket.readDataToBuffer(0, IncomingPackets.incomingPacketSize, IncomingPackets.incomingPacketBuffer.buffer);
17611761
setConfigToDefaults();
17621762
MovedStatics.regionX = -1;
1763-
Landscape.constructMapRegion(false);
1763+
currentScene.landscape.constructMapRegion(false);
17641764
IncomingPackets.opcode = -1;
17651765
}
17661766
} else {

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

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ public class Landscape {
5252
public static int randomiserHue = -8 + (int) (17.0 * Math.random());
5353
private static int lowestPlane = 99;
5454

55+
private final Scene scene;
56+
57+
public Landscape(Scene scene) {
58+
this.scene = scene;
59+
}
60+
5561
public void loadRegion() {
5662
method364(false);
5763
Game.anInt874 = 0;
@@ -91,7 +97,7 @@ public void loadRegion() {
9197
if(MovedStatics.anInt1634 != 0)
9298
MovedStatics.method940(English.loadingPleaseWait, true, Native.percent100Parentheses);
9399
Game.clearCaches();
94-
Game.currentScene.initToNull();
100+
this.scene.initToNull();
95101
System.gc();
96102
for(int z = 0; z < 4; z++)
97103
currentCollisionMap[z].reset();
@@ -143,7 +149,7 @@ public void loadRegion() {
143149
if(data != null) {
144150
int offsetX = -MovedStatics.baseX + (mapCoordinates[region] >> 8) * 64;
145151
int offsetY = 64 * (0xff & mapCoordinates[region]) - MovedStatics.baseY;
146-
loadObjectBlock(offsetX, Game.currentScene, currentCollisionMap, data, offsetY);
152+
loadObjectBlock(offsetX, currentCollisionMap, data, offsetY);
147153
} else {
148154
System.out.println("Missing map: " + objectDataIds[region]);
149155
}
@@ -194,7 +200,7 @@ public void loadRegion() {
194200
int tileCoordinates = (tileX / 8 << 8) + tileY / 8;
195201
for(int i_38_ = 0; i_38_ < mapCoordinates.length; i_38_++) {
196202
if(tileCoordinates == mapCoordinates[i_38_] && objectData[i_38_] != null) {
197-
constructMapRegionObjects(8 * (tileX & 0x7), 8 * (tileY & 0x7), tileZ, tileRotation, x * 8, 8 * y, z, Game.currentScene, objectData[i_38_], currentCollisionMap);
203+
constructMapRegionObjects(8 * (tileX & 0x7), 8 * (tileY & 0x7), tileZ, tileRotation, x * 8, 8 * y, z, objectData[i_38_], currentCollisionMap);
198204
break;
199205
}
200206
}
@@ -205,17 +211,17 @@ public void loadRegion() {
205211
}
206212
method364(true);
207213
Game.clearCaches();
208-
createRegion(Game.currentScene, currentCollisionMap);
214+
createRegion(currentCollisionMap);
209215
method364(true);
210216
int z = lowestPlane;
211217
if(Player.worldLevel < z)
212218
z = Player.worldLevel;
213219
if(z < -1 + Player.worldLevel)
214220
z = -1 + Player.worldLevel;
215221
if(!VertexNormal.lowMemory)
216-
Game.currentScene.setPlane(0);
222+
this.scene.setPlane(0);
217223
else
218-
Game.currentScene.setPlane(lowestPlane);
224+
this.scene.setPlane(lowestPlane);
219225
for(int x = 0; x < 104; x++) {
220226
for(int y = 0; y < 104; y++)
221227
MovedStatics.spawnGroundItem(y, x);
@@ -297,7 +303,7 @@ private static int getRotatedTileY(int x, int y, int rotation) {
297303

298304
}
299305

300-
private void constructMapRegionObjects(int drawX, int drawY, int drawingPlane, int orientation, int x, int y, int plane, Scene scene, byte[] objectData, CollisionMap[] collisionMaps) {
306+
private void constructMapRegionObjects(int drawX, int drawY, int drawingPlane, int orientation, int x, int y, int plane, byte[] objectData, CollisionMap[] collisionMaps) {
301307
Buffer objectBuffer = new Buffer(objectData);
302308
int i = -1;
303309
for(; ; ) {
@@ -328,7 +334,7 @@ private void constructMapRegionObjects(int drawX, int drawY, int drawingPlane, i
328334
collisionMapPlane--;
329335
if(collisionMapPlane >= 0)
330336
collisionMap = collisionMaps[collisionMapPlane];
331-
addObject(i, tileX, tileY, plane, originalOrientation + orientation & 0x3, objectType, scene, collisionMap);
337+
addObject(i, tileX, tileY, plane, originalOrientation + orientation & 0x3, objectType, collisionMap);
332338
}
333339
}
334340
}
@@ -367,7 +373,7 @@ private static int getRotatedObjectY(int x, int y, int sizeX, int sizeY, int ori
367373
return x;
368374
}
369375

370-
private void createRegion(Scene scene, CollisionMap[] collisionMaps) {
376+
private void createRegion(CollisionMap[] collisionMaps) {
371377
for(int plane = 0; plane < 4; plane++) {
372378
for(int x = 0; x < 104; x++) {
373379
for(int y = 0; y < 104; y++) {
@@ -546,29 +552,29 @@ else if(s > 255)
546552
overlayMinimapColour = generateHslBitset(overlayDefinition.otherLightness, i_55_, i_54_);
547553
rgb = Rasterizer3D.hsl2rgb[MovedStatics.mixLightnessSigned(overlayMinimapColour, 96)];
548554
}
549-
scene.addTile(_plane, x, y, shape, rotation, textureId, vertexHeightSW, vertexHeightSE, vertexHeightNE, vertexHeightNW, mixLightness(hslBitsetOriginal, lightIntensitySW), mixLightness(hslBitsetOriginal, lightIntensitySE), mixLightness(hslBitsetOriginal, lightIntensityNE), mixLightness(hslBitsetOriginal, lightIntensityNW), MovedStatics.mixLightnessSigned(hslBitset, lightIntensitySW), MovedStatics.mixLightnessSigned(hslBitset, lightIntensitySE), MovedStatics.mixLightnessSigned(hslBitset, lightIntensityNE), MovedStatics.mixLightnessSigned(hslBitset, lightIntensityNW), underlayMinimapColour, rgb);
555+
this.scene.addTile(_plane, x, y, shape, rotation, textureId, vertexHeightSW, vertexHeightSE, vertexHeightNE, vertexHeightNW, mixLightness(hslBitsetOriginal, lightIntensitySW), mixLightness(hslBitsetOriginal, lightIntensitySE), mixLightness(hslBitsetOriginal, lightIntensityNE), mixLightness(hslBitsetOriginal, lightIntensityNW), MovedStatics.mixLightnessSigned(hslBitset, lightIntensitySW), MovedStatics.mixLightnessSigned(hslBitset, lightIntensitySE), MovedStatics.mixLightnessSigned(hslBitset, lightIntensityNE), MovedStatics.mixLightnessSigned(hslBitset, lightIntensityNW), underlayMinimapColour, rgb);
550556
} else
551-
scene.addTile(_plane, x, y, 0, 0, -1, vertexHeightSW, vertexHeightSE, vertexHeightNE, vertexHeightNW, mixLightness(hslBitsetOriginal, lightIntensitySW), mixLightness(hslBitsetOriginal, lightIntensitySE), mixLightness(hslBitsetOriginal, lightIntensityNE), mixLightness(hslBitsetOriginal, lightIntensityNW), 0, 0, 0, 0, underlayMinimapColour, 0);
557+
this.scene.addTile(_plane, x, y, 0, 0, -1, vertexHeightSW, vertexHeightSE, vertexHeightNE, vertexHeightNW, mixLightness(hslBitsetOriginal, lightIntensitySW), mixLightness(hslBitsetOriginal, lightIntensitySE), mixLightness(hslBitsetOriginal, lightIntensityNE), mixLightness(hslBitsetOriginal, lightIntensityNW), 0, 0, 0, 0, underlayMinimapColour, 0);
552558
}
553559
}
554560
}
555561
}
556562
}
557563
for(int i_56_ = 1; i_56_ < 103; i_56_++) {
558564
for(int i_57_ = 1; i_57_ < 103; i_57_++)
559-
scene.setDrawLevel(_plane, i_57_, i_56_, MovedStatics.getVisibilityPlaneFor(_plane, i_56_, 0, i_57_));
565+
this.scene.setDrawLevel(_plane, i_57_, i_56_, MovedStatics.getVisibilityPlaneFor(_plane, i_56_, 0, i_57_));
560566
}
561567
tile_underlayids[_plane] = null;
562568
tile_overlayids[_plane] = null;
563569
tile_underlay_path[_plane] = null;
564570
tile_overlay_rotation[_plane] = null;
565571
tileShadowIntensity[_plane] = null;
566572
}
567-
scene.buildModels(-50, -10, -50);
573+
this.scene.buildModels(-50, -10, -50);
568574
for(int i = 0; i < 104; i++) {
569575
for(int i_58_ = 0; i_58_ < 104; i_58_++) {
570576
if((MovedStatics.tile_flags[1][i][i_58_] & 0x2) == 2)
571-
scene.setTileBridge(i, i_58_);
577+
this.scene.setTileBridge(i, i_58_);
572578
}
573579
}
574580
int renderRule1 = 1;
@@ -613,7 +619,7 @@ else if(s > 255)
613619
int i_72_ = 240;
614620
int i_73_ = -i_72_ + tile_height[i_68_][x][i_65_];
615621
int i_74_ = tile_height[i_67_][x][i_65_];
616-
Game.currentScene.createOccluder(plane, 1, 128 * x, 128 * x, 128 * i_65_, 128 + 128 * i_66_, i_73_, i_74_);
622+
this.scene.createOccluder(plane, 1, 128 * x, 128 * x, 128 * i_65_, 128 + 128 * i_66_, i_73_, i_74_);
617623
for(int i_75_ = i_67_; i_75_ <= i_68_; i_75_++) {
618624
for(int i_76_ = i_65_; i_76_ <= i_66_; i_76_++)
619625
tileCullingBitsets[i_75_][x][i_76_] = BitUtils.bitWiseAND(tileCullingBitsets[i_75_][x][i_76_], renderRule1 ^ 0xffffffff);
@@ -652,7 +658,7 @@ else if(s > 255)
652658
int lowestOcclusionVertexHeight = tile_height[lowestOcclusionPlane][lowestOcclusionX][y];
653659
int highestOcclusionVertexHeightOffset = 240;
654660
int highestOcclusionVertexHeight = tile_height[highestOcclusionPlane][lowestOcclusionX][y] - highestOcclusionVertexHeightOffset;
655-
Game.currentScene.createOccluder(plane, 2, 128 * lowestOcclusionX, 128 * highestOcclusionX + 128, 128 * y, y * 128, highestOcclusionVertexHeight, lowestOcclusionVertexHeight);
661+
this.scene.createOccluder(plane, 2, 128 * lowestOcclusionX, 128 * highestOcclusionX + 128, 128 * y, y * 128, highestOcclusionVertexHeight, lowestOcclusionVertexHeight);
656662
for(int occludedPlane = lowestOcclusionPlane; highestOcclusionPlane >= occludedPlane; occludedPlane++) {
657663
for(int occludedX = lowestOcclusionX; occludedX <= highestOcclusionX; occludedX++)
658664
tileCullingBitsets[occludedPlane][occludedX][y] = BitUtils.bitWiseAND(tileCullingBitsets[occludedPlane][occludedX][y], i_59_ ^ 0xffffffff);
@@ -688,7 +694,7 @@ else if(s > 255)
688694
}
689695
if((-i_89_ + i_90_ + 1) * (1 + i_92_ - i_91_) >= 4) {
690696
int i_95_ = tile_height[_plane][i_89_][i_91_];
691-
Game.currentScene.createOccluder(plane, 4, i_89_ * 128, i_90_ * 128 + 128, 128 * i_91_, i_92_ * 128 + 128, i_95_, i_95_);
697+
this.scene.createOccluder(plane, 4, i_89_ * 128, i_90_ * 128 + 128, 128 * i_91_, i_92_ * 128 + 128, i_95_, i_95_);
692698
for(int i_96_ = i_89_; i_96_ <= i_90_; i_96_++) {
693699
for(int i_97_ = i_91_; i_92_ >= i_97_; i_97_++)
694700
tileCullingBitsets[_plane][i_96_][i_97_] = BitUtils.bitWiseAND(tileCullingBitsets[_plane][i_96_][i_97_], i_60_ ^ 0xffffffff);
@@ -770,7 +776,7 @@ private void method922(int x, int arg1, Buffer fileData, int y, int regionY, int
770776
int opcode = fileData.getUnsignedByte();
771777
if(opcode == 0) {
772778
if(level == 0) {
773-
tile_height[0][x][y] = -method888(regionX + x + 932731, regionY + 556238 + y) * 8;
779+
tile_height[0][x][y] = -getPerlinVertexHeight(regionX + x + 932731, regionY + 556238 + y) * 8;
774780
} else {
775781
tile_height[level][x][y] = -240 + tile_height[level + -1][x][y];
776782
}
@@ -811,8 +817,7 @@ private void method922(int x, int arg1, Buffer fileData, int y, int regionY, int
811817
}
812818
}
813819

814-
public static void constructMapRegion(boolean generatedMap) {
815-
820+
public void constructMapRegion(boolean generatedMap) {
816821
loadGeneratedMap = generatedMap;
817822
if(loadGeneratedMap) {
818823
int chunkLocalY = IncomingPackets.incomingPacketBuffer.getUnsignedShortBE();
@@ -936,7 +941,7 @@ else if(lightness > 126)
936941
return lightness + (hsl & 0xff80);
937942
}
938943

939-
private void loadObjectBlock(int block_x, Scene scene, CollisionMap[] collisionMaps, byte[] block_data, int block_z) {
944+
private void loadObjectBlock(int block_x, CollisionMap[] collisionMaps, byte[] block_data, int block_z) {
940945
Buffer buffer = new Buffer(block_data);
941946
int object_id = -1;
942947
for(; ; ) {
@@ -965,13 +970,13 @@ private void loadObjectBlock(int block_x, Scene scene, CollisionMap[] collisionM
965970
logic_y--;
966971
if(logic_y >= 0)
967972
collisionMap = collisionMaps[logic_y];
968-
addObject(object_id, object_x, object_z, tile_y, object_orientation, object_type, scene, collisionMap);
973+
addObject(object_id, object_x, object_z, tile_y, object_orientation, object_type, collisionMap);
969974
}
970975
}
971976
}
972977
}
973978

974-
public void addObject(int objectId, int localX, int localY, int plane, int face, int type, Scene scene, CollisionMap collisionMap) {
979+
public void addObject(int objectId, int localX, int localY, int plane, int face, int type, CollisionMap collisionMap) {
975980
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)) {
976981
if(lowestPlane > plane)
977982
lowestPlane = plane;
@@ -1238,7 +1243,7 @@ else if(face == 3)
12381243

12391244
}
12401245

1241-
public static boolean method840(byte[] arg1, int arg2, int arg3) {
1246+
private boolean method840(byte[] arg1, int arg2, int arg3) {
12421247
boolean bool = true;
12431248
Buffer class40_sub1 = new Buffer(arg1);
12441249
int i = -1;
@@ -1435,7 +1440,7 @@ public static void method789(int chunkLocalX, int chunkY, int chunkX, int chunkL
14351440
}
14361441
}
14371442

1438-
public static int method888(int x, int y) {
1443+
private static int getPerlinVertexHeight(int x, int y) {
14391444
int vertexHeight = -128 + perlinNoise(x + 45365, 91923 + y, 4) - (-(perlinNoise(x + 10294, 37821 + y, 2) - 128 >> 1) + -(-128 + perlinNoise(x, y, 1) >> 2));
14401445
vertexHeight = 35 + (int) (0.3 * (double) vertexHeight);
14411446

@@ -1448,21 +1453,21 @@ public static int method888(int x, int y) {
14481453
return vertexHeight;
14491454
}
14501455

1451-
public static int interpolateForPerlin(int arg0, int arg1, int arg2, boolean arg3, int arg4) {
1456+
private static int interpolateForPerlin(int arg0, int arg1, int arg2, boolean arg3, int arg4) {
14521457
if (!arg3)
14531458
return -109;
14541459
int i = 65536 + -Rasterizer3D.cosinetable[1024 * arg4 / arg1] >> 1;
14551460
return ((65536 + -i) * arg0 >> 16) + (arg2 * i >> 16);
14561461
}
14571462

1458-
public static int randomNoiseWeightedSum(int arg1, int arg2) {
1463+
private static int randomNoiseWeightedSum(int arg1, int arg2) {
14591464
int i = randomNoise(-1 + arg1, -1 + arg2) + randomNoise(1 + arg1, arg2 - 1) + randomNoise(-1 + arg1, 1 + arg2) + randomNoise(1 + arg1, arg2 + 1);
14601465
int i_126_ = randomNoise(arg1 - 1, arg2) + randomNoise(arg1 + 1, arg2) - (-randomNoise(arg1, arg2 - 1) + -randomNoise(arg1, 1 + arg2));
14611466
int i_127_ = randomNoise(arg1, arg2);
14621467
return i / 16 - (-(i_126_ / 8) - i_127_ / 4);
14631468
}
14641469

1465-
public static int perlinNoise(int x, int y, int scale) {
1470+
private static int perlinNoise(int x, int y, int scale) {
14661471
int muX = x & -1 + scale;
14671472
int scaledY = y / scale;
14681473
int muY = scale - 1 & y;
@@ -1476,7 +1481,7 @@ public static int perlinNoise(int x, int y, int scale) {
14761481
return interpolateForPerlin(i1, scale, i2, true, muY);
14771482
}
14781483

1479-
public static int randomNoise(int x, int y) {
1484+
private static int randomNoise(int x, int y) {
14801485
int i = 57 * y + x;
14811486
i ^= i << 13;
14821487
int i_2_ = 1376312589 + (i * i * 15731 + 789221) * i & 0x7fffffff;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public void remove(InteractiveObject entity) {
713713
}
714714
}
715715

716-
public void renderTile(SceneTile _tile, boolean arg1) {
716+
private void renderTile(SceneTile _tile, boolean arg1) {
717717
tileList.addLast(_tile);
718718
for (; ; ) {
719719
SceneTile groundTile = (SceneTile) tileList.removeFirst();

0 commit comments

Comments
 (0)