Nebula
Loading...
Searching...
No Matches
charactercontext.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
28//------------------------------------------------------------------------------
33#include "characters/skeleton.h"
37#include "jobs/jobs.h"
38
40{
41
42extern void AnimSampleJob(SizeT totalJobs, SizeT groupSize, IndexT groupIndex, SizeT invocationOffset, void* ctx);
43extern void AnimSampleJobWithMix(SizeT totalJobs, SizeT groupSize, IndexT groupIndex, SizeT invocationOffset, void* ctx);
44
45}
46
47namespace Characters
48{
49
51{
52 Append, // adds clip to the queue to play after current on the track
53 Replace, // replace current clip on the track
54 IgnoreIfSame // ignore enqueue if same clip is playing
55};
56
58{
60public:
61
65 virtual ~CharacterContext();
66
68 static void Create();
69
71 static void Setup(
73 , const Resources::ResourceName& skeletonResource
74 , const IndexT skeletonIndex
75 , const Resources::ResourceName& animationResource
76 , const IndexT animationIndex
77 , const Util::StringAtom& tag
78 , bool supportBlending = true
79 );
80
83
85 static bool PlayClip(
88 const IndexT clipIndex,
89 const IndexT track,
90 const EnqueueMode mode,
91 const float weight = 1.0f,
92 const SizeT loopCount = 1,
93 const float startTime = 0.0f,
94 const float fadeIn = 0.0f,
95 const float fadeOut = 0.0f,
96 const float timeOffset = 0.0f,
97 const float timeFactor = 1.0f);
99 static void StopTrack(const Graphics::GraphicsEntityId id, const IndexT track);
101 static void StopAllTracks(const Graphics::GraphicsEntityId id);
103 static void PauseTrack(const Graphics::GraphicsEntityId id, const IndexT track);
105 static void Seek(const Graphics::GraphicsEntityId id, const float time);
106
108 static const float GetTime(const Graphics::GraphicsEntityId id);
110 static bool IsPlaying(const Graphics::GraphicsEntityId id);
111
113 static void SetTrackWeight(const Graphics::GraphicsEntityId id, const IndexT track, const float weight);
115 static void SetTrackTimeFactor(const Graphics::GraphicsEntityId id, const IndexT track, const float factor);
116
119
121 static void UpdateAnimations(const Graphics::FrameContext& ctx);
123 static void WaitForCharacterJobs(const Graphics::FrameContext& ctx);
124
129
130#ifndef PUBLIC_DEBUG
132 static void OnRenderDebug(uint32_t flags);
133#endif
134
141
143private:
144 friend struct CharacterJobContext;
145
165
166 friend const bool IsExpired(const CharacterContext::AnimationRuntime& runtime, const Timing::Time time);
167 friend const bool IsInfinite(const CharacterContext::AnimationRuntime& runtime);
169 friend void EvalCharacter(SizeT totalJobs, SizeT groupSize, IndexT groupIndex, SizeT invocationOffset, void* ctx);
170
171 static const SizeT MaxNumTracks = 16;
177
178 enum
179 {
193 };
194
195 typedef Ids::IdAllocator<
198 LoadState,
199 AnimationTracks,
206 bool,
208 IndexT
211
215 static void Dealloc(Graphics::ContextEntityId id);
216
219};
220
222
223//------------------------------------------------------------------------------
231
232//------------------------------------------------------------------------------
235inline void
240
241} // namespace Characters
Assumes control over the character animation functionalities of a model if it contains a character de...
Definition charactercontext.h:58
static bool IsPlaying(const Graphics::GraphicsEntityId id)
check if any animation is playing
Definition charactercontext.cc:289
static void SetTrackWeight(const Graphics::GraphicsEntityId id, const IndexT track, const float weight)
set weight for track
Definition charactercontext.cc:305
static void QueryClips(const Graphics::GraphicsEntityId id, Util::FixedArray< CoreAnimation::AnimClip > &outClips)
retrieve animation clip names and lengths
Definition charactercontext.cc:339
static IndexT GetClipIndex(const Graphics::GraphicsEntityId id, const Util::StringAtom &name)
perform a clip name lookup
Definition charactercontext.cc:150
friend Timing::Tick GetAbsoluteStopTime(const CharacterContext::AnimationRuntime &runtime)
Definition charactercontext.cc:371
static void PauseTrack(const Graphics::GraphicsEntityId id, const IndexT track)
pause animation on track, which doesn't reset time
Definition charactercontext.cc:251
friend const bool IsExpired(const CharacterContext::AnimationRuntime &runtime, const Timing::Time time)
Definition charactercontext.cc:350
static CoreAnimation::AnimSampleMask * GetAnimSampleMask(const Util::StringAtom &name)
get anim sample mask by name
Definition charactercontext.cc:796
static void OnRenderDebug(uint32_t flags)
debug rendering
Definition charactercontext.cc:808
static void SetTrackTimeFactor(const Graphics::GraphicsEntityId id, const IndexT track, const float factor)
set time factor for track
Definition charactercontext.cc:322
static void Setup(const Graphics::GraphicsEntityId id, const Resources::ResourceName &skeletonResource, const IndexT skeletonIndex, const Resources::ResourceName &animationResource, const IndexT animationIndex, const Util::StringAtom &tag, bool supportBlending=true)
setup character context, assumes there is already a model attached, by loading a skeleton and animati...
Definition charactercontext.cc:63
static Graphics::ContextEntityId Alloc()
allocate a new slice for this context
Definition charactercontext.h:227
static void Seek(const Graphics::GraphicsEntityId id, const float time)
seek animation to a certain time, clamps to length
Definition charactercontext.cc:269
static bool PlayClip(const Graphics::GraphicsEntityId id, const CoreAnimation::AnimSampleMask *mask, const IndexT clipIndex, const IndexT track, const EnqueueMode mode, const float weight=1.0f, const SizeT loopCount=1, const float startTime=0.0f, const float fadeIn=0.0f, const float fadeOut=0.0f, const float timeOffset=0.0f, const float timeFactor=1.0f)
play animation on a specific track
Definition charactercontext.cc:160
static void Create()
setup character context
Definition charactercontext.cc:50
static void Dealloc(Graphics::ContextEntityId id)
deallocate a slice
Definition charactercontext.h:236
friend void EvalCharacter(SizeT totalJobs, SizeT groupSize, IndexT groupIndex, SizeT invocationOffset, void *ctx)
Definition charactercontext.cc:403
static void StopTrack(const Graphics::GraphicsEntityId id, const IndexT track)
stops all animations queued on track (and resets their time)
Definition charactercontext.cc:220
static void WaitForCharacterJobs(const Graphics::FrameContext &ctx)
run after frame
Definition charactercontext.cc:775
@ SampleBuffer
Definition charactercontext.h:189
@ JointPalette
Definition charactercontext.h:185
@ CharacterSkinNodeIndexOffset
Definition charactercontext.h:192
@ AnimTime
Definition charactercontext.h:184
@ UserControlledJoint
Definition charactercontext.h:187
@ EntityId
Definition charactercontext.h:191
@ JobJoints
Definition charactercontext.h:188
@ SupportMix
Definition charactercontext.h:190
@ Loaded
Definition charactercontext.h:182
@ Skeleton
Definition charactercontext.h:180
@ Animation
Definition charactercontext.h:181
@ JointPaletteScaled
Definition charactercontext.h:186
@ TrackController
Definition charactercontext.h:183
static void StopAllTracks(const Graphics::GraphicsEntityId id)
stops all animations on all tracks
Definition charactercontext.cc:234
CharacterContext()
constructor
Definition charactercontext.cc:33
LoadState
Definition charactercontext.h:136
@ AnimationLoaded
Definition charactercontext.h:139
@ SkeletonLoaded
Definition charactercontext.h:138
@ NoneLoaded
Definition charactercontext.h:137
static Util::HashTable< Util::StringAtom, CoreAnimation::AnimSampleMask > masks
Definition charactercontext.h:217
static CoreAnimation::AnimSampleMask * CreateAnimSampleMask(const Util::StringAtom &name, const Util::FixedArray< Math::scalar > &weights)
register anim sample mask, and return pointer
Definition charactercontext.cc:786
friend const bool IsInfinite(const CharacterContext::AnimationRuntime &runtime)
Definition charactercontext.cc:362
Ids::IdAllocator< SkeletonId, CoreAnimation::AnimationId, LoadState, AnimationTracks, Timing::Time, Util::FixedArray< Math::mat4 >, Util::FixedArray< Math::mat4 >, Util::FixedArray< Math::mat4 >, Util::FixedArray< SkeletonJobJoint >, CoreAnimation::AnimSampleBuffer, bool, Graphics::GraphicsEntityId, IndexT > CharacterContextAllocator
Definition charactercontext.h:209
virtual ~CharacterContext()
destructor
Definition charactercontext.cc:41
static CharacterContextAllocator characterContextAllocator
Definition charactercontext.h:210
static Threading::AtomicCounter ConstantUpdateCounter
Definition charactercontext.h:142
static const SizeT MaxNumTracks
Definition charactercontext.h:171
static Threading::Event totalCompletionEvent
Definition charactercontext.h:218
static const float GetTime(const Graphics::GraphicsEntityId id)
get current time of animation
Definition charactercontext.cc:279
static void UpdateAnimations(const Graphics::FrameContext &ctx)
runs before frame is updated
Definition charactercontext.cc:648
Stores the result of an animation sampling operation, stores samples key values and sample-counts whi...
Definition animsamplebuffer.h:22
Definition graphicscontext.h:165
An ID allocator associates an id with a slice in an N number of arrays.
Definition idallocator.h:39
Ids::Id32 Alloc()
Allocate an object.
Definition idallocator.h:45
void Dealloc(Ids::Id32 index)
Deallocate an object. Just places it in freeids array for recycling.
Definition idallocator.h:65
Nebula's dynamic array class.
Definition array.h:60
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
Organizes key/value pairs by a hash code.
Definition hashtable.h:42
A StringAtom.
Definition stringatom.h:22
A character encapsulates a skeleton resource, an animation resource, and the ability to instantiate s...
Definition charactercontext.cc:21
EnqueueMode
Definition charactercontext.h:51
@ Replace
Definition charactercontext.h:53
@ IgnoreIfSame
Definition charactercontext.h:54
@ Append
Definition charactercontext.h:52
An animation resource holds a set of animations from a loaded NAX file.
Definition charactercontext.h:40
void AnimSampleJob(SizeT totalJobs, SizeT groupSize, IndexT groupIndex, SizeT invocationOffset, void *ctx)
void AnimSampleJobWithMix(SizeT totalJobs, SizeT groupSize, IndexT groupIndex, SizeT invocationOffset, void *ctx)
volatile int AtomicCounter
Definition interlocked.h:19
int Tick
the tick datatype (one tick == 1 millisecond)
Definition time.h:20
double Time
the time datatype
Definition time.h:18
#define __ImplementEnumBitOperators(type)
Definition charactercontext.h:147
Timing::Tick prevEvalTime
Definition charactercontext.h:153
const CoreAnimation::AnimSampleMask * mask
Definition charactercontext.h:157
Timing::Tick timeOffset
Definition charactercontext.h:155
Timing::Tick baseTime
Definition charactercontext.h:150
bool paused
Definition charactercontext.h:160
EnqueueMode enqueueMode
Definition charactercontext.h:149
Timing::Tick sampleTime
Definition charactercontext.h:154
Timing::Tick duration
Definition charactercontext.h:151
Timing::Tick startTime
Definition charactercontext.h:150
IndexT clip
Definition charactercontext.h:148
Timing::Tick prevSampleTime
Definition charactercontext.h:154
Timing::Tick evalTime
Definition charactercontext.h:153
Util::Array< uint > curveSampleIndices
Definition charactercontext.h:156
float timeFactor
Definition charactercontext.h:158
float blend
Definition charactercontext.h:159
Timing::Tick fadeOutTime
Definition charactercontext.h:152
Timing::Tick fadeInTime
Definition charactercontext.h:152
Definition charactercontext.h:173
AnimationRuntime playingAnimations[MaxNumTracks]
Definition charactercontext.h:175
Util::StackArray< AnimationRuntime, 8 > pendingAnimations[MaxNumTracks]
Definition charactercontext.h:174
Definition charactercontext.cc:378
Definition skeleton.h:17
Definition animsamplemask.h:16
Definition animation.h:25
Definition graphicscontext.h:133
Definition graphicsserver.h:31
The graphics entity is only an Id, to which we can attach GraphicsContexts.
Definition graphicsentity.h:16
Nebula's universal string class.
Definition string.h:50
#define N_BIT(x)
Definition types.h:86
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48