Class SceneContext
- java.lang.Object
-
- org.rspeer.game.coord.SceneContext
-
public class SceneContext extends Object
Provides scene-level information and utilities for a specificRSWorldMatrixidentified by its matrix ID.A
CoordSceneis essentially a view of the current scene (or world view) associated with a particular matrix. It exposes:- The scene base coordinate (
getBase()) - The scene size in tiles (
getSize()) - The scene floor/plane (
getFloorLevel()) - Instance/dynamic scene detection (
isInstance()) - Floor height sampling at a fine-grained coordinate (
getFloorHeight(CoordFine)) - Access to the scene tile grid (
getMapSquares())
- The scene base coordinate (
-
-
Constructor Summary
Constructors Constructor Description SceneContext(int matrixId)SceneContext(RSWorldMatrix matrix)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CoordgetBase()Returns the world-space base coordinate of this scene.intgetCollisionFlag(CoordFine fine)Retrieves the collision flag for the tile referenced by the givenCoordFine.intgetCollisionFlag(CoordGrid grid)intgetFloorHeight(CoordFine fine)Samples the floor height at the given fine coordinate within this scene, performing bilinear interpolation between the four surrounding height samples.intgetFloorLevel()Returns the current floor/plane associated with this scene.RSTile[][][]getMapSquares()Returns the 3D array of scene tiles for this matrix.DimensiongetSize()Returns the size of the scene in tiles.booleanisInFieldOfView(SceneNode source, SceneNode target)Determines whether two scene entities (players, NPCs, objects) have line-of-sight between their tile positions on the same plane.booleanisInFieldOfView(SceneNode source, SceneNode target, CollisionFlagOverride override)Determines whether two scene entities (players, NPCs, objects) have line-of-sight between them, honoring collision flags and optional overrides.booleanisInFieldOfView(CoordArea srcArea, CoordArea dstArea)Determines whether two rectangular areas have line-of-sight between them, using the bottom-left coordinate of each area as the reference point.booleanisInFieldOfView(CoordArea srcArea, CoordArea dstArea, CollisionFlagOverride override)Determines whether any point insidesrcAreahas a clear line-of-sight to any point insidedstArea, using collision flags to test for blocking.booleanisInstance()Indicates whether the current scene is dynamic (instanced).booleanisLoaded(CoordFine fine)Checks whether the tile referenced by the givenCoordFineis currently within the loaded scene bounds for this matrix.booleanisLoaded(CoordGrid grid)
-
-
-
Constructor Detail
-
SceneContext
public SceneContext(int matrixId)
-
SceneContext
public SceneContext(RSWorldMatrix matrix)
-
-
Method Detail
-
getBase
public Coord getBase()
Returns the world-space base coordinate of this scene.The base coordinate corresponds to the origin of the scene grid in world coordinates (typically the south-west corner).
-
getSize
public Dimension getSize()
Returns the size of the scene in tiles.For the default OSRS scene, this is usually
104 x 104tiles.- Returns:
- a
Dimensionwherewidthis the X-size andheightis the Y-size of the scene in tiles. If the matrix is unavailable, a default size of104x104is returned.
-
isLoaded
public boolean isLoaded(CoordFine fine)
Checks whether the tile referenced by the givenCoordFineis currently within the loaded scene bounds for this matrix.A fine coordinate is first converted to its corresponding tile coordinate by dividing by
CoordFine.UNITS_PER_SQUARE. The resulting grid coordinates are validated against the scene size.This method does not inspect collision maps, render rules, or heightmap data; it only verifies that the tile lies within the active scene (typically a
104x104region).- Parameters:
fine- the fine-grained coordinate to test- Returns:
trueif the tile containing the fine coordinate is inside the loaded scene;falseotherwise
-
isLoaded
public boolean isLoaded(CoordGrid grid)
-
getCollisionFlag
public int getCollisionFlag(CoordFine fine)
Retrieves the collision flag for the tile referenced by the givenCoordFine.The fine coordinate is converted into tile-space by dividing its X and Y by
CoordFine.UNITS_PER_SQUARE. The method then resolves theRSCollisionMapfor the coordinate’s floor level and returns the corresponding collision value.Special return values:
-1— the tile is not loaded or the scene/matrix is unavailable0— the collision map exists but contains no data for the tile- any other value — the raw collision flag for that tile
- Parameters:
fine- the fine-grained coordinate whose collision flag should be retrieved- Returns:
- the collision flag for that tile,
-1if unloaded, or0if no data exists - See Also:
Collision flags are engine-defined bitmasks that represent movement blocking, projectile blocking, interactable boundaries, etc.
-
getCollisionFlag
public int getCollisionFlag(CoordGrid grid)
-
getFloorLevel
public int getFloorLevel()
Returns the current floor/plane associated with this scene.- Returns:
- the floor level (0–3), or
0if the matrix is unavailable
-
isInstance
public boolean isInstance()
Indicates whether the current scene is dynamic (instanced).This delegates to the static client flag and is effectively global, but is exposed here for convenience and future-proof purposes.
- Returns:
trueif the scene is dynamic/instanced;falseotherwise
-
getFloorHeight
public int getFloorHeight(CoordFine fine)
Samples the floor height at the given fine coordinate within this scene, performing bilinear interpolation between the four surrounding height samples.This method:
- Converts fine-space coordinates into scene tile indices
- Checks bounds against the scene size
- Applies bridge render rules (if present)
- Interpolates height across the tile using a 128x128 sub-tile grid
- Parameters:
fine- the fine coordinate (matrix-relative) used to sample floor height- Returns:
- the interpolated floor height at the given coordinate, or
0if out of bounds or required data is unavailable
-
getMapSquares
public RSTile[][][] getMapSquares()
Returns the 3D array of scene tiles for this matrix.The returned array is typically indexed as
tiles[plane][x][y].- Returns:
- a 3D array of
RSTilerepresenting the scene, or an empty array if the matrix or scene graph is unavailable
-
isInFieldOfView
public boolean isInFieldOfView(CoordArea srcArea, CoordArea dstArea)
Determines whether two rectangular areas have line-of-sight between them, using the bottom-left coordinate of each area as the reference point.This is equivalent to calling
isInFieldOfView(CoordArea, CoordArea, CollisionFlagOverride)withCollisionFlagOverride.identity().- Parameters:
srcArea- the source rectangular areadstArea- the destination rectangular area- Returns:
trueif a clear line-of-sight exists between the areas
-
isInFieldOfView
public boolean isInFieldOfView(CoordArea srcArea, CoordArea dstArea, CollisionFlagOverride override)
Determines whether any point insidesrcAreahas a clear line-of-sight to any point insidedstArea, using collision flags to test for blocking.This method reduces each area to the most relevant point for LOS checking:
- If the destination is entirely left of the source, the source's left-most X is used; otherwise the closest interior X.
- The same rule applies for Y and for computing the destination coordinate.
isInFieldOfView(SceneNode, SceneNode, CollisionFlagOverride).- Parameters:
srcArea- the source areadstArea- the destination areaoverride- a collision-flag override, allowing dynamic masking of collision flags in the world- Returns:
trueif the areas have mutual line-of-sight; otherwisefalse
-
isInFieldOfView
public boolean isInFieldOfView(SceneNode source, SceneNode target)
Determines whether two scene entities (players, NPCs, objects) have line-of-sight between their tile positions on the same plane.Uses the default identity-based
override.- Parameters:
source- the entity initiating visiontarget- the target entity- Returns:
trueif the entities have line-of-sight;falseotherwise
-
isInFieldOfView
public boolean isInFieldOfView(SceneNode source, SceneNode target, CollisionFlagOverride override)
Determines whether two scene entities (players, NPCs, objects) have line-of-sight between them, honoring collision flags and optional overrides.Floor & load checks:
Line-of-sight requires:- Both entities are on the same floor.
- Both coordinates are loaded in the local scene.
- The world matrix provides collision data.
Tile resolution:
The algorithm resolves line-of-sight at tile resolution, not fine-coordinate resolution. It converts the fine coordinate into grid indices and then walks tiles along the line joining the two points.Traversal method:
The algorithm uses a Bresenham-like incremental stepping:- If |dx| > |dy|, X is the major axis.
- If |dy| > |dx|, Y is the major axis.
- If |dx| == |dy|, an explicit diagonal step is used (a correctness improvement over RuneLite's version).
Collision handling:
At each tile step, the relevant collision flags are determined:xFlagsblock movement horizontallyyFlagsblock movement vertically
Return value:
The method returnsfalseas soon as any blocking flag is encountered. If the traversal completes without intersecting blocked tiles, line-of-sight is considered valid.- Parameters:
source- the source entitytarget- the target entityoverride- modifies collision flags for dynamic LOS computation- Returns:
trueif unobstructed line-of-sight exists; otherwisefalse
-
-