Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/base/StarAnimatedPartSet.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2025-06-03 08:03:18 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2025-06-03 08:03:18 +1000
commit4048e211c50af86dc278f13b1b2eb2a9ec00b7bf (patch)
tree02f9be4afceb18d1e947bec7ab85afd4afaae350 /source/base/StarAnimatedPartSet.cpp
parentbb328ef289fc48743d38a3061d854bc65ce84baa (diff)
revert networked animator changes for now
Diffstat (limited to 'source/base/StarAnimatedPartSet.cpp')
-rw-r--r--source/base/StarAnimatedPartSet.cpp127
1 files changed, 8 insertions, 119 deletions
diff --git a/source/base/StarAnimatedPartSet.cpp b/source/base/StarAnimatedPartSet.cpp
index 9b9f9d7..5ffc68f 100644
--- a/source/base/StarAnimatedPartSet.cpp
+++ b/source/base/StarAnimatedPartSet.cpp
@@ -1,12 +1,11 @@
#include "StarAnimatedPartSet.hpp"
#include "StarMathCommon.hpp"
-#include "StarJsonExtra.hpp"
namespace Star {
AnimatedPartSet::AnimatedPartSet() {}
-AnimatedPartSet::AnimatedPartSet(Json config, uint8_t animatorVersion) {
+AnimatedPartSet::AnimatedPartSet(Json config) {
for (auto const& stateTypePair : config.get("stateTypes", JsonObject()).iterateObject()) {
auto const& stateTypeName = stateTypePair.first;
auto const& stateTypeConfig = stateTypePair.second;
@@ -34,7 +33,6 @@ AnimatedPartSet::AnimatedPartSet(Json config, uint8_t animatorVersion) {
newStateType.states.sortByKey();
newStateType.activeState.stateTypeName = stateTypeName;
- newStateType.activeState.reverse = false;
newStateType.activeStateDirty = true;
if (newStateType.defaultState.empty() && !newStateType.states.empty())
@@ -60,23 +58,20 @@ AnimatedPartSet::AnimatedPartSet(Json config, uint8_t animatorVersion) {
for (auto const& partStatePair : partStateTypePair.second.toObject()) {
auto const& stateName = partStatePair.first;
- auto stateConfig = partStatePair.second;
- if ((version() > 0) && stateConfig.isType(Json::Type::String))
- stateConfig = partStatePair.second.get(stateConfig.toString());
+ auto const& stateConfig = partStatePair.second;
PartState partState = {stateConfig.getObject("properties", {}), stateConfig.getObject("frameProperties", {})};
newPart.partStates[stateTypeName][stateName] = std::move(partState);
}
}
newPart.activePart.partName = partPair.first;
- newPart.activePart.setAnimationAffineTransform(Mat3F::identity());
newPart.activePartDirty = true;
m_parts[partName] = std::move(newPart);
}
for (auto const& pair : m_stateTypes)
- setActiveState(pair.first, pair.second.defaultState, true, false);
+ setActiveState(pair.first, pair.second.defaultState, true);
}
StringList AnimatedPartSet::stateTypes() const {
@@ -115,12 +110,11 @@ StringList AnimatedPartSet::partNames() const {
return m_parts.keys();
}
-bool AnimatedPartSet::setActiveState(String const& stateTypeName, String const& stateName, bool alwaysStart, bool reverse) {
+bool AnimatedPartSet::setActiveState(String const& stateTypeName, String const& stateName, bool alwaysStart) {
auto& stateType = m_stateTypes.get(stateTypeName);
- if (stateType.activeState.stateName != stateName || alwaysStart || stateType.activeState.reverse != reverse) {
+ if (stateType.activeState.stateName != stateName || alwaysStart) {
stateType.activeState.stateName = stateName;
stateType.activeState.timer = 0.0f;
- stateType.activeState.frameProgress = 0.0f;
stateType.activeStatePointer = stateType.states.get(stateName).get();
stateType.activeStateDirty = true;
@@ -180,15 +174,11 @@ size_t AnimatedPartSet::activeStateIndex(String const& stateTypeName) const {
auto const& stateType = m_stateTypes.get(stateTypeName);
return *stateType.states.indexOf(stateType.activeState.stateName);
}
-bool AnimatedPartSet::activeStateReverse(String const& stateTypeName) const {
- auto const& stateType = m_stateTypes.get(stateTypeName);
- return stateType.activeState.reverse;
-}
-bool AnimatedPartSet::setActiveStateIndex(String const& stateTypeName, size_t stateIndex, bool alwaysStart, bool reverse) {
+bool AnimatedPartSet::setActiveStateIndex(String const& stateTypeName, size_t stateIndex, bool alwaysStart) {
auto const& stateType = m_stateTypes.get(stateTypeName);
String const& stateName = stateType.states.keyAt(stateIndex);
- return setActiveState(stateTypeName, stateName, alwaysStart, reverse);
+ return setActiveState(stateTypeName, stateName, alwaysStart);
}
void AnimatedPartSet::update(float dt) {
@@ -257,40 +247,15 @@ void AnimatedPartSet::freshenActiveState(StateType& stateType) {
if (stateType.activeStateDirty) {
auto const& state = *stateType.activeStatePointer;
auto& activeState = stateType.activeState;
-
- double progress = (activeState.timer / state.cycle * state.frames);
- activeState.frameProgress = std::fmod(progress, 1);
- activeState.frame = clamp<int>(progress, 0, state.frames - 1);
- if (activeState.reverse) {
- activeState.frame = (state.frames - 1) - activeState.frame;
- if (state.animationMode == Loop)
- if (activeState.frame <= 0 ) {
- activeState.nextFrame = state.frames - 1;
- } else {
- activeState.nextFrame = clamp<int>(activeState.frame - 1, 0, state.frames - 1);
- }
- } else {
- if (state.animationMode == Loop)
- if (activeState.frame >= (state.frames-1) ) {
- activeState.nextFrame = 0;
- } else {
- activeState.nextFrame = clamp<int>(activeState.frame + 1, 0, state.frames - 1);
- }
- }
+ activeState.frame = clamp<int>(activeState.timer / state.cycle * state.frames, 0, state.frames - 1);
activeState.properties = stateType.stateTypeProperties;
activeState.properties.merge(state.stateProperties, true);
- activeState.nextProperties = activeState.properties;
-
for (auto const& pair : state.stateFrameProperties) {
if (activeState.frame < pair.second.size())
activeState.properties[pair.first] = pair.second.get(activeState.frame);
}
- for (auto const& pair : state.stateFrameProperties) {
- if (activeState.nextFrame < pair.second.size())
- activeState.nextProperties[pair.first] = pair.second.get(activeState.nextFrame);
- }
stateType.activeStateDirty = false;
}
@@ -327,56 +292,16 @@ void AnimatedPartSet::freshenActivePart(Part& part) {
freshenActiveState(stateType);
activePart.activeState = stateType.activeState;
unsigned frame = stateType.activeState.frame;
- unsigned nextFrame = stateType.activeState.nextFrame;
// Then set the part state data, as well as any part state frame data if
// the current frame is within the list size.
activePart.properties.merge(partState->partStateProperties, true);
- activePart.nextProperties = activePart.properties;
for (auto const& pair : partState->partStateFrameProperties) {
if (frame < pair.second.size())
activePart.properties[pair.first] = pair.second.get(frame);
}
- for (auto const& pair : partState->partStateFrameProperties) {
- if (nextFrame< pair.second.size())
- activePart.nextProperties[pair.first] = pair.second.get(nextFrame);
- }
- if (version() > 0) {
- auto processTransforms = [](Mat3F mat, JsonArray transforms, JsonObject properties) -> Mat3F {
- for (auto const& v : transforms) {
- auto action = v.getString(0);
- if (action == "reset") {
- mat = Mat3F::identity();
- } else if (action == "translate") {
- mat.translate(jsonToVec2F(v.getArray(1)));
- } else if (action == "rotate") {
- mat.rotate(v.getFloat(1), jsonToVec2F(v.getArray(2, properties.maybe("rotationCenter").value(JsonArray({0,0})).toArray())));
- } else if (action == "scale") {
- mat.scale(jsonToVec2F(v.getArray(1)), jsonToVec2F(v.getArray(2, properties.maybe("scalingCenter").value(JsonArray({0,0})).toArray())));
- } else if (action == "transform") {
- mat = Mat3F(v.getFloat(1), v.getFloat(2), v.getFloat(3), v.getFloat(4), v.getFloat(5), v.getFloat(6), 0, 0, 1) * mat;
- }
- }
- return mat;
- };
-
-
- if (auto transforms = activePart.properties.ptr("transforms")) {
- auto mat = processTransforms(activePart.animationAffineTransform(), transforms->toArray(), activePart.properties);
- if (activePart.properties.maybe("interpolated").value(false)) {
- if (auto nextTransforms = activePart.nextProperties.ptr("transforms")) {
- auto nextMat = processTransforms(activePart.animationAffineTransform(), nextTransforms->toArray(), activePart.nextProperties);
- activePart.setAnimationAffineTransform(mat, nextMat, stateType.activeState.frameProgress);
- } else {
- activePart.setAnimationAffineTransform(mat);
- }
- } else {
- activePart.setAnimationAffineTransform(mat);
- }
- }
- }
// Each part can only have one state type x state match, so we are done.
break;
}
@@ -385,40 +310,4 @@ void AnimatedPartSet::freshenActivePart(Part& part) {
}
}
-void AnimatedPartSet::ActivePartInformation::setAnimationAffineTransform(Mat3F const& matrix) {
- xTranslationAnimation = matrix[0][2];
- yTranslationAnimation = matrix[1][2];
- xScaleAnimation = sqrt(square(matrix[0][0]) + square(matrix[0][1]));
- yScaleAnimation = sqrt(square(matrix[1][0]) + square(matrix[1][1]));
- xShearAnimation = atan2(matrix[0][1], matrix[0][0]);
- yShearAnimation = atan2(matrix[1][0], matrix[1][1]);
-}
-void AnimatedPartSet::ActivePartInformation::setAnimationAffineTransform(Mat3F const& mat1, Mat3F const& mat2, float progress) {
- xTranslationAnimation = mat1[0][2];
- yTranslationAnimation = mat1[1][2];
- xScaleAnimation = sqrt(square(mat1[0][0]) + square(mat1[0][1]));
- yScaleAnimation = sqrt(square(mat1[1][0]) + square(mat1[1][1]));
- xShearAnimation = atan2(mat1[0][1], mat1[0][0]);
- yShearAnimation = atan2(mat1[1][0], mat1[1][1]);
-
- xTranslationAnimation += (mat2[0][2] - xTranslationAnimation) * progress;
- yTranslationAnimation += (mat2[1][2] - yTranslationAnimation) * progress;
- xScaleAnimation += (sqrt(square(mat2[0][0]) + square(mat2[0][1])) - xScaleAnimation) * progress;
- yScaleAnimation += (sqrt(square(mat2[1][0]) + square(mat2[1][1])) - yScaleAnimation) * progress;
- xShearAnimation += (atan2(mat2[0][1], mat2[0][0]) - xShearAnimation) * progress;
- yShearAnimation += (atan2(mat2[1][0], mat2[1][1]) - yShearAnimation) * progress;
-}
-
-Mat3F AnimatedPartSet::ActivePartInformation::animationAffineTransform() const {
- return Mat3F(
- xScaleAnimation * cos(xShearAnimation), xScaleAnimation * sin(xShearAnimation), xTranslationAnimation,
- yScaleAnimation * sin(yShearAnimation), yScaleAnimation * cos(yShearAnimation), yTranslationAnimation,
- 0, 0, 1
- );
-}
-
-uint8_t AnimatedPartSet::version() const {
- return m_animatorVersion;
-}
-
}