Skip to content

Commit 133a41e

Browse files
committed
refactor: add tileX and tileY to Point3d, use in Scene
1 parent 4bb4fe3 commit 133a41e

File tree

2 files changed

+66
-51
lines changed

2 files changed

+66
-51
lines changed

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
}

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

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ public class Scene {
9696

9797
private InteractiveObject[] interactiveObjects = new InteractiveObject[100];
9898
private LinkedList tileList = new LinkedList();
99-
private int currentCameraTileY;
100-
private int currentCameraTileX;
10199

102100
private Camera currentCamera;
103101
private CameraTileVisibility tileVisibilityInfo;
@@ -292,21 +290,19 @@ public void render(Camera camera, int plane) {
292290

293291
cycle++;
294292
currentTileVisibilityMap = tileVisibilityInfo.visibilityInfo[(pitch - 128) / 32][yaw / 64];
295-
currentCameraTileX = cameraPos.x / 128;
296-
currentCameraTileY = cameraPos.y / 128;
297-
drawFromTileX = currentCameraTileX - TILE_DRAW_DISTANCE;
293+
drawFromTileX = currentCamera.getPosition().tileX - TILE_DRAW_DISTANCE;
298294
if (drawFromTileX < 0) {
299295
drawFromTileX = 0;
300296
}
301-
drawFromTileY = currentCameraTileY - TILE_DRAW_DISTANCE;
297+
drawFromTileY = currentCamera.getPosition().tileY - TILE_DRAW_DISTANCE;
302298
if (drawFromTileY < 0) {
303299
drawFromTileY = 0;
304300
}
305-
drawToTileX = currentCameraTileX + TILE_DRAW_DISTANCE;
301+
drawToTileX = currentCamera.getPosition().tileX + TILE_DRAW_DISTANCE;
306302
if (drawToTileX > mapSizeX) {
307303
drawToTileX = mapSizeX;
308304
}
309-
drawToTileY = currentCameraTileY + TILE_DRAW_DISTANCE;
305+
drawToTileY = currentCamera.getPosition().tileY + TILE_DRAW_DISTANCE;
310306
if (drawToTileY > mapSizeY) {
311307
drawToTileY = mapSizeY;
312308
}
@@ -318,7 +314,7 @@ public void render(Camera camera, int plane) {
318314
for (int y = drawFromTileY; y < drawToTileY; y++) {
319315
SceneTile sceneTile = sceneTiles[x][y];
320316
if (sceneTile != null) {
321-
if (sceneTile.drawLevel > plane || !currentTileVisibilityMap[x - currentCameraTileX + TILE_DRAW_DISTANCE][y - currentCameraTileY + TILE_DRAW_DISTANCE] && heightMap[z][x][y] - cameraPosZ < 70000) {
317+
if (sceneTile.drawLevel > plane || !currentTileVisibilityMap[x - currentCamera.getPosition().tileX + TILE_DRAW_DISTANCE][y - currentCamera.getPosition().tileY + TILE_DRAW_DISTANCE] && heightMap[z][x][y] - cameraPosZ < 70000) {
322318
sceneTile.draw = false;
323319
sceneTile.visible = false;
324320
sceneTile.wallCullDirection = 0;
@@ -335,12 +331,12 @@ public void render(Camera camera, int plane) {
335331
for (int i = this.plane; i < mapSizeZ; i++) {
336332
SceneTile[][] sceneTiles = tileArray[i];
337333
for (int i_25_ = -TILE_DRAW_DISTANCE; i_25_ <= 0; i_25_++) {
338-
int i_26_ = currentCameraTileX + i_25_;
339-
int i_27_ = currentCameraTileX - i_25_;
334+
int i_26_ = currentCamera.getPosition().tileX + i_25_;
335+
int i_27_ = currentCamera.getPosition().tileX - i_25_;
340336
if (i_26_ >= drawFromTileX || i_27_ < drawToTileX) {
341337
for (int i_28_ = -TILE_DRAW_DISTANCE; i_28_ <= 0; i_28_++) {
342-
int i_29_ = currentCameraTileY + i_28_;
343-
int i_30_ = currentCameraTileY - i_28_;
338+
int i_29_ = currentCamera.getPosition().tileY + i_28_;
339+
int i_30_ = currentCamera.getPosition().tileY - i_28_;
344340
if (i_26_ >= drawFromTileX) {
345341
if (i_29_ >= drawFromTileY) {
346342
SceneTile sceneTile = sceneTiles[i_26_][i_29_];
@@ -380,12 +376,12 @@ public void render(Camera camera, int plane) {
380376
for (int i = this.plane; i < mapSizeZ; i++) {
381377
SceneTile[][] sceneTiles = tileArray[i];
382378
for (int i_31_ = -TILE_DRAW_DISTANCE; i_31_ <= 0; i_31_++) {
383-
int i_32_ = currentCameraTileX + i_31_;
384-
int i_33_ = currentCameraTileX - i_31_;
379+
int i_32_ = currentCamera.getPosition().tileX + i_31_;
380+
int i_33_ = currentCamera.getPosition().tileX - i_31_;
385381
if (i_32_ >= drawFromTileX || i_33_ < drawToTileX) {
386382
for (int i_34_ = -TILE_DRAW_DISTANCE; i_34_ <= 0; i_34_++) {
387-
int i_35_ = currentCameraTileY + i_34_;
388-
int i_36_ = currentCameraTileY - i_34_;
383+
int i_35_ = currentCamera.getPosition().tileY + i_34_;
384+
int i_36_ = currentCamera.getPosition().tileY - i_34_;
389385
if (i_32_ >= drawFromTileX) {
390386
if (i_35_ >= drawFromTileY) {
391387
SceneTile sceneTile = sceneTiles[i_32_][i_35_];
@@ -736,25 +732,25 @@ public void renderTile(SceneTile _tile, boolean arg1) {
736732
continue;
737733
}
738734
}
739-
if (x <= currentCameraTileX && x > drawFromTileX) {
735+
if (x <= currentCamera.getPosition().tileX && x > drawFromTileX) {
740736
SceneTile tile = sceneTiles[x - 1][y];
741737
if (tile != null && tile.visible && (tile.draw || (groundTile.interactiveObjectsSizeOR & 0x1) == 0)) {
742738
continue;
743739
}
744740
}
745-
if (x >= currentCameraTileX && x < drawToTileX - 1) {
741+
if (x >= currentCamera.getPosition().tileX && x < drawToTileX - 1) {
746742
SceneTile tile = sceneTiles[x + 1][y];
747743
if (tile != null && tile.visible && (tile.draw || (groundTile.interactiveObjectsSizeOR & 0x4) == 0)) {
748744
continue;
749745
}
750746
}
751-
if (y <= currentCameraTileY && y > drawFromTileY) {
747+
if (y <= currentCamera.getPosition().tileY && y > drawFromTileY) {
752748
SceneTile tile = sceneTiles[x][y - 1];
753749
if (tile != null && tile.visible && (tile.draw || (groundTile.interactiveObjectsSizeOR & 0x8) == 0)) {
754750
continue;
755751
}
756752
}
757-
if (y >= currentCameraTileY && y < drawToTileY - 1) {
753+
if (y >= currentCamera.getPosition().tileY && y < drawToTileY - 1) {
758754
SceneTile tile = sceneTiles[x][y + 1];
759755
if (tile != null && tile.visible && (tile.draw || (groundTile.interactiveObjectsSizeOR & 0x2) == 0)) {
760756
continue;
@@ -803,14 +799,14 @@ public void renderTile(SceneTile _tile, boolean arg1) {
803799
Wall wall = groundTile.wall;
804800
WallDecoration wallDecoration = groundTile.wallDecoration;
805801
if (wall != null || wallDecoration != null) {
806-
if (currentCameraTileX == x) {
802+
if (currentCamera.getPosition().tileX == x) {
807803
i_86_++;
808-
} else if (currentCameraTileX < x) {
804+
} else if (currentCamera.getPosition().tileX < x) {
809805
i_86_ += 2;
810806
}
811-
if (currentCameraTileY == y) {
807+
if (currentCamera.getPosition().tileY == y) {
812808
i_86_ += 3;
813-
} else if (currentCameraTileY > y) {
809+
} else if (currentCamera.getPosition().tileY > y) {
814810
i_86_ += 6;
815811
}
816812
i_87_ = FRONT_WALL_TYPES[i_86_];
@@ -897,25 +893,25 @@ public void renderTile(SceneTile _tile, boolean arg1) {
897893
}
898894
int i_98_ = groundTile.interactiveObjectsSizeOR;
899895
if (i_98_ != 0) {
900-
if (x < currentCameraTileX && (i_98_ & 0x4) != 0) {
896+
if (x < currentCamera.getPosition().tileX && (i_98_ & 0x4) != 0) {
901897
SceneTile sceneTile_99_ = sceneTiles[x + 1][y];
902898
if (sceneTile_99_ != null && sceneTile_99_.visible) {
903899
tileList.addLast(sceneTile_99_);
904900
}
905901
}
906-
if (y < currentCameraTileY && (i_98_ & 0x2) != 0) {
902+
if (y < currentCamera.getPosition().tileY && (i_98_ & 0x2) != 0) {
907903
SceneTile sceneTile_100_ = sceneTiles[x][y + 1];
908904
if (sceneTile_100_ != null && sceneTile_100_.visible) {
909905
tileList.addLast(sceneTile_100_);
910906
}
911907
}
912-
if (x > currentCameraTileX && (i_98_ & 0x1) != 0) {
908+
if (x > currentCamera.getPosition().tileX && (i_98_ & 0x1) != 0) {
913909
SceneTile sceneTile_101_ = sceneTiles[x - 1][y];
914910
if (sceneTile_101_ != null && sceneTile_101_.visible) {
915911
tileList.addLast(sceneTile_101_);
916912
}
917913
}
918-
if (y > currentCameraTileY && (i_98_ & 0x8) != 0) {
914+
if (y > currentCamera.getPosition().tileY && (i_98_ & 0x8) != 0) {
919915
SceneTile tile = sceneTiles[x][y - 1];
920916
if (tile != null && tile.visible) {
921917
tileList.addLast(tile);
@@ -977,13 +973,13 @@ public void renderTile(SceneTile _tile, boolean arg1) {
977973
}
978974
}
979975
interactiveObjects[i_105_++] = entity;
980-
int i_111_ = currentCameraTileX - entity.tileLeft;
981-
int i_112_ = entity.tileRight - currentCameraTileX;
976+
int i_111_ = currentCamera.getPosition().tileX - entity.tileLeft;
977+
int i_112_ = entity.tileRight - currentCamera.getPosition().tileX;
982978
if (i_112_ > i_111_) {
983979
i_111_ = i_112_;
984980
}
985-
int i_113_ = currentCameraTileY - entity.tileTop;
986-
int i_114_ = entity.tileBottom - currentCameraTileY;
981+
int i_113_ = currentCamera.getPosition().tileY - entity.tileTop;
982+
int i_114_ = entity.tileBottom - currentCamera.getPosition().tileY;
987983
if (i_114_ > i_113_) {
988984
entity.anInt491 = i_111_ + i_114_;
989985
} else {
@@ -1039,25 +1035,25 @@ public void renderTile(SceneTile _tile, boolean arg1) {
10391035
}
10401036
if (groundTile.visible) {
10411037
if (groundTile.wallCullDirection == 0) {
1042-
if (x <= currentCameraTileX && x > drawFromTileX) {
1038+
if (x <= currentCamera.getPosition().tileX && x > drawFromTileX) {
10431039
SceneTile sceneTile_125_ = sceneTiles[x - 1][y];
10441040
if (sceneTile_125_ != null && sceneTile_125_.visible) {
10451041
continue;
10461042
}
10471043
}
1048-
if (x >= currentCameraTileX && x < drawToTileX - 1) {
1044+
if (x >= currentCamera.getPosition().tileX && x < drawToTileX - 1) {
10491045
SceneTile sceneTile_126_ = sceneTiles[x + 1][y];
10501046
if (sceneTile_126_ != null && sceneTile_126_.visible) {
10511047
continue;
10521048
}
10531049
}
1054-
if (y <= currentCameraTileY && y > drawFromTileY) {
1050+
if (y <= currentCamera.getPosition().tileY && y > drawFromTileY) {
10551051
SceneTile sceneTile_127_ = sceneTiles[x][y - 1];
10561052
if (sceneTile_127_ != null && sceneTile_127_.visible) {
10571053
continue;
10581054
}
10591055
}
1060-
if (y >= currentCameraTileY && y < drawToTileY - 1) {
1056+
if (y >= currentCamera.getPosition().tileY && y < drawToTileY - 1) {
10611057
SceneTile sceneTile_128_ = sceneTiles[x][y + 1];
10621058
if (sceneTile_128_ != null && sceneTile_128_.visible) {
10631059
continue;
@@ -1127,25 +1123,25 @@ public void renderTile(SceneTile _tile, boolean arg1) {
11271123
tileList.addLast(sceneTile_139_);
11281124
}
11291125
}
1130-
if (x < currentCameraTileX) {
1126+
if (x < currentCamera.getPosition().tileX) {
11311127
SceneTile sceneTile_140_ = sceneTiles[x + 1][y];
11321128
if (sceneTile_140_ != null && sceneTile_140_.visible) {
11331129
tileList.addLast(sceneTile_140_);
11341130
}
11351131
}
1136-
if (y < currentCameraTileY) {
1132+
if (y < currentCamera.getPosition().tileY) {
11371133
SceneTile sceneTile_141_ = sceneTiles[x][y + 1];
11381134
if (sceneTile_141_ != null && sceneTile_141_.visible) {
11391135
tileList.addLast(sceneTile_141_);
11401136
}
11411137
}
1142-
if (x > currentCameraTileX) {
1138+
if (x > currentCamera.getPosition().tileX) {
11431139
SceneTile sceneTile_142_ = sceneTiles[x - 1][y];
11441140
if (sceneTile_142_ != null && sceneTile_142_.visible) {
11451141
tileList.addLast(sceneTile_142_);
11461142
}
11471143
}
1148-
if (y > currentCameraTileY) {
1144+
if (y > currentCamera.getPosition().tileY) {
11491145
SceneTile sceneTile_143_ = sceneTiles[x][y - 1];
11501146
if (sceneTile_143_ != null && sceneTile_143_.visible) {
11511147
tileList.addLast(sceneTile_143_);
@@ -1427,13 +1423,13 @@ public void processCulling(int plane) {
14271423
for (int i_172_ = 0; i_172_ < i; i_172_++) {
14281424
SceneCluster sceneCluster = sceneClusters[i_172_];
14291425
if (sceneCluster.searchMask == 1) {
1430-
int i_173_ = sceneCluster.tileStartX - currentCameraTileX + TILE_DRAW_DISTANCE;
1426+
int i_173_ = sceneCluster.tileStartX - currentCamera.getPosition().tileX + TILE_DRAW_DISTANCE;
14311427
if (i_173_ >= 0 && i_173_ <= 50) {
1432-
int i_174_ = sceneCluster.tileStartY - currentCameraTileY + TILE_DRAW_DISTANCE;
1428+
int i_174_ = sceneCluster.tileStartY - currentCamera.getPosition().tileY + TILE_DRAW_DISTANCE;
14331429
if (i_174_ < 0) {
14341430
i_174_ = 0;
14351431
}
1436-
int i_175_ = sceneCluster.tileEndY - currentCameraTileY + TILE_DRAW_DISTANCE;
1432+
int i_175_ = sceneCluster.tileEndY - currentCamera.getPosition().tileY + TILE_DRAW_DISTANCE;
14371433
if (i_175_ > 50) {
14381434
i_175_ = 50;
14391435
}
@@ -1463,13 +1459,13 @@ public void processCulling(int plane) {
14631459
}
14641460
}
14651461
} else if (sceneCluster.searchMask == 2) {
1466-
int i_177_ = sceneCluster.tileStartY - currentCameraTileY + TILE_DRAW_DISTANCE;
1462+
int i_177_ = sceneCluster.tileStartY - currentCamera.getPosition().tileY + TILE_DRAW_DISTANCE;
14671463
if (i_177_ >= 0 && i_177_ <= 50) {
1468-
int i_178_ = sceneCluster.tileStartX - currentCameraTileX + TILE_DRAW_DISTANCE;
1464+
int i_178_ = sceneCluster.tileStartX - currentCamera.getPosition().tileX + TILE_DRAW_DISTANCE;
14691465
if (i_178_ < 0) {
14701466
i_178_ = 0;
14711467
}
1472-
int i_179_ = sceneCluster.tileEndX - currentCameraTileX + TILE_DRAW_DISTANCE;
1468+
int i_179_ = sceneCluster.tileEndX - currentCamera.getPosition().tileX + TILE_DRAW_DISTANCE;
14731469
if (i_179_ > 50) {
14741470
i_179_ = 50;
14751471
}
@@ -1501,20 +1497,20 @@ public void processCulling(int plane) {
15011497
} else if (sceneCluster.searchMask == 4) {
15021498
int i_181_ = sceneCluster.worldEndZ - currentCamera.getPosition().z;
15031499
if (i_181_ > 128) {
1504-
int i_182_ = sceneCluster.tileStartY - currentCameraTileY + TILE_DRAW_DISTANCE;
1500+
int i_182_ = sceneCluster.tileStartY - currentCamera.getPosition().tileY + TILE_DRAW_DISTANCE;
15051501
if (i_182_ < 0) {
15061502
i_182_ = 0;
15071503
}
1508-
int i_183_ = sceneCluster.tileEndY - currentCameraTileY + TILE_DRAW_DISTANCE;
1504+
int i_183_ = sceneCluster.tileEndY - currentCamera.getPosition().tileY + TILE_DRAW_DISTANCE;
15091505
if (i_183_ > 50) {
15101506
i_183_ = 50;
15111507
}
15121508
if (i_182_ <= i_183_) {
1513-
int i_184_ = sceneCluster.tileStartX - currentCameraTileX + TILE_DRAW_DISTANCE;
1509+
int i_184_ = sceneCluster.tileStartX - currentCamera.getPosition().tileX + TILE_DRAW_DISTANCE;
15141510
if (i_184_ < 0) {
15151511
i_184_ = 0;
15161512
}
1517-
int i_185_ = sceneCluster.tileEndX - currentCameraTileX + TILE_DRAW_DISTANCE;
1513+
int i_185_ = sceneCluster.tileEndX - currentCamera.getPosition().tileX + TILE_DRAW_DISTANCE;
15181514
if (i_185_ > 50) {
15191515
i_185_ = 50;
15201516
}

0 commit comments

Comments
 (0)