Skip to content

Commit ac14a97

Browse files
committed
Created updateAnimationPreview for ActionSystem
1 parent 79fd282 commit ac14a97

2 files changed

Lines changed: 189 additions & 127 deletions

File tree

engine/core/subsystem/ActionSystem.cpp

Lines changed: 185 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "util/Angle.h"
1010
#include "subsystem/MeshSystem.h"
1111

12+
#include <functional>
13+
#include <unordered_set>
14+
1215
using namespace Supernova;
1316

1417

@@ -959,190 +962,245 @@ void ActionSystem::actionStateChange(Entity entity, ActionComponent& action){
959962
}
960963
}
961964

962-
void ActionSystem::update(double dt){
963-
if (paused) {
964-
return;
965+
void ActionSystem::processRunningAction(double dt, Entity entity, ActionComponent& action){
966+
Signature signature = scene->getSignature(entity);
967+
Signature targetSignature;
968+
if (action.target != NULL_ENTITY){
969+
targetSignature = scene->getSignature(action.target);
965970
}
966971

967-
//Animations actions
968-
auto animations = scene->getComponentArray<AnimationComponent>();
969-
for (int i = 0; i < animations->size(); i++){
970-
AnimationComponent& animcomp = animations->getComponentFromIndex(i);
972+
//Sprite animation
973+
if (signature.test(scene->getComponentId<SpriteAnimationComponent>())){
974+
SpriteAnimationComponent& spriteanim = scene->getComponent<SpriteAnimationComponent>(entity);
975+
if (targetSignature.test(scene->getComponentId<SpriteComponent>()) && targetSignature.test(scene->getComponentId<MeshComponent>())){
976+
SpriteComponent& sprite = scene->getComponent<SpriteComponent>(action.target);
977+
MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target);
971978

972-
Entity entity = animations->getEntity(i);
973-
Signature signature = scene->getSignature(entity);
979+
spriteActionUpdate(dt, entity, action, mesh, sprite, spriteanim);
980+
if (action.state != ActionState::Running) return;
981+
}
982+
}
974983

975-
if (signature.test(scene->getComponentId<ActionComponent>())){
976-
ActionComponent& action = scene->getComponent<ActionComponent>(entity);
984+
//Particles
985+
if (signature.test(scene->getComponentId<ParticlesComponent>())){
986+
ParticlesComponent& particles = scene->getComponent<ParticlesComponent>(entity);
977987

978-
actionStateChange(entity, action);
988+
if (targetSignature.test(scene->getComponentId<InstancedMeshComponent>())){
989+
InstancedMeshComponent& instmesh = scene->getComponent<InstancedMeshComponent>(action.target);
979990

980-
if (action.state == ActionState::Running){
981-
animationUpdate(dt, entity, action, animcomp);
982-
}
991+
particlesActionUpdate(dt, entity, action.target, action, particles, instmesh);
992+
if (action.state != ActionState::Running) return;
993+
}
994+
if (targetSignature.test(scene->getComponentId<PointsComponent>())){
995+
PointsComponent& points = scene->getComponent<PointsComponent>(action.target);
996+
997+
particlesActionUpdate(dt, entity, action.target, action, particles, points);
998+
if (action.state != ActionState::Running) return;
983999
}
9841000
}
9851001

986-
//All actions
987-
auto actions = scene->getComponentArray<ActionComponent>();
988-
for (int i = 0; i < actions->size(); i++){
989-
ActionComponent& action = actions->getComponentFromIndex(i);
1002+
//keyframe animation
1003+
if (signature.test(scene->getComponentId<KeyframeTracksComponent>())){
1004+
KeyframeTracksComponent& keyframe = scene->getComponent<KeyframeTracksComponent>(entity);
9901005

991-
actionStateChange(actions->getEntity(i), action);
1006+
keyframeUpdate(dt, action, keyframe);
1007+
if (action.state != ActionState::Running) return;
9921008

993-
// Action update
994-
if (action.state == ActionState::Running){
1009+
if (signature.test(scene->getComponentId<TranslateTracksComponent>())){
1010+
TranslateTracksComponent& translatetracks = scene->getComponent<TranslateTracksComponent>(entity);
9951011

996-
Entity entity = actions->getEntity(i);
997-
Signature signature = scene->getSignature(entity);
998-
Signature targetSignature;
999-
if (action.target != NULL_ENTITY){
1000-
targetSignature = scene->getSignature(action.target);
1012+
if (targetSignature.test(scene->getComponentId<Transform>())){
1013+
Transform& transform = scene->getComponent<Transform>(action.target);
1014+
1015+
translateTracksUpdate(keyframe, translatetracks, transform);
10011016
}
1017+
}
10021018

1003-
//Sprite animation
1004-
if (signature.test(scene->getComponentId<SpriteAnimationComponent>())){
1005-
SpriteAnimationComponent& spriteanim = scene->getComponent<SpriteAnimationComponent>(entity);
1006-
if (targetSignature.test(scene->getComponentId<SpriteComponent>()) && targetSignature.test(scene->getComponentId<MeshComponent>())){
1007-
SpriteComponent& sprite = scene->getComponent<SpriteComponent>(action.target);
1008-
MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target);
1019+
if (signature.test(scene->getComponentId<RotateTracksComponent>())){
1020+
RotateTracksComponent& rotatetracks = scene->getComponent<RotateTracksComponent>(entity);
10091021

1010-
spriteActionUpdate(dt, entity, action, mesh, sprite, spriteanim);
1011-
if (action.state != ActionState::Running) continue;
1012-
}
1022+
if (targetSignature.test(scene->getComponentId<Transform>())){
1023+
Transform& transform = scene->getComponent<Transform>(action.target);
1024+
1025+
rotateTracksUpdate(keyframe, rotatetracks, transform);
10131026
}
1027+
}
10141028

1015-
//Particles
1016-
if (signature.test(scene->getComponentId<ParticlesComponent>())){
1017-
ParticlesComponent& particles = scene->getComponent<ParticlesComponent>(entity);
1029+
if (signature.test(scene->getComponentId<ScaleTracksComponent>())){
1030+
ScaleTracksComponent& scaletracks = scene->getComponent<ScaleTracksComponent>(entity);
10181031

1019-
if (targetSignature.test(scene->getComponentId<InstancedMeshComponent>())){
1020-
InstancedMeshComponent& instmesh = scene->getComponent<InstancedMeshComponent>(action.target);
1032+
if (targetSignature.test(scene->getComponentId<Transform>())){
1033+
Transform& transform = scene->getComponent<Transform>(action.target);
10211034

1022-
particlesActionUpdate(dt, entity, action.target, action, particles, instmesh);
1023-
if (action.state != ActionState::Running) continue;
1024-
}
1025-
if (targetSignature.test(scene->getComponentId<PointsComponent>())){
1026-
PointsComponent& points = scene->getComponent<PointsComponent>(action.target);
1035+
scaleTracksUpdate(keyframe, scaletracks, transform);
1036+
}
1037+
}
10271038

1028-
particlesActionUpdate(dt, entity, action.target, action, particles, points);
1029-
if (action.state != ActionState::Running) continue;
1030-
}
1039+
if (signature.test(scene->getComponentId<MorphTracksComponent>())){
1040+
MorphTracksComponent& morpthtracks = scene->getComponent<MorphTracksComponent>(entity);
1041+
1042+
if (targetSignature.test(scene->getComponentId<MeshComponent>())){
1043+
MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target);
1044+
1045+
morphTracksUpdate(keyframe, morpthtracks, mesh);
10311046
}
1047+
}
1048+
}
10321049

1033-
//keyframe animation
1034-
if (signature.test(scene->getComponentId<KeyframeTracksComponent>())){
1035-
KeyframeTracksComponent& keyframe = scene->getComponent<KeyframeTracksComponent>(entity);
10361050

1037-
keyframeUpdate(dt, action, keyframe);
1038-
if (action.state != ActionState::Running) continue;
1051+
if (signature.test(scene->getComponentId<TimedActionComponent>())){
1052+
TimedActionComponent& timedaction = scene->getComponent<TimedActionComponent>(entity);
10391053

1040-
if (signature.test(scene->getComponentId<TranslateTracksComponent>())){
1041-
TranslateTracksComponent& translatetracks = scene->getComponent<TranslateTracksComponent>(entity);
1054+
timedActionUpdate(dt, entity, action, timedaction);
1055+
if (action.state != ActionState::Running) return;
10421056

1043-
if (targetSignature.test(scene->getComponentId<Transform>())){
1044-
Transform& transform = scene->getComponent<Transform>(action.target);
1057+
//Transform animation
1058+
if (targetSignature.test(scene->getComponentId<Transform>())){
1059+
Transform& transform = scene->getComponent<Transform>(action.target);
10451060

1046-
translateTracksUpdate(keyframe, translatetracks, transform);
1047-
}
1048-
}
1061+
if (signature.test(scene->getComponentId<PositionActionComponent>())){
1062+
PositionActionComponent& posaction = scene->getComponent<PositionActionComponent>(entity);
10491063

1050-
if (signature.test(scene->getComponentId<RotateTracksComponent>())){
1051-
RotateTracksComponent& rotatetracks = scene->getComponent<RotateTracksComponent>(entity);
1064+
positionActionUpdate(dt, action, timedaction, posaction, transform);
1065+
}
10521066

1053-
if (targetSignature.test(scene->getComponentId<Transform>())){
1054-
Transform& transform = scene->getComponent<Transform>(action.target);
1067+
if (signature.test(scene->getComponentId<RotationActionComponent>())){
1068+
RotationActionComponent& rotaction = scene->getComponent<RotationActionComponent>(entity);
10551069

1056-
rotateTracksUpdate(keyframe, rotatetracks, transform);
1057-
}
1058-
}
1070+
rotationActionUpdate(dt, action, timedaction, rotaction, transform);
1071+
}
1072+
1073+
if (signature.test(scene->getComponentId<ScaleActionComponent>())){
1074+
ScaleActionComponent& scaleaction = scene->getComponent<ScaleActionComponent>(entity);
10591075

1060-
if (signature.test(scene->getComponentId<ScaleTracksComponent>())){
1061-
ScaleTracksComponent& scaletracks = scene->getComponent<ScaleTracksComponent>(entity);
1076+
scaleActionUpdate(dt, action, timedaction, scaleaction, transform);
1077+
}
1078+
}
10621079

1063-
if (targetSignature.test(scene->getComponentId<Transform>())){
1064-
Transform& transform = scene->getComponent<Transform>(action.target);
1080+
//Color animation
1081+
if (signature.test(scene->getComponentId<ColorActionComponent>())){
1082+
ColorActionComponent& coloraction = scene->getComponent<ColorActionComponent>(entity);
10651083

1066-
scaleTracksUpdate(keyframe, scaletracks, transform);
1067-
}
1068-
}
1084+
if (targetSignature.test(scene->getComponentId<MeshComponent>())){
1085+
MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target);
10691086

1070-
if (signature.test(scene->getComponentId<MorphTracksComponent>())){
1071-
MorphTracksComponent& morpthtracks = scene->getComponent<MorphTracksComponent>(entity);
1087+
colorActionMeshUpdate(dt, action, timedaction, coloraction, mesh);
1088+
}
1089+
if (targetSignature.test(scene->getComponentId<UIComponent>())){
1090+
UIComponent& ui = scene->getComponent<UIComponent>(action.target);
10721091

1073-
if (targetSignature.test(scene->getComponentId<MeshComponent>())){
1074-
MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target);
1092+
colorActionUIUpdate(dt, action, timedaction, coloraction, ui);
1093+
}
1094+
}
10751095

1076-
morphTracksUpdate(keyframe, morpthtracks, mesh);
1077-
}
1078-
}
1096+
//Alpha animation
1097+
if (signature.test(scene->getComponentId<AlphaActionComponent>())){
1098+
AlphaActionComponent& alphaaction = scene->getComponent<AlphaActionComponent>(entity);
1099+
1100+
if (targetSignature.test(scene->getComponentId<MeshComponent>())){
1101+
MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target);
1102+
1103+
alphaActionMeshUpdate(dt, action, timedaction, alphaaction, mesh);
10791104
}
1105+
if (targetSignature.test(scene->getComponentId<UIComponent>())){
1106+
UIComponent& ui = scene->getComponent<UIComponent>(action.target);
10801107

1108+
alphaActionUIUpdate(dt, action, timedaction, alphaaction, ui);
1109+
}
1110+
}
10811111

1082-
if (signature.test(scene->getComponentId<TimedActionComponent>())){
1083-
TimedActionComponent& timedaction = scene->getComponent<TimedActionComponent>(entity);
1112+
}
10841113

1085-
timedActionUpdate(dt, entity, action, timedaction);
1086-
if (action.state != ActionState::Running) continue;
1114+
actionUpdate(dt, action);
1115+
}
10871116

1088-
//Transform animation
1089-
if (targetSignature.test(scene->getComponentId<Transform>())){
1090-
Transform& transform = scene->getComponent<Transform>(action.target);
1117+
void ActionSystem::updateAnimationPreview(double dt, Entity entity){
1118+
std::unordered_set<Entity> visitedAnimations;
10911119

1092-
if (signature.test(scene->getComponentId<PositionActionComponent>())){
1093-
PositionActionComponent& posaction = scene->getComponent<PositionActionComponent>(entity);
1120+
std::function<void(Entity)> previewAnimation = [&](Entity animationEntity) {
1121+
Signature signature = scene->getSignature(animationEntity);
1122+
if (!signature.test(scene->getComponentId<AnimationComponent>()) ||
1123+
!signature.test(scene->getComponentId<ActionComponent>()) ||
1124+
!visitedAnimations.insert(animationEntity).second) {
1125+
return;
1126+
}
10941127

1095-
positionActionUpdate(dt, action, timedaction, posaction, transform);
1096-
}
1128+
AnimationComponent& animcomp = scene->getComponent<AnimationComponent>(animationEntity);
1129+
ActionComponent& action = scene->getComponent<ActionComponent>(animationEntity);
10971130

1098-
if (signature.test(scene->getComponentId<RotationActionComponent>())){
1099-
RotationActionComponent& rotaction = scene->getComponent<RotationActionComponent>(entity);
1131+
actionStateChange(animationEntity, action);
1132+
if (action.state == ActionState::Running){
1133+
animationUpdate(dt, animationEntity, action, animcomp);
1134+
}
11001135

1101-
rotationActionUpdate(dt, action, timedaction, rotaction, transform);
1102-
}
1136+
for (int i = 0; i < (int)animcomp.actions.size(); i++){
1137+
Entity childEntity = animcomp.actions[i].action;
1138+
if (childEntity == NULL_ENTITY || !scene->isEntityCreated(childEntity)) {
1139+
continue;
1140+
}
11031141

1104-
if (signature.test(scene->getComponentId<ScaleActionComponent>())){
1105-
ScaleActionComponent& scaleaction = scene->getComponent<ScaleActionComponent>(entity);
1142+
Signature childSig = scene->getSignature(childEntity);
1143+
if (!childSig.test(scene->getComponentId<ActionComponent>())) {
1144+
continue;
1145+
}
11061146

1107-
scaleActionUpdate(dt, action, timedaction, scaleaction, transform);
1108-
}
1109-
}
1147+
ActionComponent& childAction = scene->getComponent<ActionComponent>(childEntity);
1148+
actionStateChange(childEntity, childAction);
11101149

1111-
//Color animation
1112-
if (signature.test(scene->getComponentId<ColorActionComponent>())){
1113-
ColorActionComponent& coloraction = scene->getComponent<ColorActionComponent>(entity);
1150+
if (childAction.state != ActionState::Running) {
1151+
continue;
1152+
}
11141153

1115-
if (targetSignature.test(scene->getComponentId<MeshComponent>())){
1116-
MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target);
1154+
if (childSig.test(scene->getComponentId<AnimationComponent>())) {
1155+
previewAnimation(childEntity);
1156+
} else {
1157+
processRunningAction(dt, childEntity, childAction);
1158+
}
1159+
}
11171160

1118-
colorActionMeshUpdate(dt, action, timedaction, coloraction, mesh);
1119-
}
1120-
if (targetSignature.test(scene->getComponentId<UIComponent>())){
1121-
UIComponent& ui = scene->getComponent<UIComponent>(action.target);
1161+
if (action.state == ActionState::Running){
1162+
actionUpdate(dt, action);
1163+
}
1164+
};
11221165

1123-
colorActionUIUpdate(dt, action, timedaction, coloraction, ui);
1124-
}
1125-
}
1166+
previewAnimation(entity);
1167+
}
11261168

1127-
//Alpha animation
1128-
if (signature.test(scene->getComponentId<AlphaActionComponent>())){
1129-
AlphaActionComponent& alphaaction = scene->getComponent<AlphaActionComponent>(entity);
1169+
void ActionSystem::update(double dt){
1170+
if (paused) {
1171+
return;
1172+
}
11301173

1131-
if (targetSignature.test(scene->getComponentId<MeshComponent>())){
1132-
MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target);
1174+
//Animations actions
1175+
auto animations = scene->getComponentArray<AnimationComponent>();
1176+
for (int i = 0; i < animations->size(); i++){
1177+
AnimationComponent& animcomp = animations->getComponentFromIndex(i);
1178+
1179+
Entity entity = animations->getEntity(i);
1180+
Signature signature = scene->getSignature(entity);
11331181

1134-
alphaActionMeshUpdate(dt, action, timedaction, alphaaction, mesh);
1135-
}
1136-
if (targetSignature.test(scene->getComponentId<UIComponent>())){
1137-
UIComponent& ui = scene->getComponent<UIComponent>(action.target);
1182+
if (signature.test(scene->getComponentId<ActionComponent>())){
1183+
ActionComponent& action = scene->getComponent<ActionComponent>(entity);
11381184

1139-
alphaActionUIUpdate(dt, action, timedaction, alphaaction, ui);
1140-
}
1141-
}
1185+
actionStateChange(entity, action);
11421186

1187+
if (action.state == ActionState::Running){
1188+
animationUpdate(dt, entity, action, animcomp);
11431189
}
1190+
}
1191+
}
11441192

1145-
actionUpdate(dt, action);
1193+
//All actions
1194+
auto actions = scene->getComponentArray<ActionComponent>();
1195+
for (int i = 0; i < actions->size(); i++){
1196+
ActionComponent& action = actions->getComponentFromIndex(i);
1197+
1198+
actionStateChange(actions->getEntity(i), action);
1199+
1200+
// Action update
1201+
if (action.state == ActionState::Running){
1202+
Entity entity = actions->getEntity(i);
1203+
processRunningAction(dt, entity, action);
11461204
}
11471205

11481206
}

engine/core/subsystem/ActionSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ namespace Supernova{
9898
void rotateTracksUpdate(KeyframeTracksComponent& keyframe, RotateTracksComponent& rotatetracks, Transform& transform);
9999
void morphTracksUpdate(KeyframeTracksComponent& keyframe, MorphTracksComponent& morpthtracks, MeshComponent& mesh);
100100

101+
void processRunningAction(double dt, Entity entity, ActionComponent& action);
102+
101103
public:
102104
ActionSystem(Scene* scene);
103105

104106
void actionStart(Entity entity);
105107
void actionStop(Entity entity);
106108
void actionPause(Entity entity);
109+
110+
void updateAnimationPreview(double dt, Entity entity);
107111

108112
void load() override;
109113
void draw() override;

0 commit comments

Comments
 (0)