Started initial performance testing on Lua-based keyboard controller

This commit is contained in:
Alexander Bock
2014-10-13 17:24:11 +02:00
parent 0518e8cf02
commit 8884f4cc36
5 changed files with 55 additions and 10 deletions

View File

@@ -0,0 +1,4 @@
return {
w = function() print("w") end,
s = function() print("s") end
}

View File

@@ -309,7 +309,8 @@ bool OpenSpaceEngine::initialize() {
//DeviceIdentifier::init();
//DeviceIdentifier::ref().scanDevices();
_interactionHandler.setKeyboardController(new interaction::KeyboardControllerFixed);
//_interactionHandler.setKeyboardController(new interaction::KeyboardControllerFixed);
_interactionHandler.setKeyboardController(new interaction::KeyboardControllerLua);
_interactionHandler.setMouseController(new interaction::TrackballMouseController);
// Run start up scripts

View File

@@ -24,6 +24,12 @@
#include <openspace/interaction/interactionhandler.h>
#include <ghoul/misc/highresclock.h>
namespace {
const std::string _loggerCat = "InteractionHandler";
}
namespace openspace {
namespace interaction {
@@ -91,24 +97,28 @@ const Camera* const InteractionHandler::camera() const {
}
void InteractionHandler::keyboardCallback(int key, int action) {
if (_keyboardController)
_keyboardController->keyPressed(KeyAction(action), Keys(key));
if (_keyboardController) {
auto start = ghoul::HighResClock::now();
_keyboardController->keyPressed(KeyAction(action), Keys(key));
auto end = ghoul::HighResClock::now();
LINFO("Keyboard timing: " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() << "ns");
}
}
void InteractionHandler::mouseButtonCallback(int button, int action) {
if (_mouseController)
_mouseController->button(MouseAction(action), MouseButton(button));
_mouseController->button(MouseAction(action), MouseButton(button));
}
void InteractionHandler::mousePositionCallback(int x, int y) {
if (_mouseController)
// TODO Remap screen coordinates to [0,1]
_mouseController->move(float(x), float(y));
// TODO Remap screen coordinates to [0,1]
_mouseController->move(float(x), float(y));
}
void InteractionHandler::mouseScrollWheelCallback(int pos) {
if (_mouseController)
_mouseController->scrollWheel(float(pos));
_mouseController->scrollWheel(float(pos));
}
} // namespace interaction

View File

@@ -27,6 +27,11 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/time.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/lua/ghoul_lua.h>
#include <ghoul/misc/highresclock.h>
namespace openspace {
namespace interaction {
@@ -143,8 +148,33 @@ void KeyboardControllerFixed::keyPressed(KeyAction action, Keys key) {
*/
}
void KeyboardControllerLua::keyPressed(KeyAction action, Keys key)
{
void KeyboardControllerLua::keyPressed(KeyAction action, Keys key) {
std::string _loggerCat = "KeyboardControllerLua";
lua_State* s = luaL_newstate();
luaL_openlibs(s);
int status = luaL_loadfile(s, absPath("${SCRIPTS}/default_keybinding.lua").c_str());
if (status != LUA_OK) {
LERROR("Error loading script: '" << lua_tostring(s, -1) << "'");
return;
}
if (lua_pcall(s, 0, LUA_MULTRET, 0)) {
LERROR("Error executing script: " << lua_tostring(s, -1));
return;
}
auto start = ghoul::HighResClock::now();
lua_pushstring(s, "w");
lua_gettable(s, -2);
lua_pcall(s, 0, 0, 0);
auto end = ghoul::HighResClock::now();
LINFO("Keyboard timing: " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() << "ns");
}