Mutator Class Reference

#include <Mutator.h>

Description

A piecewise function manager that changes inputs over time.

There are some instances where it is useful to model the transformation of a value in a complex manner. The Mutator component provides functionality for simple and complex easing. You can string easing functions together to achieve more complex behavior in one instance of a Mutator through the mutation interface. All times are delt with in seconds and the Mutator always begins at time 0.

Public Types

enum  Function {
  Constant,
  Linear,
  Quadratic,
  SquareRoot,
  Cubic,
  Sinusoidal,
  Logarithmic,
  RandomDistribution
}
 
enum  BindFunction {
  Set,
  Add,
  Subtract,
  Multiply,
  Divide
}
 
- Public Types inherited from Component
using EventHandler = bool(*)(void *, Component *component, Entity::ID self, Entity::ID source, const std::vector< std::string > &args)
 

Functions

 Mutator (float beginValue, float endValue, Function f, float duration)
 
void Clear (float beginValue)
 
void NewMutation (float when, float value, Function travelFunction)
 
void NewRandomMutation (float when, float minValue, float MaxValue, Function travelFunction)
 
void SetMutationDestination (int mutationIndex, float newValue)
 
void Start ()
 
void Stop ()
 
void Loop (bool)
 
bool Expired ()
 
float GetCurrentTime ()
 
float GetEnd ()
 
float GetAt (float time)
 
float Value ()
 
void OnStep ()
 
std::string GetInfo ()
 
void Bind (float &, BindFunction f=BindFunction::Set)
 
- Functions inherited from Component
std::string GetTag ()
 
EntityGetHost () const
 
template<typename T >
T * GetHostAs () const
 
Entity::ID GetHostID () const
 
bool EmitEvent (const std::string &eventName, Entity::ID source=Entity::ID(), const std::vector< std::string > &args={})
 
bool CanHandleEvent (const std::string &eventName)
 
void InstallHook (const std::string &eventName, EventHandler, void *data=nullptr)
 
void UninstallHook (const std::string &eventName, EventHandler)
 
void InstallHandler (const std::string &eventName, EventHandler, void *data=nullptr)
 
void UninstallHandler (const std::string &eventName, EventHandler)
 
std::vector< std::string > GetKnownEvents () const
 

Static Functions

static float StepTowards (float current, float destination, float step=.5f, Function f=Function::Linear)
 

Additional Inherited Members

- Protected Member Functions inherited from Component
virtual void OnDraw ()
 
virtual void OnAttach ()
 
void InstallEvent (const std::string &eventName, EventHandler mainHandler=nullptr, void *data=nullptr)
 
void UninstallEvent (const std::string &)
 

Member Enumeration Documentation

enum Function
strong

For constructing the Mutator's mutations, you must specify a mutation function. These are the various available.

Enumerator
Constant 

The state instantaneously changes to the next value.

Linear 

The state linearly changes to the next value.

Quadratic 

The state quadratically transforms to the next value.

SquareRoot 

The state transforms in a reverse-quadratic manner to the next value.

Cubic 

The state alters in a cubic manner to the next value.

Sinusoidal 

The state sinusoidally changes to the next value.

Logarithmic 

The state changes in a logarithmic manner to the next value.

RandomDistribution 

The state changes to random values between the state at the start and the end state.

enum BindFunction
strong

Tells how values should change when bound.

Enumerator
Set 

Updates the value with the current Value(), replacing the old one.

Add 

Adds the Value()

Subtract 

Subtracts the Value()

Multiply 

Multiplies by the Value()

Divide 

Divides by the Value()

Constructor & Destructor Documentation

Mutator ( float  beginValue,
float  endValue,
Function  f,
float  duration 
)

Convenience constructor to set up the Mutator with one function.

Parameters
beginValueThe value that the Mutator should start at.
endValueThe value that the Mutator should end at.
fThe mutation function to use.
durationThe duration of the mutation in seconds.

Member Function Documentation

void Clear ( float  beginValue)

Resets all mutations.

void NewMutation ( float  when,
float  value,
Function  travelFunction 
)

Sets a new point of mutation.

When denotes when the Mutator will reach the given value, and travelFunction defines how this value is reached.

void NewRandomMutation ( float  when,
float  minValue,
float  MaxValue,
Function  travelFunction 
)

Like NewMutation(), except the destination value is random chosen upon start(). min / max bound the random value.

void SetMutationDestination ( int  mutationIndex,
float  newValue 
)

Sets a new destination value for the mutation.

void Start ( )

Begins the mutation lifetime.

If it was already started, this function starts the simulation from the beginning.

void Stop ( )

Stops the mutation.

Stopping the mutation brings it to its end value.

void Loop ( bool  )

Sets whether or not to automatically restart after the final value has been reached.

bool Expired ( )

Returns whether or not the terminal value has been reached.

float GetCurrentTime ( )

Returns the mutator's progress in seconds.

float GetEnd ( )

Returns the duration of the mutation.

float GetAt ( float  time)

Returns the Mutator's mutation value at a specified time.

float Value ( )

Returns the current mutation value result.

void Bind ( float &  ,
BindFunction  f = BindFunction::Set 
)

Binds a reference to the Mutator.

Once a value is bound, it will be accessed and updated on the Step of the playing Mutation with the current Value() How the value will be updated depends on the BindFunction set The defualt is to "Set" which just replaces the value with the mutation value.

static float StepTowards ( float  current,
float  destination,
float  step = .5f,
Function  f = Function::Linear 
)
static

Iteratively eases a value to another and returns the stepped value. This is known in other toolkits as the 'lerp' function.

void OnStep ( )
virtual

Function that is called upon each Run iteration. Component Run()s are run before the entity's run function.

Reimplemented from Component.

std::string GetInfo ( )
virtual

Returns a string containing human-readable information on the state of the component.

Reimplemented from Component.


The documentation for this class was generated from the following file:
  • /home/jc/git/Dynacoe/DynacoeSrc/includes/Dynacoe/Components/Mutator.h