Feature/codegen (#1480)

* Add the ability to automatically generate code to extract values out of a Dictionary (see https://github.com/openspace/codegen for more information on how to use this)
* Applied this technique to a large number of cases in the codebase
* Don't add _codegen files to the repository

Co-authored-by: Emma Broman <emma.broman@liu.se>
This commit is contained in:
Alexander Bock
2021-02-09 09:12:43 +01:00
committed by GitHub
parent 78c0b23194
commit 6d821d4f91
104 changed files with 2939 additions and 4769 deletions
+26 -39
View File
@@ -40,6 +40,7 @@
#include <ghoul/opengl/textureunit.h>
#include <ghoul/glm.h>
#include <glm/gtx/string_cast.hpp>
#include <optional>
namespace {
constexpr const char* ProgramName = "Plane";
@@ -68,36 +69,30 @@ namespace {
"Blending Mode",
"This determines the blending mode that is applied to this plane."
};
struct [[codegen::Dictionary(RenderablePlane)]] Parameters {
// [[codegen::verbatim(BillboardInfo.description)]]
std::optional<bool> billboard;
// [[codegen::verbatim(SizeInfo.description)]]
float size;
enum class BlendMode {
Normal,
Additive
};
// [[codegen::verbatim(BlendModeInfo.description)]]
std::optional<BlendMode> blendMode;
};
#include "renderableplane_codegen.cpp"
} // namespace
namespace openspace {
documentation::Documentation RenderablePlane::Documentation() {
using namespace documentation;
return {
"Renderable Plane",
"base_renderable_plane",
{
{
SizeInfo.identifier,
new DoubleVerifier,
Optional::No,
SizeInfo.description
},
{
BillboardInfo.identifier,
new BoolVerifier,
Optional::Yes,
BillboardInfo.description
},
{
BlendModeInfo.identifier,
new StringInListVerifier({ "Normal", "Additive" }),
Optional::Yes,
BlendModeInfo.description, // + " The default value is 'Normal'.",
}
}
};
documentation::Documentation doc = codegen::doc<Parameters>();
doc.id = "base_renderable_plane";
return doc;
}
RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
@@ -106,20 +101,13 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
, _billboard(BillboardInfo, false)
, _size(SizeInfo, 10.f, 0.f, 1e25f)
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"RenderablePlane"
);
Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_size = static_cast<float>(dictionary.value<double>(SizeInfo.identifier));
if (dictionary.hasKey(BillboardInfo.identifier)) {
_billboard = dictionary.value<bool>(BillboardInfo.identifier);
}
_size = p.size;
_billboard = p.billboard.value_or(_billboard);
_blendMode.addOptions({
{ BlendModeNormal, "Normal" },
@@ -144,12 +132,11 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
}
});
if (dictionary.hasKey(BlendModeInfo.identifier)) {
const std::string v = dictionary.value<std::string>(BlendModeInfo.identifier);
if (v == "Normal") {
if (p.blendMode.has_value()) {
if (*p.blendMode == Parameters::BlendMode::Normal) {
_blendMode = BlendModeNormal;
}
else if (v == "Additive") {
else if (*p.blendMode == Parameters::BlendMode::Additive) {
_blendMode = BlendModeAdditive;
}
}