Reduce the dependency of libOpenSpace on modules

- Enable module callbacks for OpenSpaceEngine
 - Add OpenSpaceModule function that returns a Lua library
This commit is contained in:
Alexander Bock
2017-02-16 16:43:34 -05:00
parent 8167228d69
commit 11fbff5fbc
11 changed files with 382 additions and 162 deletions

View File

@@ -40,7 +40,18 @@ namespace openspace {
IswaModule::IswaModule()
: OpenSpaceModule("ISWA")
{}
{
OsEng.registerModuleCallback(
OpenSpaceEngine::CallbackOption::Initialize,
[](){
IswaManager::initialize();
}
);
}
scripting::LuaLibrary IswaModule::luaLibrary() const {
return IswaManager::luaLibrary();
}
void IswaModule::internalInitialize(){
auto fRenderable = FactoryManager::ref().factory<Renderable>();

View File

@@ -32,6 +32,8 @@
class IswaModule : public OpenSpaceModule {
public:
IswaModule();
scripting::LuaLibrary luaLibrary() const override;
protected:
void internalInitialize() override;

View File

@@ -44,7 +44,6 @@ namespace gui {
class GUI : public GuiComponent {
public:
GUI();
~GUI();
void initialize();
void deinitialize();

View File

@@ -27,13 +27,158 @@
#include <modules/onscreengui/include/gui.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/settingsengine.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/interaction/interactionhandler.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/rendering/screenspacerenderable.h>
#include <ghoul/logging/logmanager.h>
namespace openspace {
gui::GUI OnScreenGUIModule::gui;
OnScreenGUIModule::OnScreenGUIModule()
: OpenSpaceModule("OnScreenGUI")
{
addPropertySubOwner(OsEng.gui());
}
addPropertySubOwner(gui);
OsEng.registerModuleCallback(
OpenSpaceEngine::CallbackOption::Initialize,
[](){
LDEBUGC("OnScreenGUIModule", "Initializing GUI");
gui.initialize();
gui._globalProperty.setSource(
[]() {
std::vector<properties::PropertyOwner*> res = {
&(OsEng.settingsEngine()),
&(OsEng.interactionHandler()),
&(OsEng.renderEngine())
};
return res;
}
);
gui._screenSpaceProperty.setSource(
[]() {
const auto& ssr = OsEng.renderEngine().screenSpaceRenderables();
return std::vector<properties::PropertyOwner*>(ssr.begin(), ssr.end());
}
);
gui._property.setSource(
[]() {
const auto& nodes = OsEng.renderEngine().scene()->allSceneGraphNodes();
return std::vector<properties::PropertyOwner*>(nodes.begin(), nodes.end());
}
);
}
);
OsEng.registerModuleCallback(
OpenSpaceEngine::CallbackOption::Deinitialize,
[](){
LDEBUGC("OnScreenGui", "Deinitialize GUI");
gui.deinitialize();
}
);
OsEng.registerModuleCallback(
OpenSpaceEngine::CallbackOption::InitializeGL,
[](){
LDEBUGC("OnScreenGui", "Initializing GUI OpenGL");
gui.initializeGL();
}
);
OsEng.registerModuleCallback(
OpenSpaceEngine::CallbackOption::DeinitializeGL,
[](){
LDEBUGC("OnScreenGui", "Deinitialize GUI OpenGL");
gui.deinitializeGL();
}
);
OsEng.registerModuleCallback(
OpenSpaceEngine::CallbackOption::PostSyncPreDraw,
[](){
WindowWrapper& wrapper = OsEng.windowWrapper();
if (OsEng.isMaster() && wrapper.isRegularRendering()) {
glm::vec2 mousePosition = wrapper.mousePosition();
//glm::ivec2 drawBufferResolution = _windowWrapper->currentDrawBufferResolution();
glm::ivec2 windowSize = wrapper.currentWindowSize();
glm::ivec2 renderingSize = wrapper.currentWindowResolution();
uint32_t mouseButtons = wrapper.mouseButtons(2);
double dt = std::max(wrapper.averageDeltaTime(), 0.0);
gui.startFrame(
static_cast<float>(dt),
glm::vec2(windowSize),
wrapper.dpiScaling(),
mousePosition,
mouseButtons
);
}
}
);
OsEng.registerModuleCallback(
OpenSpaceEngine::CallbackOption::PostDraw,
[](){
WindowWrapper& wrapper = OsEng.windowWrapper();
bool showGui = wrapper.hasGuiWindow() ? wrapper.isGuiWindow() : true;
if (OsEng.isMaster() && wrapper.isRegularRendering() && showGui) {
gui.endFrame();
}
}
);
OsEng.registerModuleKeyboardCallback(
[](Key key, KeyModifier mod, KeyAction action) -> bool {
if (gui.isEnabled()) {
return gui.keyCallback(key, mod, action);
}
else {
return false;
}
}
);
OsEng.registerModuleCharCallback(
[](unsigned int codepoint, KeyModifier modifier) -> bool {
if (gui.isEnabled()) {
return gui.charCallback(codepoint, modifier);
}
else {
return false;
}
}
);
OsEng.registerModuleMouseButtonCallback(
[](MouseButton button, MouseAction action) -> bool {
if (gui.isEnabled()) {
return gui.mouseButtonCallback(button, action);
}
else {
return false;
}
}
);
OsEng.registerModuleMouseScrollWheelCallback(
[](double pos) -> bool {
if (gui.isEnabled()) {
return gui.mouseWheelCallback(pos);
}
else {
return false;
}
}
);
}
} // namespace openspace

View File

@@ -27,11 +27,15 @@
#include <openspace/util/openspacemodule.h>
namespace openspace {
#include <modules/onscreengui/include/gui.h>
namespace openspace {
class OnScreenGUIModule : public OpenSpaceModule {
public:
OnScreenGUIModule();
static gui::GUI gui;
};
} // namespace openspace

View File

@@ -24,6 +24,8 @@
#include <modules/onscreengui/include/gui.h>
#include <modules/onscreengui/onscreenguimodule.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/keys.h>
@@ -237,10 +239,6 @@ GUI::GUI()
addPropertySubOwner(_iswa);
}
GUI::~GUI() {
ImGui::Shutdown();
}
void GUI::initialize() {
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
configurationFile, "", ghoul::filesystem::CacheManager::Persistent::Yes
@@ -322,6 +320,8 @@ void GUI::initialize() {
}
void GUI::deinitialize() {
ImGui::Shutdown();
_iswa.deinitialize();
_help.deinitialize();
_performance.deinitialize();

View File

@@ -39,7 +39,7 @@ int show(lua_State* L) {
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
}
OsEng.gui().setEnabled(true);
OnScreenGUIModule::gui.setEnabled(true);
return 0;
}
@@ -54,7 +54,7 @@ int hide(lua_State* L) {
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
}
OsEng.gui().setEnabled(false);
OnScreenGUIModule::gui.setEnabled(false);
return 0;
}
@@ -69,7 +69,7 @@ int toggle(lua_State* L) {
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
}
OsEng.gui().setEnabled(!OsEng.gui().isEnabled());
OnScreenGUIModule::gui.setEnabled(!OnScreenGUIModule::gui.isEnabled());
return 0;
}