mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 04:58:59 -05:00
Merge branch 'develop' into feature/globebrowsing
# Conflicts: # modules/globebrowsing/chunk/chunkrenderer.cpp # modules/globebrowsing/globes/renderableglobe.cpp # modules/globebrowsing/globes/renderableglobe.h
This commit is contained in:
+100
-4
@@ -65,15 +65,61 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/performance/performancemeasurement.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/performance/performancelayout.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/performance/performancemanager.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrixproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/optionproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/propertyowner.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalarproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/selectionproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/stringproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/triggerproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vectorproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat2x3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat2x4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat3x2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat3x4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat4x2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat4x3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/dmat4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat2x3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat2x4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat3x2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat3x4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat4x2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat4x3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrix/mat4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/boolproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/charproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/doubleproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/floatproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/intproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/longdoubleproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/longlongproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/longproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/shortproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/signedcharproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/ucharproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/uintproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/ulonglongproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/ulongproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/ushortproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/scalar/wcharproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/bvec2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/bvec3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/bvec4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/dvec2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/dvec3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/dvec4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/ivec2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/ivec3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/ivec4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/uvec2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/uvec3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/uvec4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/vec2property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/vec3property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/vector/vec4property.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/query/query.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/abufferrenderer.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/framebufferrenderer.cpp
|
||||
@@ -94,8 +140,9 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/scene/scenegraphnode_doc.inl
|
||||
${OPENSPACE_BASE_DIR}/src/scripting/lualibrary.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scripting/scriptengine.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scripting/scriptscheduler.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scripting/scriptengine_lua.inl
|
||||
${OPENSPACE_BASE_DIR}/src/scripting/scriptscheduler.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scripting/scriptscheduler_lua.inl
|
||||
${OPENSPACE_BASE_DIR}/src/util/blockplaneintersectiongeometry.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/boxgeometry.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/camera.cpp
|
||||
@@ -173,6 +220,55 @@ set(OPENSPACE_HEADER
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/templateproperty.inl
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/triggerproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vectorproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat2x3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat2x4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat3x2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat3x4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat4x2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat4x3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/dmat4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat2x3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat2x4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat3x2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat3x4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat4x2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat4x3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrix/mat4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/boolproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/charproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/doubleproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/floatproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/intproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/longdoubleproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/longlongproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/longproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/shortproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/signedcharproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/ucharproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/uintproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/ulonglongproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/ulongproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/ushortproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/scalar/wcharproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/bvec2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/bvec3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/bvec4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/dvec2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/dvec3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/dvec4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/ivec2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/ivec3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/ivec4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/uvec2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/uvec3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/uvec4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/vec2property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/vec3property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/vector/vec4property.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/query/query.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/abufferrenderer.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/framebufferrenderer.h
|
||||
|
||||
@@ -867,11 +867,10 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
_timeManager->preSynchronization(dt);
|
||||
|
||||
auto scheduledScripts = _scriptScheduler->progressTo(Time::ref().j2000Seconds());
|
||||
while(scheduledScripts.size()){
|
||||
auto scheduledScript = scheduledScripts.front();
|
||||
LINFO(scheduledScript);
|
||||
_scriptEngine->queueScript(scheduledScript, ScriptEngine::RemoteScripting::Yes);
|
||||
scheduledScripts.pop();
|
||||
for (auto it = scheduledScripts.first; it != scheduledScripts.second; ++it) {
|
||||
_scriptEngine->queueScript(
|
||||
*it, ScriptEngine::RemoteScripting::Yes
|
||||
);
|
||||
}
|
||||
|
||||
_interactionHandler->updateInputStates(dt);
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
|
||||
|
||||
#include <ghoul/ghoul.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
@@ -41,11 +43,8 @@ namespace {
|
||||
const std::string _loggerCat = "SettingsEngine";
|
||||
}
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
|
||||
SettingsEngine::SettingsEngine()
|
||||
: _eyeSeparation("eyeSeparation", "Eye Separation" , 0.f, 0.f, 10.f)
|
||||
, _scenes("scenes", "Scene", properties::OptionProperty::DisplayType::Dropdown)
|
||||
@@ -53,8 +52,19 @@ SettingsEngine::SettingsEngine()
|
||||
, _busyWaitForDecode("busyWaitForDecode", "Busy Wait for decode", false)
|
||||
, _logSGCTOutOfOrderErrors("logSGCTOutOfOrderErrors", "Log SGCT out-of-order", false)
|
||||
, _useDoubleBuffering("useDoubleBuffering", "Use double buffering", false)
|
||||
, _spiceUseExceptions("enableSpiceExceptions", "Enable Spice Exceptions", false)
|
||||
{
|
||||
setName("Global Properties");
|
||||
|
||||
_spiceUseExceptions.onChange([this]{
|
||||
if (_spiceUseExceptions) {
|
||||
SpiceManager::ref().setExceptionHandling(SpiceManager::UseException::Yes);
|
||||
}
|
||||
else {
|
||||
SpiceManager::ref().setExceptionHandling(SpiceManager::UseException::No);
|
||||
}
|
||||
});
|
||||
addProperty(_spiceUseExceptions);
|
||||
}
|
||||
|
||||
void SettingsEngine::initialize() {
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat2property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2Property, glm::dmat2x2, glm::dmat2x2(0),
|
||||
glm::dmat2x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x2(
|
||||
0.01, 0.01,
|
||||
0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,144 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat2x3property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x3Property, glm::dmat2x3, glm::dmat2x3(0),
|
||||
glm::dmat2x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,148 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat2x4property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x4Property, glm::dmat2x4, glm::dmat2x4(0),
|
||||
glm::dmat2x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,151 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat3property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3Property, glm::dmat3x3, glm::dmat3x3(0),
|
||||
glm::dmat3x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,144 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat3x2property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x2Property, glm::dmat3x2, glm::dmat3x2(0),
|
||||
glm::dmat3x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,157 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat3x4property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x4Property, glm::dmat3x4, glm::dmat3x4(0),
|
||||
glm::dmat3x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,166 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat4property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4Property, glm::dmat4x4, glm::dmat4x4(0),
|
||||
glm::dmat4x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,148 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat4x2property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x2Property, glm::dmat4x2, glm::dmat4x2(0),
|
||||
glm::dmat4x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,157 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/dmat4x3property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x3Property, glm::dmat4x3, glm::dmat4x3(0),
|
||||
glm::dmat4x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,140 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat2property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2Property, glm::mat2x2, glm::mat2x2(0),
|
||||
glm::mat2x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x2(
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,144 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat2x3property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x3Property, glm::mat2x3, glm::mat2x3(0),
|
||||
glm::mat2x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,148 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat2x4property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x4Property, glm::mat2x4, glm::mat2x4(0),
|
||||
glm::mat2x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,151 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat3property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3Property, glm::mat3x3, glm::mat3x3(0),
|
||||
glm::mat3x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,144 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat3x2property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x2Property, glm::mat3x2, glm::mat3x2(0),
|
||||
glm::mat3x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x2(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,157 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat3x4property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x4Property, glm::mat3x4, glm::mat3x4(0),
|
||||
glm::mat3x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,166 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat4property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4Property, glm::mat4x4, glm::mat4x4(0),
|
||||
glm::mat4x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,148 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat4x2property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x2Property, glm::mat4x2, glm::mat4x2(0),
|
||||
glm::mat4x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x2(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,157 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrix/mat4x3property.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x3Property, glm::mat4x3, glm::mat4x3(0),
|
||||
glm::mat4x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x3(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -1,721 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/matrixproperty.h>
|
||||
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2Property, glm::mat2x2, glm::mat2x2(0),
|
||||
glm::mat2x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x2(
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x3Property, glm::mat2x3, glm::mat2x3(0),
|
||||
glm::mat2x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x4Property, glm::mat2x4, glm::mat2x4(0),
|
||||
glm::mat2x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x2Property, glm::mat3x2, glm::mat3x2(0),
|
||||
glm::mat3x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x2(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3Property, glm::mat3x3, glm::mat3x3(0),
|
||||
glm::mat3x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x4Property, glm::mat3x4, glm::mat3x4(0),
|
||||
glm::mat3x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x2Property, glm::mat4x2, glm::mat4x2(0),
|
||||
glm::mat4x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x2(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x3Property, glm::mat4x3, glm::mat4x3(0),
|
||||
glm::mat4x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x3(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4Property, glm::mat4x4, glm::mat4x4(0),
|
||||
glm::mat4x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2Property, glm::dmat2x2, glm::dmat2x2(0),
|
||||
glm::dmat2x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x2(
|
||||
0.01, 0.01,
|
||||
0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x3Property, glm::dmat2x3, glm::dmat2x3(0),
|
||||
glm::dmat2x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x4Property, glm::dmat2x4, glm::dmat2x4(0),
|
||||
glm::dmat2x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x2Property, glm::dmat3x2, glm::dmat3x2(0),
|
||||
glm::dmat3x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3Property, glm::dmat3x3, glm::dmat3x3(0),
|
||||
glm::dmat3x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x4Property, glm::dmat3x4, glm::dmat3x4(0),
|
||||
glm::dmat3x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x2Property, glm::dmat4x2, glm::dmat4x2(0),
|
||||
glm::dmat4x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x3Property, glm::dmat4x3, glm::dmat4x3(0),
|
||||
glm::dmat4x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4Property, glm::dmat4x4, glm::dmat4x4(0),
|
||||
glm::dmat4x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -33,13 +33,15 @@ namespace properties {
|
||||
|
||||
const std::string OptionProperty::OptionsKey = "Options";
|
||||
|
||||
OptionProperty::OptionProperty(std::string identifier, std::string guiName)
|
||||
: IntProperty(std::move(identifier), std::move(guiName))
|
||||
OptionProperty::OptionProperty(std::string identifier, std::string guiName,
|
||||
Property::Visibility visibility)
|
||||
: IntProperty(std::move(identifier), std::move(guiName), visibility)
|
||||
, _displayType(DisplayType::Radio)
|
||||
{}
|
||||
|
||||
OptionProperty::OptionProperty(std::string identifier, std::string guiName, DisplayType displayType)
|
||||
: IntProperty(std::move(identifier), std::move(guiName))
|
||||
OptionProperty::OptionProperty(std::string identifier, std::string guiName,
|
||||
DisplayType displayType, Property::Visibility visibility)
|
||||
: IntProperty(std::move(identifier), std::move(guiName), visibility)
|
||||
, _displayType(displayType)
|
||||
{}
|
||||
|
||||
|
||||
+26
-15
@@ -35,7 +35,7 @@ namespace {
|
||||
const std::string _loggerCat = "Property";
|
||||
const std::string MetaDataKeyGuiName = "guiName";
|
||||
const std::string MetaDataKeyGroup = "Group";
|
||||
const std::string MetaDataKeyVisible = "isVisible";
|
||||
const std::string MetaDataKeyVisibility = "Visibility";
|
||||
const std::string MetaDataKeyReadOnly = "isReadOnly";
|
||||
|
||||
const std::string _metaDataKeyViewPrefix = "view.";
|
||||
@@ -51,14 +51,14 @@ const std::string Property::NameKey = "Name";
|
||||
const std::string Property::TypeKey = "Type";
|
||||
const std::string Property::MetaDataKey = "MetaData";
|
||||
|
||||
Property::Property(std::string identifier, std::string guiName)
|
||||
Property::Property(std::string identifier, std::string guiName, Visibility visibility)
|
||||
: _owner(nullptr)
|
||||
, _identifier(std::move(identifier))
|
||||
{
|
||||
ghoul_assert(!_identifier.empty(), "Identifier must not be empty");
|
||||
ghoul_assert(!guiName.empty(), "guiName must not be empty");
|
||||
|
||||
setVisible(true);
|
||||
setVisibility(visibility);
|
||||
_metaData.setValue(MetaDataKeyGuiName, std::move(guiName));
|
||||
}
|
||||
|
||||
@@ -131,14 +131,18 @@ std::string Property::groupIdentifier() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
void Property::setVisible(bool state) {
|
||||
_metaData.setValue(MetaDataKeyVisible, state);
|
||||
void Property::setVisibility(Visibility visibility) {
|
||||
_metaData.setValue(
|
||||
MetaDataKeyVisibility,
|
||||
static_cast<std::underlying_type_t<Visibility>>(visibility)
|
||||
);
|
||||
}
|
||||
|
||||
bool Property::isVisible() const {
|
||||
bool visible = true;
|
||||
_metaData.getValue(MetaDataKeyVisible, visible);
|
||||
return visible;
|
||||
Property::Visibility Property::visibility() const {
|
||||
return
|
||||
static_cast<Visibility>(
|
||||
_metaData.value<std::underlying_type_t<Visibility>>(MetaDataKeyVisibility)
|
||||
);
|
||||
}
|
||||
|
||||
void Property::setReadOnly(bool state) {
|
||||
@@ -185,15 +189,22 @@ std::string Property::generateBaseDescription() const {
|
||||
}
|
||||
|
||||
std::string Property::generateMetaDataDescription() const {
|
||||
bool isVisible, isReadOnly;
|
||||
_metaData.getValue(MetaDataKeyVisible, isVisible);
|
||||
_metaData.getValue(MetaDataKeyReadOnly, isReadOnly);
|
||||
static const std::map<Visibility, std::string> VisibilityConverter = {
|
||||
{ Visibility::All, "All" },
|
||||
{ Visibility::Developer, "Developer" },
|
||||
{ Visibility::User, "User" },
|
||||
{ Visibility::None, "None" }
|
||||
};
|
||||
Visibility visibility = _metaData.value<Visibility>(MetaDataKeyVisibility);
|
||||
bool isReadOnly = _metaData.value<bool>(MetaDataKeyReadOnly);
|
||||
|
||||
std::string vis = VisibilityConverter.at(visibility);
|
||||
|
||||
return
|
||||
MetaDataKey + " = {" +
|
||||
MetaDataKeyGroup + " = '" + groupIdentifier() + "'," +
|
||||
MetaDataKeyVisible + " = " + (isVisible ? "true" : "false") + "," +
|
||||
MetaDataKeyReadOnly +" = " + (isReadOnly ? "true" : "false") + "}";
|
||||
MetaDataKeyGroup + " = '" + groupIdentifier() + "'," +
|
||||
MetaDataKeyVisibility + " = " + vis + "," +
|
||||
MetaDataKeyReadOnly +" = " + (isReadOnly ? "true" : "false") + "}";
|
||||
}
|
||||
|
||||
std::string Property::generateAdditionalDescription() const {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/boolproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BoolProperty, bool, false,
|
||||
[](lua_State* state, bool& success) -> bool {
|
||||
success = (lua_isboolean(state, -1) == 1);
|
||||
if (success) {
|
||||
return lua_toboolean(state, -1) == 1;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[](lua_State* state, bool value) -> bool {
|
||||
lua_pushboolean(state, value);
|
||||
return true;
|
||||
},
|
||||
[](std::string value, bool& success) -> bool {
|
||||
std::stringstream s(value);
|
||||
bool v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
},
|
||||
[](std::string& outValue, bool inValue) -> bool {
|
||||
outValue = inValue ? "true" : "false";
|
||||
return true;
|
||||
},
|
||||
LUA_TBOOLEAN
|
||||
);
|
||||
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/charproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(CharProperty, char, char(0),
|
||||
numeric_limits<char>::lowest(),
|
||||
numeric_limits<char>::max(), char(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(char, char(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(char, char(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(char),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/doubleproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DoubleProperty, double, 0.0,
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::max(), 0.01,
|
||||
DEFAULT_FROM_LUA_LAMBDA(double, double(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(double),
|
||||
DEFAULT_FROM_STRING_LAMBDA(double, double(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(double),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(FloatProperty, float, 0.f,
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::max(), 0.01f,
|
||||
DEFAULT_FROM_LUA_LAMBDA(float, float(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(float),
|
||||
DEFAULT_FROM_STRING_LAMBDA(float, float(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(float),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,80 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/intproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IntProperty, int, int(0), numeric_limits<int>::lowest(),
|
||||
numeric_limits<int>::max(), int(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(int, int(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(int),
|
||||
DEFAULT_FROM_STRING_LAMBDA(int, int(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(int),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,82 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/longdoubleproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongDoubleProperty, long double, (long double)0,
|
||||
numeric_limits<long double>::lowest(),
|
||||
numeric_limits<long double>::max(), (long double)0.01f,
|
||||
DEFAULT_FROM_LUA_LAMBDA(long double, (long double)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(long double),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long double,
|
||||
(long double)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(long double),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,82 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/longlongproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongLongProperty, long long, (long long)0,
|
||||
numeric_limits<long long>::lowest(),
|
||||
numeric_limits<long long>::max(), (long long)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(long long, (long long)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(long long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long long,
|
||||
(long long)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(long long),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/longproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongProperty, long, long(0),
|
||||
numeric_limits<long>::lowest(),
|
||||
numeric_limits<long>::max(), long(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(long, long(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long, long(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(long),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/shortproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ShortProperty, short, short(0),
|
||||
numeric_limits<short>::lowest(),
|
||||
numeric_limits<short>::max(), short(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(short, short(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(short),
|
||||
DEFAULT_FROM_STRING_LAMBDA(short, short(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(short),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/signedcharproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(SignedCharProperty, signed char, (signed char)(0),
|
||||
numeric_limits<signed char>::lowest(),
|
||||
numeric_limits<signed char>::max(), (signed char)0,
|
||||
DEFAULT_FROM_LUA_LAMBDA(signed char, (signed char)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(signed char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(signed char, (signed char)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(signed char),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,80 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/ucharproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
else \
|
||||
return DEFAULT_VALUE; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) \
|
||||
return v; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UCharProperty, unsigned char, (unsigned char)0,
|
||||
numeric_limits<unsigned char>::lowest(),
|
||||
numeric_limits<unsigned char>::max(), (unsigned char)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned char,
|
||||
(unsigned char)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned char,
|
||||
(unsigned char)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned char),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,80 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/uintproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
else \
|
||||
return DEFAULT_VALUE; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) \
|
||||
return v; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UCharProperty, unsigned int, (unsigned int)0,
|
||||
numeric_limits<unsigned int>::lowest(),
|
||||
numeric_limits<unsigned int>::max(), (unsigned int)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned int,
|
||||
(unsigned int)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned int),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned int,
|
||||
(unsigned int)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned int),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,85 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/ulonglongproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ULongLongProperty, unsigned long long,
|
||||
(unsigned long long)1,
|
||||
numeric_limits<unsigned long long>::lowest(),
|
||||
numeric_limits<unsigned long long>::max(),
|
||||
(unsigned long long)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned long long,
|
||||
(unsigned long long)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned long long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned long long,
|
||||
(unsigned long long)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned long long),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,83 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/ulongproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ULongProperty, unsigned long, (unsigned long)0,
|
||||
numeric_limits<unsigned long>::lowest(),
|
||||
numeric_limits<unsigned long>::max(), (unsigned long)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned long,
|
||||
(unsigned long)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned long,
|
||||
(unsigned long)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned long),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,84 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/ushortproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UShortProperty, unsigned short, (unsigned short)(0),
|
||||
numeric_limits<unsigned short>::lowest(),
|
||||
numeric_limits<unsigned short>::max(),
|
||||
(unsigned short)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned short,
|
||||
(unsigned short)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned short),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned short,
|
||||
(unsigned short)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned short),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,75 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalar/wcharproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
}
|
||||
|
||||
//REGISTER_NUMERICALPROPERTY_SOURCE(WCharProperty, wchar_t, wchar_t(0),
|
||||
// numeric_limits<wchar_t>::lowest(),
|
||||
// numeric_limits<wchar_t>::max(), wchar_t(1),
|
||||
// DEFAULT_FROM_LUA_LAMBDA(wchar_t, wchar_t(0)),
|
||||
// DEFAULT_TO_LUA_LAMBDA(wchar_t),
|
||||
// DEFAULT_FROM_STRING_LAMBDA(wchar_t, wchar_t(0)),
|
||||
// DEFAULT_TO_STRING_LAMBDA(wchar_t),
|
||||
// LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -1,247 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/scalarproperty.h"
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
else \
|
||||
return DEFAULT_VALUE; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
std::stringstream s(value); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) \
|
||||
return v; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
// char16_t and char32_t are not supported on Visual Studio 2013 and are defined to
|
||||
// be equal to unsigned short and unsigned int which causes a compile error
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BoolProperty, bool, false,
|
||||
[](lua_State* state, bool& success) -> bool {
|
||||
success = (lua_isboolean(state, -1) == 1);
|
||||
if (success)
|
||||
return lua_toboolean(state, -1) == 1;
|
||||
else
|
||||
return false;
|
||||
},
|
||||
[](lua_State* state, bool value) -> bool {
|
||||
lua_pushboolean(state, value);
|
||||
return true;
|
||||
},
|
||||
DEFAULT_FROM_STRING_LAMBDA(bool, false),
|
||||
[](std::string& outValue, bool inValue) -> bool {
|
||||
outValue = inValue ? "true" : "false";
|
||||
return true;
|
||||
},
|
||||
LUA_TBOOLEAN
|
||||
);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(CharProperty, char, char(0),
|
||||
numeric_limits<char>::lowest(),
|
||||
numeric_limits<char>::max(), char(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(char, char(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(char, char(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(char),
|
||||
LUA_TNUMBER);
|
||||
|
||||
// REGISTER_NUMERICALPROPERTY_SOURCE(Char16Property, char16_t, char16_t(0),
|
||||
// numeric_limits<char16_t>::lowest(), numeric_limits<char16_t>::max(), char16_t(1));
|
||||
|
||||
// REGISTER_NUMERICALPROPERTY_SOURCE(Char32Property, char32_t, char32_t(0),
|
||||
// numeric_limits<char32_t>::lowest(), numeric_limits<char32_t>::max(), char32_t(1));
|
||||
|
||||
//REGISTER_NUMERICALPROPERTY_SOURCE(WCharProperty, wchar_t, wchar_t(0),
|
||||
// numeric_limits<wchar_t>::lowest(),
|
||||
// numeric_limits<wchar_t>::max(), wchar_t(1),
|
||||
// DEFAULT_FROM_LUA_LAMBDA(wchar_t, wchar_t(0)),
|
||||
// DEFAULT_TO_LUA_LAMBDA(wchar_t),
|
||||
// DEFAULT_FROM_STRING_LAMBDA(wchar_t, wchar_t(0)),
|
||||
// DEFAULT_TO_STRING_LAMBDA(wchar_t),
|
||||
// LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(SignedCharProperty, signed char, (signed char)(0),
|
||||
numeric_limits<signed char>::lowest(),
|
||||
numeric_limits<signed char>::max(), (signed char)0,
|
||||
DEFAULT_FROM_LUA_LAMBDA(signed char, (signed char)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(signed char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(signed char, (signed char)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(signed char),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UCharProperty, unsigned char, (unsigned char)0,
|
||||
numeric_limits<unsigned char>::lowest(),
|
||||
numeric_limits<unsigned char>::max(), (unsigned char)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned char,
|
||||
(unsigned char)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned char,
|
||||
(unsigned char)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned char),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ShortProperty, short, short(0),
|
||||
numeric_limits<short>::lowest(),
|
||||
numeric_limits<short>::max(), short(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(short, short(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(short),
|
||||
DEFAULT_FROM_STRING_LAMBDA(short, short(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(short),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UShortProperty, unsigned short, (unsigned short)(0),
|
||||
numeric_limits<unsigned short>::lowest(),
|
||||
numeric_limits<unsigned short>::max(),
|
||||
(unsigned short)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned short,
|
||||
(unsigned short)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned short),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned short,
|
||||
(unsigned short)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned short),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IntProperty, int, int(0), numeric_limits<int>::lowest(),
|
||||
numeric_limits<int>::max(), int(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(int, int(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(int),
|
||||
DEFAULT_FROM_STRING_LAMBDA(int, int(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(int),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UIntProperty, unsigned int, (unsigned int)0,
|
||||
numeric_limits<unsigned int>::lowest(),
|
||||
numeric_limits<unsigned int>::max(), (unsigned int)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned int,
|
||||
(unsigned int)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned int),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned int,
|
||||
(unsigned int)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned int),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongProperty, long, long(0),
|
||||
numeric_limits<long>::lowest(),
|
||||
numeric_limits<long>::max(), long(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(long, long(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long, long(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(long),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ULongProperty, unsigned long, (unsigned long)0,
|
||||
numeric_limits<unsigned long>::lowest(),
|
||||
numeric_limits<unsigned long>::max(), (unsigned long)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned long,
|
||||
(unsigned long)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned long,
|
||||
(unsigned long)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned long),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongLongProperty, long long, (long long)0,
|
||||
numeric_limits<long long>::lowest(),
|
||||
numeric_limits<long long>::max(), (long long)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(long long, (long long)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(long long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long long,
|
||||
(long long)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(long long),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ULongLongProperty, unsigned long long,
|
||||
(unsigned long long)1,
|
||||
numeric_limits<unsigned long long>::lowest(),
|
||||
numeric_limits<unsigned long long>::max(),
|
||||
(unsigned long long)1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned long long,
|
||||
(unsigned long long)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned long long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned long long,
|
||||
(unsigned long long)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned long long),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(FloatProperty, float, 0.f,
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::max(), 0.01f,
|
||||
DEFAULT_FROM_LUA_LAMBDA(float, float(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(float),
|
||||
DEFAULT_FROM_STRING_LAMBDA(float, float(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(float),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DoubleProperty, double, 0.0,
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::max(), 0.01,
|
||||
DEFAULT_FROM_LUA_LAMBDA(double, double(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(double),
|
||||
DEFAULT_FROM_STRING_LAMBDA(double, double(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(double),
|
||||
LUA_TNUMBER);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongDoubleProperty, long double, (long double)0,
|
||||
numeric_limits<long double>::lowest(),
|
||||
numeric_limits<long double>::max(), (long double)0.01f,
|
||||
DEFAULT_FROM_LUA_LAMBDA(long double, (long double)(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(long double),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long double,
|
||||
(long double)(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(long double),
|
||||
LUA_TNUMBER);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "SelectionProperty";
|
||||
|
||||
@@ -35,8 +37,10 @@ namespace properties {
|
||||
|
||||
const std::string SelectionProperty::OptionsKey = "Options";
|
||||
|
||||
SelectionProperty::SelectionProperty(std::string identifier, std::string guiName)
|
||||
: TemplateProperty(std::move(identifier), std::move(guiName), std::vector<int>())
|
||||
SelectionProperty::SelectionProperty(std::string identifier, std::string guiName,
|
||||
Property::Visibility visibility)
|
||||
: TemplateProperty(std::move(identifier), std::move(guiName), std::vector<int>(),
|
||||
visibility)
|
||||
{}
|
||||
|
||||
void SelectionProperty::addOption(Option option) {
|
||||
|
||||
@@ -27,8 +27,9 @@
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
TriggerProperty::TriggerProperty(std::string identifier, std::string guiName)
|
||||
: Property(std::move(identifier), std::move(guiName))
|
||||
TriggerProperty::TriggerProperty(std::string identifier, std::string guiName,
|
||||
Property::Visibility visibility)
|
||||
: Property(std::move(identifier), std::move(guiName), visibility)
|
||||
{}
|
||||
|
||||
std::string TriggerProperty::className() const {
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/bvec2property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
|
||||
// Forcing value from int to bool is acceptable here (line 48)
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4800)
|
||||
#endif
|
||||
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec2Property, glm::bvec2, glm::bvec2(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec2, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(default : 4800)
|
||||
#endif
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,124 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/bvec3property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
|
||||
// Forcing value from int to bool is acceptable here (line 48)
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4800)
|
||||
#endif
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec3Property, glm::bvec3, glm::bvec3(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec3, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(default : 4800)
|
||||
#endif
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,124 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/bvec4property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
|
||||
// Forcing value from int to bool is acceptable here (line 48)
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4800)
|
||||
#endif
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec4Property, glm::bvec4, glm::bvec4(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec4, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(default : 4800)
|
||||
#endif
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/dvec2property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec2Property, glm::dvec2, glm::dvec2(0),
|
||||
glm::dvec2(numeric_limits<double>::lowest()),
|
||||
glm::dvec2(numeric_limits<double>::max()),
|
||||
glm::dvec2(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/dvec3property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec3Property, glm::dvec3, glm::dvec3(0),
|
||||
glm::dvec3(numeric_limits<double>::lowest()),
|
||||
glm::dvec3(numeric_limits<double>::max()),
|
||||
glm::dvec3(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/dvec4property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec4Property, glm::dvec4, glm::dvec4(0),
|
||||
glm::dvec4(numeric_limits<double>::lowest()),
|
||||
glm::dvec4(numeric_limits<double>::max()),
|
||||
glm::dvec4(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,116 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/ivec2property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec2Property, glm::ivec2, glm::ivec2(0),
|
||||
glm::ivec2(numeric_limits<int>::lowest()),
|
||||
glm::ivec2(numeric_limits<int>::max()), glm::ivec2(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,116 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/ivec3property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec3Property, glm::ivec3, glm::ivec3(0),
|
||||
glm::ivec3(numeric_limits<int>::lowest()),
|
||||
glm::ivec3(numeric_limits<int>::max()), glm::ivec3(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,116 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/ivec4property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec4Property, glm::ivec4, glm::ivec4(0),
|
||||
glm::ivec4(numeric_limits<int>::lowest()),
|
||||
glm::ivec4(numeric_limits<int>::max()), glm::ivec4(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/uvec2property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec2Property, glm::uvec2, glm::uvec2(0),
|
||||
glm::uvec2(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec2(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec2(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/uvec3property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec3Property, glm::uvec3, glm::uvec3(0),
|
||||
glm::uvec3(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec3(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec3(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/uvec4property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec4Property, glm::uvec4, glm::uvec4(0),
|
||||
glm::uvec4(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec4(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec4(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/vec2property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec2Property, glm::vec2, glm::vec2(0),
|
||||
glm::vec2(numeric_limits<float>::lowest()),
|
||||
glm::vec2(numeric_limits<float>::max()),
|
||||
glm::vec2(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/vec3property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec3Property, glm::vec3, glm::vec3(0),
|
||||
glm::vec3(numeric_limits<float>::lowest()),
|
||||
glm::vec3(numeric_limits<float>::max()),
|
||||
glm::vec3(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vector/vec4property.h>
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec4Property, glm::vec4, glm::vec4(0),
|
||||
glm::vec4(numeric_limits<float>::lowest()),
|
||||
glm::vec4(numeric_limits<float>::max()),
|
||||
glm::vec4(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -1,271 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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/properties/vectorproperty.h"
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int success = lua_next(state, -2); \
|
||||
if (success != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string value, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(value, ','); \
|
||||
if (tokens.size() != result.length()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else \
|
||||
result[i] = v; \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
|
||||
// Forcing value from int to bool is acceptable here (line 48)
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4800)
|
||||
#endif
|
||||
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec2Property, glm::bvec2, glm::bvec2(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec2, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec3Property, glm::bvec3, glm::bvec3(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec3, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec4Property, glm::bvec4, glm::bvec4(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec4, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(default : 4800)
|
||||
#endif
|
||||
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec2Property, glm::vec2, glm::vec2(0),
|
||||
glm::vec2(numeric_limits<float>::lowest()),
|
||||
glm::vec2(numeric_limits<float>::max()),
|
||||
glm::vec2(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec3Property, glm::vec3, glm::vec3(0),
|
||||
glm::vec3(numeric_limits<float>::lowest()),
|
||||
glm::vec3(numeric_limits<float>::max()),
|
||||
glm::vec3(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec4Property, glm::vec4, glm::vec4(0),
|
||||
glm::vec4(numeric_limits<float>::lowest()),
|
||||
glm::vec4(numeric_limits<float>::max()),
|
||||
glm::vec4(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec2Property, glm::dvec2, glm::dvec2(0),
|
||||
glm::dvec2(numeric_limits<double>::lowest()),
|
||||
glm::dvec2(numeric_limits<double>::max()),
|
||||
glm::dvec2(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec3Property, glm::dvec3, glm::dvec3(0),
|
||||
glm::dvec3(numeric_limits<double>::lowest()),
|
||||
glm::dvec3(numeric_limits<double>::max()),
|
||||
glm::dvec3(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec4Property, glm::dvec4, glm::dvec4(0),
|
||||
glm::dvec4(numeric_limits<double>::lowest()),
|
||||
glm::dvec4(numeric_limits<double>::max()),
|
||||
glm::dvec4(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec2Property, glm::ivec2, glm::ivec2(0),
|
||||
glm::ivec2(numeric_limits<int>::lowest()),
|
||||
glm::ivec2(numeric_limits<int>::max()), glm::ivec2(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec3Property, glm::ivec3, glm::ivec3(0),
|
||||
glm::ivec3(numeric_limits<int>::lowest()),
|
||||
glm::ivec3(numeric_limits<int>::max()), glm::ivec3(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec4Property, glm::ivec4, glm::ivec4(0),
|
||||
glm::ivec4(numeric_limits<int>::lowest()),
|
||||
glm::ivec4(numeric_limits<int>::max()), glm::ivec4(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec2Property, glm::uvec2, glm::uvec2(0),
|
||||
glm::uvec2(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec2(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec2(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec2),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec3Property, glm::uvec3, glm::uvec3(0),
|
||||
glm::uvec3(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec3(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec3(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec3),
|
||||
LUA_TTABLE);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec4Property, glm::uvec4, glm::uvec4(0),
|
||||
glm::uvec4(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec4(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec4(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec4),
|
||||
LUA_TTABLE);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
@@ -97,5 +97,14 @@ glm::dvec3 Translation::position(double time) {
|
||||
return position();
|
||||
}
|
||||
|
||||
void Translation::notifyObservers() {
|
||||
if (_onParameterChangeCallback) {
|
||||
_onParameterChangeCallback();
|
||||
}
|
||||
}
|
||||
|
||||
void Translation::onParameterChange(std::function<void()> callback) {
|
||||
_onParameterChangeCallback = std::move(callback);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
+211
-109
@@ -27,74 +27,154 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/spicemanager.h> // parse time
|
||||
#include <openspace/util/time.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
namespace scripting {
|
||||
#include <openspace/documentation/verifier.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ScriptScheduler";
|
||||
|
||||
const std::string KEY_TIME = "Time";
|
||||
const std::string KEY_FORWARD_SCRIPT = "ReversibleLuaScript.Forward";
|
||||
const std::string KEY_BACKWARD_SCRIPT = "ReversibleLuaScript.Backward";
|
||||
const char* KeyTime = "Time";
|
||||
const char* KeyForwardScript = "ForwardScript";
|
||||
const char* KeyBackwardScript = "BackwardScript";
|
||||
const char* KeyUniversalScript = "Script";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ScheduledScript::ScheduledScript(const ghoul::Dictionary& dict)
|
||||
: ScheduledScript() // default init first
|
||||
#include "scriptscheduler_lua.inl"
|
||||
|
||||
namespace scripting {
|
||||
|
||||
openspace::Documentation ScriptScheduler::Documentation() {
|
||||
using namespace openspace::documentation;
|
||||
|
||||
using TimeVerifier = StringVerifier;
|
||||
using LuaScriptVerifier = StringVerifier;
|
||||
|
||||
return{
|
||||
"Scheduled Scripts",
|
||||
"core_scheduledscript",
|
||||
{
|
||||
{
|
||||
"*",
|
||||
new TableVerifier({
|
||||
{
|
||||
KeyTime,
|
||||
new TimeVerifier,
|
||||
"The time at which, when the in game time passes it, the two "
|
||||
"scripts will be executed. If the traversal is forwards (towards "
|
||||
"+ infinity), the ForwardScript will be executed, otherwise the "
|
||||
"BackwardScript will be executed instead.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeyUniversalScript,
|
||||
new LuaScriptVerifier,
|
||||
"The Lua script that will be executed when the specified time is "
|
||||
"passed independent of its direction. This script will be "
|
||||
"executed before the specific scripts if both versions are "
|
||||
"specified",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyForwardScript,
|
||||
new LuaScriptVerifier,
|
||||
"The Lua script that is executed when OpenSpace passes the time "
|
||||
"in a forward direction.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyBackwardScript,
|
||||
new LuaScriptVerifier,
|
||||
"The Lua script that is executed when OpenSpace passes the time "
|
||||
"in a backward direction.",
|
||||
Optional::Yes
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
Exhaustive::Yes
|
||||
};
|
||||
}
|
||||
|
||||
ScriptScheduler::ScheduledScript::ScheduledScript(const ghoul::Dictionary& dictionary)
|
||||
: time(-std::numeric_limits<double>::max())
|
||||
{
|
||||
std::string timeStr;
|
||||
if (dict.getValue(KEY_TIME, timeStr)) {
|
||||
time = SpiceManager::ref().ephemerisTimeFromDate(timeStr);
|
||||
std::string timeStr = dictionary.value<std::string>(KeyTime);
|
||||
time = Time::ref().convertTime(timeStr);
|
||||
|
||||
// If a universal script is specified, retrieve it and add a ; as a separator so that
|
||||
// it can be added to the other scripts
|
||||
std::string universal;
|
||||
dictionary.getValue(KeyUniversalScript, universal);
|
||||
if (!universal.empty()) {
|
||||
universal += ";";
|
||||
}
|
||||
|
||||
if (dictionary.hasKeyAndValue<std::string>(KeyForwardScript)) {
|
||||
forwardScript =
|
||||
universal + dictionary.value<std::string>(KeyForwardScript);
|
||||
}
|
||||
|
||||
if (dictionary.hasKeyAndValue<std::string>(KeyBackwardScript)) {
|
||||
backwardScript =
|
||||
universal + dictionary.value<std::string>(KeyBackwardScript);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dict.getValue(KEY_FORWARD_SCRIPT, script.forwardScript)) {
|
||||
LERROR("Unable to read " << KEY_FORWARD_SCRIPT);
|
||||
}
|
||||
if (!dict.getValue(KEY_BACKWARD_SCRIPT, script.backwardScript)) {
|
||||
LERROR("Unable to read " << KEY_BACKWARD_SCRIPT);
|
||||
void ScriptScheduler::loadScripts(const ghoul::Dictionary& dictionary) {
|
||||
// Check if all of the scheduled scripts are formed correctly
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"ScriptScheduler"
|
||||
);
|
||||
|
||||
// Create all the scheduled script first
|
||||
std::vector<ScheduledScript> scheduledScripts;
|
||||
for (size_t i = 1; i <= dictionary.size(); ++i) {
|
||||
const ghoul::Dictionary& timedScriptDict = dictionary.value<ghoul::Dictionary>(
|
||||
std::to_string(i)
|
||||
);
|
||||
scheduledScripts.emplace_back(timedScriptDict);
|
||||
}
|
||||
|
||||
// Sort scripts by time; use a stable_sort as the user might have had an intention
|
||||
// specifying multiple scripts for the same time in a specific order
|
||||
std::stable_sort(
|
||||
scheduledScripts.begin(),
|
||||
scheduledScripts.end(),
|
||||
[](const ScheduledScript& lhs, const ScheduledScript& rhs) {
|
||||
return lhs.time < rhs.time;
|
||||
}
|
||||
);
|
||||
|
||||
// Move the scheduled scripts into their SOA alignment
|
||||
// For the forward scripts, this is the forwards direction
|
||||
// For the backward scripts, we insert them in the opposite order so that we can still
|
||||
// return forward iterators to them in the progressTo method
|
||||
for (ScheduledScript& script : scheduledScripts) {
|
||||
_timings.push_back(script.time);
|
||||
|
||||
_forwardScripts.push_back(std::move(script.forwardScript));
|
||||
|
||||
_backwardScripts.insert(
|
||||
_backwardScripts.begin(),
|
||||
std::move(script.backwardScript)
|
||||
);
|
||||
}
|
||||
else {
|
||||
LERROR("Unable to read " << KEY_TIME);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScheduledScript::CompareByTime(const ScheduledScript& s1, const ScheduledScript& s2){
|
||||
return s1.time < s2.time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ScriptScheduler::loadScripts(const std::string& filepath, lua_State* L) {
|
||||
ghoul::Dictionary timedScriptsDict;
|
||||
try {
|
||||
ghoul::lua::loadDictionaryFromFile(absPath(filepath), timedScriptsDict, L);
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
LERROR(e.what());
|
||||
return;
|
||||
}
|
||||
loadScripts(timedScriptsDict);
|
||||
}
|
||||
|
||||
void ScriptScheduler::loadScripts(const ghoul::Dictionary& dict) {
|
||||
for (size_t i = 0; i < dict.size(); ++i) {
|
||||
std::string id = std::to_string(i + 1);
|
||||
const ghoul::Dictionary& timedScriptDict = dict.value<ghoul::Dictionary>(id);
|
||||
_scheduledScripts.push_back(ScheduledScript(timedScriptDict));
|
||||
}
|
||||
|
||||
// Sort scripts by time
|
||||
std::stable_sort(_scheduledScripts.begin(), _scheduledScripts.end(), &ScheduledScript::CompareByTime);
|
||||
|
||||
// Ensure _currentIndex and _currentTime is accurate after new scripts was added
|
||||
double lastTime = _currentTime;
|
||||
rewind();
|
||||
progressTo(lastTime);
|
||||
|
||||
ghoul_assert(
|
||||
(_timings.size() == _forwardScripts.size()) &&
|
||||
(_timings.size() == _backwardScripts.size()),
|
||||
"The SOA data structure has been mistreated and has different number of values"
|
||||
);
|
||||
}
|
||||
|
||||
void ScriptScheduler::rewind() {
|
||||
@@ -102,91 +182,113 @@ void ScriptScheduler::rewind() {
|
||||
_currentTime = -DBL_MAX;
|
||||
}
|
||||
|
||||
|
||||
void ScriptScheduler::clearSchedule() {
|
||||
rewind();
|
||||
_scheduledScripts.clear();
|
||||
_timings.clear();
|
||||
_forwardScripts.clear();
|
||||
_backwardScripts.clear();
|
||||
}
|
||||
|
||||
std::queue<std::string> ScriptScheduler::progressTo(double newTime) {
|
||||
std::queue<std::string> triggeredScripts;
|
||||
std::pair<
|
||||
std::vector<std::string>::const_iterator, std::vector<std::string>::const_iterator
|
||||
>
|
||||
ScriptScheduler::progressTo(double newTime)
|
||||
{
|
||||
if (newTime == _currentTime) {
|
||||
return { _forwardScripts.end(), _forwardScripts.end() };
|
||||
}
|
||||
|
||||
if (newTime > _currentTime) {
|
||||
while(_currentIndex < _scheduledScripts.size() && _scheduledScripts[_currentIndex].time <= newTime){
|
||||
triggeredScripts.push(_scheduledScripts[_currentIndex].script.forwardScript);
|
||||
_currentIndex++;
|
||||
}
|
||||
// Moving forward in time; we need to find the highest entry in the timings
|
||||
// vector that is still smaller than the newTime
|
||||
size_t prevIndex = _currentIndex;
|
||||
auto it = std::upper_bound(
|
||||
_timings.begin() + prevIndex, // We only need to start at the previous time
|
||||
_timings.end(),
|
||||
newTime
|
||||
);
|
||||
|
||||
// How many values did we pass over?
|
||||
int n = std::distance(_timings.begin() + prevIndex, it);
|
||||
_currentIndex = prevIndex + n;
|
||||
|
||||
// Update the new time
|
||||
_currentTime = newTime;
|
||||
|
||||
return {
|
||||
_forwardScripts.begin() + prevIndex,
|
||||
_forwardScripts.begin() + _currentIndex
|
||||
};
|
||||
}
|
||||
else {
|
||||
while (0 < _currentIndex && _scheduledScripts[_currentIndex - 1].time > newTime) {
|
||||
triggeredScripts.push(_scheduledScripts[_currentIndex - 1].script.backwardScript);
|
||||
_currentIndex--;
|
||||
}
|
||||
// Moving backward in time; the need to find the lowest entry that is still bigger
|
||||
// than the newTime
|
||||
size_t prevIndex = _currentIndex;
|
||||
auto it = std::lower_bound(
|
||||
_timings.begin(),
|
||||
_timings.begin() + prevIndex, // We can stop at the previous time
|
||||
newTime
|
||||
);
|
||||
|
||||
// How many values did we pass over?
|
||||
int n = std::distance(it, _timings.begin() + prevIndex);
|
||||
_currentIndex = prevIndex - n;
|
||||
|
||||
// Update the new time
|
||||
_currentTime = newTime;
|
||||
|
||||
int size = _timings.size();
|
||||
return {
|
||||
_backwardScripts.begin() + (size - prevIndex),
|
||||
_backwardScripts.begin() + (size - _currentIndex)
|
||||
};
|
||||
}
|
||||
|
||||
_currentTime = newTime;
|
||||
return triggeredScripts;
|
||||
}
|
||||
|
||||
std::queue<std::string> ScriptScheduler::progressTo(const std::string& timeStr) {
|
||||
return std::move(progressTo(SpiceManager::ref().ephemerisTimeFromDate(timeStr)));
|
||||
}
|
||||
|
||||
double ScriptScheduler::currentTime() const {
|
||||
double ScriptScheduler::currentTime() const {
|
||||
return _currentTime;
|
||||
};
|
||||
|
||||
const std::vector<ScheduledScript>& ScriptScheduler::allScripts() const {
|
||||
return _scheduledScripts;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Lua library functions //
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace luascriptfunctions {
|
||||
int loadTimedScripts(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
|
||||
std::string missionFileName = luaL_checkstring(L, -1);
|
||||
if (missionFileName.empty()) {
|
||||
return luaL_error(L, "filepath string is empty");
|
||||
}
|
||||
std::vector<ScriptScheduler::ScheduledScript> ScriptScheduler::allScripts() const {
|
||||
std::vector<ScheduledScript> result;
|
||||
for (size_t i = 0; i < _timings.size(); ++i) {
|
||||
ScheduledScript script;
|
||||
script.time = _timings[i];
|
||||
script.forwardScript = _forwardScripts[i];
|
||||
script.backwardScript = _backwardScripts[i];
|
||||
|
||||
OsEng.scriptScheduler().loadScripts(missionFileName, L);
|
||||
result.push_back(std::move(script));
|
||||
}
|
||||
|
||||
int clear(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
|
||||
OsEng.scriptScheduler().clearSchedule();
|
||||
}
|
||||
} // namespace luascriptfunction
|
||||
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
LuaLibrary ScriptScheduler::luaLibrary() {
|
||||
return {
|
||||
"scriptScheduler",
|
||||
{
|
||||
{
|
||||
"load",
|
||||
&luascriptfunctions::loadTimedScripts,
|
||||
"loadFile",
|
||||
&luascriptfunctions::loadFile,
|
||||
"string",
|
||||
"Load timed scripts from file"
|
||||
"Load timed scripts from a Lua script file that returns a list of "
|
||||
"scheduled scripts."
|
||||
},
|
||||
{
|
||||
"loadScheduledScript",
|
||||
&luascriptfunctions::loadScheduledScript,
|
||||
"string, string, (string, string)",
|
||||
"Load a single scheduled script. The first argument is the time at which "
|
||||
"the scheduled script is triggered, the second argument is the script "
|
||||
"that is executed in the forward direction, the optional third argument "
|
||||
"is the script executed in the backwards direction, and the optional "
|
||||
"last argument is the universal script, executed in either direction."
|
||||
|
||||
},
|
||||
{
|
||||
"clear",
|
||||
&luascriptfunctions::clear,
|
||||
"",
|
||||
"clears all scheduled scripts"
|
||||
"Clears all scheduled scripts."
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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 luascriptfunctions {
|
||||
|
||||
int loadFile(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
|
||||
std::string missionFileName = luaL_checkstring(L, -1);
|
||||
if (missionFileName.empty()) {
|
||||
return luaL_error(L, "filepath string is empty");
|
||||
}
|
||||
|
||||
OsEng.scriptScheduler().loadScripts(
|
||||
ghoul::lua::loadDictionaryFromFile(missionFileName, L)
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int loadScheduledScript(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments == 2) {
|
||||
OsEng.scriptScheduler().loadScripts({
|
||||
{
|
||||
"1",
|
||||
ghoul::Dictionary {
|
||||
{ KeyTime, std::string(luaL_checkstring(L, -2)) },
|
||||
{ KeyForwardScript, std::string(luaL_checkstring(L, -1)) }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (nArguments == 3) {
|
||||
OsEng.scriptScheduler().loadScripts({
|
||||
{
|
||||
"1",
|
||||
ghoul::Dictionary {
|
||||
{ KeyTime, std::string(luaL_checkstring(L, -3)) },
|
||||
{ KeyForwardScript, std::string(luaL_checkstring(L, -2)) },
|
||||
{ KeyBackwardScript, std::string(luaL_checkstring(L, -1)) }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (nArguments == 4) {
|
||||
OsEng.scriptScheduler().loadScripts({
|
||||
{
|
||||
"1",
|
||||
ghoul::Dictionary {
|
||||
{ KeyTime, std::string(luaL_checkstring(L, -4)) },
|
||||
{ KeyForwardScript, std::string(luaL_checkstring(L, -3)) },
|
||||
{ KeyBackwardScript, std::string(luaL_checkstring(L, -2)) },
|
||||
{ KeyUniversalScript, std::string(luaL_checkstring(L, -1)) }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
return luaL_error(L, "Expected %i-%i arguments, got %i", 2, 4, nArguments);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clear(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
}
|
||||
|
||||
OsEng.scriptScheduler().clearSchedule();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace luascriptfunction
|
||||
+33
-15
@@ -34,6 +34,9 @@
|
||||
#include <algorithm>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "SpiceUsr.h"
|
||||
#include "SpiceZpr.h"
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "SpiceManager";
|
||||
|
||||
@@ -45,14 +48,16 @@ namespace {
|
||||
// This method checks if one of the previous SPICE methods has failed. If it has, an
|
||||
// exception with the SPICE error message is thrown
|
||||
void throwOnSpiceError(std::string errorMessage) {
|
||||
SpiceBoolean failed = failed_c();
|
||||
if (failed) {
|
||||
char buffer[SpiceErrorBufferSize];
|
||||
getmsg_c("LONG", SpiceErrorBufferSize, buffer);
|
||||
reset_c();
|
||||
throw openspace::SpiceManager::SpiceException(
|
||||
errorMessage + ": " + buffer
|
||||
);
|
||||
if (openspace::SpiceManager::ref().exceptionHandling()) {
|
||||
SpiceBoolean failed = failed_c();
|
||||
if (failed) {
|
||||
char buffer[SpiceErrorBufferSize];
|
||||
getmsg_c("LONG", SpiceErrorBufferSize, buffer);
|
||||
reset_c();
|
||||
throw openspace::SpiceManager::SpiceException(
|
||||
errorMessage + ": " + buffer
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,9 +90,12 @@ namespace openspace {
|
||||
|
||||
SpiceManager::SpiceException::SpiceException(const string& msg)
|
||||
: ghoul::RuntimeError(msg, "Spice")
|
||||
{}
|
||||
|
||||
|
||||
{
|
||||
ghoul_assert(
|
||||
SpiceManager::ref().exceptionHandling() == SpiceManager::UseException::Yes,
|
||||
"No exceptions should be thrown when UseException is No"
|
||||
);
|
||||
}
|
||||
|
||||
SpiceManager::AberrationCorrection::AberrationCorrection(Type t, Direction d)
|
||||
: type(t)
|
||||
@@ -155,7 +163,9 @@ SpiceManager::TerminatorType SpiceManager::terminatorTypeFromString( const strin
|
||||
return Mapping.at(type);
|
||||
}
|
||||
|
||||
SpiceManager::SpiceManager() {
|
||||
SpiceManager::SpiceManager()
|
||||
: _useExceptions(UseException::No)
|
||||
{
|
||||
// Set the SPICE library to not exit the program if an error occurs
|
||||
erract_c("SET", 0, const_cast<char*>("REPORT"));
|
||||
// But we do not want SPICE to print the errors, we will fetch them ourselves
|
||||
@@ -473,7 +483,7 @@ glm::dvec3 SpiceManager::targetPosition(const std::string& target,
|
||||
|
||||
bool targetHasCoverage = hasSpkCoverage(target, ephemerisTime);
|
||||
bool observerHasCoverage = hasSpkCoverage(observer, ephemerisTime);
|
||||
if (!targetHasCoverage && !observerHasCoverage){
|
||||
if (!targetHasCoverage && !observerHasCoverage && _useExceptions) {
|
||||
throw SpiceException(
|
||||
format("Neither target '{}' nor observer '{}' has SPK coverage at time {}",
|
||||
target,
|
||||
@@ -945,7 +955,7 @@ glm::dvec3 SpiceManager::getEstimatedPosition(const std::string& target,
|
||||
return glm::dvec3(0.0);
|
||||
}
|
||||
|
||||
if (_spkCoverageTimes.find(targetId) == _spkCoverageTimes.end()) {
|
||||
if (_spkCoverageTimes.find(targetId) == _spkCoverageTimes.end() && _useExceptions) {
|
||||
// no coverage
|
||||
throw SpiceException(format("No position for '{}' at any time", target));
|
||||
}
|
||||
@@ -1034,7 +1044,7 @@ glm::dmat3 SpiceManager::getEstimatedTransformMatrix(const std::string& fromFram
|
||||
glm::dmat3 result;
|
||||
int idFrame = frameId(fromFrame);
|
||||
|
||||
if (_ckCoverageTimes.find(idFrame) == _ckCoverageTimes.end()) {
|
||||
if (_ckCoverageTimes.find(idFrame) == _ckCoverageTimes.end() && _useExceptions) {
|
||||
// no coverage
|
||||
throw SpiceException(format(
|
||||
"No data available for the transform matrix from '{}' to '{}' at any time",
|
||||
@@ -1107,6 +1117,14 @@ glm::dmat3 SpiceManager::getEstimatedTransformMatrix(const std::string& fromFram
|
||||
return result;
|
||||
}
|
||||
|
||||
void SpiceManager::setExceptionHandling(UseException useException) {
|
||||
_useExceptions = useException;
|
||||
}
|
||||
|
||||
SpiceManager::UseException SpiceManager::exceptionHandling() const {
|
||||
return _useExceptions;
|
||||
}
|
||||
|
||||
scripting::LuaLibrary SpiceManager::luaLibrary() {
|
||||
return {
|
||||
"spice",
|
||||
|
||||
+6
-3
@@ -34,12 +34,15 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
Time* Time::_instance = nullptr;
|
||||
|
||||
|
||||
double Time::convertTime(const std::string& time) {
|
||||
ghoul_assert(!time.empty(), "timeString must not be empty");
|
||||
return SpiceManager::ref().ephemerisTimeFromDate(time);
|
||||
}
|
||||
|
||||
Time::Time(double secondsJ2000)
|
||||
: _time(secondsJ2000)
|
||||
|
||||
Reference in New Issue
Block a user