Skip to content

Commit 8641e59

Browse files
committed
Refactor AnimationHelper: Improve operator overloads and clean up code
1 parent c532005 commit 8641e59

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

src/Animation/AnimationHelper.cpp

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "GlobalNamespace/BeatmapCallbacksController.hpp"
22
#include "GlobalNamespace/BeatmapObjectSpawnController.hpp"
3+
#include "GlobalNamespace/StaticBeatmapObjectSpawnMovementData.hpp"
34
#include "GlobalNamespace/BeatmapObjectSpawnMovementData.hpp"
45
#include "custom-json-data/shared/CustomBeatmapData.h"
56
#include "tracks/shared/Animation/PointDefinition.h"
@@ -21,49 +22,47 @@ extern BeatmapCallbacksController* callbackController;
2122
extern BeatmapObjectSpawnController* spawnController;
2223

2324
constexpr std::optional<Vector3> operator+(std::optional<Vector3> const& a, std::optional<Vector3> const& b) {
24-
if (!a && !b) {
25-
return std::nullopt;
25+
if (a && b) {
26+
return *a + *b;
2627
}
27-
28-
Vector3 total = Vector3::zero();
2928
if (a) {
30-
total = total + *a;
29+
return a;
3130
}
3231

3332
if (b) {
34-
total = total + *b;
33+
return b;
3534
}
3635

37-
return total;
36+
return std::nullopt;
3837
}
3938

4039
template <typename T> constexpr std::optional<T> operator*(std::optional<T> const& a, std::optional<T> const& b) {
4140
if (a && b) {
4241
return *a * *b;
43-
} else if (a) {
42+
}
43+
if (a) {
4444
return a;
45-
} else if (b) {
45+
}
46+
if (b) {
4647
return b;
47-
} else {
48+
}
4849
return std::nullopt;
49-
}
50+
5051
}
5152

5253
std::optional<NEVector::Vector3> AnimationHelper::GetDefinitePositionOffset(AnimationObjectData const& animationData,
5354
std::span<TrackW const> tracks,
5455
float time) {
5556
PointDefinitionW localDefinitePosition = animationData.definitePosition;
5657

57-
5858
std::optional<Vector3> pathDefinitePosition =
5959
localDefinitePosition ? std::optional(localDefinitePosition.InterpolateVec3(time)) : std::nullopt;
6060

6161
// track animation only
6262
if (!pathDefinitePosition && !tracks.empty()) {
6363
if (tracks.size() == 1) {
6464
auto track = tracks.front();
65-
pathDefinitePosition =
66-
track.GetPathPropertyNamed(PropertyNames::DefinitePosition).InterpolateVec3(time);
65+
pathDefinitePosition = track.GetPathPropertyNamed(PropertyNames::DefinitePosition).InterpolateVec3(time);
6766
} else {
6867
auto positions = Animation::getPathPropertiesVec3(tracks, PropertyNames::DefinitePosition, time);
6968
pathDefinitePosition = Animation::addVector3s(positions);
@@ -82,16 +81,14 @@ std::optional<NEVector::Vector3> AnimationHelper::GetDefinitePositionOffset(Anim
8281
if (tracks.size() == 1) {
8382
auto track = tracks.front();
8483

85-
if (!pathPosition)
86-
pathPosition = track.GetPathPropertyNamed(PropertyNames::Position).InterpolateVec3(time);
84+
if (!pathPosition) pathPosition = track.GetPathPropertyNamed(PropertyNames::Position).InterpolateVec3(time);
8785

8886
trackPosition = track.GetPropertyNamed(PropertyNames::Position).GetVec3();
8987
} else {
90-
trackPosition = Animation::addVector3s(Animation::getPropertiesVec3(tracks, PropertyNames::Position, {}));
88+
trackPosition = Animation::addVector3s(Animation::getPropertiesVec3(tracks, PropertyNames::Position, TimeUnit()));
9189

9290
if (!pathPosition)
93-
pathPosition =
94-
Animation::addVector3s(Animation::getPathPropertiesVec3(tracks, PropertyNames::Position, time));
91+
pathPosition = Animation::addVector3s(Animation::getPathPropertiesVec3(tracks, PropertyNames::Position, time));
9592
}
9693

9794
positionOffset = pathPosition + trackPosition;
@@ -100,7 +97,11 @@ std::optional<NEVector::Vector3> AnimationHelper::GetDefinitePositionOffset(Anim
10097
}
10198

10299
std::optional<Vector3> definitePosition = positionOffset + pathDefinitePosition;
103-
if (definitePosition) definitePosition = definitePosition.value() * NECaches::get_noteLinesDistanceFast();
100+
101+
if (definitePosition) {
102+
definitePosition =
103+
definitePosition.value() * GlobalNamespace::StaticBeatmapObjectSpawnMovementData::kNoteLinesDistance;
104+
}
104105

105106
if (NECaches::LeftHandedMode) {
106107
definitePosition = Animation::MirrorVectorNullable(definitePosition);
@@ -138,22 +139,16 @@ ObjectOffset AnimationHelper::GetObjectOffset(AnimationObjectData const& animati
138139
auto const track = tracks.front();
139140

140141
// Macros to simplify getter code
141-
if (!pathPosition)
142-
pathPosition = track.GetPathPropertyNamed(PropertyNames::Position).InterpolateVec3(time);
143-
if (!pathRotation)
144-
pathRotation = track.GetPathPropertyNamed(PropertyNames::Rotation).InterpolateQuat(time);
142+
if (!pathPosition) pathPosition = track.GetPathPropertyNamed(PropertyNames::Position).InterpolateVec3(time);
143+
if (!pathRotation) pathRotation = track.GetPathPropertyNamed(PropertyNames::Rotation).InterpolateQuat(time);
145144
if (!pathScale) pathScale = track.GetPathPropertyNamed(PropertyNames::Scale).InterpolateVec3(time);
146145
if (!pathLocalRotation)
147-
pathLocalRotation =
148-
track.GetPathPropertyNamed(PropertyNames::LocalRotation).InterpolateQuat(time);
146+
pathLocalRotation = track.GetPathPropertyNamed(PropertyNames::LocalRotation).InterpolateQuat(time);
149147

150-
if (!pathDissolve)
151-
pathDissolve = track.GetPathPropertyNamed(PropertyNames::Dissolve).InterpolateLinear(time);
148+
if (!pathDissolve) pathDissolve = track.GetPathPropertyNamed(PropertyNames::Dissolve).InterpolateLinear(time);
152149
if (!pathDissolveArrow)
153-
pathDissolveArrow =
154-
track.GetPathPropertyNamed(PropertyNames::DissolveArrow).InterpolateLinear(time);
155-
if (!pathCuttable)
156-
pathCuttable = track.GetPathPropertyNamed(PropertyNames::Cuttable).InterpolateLinear(time);
150+
pathDissolveArrow = track.GetPathPropertyNamed(PropertyNames::DissolveArrow).InterpolateLinear(time);
151+
if (!pathCuttable) pathCuttable = track.GetPathPropertyNamed(PropertyNames::Cuttable).InterpolateLinear(time);
157152

158153
// Combine with track properties
159154
offset.positionOffset = pathPosition + track.GetPropertyNamed(PropertyNames::Position).GetVec3();
@@ -186,8 +181,7 @@ ObjectOffset AnimationHelper::GetObjectOffset(AnimationObjectData const& animati
186181
pathDissolve = Animation::multiplyFloats(dissolvePaths);
187182
}
188183
if (!pathDissolveArrow) {
189-
auto dissolveArrowPaths =
190-
Animation::getPathPropertiesFloat(tracks, PropertyNames::DissolveArrow, time);
184+
auto dissolveArrowPaths = Animation::getPathPropertiesFloat(tracks, PropertyNames::DissolveArrow, time);
191185
pathDissolveArrow = Animation::multiplyFloats(dissolveArrowPaths);
192186
}
193187
if (!pathCuttable) {

0 commit comments

Comments
 (0)