Merge branch 'master' of github.com:OpenSpace/OpenSpace

This commit is contained in:
Alexander Bock
2022-02-10 16:00:40 +01:00
23 changed files with 102 additions and 479 deletions
-17
View File
@@ -30,7 +30,6 @@
#include <openspace/engine/moduleengine.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/syncengine.h>
#include <openspace/engine/virtualpropertymanager.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/events/eventengine.h>
#include <openspace/interaction/actionmanager.h>
@@ -89,7 +88,6 @@ namespace {
sizeof(SyncEngine) +
sizeof(TimeManager) +
sizeof(VersionChecker) +
sizeof(VirtualPropertyManager) +
sizeof(WindowDelegate) +
sizeof(configuration::Configuration) +
sizeof(interaction::ActionManager) +
@@ -258,14 +256,6 @@ void create() {
versionChecker = new VersionChecker;
#endif // WIN32
#ifdef WIN32
virtualPropertyManager = new (currentPos) VirtualPropertyManager;
ghoul_assert(virtualPropertyManager, "No virtualPropertyManager");
currentPos += sizeof(VirtualPropertyManager);
#else // ^^^ WIN32 / !WIN32 vvv
virtualPropertyManager = new VirtualPropertyManager;
#endif // WIN32
#ifdef WIN32
windowDelegate = new (currentPos) WindowDelegate;
ghoul_assert(windowDelegate, "No windowDelegate");
@@ -507,13 +497,6 @@ void destroy() {
delete windowDelegate;
#endif // WIN32
LDEBUGC("Globals", "Destroying 'VirtualPropertyManager'");
#ifdef WIN32
virtualPropertyManager->~VirtualPropertyManager();
#else // ^^^ WIN32 / !WIN32 vvv
delete virtualPropertyManager;
#endif // WIN32
LDEBUGC("Globals", "Destroying 'VersionChecker'");
#ifdef WIN32
versionChecker->~VersionChecker();
-20
View File
@@ -34,7 +34,6 @@
#include <openspace/engine/logfactory.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/engine/syncengine.h>
#include <openspace/engine/virtualpropertymanager.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/events/event.h>
#include <openspace/events/eventengine.h>
@@ -1811,25 +1810,6 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
"",
"Downloads a file from Lua scope"
},
{
"addVirtualProperty",
&luascriptfunctions::addVirtualProperty,
"type, name, identifier,"
"[description, 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"
},
{
"setScreenshotFolder",
&luascriptfunctions::setScreenshotFolder,
-102
View File
@@ -59,108 +59,6 @@ int writeDocumentation(lua_State* L) {
return 0;
}
/**
* \ingroup LuaScripts
* addVirtualProperty():
* Adds a virtual property that will set a group of properties
*/
int addVirtualProperty(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, { 5, 7 }, "lua::addVirtualProperty");
auto [type, name, identifier, description] =
ghoul::lua::values<std::string, std::string, std::string, std::string>(L);
std::unique_ptr<properties::Property> prop;
if (type == "BoolProperty") {
const bool v = ghoul::lua::value<bool>(L);
prop = std::make_unique<properties::BoolProperty>(
properties::Property::PropertyInfo {
identifier.c_str(),
name.c_str(),
description.c_str()
},
v
);
}
else if (type == "IntProperty") {
auto [v, min, max] = ghoul::lua::values<int, int, int>(L);
prop = std::make_unique<properties::IntProperty>(
properties::Property::PropertyInfo {
identifier.c_str(),
name.c_str(),
description.c_str()
},
v,
min,
max
);
}
else if (type == "FloatProperty") {
auto [v, min, max] = ghoul::lua::values<float, float, float>(L);
prop = std::make_unique<properties::FloatProperty>(
properties::Property::PropertyInfo {
identifier.c_str(),
name.c_str(),
description.c_str()
},
v,
min,
max
);
}
else if (type == "TriggerProperty") {
prop = std::make_unique<properties::TriggerProperty>(
properties::Property::PropertyInfo {
identifier.c_str(),
name.c_str(),
description.c_str()
}
);
}
else {
return ghoul::lua::luaError(L, fmt::format("Unknown property type '{}'", type));
}
global::virtualPropertyManager->addProperty(std::move(prop));
return 0;
}
/**
* \ingroup LuaScripts
* removeVirtualProperty():
* Removes a previously added virtual property
*/
int removeVirtualProperty(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::removeVirtualProperty");
const std::string name = ghoul::lua::value<std::string>(L);
properties::Property* p = global::virtualPropertyManager->property(name);
if (p) {
global::virtualPropertyManager->removeProperty(p);
}
else {
LWARNINGC(
"removeVirtualProperty",
fmt::format("Virtual Property with name '{}' did not exist", name)
);
}
return 0;
}
/**
* \ingroup LuaScripts
* removeAllVirtualProperties():
* Remove all registered virtual properties
*/
int removeAllVirtualProperties(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::removeAllVirtualProperties");
for (properties::Property* p : global::virtualPropertyManager->properties()) {
global::virtualPropertyManager->removeProperty(p);
delete p;
}
return 0;
}
int setScreenshotFolder(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::setScreenshotFolder");
const std::string arg = ghoul::lua::value<std::string>(L);
-62
View File
@@ -1,62 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2022 *
* *
* 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>
#include <openspace/properties/property.h>
#include <algorithm>
namespace openspace {
// The VirtualPropertyManager cannot have an identifier (and thus cannot be part of
// another PropertyOwner) as otherwise the regex-as-name trick would no longer work. I
// don't particular like this implementation, but it's what we got for now; I'm open to
// replacing it with a better mechanism
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