Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Linux CI

on: [push, pull_request]

jobs:
Linux:
name: ubuntu-latest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: python -m pip install meson==1.4.0 ninja

- name: Configure project
run: |
meson setup build

- name: Build and test
run: |
meson test -C build/ -v

- name: Upload Test Log
uses: actions/upload-artifact@v4
if: failure()
with:
name: Meson_Testlog
path: builddir/meson-logs/testlog.txt
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Vim
.*.swp

# XCode gitignore
build/
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ v0.4.0

Choreograph is designed to describe motion. With it, you compose motion Phrases into Sequences that can be used to animate arbitrary properties on a Timeline.

This is a maintained fork, after [the original project](https://github.com/sansumbrella/Choreograph) stopped being maintained.

## Basic Usage

Simple things are simple. You can animate a variable through a sequence of values in Choreograph by creating a sequence of ramps.
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project('Choreograph', 'cpp')

subdir('src/choreograph')
subdir('tests')
6 changes: 3 additions & 3 deletions src/choreograph/Easing.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ inline float easeInAtan( float t, float a = 15 )

//! Easing equation for an atan ease-in, accelerating from zero velocity. Functor edition. Used by permssion from Chris McKenzie.
struct EaseInAtan {
EaseInAtan( float a = 15 ) : mInvM( 1.0f / std::atan( a ) ), mA( a ) {}
EaseInAtan( float a = 15 ) : mA( a ), mInvM( 1.0f / std::atan( a ) ) {}
float operator()( float t ) const { return ( std::atan( (t - 1) * mA ) * mInvM ) + 1; }
float mA, mInvM;
};
Expand All @@ -679,7 +679,7 @@ inline float easeOutAtan( float t, float a = 15 )

//! Easing equation for an atan ease-out, decelerating from zero velocity. Functor edition. Used by permssion from Chris McKenzie.
struct EaseOutAtan {
EaseOutAtan( float a = 15 ) : mInvM( 1.0f / std::atan( a ) ), mA( a ) {}
EaseOutAtan( float a = 15 ) : mA( a ), mInvM( 1.0f / std::atan( a ) ) {}
float operator()( float t ) const { return std::atan( t * mA ) * mInvM; }
float mA, mInvM;
};
Expand All @@ -693,7 +693,7 @@ inline float easeInOutAtan( float t, float a = 15 )

//! Easing equation for an atan ease-in/out, accelerating until halfway, then decelerating. Functor edition. Used by permssion from Chris McKenzie.
struct EaseInOutAtan {
EaseInOutAtan( float a = 15 ) : mInv2M( 1.0f / ( 2 * std::atan( 0.5f * a ) ) ), mA( a ) {}
EaseInOutAtan( float a = 15 ) : mA( a ), mInv2M( 1.0f / ( 2 * std::atan( 0.5f * a ) ) ) {}
float operator()( float t ) const { return ( std::atan((t - 0.5f)*mA) * mInv2M ) + 0.5f; }
float mA, mInv2M;
};
Expand Down
13 changes: 9 additions & 4 deletions src/choreograph/Motion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class Motion : public TimelineItem

Motion() = delete;

Motion( T *target ):
_source( *target ),
_target( target )
{}

Motion( T *target, const SequenceT &sequence ):
_target( target ),
_source( sequence )
Expand Down Expand Up @@ -131,7 +136,7 @@ class Motion : public TimelineItem
Callback _finish_fn;
Callback _start_fn;
Callback _update_fn;
std::vector<std::pair<int, Callback>> _inflection_callbacks;
std::vector<std::pair<size_t, Callback>> _inflection_callbacks;

/// Sets the output to a different output.
/// Used by Output<T>'s move assignment and move constructor.
Expand Down Expand Up @@ -173,7 +178,7 @@ void Motion<T>::update()
auto bottom = std::min( points.first, points.second );
for( const auto &fn : _inflection_callbacks )
{
auto inflection = fn.first;
unsigned int inflection = fn.first;
if( inflection > bottom && inflection <= top ) {
fn.second();
}
Expand All @@ -200,7 +205,7 @@ void Motion<T>::update()
template<typename T>
void Motion<T>::addInflectionCallback( size_t inflection_point, const Callback &callback )
{
_inflection_callbacks.emplace_back( std::make_pair( (int)inflection_point, callback ) );
_inflection_callbacks.emplace_back( std::make_pair( inflection_point, callback ) );
}

template<typename T>
Expand All @@ -212,7 +217,7 @@ void Motion<T>::sliceSequence( Time from, Time to )
fn.first -= inflection;
}

detail::erase_if( &_inflection_callbacks, [] (const std::pair<int, Callback> &p) {
detail::erase_if( &_inflection_callbacks, [] (const std::pair<size_t, Callback> &p) {
return p.first < 0;
} );

Expand Down
16 changes: 16 additions & 0 deletions src/choreograph/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
src = [
'Cue.cpp',
'Timeline.cpp',
'TimelineItem.cpp',
]

choreograph = library('choreograph',
sources: src,
include_directories: '..',
install: true,
)

choreograph_dep = declare_dependency(
link_with: choreograph,
include_directories: '..',
)
74 changes: 63 additions & 11 deletions tests/Benchmarks_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,51 @@

#include "choreograph/Choreograph.h"

#if TEST_WITH_CINDER
#include "cinder/Vector.h"
#include "cinder/Timeline.h"
#include "cinder/Timer.h"
using cinder::Timeline;
#endif


#include <chrono>

using namespace std;
using cinder::Timeline;
using cinder::vec2;
using cinder::Timer;
using namespace choreograph;

class Timer: public Catch::Timer
{
public:
Timer(bool start_on_creation = false):
Catch::Timer()
{
if (start_on_creation)
start();
}

void stop() {}
double getSeconds() const { return getElapsedSeconds(); }
};

struct vec2
{
vec2(double x = 0.0f, double y = 0.0f): x(x), y(y) {}

vec2 operator+(const vec2 &o) const {
return { x + o.x, y + o.y };
}
vec2 operator-(const vec2 &o) const {
return { x - o.x, y - o.y };
}
vec2 operator*(double s) const {
return { x * s, y *s };
}

private:
double x, y;
};

void printTiming( const std::string &text, double milliseconds, const std::string &suffix = "ms" )
{
string message = "[" + text + "] ";
Expand All @@ -41,7 +74,7 @@ TEST_CASE( "Sequence Manipulation Timing" )
{
printHeading( "Sequence Creation and Slicing" );

Timer create_medium( true );
Timer create_medium;
Sequence<float> medium_sequence( 0.0f );
medium_sequence.then<RampTo>( 10.0f, 1.0f, EaseInOutQuad() )
.then<RampTo>( 1.0f, 1.0f, EaseInOutQuad() )
Expand Down Expand Up @@ -161,21 +194,24 @@ TEST_CASE( "Choreograph Timeline Basic Performance" )
TEST_CASE( "Comparative Performance with cinder::Timeline" )
{
ch::Timeline choreograph_timeline;
ci::TimelineRef cinder_timeline = ci::Timeline::create();

const int tween_count = 5000;
vector<Output<vec2>> targets;
while ( targets.size() < tween_count ) {
targets.emplace_back( vec2( 0 ) );
}
vector<ci::Anim<vec2>> cinder_targets( tween_count, vec2( 0 ) );

double ci_step_avg = 0;
double ch_step_avg = 0;
double ci_create_avg = 0;
double ch_create_avg = 0;
double iterations = 4;

#if TEST_WITH_CINDER
ci::TimelineRef cinder_timeline = ci::Timeline::create();
vector<ci::Anim<vec2>> cinder_targets( tween_count, vec2( 0 ) );
double ci_step_avg = 0;
double ci_create_avg = 0;
#endif

SECTION( "Tween many targets" )
{
printHeading( "Comparative Performance: many targets, short animations." );
Expand All @@ -193,13 +229,15 @@ TEST_CASE( "Comparative Performance with cinder::Timeline" )
}
ch_create.stop();

#if TEST_WITH_CINDER
// Create Cinder Tweens
Timer ci_create( true );
for( int i = 0; i < tween_count; ++i ) {
cinder_timeline->apply( &cinder_targets[i], vec2( i * 5, i * 20 ), 2.0f )
.delay( 1.0f );
}
ci_create.stop();
#endif

Timer ch_step( true );
// Step through Choreograph Motions
Expand All @@ -208,6 +246,7 @@ TEST_CASE( "Comparative Performance with cinder::Timeline" )
}
ch_step.stop();

#if TEST_WITH_CINDER
Timer ci_step( true );
// Step through Cinder Tweens
for( float t = 0.0f; t <= total_time; t += dt ) {
Expand All @@ -217,22 +256,27 @@ TEST_CASE( "Comparative Performance with cinder::Timeline" )

ci_create_avg += ci_create.getSeconds() * 1000;
ci_step_avg += ci_step.getSeconds() * 1000;
#endif

ch_create_avg += ch_create.getSeconds() * 1000;
ch_step_avg += ch_step.getSeconds() * 1000;
}

#if TEST_WITH_CINDER
ci_create_avg /= iterations;
ci_step_avg /= iterations;
#endif
ch_create_avg /= iterations;
ch_step_avg /= iterations;

printTiming( "Choreograph Create Average", ch_create_avg );
printTiming( "Cinder Create Average", ci_create_avg );
printTiming( "Choreograph Step Average", ch_step_avg );
#if TEST_WITH_CINDER
printTiming( "Cinder Create Average", ci_create_avg );
printTiming( "Cinder Step Average", ci_step_avg );
printTiming( "Create Performance (Choreograph / Cinder)", (ch_create_avg / ci_create_avg), "" );
printTiming( "Step Performance (Choreograph / Cinder)", (ch_step_avg / ci_step_avg), "" );
#endif
}

SECTION( "Tween one target many times" )
Expand All @@ -244,7 +288,6 @@ TEST_CASE( "Comparative Performance with cinder::Timeline" )
for( int j = 0; j < iterations; j += 1 )
{
Output<vec2> target( vec2( 0 ) );
ci::Anim<vec2> cinder_target( vec2( 0 ) );

// Create Choreograph Motions
Timer ch_create( true );
Expand All @@ -253,12 +296,15 @@ TEST_CASE( "Comparative Performance with cinder::Timeline" )
}
ch_create.stop();

#if TEST_WITH_CINDER
ci::Anim<vec2> cinder_target( vec2( 0 ) );
// Create Cinder Tweens
Timer ci_create( true );
for( int i = 0; i < tween_count; ++i ) {
cinder_timeline->appendTo( &cinder_target, vec2( i * 5, i * 20 ), 2.0f ).delay( 1.0f );
}
ci_create.stop();
#endif

// Step through Choreograph Motions
Timer ch_step( true );
Expand All @@ -267,6 +313,7 @@ TEST_CASE( "Comparative Performance with cinder::Timeline" )
}
ch_step.stop();

#if TEST_WITH_CINDER
// Step through Cinder Tweens
Timer ci_step( true );
for( float t = 0.0f; t <= total_time; t += dt ) {
Expand All @@ -276,21 +323,26 @@ TEST_CASE( "Comparative Performance with cinder::Timeline" )

ci_create_avg += ci_create.getSeconds() * 1000;
ci_step_avg += ci_step.getSeconds() * 1000;
#endif

ch_create_avg += ch_create.getSeconds() * 1000;
ch_step_avg += ch_step.getSeconds() * 1000;
}

#if TEST_WITH_CINDER
ci_create_avg /= iterations;
ci_step_avg /= iterations;
#endif
ch_create_avg /= iterations;
ch_step_avg /= iterations;

printTiming( "Choreograph Create Average", ch_create_avg );
printTiming( "Cinder Create Average", ci_create_avg );
printTiming( "Choreograph Step Average", ch_step_avg );
#if TEST_WITH_CINDER
printTiming( "Cinder Step Average", ci_step_avg );
printTiming( "Cinder Create Average", ci_create_avg );
printTiming( "Create Performance (Choreograph / Cinder)", (ch_create_avg / ci_create_avg), "" );
printTiming( "Step Performance (Choreograph / Cinder)", (ch_step_avg / ci_step_avg), "" );
#endif
}
}
3 changes: 0 additions & 3 deletions tests/Choreograph_test.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions tests/Cue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//
//

#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "choreograph/Choreograph.h"

Expand Down
2 changes: 2 additions & 0 deletions tests/Ease_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//
//

#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "choreograph/Choreograph.h"

Expand Down
2 changes: 2 additions & 0 deletions tests/ForumMiscellany_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//
//

#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "choreograph/Choreograph.h"

Expand Down
2 changes: 2 additions & 0 deletions tests/Grouping_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//
//

#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "choreograph/Choreograph.h"

Expand Down
Loading