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, int tick, int timeintick)
 

Detailed Description

Handles updating time of Ogre animations.

Todo:
This needs to be replaced with an animation system

Definition at line 121 of file Systems.h.

Member Function Documentation

◆ Run()

DLLEXPORT void AnimationSystem::Run ( GameWorld world,
std::unordered_map< ObjectID, Animated * > &  index,
int  tick,
int  timeintick 
)

Definition at line 243 of file Systems.cpp.

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

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