VR-Engage  2.2
Loading...
Searching...
No Matches
scriptComponent.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*****************************************************************************/
5
6//! \file scriptComponent.h
7//! \brief Component for integrating Lua scripts into the player component system
8//! \ingroup vreCommonComponents
9
10#pragma once
11
13
15
16#include <string>
17
18namespace makVre
19{
20class DtLuaState;
21
23{
24//! \ingroup RoleConfigParams
25//! \defgroup ScriptComponentRoleParams Script Component Role Parameters
26//! \roleInherits{PlayerComponentRoleParams}
27//! Configuration Options for script component role.
28//! @{
29
30//! \vreRoleParamRequired{script,string,scriptComponent,"scripts/myScript.lua",Path to the Lua script file to load and execute.}
31constexpr const char* script = "script";
32
33//! \vreRoleParam{scriptConfig,table,"",scriptComponent,Configuration table to pass to the script's initialize function.}
34constexpr const char* scriptConfig = "scriptConfig";
35
36//! @}
37} // namespace ScriptComponentConfig
38
39//! \brief Type identifier for DtScriptComponent component
40constexpr const char* DtScriptComponentType = "DtScriptComponent";
41
42//! \brief Component for executing Lua scripts as part of a player role
43//!
44//! DtScriptComponent loads and executes Lua scripts within the player component
45//! lifecycle, allowing custom behavior implementation through scripts rather than
46//! C++ code. Scripts have access to the player attribute store and can implement
47//! initialize, postInitialize, tick, and shutdown callbacks that align with the
48//! component lifecycle methods.
49//!
50//! \note Based on implementation examination, this component may be deprecated
51//! or temporarily disabled in the current codebase.
53{
54public:
55 //! \brief Constructor for DtScriptComponent
56 //!
57 //! Initializes the component with the name "DtScriptedUpdater"
59
60 //! \brief Virtual destructor for DtScriptComponent
61 virtual ~DtScriptComponent() override;
62
63 //! \brief Initializes the script component
64 //! \param player Pointer to the player station this component belongs to
65 //! \param config Configuration table containing script settings
66 //! \return True if initialization succeeded, false otherwise
67 //!
68 //! Loads the script file specified in the config and initializes the Lua VM.
69 //! Serializes any scriptConfig table for passing to the script's initialize function.
71 //! \brief Performs post-initialization after all components are initialized
72 //! \return True if post-initialization succeeded, false otherwise
73 //!
74 //! Calls the script's postInitialize function if it exists
75 virtual bool postInitialize() override;
76 //! \brief Called every frame to update the script state
77 //! \param dt Delta time since the last frame in seconds
78 //!
79 //! Calls the script's tick function, passing the delta time
80 virtual void tick(double dt) override;
81 //! \brief Shuts down the script component
82 //!
83 //! Calls the script's shutdown function if it exists and cleans up the Lua VM
84 virtual void shutdown() override;
85
86 //! \brief Returns the type identifier for this component
87 //! \return The type string for DtScriptComponent
88 virtual const char* type() const override;
89
90 //! \brief Reloads the script file
91 //!
92 //! Reinitializes the Lua VM and reloads the script file
93 virtual void reload();
94
95protected:
96 //! \brief Sets up the Lua virtual machine
97 //! \return True if VM setup succeeded, false otherwise
98 //!
99 //! Creates a new Lua VM, loads serialization library, installs VR bindings,
100 //! loads the script file, and calls the script's initialize function
101 virtual bool setupVm();
102
103 //! \brief Shuts down and cleans up the Lua virtual machine
104 virtual void shutdownVm();
105
106 //! \brief Path to the Lua script file to execute
107 std::string myScriptFilename;
108
109 //! \brief Serialized configuration table to pass to the script
110 std::string myScriptConfig;
111
112 //! \brief Pointer to the Lua virtual machine instance
114};
115} // namespace makVre
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing a Lua state and providing high-level operations.
Definition luaState.h:43
Base class for all role components in VR-Engage.
Definition playerComponent.h:78
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
virtual void shutdown() override
Shuts down the script component.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the script component.
std::string myScriptConfig
Serialized configuration table to pass to the script.
Definition scriptComponent.h:110
virtual void reload()
Reloads the script file.
virtual void tick(double dt) override
Called every frame to update the script state.
virtual void shutdownVm()
Shuts down and cleans up the Lua virtual machine.
virtual bool setupVm()
Sets up the Lua virtual machine.
virtual bool postInitialize() override
Performs post-initialization after all components are initialized.
virtual ~DtScriptComponent() override
Virtual destructor for DtScriptComponent.
DtScriptComponent()
Constructor for DtScriptComponent.
std::string myScriptFilename
Path to the Lua script file to execute.
Definition scriptComponent.h:107
DtLuaState * myVm
Pointer to the Lua virtual machine instance.
Definition scriptComponent.h:113
virtual const char * type() const override
Returns the type identifier for this component.
constexpr const char * script
Definition scriptComponent.h:31
constexpr const char * scriptConfig
Definition scriptComponent.h:34
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition scriptComponent.h:23
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtScriptComponentType
Type identifier for DtScriptComponent component.
Definition scriptComponent.h:40
Defines the DtPlayerComponent base class for VR-Engage role components.