|
9 | 9 | #include "util/Angle.h" |
10 | 10 | #include "subsystem/MeshSystem.h" |
11 | 11 |
|
| 12 | +#include <functional> |
| 13 | +#include <unordered_set> |
| 14 | + |
12 | 15 | using namespace Supernova; |
13 | 16 |
|
14 | 17 |
|
@@ -959,190 +962,245 @@ void ActionSystem::actionStateChange(Entity entity, ActionComponent& action){ |
959 | 962 | } |
960 | 963 | } |
961 | 964 |
|
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); |
965 | 970 | } |
966 | 971 |
|
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); |
971 | 978 |
|
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 | + } |
974 | 983 |
|
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); |
977 | 987 |
|
978 | | - actionStateChange(entity, action); |
| 988 | + if (targetSignature.test(scene->getComponentId<InstancedMeshComponent>())){ |
| 989 | + InstancedMeshComponent& instmesh = scene->getComponent<InstancedMeshComponent>(action.target); |
979 | 990 |
|
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; |
983 | 999 | } |
984 | 1000 | } |
985 | 1001 |
|
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); |
990 | 1005 |
|
991 | | - actionStateChange(actions->getEntity(i), action); |
| 1006 | + keyframeUpdate(dt, action, keyframe); |
| 1007 | + if (action.state != ActionState::Running) return; |
992 | 1008 |
|
993 | | - // Action update |
994 | | - if (action.state == ActionState::Running){ |
| 1009 | + if (signature.test(scene->getComponentId<TranslateTracksComponent>())){ |
| 1010 | + TranslateTracksComponent& translatetracks = scene->getComponent<TranslateTracksComponent>(entity); |
995 | 1011 |
|
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); |
1001 | 1016 | } |
| 1017 | + } |
1002 | 1018 |
|
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); |
1009 | 1021 |
|
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); |
1013 | 1026 | } |
| 1027 | + } |
1014 | 1028 |
|
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); |
1018 | 1031 |
|
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); |
1021 | 1034 |
|
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 | + } |
1027 | 1038 |
|
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); |
1031 | 1046 | } |
| 1047 | + } |
| 1048 | + } |
1032 | 1049 |
|
1033 | | - //keyframe animation |
1034 | | - if (signature.test(scene->getComponentId<KeyframeTracksComponent>())){ |
1035 | | - KeyframeTracksComponent& keyframe = scene->getComponent<KeyframeTracksComponent>(entity); |
1036 | 1050 |
|
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); |
1039 | 1053 |
|
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; |
1042 | 1056 |
|
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); |
1045 | 1060 |
|
1046 | | - translateTracksUpdate(keyframe, translatetracks, transform); |
1047 | | - } |
1048 | | - } |
| 1061 | + if (signature.test(scene->getComponentId<PositionActionComponent>())){ |
| 1062 | + PositionActionComponent& posaction = scene->getComponent<PositionActionComponent>(entity); |
1049 | 1063 |
|
1050 | | - if (signature.test(scene->getComponentId<RotateTracksComponent>())){ |
1051 | | - RotateTracksComponent& rotatetracks = scene->getComponent<RotateTracksComponent>(entity); |
| 1064 | + positionActionUpdate(dt, action, timedaction, posaction, transform); |
| 1065 | + } |
1052 | 1066 |
|
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); |
1055 | 1069 |
|
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); |
1059 | 1075 |
|
1060 | | - if (signature.test(scene->getComponentId<ScaleTracksComponent>())){ |
1061 | | - ScaleTracksComponent& scaletracks = scene->getComponent<ScaleTracksComponent>(entity); |
| 1076 | + scaleActionUpdate(dt, action, timedaction, scaleaction, transform); |
| 1077 | + } |
| 1078 | + } |
1062 | 1079 |
|
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); |
1065 | 1083 |
|
1066 | | - scaleTracksUpdate(keyframe, scaletracks, transform); |
1067 | | - } |
1068 | | - } |
| 1084 | + if (targetSignature.test(scene->getComponentId<MeshComponent>())){ |
| 1085 | + MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target); |
1069 | 1086 |
|
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); |
1072 | 1091 |
|
1073 | | - if (targetSignature.test(scene->getComponentId<MeshComponent>())){ |
1074 | | - MeshComponent& mesh = scene->getComponent<MeshComponent>(action.target); |
| 1092 | + colorActionUIUpdate(dt, action, timedaction, coloraction, ui); |
| 1093 | + } |
| 1094 | + } |
1075 | 1095 |
|
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); |
1079 | 1104 | } |
| 1105 | + if (targetSignature.test(scene->getComponentId<UIComponent>())){ |
| 1106 | + UIComponent& ui = scene->getComponent<UIComponent>(action.target); |
1080 | 1107 |
|
| 1108 | + alphaActionUIUpdate(dt, action, timedaction, alphaaction, ui); |
| 1109 | + } |
| 1110 | + } |
1081 | 1111 |
|
1082 | | - if (signature.test(scene->getComponentId<TimedActionComponent>())){ |
1083 | | - TimedActionComponent& timedaction = scene->getComponent<TimedActionComponent>(entity); |
| 1112 | + } |
1084 | 1113 |
|
1085 | | - timedActionUpdate(dt, entity, action, timedaction); |
1086 | | - if (action.state != ActionState::Running) continue; |
| 1114 | + actionUpdate(dt, action); |
| 1115 | +} |
1087 | 1116 |
|
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; |
1091 | 1119 |
|
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 | + } |
1094 | 1127 |
|
1095 | | - positionActionUpdate(dt, action, timedaction, posaction, transform); |
1096 | | - } |
| 1128 | + AnimationComponent& animcomp = scene->getComponent<AnimationComponent>(animationEntity); |
| 1129 | + ActionComponent& action = scene->getComponent<ActionComponent>(animationEntity); |
1097 | 1130 |
|
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 | + } |
1100 | 1135 |
|
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 | + } |
1103 | 1141 |
|
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 | + } |
1106 | 1146 |
|
1107 | | - scaleActionUpdate(dt, action, timedaction, scaleaction, transform); |
1108 | | - } |
1109 | | - } |
| 1147 | + ActionComponent& childAction = scene->getComponent<ActionComponent>(childEntity); |
| 1148 | + actionStateChange(childEntity, childAction); |
1110 | 1149 |
|
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 | + } |
1114 | 1153 |
|
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 | + } |
1117 | 1160 |
|
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 | + }; |
1122 | 1165 |
|
1123 | | - colorActionUIUpdate(dt, action, timedaction, coloraction, ui); |
1124 | | - } |
1125 | | - } |
| 1166 | + previewAnimation(entity); |
| 1167 | +} |
1126 | 1168 |
|
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 | + } |
1130 | 1173 |
|
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); |
1133 | 1181 |
|
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); |
1138 | 1184 |
|
1139 | | - alphaActionUIUpdate(dt, action, timedaction, alphaaction, ui); |
1140 | | - } |
1141 | | - } |
| 1185 | + actionStateChange(entity, action); |
1142 | 1186 |
|
| 1187 | + if (action.state == ActionState::Running){ |
| 1188 | + animationUpdate(dt, entity, action, animcomp); |
1143 | 1189 | } |
| 1190 | + } |
| 1191 | + } |
1144 | 1192 |
|
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); |
1146 | 1204 | } |
1147 | 1205 |
|
1148 | 1206 | } |
|
0 commit comments