demotool/sync.hh

187 lines
4.4 KiB
C++
Raw Normal View History

2017-10-07 16:56:20 +02:00
#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
2017-10-17 11:30:44 +02:00
// Definition of a single input - id & range
struct T_SyncInputDfn
2017-10-07 16:56:20 +02:00
{
2017-10-17 11:30:44 +02:00
std::string identifier;
float min = -std::numeric_limits< float >::infinity( ),
max = std::numeric_limits< float >::infinity( );
T_SyncInputDfn( __rd__ std::string const& identifier ,
__rd__ const float min ,
__rd__ const float max ) noexcept
: identifier( identifier ) , min( min ) , max( max )
{ }
};
using P_SyncInputDfn = std::unique_ptr< T_SyncInputDfn >;
/*============================================================================*/
// Definition of UI overrides for inputs
struct T_SyncUIOverride
{
enum E_Type {
FLOAT , VEC2 , VEC3 , VEC4 , INT ,
COLOR , COLOR_GRADING , CAMERA
};
E_Type type;
std::vector< std::string > inputs;
bool enabled;
};
using P_SyncUIOverride = std::unique_ptr< T_SyncUIOverride >;
using T_SyncUIOverrides = std::vector< P_SyncUIOverride >;
// UI override sections
struct T_SyncUISection;
using P_SyncUISection = std::unique_ptr< T_SyncUISection >;
using T_SyncUISections = std::vector< P_SyncUISection >;
struct T_SyncUISection
{
std::string title;
T_SyncUISections subsections;
T_SyncUIOverrides overrides;
2017-10-07 16:56:20 +02:00
};
2017-10-17 11:30:44 +02:00
/*============================================================================*/
// Segment of an input's curve
2017-10-07 16:56:20 +02:00
struct T_SyncSegment
{
2017-10-17 11:30:44 +02:00
enum E_SegmentType
{
LINEAR ,
RAMP ,
SMOOTH ,
//HERMITE
};
2017-10-07 16:56:20 +02:00
uint32_t nPoints;
2017-10-17 11:30:44 +02:00
E_SegmentType type;
2017-10-07 16:56:20 +02:00
std::vector< float > values; // nPoints items
std::vector< uint32_t > durations; // nPoints - 1 items
};
2017-10-17 11:30:44 +02:00
// An input curve
struct T_SyncCurve
{
std::string name;
std::vector< T_SyncSegment > segments;
};
// Pre-computed data for a curve
struct T_SyncCurveCache
{
using T_SegRef = std::pair< uint32_t , uint32_t >;
2017-10-07 16:56:20 +02:00
2017-10-17 11:30:44 +02:00
T_SyncCurve const* variable;
std::vector< T_SegRef > segRefs;
std::vector< float > segStarts;
2017-10-07 16:56:20 +02:00
2017-10-17 11:30:44 +02:00
T_SyncCurveCache(
__rd__ T_SyncCurve const* const variable ,
__rd__ const uint32_t duration ,
__rd__ const uint32_t position ) noexcept;
float valueAt(
__rd__ const float position ,
__rd__ const float units ) const noexcept;
};
using P_SyncCurveCache = std::unique_ptr< T_SyncCurveCache >;
/*============================================================================*/
struct T_SyncManager
{
float uDuration; // Duration - unit size
uint32_t iDuration; // Duration - total units
float duration( ) const noexcept
{ return uDuration * iDuration; }
// Sync manager data for an input may include a definition, a curve,
// or both. The idea behind supporting "curve only" is that a curve may
// have been defined for an input that has been removed temporarily
// (e.g. because some include was commented out), in which case we don't
// want to waste it.
struct T_Data
{
P_SyncInputDfn definition;
P_SyncCurveCache curve;
bool overriden;
};
// Data and ID<->index map
std::vector< T_Data > data;
std::map< std::string , uint32_t > posMap;
// Current time & values
float time;
std::vector< float > values;
// Root of the UI's tree
T_SyncUISections uiRoot;
void makeUI( );
};
/*============================================================================*/
using T_SyncVariable = std::vector< T_SyncSegment >;
2017-10-07 16:56:20 +02:00
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_;
};