Skip to content

Engine → Scripting → null_script_host.h

null_script_host

Syntax

class CONJURE_API null_script_host final : public script_host

Inheritance Hierarchy

script_host → null_script_host

Constructors

AccessSignatureDescription
publicnull_script_host();

Destructors

AccessSignatureDescription
public~null_script_host() override;

Variables

AccessNameTypeDefaultDescription
privatemActivityHookactivity_hook{}
privatemAssemblyLoadedboolfalse
privatemCollisionHookcollision_hook{}
privatemCreateHookcreate_hook{}
privatemDestroyHookdestroy_hook{}
privatemFakeClassesstd::vector<script_class_info>{}
privatemFreeListstd::vector<i32>{}
privatemLoadedAssemblystd::string{}
privatemLoadResulti320
privatemManagedApiconjure_managed_api{}
privatemManagedMemoryconjure_managed_memory{}
privatemNativeApiconjure_native_api *nullptr
privatemPhaseHookphase_hook{}
privatemRecordernull_host_recorder{}
privatemReloadHookcreate_hook{}
privatemSampleMemoryResulti320
privatemSlotsstd::vector<slot_state>{}
privatemStatusscript_host_statusscript_host_status::UNINITIALISED
privatemUnloadResulti320

Functions

Public

active

[[nodiscard]] static null_script_host *active() noexcept;

The null host whose functions the managed table currently calls, or nullptr.

add_fake_class

void add_fake_class(
    script_class_info info);

A class load_game_assembly reports to native through script_register_class/field (fields may be in any order; the registry sorts them).

backend

[[nodiscard]] script_backend backend() const noexcept override;

clear_fake_classes

void clear_fake_classes();

Forgets every fake class.

free_list

[[nodiscard]] const std::vector<i32> &free_list() const noexcept;

Slots on the free list, most recently freed first.

initialise

[[nodiscard]] core::result<void> initialise(
    const script_host_config &config,
    conjure_native_api &nativeApi) override;

Fills the managed table with the recording functions and becomes the active null host. Never fails; a second active null host in the process asserts and replaces the first.

is_assembly_loaded

[[nodiscard]] bool is_assembly_loaded() const noexcept;

is_slot_active

[[nodiscard]] bool is_slot_active(
    i32 slot) const noexcept;

True when the slot is live and active: a slot starts active unless its create request carried CREATE_FLAG_INACTIVE, and set_active changes it. This is what the managed side keeps per instance.

is_slot_live

[[nodiscard]] bool is_slot_live(
    i32 slot) const noexcept;

is_slot_started

[[nodiscard]] bool is_slot_started(
    i32 slot) const noexcept;

True when the slot is live and either took part in a FIXED_UPDATE or UPDATE run_phase (the phases that run OnStart; LATE_UPDATE does not start a slot) or was created with CREATE_FLAG_ALREADY_STARTED. This mirrors what the managed side marks after OnStart, so a test can inspect it.

live_slot_count

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

loaded_assembly

[[nodiscard]] const std::string &loaded_assembly() const noexcept;

managed_api

[[nodiscard]] const conjure_managed_api &managed_api() const noexcept override;

parse_classes_fixture

[[nodiscard]] static core::result<std::vector<script_class_info>> parse_classes_fixture(
    std::string_view jsonText);

Parses a <assembly>.classes.json fixture: {"classes":[{"name","callbacks":["UPDATE",...], "fields":[{"name","kind","elementKind","default","meta"}]}]}.

recorder

[[nodiscard]] const null_host_recorder &recorder() const noexcept;

remove_fake_class

bool remove_fake_class(
    u64 classHash);

Removes a fake class so the next load models an assembly that dropped it.

reset_recorder

void reset_recorder();

set_activity_hook

void set_activity_hook(
    activity_hook hook);

set_collect_override

void set_collect_override(
    i32 slot,
    std::vector<u8> blob);

Bytes collect_fields returns for a slot instead of echoing the last apply_fields blob.

set_collision_hook

void set_collision_hook(
    collision_hook hook);

set_create_hook

void set_create_hook(
    create_hook hook);

Callbacks standing in for managed script code (empty = none). They run on the main thread inside the managed_api call and may call back into the runtime like a script would: add scripts, destroy entities, open query scopes through the native table.

set_destroy_hook

void set_destroy_hook(
    destroy_hook hook);

set_load_result

void set_load_result(
    i32 result) noexcept;

The value load_game_assembly returns (0 = success; a scripting_error code models a failed load).

set_managed_memory

void set_managed_memory(
    const conjure_managed_memory &memory) noexcept;

The counters sample_memory reports from now on (all 0 until set), standing in for the CLR's. Like the CLR's, every field but heap_bytes should only grow while the host lives; a test models a host restart by setting smaller values.

set_phase_hook

void set_phase_hook(
    phase_hook hook);

set_recording

void set_recording(
    bool enabled) noexcept;

False makes the recorder record nothing (null_host_recorder::set_enabled) and the host build no record, so recording adds no allocation to a managed call: for long runs and allocation gates. Only the slot state the host keeps (a new slot, a slot's fields) may still grow. Survives reset_recorder(). On by default.

set_reload_hook

void set_reload_hook(
    create_hook hook);

set_sample_memory_result

void set_sample_memory_result(
    i32 result) noexcept;

The value sample_memory returns (0 = success and out filled; a negative scripting status models a failed sample and leaves out untouched).

set_unload_result

void set_unload_result(
    i32 result) noexcept;

The value unload_game_assembly returns: 0 collected, 1 leaked.

shutdown

void shutdown() override;

Frees every slot, forgets the loaded assembly, deactivates. Recorded as "shutdown".

slot_class

[[nodiscard]] u64 slot_class(
    i32 slot) const noexcept;

slot_entity

[[nodiscard]] u64 slot_entity(
    i32 slot) const noexcept;

Entity recorded for a live slot (0 otherwise).

slot_fields

[[nodiscard]] const std::vector<u8> &slot_fields(
    i32 slot) const noexcept;

Blob last applied to a live slot (empty otherwise).

slot_phase_count

[[nodiscard]] u32 slot_phase_count(
    i32 slot,
    script_phase phase) const noexcept;

How often a live slot took part in run_phase(phase).

status

[[nodiscard]] script_host_status status() const noexcept override;

Private

allocate_slot

[[nodiscard]] i32 allocate_slot();

apply_fields

[[nodiscard]] i32 apply_fields(
    i32 slot,
    const u8 *blob,
    i32 size);

collect_fields

[[nodiscard]] i32 collect_fields(
    i32 slot,
    u8 *buffer,
    i32 capacity);

collect_garbage

[[nodiscard]] i32 collect_garbage();

create_instances

[[nodiscard]] i32 create_instances(
    conjure_create_request *requests,
    i32 count);

destroy_instances

[[nodiscard]] i32 destroy_instances(
    const i32 *slots,
    i32 count,
    i32 callOnDestroy);

dispatch_collisions

[[nodiscard]] i32 dispatch_collisions(
    const conjure_collision_record *records,
    i32 count);

free_slot

void free_slot(
    i32 slot);

load_game_assembly

[[nodiscard]] i32 load_game_assembly(
    std::string_view path);

register_classes_with_native

void register_classes_with_native(
    const std::vector<script_class_info> &classes);

run_phase

[[nodiscard]] i32 run_phase(
    u8 phase,
    f32 deltaTime);

sample_memory

[[nodiscard]] i32 sample_memory(
    conjure_managed_memory *out);

set_active

[[nodiscard]] i32 set_active(
    const i32 *slots,
    i32 count,
    i32 active);

shutdown_managed

[[nodiscard]] i32 shutdown_managed();

trampoline_apply_fields

static i32 trampoline_apply_fields(
    i32 slot,
    const u8 *blob,
    i32 size);

trampoline_collect_fields

static i32 trampoline_collect_fields(
    i32 slot,
    u8 *buffer,
    i32 capacity);

trampoline_collect_garbage

static i32 trampoline_collect_garbage();

trampoline_create_instances

static i32 trampoline_create_instances(
    conjure_create_request *requests,
    i32 count);

trampoline_destroy_instances

static i32 trampoline_destroy_instances(
    const i32 *slots,
    i32 count,
    i32 callOnDestroy);

trampoline_dispatch_collisions

static i32 trampoline_dispatch_collisions(
    const conjure_collision_record *records,
    i32 count);

trampoline_load_game_assembly

static i32 trampoline_load_game_assembly(
    const char *utf8Path,
    i32 length);

trampoline_run_phase

static i32 trampoline_run_phase(
    u8 phase,
    f32 deltaTime);

trampoline_sample_memory

static i32 trampoline_sample_memory(
    conjure_managed_memory *out);

trampoline_set_active

static i32 trampoline_set_active(
    const i32 *slots,
    i32 count,
    i32 active);

trampoline_shutdown

static i32 trampoline_shutdown();

trampoline_unload_game_assembly

static i32 trampoline_unload_game_assembly();

unload_game_assembly

[[nodiscard]] i32 unload_game_assembly();