api: fix computing scene coord for negative local points

Also add an isInScene method to make testing if a point is in the scene
easier, and use it.
This commit is contained in:
Adam
2021-07-04 21:23:20 -04:00
parent 557921950a
commit 850bf3d333
2 changed files with 27 additions and 18 deletions

View File

@@ -410,6 +410,21 @@ public class Perspective
int plane,
int zOffset)
{
if (!localLocation.isInScene())
{
return null;
}
final byte[][][] tileSettings = client.getTileSettings();
final int sceneX = localLocation.getSceneX();
final int sceneY = localLocation.getSceneY();
int tilePlane = plane;
if (plane < Constants.MAX_Z - 1 && (tileSettings[1][sceneX][sceneY] & TILE_FLAG_BRIDGE) == TILE_FLAG_BRIDGE)
{
tilePlane = plane + 1;
}
final int swX = localLocation.getX() - (sizeX * LOCAL_TILE_SIZE / 2);
final int swY = localLocation.getY() - (sizeY * LOCAL_TILE_SIZE / 2);
@@ -422,22 +437,6 @@ public class Perspective
final int nwX = neX;
final int nwY = swY;
final byte[][][] tileSettings = client.getTileSettings();
final int sceneX = localLocation.getSceneX();
final int sceneY = localLocation.getSceneY();
if (sceneX < 0 || sceneY < 0 || sceneX >= SCENE_SIZE || sceneY >= SCENE_SIZE)
{
return null;
}
int tilePlane = plane;
if (plane < Constants.MAX_Z - 1 && (tileSettings[1][sceneX][sceneY] & TILE_FLAG_BRIDGE) == TILE_FLAG_BRIDGE)
{
tilePlane = plane + 1;
}
final int swHeight = getHeight(client, swX, swY, tilePlane) - zOffset;
final int nwHeight = getHeight(client, nwX, nwY, tilePlane) - zOffset;
final int neHeight = getHeight(client, neX, neY, tilePlane) - zOffset;

View File

@@ -95,6 +95,16 @@ public class LocalPoint
return (int) Math.hypot(getX() - other.getX(), getY() - other.getY());
}
/**
* Test if this point is in the loaded scene, a 104x104 tile area.
* @return
*/
public boolean isInScene()
{
return x >= 0 && x < Perspective.SCENE_SIZE << Perspective.LOCAL_COORD_BITS
&& y >= 0 && y < Perspective.SCENE_SIZE << Perspective.LOCAL_COORD_BITS;
}
/**
* Gets the coordinate at the center of the passed tile.
*
@@ -117,7 +127,7 @@ public class LocalPoint
*/
public int getSceneX()
{
return x >>> Perspective.LOCAL_COORD_BITS;
return x >> Perspective.LOCAL_COORD_BITS;
}
/**
@@ -127,6 +137,6 @@ public class LocalPoint
*/
public int getSceneY()
{
return y >>> Perspective.LOCAL_COORD_BITS;
return y >> Perspective.LOCAL_COORD_BITS;
}
}