Motive Animation System
An open source project by FPL.
 All Classes Functions Variables Typedefs Friends Pages
motive::MotiveProcessor Class Referenceabstract

A MotiveProcessor processes all instances of one type of Motivator. More...

#include <processor.h>

Inheritance diagram for motive::MotiveProcessor:
motive::MatrixProcessor4f motive::MotiveProcessorNf motive::RigProcessor motive::SimpleProcessorTemplate< T >

Detailed Description

A MotiveProcessor processes all instances of one type of Motivator.

Each derivation of MotiveProcessor is one animation algorithm. It holds all the data for all Motivators that are currently using that animation algorithm.

We pool the processing for potential optimization opportunities. We may have hundreds of smoothly-interpolating one-dimensional Motivators, for example. It's nice to be able to update those 4 or 8 or 16 at a time using SIMD. And it's nice to have the data gathered in one spot if we want to use multiple threads.

MotiveProcessors exists in the internal API. For the external API, please see Motivator.

Users can create their own Motivator algorithms by deriving from MotiveProcessor. MotiveProcessors must have a factory that's registered with the MotiveEngine (please see MotiveEngine for details). Once registered, you can use your new Motivator algorithm by calling Motivator::Initialize() with Init::type set to your MotiveProcessor's MotivatorType.

MotiveProcessors run on mathfu types. Please see the specializations below for MotiveProcessors of various dimensions.

Public Member Functions

void InitializeMotivator (const MotivatorInit &init, MotiveEngine *engine, Motivator *motivator, MotiveDimension dimensions)
 
void RemoveMotivator (MotiveIndex index)
 
void TransferMotivator (MotiveIndex index, Motivator *new_motivator)
 
bool IsMotivatorIndex (MotiveIndex index) const
 
bool ValidIndex (MotiveIndex index) const
 
bool ValidMotivatorIndex (MotiveIndex index) const
 
bool ValidMotivator (MotiveIndex index, const Motivator *motivator) const
 
virtual void AdvanceFrame (MotiveTime delta_time)=0
 
virtual MotivatorType Type () const =0
 
virtual int Priority () const =0
 
MotiveDimension Dimensions (MotiveIndex index) const
 
void VerifyInternalState () const
 
void RegisterBenchmarks ()
 
int benchmark_id_for_advance_frame () const
 
int benchmark_id_for_init () const
 

Protected Member Functions

virtual void InitializeIndices (const MotivatorInit &init, MotiveIndex index, MotiveDimension dimensions, MotiveEngine *engine)=0
 
virtual void RemoveIndices (MotiveIndex index, MotiveDimension dimensions)=0
 
virtual void MoveIndices (MotiveIndex old_index, MotiveIndex new_index, MotiveDimension dimensions)=0
 
virtual void SetNumIndices (MotiveIndex num_indices)=0
 
void Defragment ()
 

Member Function Documentation

virtual void motive::MotiveProcessor::AdvanceFrame ( MotiveTime  delta_time)
pure virtual

Advance the simulation by delta_time.

This function should only be called by MotiveEngine::AdvanceFrame.

Parameters
delta_timeTime since the last call to AdvanceFrame(). Time units are determined by the user.
void motive::MotiveProcessor::Defragment ( )
inlineprotected

When an index is moved, the Motivator that references that index is updated. Can be called at the discretion of your MotiveProcessor, but normally called at the beginning of your MotiveProcessor::AdvanceFrame.

MotiveDimension motive::MotiveProcessor::Dimensions ( MotiveIndex  index) const
inline

The number of slots occupied in the MotiveProcessor. For example, a position in 3D space would return 3. A single 4x4 matrix would return 1.

virtual void motive::MotiveProcessor::InitializeIndices ( const MotivatorInit init,
MotiveIndex  index,
MotiveDimension  dimensions,
MotiveEngine engine 
)
protectedpure virtual

Initialize data at [index, index + dimensions). The meaning of index is determined by the MotiveProcessor implementation (most likely it is the index into one or more data_ arrays though). MotiveProcessor tries to keep the index as low as possible, by recycling ones that have been freed, and by providing a Defragment() function to move later indices to indices that have been freed.

Implemented in motive::SimpleProcessorTemplate< T >.

void motive::MotiveProcessor::InitializeMotivator ( const MotivatorInit init,
MotiveEngine engine,
Motivator motivator,
MotiveDimension  dimensions 
)

Instantiate motivator data inside the MotiveProcessor, and initialize motivator as a reference to that data.

This function should only be called by Motivator::Initialize().

Parameters
initThe initialization parameters for the Motivator. Each MotiveProcessor has its own derivation of MotivatorInit, and InitializeMotivator will only ever be called with that derivation.
engineThe owner of all the MotiveProcessors. An engine holds at most one of any type of MotiveProcessor. The engine can be used to create child Motivators that drive motivator.
motivatorThe Motivator that is initialized to reference into This MotiveProcessor. The MotiveProcessor also keeps a reference to motivator in case it shuffles around internal data.
dimensionsThe number of slots to consume in the MotiveProcessor. For example, a 3D vector would consume three slots in a MotiveProcessor of floats.
bool motive::MotiveProcessor::IsMotivatorIndex ( MotiveIndex  index) const

Returns true if index is currently driving a motivator. Does not do any validity checking, however, like ValidMotivatorIndex() does.

Parameters
indexReference into the MotiveProcessor's internal arrays.
virtual void motive::MotiveProcessor::MoveIndices ( MotiveIndex  old_index,
MotiveIndex  new_index,
MotiveDimension  dimensions 
)
protectedpure virtual

Move the data chunk of length dimensions from old_index into new_index. Used by Defragment(). Note that the index range starting at new_index is guaranteed to be inactive.

Implemented in motive::SimpleProcessorTemplate< T >.

virtual int motive::MotiveProcessor::Priority ( ) const
pure virtual

The lower the number, the sooner the MotiveProcessor gets updated. Should never change. We want a static ordering of processors. Some MotiveProcessors use the output of other MotiveProcessors, so we impose a strict ordering here.

virtual void motive::MotiveProcessor::RemoveIndices ( MotiveIndex  index,
MotiveDimension  dimensions 
)
protectedpure virtual

Reset data at [index, index + dimensions). See comment above InitializeIndex for meaning of index. If your MotiveProcessor stores data in a plain array, you probably have nothing to do. But if you use dynamic memory per index, (which you really shouldn't - too slow!), you should deallocate it here. For debugging, it might be nice to invalidate the data.

Implemented in motive::SimpleProcessorTemplate< T >.

void motive::MotiveProcessor::RemoveMotivator ( MotiveIndex  index)

Remove an motivator and return its index to the pile of allocatable indices.

This function should only be called by Motivator::Invalidate().

Parameters
indexReference into the MotiveProcessor's internal arrays.
virtual void motive::MotiveProcessor::SetNumIndices ( MotiveIndex  num_indices)
protectedpure virtual

Increase or decrease the total number of indices. If decreased, existing indices >= num_indices should be uninitialized. If increased, internal arrays should be extended to new_indices, and new items in the arrays should be initialized as reset.

Implemented in motive::SimpleProcessorTemplate< T >.

void motive::MotiveProcessor::TransferMotivator ( MotiveIndex  index,
Motivator new_motivator 
)

Transfer ownership of the motivator at index to 'new_motivator'. Resets the Motivator that currently owns index and initializes 'new_motivator'.

This function should only be called by Motivator's copy operations.

Parameters
indexReference into the MotiveProcessor's internal arrays.
new_motivatorThe Motivator that is initialized to reference index.
virtual MotivatorType motive::MotiveProcessor::Type ( ) const
pure virtual

Should return kType of the MotivatorInit class for the derived processor. kType is defined by the macro MOTIVE_INTERFACE, which is put in a processor's MotivatorInit derivation.

bool motive::MotiveProcessor::ValidIndex ( MotiveIndex  index) const

Returns true if index is currently in a block of indices driven by a motivator.

Parameters
indexReference into the MotiveProcessor's internal arrays.
bool motive::MotiveProcessor::ValidMotivator ( MotiveIndex  index,
const Motivator motivator 
) const
inline

Returns true if index is currently driving motivator.

Parameters
indexReference into the MotiveProcessor's internal arrays.
motivatorMotivator to verify points to index.
bool motive::MotiveProcessor::ValidMotivatorIndex ( MotiveIndex  index) const

Returns true if a Motivator is referencing this index. That is, if this index is part of a block of indices (for example a block of 3 indices referenced by a Motivator3f), then this index is the first index in that block.

void motive::MotiveProcessor::VerifyInternalState ( ) const

Ensure that the internal state is consistent. Call periodically when debugging problems where the internal state is corrupt.


The documentation for this class was generated from the following file: