Leviathan  0.8.0.0
Leviathan game engine
Leviathan::AnimationSystem Class Reference

Handles updating time of Ogre animations. More...

#include <Systems.h>

Public Member Functions

DLLEXPORT void Run (GameWorld &world, std::unordered_map< ObjectID, Animated * > &index, float elapsed)
 

Detailed Description

Handles updating time of Ogre animations.

Todo:
This needs to be replaced with an animation system

Definition at line 126 of file Systems.h.

Member Function Documentation

◆ Run()

DLLEXPORT void AnimationSystem::Run ( GameWorld world,
std::unordered_map< ObjectID, Animated * > &  index,
float  elapsed 
)

Definition at line 242 of file Systems.cpp.

244 {
245  Graphics* graphics = Engine::Get()->GetGraphics();
246 
247  for(auto iter = index.begin(); iter != index.end(); ++iter) {
248 
249  Animated& animated = *iter->second;
250 
251  if(!animated.Animation)
252  continue;
253 
254  if(animated.Marked) {
255  animated.Marked = false;
256 
257  // Apply all properties and start playback
258  for(size_t animationIndex = 0; animationIndex < animated.Animations.size();
259  ++animationIndex) {
260 
261  auto& animation = animated.Animations[animationIndex];
262 
263  // Load clip
264  if(!animation._LoadedAnimation || animation.NameMarked) {
265  animation._LoadedAnimation = AnimationTrack::MakeShared<AnimationTrack>(
266  graphics->LoadAnimationClipByName(animation.Name));
267  animation.NameMarked = false;
268 
269  if(!animation._LoadedAnimation ||
270  !animation._LoadedAnimation->GetInternal()) {
271  LOG_ERROR("AnimationSystem: failed to load animation named: " +
272  animation.Name);
273  continue;
274  }
275  }
276 
277  bs::AnimationClipState state;
278  if(!animated.Animation->GetInternal()->getState(
279  animation._LoadedAnimation->GetInternal(), state)) {
280 
281  // Not playing currently. setState will begin playback, fill the extra info
282  // Is this needed?
283  state = bs::AnimationClipState();
284  // state.layer = static_cast<uint32_t>(animationIndex);
285  state.time = 0.f;
286  }
287 
288  // TODO: if animations are removed the indexes need fixing up. Probably needs
289  // to switch to a dynamic numbering scheme
290 
291  // getState doesn't return the correct layer so this is always applied
292  state.layer = static_cast<uint32_t>(animationIndex);
293 
294  state.speed = animation.SpeedFactor;
295  state.stopped = animation.Paused;
296  state.wrapMode =
297  animation.Loop ? bs::AnimWrapMode::Loop : bs::AnimWrapMode::Clamp;
298 
299  animated.Animation->GetInternal()->setState(
300  animation._LoadedAnimation->GetInternal(), state);
301  }
302 
303  // Then disable other animations
304  for(uint32_t i = 0; i < animated.Animation->GetInternal()->getNumClips(); ++i) {
305 
306  bool found = false;
307  auto clip = animated.Animation->GetInternal()->getClip(i);
308 
309  for(const auto& animation : animated.Animations) {
310  if(animation._LoadedAnimation->GetInternal() == clip) {
311  found = true;
312  break;
313  }
314  }
315 
316  if(!found) {
317  LOG_WRITE("TODO: animation stopping for AnimationSystem");
318  }
319  }
320  }
321  }
322 }
#define LOG_ERROR(x)
Definition: Define.h:92
ObjectAnimationHandler::pointer Animation
Created animation component for this entity.
Definition: Components.h:305
DLLEXPORT bs::HAnimationClip LoadAnimationClipByName(const std::string &name)
Works the same as LoadShaderByName.
Definition: Graphics.cpp:627
#define LOG_WRITE(x)
Definition: Define.h:93
Graphics * GetGraphics()
Definition: Engine.h:185
Entity plays animations on an Ogre::Item.
Definition: Components.h:296
static DLLEXPORT Engine * Get()
Definition: Engine.cpp:86
unsigned int uint32_t
Definition: core.h:40
std::vector< SimpleAnimation > Animations
Definition: Components.h:310

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