CoriEngine
Loading...
Searching...
No Matches
WorldSystem/Systems/Animation.hpp
Go to the documentation of this file.
1#pragma once
2#include "System.hpp"
6
7#ifndef CORI_DISPOSABLE_ANIMATION_POOL_SIZE
8 #define CORI_DISPOSABLE_ANIMATION_POOL_SIZE 32
9#endif
10
11namespace Cori {
12 namespace World {
13 namespace Systems {
17 class Animation final : public System {
18 public:
19 void OnTickUpdate(Core::GameTimer& gameTimer) override;
20
33 std::optional<Entity> PlayAnimation(const glm::vec2 position, const int16_t depth, const glm::vec2 scale, const float rotation, const Graphics::IsAnimationWithParams auto&... sequence) {
34 auto result = m_EntityPool.GetFreeEntity();
35 if (result) {
36 Entity entity = result.value().first;
37 uint16_t index = result.value().second;
39 tr.SetLocalPosition(position);
40 tr.SetLocalDepth(depth);
41 tr.SetLocalScale(scale);
42 tr.SetLocalRotation(rotation);
43
45 qa.Play(std::forward<decltype(sequence)>(sequence)...);
46
47 qa.SetEngineStopCallback([this, index] {
48 m_EntityPool.FreeIndex(index);
49 });
50
51 return entity;
52 }
53
54 CORI_CORE_WARN_TAGGED({ Logger::Tags::World::Self, Logger::Tags::World::Systems::Self, Logger::Tags::World::Systems::Animation }, "Failed to play independent animation, no free entities available.");
55 return std::nullopt;
56 }
57
58 bool Create();
59
60 static constexpr SystemPriority Priority = 200;
61 private:
62 void OnQuadAnimationCreate(entt::registry& registry, entt::entity entity);
63
65 };
66 }
67 }
68}
#define CORI_CORE_WARN_TAGGED(...)
Definition Logger.hpp:1038
A GameTimer is responsible for managing everything that is connected with time, ticks,...
Definition Time.hpp:8
Responsible for playing animations when attached to an entity.
void Play(const Graphics::IsAnimationWithParams auto &... sequence)
Plays a sequence of animations. @detials Animation sequence can be either looped or no,...
Creates a pool with disposable entities.
Entities are the essential part of WorldSystem.
Definition Entity.hpp:25
decltype(auto) GetComponents()
Retries the references to the requested components of the entity.
Definition Entity.hpp:74
System(const System &)=delete
System that is responsible for Animations, every Scene has it by default.
std::optional< Entity > PlayAnimation(const glm::vec2 position, const int16_t depth, const glm::vec2 scale, const float rotation, const Graphics::IsAnimationWithParams auto &... sequence)
Allows you to play animation sequence without having an entity to do so on. Fire and forget style.
void OnTickUpdate(Core::GameTimer &gameTimer) override
uint16_t SystemPriority
Definition Concept.hpp:5
Global engine namespace.
static constexpr char Animation[]
Definition Logger.hpp:139
static constexpr char Self[]
Definition Logger.hpp:137
static constexpr char Self[]
Definition Logger.hpp:119
Every Entity has a transform component by default, essential for rendering.
void SetLocalPosition(const glm::vec2 localPosition)
Changes the local position of the Entity.