mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 12:10:52 -06:00
- Some cleanup of LuaConsole
- Moved dedicated Lua commands into a visible property - Disallow non-ASCII characters - Remove unused KeyboardController - Remove unused DeviceIdentifier - Some cleanup of LogFactory - Move and use documentation into the class
This commit is contained in:
@@ -90,13 +90,13 @@ void mainInitFunc() {
|
||||
LDEBUG("Initializing OpenGL in OpenSpace Engine started");
|
||||
OsEng.initializeGL();
|
||||
LDEBUG("Initializing OpenGL in OpenSpace Engine finished");
|
||||
|
||||
// Find if we have at least one OpenVR window
|
||||
// Save reference to first OpenVR window, which is the one we will copy to the HMD.
|
||||
for (size_t i = 0; i < SgctEngine->getNumberOfWindows(); ++i) {
|
||||
if (SgctEngine->getWindowPtr(i)->checkIfTagExists("OpenVR")) {
|
||||
|
||||
// Find if we have at least one OpenVR window
|
||||
// Save reference to first OpenVR window, which is the one we will copy to the HMD.
|
||||
for (size_t i = 0; i < SgctEngine->getNumberOfWindows(); ++i) {
|
||||
if (SgctEngine->getWindowPtr(i)->checkIfTagExists("OpenVR")) {
|
||||
#ifdef OPENVR_SUPPORT
|
||||
FirstOpenVRWindow = SgctEngine->getWindowPtr(i);
|
||||
FirstOpenVRWindow = SgctEngine->getWindowPtr(i);
|
||||
|
||||
// If we have an OpenVRWindow, initialize OpenVR.
|
||||
sgct::SGCTOpenVR::initialize(
|
||||
@@ -109,8 +109,8 @@ void mainInitFunc() {
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the clear color for all non-linear projection viewports
|
||||
// @CLEANUP: Why is this necessary? We can set the clear color in the configuration
|
||||
@@ -142,10 +142,10 @@ void mainPostSyncPreDrawFunc() {
|
||||
OsEng.postSynchronizationPreDraw();
|
||||
|
||||
#ifdef OPENVR_SUPPORT
|
||||
if (FirstOpenVRWindow) {
|
||||
// Update pose matrices for all tracked OpenVR devices once per frame
|
||||
sgct::SGCTOpenVR::updatePoses();
|
||||
}
|
||||
if (FirstOpenVRWindow) {
|
||||
// Update pose matrices for all tracked OpenVR devices once per frame
|
||||
sgct::SGCTOpenVR::updatePoses();
|
||||
}
|
||||
#endif
|
||||
|
||||
LTRACE("main::postSynchronizationPreDraw(end)");
|
||||
@@ -167,10 +167,10 @@ void mainRenderFunc() {
|
||||
#ifdef OPENVR_SUPPORT
|
||||
bool currentWindowIsHMD = FirstOpenVRWindow == _sgctEngine->getCurrentWindowPtr();
|
||||
if (sgct::SGCTOpenVR::isHMDActive() && currentWindowIsHMD) {
|
||||
projectionMatrix = sgct::SGCTOpenVR::getHMDCurrentViewProjectionMatrix(
|
||||
projectionMatrix = sgct::SGCTOpenVR::getHMDCurrentViewProjectionMatrix(
|
||||
_sgctEngine->getCurrentFrustumMode()
|
||||
);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (SgctEngine->isMaster()) {
|
||||
@@ -187,10 +187,10 @@ void mainPostDrawFunc() {
|
||||
LTRACE("main::mainPostDrawFunc(begin)");
|
||||
|
||||
#ifdef OPENVR_SUPPORT
|
||||
if (FirstOpenVRWindow) {
|
||||
// Copy the first OpenVR window to the HMD
|
||||
sgct::SGCTOpenVR::copyWindowToHMD(FirstOpenVRWindow);
|
||||
}
|
||||
if (FirstOpenVRWindow) {
|
||||
// Copy the first OpenVR window to the HMD
|
||||
sgct::SGCTOpenVR::copyWindowToHMD(FirstOpenVRWindow);
|
||||
}
|
||||
#endif
|
||||
|
||||
OsEng.postDraw();
|
||||
@@ -395,6 +395,7 @@ int main_main(int argc, char** argv) {
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
return main_main(argc, argv);
|
||||
// We wrap the actual main function in a try catch block so that we can get and print
|
||||
// some additional information in case an exception is raised
|
||||
try {
|
||||
@@ -406,7 +407,12 @@ int main(int argc, char** argv) {
|
||||
LogMgr.flushLogs();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
catch (const ghoul::AssertionException& e) {
|
||||
// We don't want to catch the assertion exception as we won't be able to add a
|
||||
// breakpoint for debugging
|
||||
LFATALC("Assertion failed", e.what());
|
||||
throw;
|
||||
} catch (const std::exception& e) {
|
||||
LFATALC("Exception", e.what());
|
||||
LogMgr.flushLogs();
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -28,12 +28,16 @@
|
||||
#include <memory>
|
||||
|
||||
namespace ghoul {
|
||||
|
||||
class Dictionary;
|
||||
namespace logging { class Log; }
|
||||
}
|
||||
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
/**
|
||||
* This function provides the capabilities to create a new ghoul::logging::Log from the
|
||||
* provided ghoul::Dictionary%. The Dictionary must at least contain a <code>Type</code>
|
||||
@@ -44,15 +48,24 @@ namespace openspace {
|
||||
* created . Both logs can be customized using the <code>Append</code>,
|
||||
* <code>TimeStamping</code>, <code>DateStamping</code>, <code>CategoryStamping</code>,
|
||||
* and <code>LogLevelStamping</code> values.
|
||||
* \param dictionary The dictionary from which the ghoul::logging::Log should be created
|
||||
*
|
||||
* \param dictionary The dictionary from which the ghoul::logging::Log should be created
|
||||
* \return The created ghoul::logging::Log
|
||||
* \post The return value will not be <code>nullptr</code>
|
||||
* \throw ghoul::RuntimeError If there was an error creating the ghoul::logging::Log
|
||||
* \sa ghoul::logging::TextLeg
|
||||
* \sa ghoul::logging::HTMLLog
|
||||
* \post The return value will not be <code>nullptr</code>
|
||||
* \throw ghoul::RuntimeError If there was an error creating the ghoul::logging::Log
|
||||
* \sa ghoul::logging::TextLog
|
||||
* \sa ghoul::logging::HTMLLog
|
||||
*/
|
||||
std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictionary);
|
||||
|
||||
/**
|
||||
* Returns the Documentation that describes a Dictionary used to create a log by using the
|
||||
* function createLog.
|
||||
* \return The Documentation that describes an acceptable Dictionary for the method
|
||||
* createLog
|
||||
*/
|
||||
documentation::Documentation LogFactoryDocumentation();
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___LOGFACTORY___H__
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_CORE___DEVICEIDENTIFIER___H__
|
||||
#define __OPENSPACE_CORE___DEVICEIDENTIFIER___H__
|
||||
|
||||
// std includes
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
#define MAXDEVICES 16
|
||||
|
||||
enum class InputDevice {NONE, UNKNOWN, SPACENAVIGATOR, XBOX};
|
||||
|
||||
class DeviceIdentifier {
|
||||
public:
|
||||
static DeviceIdentifier& ref();
|
||||
virtual ~DeviceIdentifier();
|
||||
|
||||
static void init();
|
||||
static void deinit();
|
||||
static bool isInitialized();
|
||||
|
||||
void scanDevices();
|
||||
const int numberOfDevices() const;
|
||||
const InputDevice type(const int device) const;
|
||||
|
||||
void update();
|
||||
void update(const int device);
|
||||
|
||||
const int getButtons(const int device, unsigned char **buttons = nullptr) const;
|
||||
const int getAxes(const int device, float **axespos = nullptr) const;
|
||||
void get(const int device, unsigned char **buttons, float **axespos) const;
|
||||
|
||||
private:
|
||||
// singleton
|
||||
static DeviceIdentifier* this_;
|
||||
DeviceIdentifier(void);
|
||||
DeviceIdentifier(const DeviceIdentifier& src);
|
||||
DeviceIdentifier& operator=(const DeviceIdentifier& rhs);
|
||||
|
||||
|
||||
// member variables
|
||||
int devices_;
|
||||
std::array<InputDevice, MAXDEVICES> inputDevice_;
|
||||
std::array<int, MAXDEVICES> numberOfAxes_;
|
||||
std::array<int, MAXDEVICES> numberOfButtons_;
|
||||
std::array<float *, MAXDEVICES> axesPos_;
|
||||
std::array<unsigned char *, MAXDEVICES> buttons_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___DEVICEIDENTIFIER___H__
|
||||
@@ -25,7 +25,6 @@
|
||||
#ifndef __OPENSPACE_CORE___INTERACTIONHANDLER___H__
|
||||
#define __OPENSPACE_CORE___INTERACTIONHANDLER___H__
|
||||
|
||||
#include <openspace/interaction/keyboardcontroller.h>
|
||||
#include <openspace/interaction/interactionmode.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#ifndef __OPENSPACE_CORE___INTERACTIONMODE___H__
|
||||
#define __OPENSPACE_CORE___INTERACTIONMODE___H__
|
||||
|
||||
#include <openspace/interaction/keyboardcontroller.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/util/mouse.h>
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_CORE___KEYBOARDCONTROLLER___H__
|
||||
#define __OPENSPACE_CORE___KEYBOARDCONTROLLER___H__
|
||||
|
||||
#include <openspace/interaction/controller.h>
|
||||
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
class KeyboardController : public Controller {
|
||||
public:
|
||||
virtual ~KeyboardController() {};
|
||||
virtual void keyPressed(KeyAction action, Key key, KeyModifier modifier) = 0;
|
||||
};
|
||||
|
||||
class KeyboardControllerFixed : public KeyboardController {
|
||||
public:
|
||||
void keyPressed(KeyAction action, Key key, KeyModifier modifier);
|
||||
};
|
||||
|
||||
class KeyboardControllerLua : public KeyboardController {
|
||||
public:
|
||||
void keyPressed(KeyAction action, Key key, KeyModifier modifier);
|
||||
|
||||
protected:
|
||||
std::string keyToString(Key key, KeyModifier mod) const;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___KEYBOARDCONTROLLER___H__
|
||||
@@ -25,9 +25,10 @@
|
||||
#ifndef __OPENSPACE_CORE___LUACONSOLE___H__
|
||||
#define __OPENSPACE_CORE___LUACONSOLE___H__
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
#include <string>
|
||||
@@ -35,50 +36,35 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class LuaConsole {
|
||||
class LuaConsole : public properties::PropertyOwner {
|
||||
public:
|
||||
LuaConsole();
|
||||
|
||||
void initialize();
|
||||
void deinitialize();
|
||||
|
||||
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
bool keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
void charCallback(unsigned int codepoint, KeyModifier modifier);
|
||||
|
||||
void render();
|
||||
|
||||
Key commandInputButton();
|
||||
|
||||
bool isVisible() const;
|
||||
void setVisible(bool visible);
|
||||
bool isRemoteScripting() const;
|
||||
void setRemoteScripting(bool remoteScripting);
|
||||
|
||||
void toggleMode();
|
||||
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
|
||||
|
||||
private:
|
||||
void parallelConnectionChanged(const ParallelConnection::Status& status);
|
||||
void addToCommand(std::string c);
|
||||
std::string UnicodeToUTF8(unsigned int codepoint);
|
||||
|
||||
properties::BoolProperty _isVisible;
|
||||
bool _remoteScripting;
|
||||
|
||||
size_t _inputPosition;
|
||||
std::vector<std::string> _commandsHistory;
|
||||
size_t _activeCommand;
|
||||
std::vector<std::string> _commands;
|
||||
|
||||
std::string _filename;
|
||||
|
||||
struct {
|
||||
int lastIndex;
|
||||
bool hasInitialValue;
|
||||
std::string initialValue;
|
||||
} _autoCompleteInfo;
|
||||
|
||||
bool _isVisible;
|
||||
bool _remoteScripting;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -218,7 +218,6 @@ struct KeyWithModifier {
|
||||
KeyWithModifier stringToKey(std::string str);
|
||||
bool operator<(const KeyWithModifier& lhs, const KeyWithModifier& rhs);
|
||||
|
||||
|
||||
static const std::map<std::string, KeyModifier> KeyModifierMapping = {
|
||||
{ "SHIFT", KeyModifier::Shift },
|
||||
{ "ALT", KeyModifier::Alt },
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ void SpiceRotation::update(const UpdateData& data) {
|
||||
data.time
|
||||
);
|
||||
}
|
||||
catch (...) {
|
||||
catch (const SpiceManager::SpiceException&) {
|
||||
_matrix = glm::dmat3(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,13 +40,10 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/engine/wrapper/sgctwindowwrapper.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/engine/wrapper/windowwrapper.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/controller.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/deviceidentifier.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/interactionhandler.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/interactionmode.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/interactionhandler_lua.inl
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/keyboardcontroller.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/luaconsole.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/luaconsole_lua.inl
|
||||
${OPENSPACE_BASE_DIR}/src/mission/mission.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/mission/missionmanager.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/mission/missionmanager_lua.inl
|
||||
@@ -177,10 +174,8 @@ set(OPENSPACE_HEADER
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/engine/wrapper/sgctwindowwrapper.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/engine/wrapper/windowwrapper.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/interaction/controller.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/interaction/deviceidentifier.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/interaction/interactionhandler.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/interaction/interactionmode.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/interaction/keyboardcontroller.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/interaction/luaconsole.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/mission/mission.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/mission/missionmanager.h
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
|
||||
#include <openspace/documentation/documentationengine.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/logfactory.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
#include <openspace/mission/mission.h>
|
||||
#include <openspace/mission/missionmanager.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
@@ -51,6 +51,7 @@ namespace openspace {
|
||||
|
||||
void registerCoreClasses(documentation::DocumentationEngine& engine) {
|
||||
engine.addDocumentation(ConfigurationManager::Documentation());
|
||||
engine.addDocumentation(LogFactoryDocumentation());
|
||||
engine.addDocumentation(Mission::Documentation());
|
||||
engine.addDocumentation(Renderable::Documentation());
|
||||
engine.addDocumentation(Rotation::Documentation());
|
||||
@@ -69,7 +70,6 @@ void registerCoreClasses(scripting::ScriptEngine& engine) {
|
||||
engine.addLibrary(Scene::luaLibrary());
|
||||
engine.addLibrary(Time::luaLibrary());
|
||||
engine.addLibrary(interaction::InteractionHandler::luaLibrary());
|
||||
engine.addLibrary(LuaConsole::luaLibrary());
|
||||
engine.addLibrary(ParallelConnection::luaLibrary());
|
||||
engine.addLibrary(ModuleEngine::luaLibrary());
|
||||
engine.addLibrary(scripting::ScriptScheduler::luaLibrary());
|
||||
|
||||
@@ -225,25 +225,25 @@ TestResult ReferencingVerifier::operator()(const ghoul::Dictionary& dictionary,
|
||||
[this](const Documentation& doc) { return doc.id == identifier; }
|
||||
);
|
||||
|
||||
if (it == documentations.end()) {
|
||||
return { false, { { key, TestResult::Offense::Reason::UnknownIdentifier } } };
|
||||
ghoul_assert(
|
||||
it != documentations.end(),
|
||||
"Did not find referencing identifier '" + identifier + "'"
|
||||
);
|
||||
|
||||
ghoul::Dictionary d = dictionary.value<ghoul::Dictionary>(key);
|
||||
TestResult res = testSpecification(*it, d);
|
||||
|
||||
// Add the 'key' as a prefix to make the offender a fully qualified identifer
|
||||
for (TestResult::Offense& s : res.offenses) {
|
||||
s.offender = key + "." + s.offender;
|
||||
}
|
||||
else {
|
||||
ghoul::Dictionary d = dictionary.value<ghoul::Dictionary>(key);
|
||||
TestResult res = testSpecification(*it, d);
|
||||
|
||||
// Add the 'key' as a prefix to make the offender a fully qualified identifer
|
||||
for (TestResult::Offense& s : res.offenses) {
|
||||
s.offender = key + "." + s.offender;
|
||||
}
|
||||
|
||||
// Add the 'key' as a prefix to make the warning a fully qualified identifer
|
||||
for (TestResult::Warning& w : res.warnings) {
|
||||
w.offender = key + "." + w.offender;
|
||||
}
|
||||
|
||||
return res;
|
||||
// Add the 'key' as a prefix to make the warning a fully qualified identifer
|
||||
for (TestResult::Warning& w : res.warnings) {
|
||||
w.offender = key + "." + w.offender;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
return res;
|
||||
|
||||
@@ -105,31 +105,8 @@ documentation::Documentation ConfigurationManager::Documentation() {
|
||||
new TableVerifier({
|
||||
{
|
||||
"*",
|
||||
new TableVerifier({
|
||||
{
|
||||
ConfigurationManager::PartType,
|
||||
new StringInListVerifier({
|
||||
// List from logfactory.cpp::createLog
|
||||
"text", "html"
|
||||
}),
|
||||
"The type of the new log to be generated."
|
||||
},
|
||||
{
|
||||
ConfigurationManager::PartFile,
|
||||
new StringVerifier,
|
||||
"The filename to which the log will be written."
|
||||
},
|
||||
{
|
||||
ConfigurationManager::PartAppend,
|
||||
new BoolVerifier,
|
||||
"Determines whether the file will be cleared at "
|
||||
"startup or if the contents will be appended to "
|
||||
"previous runs.",
|
||||
Optional::Yes
|
||||
}
|
||||
}),
|
||||
"Additional log files",
|
||||
Optional::Yes
|
||||
new ReferencingVerifier("core_logfactory"),
|
||||
"Additional log files"
|
||||
}
|
||||
}),
|
||||
"Per default, log messages are written to the console, the "
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
|
||||
#include <openspace/engine/logfactory.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -51,37 +54,105 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation LogFactoryDocumentation() {
|
||||
using namespace documentation;
|
||||
|
||||
return {
|
||||
"LogFactory",
|
||||
"core_logfactory",
|
||||
{
|
||||
{
|
||||
keyType,
|
||||
new StringInListVerifier({
|
||||
// List from createLog
|
||||
valueTextLog, valueHtmlLog
|
||||
}),
|
||||
"The type of the new log to be generated."
|
||||
},
|
||||
{
|
||||
keyFilename,
|
||||
new StringVerifier,
|
||||
"The filename to which the log will be written."
|
||||
},
|
||||
{
|
||||
keyAppend,
|
||||
new BoolVerifier,
|
||||
"Determines whether the file will be cleared at startup or if the "
|
||||
"contents will be appended to previous runs.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
keyTimeStamping,
|
||||
new BoolVerifier,
|
||||
"Determines whether the log entires should be stamped with the time at "
|
||||
"which the message was logged.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
keyDateStamping,
|
||||
new BoolVerifier,
|
||||
"Determines whether the log entries should be stamped with the date at "
|
||||
"which the message was logged.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
keyCategoryStamping,
|
||||
new BoolVerifier,
|
||||
"Determines whether the log entries should be stamped with the "
|
||||
"category that creates the log message.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
keyLogLevelStamping,
|
||||
new BoolVerifier,
|
||||
"Determines whether the log entries should be stamped with the log level "
|
||||
"that was used to create the log message.",
|
||||
Optional::Yes
|
||||
}
|
||||
},
|
||||
Exhaustive::Yes
|
||||
};
|
||||
}
|
||||
|
||||
std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictionary) {
|
||||
using namespace std::string_literals;
|
||||
std::string type;
|
||||
bool typeSuccess = dictionary.getValue(keyType, type);
|
||||
if (!typeSuccess) {
|
||||
throw ghoul::RuntimeError(
|
||||
"Requested log did not contain key '"s + keyType + "'", "LogFactory"
|
||||
);
|
||||
}
|
||||
|
||||
std::string filename;
|
||||
bool filenameSuccess = dictionary.getValue(keyFilename, filename);
|
||||
if (!filenameSuccess) {
|
||||
throw ghoul::RuntimeError(
|
||||
"Requested log did not contain key '"s + keyFilename + "'", "LogFactory"
|
||||
);
|
||||
}
|
||||
filename = absPath(filename);
|
||||
documentation::testSpecificationAndThrow(
|
||||
LogFactoryDocumentation(),
|
||||
dictionary,
|
||||
"LogFactory"
|
||||
);
|
||||
|
||||
// 'type' and 'filename' are required keys
|
||||
std::string type = dictionary.value<std::string>(keyType);
|
||||
std::string filename = absPath(dictionary.value<std::string>(keyFilename));
|
||||
|
||||
// the rest are optional
|
||||
bool append = true;
|
||||
dictionary.getValue(keyAppend, append);
|
||||
if (dictionary.hasKeyAndValue<bool>(keyAppend)) {
|
||||
dictionary.value<bool>(keyAppend);
|
||||
}
|
||||
bool timeStamp = true;
|
||||
dictionary.getValue(keyTimeStamping, timeStamp);
|
||||
if (dictionary.hasKeyAndValue<bool>(keyTimeStamping)) {
|
||||
dictionary.value<bool>(keyTimeStamping);
|
||||
}
|
||||
bool dateStamp = true;
|
||||
dictionary.getValue(keyDateStamping, dateStamp);
|
||||
if (dictionary.hasKeyAndValue<bool>(keyDateStamping)) {
|
||||
dictionary.value<bool>(keyDateStamping);
|
||||
}
|
||||
bool categoryStamp = true;
|
||||
dictionary.getValue(keyCategoryStamping, categoryStamp);
|
||||
if (dictionary.hasKeyAndValue<bool>(keyCategoryStamping)) {
|
||||
dictionary.value<bool>(keyCategoryStamping);
|
||||
}
|
||||
bool logLevelStamp = true;
|
||||
dictionary.getValue(keyLogLevelStamping, logLevelStamp);
|
||||
if (dictionary.hasKeyAndValue<bool>(keyLogLevelStamping)) {
|
||||
dictionary.value<bool>(keyLogLevelStamping);
|
||||
}
|
||||
std::string logLevel;
|
||||
dictionary.getValue(keyLogLevel, logLevel);
|
||||
if (dictionary.hasKeyAndValue<std::string>(keyLogLevel)) {
|
||||
dictionary.value<std::string>(keyLogLevel);
|
||||
}
|
||||
|
||||
|
||||
using Append = ghoul::logging::TextLog::Append;
|
||||
using TimeStamping = ghoul::logging::Log::TimeStamping;
|
||||
@@ -90,7 +161,6 @@ std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictiona
|
||||
using LogLevelStamping = ghoul::logging::Log::LogLevelStamping;
|
||||
|
||||
if (type == valueHtmlLog) {
|
||||
|
||||
std::vector<std::string> cssFiles{absPath(BootstrapPath), absPath(CssPath)};
|
||||
std::vector<std::string> jsFiles{absPath(JsPath)};
|
||||
|
||||
@@ -102,7 +172,8 @@ std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictiona
|
||||
dateStamp ? DateStamping::Yes : DateStamping::No,
|
||||
categoryStamp ? CategoryStamping::Yes : CategoryStamping::No,
|
||||
logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No,
|
||||
cssFiles, jsFiles
|
||||
cssFiles,
|
||||
jsFiles
|
||||
);
|
||||
}
|
||||
else {
|
||||
@@ -141,11 +212,7 @@ std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictiona
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError(
|
||||
"Log with type '" + type + "' did not name a valid log", "LogFactory"
|
||||
);
|
||||
}
|
||||
ghoul_assert(false, "Missing case in the documentation for LogFactory");
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <openspace/engine/syncengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/keyboardcontroller.h>
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
#include <openspace/mission/missionmanager.h>
|
||||
#include <openspace/network/networkengine.h>
|
||||
@@ -47,8 +46,10 @@
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/scripting/scriptscheduler.h>
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/scene/rotation.h>
|
||||
#include <openspace/scene/scale.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/timemanager.h>
|
||||
@@ -235,6 +236,8 @@ void OpenSpaceEngine::create(int argc, char** argv,
|
||||
LDEBUG("Creating OpenSpaceEngine");
|
||||
_engine = new OpenSpaceEngine(std::string(argv[0]), std::move(windowWrapper));
|
||||
|
||||
registerCoreClasses(DocEng);
|
||||
|
||||
// Query modules for commandline arguments
|
||||
_engine->gatherCommandlineArguments();
|
||||
|
||||
@@ -341,7 +344,6 @@ void OpenSpaceEngine::create(int argc, char** argv,
|
||||
// Register modules
|
||||
_engine->_moduleEngine->initialize();
|
||||
|
||||
registerCoreClasses(DocEng);
|
||||
// After registering the modules, the documentations for the available classes
|
||||
// can be added as well
|
||||
for (OpenSpaceModule* m : _engine->_moduleEngine->modules()) {
|
||||
@@ -938,8 +940,7 @@ void OpenSpaceEngine::render(const glm::mat4& viewMatrix,
|
||||
bool showGui = _windowWrapper->hasGuiWindow() ? _windowWrapper->isGuiWindow() : true;
|
||||
if (showGui && _windowWrapper->isMaster() && _windowWrapper->isRegularRendering()) {
|
||||
_renderEngine->renderScreenLog();
|
||||
if (_console->isVisible())
|
||||
_console->render();
|
||||
_console->render();
|
||||
}
|
||||
|
||||
if (_shutdown.inShutdown) {
|
||||
@@ -968,25 +969,18 @@ void OpenSpaceEngine::postDraw() {
|
||||
|
||||
void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) {
|
||||
for (const auto& func : _moduleCallbacks.keyboard) {
|
||||
bool consumed = func(key, mod, action);
|
||||
const bool consumed = func(key, mod, action);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// @CLEANUP: Remove the commandInputButton and replace with a method just based
|
||||
// on Lua by binding a key to the Lua script toggling the console ---abock
|
||||
if (key == _console->commandInputButton()) {
|
||||
if (action == KeyAction::Press) {
|
||||
_console->toggleMode();
|
||||
}
|
||||
} else if (!_console->isVisible()) {
|
||||
// @CLEANUP: Make the interaction handler return whether a key has been consumed
|
||||
// and then pass it on to the console ---abock
|
||||
_interactionHandler->keyboardCallback(key, mod, action);
|
||||
} else {
|
||||
_console->keyboardCallback(key, mod, action);
|
||||
|
||||
const bool consoleConsumed = _console->keyboardCallback(key, mod, action);
|
||||
if (consoleConsumed) {
|
||||
return;
|
||||
}
|
||||
|
||||
_interactionHandler->keyboardCallback(key, mod, action);
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier) {
|
||||
@@ -997,9 +991,7 @@ void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier)
|
||||
}
|
||||
}
|
||||
|
||||
if (_console->isVisible()) {
|
||||
_console->charCallback(codepoint, modifier);
|
||||
}
|
||||
_console->charCallback(codepoint, modifier);
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action) {
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <openspace/interaction/deviceidentifier.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
DeviceIdentifier* DeviceIdentifier::this_ = nullptr;
|
||||
|
||||
DeviceIdentifier::DeviceIdentifier() {
|
||||
|
||||
// scan for devices on init
|
||||
devices_ = 0;
|
||||
for(int i = 0; i < MAXDEVICES; ++i) {
|
||||
inputDevice_[i] = InputDevice::NONE;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceIdentifier::~DeviceIdentifier() {
|
||||
|
||||
// deallocates memory on exit
|
||||
for(int i = 0; i < MAXDEVICES; ++i) {
|
||||
if(inputDevice_[i] != InputDevice::NONE) {
|
||||
delete axesPos_[i];
|
||||
delete buttons_[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceIdentifier::init() {
|
||||
assert( ! this_);
|
||||
this_ = new DeviceIdentifier();
|
||||
}
|
||||
|
||||
void DeviceIdentifier::deinit() {
|
||||
assert(this_);
|
||||
delete this_;
|
||||
this_ = nullptr;
|
||||
}
|
||||
|
||||
DeviceIdentifier& DeviceIdentifier::ref() {
|
||||
assert(this_);
|
||||
return *this_;
|
||||
}
|
||||
|
||||
bool DeviceIdentifier::isInitialized() {
|
||||
return this_ != nullptr;
|
||||
}
|
||||
|
||||
void DeviceIdentifier::scanDevices() {
|
||||
assert(this_);
|
||||
|
||||
// sgct/glfw supports 16 joysticks, scans all of them
|
||||
for (int i = 0; i < MAXDEVICES; ++i)
|
||||
{
|
||||
void* joystickName = NULL;
|
||||
if( joystickName != NULL ) {
|
||||
|
||||
// allocate
|
||||
axesPos_[i] = new float[numberOfAxes_[i]];
|
||||
buttons_[i] = new unsigned char[numberOfButtons_[i]];
|
||||
|
||||
// increment the device count
|
||||
++devices_;
|
||||
|
||||
// identify what device it is
|
||||
if(numberOfAxes_[i] == 6 && numberOfButtons_[i] == 10) {
|
||||
printf("XBOX controller ");
|
||||
inputDevice_[i] = InputDevice::XBOX;
|
||||
} else if(numberOfAxes_[i] == 6 && numberOfButtons_[i] == 4) {
|
||||
printf("SPACENAVIGATOR ");
|
||||
inputDevice_[i] = InputDevice::SPACENAVIGATOR;
|
||||
} else {
|
||||
printf("UNKNOWN device ");
|
||||
inputDevice_[i] = InputDevice::UNKNOWN;
|
||||
}
|
||||
printf("found at position %i, b=%i, a=%i\n", i, numberOfButtons_[i], numberOfAxes_[i]);
|
||||
|
||||
|
||||
} else {
|
||||
inputDevice_[i] = InputDevice::NONE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const int DeviceIdentifier::numberOfDevices() const {
|
||||
assert(this_);
|
||||
return devices_;
|
||||
}
|
||||
|
||||
const InputDevice DeviceIdentifier::type(const int device) const {
|
||||
assert(this_);
|
||||
return inputDevice_[device];
|
||||
}
|
||||
|
||||
void DeviceIdentifier::update() {
|
||||
assert(this_);
|
||||
for(int i = 0; i < devices_; ++i) {
|
||||
update(i);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceIdentifier::update(const int device) {
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
}
|
||||
}
|
||||
|
||||
const int DeviceIdentifier::getButtons(const int device, unsigned char **buttons) const {
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
if(buttons)
|
||||
*buttons = buttons_[device];
|
||||
return numberOfButtons_[device];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int DeviceIdentifier::getAxes(const int device, float **axespos) const {
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
if(axespos)
|
||||
*axespos = axesPos_[device];
|
||||
return numberOfAxes_[device];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DeviceIdentifier::get(const int device, unsigned char **buttons, float **axespos) const {
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
*axespos = axesPos_[device];
|
||||
*buttons = buttons_[device];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <openspace/interaction/interactionmode.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
@@ -50,19 +51,19 @@
|
||||
#include <fstream>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "InteractionHandler";
|
||||
const char* _loggerCat = "InteractionHandler";
|
||||
|
||||
const std::string KeyFocus = "Focus";
|
||||
const std::string KeyPosition = "Position";
|
||||
const std::string KeyRotation = "Rotation";
|
||||
const char* KeyFocus = "Focus";
|
||||
const char* KeyPosition = "Position";
|
||||
const char* KeyRotation = "Rotation";
|
||||
|
||||
const std::string MainTemplateFilename = "${OPENSPACE_DATA}/web/keybindings/main.hbs";
|
||||
const std::string KeybindingTemplateFilename = "${OPENSPACE_DATA}/web/keybindings/keybinding.hbs";
|
||||
const std::string HandlebarsFilename = "${OPENSPACE_DATA}/web/common/handlebars-v4.0.5.js";
|
||||
const std::string JsFilename = "${OPENSPACE_DATA}/web/keybindings/script.js";
|
||||
const std::string BootstrapFilename = "${OPENSPACE_DATA}/web/common/bootstrap.min.css";
|
||||
const std::string CssFilename = "${OPENSPACE_DATA}/web/common/style.css";
|
||||
}
|
||||
const char* MainTemplateFilename = "${OPENSPACE_DATA}/web/keybindings/main.hbs";
|
||||
const char* KeybindingTemplateFilename = "${OPENSPACE_DATA}/web/keybindings/keybinding.hbs";
|
||||
const char* HandlebarsFilename = "${OPENSPACE_DATA}/web/common/handlebars-v4.0.5.js";
|
||||
const char* JsFilename = "${OPENSPACE_DATA}/web/keybindings/script.js";
|
||||
const char* BootstrapFilename = "${OPENSPACE_DATA}/web/common/bootstrap.min.css";
|
||||
const char* CssFilename = "${OPENSPACE_DATA}/web/common/style.css";
|
||||
} // namespace
|
||||
|
||||
#include "interactionhandler_lua.inl"
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
|
||||
@@ -1,329 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/interaction/keyboardcontroller.h>
|
||||
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "KeyboardController";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
void KeyboardControllerFixed::keyPressed(KeyAction action, Key key, KeyModifier modifier) {
|
||||
// TODO package in script
|
||||
/*
|
||||
const float dt = static_cast<float>( _handler->deltaTime());
|
||||
if(action == KeyAction::Press|| action == KeyAction::Repeat) {
|
||||
const float speed = 2.75;
|
||||
if (key == Key::S) {
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::W) {
|
||||
glm::vec3 euler(-speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::A) {
|
||||
glm::vec3 euler(0.0, -speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::D) {
|
||||
glm::vec3 euler(0.0, speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::Q) {
|
||||
Time::ref().advanceTime(dt);
|
||||
}
|
||||
if (key == Key::Right) {
|
||||
glm::vec3 euler(0.0, speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Left) {
|
||||
glm::vec3 euler(0.0, -speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Down) {
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Up) {
|
||||
glm::vec3 euler(-speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::R) {
|
||||
PowerScaledScalar dist(-speed * dt, 0.0);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::F) {
|
||||
PowerScaledScalar dist(speed * dt, 0.0);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::T) {
|
||||
PowerScaledScalar dist(-speed * pow(10.0f, 11.0f) * dt, 0.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
//if (key == Keys::G) {
|
||||
// acc += 0.001;
|
||||
// PowerScaledScalar dist(speed * pow(10, 8 * acc) * dt, 0.0);
|
||||
// distanceDelta(dist);
|
||||
//}
|
||||
if (key == Key::Y) {
|
||||
PowerScaledScalar dist(-speed * 100.0f * dt, 6.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::H) {
|
||||
PowerScaledScalar dist(speed * 100.0f * dt, 6.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
|
||||
if (key == Key::KeypadSubtract) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] -= 0.5;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
if (key == Key::KeypadAdd) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] += 0.5;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (key == '1') {
|
||||
SceneGraphNode* node = getSceneGraphNode("sun");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 0.5, 10.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
if (key == '2') {
|
||||
SceneGraphNode* node = getSceneGraphNode("earth");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 1.0, 8.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
|
||||
if (key == '3') {
|
||||
SceneGraphNode* node = getSceneGraphNode("moon");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 0.5, 8.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void KeyboardControllerLua::keyPressed(KeyAction action, Key key, KeyModifier modifier) {
|
||||
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 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
lua_getfield(s, -1, keyToString(key, modifier).c_str());
|
||||
if (!lua_isnil(s, -1))
|
||||
lua_pcall(s, 0, 0, 0);
|
||||
else
|
||||
LINFO("Key not found");
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
LINFO("Keyboard timing: " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() << "ns");
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::string KeyboardControllerLua::keyToString(Key key, KeyModifier mod) const {
|
||||
std::string result = "";
|
||||
int intMod = static_cast<int>(mod);
|
||||
if (intMod & static_cast<int>(KeyModifier::Control))
|
||||
result += "CTRL + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Super))
|
||||
result += "SUPER + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Alt))
|
||||
result += "ALT + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Shift))
|
||||
result += "SHIFT + ";
|
||||
|
||||
switch (key) {
|
||||
case Key::Unknown: result += "Unknown"; break;
|
||||
case Key::Space: result += "Space"; break;
|
||||
case Key::Apostrophe: result += "Apostrophe"; break;
|
||||
case Key::Comma: result += "Comma"; break;
|
||||
case Key::Minus: result += "Minus"; break;
|
||||
case Key::Period: result += "Period"; break;
|
||||
case Key::Slash: result += "Slash"; break;
|
||||
case Key::Num0: result += "0"; break;
|
||||
case Key::Num1: result += "1"; break;
|
||||
case Key::Num2: result += "2"; break;
|
||||
case Key::Num3: result += "3"; break;
|
||||
case Key::Num4: result += "4"; break;
|
||||
case Key::Num5: result += "5"; break;
|
||||
case Key::Num6: result += "6"; break;
|
||||
case Key::Num7: result += "7"; break;
|
||||
case Key::Num8: result += "8"; break;
|
||||
case Key::Num9: result += "9"; break;
|
||||
case Key::SemiColon: result += "SemiColon"; break;
|
||||
case Key::Equal: result += "Equal"; break;
|
||||
case Key::A: result += "A"; break;
|
||||
case Key::B: result += "B"; break;
|
||||
case Key::C: result += "C"; break;
|
||||
case Key::D: result += "D"; break;
|
||||
case Key::E: result += "E"; break;
|
||||
case Key::F: result += "F"; break;
|
||||
case Key::G: result += "G"; break;
|
||||
case Key::H: result += "H"; break;
|
||||
case Key::I: result += "I"; break;
|
||||
case Key::J: result += "J"; break;
|
||||
case Key::K: result += "K"; break;
|
||||
case Key::L: result += "L"; break;
|
||||
case Key::M: result += "M"; break;
|
||||
case Key::N: result += "N"; break;
|
||||
case Key::O: result += "O"; break;
|
||||
case Key::P: result += "P"; break;
|
||||
case Key::Q: result += "Q"; break;
|
||||
case Key::R: result += "R"; break;
|
||||
case Key::S: result += "S"; break;
|
||||
case Key::T: result += "T"; break;
|
||||
case Key::U: result += "U"; break;
|
||||
case Key::V: result += "V"; break;
|
||||
case Key::W: result += "W"; break;
|
||||
case Key::X: result += "X"; break;
|
||||
case Key::Y: result += "Y"; break;
|
||||
case Key::Z: result += "Z"; break;
|
||||
case Key::LeftBracket: result += "LeftBracket"; break;
|
||||
case Key::BackSlash: result += "BackSlash"; break;
|
||||
case Key::RightBracket: result += "RightBracket"; break;
|
||||
case Key::GraveAccent: result += "GraveAccent"; break;
|
||||
case Key::World1: result += "World1"; break;
|
||||
case Key::World2: result += "World2"; break;
|
||||
case Key::Escape: result += "Escape"; break;
|
||||
case Key::Enter: result += "Enter"; break;
|
||||
case Key::Tab: result += "Tab"; break;
|
||||
case Key::BackSpace: result += "BackSpace"; break;
|
||||
case Key::Insert: result += "Insert"; break;
|
||||
case Key::Delete: result += "Delete"; break;
|
||||
case Key::Right: result += "Right"; break;
|
||||
case Key::Left: result += "Left"; break;
|
||||
case Key::Down: result += "Down"; break;
|
||||
case Key::Up: result += "Up"; break;
|
||||
case Key::PageUp: result += "PageUp"; break;
|
||||
case Key::PageDown: result += "PageDown"; break;
|
||||
case Key::Home: result += "Home"; break;
|
||||
case Key::End: result += "End"; break;
|
||||
case Key::CapsLock: result += "CapsLock"; break;
|
||||
case Key::ScrollLock: result += "ScrollLock"; break;
|
||||
case Key::NumLock: result += "NumLock"; break;
|
||||
case Key::PrintScreen: result += "PrintScreen"; break;
|
||||
case Key::Pause: result += "Pause"; break;
|
||||
case Key::F1: result += "F1"; break;
|
||||
case Key::F2: result += "F2"; break;
|
||||
case Key::F3: result += "F3"; break;
|
||||
case Key::F4: result += "F4"; break;
|
||||
case Key::F5: result += "F5"; break;
|
||||
case Key::F6: result += "F6"; break;
|
||||
case Key::F7: result += "F7"; break;
|
||||
case Key::F8: result += "F8"; break;
|
||||
case Key::F9: result += "F9"; break;
|
||||
case Key::F10: result += "F10"; break;
|
||||
case Key::F11: result += "F11"; break;
|
||||
case Key::F12: result += "F12"; break;
|
||||
case Key::F13: result += "F13"; break;
|
||||
case Key::F14: result += "F14"; break;
|
||||
case Key::F15: result += "F15"; break;
|
||||
case Key::F16: result += "F16"; break;
|
||||
case Key::F17: result += "F17"; break;
|
||||
case Key::F18: result += "F18"; break;
|
||||
case Key::F19: result += "F19"; break;
|
||||
case Key::F20: result += "F20"; break;
|
||||
case Key::F21: result += "F21"; break;
|
||||
case Key::F22: result += "F22"; break;
|
||||
case Key::F23: result += "F23"; break;
|
||||
case Key::F24: result += "F24"; break;
|
||||
case Key::F25: result += "F25"; break;
|
||||
case Key::Keypad0: result += "Keypad0"; break;
|
||||
case Key::Keypad1: result += "Keypad1"; break;
|
||||
case Key::Keypad2: result += "Keypad2"; break;
|
||||
case Key::Keypad3: result += "Keypad3"; break;
|
||||
case Key::Keypad4: result += "Keypad4"; break;
|
||||
case Key::Keypad5: result += "Keypad5"; break;
|
||||
case Key::Keypad6: result += "Keypad6"; break;
|
||||
case Key::Keypad7: result += "Keypad7"; break;
|
||||
case Key::Keypad8: result += "Keypad8"; break;
|
||||
case Key::Keypad9: result += "Keypad9"; break;
|
||||
case Key::KeypadDecimal: result += "KeypadDecimal"; break;
|
||||
case Key::KeypadDivide: result += "KeypadDivide"; break;
|
||||
case Key::KeypadMultiply: result += "KeypadMultiply"; break;
|
||||
case Key::KeypadSubtract: result += "KeypadSubtract"; break;
|
||||
case Key::KeypadAdd: result += "KeypadAdd"; break;
|
||||
case Key::KeypadEnter: result += "KeypadEnter"; break;
|
||||
case Key::LeftShift: result += "LeftShift"; break;
|
||||
case Key::LeftControl: result += "LeftControl"; break;
|
||||
case Key::LeftAlt: result += "LeftAlt"; break;
|
||||
case Key::LeftSuper: result += "LeftSuper"; break;
|
||||
case Key::RightShift: result += "RightShift"; break;
|
||||
case Key::RightControl: result += "RightControl"; break;
|
||||
case Key::RightAlt: result += "RightAlt"; break;
|
||||
case Key::RightSuper: result += "RightSuper"; break;
|
||||
case Key::Menu: result += "Menu"; break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
@@ -24,280 +24,351 @@
|
||||
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/clipboard.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/font/font.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/clipboard.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "LuaConsole";
|
||||
const std::string historyFile = "ConsoleHistory";
|
||||
const char* HistoryFile = "ConsoleHistory";
|
||||
|
||||
const int NoAutoComplete = -1;
|
||||
}
|
||||
|
||||
#include "luaconsole_lua.inl"
|
||||
const openspace::Key CommandInputButton = openspace::Key::GraveAccent;
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
LuaConsole::LuaConsole()
|
||||
: _inputPosition(0)
|
||||
, _activeCommand(0)
|
||||
, _filename("")
|
||||
, _autoCompleteInfo({NoAutoComplete, false, ""})
|
||||
, _isVisible(false)
|
||||
LuaConsole::LuaConsole()
|
||||
: _isVisible("isVisible", "Is Visible", false)
|
||||
, _remoteScripting(true)
|
||||
, _inputPosition(0)
|
||||
, _activeCommand(0)
|
||||
, _autoCompleteInfo({NoAutoComplete, false, ""})
|
||||
{
|
||||
// _commands.push_back("");
|
||||
// _activeCommand = _commands.size() - 1;
|
||||
setName("LuaConsole");
|
||||
|
||||
_isVisible.onChange([this](){
|
||||
if (_isVisible) {
|
||||
_remoteScripting = false;
|
||||
} else {
|
||||
_remoteScripting = OsEng.parallelConnection().isHost();
|
||||
}
|
||||
});
|
||||
addProperty(_isVisible);
|
||||
}
|
||||
|
||||
void LuaConsole::initialize() {
|
||||
_filename = FileSys.cacheManager()->cachedFilename(
|
||||
historyFile,
|
||||
std::string filename = FileSys.cacheManager()->cachedFilename(
|
||||
HistoryFile,
|
||||
"",
|
||||
ghoul::filesystem::CacheManager::Persistent::Yes
|
||||
);
|
||||
|
||||
std::ifstream file(_filename, std::ios::binary | std::ios::in);
|
||||
if (file.good()) {
|
||||
int64_t nCommands;
|
||||
file.read(reinterpret_cast<char*>(&nCommands), sizeof(int64_t));
|
||||
std::ifstream file;
|
||||
file.exceptions(~std::ofstream::goodbit);
|
||||
file.open(filename, std::ios::binary | std::ios::in);
|
||||
|
||||
std::vector<char> tmp;
|
||||
for (int64_t i = 0; i < nCommands; ++i) {
|
||||
int64_t length;
|
||||
file.read(reinterpret_cast<char*>(&length), sizeof(int64_t));
|
||||
tmp.resize(length + 1);
|
||||
file.read(tmp.data(), length);
|
||||
tmp[length] = '\0';
|
||||
_commandsHistory.emplace_back(std::string(tmp.begin(), tmp.end()));
|
||||
}
|
||||
file.close();
|
||||
_commands = _commandsHistory;
|
||||
// Read the number of commands from the history
|
||||
int64_t nCommands;
|
||||
file.read(reinterpret_cast<char*>(&nCommands), sizeof(int64_t));
|
||||
|
||||
for (int64_t i = 0; i < nCommands; ++i) {
|
||||
int64_t length;
|
||||
file.read(reinterpret_cast<char*>(&length), sizeof(int64_t));
|
||||
|
||||
std::vector<char> tmp(length + 1);
|
||||
file.read(tmp.data(), length);
|
||||
tmp[length] = '\0';
|
||||
_commandsHistory.emplace_back(std::string(tmp.begin(), tmp.end()));
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
_commands = _commandsHistory;
|
||||
_commands.push_back("");
|
||||
_activeCommand = _commands.size() - 1;
|
||||
|
||||
OsEng.parallelConnection().connectionEvent()->subscribe("luaConsole",
|
||||
"statusChanged", [this]() {
|
||||
ParallelConnection::Status status = OsEng.parallelConnection().status();
|
||||
parallelConnectionChanged(status);
|
||||
});
|
||||
|
||||
OsEng.parallelConnection().connectionEvent()->subscribe(
|
||||
"luaConsole",
|
||||
"statusChanged",
|
||||
[this]() {
|
||||
ParallelConnection::Status status = OsEng.parallelConnection().status();
|
||||
parallelConnectionChanged(status);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void LuaConsole::deinitialize() {
|
||||
std::ofstream file(_filename, std::ios::binary | std::ios::out);
|
||||
if (file.good()) {
|
||||
int64_t nCommands = _commandsHistory.size();
|
||||
file.write(reinterpret_cast<const char*>(&nCommands), sizeof(int64_t));
|
||||
for (const std::string& s : _commandsHistory) {
|
||||
int64_t length = s.length();
|
||||
file.write(reinterpret_cast<const char*>(&length), sizeof(int64_t));
|
||||
file.write(s.c_str(), length);
|
||||
}
|
||||
std::string filename = FileSys.cacheManager()->cachedFilename(
|
||||
HistoryFile,
|
||||
"",
|
||||
ghoul::filesystem::CacheManager::Persistent::Yes
|
||||
);
|
||||
|
||||
std::ofstream file;
|
||||
file.exceptions(~std::ofstream::goodbit);
|
||||
file.open(filename, std::ios::binary | std::ios::in);
|
||||
|
||||
int64_t nCommands = _commandsHistory.size();
|
||||
file.write(reinterpret_cast<const char*>(&nCommands), sizeof(int64_t));
|
||||
|
||||
for (const std::string& s : _commandsHistory) {
|
||||
int64_t length = s.length();
|
||||
file.write(reinterpret_cast<const char*>(&length), sizeof(int64_t));
|
||||
// We don't write the \0 at the end on purpose
|
||||
file.write(s.c_str(), length);
|
||||
}
|
||||
|
||||
OsEng.parallelConnection().connectionEvent()->unsubscribe("luaConsole");
|
||||
}
|
||||
|
||||
void LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) {
|
||||
if (action == KeyAction::Press || action == KeyAction::Repeat) {
|
||||
const bool modifierControl = (modifier == KeyModifier::Control);
|
||||
const bool modifierShift = (modifier == KeyModifier::Shift);
|
||||
bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) {
|
||||
if (action != KeyAction::Press && action != KeyAction::Repeat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Paste from clipboard
|
||||
if (modifierControl && (key == Key::V))
|
||||
addToCommand(ghoul::clipboardText());
|
||||
if (key == CommandInputButton) {
|
||||
// Button left of 1 and above TAB
|
||||
// How to deal with different keyboard languages? ---abock
|
||||
_isVisible = !_isVisible;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Copy to clipboard
|
||||
if (modifierControl && (key == Key::C))
|
||||
ghoul::setClipboardText(_commands.at(_activeCommand));
|
||||
if (!_isVisible) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Go to the previous character
|
||||
if ((key == Key::Left) && (_inputPosition > 0))
|
||||
const bool modifierControl = (modifier == KeyModifier::Control);
|
||||
const bool modifierShift = (modifier == KeyModifier::Shift);
|
||||
|
||||
// Paste from clipboard
|
||||
if (modifierControl && (key == Key::V)) {
|
||||
addToCommand(ghoul::clipboardText());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Copy to clipboard
|
||||
if (modifierControl && (key == Key::C)) {
|
||||
ghoul::setClipboardText(_commands.at(_activeCommand));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to the previous character
|
||||
if ((key == Key::Left) && (_inputPosition > 0)) {
|
||||
--_inputPosition;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to the next character
|
||||
if (key == Key::Right) {
|
||||
//&& _inputPosition < _commands.at(_activeCommand).length())
|
||||
//++_inputPosition;
|
||||
_inputPosition = std::min(
|
||||
_inputPosition + 1,
|
||||
_commands.at(_activeCommand).length()
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to previous command
|
||||
if (key == Key::Up) {
|
||||
if (_activeCommand > 0) {
|
||||
--_activeCommand;
|
||||
}
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to next command (the last is empty)
|
||||
if (key == Key::Down) {
|
||||
if (_activeCommand < _commands.size() - 1) {
|
||||
++_activeCommand;
|
||||
}
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove character before _inputPosition
|
||||
if (key == Key::BackSpace) {
|
||||
if (_inputPosition > 0) {
|
||||
_commands.at(_activeCommand).erase(_inputPosition - 1, 1);
|
||||
--_inputPosition;
|
||||
|
||||
// Go to the next character
|
||||
if ((key == Key::Right) && _inputPosition < _commands.at(_activeCommand).length())
|
||||
++_inputPosition;
|
||||
|
||||
// Go to previous command
|
||||
if (key == Key::Up) {
|
||||
if (_activeCommand > 0)
|
||||
--_activeCommand;
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to next command (the last is empty)
|
||||
if (key == Key::Down) {
|
||||
if (_activeCommand < _commands.size() - 1)
|
||||
++_activeCommand;
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
}
|
||||
|
||||
// Remove character before _inputPosition
|
||||
if (key == Key::BackSpace) {
|
||||
if (_inputPosition > 0) {
|
||||
_commands.at(_activeCommand).erase(_inputPosition - 1, 1);
|
||||
--_inputPosition;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove character after _inputPosition
|
||||
if (key == Key::Delete) {
|
||||
if (_inputPosition <= _commands.at(_activeCommand).size())
|
||||
_commands.at(_activeCommand).erase(_inputPosition, 1);
|
||||
// Remove character after _inputPosition
|
||||
if (key == Key::Delete) {
|
||||
if (_inputPosition <= _commands.at(_activeCommand).size()) {
|
||||
_commands.at(_activeCommand).erase(_inputPosition, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to the beginning of command string
|
||||
if (key == Key::Home)
|
||||
_inputPosition = 0;
|
||||
// Go to the beginning of command string
|
||||
if (key == Key::Home) {
|
||||
_inputPosition = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to the end of command string
|
||||
if (key == Key::End)
|
||||
_inputPosition = _commands.at(_activeCommand).size();
|
||||
// Go to the end of command string
|
||||
if (key == Key::End) {
|
||||
_inputPosition = _commands.at(_activeCommand).size();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == Key::Enter) {
|
||||
// SHIFT+ENTER == new line
|
||||
if (modifierShift)
|
||||
addToCommand("\n");
|
||||
// ENTER == run lua script
|
||||
else {
|
||||
std::string cmd = _commands.at(_activeCommand);
|
||||
if (cmd != "") {
|
||||
OsEng.scriptEngine().queueScript(cmd,
|
||||
_remoteScripting ? scripting::ScriptEngine::RemoteScripting::Yes : scripting::ScriptEngine::RemoteScripting::No);
|
||||
if (key == Key::Enter) {
|
||||
// SHIFT+ENTER == new line
|
||||
if (modifierShift) {
|
||||
addToCommand("\n");
|
||||
}
|
||||
// ENTER == run lua script
|
||||
else {
|
||||
std::string cmd = _commands.at(_activeCommand);
|
||||
if (cmd != "") {
|
||||
using RemoteScripting = scripting::ScriptEngine::RemoteScripting;
|
||||
OsEng.scriptEngine().queueScript(
|
||||
cmd,
|
||||
_remoteScripting ? RemoteScripting::Yes : RemoteScripting::No
|
||||
);
|
||||
|
||||
// Only add the current command to the history if it hasn't been
|
||||
// executed before. We don't want two of the same commands in a row
|
||||
if (_commandsHistory.empty() || (cmd != _commandsHistory.back()))
|
||||
_commandsHistory.push_back(_commands.at(_activeCommand));
|
||||
// Only add the current command to the history if it hasn't been
|
||||
// executed before. We don't want two of the same commands in a row
|
||||
if (_commandsHistory.empty() || (cmd != _commandsHistory.back())) {
|
||||
_commandsHistory.push_back(_commands.at(_activeCommand));
|
||||
}
|
||||
|
||||
// Some clean up after the execution of the command
|
||||
_commands = _commandsHistory;
|
||||
_commands.push_back("");
|
||||
_activeCommand = _commands.size() - 1;
|
||||
_inputPosition = 0;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
// Some clean up after the execution of the command
|
||||
_commands = _commandsHistory;
|
||||
_commands.push_back("");
|
||||
_activeCommand = _commands.size() - 1;
|
||||
_inputPosition = 0;
|
||||
_isVisible = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == Key::Tab) {
|
||||
// We get a list of all the available commands and initially find the first
|
||||
// command that starts with how much we typed sofar. We store the index so
|
||||
// that in subsequent "tab" presses, we will discard previous commands. This
|
||||
// implements the 'hop-over' behavior. As soon as another key is pressed,
|
||||
// everything is set back to normal
|
||||
|
||||
// If the shift key is pressed, we decrement the current index so that we will
|
||||
// find the value before the one that was previously found
|
||||
if (_autoCompleteInfo.lastIndex != NoAutoComplete && modifierShift) {
|
||||
_autoCompleteInfo.lastIndex -= 2;
|
||||
}
|
||||
std::vector<std::string> allCommands = OsEng.scriptEngine().allLuaFunctions();
|
||||
std::sort(allCommands.begin(), allCommands.end());
|
||||
|
||||
std::string currentCommand = _commands.at(_activeCommand);
|
||||
|
||||
// Check if it is the first time the tab has been pressed. If so, we need to
|
||||
// store the already entered command so that we can later start the search
|
||||
// from there. We will overwrite the 'currentCommand' thus making the storage
|
||||
// necessary
|
||||
if (!_autoCompleteInfo.hasInitialValue) {
|
||||
_autoCompleteInfo.initialValue = currentCommand;
|
||||
_autoCompleteInfo.hasInitialValue = true;
|
||||
}
|
||||
|
||||
if (key == Key::Tab) {
|
||||
// We get a list of all the available commands and initially find the first
|
||||
// command that starts with how much we typed sofar. We store the index so
|
||||
// that in subsequent "tab" presses, we will discard previous commands. This
|
||||
// implements the 'hop-over' behavior. As soon as another key is pressed,
|
||||
// everything is set back to normal
|
||||
for (int i = 0; i < static_cast<int>(allCommands.size()); ++i) {
|
||||
const std::string& command = allCommands[i];
|
||||
|
||||
// If the shift key is pressed, we decrement the current index so that we will
|
||||
// find the value before the one that was previously found
|
||||
if (_autoCompleteInfo.lastIndex != NoAutoComplete && modifierShift)
|
||||
_autoCompleteInfo.lastIndex -= 2;
|
||||
std::vector<std::string> allCommands = OsEng.scriptEngine().allLuaFunctions();
|
||||
std::sort(allCommands.begin(), allCommands.end());
|
||||
// Check if the command has enough length (we don't want crashes here)
|
||||
// Then check if the iterator-command's start is equal to what we want
|
||||
// then check if we need to skip the first found values as the user has
|
||||
// pressed TAB repeatedly
|
||||
size_t fullLength = _autoCompleteInfo.initialValue.length();
|
||||
bool correctLength = command.length() >= fullLength;
|
||||
|
||||
std::string currentCommand = _commands.at(_activeCommand);
|
||||
|
||||
// Check if it is the first time the tab has been pressed. If so, we need to
|
||||
// store the already entered command so that we can later start the search
|
||||
// from there. We will overwrite the 'currentCommand' thus making the storage
|
||||
// necessary
|
||||
if (!_autoCompleteInfo.hasInitialValue) {
|
||||
_autoCompleteInfo.initialValue = currentCommand;
|
||||
_autoCompleteInfo.hasInitialValue = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < static_cast<int>(allCommands.size()); ++i) {
|
||||
const std::string& command = allCommands[i];
|
||||
|
||||
// Check if the command has enough length (we don't want crashes here)
|
||||
// Then check if the iterator-command's start is equal to what we want
|
||||
// then check if we need to skip the first found values as the user has
|
||||
// pressed TAB repeatedly
|
||||
size_t fullLength = _autoCompleteInfo.initialValue.length();
|
||||
bool correctLength = command.length() >= fullLength;
|
||||
|
||||
std::string commandLowerCase;
|
||||
std::transform(
|
||||
command.begin(), command.end(),
|
||||
std::back_inserter(commandLowerCase),
|
||||
::tolower
|
||||
);
|
||||
std::string commandLowerCase;
|
||||
std::transform(
|
||||
command.begin(), command.end(),
|
||||
std::back_inserter(commandLowerCase),
|
||||
::tolower
|
||||
);
|
||||
|
||||
std::string initialValueLowerCase;
|
||||
std::transform(
|
||||
_autoCompleteInfo.initialValue.begin(),
|
||||
_autoCompleteInfo.initialValue.end(),
|
||||
std::back_inserter(initialValueLowerCase),
|
||||
::tolower
|
||||
);
|
||||
std::string initialValueLowerCase;
|
||||
std::transform(
|
||||
_autoCompleteInfo.initialValue.begin(),
|
||||
_autoCompleteInfo.initialValue.end(),
|
||||
std::back_inserter(initialValueLowerCase),
|
||||
::tolower
|
||||
);
|
||||
|
||||
bool correctCommand =
|
||||
commandLowerCase.substr(0, fullLength) == initialValueLowerCase;
|
||||
bool correctCommand =
|
||||
commandLowerCase.substr(0, fullLength) == initialValueLowerCase;
|
||||
|
||||
if (correctLength && correctCommand && (i > _autoCompleteInfo.lastIndex)){
|
||||
// We found our index, so store it
|
||||
_autoCompleteInfo.lastIndex = i;
|
||||
if (correctLength && correctCommand && (i > _autoCompleteInfo.lastIndex)){
|
||||
// We found our index, so store it
|
||||
_autoCompleteInfo.lastIndex = i;
|
||||
|
||||
// We only want to auto-complete until the next separator "."
|
||||
size_t pos = command.find('.', fullLength);
|
||||
if (pos == std::string::npos) {
|
||||
// If we don't find a separator, we autocomplete until the end
|
||||
// Set the found command as active command
|
||||
_commands.at(_activeCommand) = command + "();";
|
||||
// Set the cursor position to be between the brackets
|
||||
_inputPosition = _commands.at(_activeCommand).size() - 2;
|
||||
// We only want to auto-complete until the next separator "."
|
||||
size_t pos = command.find('.', fullLength);
|
||||
if (pos == std::string::npos) {
|
||||
// If we don't find a separator, we autocomplete until the end
|
||||
// Set the found command as active command
|
||||
_commands.at(_activeCommand) = command + "();";
|
||||
// Set the cursor position to be between the brackets
|
||||
_inputPosition = _commands.at(_activeCommand).size() - 2;
|
||||
}
|
||||
else {
|
||||
// If we find a separator, we autocomplete until and including the
|
||||
// separator unless the autocompletion would be the same that we
|
||||
// already have (the case if there are multiple commands in the
|
||||
// same group
|
||||
std::string subCommand = command.substr(0, pos + 1);
|
||||
if (subCommand == _commands.at(_activeCommand)) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// If we find a separator, we autocomplete until and including the
|
||||
// separator unless the autocompletion would be the same that we
|
||||
// already have (the case if there are multiple commands in the
|
||||
// same group
|
||||
std::string subCommand = command.substr(0, pos + 1);
|
||||
if (subCommand == _commands.at(_activeCommand))
|
||||
continue;
|
||||
else {
|
||||
_commands.at(_activeCommand) = command.substr(0, pos + 1);
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
// We only want to remove the autocomplete info if we just
|
||||
// entered the 'default' openspace namespace
|
||||
if (command.substr(0, pos + 1) == "openspace.")
|
||||
_autoCompleteInfo = { NoAutoComplete, false, "" };
|
||||
_commands.at(_activeCommand) = command.substr(0, pos + 1);
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
// We only want to remove the autocomplete info if we just
|
||||
// entered the 'default' openspace namespace
|
||||
if (command.substr(0, pos + 1) == "openspace.") {
|
||||
_autoCompleteInfo = { NoAutoComplete, false, "" };
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// If any other key is pressed, we want to remove our previous findings
|
||||
// The special case for Shift is necessary as we want to allow Shift+TAB
|
||||
if (!modifierShift)
|
||||
_autoCompleteInfo = { NoAutoComplete, false, ""};
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// If any other key is pressed, we want to remove our previous findings
|
||||
// The special case for Shift is necessary as we want to allow Shift+TAB
|
||||
if (!modifierShift) {
|
||||
_autoCompleteInfo = { NoAutoComplete, false, "" };
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LuaConsole::charCallback(unsigned int codepoint, KeyModifier modifier) {
|
||||
if (codepoint == static_cast<unsigned int>(commandInputButton()))
|
||||
if (!_isVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (codepoint == static_cast<unsigned int>(CommandInputButton)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
const bool modifierControl = (modifier == KeyModifier::Control);
|
||||
@@ -308,50 +379,84 @@ void LuaConsole::charCallback(unsigned int codepoint, KeyModifier modifier) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
addToCommand(UnicodeToUTF8(codepoint));
|
||||
|
||||
// Disallow all non ASCII characters for now
|
||||
if (codepoint > 0x7f) {
|
||||
return;
|
||||
}
|
||||
|
||||
addToCommand(std::string(1, codepoint));
|
||||
}
|
||||
|
||||
void LuaConsole::render() {
|
||||
const float font_size = 10.0f;
|
||||
|
||||
int ySize = OsEng.renderEngine().fontResolution().y;
|
||||
//int ySize = OsEng.windowWrapper().currentWindowSize().y;
|
||||
//int ySize = OsEng.windowWrapper().viewportPixelCoordinates().w;
|
||||
const float FontSize = 10.0f;
|
||||
|
||||
float startY = static_cast<float>(ySize) - 2.0f * font_size;
|
||||
startY = startY - font_size * 15.0f * 2.0f;
|
||||
if (!_isVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int ySize = OsEng.renderEngine().fontResolution().y;
|
||||
|
||||
const float startY =
|
||||
static_cast<float>(ySize) - 2.0f * FontSize - FontSize * 15.0f * 2.0f;;
|
||||
|
||||
const glm::vec4 red(1, 0, 0, 1);
|
||||
const glm::vec4 lightBlue(0.4, 0.4, 1, 1);
|
||||
const glm::vec4 green(0, 1, 0, 1);
|
||||
const glm::vec4 white(1, 1, 1, 1);
|
||||
std::shared_ptr<ghoul::fontrendering::Font> font = OsEng.fontManager().font("Mono", font_size);
|
||||
std::shared_ptr<ghoul::fontrendering::Font> font = OsEng.fontManager().font(
|
||||
"Mono", FontSize
|
||||
);
|
||||
|
||||
using ghoul::fontrendering::RenderFont;
|
||||
|
||||
if (_remoteScripting) {
|
||||
int nClients = OsEng.parallelConnection().nConnections() - 1;
|
||||
if (nClients == 1) {
|
||||
RenderFont(*font, glm::vec2(15.f, startY + 20.0f), red, "Broadcasting script to 1 client");
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f, startY + 20.0f),
|
||||
red,
|
||||
"Broadcasting script to 1 client"
|
||||
);
|
||||
} else {
|
||||
RenderFont(*font, glm::vec2(15.f, startY + 20.0f), red, ("Broadcasting script to " + std::to_string(nClients) + " clients").c_str());
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f, startY + 20.0f),
|
||||
red,
|
||||
("Broadcasting script to " + std::to_string(nClients) + " clients").c_str()
|
||||
);
|
||||
}
|
||||
RenderFont(*font, glm::vec2(15.f, startY), red, "$");
|
||||
}
|
||||
else {
|
||||
if (OsEng.parallelConnection().isHost()) {
|
||||
RenderFont(*font, glm::vec2(15.f, startY + 20.0f), lightBlue, "Local script execution");
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f, startY + 20.0f),
|
||||
lightBlue,
|
||||
"Local script execution"
|
||||
);
|
||||
}
|
||||
RenderFont(*font, glm::vec2(15.f, startY), lightBlue, "$");
|
||||
}
|
||||
RenderFont(*font, glm::vec2(15.f + font_size, startY), white, "%s", _commands.at(_activeCommand).c_str());
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f + FontSize, startY),
|
||||
white,
|
||||
"%s",
|
||||
_commands.at(_activeCommand).c_str()
|
||||
);
|
||||
|
||||
size_t n = std::count(_commands.at(_activeCommand).begin(), _commands.at(_activeCommand).begin() + _inputPosition, '\n');
|
||||
const size_t n = std::count(
|
||||
_commands.at(_activeCommand).begin(),
|
||||
_commands.at(_activeCommand).begin() + _inputPosition,
|
||||
'\n'
|
||||
);
|
||||
size_t p = _commands.at(_activeCommand).find_last_of('\n', _inputPosition);
|
||||
size_t linepos = _inputPosition;
|
||||
|
||||
if (n>0) {
|
||||
if (n > 0) {
|
||||
if (p == _inputPosition) {
|
||||
p = _commands.at(_activeCommand).find_last_of('\n', _inputPosition - 1);
|
||||
if (p != std::string::npos) {
|
||||
@@ -361,107 +466,30 @@ void LuaConsole::render() {
|
||||
linepos = _inputPosition - 1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
linepos -= p + 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "%" << linepos + 1 << "s";
|
||||
RenderFont(*font, glm::vec2(15.f + font_size * 0.5f, startY - (font_size)*(n + 1)*3.0f / 2.0f), green, ss.str().c_str(), "^");
|
||||
|
||||
// sgct_text::print(font, 15.0f + font_size*0.5f, startY - (font_size)*(n + 1)*3.0f / 2.0f, green, ss.str().c_str(), "^");
|
||||
}
|
||||
|
||||
Key LuaConsole::commandInputButton() {
|
||||
// Button left of 1 and above TAB
|
||||
// How to deal with different keyboard languages? ---abock
|
||||
return Key::GraveAccent;
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f + FontSize * 0.5f, startY - (FontSize) * (n + 1) * 3.0f / 2.0f),
|
||||
green,
|
||||
ss.str().c_str(),
|
||||
"^"
|
||||
);
|
||||
}
|
||||
|
||||
void LuaConsole::addToCommand(std::string c) {
|
||||
size_t length = c.length();
|
||||
_commands.at(_activeCommand).insert(_inputPosition, c);
|
||||
const size_t length = c.length();
|
||||
_commands.at(_activeCommand).insert(_inputPosition, std::move(c));
|
||||
_inputPosition += length;
|
||||
}
|
||||
|
||||
std::string LuaConsole::UnicodeToUTF8(unsigned int codepoint) {
|
||||
std::string out;
|
||||
|
||||
if (codepoint <= 0x7f)
|
||||
out.append(1, static_cast<char>(codepoint));
|
||||
else if (codepoint <= 0x7ff)
|
||||
{
|
||||
out.append(1, static_cast<char>(0xc0 | ((codepoint >> 6) & 0x1f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
else if (codepoint <= 0xffff)
|
||||
{
|
||||
out.append(1, static_cast<char>(0xe0 | ((codepoint >> 12) & 0x0f)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.append(1, static_cast<char>(0xf0 | ((codepoint >> 18) & 0x07)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 12) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool LuaConsole::isVisible() const {
|
||||
return _isVisible;
|
||||
}
|
||||
|
||||
void LuaConsole::setVisible(bool visible) {
|
||||
_isVisible = visible;
|
||||
}
|
||||
|
||||
void LuaConsole::toggleMode() {
|
||||
if (_isVisible) {
|
||||
if (_remoteScripting) {
|
||||
_remoteScripting = false;
|
||||
} else {
|
||||
_isVisible = false;
|
||||
}
|
||||
} else {
|
||||
_remoteScripting = OsEng.parallelConnection().isHost();
|
||||
_isVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
void LuaConsole::parallelConnectionChanged(const ParallelConnection::Status& status) {
|
||||
_remoteScripting = status == ParallelConnection::Status::Host;
|
||||
_remoteScripting = (status == ParallelConnection::Status::Host);
|
||||
}
|
||||
|
||||
|
||||
scripting::LuaLibrary LuaConsole::luaLibrary() {
|
||||
return {
|
||||
"console",
|
||||
{
|
||||
{
|
||||
"show",
|
||||
&luascriptfunctions::show,
|
||||
"",
|
||||
"Shows the console"
|
||||
},
|
||||
{
|
||||
"hide",
|
||||
&luascriptfunctions::hide,
|
||||
"",
|
||||
"Hides the console"
|
||||
},
|
||||
{
|
||||
"toggle",
|
||||
&luascriptfunctions::toggle,
|
||||
"",
|
||||
"Toggles the console"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace luascriptfunctions {
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* show():
|
||||
* Shows the console
|
||||
*/
|
||||
int show(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
|
||||
OsEng.console().setVisible(true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* hide():
|
||||
* Hides the console
|
||||
*/
|
||||
int hide(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
|
||||
OsEng.console().setVisible(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* toggle():
|
||||
* Toggles the console
|
||||
*/
|
||||
int toggle(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
|
||||
OsEng.console().toggleMode();
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace luascriptfunctions
|
||||
|
||||
} // namespace openspace
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <openspace/rendering/raycastermanager.h>
|
||||
#include <openspace/rendering/renderer.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/screenlog.h>
|
||||
@@ -1098,6 +1099,8 @@ void RenderEngine::renderInformation() {
|
||||
penPosition.y -= _fontInfo->height();
|
||||
}
|
||||
catch (...) {
|
||||
// @CLEANUP: This is bad as it will discard all exceptions
|
||||
// without telling us about it! ---abock
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
|
||||
);
|
||||
}
|
||||
catch (...) {
|
||||
// @CLEANUP: This is bad to just catch all exceptions! ---abock
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ KeyModifier operator|(KeyModifier lhs, KeyModifier rhs) {
|
||||
return static_cast<KeyModifier>(
|
||||
static_cast<std::underlying_type_t<KeyModifier>>(lhs) |
|
||||
static_cast<std::underlying_type_t<KeyModifier>>(rhs)
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
KeyModifier operator|=(KeyModifier& lhs, KeyModifier rhs) {
|
||||
@@ -82,8 +82,9 @@ KeyWithModifier stringToKey(std::string str) {
|
||||
// default is unknown
|
||||
Key k = Key::Unknown;
|
||||
auto it = KeyMapping.find(tokens.back());
|
||||
if (it != KeyMapping.end())
|
||||
if (it != KeyMapping.end()) {
|
||||
k = it->second;
|
||||
}
|
||||
|
||||
|
||||
KeyModifier m = KeyModifier::NoModifier;
|
||||
@@ -92,10 +93,12 @@ KeyWithModifier stringToKey(std::string str) {
|
||||
tokens.end() - 1,
|
||||
[&m](const std::string& s) {
|
||||
auto it = KeyModifierMapping.find(s);
|
||||
if (it != KeyModifierMapping.end())
|
||||
if (it != KeyModifierMapping.end()) {
|
||||
m |= it->second;
|
||||
else
|
||||
}
|
||||
else {
|
||||
LERROR("Unknown modifier key '" << s << "'");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -103,10 +106,12 @@ KeyWithModifier stringToKey(std::string str) {
|
||||
}
|
||||
|
||||
bool operator<(const KeyWithModifier& lhs, const KeyWithModifier& rhs) {
|
||||
if (lhs.modifier == rhs.modifier)
|
||||
if (lhs.modifier == rhs.modifier) {
|
||||
return lhs.key < rhs.key;
|
||||
else
|
||||
}
|
||||
else {
|
||||
return lhs.modifier < rhs.modifier;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -115,8 +120,9 @@ namespace std {
|
||||
|
||||
std::string to_string(openspace::Key key) {
|
||||
for (const auto& p : openspace::KeyMapping) {
|
||||
if (p.second == key)
|
||||
if (p.second == key) {
|
||||
return p.first;
|
||||
}
|
||||
}
|
||||
ghoul_assert(false, "Missing key in KeyMapping");
|
||||
}
|
||||
@@ -124,8 +130,9 @@ std::string to_string(openspace::Key key) {
|
||||
std::string to_string(openspace::KeyModifier mod) {
|
||||
using namespace openspace;
|
||||
|
||||
if (mod == KeyModifier::NoModifier)
|
||||
if (mod == KeyModifier::NoModifier) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string result;
|
||||
for (const auto& p : KeyModifierMapping) {
|
||||
@@ -139,10 +146,12 @@ std::string to_string(openspace::KeyModifier mod) {
|
||||
}
|
||||
|
||||
std::string to_string(openspace::KeyWithModifier key) {
|
||||
if (key.modifier == openspace::KeyModifier::NoModifier)
|
||||
if (key.modifier == openspace::KeyModifier::NoModifier) {
|
||||
return to_string(key.key);
|
||||
else
|
||||
}
|
||||
else {
|
||||
return to_string(key.modifier) + "+" + to_string(key.key);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
|
||||
Reference in New Issue
Block a user