demotool/sync.hh

78 lines
1.6 KiB
C++
Raw Normal View History

2017-10-07 16:56:20 +02:00
#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
enum class E_SyncSegment
{
LINEAR ,
RAMP ,
SMOOTH ,
//HERMITE
};
struct T_SyncSegment
{
uint32_t nPoints;
E_SyncSegment type;
std::vector< float > values; // nPoints items
std::vector< uint32_t > durations; // nPoints - 1 items
};
using T_SyncVariable = std::vector< T_SyncSegment >;
struct T_SyncData
{
2017-10-07 17:39:38 +02:00
T_SyncData( );
2017-10-07 16:56:20 +02:00
T_SyncData(
__rd__ const uint32_t duration ,
__rd__ const float units ) noexcept;
2017-10-07 17:39:38 +02:00
float duration( ) const noexcept
{ return duration_ * units_; }
2017-10-07 16:56:20 +02:00
void setSyncVariable(
__rd__ std::string const& name ,
__rw__ T_SyncVariable&& variable ) noexcept;
T_SyncVariable const& variable(
__rd__ std::string const& name ) const noexcept;
uint32_t offsetOf(
__rd__ std::string const& name ) const noexcept;
2017-10-07 16:56:20 +02:00
float valueOf(
__rd__ std::string const& variable ,
__rd__ const float time ) const noexcept;
void computeValues(
__rd__ const float time ,
__wr__ std::vector< float >& values ) const noexcept;
2017-10-07 16:56:20 +02:00
private:
static const T_SyncVariable MissingVariable_;
// Caching structure used to access segments
using T_SegRef_ = std::pair< uint32_t , uint32_t >;
struct T_VarHelper_
{
T_SyncVariable variable;
std::vector< T_SegRef_ > segRefs;
std::vector< float > segStarts;
uint32_t position;
2017-10-07 16:56:20 +02:00
T_VarHelper_(
__rw__ T_SyncVariable&& variable ,
__rd__ const uint32_t duration ,
__rd__ const uint32_t position ) noexcept;
float valueAt(
__rd__ const float position ,
__rd__ const float units ) const noexcept;
2017-10-07 16:56:20 +02:00
};
uint32_t duration_;
float units_;
std::unordered_map< std::string , T_VarHelper_ > variables_;
};