Skip to content

Engine → Physics → physics_layers.h

physics_layer_table

Syntax

class CONJURE_API physics_layer_table

Constructors

AccessSignatureDescription
publicphysics_layer_table();One layer "default" that collides with itself.
publicphysics_layer_table( const physics_layer_table &) = default;
publicphysics_layer_table( physics_layer_table &&) noexcept = default;

Destructors

AccessSignatureDescription
public~physics_layer_table();

Variables

AccessNameTypeDefaultDescription
privatemCollidesstd::array<u32, MAX_PHYSICS_LAYERS>{}
privatemNamescore::small_vector<core::string_id, 8>{}

Functions

Public

add_layer

[[nodiscard]] core::result<u8> add_layer(
    core::string_id name);

Appends a layer that collides with every existing layer and itself; returns its index. LAYER_LIMIT_REACHED, DUPLICATE_LAYER (also for the null id).

collides

[[nodiscard]] bool collides(
    u8 a,
    u8 b) const noexcept;

True when the two layers collide; false for indices outside the table.

collision_mask

[[nodiscard]] physics_layer_mask collision_mask(
    u8 layer) const noexcept;

The layers layer collides with (the empty mask for an index outside the table).

count

[[nodiscard]] u32 count() const noexcept;

Number of layers (at least 1).

find

[[nodiscard]] std::optional<u8> find(
    core::string_id name) const noexcept;

The index of the layer with this name, or nullopt.

from_json

[[nodiscard]] static core::result<physics_layer_table> from_json(
    const core::json::value &section);

Builds a table from the project.json section: "names" (required, 1..32 unique strings) and "ignore" (optional pairs of names that do not collide). LAYER_CONFIG_INVALID, LAYER_LIMIT_REACHED, DUPLICATE_LAYER, UNKNOWN_LAYER. Everything collides unless ignored.

name

[[nodiscard]] core::string_id name(
    u8 layer) const noexcept;

The name of a layer (the null id for an index outside the table).

set_collides

void set_collides(
    u8 a,
    u8 b,
    bool collides) noexcept;

Sets whether two layers collide (symmetric). Indices outside the table are ignored.

to_json

[[nodiscard]] core::result<void> to_json(
    core::json::writer &out) const;

Writes {"ignore": [[a, b], ...], "names": [...]} with sorted keys and the ignored pairs in ascending (a, b) index order, so the text equals the canonical form of its parse. Fails with LAYER_CONFIG_INVALID when a layer name was never interned (it cannot be spelt).

validate

[[nodiscard]] core::result<void> validate() const;

LAYER_CONFIG_INVALID when the table is empty or the matrix is not symmetric, DUPLICATE_LAYER when two layers share a name.

Operator Overloads

Public

operator=

physics_layer_table &operator=(
    const physics_layer_table &) = default;
physics_layer_table &operator=(
    physics_layer_table &&) noexcept = default;

operator==

[[nodiscard]] bool operator==(
    const physics_layer_table &other) const noexcept;