KROYSDOCS
HomeWhat's newv0.1.0
C/C++ SDK / C++ layer · Host / kroys::Host

kroys::Host

The plugin's host for one target: typed registrations with lambdas, the document scene, selection, tasks, settings and logging. Closures registered through it live until it is destroyed (after the host removed the registrations).

Kindclass
Headerkroys/plugin.hpp
Members35
DECLARATION

Declaration

Declared in kroys/plugin.hpp.

plugin.hpp
class Host
REFERENCE

Members

Constructors
#explicit Host(const KroysHost* host);

Wraps the KroysHost handed to KroysPlugin_Start (KROYS_PLUGIN does this).

constructor
Methods
#[[nodiscard]] const KroysHost* Raw() const;

The raw C host (every table).

method
#[[nodiscard]] KroysContext Context() const;

The KroysContext passed first to every C function.

method
#[[nodiscard]] bool IsEditor() const;

True for the editor target.

method
#[[nodiscard]] bool IsRuntime() const;

True for the runtime target.

method
#[[nodiscard]] KroysVersion EngineSdk() const;

The engine's SDK version.

method
#[[nodiscard]] Ui UiApi() const;

The UI API (valid inside draw callbacks).

method
#void Log(int32_t severity, const std::string& message) const;

Thread-safe.

methodwraps KroysCoreApi::Log
#void Info(const std::string& message) const;

Logs an information line (thread-safe).

method
#void Warning(const std::string& message) const;

Logs a warning (thread-safe).

method
#void Error(const std::string& message) const;

Logs an error (thread-safe).

method
#[[nodiscard]] std::string LastError() const;

Thread-safe. The calling thread's last error message ("" when none).

#[[nodiscard]] std::string Id() const;

The plugin's manifest id (host string).

#[[nodiscard]] std::string Path(int32_t which) const;

A folder of the plugin's environment: KROYS_PATH_PLUGIN, KROYS_PATH_PROJECT, KROYS_PATH_CONTENT or KROYS_PATH_PLUGIN_DATA (host string).

#[[nodiscard]] std::string Setting(const std::string& key, const std::string& fallback = {}) const;

Per-user plugin settings (saved under the user settings folder).

#Result SetSetting(const std::string& key, const std::string& value) const;

Stores a per-user plugin setting (kept across reloads and restarts).

#Result Unregister(Handle handle) const;

Removes one registration (command, panel, system, ...).

#ComponentType AddComponentType(const ComponentTypeBuilder& builder) const;

Capability "components". Registering an identical definition again returns the same type.

#Handle AddCommand(const CommandOptions& options, std::function<void()> execute, std::function<bool()> enabled = {}, std::function<bool()> checked = {});

Capability commands: a command in the palette and under Tools > Plugins, optionally on the toolbar and under a shortcut.

#Handle AddPanel(const PanelOptions& options, std::function<void(const Ui&, const KroysDrawArgs&)> draw);

Capability panels: a dockable panel drawn every frame.

#Handle AddSettingsPage(const SettingsPageOptions& options, std::function<void(const Ui&, const KroysDrawArgs&)> draw);

Capability settings: a page in Settings > PLUGINS.

#Handle AddImporter(const FileConverterOptions& options, std::function<Result(const FileJob&)> run);

Capability importers: Run converts a source file on a worker thread.

#Handle AddExporter(const FileConverterOptions& options, std::function<Result(const FileJob&)> run);

Capability exporters: Run writes an exported file on a worker thread.

#Handle AddAssetType(const AssetTypeOptions& options, AssetTypeHooks hooks);

Capability asset-types: create, describe, open and save hooks for files with the extension.

#Handle AddService(const std::string& name, std::function<void(float)> tick);

Capability services: Tick runs every editor frame.

#Handle AddAutomationStep(const std::string& name, std::function<Result(const std::string& argument, const AutomationJob&)> run);

Capability automation: a step capture scripts run by name.

#Handle AddViewportTool(const ViewportToolOptions& options, ViewportToolHooks hooks);

2.1: 0 on an older engine (no viewport API).

method
#Handle AddSystem(const SystemOptions& options, std::function<void(const World&, const KroysTickArgs&)> tick);

Capability "systems". Runs in every game world (player and the editor's Play mode).

#uint64_t SubmitTask(const std::string& name, std::function<Result(const TaskJob&)> run, std::function<void(bool succeeded, const std::string& message)> complete = {}, const std::string& lane = {});

Editor task queue. run runs on a worker thread; complete on the main thread.

method
#void Notify(int32_t severity, const std::string& title, const std::string& message) const;

Non-modal toast + console line.

#Result Execute(const std::string& commandId) const;

Any editor command ("File.SaveProject", "<plugin id>.<id>").

#[[nodiscard]] World Document() const;

The edited scene; null without a scene or during Play.

#[[nodiscard]] std::vector<Entity> Selection() const;

Number of selected entities.

#Result Select(const std::vector<Entity>& entities) const;

Replaces the selection (count 0: clears it).

#void ReleaseClosures();

Removes the closures this Host owns. Call only after the registrations are gone.

method
Signatures
explicit Host(const KroysHost* host);
[[nodiscard]] const KroysHost* Raw() const;
[[nodiscard]] KroysContext Context() const;
[[nodiscard]] bool IsEditor() const;
[[nodiscard]] bool IsRuntime() const;
[[nodiscard]] KroysVersion EngineSdk() const;
[[nodiscard]] Ui UiApi() const;
void Log(int32_t severity, const std::string& message) const;
void Info(const std::string& message) const;
void Warning(const std::string& message) const;
void Error(const std::string& message) const;
[[nodiscard]] std::string LastError() const;
[[nodiscard]] std::string Id() const;
[[nodiscard]] std::string Path(int32_t which) const;
[[nodiscard]] std::string Setting(const std::string& key, const std::string& fallback = {}) const;
Result SetSetting(const std::string& key, const std::string& value) const;
Result Unregister(Handle handle) const;
ComponentType AddComponentType(const ComponentTypeBuilder& builder) const;
Handle AddCommand(const CommandOptions& options, std::function<void()> execute, std::function<bool()> enabled = {}, std::function<bool()> checked = {});
Handle AddPanel(const PanelOptions& options, std::function<void(const Ui&, const KroysDrawArgs&)> draw);
Handle AddSettingsPage(const SettingsPageOptions& options, std::function<void(const Ui&, const KroysDrawArgs&)> draw);
Handle AddImporter(const FileConverterOptions& options, std::function<Result(const FileJob&)> run);
Handle AddExporter(const FileConverterOptions& options, std::function<Result(const FileJob&)> run);
Handle AddAssetType(const AssetTypeOptions& options, AssetTypeHooks hooks);
Handle AddService(const std::string& name, std::function<void(float)> tick);
Handle AddAutomationStep(const std::string& name, std::function<Result(const std::string& argument, const AutomationJob&)> run);
Handle AddViewportTool(const ViewportToolOptions& options, ViewportToolHooks hooks);
Handle AddSystem(const SystemOptions& options, std::function<void(const World&, const KroysTickArgs&)> tick);
uint64_t SubmitTask(const std::string& name, std::function<Result(const TaskJob&)> run, std::function<void(bool succeeded, const std::string& message)> complete = {}, const std::string& lane = {});
void Notify(int32_t severity, const std::string& title, const std::string& message) const;
Result Execute(const std::string& commandId) const;
[[nodiscard]] World Document() const;
[[nodiscard]] std::vector<Entity> Selection() const;
Result Select(const std::vector<Entity>& entities) const;
void ReleaseClosures();

KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.