vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::ScriptModule Class Reference

Loads the hot-reloadable gameplay module and swaps it at runtime. More...

#include <script_module.h>

Public Member Functions

bool load (const std::filesystem::path &modulePath, EventBus *events)
 Load the gameplay module and register its behaviors.
bool reload (Scene &scene, BehaviorSystem &behaviors, EventBus &events)
 Hot-reload from the same path: serialize, swap module, recreate.
bool buildScene (Scene &scene, ResourceManager &resources)
 Let the module seed scene through the optional vkmBuildScene, if it has one.
bool setupNetwork (NetSession &session)
 Let the module say what a player is, through the optional vkmSetupNetwork.
void unload (EventBus &events)
 Drop the loaded module and the behavior types it registered.
void expect (const std::filesystem::path &modulePath, EventBus &events)
 Unload whatever is loaded and remember modulePath for a project not yet built.
const std::filesystem::path & modulePath () const
 The built module this loaded from, not the mapped copy: the file to watch for a build.

Detailed Description

Loads the hot-reloadable gameplay module and swaps it at runtime.

reload() rebuilds only the behavior objects; entities and other components are untouched. Reloaded behaviors run onStart again next tick.

Member Function Documentation

◆ load()

bool Vkm::Engine::ScriptModule::load ( const std::filesystem::path & modulePath,
EventBus * events )

Load the gameplay module and register its behaviors.

Loads a copy, keeping the original writable for rebuilds. A read-only directory (an installed game) loads in place; any other copy failure refuses the load.

Parameters
modulePathPath to the built module (.dll/.so) to load.
eventsThe host's bus, so a replaced module is released fully; null for a host with no Engine yet, which has nothing to replace.
Returns
True if the module loaded and registered successfully.

◆ reload()

bool Vkm::Engine::ScriptModule::reload ( Scene & scene,
BehaviorSystem & behaviors,
EventBus & events )

Hot-reload from the same path: serialize, swap module, recreate.

The new build is checked before anything is torn down; a refused one leaves the running module untouched. With none loaded, this is a plain load. scene must hold no component set the outgoing module created (its vtable is module code); see docs/reference/scripting.md, "Nothing may hold module code across the swap".

Parameters
sceneScene whose behaviors are saved across the swap.
behaviorsThe system running them, whose session the swap ends.
eventsBus to clear the outgoing module's event types from.
Returns
True if the module reloaded and its behaviors were restored.

◆ buildScene()

bool Vkm::Engine::ScriptModule::buildScene ( Scene & scene,
ResourceManager & resources )

Let the module seed scene through the optional vkmBuildScene, if it has one.

Parameters
sceneScene to seed.
resourcesAsset graph the built world's assets go into.
Returns
True if the module had the entry and it ran.

◆ setupNetwork()

bool Vkm::Engine::ScriptModule::setupNetwork ( NetSession & session)

Let the module say what a player is, through the optional vkmSetupNetwork.

Sets spawn callbacks and registers replicated components. Harmless offline: an empty session behaves as no session.

Parameters
sessionSession the host will host or join with.
Returns
True if the module had the entry and it ran.

◆ unload()

void Vkm::Engine::ScriptModule::unload ( EventBus & events)

Drop the loaded module and the behavior types it registered.

Safe when nothing is loaded. Clear the scene first: behaviors outlive this only as dangling objects.

Parameters
eventsBus to clear the outgoing module's event types from.

◆ expect()

void Vkm::Engine::ScriptModule::expect ( const std::filesystem::path & modulePath,
EventBus & events )

Unload whatever is loaded and remember modulePath for a project not yet built.

Parameters
modulePathWhere the project's build writes its module.
eventsBus to clear the outgoing module's event types from.

◆ modulePath()

const std::filesystem::path & Vkm::Engine::ScriptModule::modulePath ( ) const
inline

The built module this loaded from, not the mapped copy: the file to watch for a build.

Returns
The path given to load() or expect(), or empty when none was given or unload() has since dropped a loaded module.

The documentation for this class was generated from the following file: