Skip to content

Commit 6d9d8d7

Browse files
authored
Merge pull request #1724 from jere8184/array_curve
Array curve
2 parents 3850400 + d571822 commit 6d9d8d7

27 files changed

Lines changed: 615 additions & 55 deletions

doc/code/curves.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Curves are an integral part of openage's event-based game simulation.
1717
2. [Container](#container)
1818
1. [Queue](#queue)
1919
2. [Unordered Map](#unordered-map)
20+
3. [Array](#array)
2021

2122

2223
## Motivation
@@ -198,7 +199,7 @@ e.g. angles between 0 and 360 degrees.
198199
### Container
199200

200201
Container curves are intended for storing changes to collections and containers.
201-
The currently supported containers are `Queue` and `UnorderedMap`.
202+
The currently supported containers are `Queue`, `UnorderedMap` and `Array`.
202203

203204
The most important distinction between regular C++ containers and curve containers
204205
is that curve containers track the *lifespan* of each element, i.e. their insertion time,
@@ -253,3 +254,41 @@ Unordered map curve containers store key-value pairs while additionally keeping
253254
track of element insertion time. Requests for a key `k` at time `t` will return the value
254255
of `k` at that time. The unordered map can also be iterated over for a specific time `t` which
255256
allows access to all key-value pairs that were in the map at time `t`.
257+
258+
259+
#### Array
260+
261+
Array curve containers store a fixed number of `n` elements where `n` is determined at compile-time.
262+
They are the curve equivalent to the `std::array` C++ containers. In comparison to `std::array` each
263+
element in the array curve container is tracked individually over time. Hence, each index is associated
264+
with its own `KeyframeContainer` whose keyframes can be updated independent from other indices.
265+
When a value is added to the `Array` curve at a given index, a new keyframe is added to the respective
266+
`KeyframeContainer` stored at that index.
267+
268+
**Read**
269+
270+
Read operations retrieve values for a specific point in time.
271+
272+
| Method | Description |
273+
| ------------------ | ------------------------------------------------------------------------ |
274+
| `get(t, i)` | Get value of element at index `i` at time <= `t` |
275+
| `get(t)` | Get array of values at time <= `t` |
276+
| `size()` | Get the number of elements in the array |
277+
| `frame(t, i)` | Get the previous keyframe (time and value) at index `i` before or at `t` |
278+
| `next_frame(t, i)` | Get the next keyframe (time and value) at index `i` after `t` |
279+
280+
**Modify**
281+
282+
Modify operations insert values for a specific point in time.
283+
284+
| Method | Description |
285+
| -------------------------- | ------------------------------------------------------------------------------------------ |
286+
| `set_insert(t, i, value)` | Insert a new keyframe(`t`, `value`) at index `i` |
287+
| `set_last(t, i, value)` | Insert a new keyframe(`t`, `value`) at index `i`; delete all keyframes after time `t` |
288+
| `set_replace(t, i, value)` | Insert a new keyframe(`t`, `value`) at index `i`; remove all other keyframes with time `t` |
289+
290+
**Copy**
291+
292+
| Method | Description |
293+
| ---------------- | ------------------------------------------------------------------------------------------------ |
294+
| `sync(Curve, t)` | Replace all keyframes from self after time `t` with keyframes from source `Curve` after time `t` |

libopenage/curve/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@ add_sources(libopenage
33
continuous.cpp
44
discrete.cpp
55
discrete_mod.cpp
6-
element_wrapper.cpp
76
interpolated.cpp
8-
iterator.cpp
97
keyframe.cpp
108
keyframe_container.cpp
11-
map.cpp
12-
map_filter_iterator.cpp
13-
queue.cpp
14-
queue_filter_iterator.cpp
159
segmented.cpp
1610
)
1711

12+
add_subdirectory("container")
1813
add_subdirectory("tests")

libopenage/curve/base_curve.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017-2024 the openage authors. See copying.md for legal info.
1+
// Copyright 2017-2025 the openage authors. See copying.md for legal info.
22

33
#pragma once
44

@@ -47,6 +47,7 @@ class BaseCurve : public event::EventEntity {
4747
// registration. If you need to copy a curve, use the sync() method.
4848
// TODO: if copying is enabled again, these members have to be reassigned: _id, _idstr, last_element
4949
BaseCurve(const BaseCurve &) = delete;
50+
BaseCurve &operator=(const BaseCurve &) = delete;
5051

5152
BaseCurve(BaseCurve &&) = default;
5253

@@ -245,7 +246,7 @@ template <typename T>
245246
std::pair<time::time_t, const T> BaseCurve<T>::frame(const time::time_t &time) const {
246247
auto e = this->container.last(time, this->container.size());
247248
auto elem = this->container.get(e);
248-
return std::make_pair(elem.time(), elem.val());
249+
return elem.as_pair();
249250
}
250251

251252

@@ -254,7 +255,7 @@ std::pair<time::time_t, const T> BaseCurve<T>::next_frame(const time::time_t &ti
254255
auto e = this->container.last(time, this->container.size());
255256
e++;
256257
auto elem = this->container.get(e);
257-
return std::make_pair(elem.time(), elem.val());
258+
return elem.as_pair();
258259
}
259260

260261
template <typename T>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
add_sources(libopenage
2+
array.cpp
3+
element_wrapper.cpp
4+
iterator.cpp
5+
map.cpp
6+
map_filter_iterator.cpp
7+
queue.cpp
8+
queue_filter_iterator.cpp
9+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2024-2025 the openage authors. See copying.md for legal info.
2+
3+
4+
#include "array.h"
5+
6+
namespace openage::curve {
7+
8+
// This file is intended to be empty
9+
10+
} // openage::curve

0 commit comments

Comments
 (0)