More work in preparing for lua-based keyboard controller

Modified ScriptManager to decouple adding libraries from registering libraries
Allowing ScriptManager to register libraries to other lua states as well
This commit is contained in:
Alexander Bock
2014-10-14 00:08:26 +02:00
parent 8884f4cc36
commit 86efb3573b
12 changed files with 366 additions and 224 deletions
@@ -44,24 +44,6 @@ public:
void setHandler(InteractionHandler* handler);
protected:
SceneGraphNode* focusNode() const;
Camera* camera() const;
double deltaTime() const;
void orbitDelta(const glm::quat& rotation);
void rotateDelta(const glm::quat& rotation);
void distanceDelta(const PowerScaledScalar& distance);
void lookAt(const glm::quat& rotation);
void setRotation(const glm::quat& rotation);
private:
InteractionHandler* _handler;
};
@@ -62,6 +62,19 @@ public:
void mousePositionCallback(int x, int y);
void mouseScrollWheelCallback(int pos);
double deltaTime() const;
void orbitDelta(const glm::quat& rotation);
void rotateDelta(const glm::quat& rotation);
void distanceDelta(const PowerScaledScalar& distance);
void lookAt(const glm::quat& rotation);
void setRotation(const glm::quat& rotation);
private:
friend class Controller;
@@ -34,17 +34,20 @@ namespace interaction {
class KeyboardController : public Controller {
public:
virtual void keyPressed(KeyAction action, Keys key) = 0;
virtual void keyPressed(KeyAction action, Key key, KeyModifier modifier) = 0;
};
class KeyboardControllerFixed : public KeyboardController {
public:
void keyPressed(KeyAction action, Keys key);
void keyPressed(KeyAction action, Key key, KeyModifier modifier);
};
class KeyboardControllerLua : public KeyboardController {
public:
void keyPressed(KeyAction action, Keys key);
void keyPressed(KeyAction action, Key key, KeyModifier modifier);
protected:
std::string keyToString(Key key, KeyModifier mod) const;
};
} // namespace interaction
+10 -6
View File
@@ -36,7 +36,15 @@ enum class KeyAction {
Repeat = SGCT_REPEAT
};
enum class Keys {
enum class KeyModifier {
None = 0,
Shift = GLFW_MOD_SHIFT,
Control = GLFW_MOD_CONTROL,
Alt = GLFW_MOD_ALT,
Super = GLFW_MOD_SUPER
};
enum class Key {
Unknown = SGCT_KEY_UNKNOWN,
Space = SGCT_KEY_SPACE,
Apostrophe = SGCT_KEY_APOSTROPHE,
@@ -157,11 +165,7 @@ enum class Keys {
RightAlt = SGCT_KEY_RIGHT_ALT,
RightSuper = SGCT_KEY_RIGHT_SUPER,
Menu = SGCT_KEY_MENU,
Last = SGCT_KEY_LAST,
Shift = LeftShift | RightShift,
Control = LeftControl | RightControl,
Alt = LeftAlt | RightAlt,
Super = LeftSuper | RightSuper
Last = SGCT_KEY_LAST
};
} // namespace interaction
+9 -3
View File
@@ -26,6 +26,7 @@
#define __SCRIPTENGINE_H__
#include <ghoul/lua/ghoul_lua.h>
#include <set>
/**
@@ -50,19 +51,24 @@ public:
};
ScriptEngine();
bool initialize();
void deinitialize();
bool addLibrary(const LuaLibrary& library);
void initializeLuaState(lua_State* state);
void addLibrary(const LuaLibrary& library);
bool hasLibrary(const std::string& name);
bool runScript(const std::string& script);
bool runScriptFile(const std::string& filename);
private:
bool registerLuaLibrary(lua_State* state, const LuaLibrary& library);
void addLibraryFunctions(lua_State* state, const LuaLibrary& library, bool replace);
bool isLibraryNameAllowed(const std::string& name);
void addLibraryFunctions(const LuaLibrary& library, bool replace);
void addBaseLibrary();
void remapPrintFunction();