Feature/virtualproperty (#286)

* Add virtual property owner to OpenSpaceEngine

* Ability to add and remove virtual properties

* Do not try to render empty PropertyOwner name
Compile fix for iswaComponent
Add example in default.scene

* Delete virtual properties also in the OpenSpaceEngine dtor

* Make RenderablePlanet not crash if the nighttextures are not present

* - Add VirtualPropertyManager to manage ownership of virtual properties
- Only execute regex when it was necessary
-
This commit is contained in:
Alexander Bock
2017-04-13 14:38:28 -04:00
committed by GitHub
parent 8a617ee254
commit 76aed0578c
18 changed files with 499 additions and 97 deletions
+2
View File
@@ -37,6 +37,7 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/engine/openspaceengine.cpp
${OPENSPACE_BASE_DIR}/src/engine/settingsengine.cpp
${OPENSPACE_BASE_DIR}/src/engine/syncengine.cpp
${OPENSPACE_BASE_DIR}/src/engine/virtualpropertymanager.cpp
${OPENSPACE_BASE_DIR}/src/engine/wrapper/sgctwindowwrapper.cpp
${OPENSPACE_BASE_DIR}/src/engine/wrapper/windowwrapper.cpp
${OPENSPACE_BASE_DIR}/src/interaction/controller.cpp
@@ -174,6 +175,7 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/engine/openspaceengine.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/settingsengine.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/syncengine.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/virtualpropertymanager.h
${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
+30 -1
View File
@@ -34,6 +34,7 @@
#include <openspace/engine/moduleengine.h>
#include <openspace/engine/settingsengine.h>
#include <openspace/engine/syncengine.h>
#include <openspace/engine/virtualpropertymanager.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/interaction/interactionhandler.h>
#include <openspace/interaction/luaconsole.h>
@@ -135,6 +136,7 @@ OpenSpaceEngine::OpenSpaceEngine(
, _parallelConnection(new ParallelConnection)
, _windowWrapper(std::move(windowWrapper))
, _globalPropertyNamespace(new properties::PropertyOwner(""))
, _virtualPropertyManager(new VirtualPropertyManager)
, _scheduledSceneSwitch(false)
, _scenePath("")
, _runTime(0.0)
@@ -148,7 +150,7 @@ OpenSpaceEngine::OpenSpaceEngine(
_globalPropertyNamespace->addPropertySubOwner(_settingsEngine.get());
_globalPropertyNamespace->addPropertySubOwner(_renderEngine.get());
_globalPropertyNamespace->addPropertySubOwner(_windowWrapper.get());
FactoryManager::initialize();
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Renderable>>(),
@@ -1170,6 +1172,24 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
&luascriptfunctions::writeDocumentation,
"",
"Writes out documentation files"
},
{
"addVirtualProperty",
&luascriptfunctions::addVirtualProperty,
"type, name, identifier, [value, minimumValue, maximumValue]",
"Adds a virtual property that will set a group of properties"
},
{
"removeVirtualProperty",
&luascriptfunctions::removeVirtualProperty,
"string",
"Removes a previously added virtual property"
},
{
"removeAllVirtualProperties",
&luascriptfunctions::removeAllVirtualProperties,
"",
"Remove all registered virtual properties"
}
}
};
@@ -1315,6 +1335,15 @@ properties::PropertyOwner& OpenSpaceEngine::globalPropertyOwner() {
return *_globalPropertyNamespace;
}
VirtualPropertyManager& OpenSpaceEngine::virtualPropertyManager() {
ghoul_assert(
_virtualPropertyManager,
"Virtual Property Manager must not be nullptr"
);
return *_virtualPropertyManager;
}
ScriptEngine& OpenSpaceEngine::scriptEngine() {
ghoul_assert(_scriptEngine, "ScriptEngine must not be nullptr");
return *_scriptEngine;
+86 -6
View File
@@ -32,13 +32,14 @@ namespace luascriptfunctions {
* reached
*/
int toggleShutdown(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 0)
const int nArguments = lua_gettop(L);
if (nArguments != 0) {
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
}
OsEng.toggleShutdownMode();
return 1;
return 0;
}
/**
@@ -47,13 +48,92 @@ int toggleShutdown(lua_State* L) {
* Writes out documentation files
*/
int writeDocumentation(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 0)
const int nArguments = lua_gettop(L);
if (nArguments != 0) {
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
}
OsEng.writeDocumentation();
return 1;
return 0;
}
/**
* \ingroup LuaScripts
* addVirtualProperty():
* Adds a virtual property that will set a group of properties
*/
int addVirtualProperty(lua_State* L) {
using namespace properties;
const int nArguments = lua_gettop(L);
if (nArguments != 6) {
return luaL_error(L, "Expected %i arguments, got %i", 6, nArguments);
}
const std::string type = lua_tostring(L, -6);
const std::string name = lua_tostring(L, -5);
const std::string identifier = lua_tostring(L, -4);
std::unique_ptr<Property> prop;
if (type == "BoolProperty") {
bool v = lua_toboolean(L, -3);
prop = std::make_unique<BoolProperty>(identifier, name, v);
}
else if (type == "IntProperty") {
int v = static_cast<int>(lua_tonumber(L, -3));
int min = static_cast<int>(lua_tonumber(L, -2));
int max = static_cast<int>(lua_tonumber(L, -1));
prop = std::make_unique<IntProperty>(identifier, name, v, min, max);
}
else if (type == "FloatProperty") {
float v = static_cast<float>(lua_tonumber(L, -3));
float min = static_cast<float>(lua_tonumber(L, -2));
float max = static_cast<float>(lua_tonumber(L, -1));
prop = std::make_unique<FloatProperty>(identifier, name, v, min, max);
}
else if (type == "TriggerProperty") {
prop = std::make_unique<TriggerProperty>(identifier, name);
}
else {
return luaL_error(L, "Unknown property type '%s'", type.c_str());
}
OsEng.virtualPropertyManager().addProperty(std::move(prop));
return 0;
}
/**
* \ingroup LuaScripts
* removeVirtualProperty():
* Removes a previously added virtual property
*/
int removeVirtualProperty(lua_State* L) {
const int nArguments = lua_gettop(L);
if (nArguments != 1) {
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
}
const std::string name = lua_tostring(L, -1);
properties::Property* p = OsEng.virtualPropertyManager().property(name);
OsEng.virtualPropertyManager().removeProperty(p);
return 0;
}
/**
* \ingroup LuaScripts
* removeAllVirtualProperties():
* Remove all registered virtual properties
*/
int removeAllVirtualProperties(lua_State* L) {
std::vector<properties::Property*> ps = OsEng.virtualPropertyManager().properties();
for (properties::Property* p : ps) {
OsEng.virtualPropertyManager().removeProperty(p);
delete p;
}
return 0;
}
+58
View File
@@ -0,0 +1,58 @@
/*****************************************************************************************
* *
* 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/engine/virtualpropertymanager.h>
namespace openspace {
VirtualPropertyManager::VirtualPropertyManager()
: properties::PropertyOwner("")
{
}
void VirtualPropertyManager::addProperty(std::unique_ptr<properties::Property> prop) {
// PropertyOwner does not take the ownership of the pointer
properties::PropertyOwner::addProperty(prop.get());
// So we store the pointer locally instead
_properties.push_back(std::move(prop));
}
void VirtualPropertyManager::removeProperty(properties::Property* prop) {
properties::PropertyOwner::removeProperty(prop);
_properties.erase(
std::remove_if(
_properties.begin(),
_properties.end(),
[prop](const std::unique_ptr<properties::Property>& p) {
return p.get() == prop;
}
),
_properties.end()
);
}
} // namespace openspace
+10
View File
@@ -25,6 +25,7 @@
#include <openspace/query/query.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/virtualpropertymanager.h>
#include <openspace/interaction/interactionhandler.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/rendering/renderable.h>
@@ -108,6 +109,15 @@ std::vector<properties::Property*> allProperties() {
p.end()
);
std::vector<properties::Property*> q =
OsEng.virtualPropertyManager().propertiesRecursive();
properties.insert(
properties.end(),
q.begin(),
q.end()
);
const Scene* graph = sceneGraph();
std::vector<SceneGraphNode*> nodes = graph->allSceneGraphNodes();