Skip to content

Commit 350e07e

Browse files
authored
Merge pull request #185 from runejs/scene-refactor
refactor: more scene and landscape instancing
2 parents fb4e17c + f6d34ae commit 350e07e

File tree

11 files changed

+142
-128
lines changed

11 files changed

+142
-128
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/frame/ScreenController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static void setBounds() {
108108
}
109109

110110

111-
Game.currentScene.precalculateTileVisibility(500, 800, frameMode == ScreenMode.FIXED ? 512 : drawWidth, frameMode == ScreenMode.FIXED ? 334 : drawHeight, is);
111+
Game.currentScene.precalculateTileVisibility(frameMode == ScreenMode.FIXED ? 512 : drawWidth, frameMode == ScreenMode.FIXED ? 334 : drawHeight, 500, 800, is);
112112
Game.gameCanvas.setSize(ScreenController.frameMode == ScreenMode.FIXED ? 512 : ScreenController.drawWidth, ScreenController.frameMode == ScreenMode.FIXED ? 334 : ScreenController.drawHeight);
113113

114114
if (Game.gameStatusCode <= 35 && Game.gameStatusCode >= 30) {

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/Point3d.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
package org.runejs.client.scene;
22

3+
/**
4+
* Represents a 3d point within the scene.
5+
*
6+
* Do not confuse this with the discrete (x/y/plane) tile coordinates. These are 3d coordinates.
7+
*/
38
public class Point3d {
49
public final int x;
510
public final int y;
611
public final int z;
712

13+
/**
14+
* The x coordinate (0-104) of the scene tile at this Point3d.
15+
*/
16+
public final int tileX;
17+
/**
18+
* The y coordinate (0-104) the scene tile at this Point3d.
19+
*/
20+
public final int tileY;
21+
822
public Point3d(int x, int y, int z) {
923
this.x = x;
1024
this.y = y;
1125
this.z = z;
26+
27+
this.tileX = x / 128;
28+
this.tileY = y / 128;
1229
}
1330

1431
public Point3d add(Point3d other) {
@@ -26,4 +43,6 @@ public Point3d addY(int y) {
2643
public Point3d addZ(int z) {
2744
return new Point3d(this.x, this.y, this.z + z );
2845
}
46+
47+
// TODO (jkm) make a `Point3d fromTile(x, y)`
2948
}

0 commit comments

Comments
 (0)