cstool/animnodetmpl.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2011 Christian Van Brussel, Institute of Information 00003 and Communication Technologies, Electronics and Applied Mathematics 00004 at Universite catholique de Louvain, Belgium 00005 http://www.uclouvain.be/en-icteam.html 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public 00018 License along with this library; if not, write to the Free 00019 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 #ifndef __CS_IMESH_ANIMNODE_TEMPLATE_H__ 00022 #define __CS_IMESH_ANIMNODE_TEMPLATE_H__ 00023 00028 #include "csextern.h" 00029 #include "csutil/csstring.h" 00030 #include "csutil/refarr.h" 00031 #include "csutil/scf_implementation.h" 00032 #include "csutil/weakref.h" 00033 #include "imesh/animnode/skeleton2anim.h" 00034 #include "iutil/comp.h" 00035 00036 namespace CS { 00037 namespace Animation { 00038 00061 template<typename ThisType, 00062 typename ManagerInterface, 00063 typename FactoryType> 00064 class AnimNodeManagerCommon 00065 : public scfImplementation2<AnimNodeManagerCommon<ThisType, ManagerInterface, FactoryType>, 00066 ManagerInterface, 00067 iComponent> 00068 { 00069 typedef typename ManagerInterface::FactoryInterfaceType FactoryInterfaceType; 00070 typedef scfImplementation2<AnimNodeManagerCommon<ThisType, ManagerInterface, FactoryType>, 00071 ManagerInterface, 00072 iComponent> scfImplementationType; 00073 public: 00074 typedef AnimNodeManagerCommon<ThisType, ManagerInterface, FactoryType> AnimNodeManagerCommonType; 00075 00076 AnimNodeManagerCommon (iBase* parent) 00077 : scfImplementationType (this, parent), object_reg (nullptr) 00078 {} 00079 00080 FactoryInterfaceType* CreateAnimNodeFactory (const char* name) 00081 { 00082 csRef<FactoryInterfaceType> newFact; 00083 newFact.AttachNew (new FactoryType (static_cast<ThisType*> (this), name)); 00084 return nodeFactories.PutUnique (name, newFact); 00085 } 00086 FactoryInterfaceType* FindAnimNodeFactory (const char* name) 00087 { 00088 return nodeFactories.Get (name, 0); 00089 } 00090 void RemoveAnimNodeFactory (const char* name) 00091 { 00092 nodeFactories.DeleteAll (name); 00093 } 00094 void ClearAnimNodeFactories () 00095 { 00096 nodeFactories.DeleteAll (); 00097 } 00098 00101 bool Initialize (iObjectRegistry* object_reg) 00102 { this->object_reg = object_reg; return true; } 00105 iObjectRegistry* GetObjectRegistry() const { return object_reg; } 00106 protected: 00107 iObjectRegistry* object_reg; 00108 csHash<csRef<FactoryInterfaceType>, csString> nodeFactories; 00109 }; 00110 00114 class CS_CRYSTALSPACE_EXPORT SkeletonAnimNodeFactory 00115 : public virtual iSkeletonAnimNodeFactory 00116 { 00117 public: 00121 SkeletonAnimNodeFactory (const char* name); 00122 00126 virtual ~SkeletonAnimNodeFactory () {} 00127 00131 virtual const char* GetNodeName () const; 00132 00133 protected: 00135 csString name; 00136 }; 00137 00138 class SkeletonAnimNodeSingleBase; 00139 00143 class CS_CRYSTALSPACE_EXPORT SkeletonAnimNodeFactorySingle 00144 : public SkeletonAnimNodeFactory 00145 { 00146 public: 00150 SkeletonAnimNodeFactorySingle (const char* name); 00151 00155 virtual ~SkeletonAnimNodeFactorySingle () {} 00156 00160 virtual void SetChildNode (iSkeletonAnimNodeFactory* factory); 00161 00165 virtual iSkeletonAnimNodeFactory* GetChildNode () const; 00166 00167 csPtr<iSkeletonAnimNode> CreateInstance (iSkeletonAnimPacket* packet, iSkeleton* skeleton); 00168 iSkeletonAnimNodeFactory* FindNode (const char* name); 00169 00170 protected: 00172 csRef<CS::Animation::iSkeletonAnimNodeFactory> childNodeFactory; 00173 00175 virtual csPtr<SkeletonAnimNodeSingleBase> ActualCreateInstance (iSkeletonAnimPacket* packet, 00176 iSkeleton* skeleton) = 0; 00177 }; 00178 00180 class CS_CRYSTALSPACE_EXPORT SkeletonAnimNodeSingleBase : public virtual iSkeletonAnimNode 00181 { 00182 public: 00186 SkeletonAnimNodeSingleBase (CS::Animation::iSkeleton* skeleton); 00187 00191 virtual ~SkeletonAnimNodeSingleBase () {} 00192 00196 virtual iSkeletonAnimNode* GetChildNode () const; 00197 00198 virtual void Play (); 00199 virtual void Stop (); 00200 virtual void SetPlaybackPosition (float time); 00201 virtual float GetPlaybackPosition () const; 00202 virtual float GetDuration () const; 00203 virtual void SetPlaybackSpeed (float speed); 00204 virtual float GetPlaybackSpeed () const; 00205 virtual void BlendState (AnimatedMeshState* state, float baseWeight = 1.0f); 00206 virtual void TickAnimation (float dt); 00207 virtual bool IsActive () const; 00208 virtual void AddAnimationCallback (iSkeletonAnimCallback* callback); 00209 virtual void RemoveAnimationCallback (iSkeletonAnimCallback* callback); 00210 00211 protected: 00213 csWeakRef<CS::Animation::iSkeleton> skeleton; 00214 00216 csRef<CS::Animation::iSkeletonAnimNode> childNode; 00217 00219 bool isPlaying; 00220 00222 float playbackSpeed; 00223 00224 friend class SkeletonAnimNodeFactorySingle; 00225 }; 00226 00232 template<typename FactoryType> 00233 class SkeletonAnimNodeSingle : public SkeletonAnimNodeSingleBase 00234 { 00235 public: 00236 SkeletonAnimNodeSingle (FactoryType* factory, 00237 CS::Animation::iSkeleton* skeleton) 00238 : SkeletonAnimNodeSingleBase (skeleton), factory (factory) {} 00239 00240 iSkeletonAnimNodeFactory* GetFactory () const 00241 { 00242 return factory; 00243 } 00244 00245 iSkeletonAnimNode* FindNode (const char* name) 00246 { 00247 if (strcmp (factory->GetNodeName (), name) == 0) 00248 return this; 00249 00250 if (childNode) 00251 return childNode->FindNode (name); 00252 00253 return nullptr; 00254 } 00255 00256 protected: 00258 csRef<FactoryType> factory; 00259 }; 00260 00264 class CS_CRYSTALSPACE_EXPORT SkeletonAnimNodeFactoryMulti 00265 : public SkeletonAnimNodeFactory 00266 { 00267 public: 00271 SkeletonAnimNodeFactoryMulti (const char* name); 00272 00276 virtual ~SkeletonAnimNodeFactoryMulti () {} 00277 00281 virtual void AddChildNode (iSkeletonAnimNodeFactory* factory); 00282 00286 virtual void RemoveChildNode (iSkeletonAnimNodeFactory* factory); 00287 00291 virtual void ClearChildNodes (); 00292 00296 virtual iSkeletonAnimNodeFactory* GetChildNode (size_t index) const; 00297 00298 protected: 00300 csRefArray<CS::Animation::iSkeletonAnimNodeFactory> childNodeFactories; 00301 }; 00302 00303 } // namespace Animation 00304 } // namespace CS 00305 00306 #endif // __CS_IMESH_ANIMNODE_TEMPLATE_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1