stmm-games-doc  0.32.0
Public Types | Public Member Functions | Public Attributes | List of all members
stmg::ElapsedMapper Class Reference

Elapsed mapper. More...

Public Types

enum  MAPPING_TYPE {
  MAPPING_TYPE_IDENTITY = 0, MAPPING_TYPE_OOR_UNDEFINED = 1, MAPPING_TYPE_OOR_CLAMP = 2, MAPPING_TYPE_OOR_MODULO = 3,
  MAPPING_TYPE_OOR_ALT_MODULO = 4
}
 

Public Member Functions

double map (double fElapsed01) const noexcept
 The mapping. More...
 

Public Attributes

MAPPING_TYPE m_eMappingType = MAPPING_TYPE_IDENTITY
 Default is MAPPING_TYPE_IDENTITY. More...
 
double m_fA = 1.0
 The 'a' in the mapping function 'y = a * x + b'. More...
 
double m_fB = 0.0
 The 'b' in the mapping function 'y = a * x + b'. More...
 
double m_fMin = 0.0
 The min value. More...
 
double m_fMax = 1.0
 The max value. More...
 
bool m_bShrink = false
 Apply shrinking to (m_fMin, m_fMax) rather than clamping. More...
 

Detailed Description

Elapsed mapper.

A linear function a * elapsed + b is applied according to MAPPING_TYPE. If elapsed is -1.0 the same value is returned, with no further processing. Otherwise an additional optional clamping or shrinking to a min and max value is applied.

Member Enumeration Documentation

◆ MAPPING_TYPE

Enumerator
MAPPING_TYPE_IDENTITY 

The identity mapping, as if m_fA is 1.0 and m_fB is 0.0.

m_fA and m_fB are ignored, but min-max is still applied.

MAPPING_TYPE_OOR_UNDEFINED 

When the (linear) function maps outside of (0.0, 1.0) the result is undefined (-1.0) and all other members are ignored.

MAPPING_TYPE_OOR_CLAMP 

When the function maps outside of (0.0, 1.0) the result is clamped to 0.0 for negative values and 1.0 for positive values.

Example: -3.5 is mapped to 0.0.

MAPPING_TYPE_OOR_MODULO 

When the function maps outside of (0.0, 1.0) the result is y - std::floor(y).

Example: If 'a * x + b' returns value 1.7, the result is mapped to 0.7. -1.7 on the other hand would be mapped to 0.3.

MAPPING_TYPE_OOR_ALT_MODULO 

Same as MAPPING_TYPE_OOR_MODULO but the result is subtracted to 1.0 if ((int)std::trunc(a * x + b)) % 2 is not 0.

Example: -0.1 is mapped to '0.1'. Example: -1.1 is mapped to '0.9'. Example: -2.1 is mapped to '0.1'.

Member Function Documentation

◆ map()

double stmg::ElapsedMapper::map ( double  fElapsed01) const
noexcept

The mapping.

Parameters
fElapsed01The input. Must be a non negative number not bigger than 1.0.
Returns
The result. Is either -1 or a non negative number not bigger than 1.0.

Member Data Documentation

◆ m_bShrink

bool stmg::ElapsedMapper::m_bShrink = false

Apply shrinking to (m_fMin, m_fMax) rather than clamping.

Default is false.

◆ m_eMappingType

MAPPING_TYPE stmg::ElapsedMapper::m_eMappingType = MAPPING_TYPE_IDENTITY

Default is MAPPING_TYPE_IDENTITY.

◆ m_fA

double stmg::ElapsedMapper::m_fA = 1.0

The 'a' in the mapping function 'y = a * x + b'.

Default is 1.

◆ m_fB

double stmg::ElapsedMapper::m_fB = 0.0

The 'b' in the mapping function 'y = a * x + b'.

Default is 0.

◆ m_fMax

double stmg::ElapsedMapper::m_fMax = 1.0

The max value.

Must be within interval (0.0, 1.0) and be bigger than m_fMin. Default is 1.

◆ m_fMin

double stmg::ElapsedMapper::m_fMin = 0.0

The min value.

Must be within interval (0.0, 1.0). Default is 0.