Commit ace82352 authored by Lázár Bence Kis's avatar Lázár Bence Kis
Browse files

convertToValuePtr not defined multiple times anymore

parent 75ee2d3b
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ public:

private:
    double get_relative_time(double low, double high, double t) const;
    ValuePtr convertToValuePtr(const ValueType& value);
};

} // namespace anim 
 No newline at end of file
+0 −19
Original line number Diff line number Diff line
@@ -5,25 +5,6 @@

namespace anim {

namespace {
    com::Reflection::ValuePtr convertToValuePtr(const ValueType& value) {
        COM_REFLECTION_USINGS();
        return std::visit([](auto&& val) -> com::Reflection::ValuePtr {
            using T = std::decay_t<decltype(val)>;
            if constexpr (std::is_same_v<T, bool>) {
                return ValuePtr(new ValueBOOL(val));
            } else if constexpr (std::is_same_v<T, scalar>) {
                return ValuePtr(new ValueFLOAT(val));
            } else if constexpr (std::is_same_v<T, vec3>) {
                return ValuePtr(new ValueVEC3(val));
            } else if constexpr (std::is_same_v<T, quat>) {
                return ValuePtr(new ValueQUAT(val));
            }
            throw std::runtime_error("Unsupported value type");
        }, value);
    }
}

struct IAnimationPlayer : public com::Folder {
    using com::Folder::Folder;
    virtual void update(scalar t) = 0;
+3 −0
Original line number Diff line number Diff line
@@ -2,12 +2,15 @@

#include <variant>
#include <math/math.hpp>
#include <com/reflection.hpp>

namespace anim {

// Type-safe variant to store different value types
using ValueType = std::variant<bool, scalar, vec3, quat>;

com::Reflection::ValuePtr convertToValuePtr(const ValueType& value);

enum class InterpolationType : uint8_t {
    CONSTANT,
    LINEAR,
+0 −17
Original line number Diff line number Diff line
@@ -71,23 +71,6 @@ double AnimationTrack::get_relative_time(double low, double high, double t) cons
    return (t - low) / (high - low);
}

com::Reflection::ValuePtr AnimationTrack::convertToValuePtr(const ValueType& value) {
    COM_REFLECTION_USINGS();
    return std::visit([](auto&& val) -> com::Reflection::ValuePtr {
        using T = std::decay_t<decltype(val)>;
        if constexpr (std::is_same_v<T, bool>) {
            return ValuePtr(new ValueBOOL(val));
        } else if constexpr (std::is_same_v<T, scalar>) {
            return ValuePtr(new ValueFLOAT(val));
        } else if constexpr (std::is_same_v<T, vec3>) {
            return ValuePtr(new ValueVEC3(val));
        } else if constexpr (std::is_same_v<T, quat>) {
            return ValuePtr(new ValueQUAT(val));
        }
        throw std::runtime_error("Unsupported value type");
    }, value);
}

anim::ValueType AnimationTrack::update(double t) {
    ASSUMPTION(!m_keyframes.empty());

anim/src/types.cpp

0 → 100644
+22 −0
Original line number Diff line number Diff line
#include <anim/types.hpp>

namespace anim {

com::Reflection::ValuePtr convertToValuePtr(const ValueType& value) {
    COM_REFLECTION_USINGS();
    return std::visit([](auto&& val) -> com::Reflection::ValuePtr {
        using T = std::decay_t<decltype(val)>;
        if constexpr (std::is_same_v<T, bool>) {
            return ValuePtr(new ValueBOOL(val));
        } else if constexpr (std::is_same_v<T, scalar>) {
            return ValuePtr(new ValueFLOAT(val));
        } else if constexpr (std::is_same_v<T, vec3>) {
            return ValuePtr(new ValueVEC3(val));
        } else if constexpr (std::is_same_v<T, quat>) {
            return ValuePtr(new ValueQUAT(val));
        }
        throw std::runtime_error("Unsupported value type");
    }, value);
}

} // namespace anim