Skip to content

Commit

Permalink
ref: better code performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Oct 7, 2024
1 parent 7ecec38 commit 282800b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

public class AnimationRotionCalc {

private final float animationSpeed;
private float step;
private final RotationAxis axis;
private float progress;
private float max;

public AnimationRotionCalc(final Vector3f startPosition, final Vector3f finalPosition,
final float animationSpeed, final RotationAxis axis) {
this.animationSpeed = animationSpeed;
this.step = 0.005f * animationSpeed;
this.axis = axis;
calculateWayAndValues(startPosition, finalPosition);
Expand Down Expand Up @@ -65,7 +63,7 @@ public Quaternion getQuaternion() {

@Override
public int hashCode() {
return Objects.hash(animationSpeed, axis, max, progress, step);
return Objects.hash(axis, max, progress, step);
}

@Override
Expand All @@ -77,9 +75,7 @@ public boolean equals(final Object obj) {
if (getClass() != obj.getClass())
return false;
final AnimationRotionCalc other = (AnimationRotionCalc) obj;
return Float.floatToIntBits(animationSpeed) == Float.floatToIntBits(other.animationSpeed)
&& axis == other.axis
&& Float.floatToIntBits(max) == Float.floatToIntBits(other.max)
return axis == other.axis && Float.floatToIntBits(max) == Float.floatToIntBits(other.max)
&& Float.floatToIntBits(progress) == Float.floatToIntBits(other.progress)
&& Float.floatToIntBits(step) == Float.floatToIntBits(other.step);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

public class AnimationTranslationCalc {

private final float animationSpeed;
private float stepX;
private float stepY;
private float stepZ;
Expand All @@ -23,7 +22,6 @@ public class AnimationTranslationCalc {

public AnimationTranslationCalc(final VectorWrapper startPosition,
final VectorWrapper finalPosition, final float animationSpeed) {
this.animationSpeed = animationSpeed;
this.stepX = 0.005f * animationSpeed;
this.stepY = 0.005f * animationSpeed;
this.stepZ = 0.005f * animationSpeed;
Expand Down Expand Up @@ -89,7 +87,7 @@ public VectorWrapper getTranslation() {

@Override
public int hashCode() {
return Objects.hash(animationSpeed, maxX, maxY, maxZ, progressX, progressY, progressZ);
return Objects.hash(maxX, maxY, maxZ, progressX, progressY, progressZ);
}

@Override
Expand All @@ -101,8 +99,7 @@ public boolean equals(final Object obj) {
if (getClass() != obj.getClass())
return false;
final AnimationTranslationCalc other = (AnimationTranslationCalc) obj;
return Float.floatToIntBits(animationSpeed) == Float.floatToIntBits(other.animationSpeed)
&& Float.floatToIntBits(maxX) == Float.floatToIntBits(other.maxX)
return Float.floatToIntBits(maxX) == Float.floatToIntBits(other.maxX)
&& Float.floatToIntBits(maxY) == Float.floatToIntBits(other.maxY)
&& Float.floatToIntBits(maxZ) == Float.floatToIntBits(other.maxZ)
&& Float.floatToIntBits(progressX) == Float.floatToIntBits(other.progressX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

public class SignalAnimationRotation implements SignalAnimation {

private static float factor = 3.49065f;

private AnimationRotionCalc calc;

private final Predicate<Map<SEProperty, String>> predicate;
private final float animationSpeed;
private final RotationAxis axis;
private final float rotation;
private final VectorWrapper pivot;
private final float finalRotationValue;

public SignalAnimationRotation(final Predicate<Map<SEProperty, String>> predicate,
final float animationSpeed, final RotationAxis axis, final float rotation,
Expand All @@ -28,6 +27,7 @@ public SignalAnimationRotation(final Predicate<Map<SEProperty, String>> predicat
this.axis = axis;
this.rotation = rotation;
this.pivot = pivot;
this.finalRotationValue = rotation * 0.005f * 3.49065f;
}

@Override
Expand All @@ -41,15 +41,15 @@ public void setUpAnimationValues(final ModelTranslation currentTranslation) {
Vector3f maxPos = new Vector3f(0, 0, 0);
switch (axis) {
case X: {
maxPos = new Vector3f(rotation * 0.005f * factor, 0, 0);
maxPos = new Vector3f(finalRotationValue, 0, 0);
break;
}
case Y: {
maxPos = new Vector3f(0, rotation * 0.005f * factor, 0);
maxPos = new Vector3f(0, finalRotationValue, 0);
break;
}
case Z: {
maxPos = new Vector3f(0, 0, rotation * 0.005f * factor);
maxPos = new Vector3f(0, 0, finalRotationValue);
break;
}
default:
Expand All @@ -60,7 +60,7 @@ public void setUpAnimationValues(final ModelTranslation currentTranslation) {

@Override
public ModelTranslation getFinalModelTranslation() {
return new ModelTranslation(pivot, axis.getForAxis(rotation * 0.005f * factor));
return new ModelTranslation(pivot, axis.getForAxis(finalRotationValue));
}

@Override
Expand Down

0 comments on commit 282800b

Please sign in to comment.