Class SceneContext


  • public class SceneContext
    extends Object
    Provides scene-level information and utilities for a specific RSWorldMatrix identified by its matrix ID.

    A CoordScene is essentially a view of the current scene (or world view) associated with a particular matrix. It exposes:

    • Constructor Detail

      • SceneContext

        public SceneContext​(int matrixId)
    • 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).

        Returns:
        the base Coord, or Coord.NIL if the matrix is not available
      • getSize

        public Dimension getSize()
        Returns the size of the scene in tiles.

        For the default OSRS scene, this is usually 104 x 104 tiles.

        Returns:
        a Dimension where width is the X-size and height is the Y-size of the scene in tiles. If the matrix is unavailable, a default size of 104x104 is returned.
      • isLoaded

        public boolean isLoaded​(CoordFine fine)
        Checks whether the tile referenced by the given CoordFine is 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 104x104 region).

        Parameters:
        fine - the fine-grained coordinate to test
        Returns:
        true if the tile containing the fine coordinate is inside the loaded scene; false otherwise
      • isLoaded

        public boolean isLoaded​(CoordGrid grid)
      • 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 0 if 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:
        true if the scene is dynamic/instanced; false otherwise
      • 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:

        1. Converts fine-space coordinates into scene tile indices
        2. Checks bounds against the scene size
        3. Applies bridge render rules (if present)
        4. 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 0 if 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 RSTile representing the scene, or an empty array if the matrix or scene graph is unavailable
      • isInFieldOfView

        public boolean isInFieldOfView​(CoordArea srcArea,
                                       CoordArea dstArea,
                                       CollisionFlagOverride override)
        Determines whether any point inside srcArea has a clear line-of-sight to any point inside dstArea, 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.
        The chosen pair of points is then passed to isInFieldOfView(SceneNode, SceneNode, CollisionFlagOverride).
        Parameters:
        srcArea - the source area
        dstArea - the destination area
        override - a collision-flag override, allowing dynamic masking of collision flags in the world
        Returns:
        true if the areas have mutual line-of-sight; otherwise false
      • 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 vision
        target - the target entity
        Returns:
        true if the entities have line-of-sight; false otherwise
      • 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:

        • xFlags block movement horizontally
        • yFlags block movement vertically
        CollisionFlagOverride is applied to allow runtime adjustment of flags.

        Return value:
        The method returns false as 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 entity
        target - the target entity
        override - modifies collision flags for dynamic LOS computation
        Returns:
        true if unobstructed line-of-sight exists; otherwise false