animationComponent.h
Engine/source/T3D/components/animation/animationComponent.h
Classes:
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef ANIMATION_COMPONENT_H 25#define ANIMATION_COMPONENT_H 26 27#ifndef COMPONENT_H 28#include "T3D/components/component.h" 29#endif 30#ifndef _TSSHAPE_H_ 31#include "ts/tsShapeInstance.h" 32#endif 33#ifndef ENTITY_H 34#include "T3D/entity.h" 35#endif 36#ifndef RENDER_COMPONENT_INTERFACE_H 37#include "T3D/components/render/renderComponentInterface.h" 38#endif 39 40class SceneRenderState; 41 42class AnimationComponent : public Component 43{ 44 typedef Component Parent; 45public: 46 enum PublicConstants { 47 ThreadSequenceBits = 6, 48 MaxSequenceIndex = (1 << ThreadSequenceBits) - 1, 49 MaxScriptThreads = 16, ///< Should be a power of 2 50 }; 51 52 enum MaskBits { 53 ThreadMaskN = Parent::NextFreeMask << 0, 54 ThreadMask = (ThreadMaskN << MaxScriptThreads) - ThreadMaskN, 55 NextFreeMask = ThreadMaskN << MaxScriptThreads 56 }; 57 58protected: 59 60 struct Thread 61 { 62 /// State of the animation thread. 63 enum State 64 { 65 Play, Stop, Pause, Destroy 66 }; 67 TSThread* thread; ///< Pointer to 3space data. 68 U32 state; ///< State of the thread 69 /// 70 /// @see Thread::State 71 S32 sequence; ///< The animation sequence which is running in this thread. 72 F32 timescale; ///< Timescale 73 U32 sound; ///< Handle to sound. 74 bool atEnd; ///< Are we at the end of this thread? 75 F32 position; 76 bool transition; 77 }; 78 79 Thread mAnimationThreads[MaxScriptThreads]; 80 81protected: 82 RenderComponentInterface * mOwnerRenderInst; 83 84 TSShapeInstance *mOwnerShapeInstance; 85 86public: 87 AnimationComponent(); 88 virtual ~AnimationComponent(); 89 DECLARE_CONOBJECT(AnimationComponent); 90 91 virtual bool onAdd(); 92 virtual void onRemove(); 93 static void initPersistFields(); 94 95 virtual void onComponentAdd(); 96 97 virtual void componentAddedToOwner(Component *comp); 98 virtual void componentRemovedFromOwner(Component *comp); 99 100 virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream); 101 virtual void unpackUpdate(NetConnection *con, BitStream *stream); 102 103 TSShape* getShape(); 104 105 void targetShapeChanged(RenderComponentInterface* instanceInterface); 106 107 virtual void processTick(); 108 virtual void advanceTime(F32 dt); 109 110 const char *getThreadSequenceName(U32 slot); 111 bool setThreadSequence(U32 slot, S32 seq, bool reset = true, bool transition = true, F32 transitionTime = 0.5); 112 void updateThread(Thread& st); 113 bool stopThread(U32 slot); 114 bool destroyThread(U32 slot); 115 bool pauseThread(U32 slot); 116 bool playThread(U32 slot); 117 bool playThread(U32 slot, const char* name, bool transition, F32 transitionTime); 118 bool setThreadAnimation(U32 slot, const char* name); 119 bool setThreadPosition(U32 slot, F32 pos); 120 bool setThreadDir(U32 slot, bool forward); 121 bool setThreadTimeScale(U32 slot, F32 timeScale); 122 void stopThreadSound(Thread& thread); 123 void startSequenceSound(Thread& thread); 124 void advanceThreads(F32 dt); 125 126 S32 getThreadSequenceID(S32 slot); 127 128 //other helper functions 129 S32 getAnimationCount(); 130 S32 getAnimationIndex(const char* name); 131 const char* getAnimationName(S32 index); 132 133 //callbacks 134 DECLARE_CALLBACK(void, onAnimationStart, (Component* obj, const String& animName)); 135 DECLARE_CALLBACK(void, onAnimationEnd, (Component* obj, const char* animName)); 136 DECLARE_CALLBACK(void, onAnimationTrigger, (Component* obj, const String& animName, S32 triggerID)); 137}; 138 139#endif //_ANIMATION_COMPONENT_H 140
