• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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     /** Playback time. */
47     DEFINE_PROPERTY(float, time, "Playback Time", 0, VALUE(0.0f))
48 
49     // Current repeat loop.
50     DEFINE_PROPERTY(uint32_t, currentLoop, "", CORE_NS::PropertyFlags::IS_HIDDEN, VALUE(0U))
51 
52     // Last known playback state.
53     DEFINE_PROPERTY(AnimationComponent::PlaybackState, state, "", CORE_NS::PropertyFlags::IS_HIDDEN,
54         VALUE(AnimationComponent::PlaybackState::STOP))
55 
56     // Completion flag.
57     DEFINE_PROPERTY(bool, completed, "", CORE_NS::PropertyFlags::IS_HIDDEN, VALUE(false))
58 
59     // Dirty state means the animation need to be updated also at the next frame.
60     DEFINE_PROPERTY(bool, dirty, "", CORE_NS::PropertyFlags::IS_HIDDEN, VALUE(false))
61 
62     /** Additional controls for animation playback. */
63     DEFINE_BITFIELD_PROPERTY(
64         Flags, options, "Options", CORE_NS::PropertyFlags::IS_BITFIELD, VALUE(0), AnimationStateComponent::FlagBits)
65 
66 END_COMPONENT(IAnimationStateComponentManager, AnimationStateComponent, "a590f16c-723d-421e-a9f6-451a4ac49907")
67 #if !defined(IMPLEMENT_MANAGER)
68 CORE3D_END_NAMESPACE()
69 #endif
70 
71 #endif
72