diff --git a/apps/openmw/mwlua/inputprocessor.hpp b/apps/openmw/mwlua/inputprocessor.hpp index 112d10c750..fe6de5450e 100644 --- a/apps/openmw/mwlua/inputprocessor.hpp +++ b/apps/openmw/mwlua/inputprocessor.hpp @@ -3,18 +3,17 @@ #include -#include -#include #include #include "../mwbase/luamanager.hpp" namespace MWLua { + template class InputProcessor { public: - InputProcessor(LuaUtil::ScriptsContainer* scriptsContainer) + InputProcessor(Container* scriptsContainer) : mScriptsContainer(scriptsContainer) { mScriptsContainer->registerEngineHandlers({ &mKeyPressHandlers, &mKeyReleaseHandlers, @@ -58,15 +57,15 @@ namespace MWLua } private: - LuaUtil::ScriptsContainer* mScriptsContainer; - LuaUtil::ScriptsContainer::EngineHandlerList mKeyPressHandlers{ "onKeyPress" }; - LuaUtil::ScriptsContainer::EngineHandlerList mKeyReleaseHandlers{ "onKeyRelease" }; - LuaUtil::ScriptsContainer::EngineHandlerList mControllerButtonPressHandlers{ "onControllerButtonPress" }; - LuaUtil::ScriptsContainer::EngineHandlerList mControllerButtonReleaseHandlers{ "onControllerButtonRelease" }; - LuaUtil::ScriptsContainer::EngineHandlerList mActionHandlers{ "onInputAction" }; - LuaUtil::ScriptsContainer::EngineHandlerList mTouchpadPressed{ "onTouchPress" }; - LuaUtil::ScriptsContainer::EngineHandlerList mTouchpadReleased{ "onTouchRelease" }; - LuaUtil::ScriptsContainer::EngineHandlerList mTouchpadMoved{ "onTouchMove" }; + Container* mScriptsContainer; + Container::EngineHandlerList mKeyPressHandlers{ "onKeyPress" }; + Container::EngineHandlerList mKeyReleaseHandlers{ "onKeyRelease" }; + Container::EngineHandlerList mControllerButtonPressHandlers{ "onControllerButtonPress" }; + Container::EngineHandlerList mControllerButtonReleaseHandlers{ "onControllerButtonRelease" }; + Container::EngineHandlerList mActionHandlers{ "onInputAction" }; + Container::EngineHandlerList mTouchpadPressed{ "onTouchPress" }; + Container::EngineHandlerList mTouchpadReleased{ "onTouchRelease" }; + Container::EngineHandlerList mTouchpadMoved{ "onTouchMove" }; }; } diff --git a/apps/openmw/mwlua/menuscripts.hpp b/apps/openmw/mwlua/menuscripts.hpp index befa76a3b2..8721224413 100644 --- a/apps/openmw/mwlua/menuscripts.hpp +++ b/apps/openmw/mwlua/menuscripts.hpp @@ -45,7 +45,8 @@ namespace MWLua void uiModeChanged() { callEngineHandlers(mUiModeChanged); } private: - MWLua::InputProcessor mInputProcessor; + friend class MWLua::InputProcessor; + MWLua::InputProcessor mInputProcessor; EngineHandlerList mOnFrameHandlers{ "onFrame" }; EngineHandlerList mStateChanged{ "onStateChanged" }; EngineHandlerList mConsoleCommandHandlers{ "onConsoleCommand" }; diff --git a/apps/openmw/mwlua/playerscripts.hpp b/apps/openmw/mwlua/playerscripts.hpp index bc3bee15ca..ea7baccb76 100644 --- a/apps/openmw/mwlua/playerscripts.hpp +++ b/apps/openmw/mwlua/playerscripts.hpp @@ -48,7 +48,8 @@ namespace MWLua } private: - InputProcessor mInputProcessor; + friend class MWLua::InputProcessor; + InputProcessor mInputProcessor; EngineHandlerList mConsoleCommandHandlers{ "onConsoleCommand" }; EngineHandlerList mOnFrameHandlers{ "onFrame" }; EngineHandlerList mQuestUpdate{ "onQuestUpdate" }; diff --git a/components/lua/scriptscontainer.hpp b/components/lua/scriptscontainer.hpp index b3fb0bd376..631b1e58a8 100644 --- a/components/lua/scriptscontainer.hpp +++ b/components/lua/scriptscontainer.hpp @@ -157,8 +157,7 @@ namespace LuaUtil void collectStats(std::vector& stats) const; static int64_t getInstanceCount() { return sInstanceCount; } - public: // TODO: public to be available to MWLua::InputProcessor. Consider other ways of reusing engine handlers - // between containers + protected: struct Handler { int mScriptId; @@ -199,7 +198,6 @@ namespace LuaUtil // a public function (see how ScriptsContainer::update is implemented) that calls `callEngineHandlers`. void registerEngineHandlers(std::initializer_list handlers); - protected: const std::string mNamePrefix; LuaUtil::LuaState& mLua;