Skip to content

Commit

Permalink
doc: Add documentation for curve compression.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Oct 31, 2024
1 parent a5832dd commit d5f0466
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions doc/code/curves.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Curves are an integral part of openage's event-based game simulation.
2. [Container](#container)
1. [Queue](#queue)
2. [Unordered Map](#unordered-map)
4. [Compression](#compression)


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

[Compression]: #compression

**Copy**

Expand Down Expand Up @@ -253,3 +257,27 @@ Unordered map curve containers store key-value pairs while additionally keeping
track of element insertion time. Requests for a key `k` at time `t` will return the value
of `k` at that time. The unordered map can also be iterated over for a specific time `t` which
allows access to all key-value pairs that were in the map at time `t`.

## Compression

Curves support basic lossless compression by removing redundant keyframes from the curve.
Keyframes are considered redundant if they do not change any interpolation results, i.e.
the result of `get(t)` does not change.

The most straight-forward way to use compression with primitive curves is the `compress(t)`
method. `compress(t)` iterates over the curve and removes all redundant keyframes after
or at time `t`. The runtime has linear complexity `O(n)` based on the number of elements
in the keyframe container.

Furthermore, primitive curves support incremental compression during insertion for the
`set_insert(t, value)` and `set_last(t, value)` methods via their `compress` argument.
If compression is active, `(t, value)` is only inserted when it is not a redundant
keyframe. `sync(Curve, t)` also supports compression with a flag `compress` passed as
an argument.

Compression may be used in cases where the size should be kept small, e.g. when the curve
is tranferred via network or recorded in a replay file. Another application of compression
is in the [renderer](/doc/code/renderer/README.md) for the discrete curves storing an object's
animations. Since compression removes redundant animation entries, the renderer can determine
when the current animation has started much easier as this is then returned by the keyframe
time in `frame(t)`.

0 comments on commit d5f0466

Please sign in to comment.