diff --git a/libopenage/curve/CMakeLists.txt b/libopenage/curve/CMakeLists.txt index 63a7a12c00..0b800ced83 100644 --- a/libopenage/curve/CMakeLists.txt +++ b/libopenage/curve/CMakeLists.txt @@ -1,4 +1,5 @@ add_sources(libopenage + array.cpp base_curve.cpp continuous.cpp discrete.cpp @@ -12,7 +13,6 @@ add_sources(libopenage queue.cpp queue_filter_iterator.cpp segmented.cpp - array.cpp ) add_subdirectory("tests") diff --git a/libopenage/curve/array.cpp b/libopenage/curve/array.cpp index 23c60bf154..51f53eb9cf 100644 --- a/libopenage/curve/array.cpp +++ b/libopenage/curve/array.cpp @@ -1,4 +1,4 @@ -// Copyright 2017-2024 the openage authors. See copying.md for legal info. +// Copyright 2024-2024 the openage authors. See copying.md for legal info. #include "array.h" diff --git a/libopenage/curve/array.h b/libopenage/curve/array.h index 417317a9d2..1f5b1364d0 100644 --- a/libopenage/curve/array.h +++ b/libopenage/curve/array.h @@ -1,4 +1,4 @@ -// Copyright 2017-2024 the openage authors. See copying.md for legal info. +// Copyright 2024-2024 the openage authors. See copying.md for legal info. #pragma once @@ -15,9 +15,6 @@ namespace curve { template class Array { public: - using container_t = std::array, Size>; - - Array() = default; // prevent accidental copy of queue @@ -30,12 +27,12 @@ class Array { std::array get_all(const time::time_t &t) const; - size_t size() const; + consteval size_t size() const; - const Keyframe &frame(const time::time_t &t, const size_t index) const; + std::pair frame(const time::time_t &t, const size_t index) const; - const Keyframe &next_frame(const time::time_t &t, const size_t index) const; + std::pair next_frame(const time::time_t &t, const size_t index) const; void set_insert(const time::time_t &t, const size_t index, T value); @@ -52,7 +49,7 @@ class Array { curve(curve), time(time), offset(offset) {}; const T &operator*() { - return curve->frame(this->time, this->offset).value; + return curve->frame(this->time, this->offset).second; } void operator++() { @@ -77,26 +74,28 @@ class Array { private: - container_t container; + std::array, Size> container; + + //hint for KeyframeContainer operations mutable size_t last_hit_index = 0; }; template -const Keyframe &Array::frame(const time::time_t &t, const size_t index) const { +std::pair Array::frame(const time::time_t &t, const size_t index) const { this->last_hit_index = container[index].last(t, this->last_hit_index); - return container[index].get(this->last_hit_index); + return container[index].get(this->last_hit_index).make_pair(); } template -const Keyframe &Array::next_frame(const time::time_t &t, const size_t index) const { +std::pair Array::next_frame(const time::time_t &t, const size_t index) const { this->last_hit_index = container[index].last(t, this->last_hit_index); return container[index].get(this->last_hit_index + 1); } template T Array::get(const time::time_t &t, const size_t index) const { - return this->frame(t, index).value; + return this->frame(t, index).second; } template @@ -107,7 +106,7 @@ std::array Array::get_all(const time::time_t &t) const { } template -size_t Array::size() const { +consteval size_t Array::size() const { return Size; } @@ -133,7 +132,7 @@ void Array::set_replace(const time::time_t &t, const size_t index, T va template void Array::sync(const Array &other, const time::time_t &start) { for (int i = 0; i < Size; i++) { - this->container[i].sync(other, start); + this->container[i].sync(other[i], start); } } diff --git a/libopenage/curve/keyframe.h b/libopenage/curve/keyframe.h index e868783cbb..a34b0c6262 100644 --- a/libopenage/curve/keyframe.h +++ b/libopenage/curve/keyframe.h @@ -54,6 +54,15 @@ class Keyframe { return this->value; } + /** + * Get the value and timestamp of the keyframe in form of std::pair + * @return keyframe pair + */ + std::pair make_pair() const + { + return {time(), val()}; + } + public: /** * Value of the keyframe. diff --git a/libopenage/curve/keyframe_container.h b/libopenage/curve/keyframe_container.h index d9bb9a0bbd..8434942058 100644 --- a/libopenage/curve/keyframe_container.h +++ b/libopenage/curve/keyframe_container.h @@ -279,8 +279,6 @@ class KeyframeContainer { * Replaces all keyframes beginning at t >= start with keyframes from \p other. * * @param other Curve that keyframes are copied from. - * @param converter Function that converts the value type of \p other to the - * value type of \p this. * @param start Start time at which keyframes are replaced (default = -INF). * Using the default value replaces ALL keyframes of \p this with * the keyframes of \p other.