neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
animation_filter.hpp
Go to the documentation of this file.
1// animation_filter.hpp
2/*
3neogfx C++ App/Game Engine
4Copyright (c) 2020 Leigh Johnston. All Rights Reserved.
5
6This program is free software: you can redistribute it and / or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <neolib/core/uuid.hpp>
26
27namespace neogfx::game
28{
30 {
32 std::optional<animation> animation;
33 std::optional<mat44> transformation;
36 std::optional<i64> currentFrameStartTime; // ECS internal
37
39 {
40 static const neolib::uuid& id()
41 {
42 static const neolib::uuid sId = { 0xe876ec93, 0x21b2, 0x410e, 0xbd81, { 0x8c, 0x1d, 0x9, 0xec, 0xbc, 0x45 } };
43 return sId;
44 }
45 static const i_string& name()
46 {
47 static const string sName = "Animation Filter";
48 return sName;
49 }
50 static uint32_t field_count()
51 {
52 return 6;
53 }
54 static component_data_field_type field_type(uint32_t aFieldIndex)
55 {
56 switch (aFieldIndex)
57 {
58 case 0:
59 return component_data_field_type::ComponentData | component_data_field_type::Shared;
60 case 1:
61 return component_data_field_type::ComponentData | component_data_field_type::Optional;
62 case 2:
63 return component_data_field_type::Mat44 | component_data_field_type::Optional;
64 case 3:
65 return component_data_field_type::Uint32;
66 case 4:
67 return component_data_field_type::Bool;
68 case 5:
69 return component_data_field_type::Int64 | component_data_field_type::Internal;
70 default:
71 throw invalid_field_index();
72 }
73 }
74 static neolib::uuid field_type_id(uint32_t aFieldIndex)
75 {
76 switch (aFieldIndex)
77 {
78 case 0:
79 case 1:
80 return animation::meta::id();
81 case 2:
82 case 3:
83 case 4:
84 case 5:
85 return neolib::uuid{};
86 default:
87 throw invalid_field_index();
88 }
89 }
90 static const i_string& field_name(uint32_t aFieldIndex)
91 {
92 static const string sFieldNames[] =
93 {
94 "Shared Animation",
95 "Animation",
96 "Transformation",
97 "Current Frame",
98 "Auto Destroy",
99 "Current Frame Start Time"
100 };
101 return sFieldNames[aFieldIndex];
102 }
103 };
104 };
105
106 inline mesh_filter const& current_animation_frame(animation_filter const& aAnimationFilter)
107 {
108 return aAnimationFilter.animation ?
109 aAnimationFilter.animation->frames[aAnimationFilter.currentFrame].filter :
110 aAnimationFilter.sharedAnimation.ptr->frames[aAnimationFilter.currentFrame].filter;
111 }
112
113 inline mat44 const& to_transformation_matrix(animation_filter const& aAnimationFilter)
114 {
115 return aAnimationFilter.transformation ? *aAnimationFilter.transformation : mat44::identity();
116 }
117}
static const std::enable_if_t< Rows==Columns, SFINAE > & identity()
mesh_filter const & current_animation_frame(animation_filter const &aAnimationFilter)
mat44 const & to_transformation_matrix(animation_filter const &aAnimationFilter)
uint32_t u32
static const neolib::uuid & id()
Definition animation.hpp:98
static const neolib::uuid & id()
static neolib::uuid field_type_id(uint32_t aFieldIndex)
static const i_string & field_name(uint32_t aFieldIndex)
static component_data_field_type field_type(uint32_t aFieldIndex)
std::optional< mat44 > transformation
std::optional< i64 > currentFrameStartTime
std::optional< animation > animation