1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #if !defined(ANIMATION_STATE_COMPONENT) || defined(IMPLEMENT_MANAGER)
17 #define ANIMATION_STATE_COMPONENT
18 
19 #if !defined(IMPLEMENT_MANAGER)
20 #include <3d/ecs/components/animation_component.h>
21 #include <base/containers/vector.h>
22 #include <core/ecs/component_struct_macros.h>
23 #include <core/ecs/intf_component_manager.h>
24 #include <core/property/property.h>
25 
26 CORE3D_BEGIN_NAMESPACE()
27 #endif
28 /** Internal state of animation playback. Inteded to be used by the AnimationSystem to track playback state changes. */
29 BEGIN_COMPONENT(IAnimationStateComponentManager, AnimationStateComponent)
30 #if !defined(IMPLEMENT_MANAGER)
31     // A description of a state of track that is animated.
32     struct TrackState {
33         // Target entity.
34         CORE_NS::Entity entity;
35 
36         // Number of frames.
37         size_t length;
38     };
39     /** Playback states for an animation. */
40     enum FlagBits : uint8_t { MANUAL_PROGRESS = 0x01 };
41     using Flags = uint8_t;
42 #endif
43     // Animated entities (matches tracks).
44     DEFINE_PROPERTY(BASE_NS::vector<TrackState>, trackStates, "", CORE_NS::PropertyFlags::IS_HIDDEN, )
45 
46     DEFINE_PROPERTY(AnimationComponent::PlaybackState, state, "", CORE_NS::PropertyFlags::IS_HIDDEN,
47         VALUE(AnimationComponent::PlaybackState::STOP))
48 
49     // Playback time.
50     DEFINE_PROPERTY(float, time, "Playback Time", 0, VALUE(0.0f))
51 
52     // current repeat loop.
53     DEFINE_PROPERTY(uint32_t, currentLoop, "", CORE_NS::PropertyFlags::IS_HIDDEN, VALUE(0U))
54 
55     // Completion flag.
56     DEFINE_PROPERTY(bool, completed, "", CORE_NS::PropertyFlags::IS_HIDDEN, VALUE(false))
57 
58     DEFINE_PROPERTY(bool, dirty, "", CORE_NS::PropertyFlags::IS_HIDDEN, VALUE(false))
59     /** Additional controls for animation playback. */
60     DEFINE_BITFIELD_PROPERTY(
61         Flags, options, "Options", CORE_NS::PropertyFlags::IS_BITFIELD, VALUE(0), AnimationStateComponent::FlagBits)
62 
63 END_COMPONENT(IAnimationStateComponentManager, AnimationStateComponent, "a590f16c-723d-421e-a9f6-451a4ac49907")
64 #if !defined(IMPLEMENT_MANAGER)
65 CORE3D_END_NAMESPACE()
66 #endif
67 
68 #endif
69