15 #ifndef MOTIVE_PROCESSOR_H_
16 #define MOTIVE_PROCESSOR_H_
20 #include "fplutil/index_allocator.h"
21 #include "motive/common.h"
22 #include "motive/math/compact_spline.h"
23 #include "motive/math/vector_converter.h"
24 #include "motive/target.h"
61 : index_allocator_(allocator_callbacks_),
62 benchmark_id_for_advance_frame_(-1),
63 benchmark_id_for_init_(-1) {
64 allocator_callbacks_.set_processor(
this);
88 Motivator* motivator, MotiveDimension dimensions);
129 return ValidIndex(index) && motivators_[index] == motivator;
143 virtual MotivatorType
Type()
const = 0;
154 return index_allocator_.CountForIndex(index);
162 void RegisterBenchmarks();
163 int benchmark_id_for_advance_frame()
const {
164 return benchmark_id_for_advance_frame_;
166 int benchmark_id_for_init()
const {
return benchmark_id_for_init_; }
176 MotiveDimension dimensions,
177 MotiveEngine* engine) = 0;
185 virtual void RemoveIndices(MotiveIndex index, MotiveDimension dimensions) = 0;
191 virtual void MoveIndices(MotiveIndex old_index, MotiveIndex new_index,
192 MotiveDimension dimensions) = 0;
207 typedef fplutil::IndexAllocator<MotiveIndex> MotiveIndexAllocator;
208 typedef MotiveIndexAllocator::IndexRange IndexRange;
211 void RemoveMotivatorWithoutNotifying(MotiveIndex index);
214 void MoveIndexRangeBase(
const IndexRange& source, MotiveIndex target);
215 void SetNumIndicesBase(MotiveIndex num_indices);
218 class AllocatorCallbacks :
public MotiveIndexAllocator::CallbackInterface {
220 AllocatorCallbacks() : processor_(nullptr) {}
221 void set_processor(MotiveProcessor* processor) { processor_ = processor; }
223 processor_->SetNumIndicesBase(num_indices);
225 virtual void MoveIndexRange(
const IndexRange& source, MotiveIndex target) {
226 processor_->MoveIndexRangeBase(source, target);
230 MotiveProcessor* processor_;
240 std::vector<Motivator*> motivators_;
246 AllocatorCallbacks allocator_callbacks_;
253 MotiveIndexAllocator index_allocator_;
255 int benchmark_id_for_advance_frame_;
256 int benchmark_id_for_init_;
269 float Value(MotiveIndex index)
const {
return Values(index)[0]; }
270 float Velocity(MotiveIndex index)
const {
272 Velocities(index, 1, &v);
275 float Direction(MotiveIndex index)
const {
277 Directions(index, 1, &v);
280 float TargetValue(MotiveIndex index)
const {
282 TargetValues(index, 1, &v);
285 float TargetVelocity(MotiveIndex index)
const {
287 TargetVelocities(index, 1, &v);
290 float Difference(MotiveIndex index)
const {
292 Differences(index, 1, &v);
296 virtual const float* Values(MotiveIndex index)
const = 0;
297 virtual void Velocities(MotiveIndex index, MotiveDimension dimensions,
298 float* out)
const = 0;
299 virtual void Directions(MotiveIndex index, MotiveDimension dimensions,
301 Velocities(index, dimensions, out);
303 virtual void TargetValues(MotiveIndex index, MotiveDimension dimensions,
304 float* out)
const = 0;
305 virtual void TargetVelocities(MotiveIndex index, MotiveDimension dimensions,
306 float* out)
const = 0;
307 virtual void Differences(MotiveIndex index, MotiveDimension dimensions,
308 float* out)
const = 0;
310 virtual MotiveTime TargetTime(MotiveIndex index,
311 MotiveDimension dimensions)
const = 0;
312 virtual MotiveTime SplineTime(MotiveIndex )
const {
return 0; }
323 virtual void SetTargets(MotiveIndex , MotiveDimension ,
328 virtual void SetTargetWithShape(MotiveIndex ,
335 virtual void SetSplines(MotiveIndex , MotiveDimension ,
341 virtual void Splines(MotiveIndex , MotiveIndex count,
343 for (MotiveIndex i = 0; i < count; ++i) splines[i] =
nullptr;
348 virtual void SetSplinesAndTargets(MotiveIndex ,
354 virtual void SetSplineTime(MotiveIndex ,
357 virtual void SetSplinePlaybackRate(MotiveIndex ,
368 virtual const mathfu::mat4&
Value(MotiveIndex index)
const = 0;
371 virtual int NumChildren(MotiveIndex index)
const = 0;
374 virtual void ChildValues(MotiveIndex index, MotiveChildIndex child_index,
375 MotiveChildIndex count,
float* values)
const = 0;
380 MotiveIndex index, MotiveChildIndex child_index)
const = 0;
386 virtual void SetChildValues(MotiveIndex index, MotiveChildIndex child_index,
387 MotiveChildIndex count,
const float* values) = 0;
394 virtual void SetPlaybackRate(MotiveIndex index,
float playback_rate) = 0;
403 MotiveIndex index)
const = 0;
406 virtual MotiveTime
TimeRemaining(MotiveIndex index)
const = 0;
416 virtual void SetPlaybackRate(MotiveIndex index,
float playback_rate) = 0;
418 virtual std::string CsvHeaderForDebugging(MotiveIndex )
const {
419 return std::string();
421 virtual std::string CsvValuesForDebugging(MotiveIndex )
const {
422 return std::string();
424 virtual std::string LocalTransformsForDebugging(MotiveIndex ,
426 return std::string();
435 MotiveProcessorCreateFn* create;
436 MotiveProcessorDestroyFn* destroy;
439 MotiveProcessorDestroyFn* destroy)
440 : create(create), destroy(destroy) {}
445 #endif // MOTIVE_PROCESSOR_H_
virtual const Motivator * ChildMotivator1f(MotiveIndex index, MotiveChildIndex child_index) const =0
Interface for motivator types that drive a single float value.
Definition: processor.h:264
bool IsMotivatorIndex(MotiveIndex index) const
void Defragment()
Definition: processor.h:204
virtual void SetChildTarget1f(MotiveIndex, MotiveChildIndex, const MotiveTarget1f &)
Set child values. Matrices are composed from child components.
Definition: processor.h:383
virtual int NumChildren(MotiveIndex index) const =0
Get the number of matrix operations performed by this motivator.
virtual int Priority() const =0
virtual void MoveIndices(MotiveIndex old_index, MotiveIndex new_index, MotiveDimension dimensions)=0
bool ValidIndex(MotiveIndex index) const
virtual void BlendToAnim(MotiveIndex index, const RigAnim &anim, const motive::SplinePlayback &playback)=0
Smoothly transition to the animation in anim.
virtual void SetPlaybackRate(MotiveIndex index, float playback_rate)=0
Instantly change the playback speed of this animation.
virtual const mathfu::AffineTransform * GlobalTransforms(MotiveIndex index) const =0
virtual const mathfu::mat4 & Value(MotiveIndex index) const =0
Get the current matrix value from the processor.
virtual MotiveTime TimeRemaining(MotiveIndex index) const =0
Return the time remaining in the current matrix animation.
A MotiveProcessor processes all instances of one type of Motivator.
Definition: processor.h:58
Definition: processor.h:397
Animation for a RigMotivator. Drives a fully rigged model.
Definition: anim.h:72
bool ValidMotivator(MotiveIndex index, const Motivator *motivator) const
Definition: processor.h:128
virtual MotivatorType Type() const =0
A target curve shape for the motivator.
Definition: target.h:29
Definition: processor.h:434
void RemoveMotivator(MotiveIndex index)
virtual void BlendToOps(MotiveIndex, const MatrixOpArray &, const motive::SplinePlayback &)
Smoothly transition to the operations specified in ops.
Definition: processor.h:390
Hold and update all animation data.
Definition: engine.h:36
virtual void ChildValues(MotiveIndex index, MotiveChildIndex child_index, MotiveChildIndex count, float *values) const =0
Get current values of the components that create the matrix.
virtual void AdvanceFrame(MotiveTime delta_time)=0
Parameters to specify how a spline should be traversed.
Definition: compact_spline.h:590
virtual void RemoveIndices(MotiveIndex index, MotiveDimension dimensions)=0
virtual void SetNumIndices(MotiveIndex num_indices)=0
MotiveDimension Dimensions(MotiveIndex index) const
Definition: processor.h:153
void InitializeMotivator(const MotivatorInit &init, MotiveEngine *engine, Motivator *motivator, MotiveDimension dimensions)
Interface for motivator types that drive a 4x4 float matrix. That is, for MotiveProcessors that inter...
Definition: processor.h:365
Drives a value towards a target value, or along a path.
Definition: motivator.h:47
void TransferMotivator(MotiveIndex index, Motivator *new_motivator)
Set the current and/or target state for a one-dimensional Motivator.
Definition: target.h:98
Represent a smooth curve in a small amount of memory.
Definition: compact_spline.h:73
void VerifyInternalState() const
bool ValidMotivatorIndex(MotiveIndex index) const
virtual const RigAnim * DefiningAnim(MotiveIndex index) const =0
Return the animation that defines the rig.
virtual void InitializeIndices(const MotivatorInit &init, MotiveIndex index, MotiveDimension dimensions, MotiveEngine *engine)=0
virtual void SetPlaybackRate(MotiveIndex index, float playback_rate)=0
Instantly change the playback speed of this animation.