mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-28 15:57:59 +03:00
Allow to run console input in freeze modes as well
This commit is contained in:
parent
f0f733519f
commit
e27ec86e85
4 changed files with 32 additions and 13 deletions
|
@ -62,6 +62,7 @@ public:
|
|||
virtual void OnUseItem(GAME_OBJECT_ID objectNumber) = 0;
|
||||
virtual void OnFreeze() = 0;
|
||||
|
||||
virtual void AddConsoleInput(const std::string& input) = 0;
|
||||
virtual void ShortenTENCalls() = 0;
|
||||
virtual void FreeLevelScripts() = 0;
|
||||
virtual void ResetScripts(bool clearGameVars) = 0;
|
||||
|
|
|
@ -620,6 +620,28 @@ int Handle(TypeFrom& var, MapType& varsMap, size_t& numVars, std::vector<SavedVa
|
|||
return first->second;
|
||||
}
|
||||
|
||||
void LogicHandler::AddConsoleInput(const std::string& input)
|
||||
{
|
||||
_consoleInput = input;
|
||||
}
|
||||
|
||||
void LogicHandler::PerformConsoleInput()
|
||||
{
|
||||
if (!_consoleInput.empty())
|
||||
{
|
||||
try
|
||||
{
|
||||
ExecuteString(_consoleInput);
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
TENLog("Error executing " + _consoleInput + ": " + ex.what(), LogLevel::Error);
|
||||
}
|
||||
|
||||
_consoleInput.clear();
|
||||
}
|
||||
}
|
||||
|
||||
std::string LogicHandler::GetRequestedPath() const
|
||||
{
|
||||
auto path = std::string();
|
||||
|
@ -1027,6 +1049,8 @@ void LogicHandler::OnLoop(float deltaTime, bool postLoop)
|
|||
for (const auto& name : _callbacksPreLoop)
|
||||
CallLevelFuncByName(name, deltaTime);
|
||||
|
||||
PerformConsoleInput();
|
||||
|
||||
lua_gc(_handler.GetState()->lua_state(), LUA_GCCOLLECT, 0);
|
||||
if (_onLoop.valid())
|
||||
CallLevelFunc(_onLoop, deltaTime);
|
||||
|
@ -1099,6 +1123,8 @@ void LogicHandler::OnFreeze()
|
|||
for (const auto& name : _callbacksPreFreeze)
|
||||
CallLevelFuncByName(name);
|
||||
|
||||
PerformConsoleInput();
|
||||
|
||||
if (_onFreeze.valid())
|
||||
CallLevelFunc(_onFreeze);
|
||||
|
||||
|
|
|
@ -75,11 +75,13 @@ private:
|
|||
sol::protected_function _onFreeze = {};
|
||||
|
||||
std::unordered_map<CallbackPoint, std::unordered_set<std::string>*> _callbacks;
|
||||
|
||||
std::vector<std::variant<std::string, unsigned int>> _savedVarPath;
|
||||
|
||||
bool _shortenedCalls = false;
|
||||
|
||||
std::string _consoleInput = "";
|
||||
void PerformConsoleInput();
|
||||
|
||||
std::string GetRequestedPath() const;
|
||||
|
||||
void ResetLevelTables();
|
||||
|
@ -132,6 +134,7 @@ public:
|
|||
void HandleEvent(const std::string& name, EventType type, sol::optional<Moveable&> activator);
|
||||
void EnableEvent(const std::string& name, EventType type);
|
||||
void DisableEvent(const std::string& name, EventType type);
|
||||
void AddConsoleInput(const std::string& input);
|
||||
|
||||
void ResetScripts(bool clearGameVars) override;
|
||||
void ShortenTENCalls() override;
|
||||
|
|
|
@ -24,10 +24,6 @@ using namespace TEN::Renderer;
|
|||
using namespace TEN::Input;
|
||||
using namespace TEN::Utils;
|
||||
|
||||
using std::exception;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
WINAPP App;
|
||||
unsigned int ThreadID, ConsoleThreadID;
|
||||
|
@ -261,14 +257,7 @@ unsigned CALLBACK ConsoleInput(void*)
|
|||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
g_GameScript->ExecuteString(input);
|
||||
}
|
||||
catch (const exception& ex)
|
||||
{
|
||||
TENLog("Error executing " + input + ": " + ex.what(), LogLevel::Error);
|
||||
}
|
||||
g_GameScript->AddConsoleInput(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue