mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 03:00:58 -06:00
Started initial performance testing on Lua-based keyboard controller
This commit is contained in:
Submodule ext/ghoul updated: 1f1386215e...7553b63a5b
4
scripts/default_keybinding.lua
Normal file
4
scripts/default_keybinding.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
return {
|
||||
w = function() print("w") end,
|
||||
s = function() print("s") end
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user