Skip to content

Engine → Scripting

native_api.h

The C ABI shared with Conjure.Managed.

Structs

File Description
conjure_anti_aliasing The anti-aliasing of every view the renderer draws, as rendering_get_anti_aliasing reports it and rendering_set_anti_aliasing takes it (renderer::anti_aliasing_settings, whose layout it shares: 12 bytes, post at 4, fxaa_subpixel at 8). msaa_sample_count is 1 (off), 2, 4 or 8; post is 0 (none) or 1 (FXAA); fxaa_subpixel is in [0, 1], 0 sharpest and 1 softest. The two filters are independent: either, both or neither can be on. pad is written as 0 and ignored when read.
conjure_asset_info
conjure_chunk_view Columns of one chunk inside a DOD query scope, valid until query_end.
conjure_collision_record
conjure_create_request One instance to create; filled by native, out_slot written by managed.
conjure_frame_block Written once per frame by the engine before FRAME_BEGIN and read directly by Time, Input and Screen in C#. The screen fields are engine::game_screen_of(window) (conjure/engine/game_screen.h): the framebuffer in pixels (0 x 0 while minimised or without a window), the framebuffer / logical ratio, the OS UI scale of the window's monitor, and window_state, a set of the FRAME_WINDOW_* bits of conjure::scripting.
conjure_frame_stats_block The last committed engine::frame_sample. The managed_* fields are its managed-heap figures (the main thread's allocations, the heap size and the collections of that frame), 0 in a frame without a ready script host.
conjure_gamepad_state
conjure_input_block
conjure_managed_api Functions managed provides to native, filled by Conjure.Interop.NativeBridge.Initialize. sample_memory fills a conjure_managed_memory and returns 0 (a negative status when it cannot). set_active(slots, count, active) tells the instances in slots that their entity became active (1) or inactive (0) and returns how many of them changed state (running OnDisable or OnEnable); a free slot is skipped. script_runtime calls it at the points where an activity change takes effect (script_runtime::set_activity_tags).
conjure_managed_component_desc An [EcsComponent] struct: schema_json lists {"fields":[{"name","type","offset"}]} with core::reflect type names.
conjure_managed_memory What conjure_managed_api::sample_memory reports: thread_allocated_bytes is GC.GetAllocatedBytesForCurrentThread() on the calling (main) thread, heap_bytes GC.GetTotalMemory(false), and the collections GC.CollectionCount(0) and GC.CollectionCount(2). Everything but heap_bytes is cumulative over the life of the managed runtime.
conjure_mat4 Column-major 4x4 matrix.
conjure_module_record
conjure_native_api Functions native provides to managed. Every entry defaults to nullptr; the handshake validates the header, and managed throws NotSupportedException for an entry nobody filled.
conjure_quat_xyzw A quaternion in explicit x, y, z, w storage order (converted from math::quat by name, /).
conjure_query_scope
conjure_ray_query A ray query; flags is a set of conjure_query_flags, and a bit outside it is refused with INVALID_ARGUMENT.
conjure_raycast_hit One query hit; is_trigger is 1 when the body hit is a trigger volume (hit only with INCLUDE_TRIGGERS).
conjure_script_class_desc
conjure_script_field_desc One serialised field of a script class. meta_json is {"tooltip","min","max","enumNames","enumValues", "enumFlags","assetType","hidden"}, each key present only when it applies: enumValues runs parallel to enumNames with the int32 the ENUM payload carries for each name, enumFlags is true for a [Flags] enum, and assetType is the registered asset type name of the AssetRef tag ("conjure.audio.clip"), absent for an untyped reference. default_json is the canonical JSON of the default value.
conjure_shape_query
conjure_spawn_component One component of an entity_spawn request: type_id is the id component_lookup_type or component_register_managed returned, stride the bytes between two entities' values (0: data is one value for every entity) and data the values (nullptr: the registered default value). A stride below the component size and a value of a component that is not blittable are refused; a tag ignores data and stride.
conjure_spawn_desc An entity_spawn request: count entities (1..65536) holding the component_count components (0..8) each. parent (0: scene roots) needs SCENE_ENTITIES: a non-zero parent without it is refused with INVALID_ARGUMENT, and a parent that is not alive with ENTITY_NOT_ALIVE. flags is a set of conjure_spawn_flags; an unknown bit is refused.
conjure_transform
conjure_uuid
conjure_vec2
conjure_vec3
conjure_vec4
native_entry_descriptor One row of the table as text, as the generator normalised it: signature is "<return> <arguments>" with single spaces and '*' hugging the parameter name.

Enumerations

collision_kind

enum class collision_kind : uint8_t {
    COLLISION_ENTER,
    COLLISION_EXIT,
    TRIGGER_ENTER,
    TRIGGER_EXIT,
    COLLISION_STAY,
    COUNT
};

conjure_collision_record::kind. COLLISION_STAY (a solid contact that persists through a fixed step) is appended, so the older kinds keep their values; there is no trigger stay.

conjure_asset_load_priority

enum class conjure_asset_load_priority : uint8_t {
    LOW,
    NORMAL,
    HIGH
};

conjure_button_action

enum class conjure_button_action : uint8_t {
    RELEASE,
    PRESS,
    REPEAT
};

conjure_cast_shape

enum class conjure_cast_shape : uint8_t {
    SPHERE,
    BOX,
    CAPSULE
};

conjure_cursor_mode

enum class conjure_cursor_mode : uint8_t {
    NORMAL,
    HIDDEN,
    DISABLED,
    CAPTURED
};

conjure_force_mode

enum class conjure_force_mode : uint8_t {
    FORCE,
    IMPULSE,
    VELOCITY_CHANGE,
    ACCELERATION
};

conjure_query_flags

enum class conjure_query_flags : uint32_t {
    NONE = 0,
    INCLUDE_TRIGGERS = 1 << 0,
    EXCLUDE_STATIC = 1 << 1
};

conjure_ray_query::flags and the flags of the overlap entries, as bits: NONE (0) skips trigger volumes and hits static bodies; INCLUDE_TRIGGERS (1) also hits trigger volumes, EXCLUDE_STATIC (2) skips static bodies. The values are ABI, pinned by the static_asserts of the layout pins below; a new bit is appended with an explicit value of its own.

conjure_spawn_flags

enum class conjure_spawn_flags : uint32_t {
    NONE = 0,
    SCENE_ENTITIES = 1 << 0
};

conjure_spawn_desc::flags, as bits: NONE (0) makes bare entities, as entity_create does; SCENE_ENTITIES (1) makes scene entities under conjure_spawn_desc::parent, as entity_create_many does. The values are ABI, pinned by the static_asserts of the layout pins below; a new bit is appended with an explicit value of its own.

script_callback

enum class script_callback : uint8_t {
    CREATE,
    START,
    FIXED_UPDATE,
    UPDATE,
    LATE_UPDATE,
    DESTROY,
    COLLISION_ENTER,
    COLLISION_EXIT,
    TRIGGER_ENTER,
    TRIGGER_EXIT,
    RELOAD,
    COLLISION_STAY,
    ENABLE,
    DISABLE,
    COUNT
};

Bit index of conjure_script_class_desc::callback_mask and index of the fault counters. Later callbacks are appended, so the older ones keep their bits: RELOAD (OnReload, which runs instead of OnCreate on an instance a hot reload recreated), then COLLISION_STAY (OnCollisionStay, every fixed step a solid contact persists), ENABLE and DISABLE (OnEnable and OnDisable, when the entity becomes active or inactive). COUNT stays within the 16 bits of the callback mask.

script_field_kind

enum class script_field_kind : uint8_t {
    BOOL,
    INT32,
    INT64,
    FLOAT,
    DOUBLE,
    STRING,
    VEC2,
    VEC3,
    VEC4,
    QUAT,
    COLOR,
    ENTITY,
    ASSET,
    ENUM,
    LIST,
    COUNT
};

Kind of a serialised script field (field_blob payload and inspector schema).

script_phase

enum class script_phase : uint8_t {
    FIXED_UPDATE,
    UPDATE,
    LATE_UPDATE,
    COUNT
};

The three callback phases run_phase takes.

Constants

Name Type Value Description
CREATE_FLAG_ALREADY_CREATED inline constexpr uint8_t 2 conjure_create_request::flags bit: the entry's OnCreate already returned in this entity's lifetime, so the recreated instance runs OnReload instead of OnCreate, after its fields were applied (hot reload, and a snapshot restore or set replace from JSON whose entry says "created").
CREATE_FLAG_ALREADY_STARTED inline constexpr uint8_t 1 conjure_create_request::flags bit: the entry already ran OnStart (reload, snapshot restore).
CREATE_FLAG_INACTIVE inline constexpr uint8_t 4 conjure_create_request::flags bit: the entity is inactive (it or an ancestor is disabled: it carries one of the tags script_runtime::set_activity_tags named) when the instance is created, so the instance starts inactive: it runs OnCreate (or OnReload) but no OnEnable, joins no phase and waits for its first activation to run OnEnable and, when it never ran, OnStart. conjure_managed_api::set_active reports later changes.
FRAME_WINDOW_FOCUSED inline constexpr uint8_t 1 conjure_frame_block::window_state bit: the window has the input focus.
FRAME_WINDOW_FULLSCREEN inline constexpr uint8_t 4 conjure_frame_block::window_state bit: the window is (borderless) fullscreen.
FRAME_WINDOW_MINIMISED inline constexpr uint8_t 2 conjure_frame_block::window_state bit: the window is minimised (the screen is then 0 x 0).
NATIVE_API_CORE_ENTRY_COUNT inline constexpr u32 CONJURE_NATIVE_API_CORE_ENTRY_COUNT Entries this module implements (everything before the bindings marker in native_api.inl).
NATIVE_API_ENTRY_COUNT inline constexpr u32 CONJURE_NATIVE_API_ENTRY_COUNT Entries in the table, core and bindings together.
QUERY_MAX_COMPONENTS inline constexpr int32_t 8 Column slots of a conjure_chunk_view, and the most component ids a query_begin exclusion list holds.

Macros

CONJURE_ENUM_FLAGS

CONJURE_ENUM_FLAGS(conjure_query_flags)

Functions

Public

callback_bit

[[nodiscard]] constexpr uint16_t callback_bit(
    script_callback callback) noexcept;

The callback_mask bit of a callback.

compute_native_api_hash

[[nodiscard]] CONJURE_API u64 compute_native_api_hash() noexcept;

FNV-1a 64 over "<group>_<name> <signature>\n" per descriptor, then over "<line>\n" per line of CONJURE_NATIVE_API_FOR_EACH_RECORD_LINE (the conjure_* records, enumerations and table members of this header): the generator's algorithm run at runtime over the text it generated. It equals CONJURE_NATIVE_API_HASH, which proves both implementations agree; whether the generated text still matches this header is checked by tools/generate_native_api.py --check, not here.

find_native_entry

[[nodiscard]] CONJURE_API i32 find_native_entry(
    std::string_view fullName) noexcept;

Index of the entry named "<group>_<name>", or -1.

make_native_api

[[nodiscard]] CONJURE_API conjure_native_api make_native_api(
    const conjure_frame_block *frame) noexcept;

A fresh table: header filled, every entry nullptr, frame pointing at frame (may be null).

native_api_slots

[[nodiscard]] CONJURE_API std::span<void *const> native_api_slots(
    const conjure_native_api &api) noexcept;

The function pointer slots of a table as an array of void pointers (index = descriptor index).

[[nodiscard]] CONJURE_API std::span<void *> native_api_slots(
    conjure_native_api &api) noexcept;

Mutable form of native_api_slots for fillers that address entries by index.

native_entry_descriptors

[[nodiscard]] CONJURE_API std::span<const native_entry_descriptor> native_entry_descriptors() noexcept;

Every entry of native_api.inl in table order; the bindings entries start at NATIVE_API_CORE_ENTRY_COUNT.

parse_script_callback

[[nodiscard]] CONJURE_API script_callback parse_script_callback(
    std::string_view name) noexcept;

Parses a name produced by to_string(script_callback). COUNT when unknown.

parse_script_field_kind

[[nodiscard]] CONJURE_API script_field_kind parse_script_field_kind(
    std::string_view name) noexcept;

Parses a name produced by to_string(script_field_kind). COUNT when unknown.

to_string

[[nodiscard]] CONJURE_API std::string_view to_string(
    script_field_kind kind) noexcept;

The stable upper-case name of a field kind ("VEC3"); "COUNT" for out-of-range values.

[[nodiscard]] CONJURE_API std::string_view to_string(
    script_callback callback) noexcept;

The upper-case name of a callback ("UPDATE"); "COUNT" for out-of-range values.

[[nodiscard]] CONJURE_API std::string_view to_string(
    script_phase phase) noexcept;

The upper-case name of a phase ("FIXED_UPDATE"); "COUNT" for out-of-range values.

validate_managed_api

[[nodiscard]] CONJURE_API core::result<void> validate_managed_api(
    const conjure_managed_api &api);

Checks a managed table a host received: size, version, hash and that every function is set.

validate_native_api

[[nodiscard]] CONJURE_API core::result<void> validate_native_api(
    const conjure_native_api &api);

Checks the header (size, version, hash) and that every core entry is filled. ABI_MISMATCH or NOT_INITIALISED naming the first missing entry.