demotool/sync.hh

67 lines
1.3 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;
float valueOf(
__rd__ std::string const& variable ,
__rd__ const float time ) const noexcept;
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;
T_VarHelper_(
__rw__ T_SyncVariable&& variable ,
__rd__ const uint32_t duration ) noexcept;
};
uint32_t duration_;
float units_;
std::unordered_map< std::string , T_VarHelper_ > variables_;
};