mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-27 06:19:51 -05:00
Allow access to the console through OpenSpaceEngine
Enable scripting for showing/hiding the console
This commit is contained in:
@@ -26,8 +26,10 @@
|
||||
#define __OPENSPACEENGINE_H__
|
||||
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
|
||||
#include <ghoul/cmdparser/commandlineparser.h>
|
||||
|
||||
namespace openspace {
|
||||
@@ -55,6 +57,7 @@ public:
|
||||
interaction::InteractionHandler& interactionHandler();
|
||||
RenderEngine& renderEngine();
|
||||
scripting::ScriptEngine& scriptEngine();
|
||||
LuaConsole& console();
|
||||
|
||||
// SGCT callbacks
|
||||
bool initializeGL();
|
||||
@@ -71,6 +74,8 @@ public:
|
||||
void encode();
|
||||
void decode();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
OpenSpaceEngine(std::string programName);
|
||||
~OpenSpaceEngine();
|
||||
@@ -88,10 +93,10 @@ private:
|
||||
RenderEngine _renderEngine;
|
||||
scripting::ScriptEngine _scriptEngine;
|
||||
ghoul::cmdparser::CommandlineParser _commandlineParser;
|
||||
LuaConsole _console;
|
||||
|
||||
SyncBuffer* _syncBuffer;
|
||||
|
||||
LuaConsole* _console;
|
||||
};
|
||||
|
||||
#define OsEng (openspace::OpenSpaceEngine::ref())
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#ifndef LUACONSOLE_H
|
||||
#define LUACONSOLE_H
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -46,6 +48,15 @@ public:
|
||||
bool isVisible() const;
|
||||
void setVisible(bool visible);
|
||||
void toggleVisibility();
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to affect the
|
||||
* console. The functions contained are
|
||||
* \return The Lua library that contains all Lua functions available to affect the
|
||||
* console
|
||||
*/
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
|
||||
private:
|
||||
void addToCommand(std::string c);
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
// openspace
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/keyboardcontroller.h>
|
||||
#include <openspace/interaction/mousecontroller.h>
|
||||
@@ -85,7 +84,6 @@ OpenSpaceEngine* OpenSpaceEngine::_engine = nullptr;
|
||||
OpenSpaceEngine::OpenSpaceEngine(std::string programName)
|
||||
: _commandlineParser(programName, true)
|
||||
, _syncBuffer(nullptr)
|
||||
, _console(nullptr)
|
||||
{
|
||||
// initialize OpenSpace helpers
|
||||
SpiceManager::initialize();
|
||||
@@ -95,9 +93,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
|
||||
}
|
||||
|
||||
OpenSpaceEngine::~OpenSpaceEngine() {
|
||||
if (_console)
|
||||
delete _console;
|
||||
|
||||
ghoul::systemcapabilities::SystemCapabilities::deinitialize();
|
||||
FactoryManager::deinitialize();
|
||||
Time::deinitialize();
|
||||
@@ -295,7 +290,6 @@ bool OpenSpaceEngine::create(int argc, char** argv,
|
||||
// Create the cachemanager
|
||||
FileSys.createCacheManager(absPath("${" + constants::configurationmanager::keyCache + "}"));
|
||||
|
||||
_engine->_console = new LuaConsole();
|
||||
_engine->_syncBuffer = new SyncBuffer(1024);
|
||||
|
||||
// Determining SGCT configuration file
|
||||
@@ -345,6 +339,7 @@ bool OpenSpaceEngine::initialize() {
|
||||
_scriptEngine.addLibrary(SceneGraph::luaLibrary());
|
||||
_scriptEngine.addLibrary(Time::luaLibrary());
|
||||
_scriptEngine.addLibrary(interaction::InteractionHandler::luaLibrary());
|
||||
_scriptEngine.addLibrary(LuaConsole::luaLibrary());
|
||||
|
||||
// TODO: Maybe move all scenegraph and renderengine stuff to initializeGL
|
||||
scriptEngine().initialize();
|
||||
@@ -396,6 +391,10 @@ ScriptEngine& OpenSpaceEngine::scriptEngine() {
|
||||
return _scriptEngine;
|
||||
}
|
||||
|
||||
LuaConsole& OpenSpaceEngine::console() {
|
||||
return _console;
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::initializeGL()
|
||||
{
|
||||
return _renderEngine.initializeGL();
|
||||
@@ -422,8 +421,8 @@ void OpenSpaceEngine::render() {
|
||||
|
||||
// If currently writing a command, render it to screen
|
||||
sgct::SGCTWindow* w = sgct::Engine::instance()->getActiveWindowPtr();
|
||||
if (sgct::Engine::instance()->isMaster() && !w->isUsingFisheyeRendering() && _console->isVisible()) {
|
||||
_console->render();
|
||||
if (sgct::Engine::instance()->isMaster() && !w->isUsingFisheyeRendering() && _console.isVisible()) {
|
||||
_console.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,21 +436,21 @@ void OpenSpaceEngine::postDraw() {
|
||||
|
||||
void OpenSpaceEngine::keyboardCallback(int key, int action) {
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
if (key == _console->commandInputButton() && (action == SGCT_PRESS || action == SGCT_REPEAT))
|
||||
_console->toggleVisibility();
|
||||
if (key == _console.commandInputButton() && (action == SGCT_PRESS || action == SGCT_REPEAT))
|
||||
_console.toggleVisibility();
|
||||
|
||||
if (!_console->isVisible()) {
|
||||
if (!_console.isVisible()) {
|
||||
_interactionHandler.keyboardCallback(key, action);
|
||||
}
|
||||
else {
|
||||
_console->keyboardCallback(key, action);
|
||||
_console.keyboardCallback(key, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::charCallback(unsigned int codepoint) {
|
||||
if (_console->isVisible()) {
|
||||
_console->charCallback(codepoint);
|
||||
if (_console.isVisible()) {
|
||||
_console.charCallback(codepoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,6 +144,52 @@ namespace {
|
||||
|
||||
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().toggleVisibility();
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LuaConsole::LuaConsole()
|
||||
: _inputPosition(0)
|
||||
, _activeCommand(0)
|
||||
@@ -407,5 +453,27 @@ void LuaConsole::toggleVisibility() {
|
||||
_isVisible = !_isVisible;
|
||||
}
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary LuaConsole::luaLibrary() {
|
||||
return {
|
||||
"console",
|
||||
{
|
||||
{
|
||||
"show",
|
||||
&luascriptfunctions::show,
|
||||
"show(): Shows the console"
|
||||
},
|
||||
{
|
||||
"hide",
|
||||
&luascriptfunctions::hide,
|
||||
"hide(): Hides the console"
|
||||
},
|
||||
{
|
||||
"toggle",
|
||||
&luascriptfunctions::toggle,
|
||||
"toggle(): Toggles the console"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user