mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 12:29:04 -06:00
Add function to destroy the current state machine
This commit is contained in:
@@ -69,6 +69,11 @@ void StateMachineModule::initializeStateMachine(const ghoul::Dictionary& states,
|
||||
}
|
||||
}
|
||||
|
||||
void StateMachineModule::deinitializeStateMachine() {
|
||||
_machine.reset();
|
||||
_machine = nullptr;
|
||||
}
|
||||
|
||||
bool StateMachineModule::hasStateMachine() const {
|
||||
return _machine != nullptr;
|
||||
}
|
||||
@@ -148,6 +153,13 @@ scripting::LuaLibrary StateMachineModule::luaLibrary() const {
|
||||
"the identifier of the desired initial state. If left out, the first state "
|
||||
"in the list will be used."
|
||||
},
|
||||
{
|
||||
"destroyStateMachine",
|
||||
&luascriptfunctions::destroyStateMachine,
|
||||
{},
|
||||
"",
|
||||
"Destroys the current state machine and deletes all the memory."
|
||||
},
|
||||
{
|
||||
"goToState",
|
||||
&luascriptfunctions::goToState,
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
void initializeStateMachine(const ghoul::Dictionary& states,
|
||||
const ghoul::Dictionary& transitions,
|
||||
const std::optional<std::string> startState = std::nullopt);
|
||||
void deinitializeStateMachine();
|
||||
|
||||
bool hasStateMachine() const;
|
||||
|
||||
|
||||
@@ -47,6 +47,15 @@ int createStateMachine(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int destroyStateMachine(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::destroyStateMachine");
|
||||
|
||||
StateMachineModule* module = global::moduleEngine->module<StateMachineModule>();
|
||||
module->deinitializeStateMachine();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int goToState(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::goToState");
|
||||
std::string newState = ghoul::lua::value<std::string>(L);
|
||||
|
||||
Reference in New Issue
Block a user