Skip to content

Commit 598a58b

Browse files
committed
doc: Add documentation for curve compression.
1 parent 3c17e2b commit 598a58b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/code/curves.md

Lines changed: 28 additions & 0 deletions
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+
4. [Compression](#compression)
2021

2122

2223
## Motivation
@@ -132,6 +133,9 @@ Modify operations insert values for a specific point in time.
132133
| `set_insert(t, value)` | Insert a new keyframe value at time `t` |
133134
| `set_last(t, value)` | Insert a new keyframe value at time `t`; delete all keyframes after time `t` |
134135
| `set_replace(t, value)` | Insert a new keyframe value at time `t`; remove all other keyframes with time `t` |
136+
| `compress(t)` | Remove redundant keyframes at and after time `t`; see [Compression] for more info |
137+
138+
[Compression]: #compression
135139

136140
**Copy**
137141

@@ -253,3 +257,27 @@ Unordered map curve containers store key-value pairs while additionally keeping
253257
track of element insertion time. Requests for a key `k` at time `t` will return the value
254258
of `k` at that time. The unordered map can also be iterated over for a specific time `t` which
255259
allows access to all key-value pairs that were in the map at time `t`.
260+
261+
## Compression
262+
263+
Curves support basic lossless compression by removing redundant keyframes from the curve.
264+
Keyframes are considered redundant if they do not change any interpolation results, i.e.
265+
the result of `get(t)` does not change.
266+
267+
The most straight-forward way to use compression with primitive curves is the `compress(t)`
268+
method. `compress(t)` iterates over the curve and removes all redundant keyframes after
269+
or at time `t`. The runtime has linear complexity `O(n)` based on the number of elements
270+
in the keyframe container.
271+
272+
Furthermore, primitive curves support incremental compression during insertion for the
273+
`set_insert(t, value)` and `set_last(t, value)` methods via their `compress` argument.
274+
If compression is active, `(t, value)` is only inserted when it is not a redundant
275+
keyframe. `sync(Curve, t)` also supports compression with a flag `compress` passed as
276+
an argument.
277+
278+
Compression may be used in cases where the size should be kept small, e.g. when the curve
279+
is tranferred via network or recorded in a replay file. Another application of compression
280+
is in the [renderer](/doc/code/renderer/README.md) for the discrete curves storing an object's
281+
animations. Since compression removes redundant animation entries, the renderer can determine
282+
when the current animation has started much easier as this is then returned by the keyframe
283+
time in `frame(t)`.

0 commit comments

Comments
 (0)