Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
jere8184 committed Dec 11, 2024
1 parent 6420b76 commit 3ea0f4a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion libopenage/curve/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_sources(libopenage
array.cpp
base_curve.cpp
continuous.cpp
discrete.cpp
Expand All @@ -12,7 +13,6 @@ add_sources(libopenage
queue.cpp
queue_filter_iterator.cpp
segmented.cpp
array.cpp
)

add_subdirectory("tests")
2 changes: 1 addition & 1 deletion libopenage/curve/array.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
29 changes: 14 additions & 15 deletions libopenage/curve/array.h
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -15,9 +15,6 @@ namespace curve {
template <typename T, size_t Size>
class Array {
public:
using container_t = std::array<KeyframeContainer<T>, Size>;


Array() = default;

// prevent accidental copy of queue
Expand All @@ -30,12 +27,12 @@ class Array {
std::array<T, Size> get_all(const time::time_t &t) const;


size_t size() const;
consteval size_t size() const;

const Keyframe<T> &frame(const time::time_t &t, const size_t index) const;
std::pair<time::time_t, T> frame(const time::time_t &t, const size_t index) const;


const Keyframe<T> &next_frame(const time::time_t &t, const size_t index) const;
std::pair<time::time_t, T> 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);

Expand All @@ -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++() {
Expand All @@ -77,26 +74,28 @@ class Array {


private:
container_t container;
std::array<KeyframeContainer<T>, Size> container;

//hint for KeyframeContainer operations
mutable size_t last_hit_index = 0;
};


template <typename T, size_t Size>
const Keyframe<T> &Array<T, Size>::frame(const time::time_t &t, const size_t index) const {
std::pair<time::time_t, T> Array<T, Size>::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 <typename T, size_t Size>
const Keyframe<T> &Array<T, Size>::next_frame(const time::time_t &t, const size_t index) const {
std::pair<time::time_t, T> Array<T, Size>::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 <typename T, size_t Size>
T Array<T, Size>::get(const time::time_t &t, const size_t index) const {
return this->frame(t, index).value;
return this->frame(t, index).second;
}

template <typename T, size_t Size>
Expand All @@ -107,7 +106,7 @@ std::array<T, Size> Array<T, Size>::get_all(const time::time_t &t) const {
}

template <typename T, size_t Size>
size_t Array<T, Size>::size() const {
consteval size_t Array<T, Size>::size() const {
return Size;
}

Expand All @@ -133,7 +132,7 @@ void Array<T, Size>::set_replace(const time::time_t &t, const size_t index, T va
template <typename T, size_t Size>
void Array<T, Size>::sync(const Array<T, Size> &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);
}
}

Expand Down
9 changes: 9 additions & 0 deletions libopenage/curve/keyframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ class Keyframe {
return this->value;
}

/**
* Get the value and timestamp of the keyframe in form of std::pair<time, value>
* @return keyframe pair
*/
std::pair<time::time_t, T> make_pair() const
{
return {time(), val()};
}

public:
/**
* Value of the keyframe.
Expand Down
2 changes: 0 additions & 2 deletions libopenage/curve/keyframe_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3ea0f4a

Please sign in to comment.