Skip to content

Game.Common.QuadTreeBoundsXZ

Assembly:
Game (assembly inferred from file path: Game\Common)

Namespace:
Game.Common

Type:
struct

Base:
Implements: IEquatable, IBounds2

Summary:
Represents an axis-aligned bounding volume oriented to the XZ plane backed by a 3D Bounds3. Stores an associated BoundsMask and a range of LOD (level-of-detail) bytes. Provides utilities to compute 2D center/size (XZ), merge with other bounds, check intersections, and reset to an empty state. Also contains a nested DebugIterator used to test/intersect bounds and draw wireframe gizmos (via GizmoBatcher) for debugging purposes.


Fields

  • public Bounds3 m_Bounds
    Holds the 3D axis-aligned bounds (min/max) for the volume. The Y component is kept but most utilities expose only the XZ components.

  • public BoundsMask m_Mask
    Mask flags describing layers, debug state, walk-through, overrides, etc. Used to categorize/filter bounds in quad-tree queries.

  • public byte m_MinLod
    Minimum LOD index this bounds applies to.

  • public byte m_MaxLod
    Maximum LOD index this bounds applies to.

Nested DebugIterator fields (inside struct DebugIterator):

  • private Bounds3 m_Bounds
    The bounds this debug iterator will use for intersection tests and for drawing a white reference box.

  • private GizmoBatcher m_GizmoBatcher
    GizmoBatcher instance used to draw wireframe cubes for debugging (white/red boxes).

Properties

  • None declared on QuadTreeBoundsXZ itself.

(Interfaces implemented do not introduce publicly visible auto-properties in this definition.)

Constructors

  • public QuadTreeBoundsXZ(Bounds3 bounds)
    Initializes using the provided Bounds3. Sets default BoundsMask to include Debug, NormalLayers, NotOverridden and NotWalkThrough. Sets m_MinLod = 1 and m_MaxLod = 1.

  • public QuadTreeBoundsXZ(Bounds3 bounds, BoundsMask mask, int lod)
    Initializes with specified bounds and mask; sets both m_MinLod and m_MaxLod to the provided lod.

  • public QuadTreeBoundsXZ(Bounds3 bounds, BoundsMask mask, int minLod, int maxLod)
    Initializes with specified bounds, mask and an explicit LOD range.

Nested DebugIterator constructor:

  • public DebugIterator(Bounds3 bounds, GizmoBatcher gizmoBatcher)
    Creates a debug iterator that keeps a reference bounds (m_Bounds) and a GizmoBatcher for drawing debug wire cubes.

Methods

  • public bool Equals(QuadTreeBoundsXZ other)
    Value equality: compares m_Bounds, m_Mask, m_MinLod and m_MaxLod. Uses bitwise & chaining for evaluation.

  • public void Reset()
    Resets bounds and metadata to an "empty/uninitialized" state: sets min to float.MaxValue, max to float.MinValue, mask to 0, m_MinLod to byte.MaxValue and m_MaxLod to 0.

  • public float2 Center()
    Returns the XZ center of m_Bounds: MathUtils.Center(m_Bounds).xz.

  • public float2 Size()
    Returns the XZ size of m_Bounds: MathUtils.Size(m_Bounds).xz.

  • public QuadTreeBoundsXZ Merge(QuadTreeBoundsXZ other)
    Returns a new QuadTreeBoundsXZ that is the union of this and other: merged Bounds3 (bitwise |), combined mask (bitwise |), minLod = min(this.m_MinLod, other.m_MinLod), maxLod = max(this.m_MaxLod, other.m_MaxLod).

  • public bool Intersect(QuadTreeBoundsXZ other)
    Returns whether the two Bounds3 intersect according to MathUtils.Intersect.

Nested DebugIterator methods (TItem : unmanaged, IEquatable):

  • public bool Intersect(QuadTreeBoundsXZ bounds)
    Checks intersection between this iterator's stored m_Bounds and the supplied bounds.m_Bounds using MathUtils.Intersect. If they intersect, draws a white wire cube for bounds via m_GizmoBatcher and returns true.

  • public void Iterate(QuadTreeBoundsXZ bounds, TItem edgeEntity)
    Called during iteration over quad-tree entries. If the supplied bounds intersect the iterator's stored bounds, draws a red wire cube for the supplied bounds via m_GizmoBatcher. The edgeEntity parameter is present to satisfy iterator interface signatures (unused for drawing).

Usage Example

// Example usage of QuadTreeBoundsXZ and DebugIterator in a mod/debug context.

using Unity.Mathematics;
using UnityEngine;
using Colossal; // types like Bounds3, BoundsMask, GizmoBatcher, MathUtils

// simple unmanaged item type for DebugIterator generic requirement
public struct MyItem : IEquatable<MyItem>
{
    public int id;
    public bool Equals(MyItem other) => id == other.id;
}

void Example()
{
    // create some Bounds3 (min/max)
    Bounds3 boundsA = new Bounds3
    {
        min = new float3(0f, 0f, 0f),
        max = new float3(100f, 10f, 100f)
    };

    Bounds3 boundsB = new Bounds3
    {
        min = new float3(50f, 0f, 50f),
        max = new float3(150f, 10f, 150f)
    };

    // create QuadTreeBoundsXZ nodes
    var nodeA = new QuadTreeBoundsXZ(boundsA);
    var nodeB = new QuadTreeBoundsXZ(boundsB, BoundsMask.NormalLayers, 2);

    // merge nodes
    var merged = nodeA.Merge(nodeB);

    // check intersection
    bool intersects = nodeA.Intersect(nodeB);

    // get center and size (XZ)
    float2 center = merged.Center();
    float2 size = merged.Size();

    // reset a node
    nodeA.Reset();

    // Debug drawing using DebugIterator: obtain a GizmoBatcher from rendering system (context-dependent)
    GizmoBatcher gizmo = /* acquire from game/editor context */ null;

    if (gizmo != null)
    {
        var debugIt = new QuadTreeBoundsXZ.DebugIterator<MyItem>(boundsA, gizmo);

        // draw white box for iterator bounds if it intersects nodeB
        bool doesIntersect = debugIt.Intersect(nodeB);

        // simulate iterating an item in the quad-tree: draws red box for nodeB if intersecting
        MyItem item = new MyItem { id = 1 };
        debugIt.Iterate(nodeB, item);
    }
}

Notes: - m_Bounds stores a full 3D AABB (Bounds3) but most consumer APIs use only XZ components via Center() and Size(). - m_MinLod/m_MaxLod are stored as bytes and clamped when provided via constructors. - DebugIterator is intended for editor/debug visualizations and requires a valid GizmoBatcher to draw wireframe boxes.