Skip to content

Commit

Permalink
refactor: rename Frame to BoneFrame, move inside timeline package
Browse files Browse the repository at this point in the history
  • Loading branch information
yusshu committed Oct 9, 2023
1 parent 362ba61 commit 227b984
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import team.unnamed.creative.base.Vector3Float;
import team.unnamed.hephaestus.Bone;
import team.unnamed.hephaestus.animation.Animation;
import team.unnamed.hephaestus.animation.Frame;
import team.unnamed.hephaestus.animation.timeline.BoneFrame;
import team.unnamed.hephaestus.animation.timeline.BoneTimeline;
import team.unnamed.hephaestus.util.Quaternion;
import team.unnamed.hephaestus.util.Vectors;
Expand All @@ -46,7 +46,7 @@ class NormalAnimationController implements AnimationController {

private final Map<String, BoneTimeline.StateIterator> iterators = new HashMap<>();

private final Map<String, Frame> lastFrames = new HashMap<>();
private final Map<String, BoneFrame> lastFrames = new HashMap<>();

// Reference to the animation currently being played
private @Nullable Animation currentAnimation;
Expand All @@ -69,11 +69,11 @@ public synchronized void queue(Animation animation, int transitionTicks) {
Map<String, BoneTimeline> boneTimelines = new HashMap<>();
Animation transitionAnimation = Animation.animation("$transition", transitionTicks, Animation.LoopMode.HOLD, boneTimelines);

lastFrames.forEach((boneName, frame) -> {
lastFrames.forEach((boneName, boneFrame) -> {
BoneTimeline timeline = BoneTimeline.create();
timeline.positions().put(0, frame.position());
timeline.rotations().put(0, frame.rotation());
timeline.scales().put(0, frame.scale());
timeline.positions().put(0, boneFrame.position());
timeline.rotations().put(0, boneFrame.rotation());
timeline.scales().put(0, boneFrame.scale());
boneTimelines.put(boneName, timeline);
});

Expand Down Expand Up @@ -103,9 +103,9 @@ private void tickBone(
BaseBoneView boneView = view.bone(bone.name());
assert boneView != null;

Frame frame = nextFrame(bone.name());
Vector3Float framePosition = frame.position();
Vector3Float frameRotation = frame.rotation();
BoneFrame boneFrame = nextFrame(bone.name());
Vector3Float framePosition = boneFrame.position();
Vector3Float frameRotation = boneFrame.rotation();

Vector3Float defaultPosition = bone.position();
Vector3Float defaultRotation = bone.rotation();
Expand Down Expand Up @@ -159,7 +159,7 @@ private void createIterators(Animation animation) {
animation.timelines().forEach((name, list) -> iterators.put(name, list.iterator()));
}

private Frame nextFrame(String boneName) {
private BoneFrame nextFrame(String boneName) {

if (currentAnimation == null) {
// if no animation currently being played,
Expand All @@ -175,8 +175,8 @@ private Frame nextFrame(String boneName) {
BoneTimeline.StateIterator iterator = iterators.get(boneName);

if (iterator != null) {
Frame frame = iterator.next();
lastFrames.put(boneName, frame);
BoneFrame boneFrame = iterator.next();
lastFrames.put(boneName, boneFrame);

if (iterator.tick() >= currentAnimation.length()) {
// animation ended!
Expand All @@ -186,22 +186,22 @@ private Frame nextFrame(String boneName) {
// animation ended, lastFrames are removed
// so that next calls will return INITIAL
lastFrames.remove(boneName);
return frame;
return boneFrame;
case LOOP:
createIterators(currentAnimation);
return frame;
return boneFrame;
case HOLD:
nextAnimation();
return frame;
return boneFrame;
}
}
}

return fallback(boneName);
}

private Frame fallback(String boneName) {
return lastFrames.getOrDefault(boneName, Frame.INITIAL);
private BoneFrame fallback(String boneName) {
return lastFrames.getOrDefault(boneName, BoneFrame.INITIAL);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.hephaestus.animation;
package team.unnamed.hephaestus.animation.timeline;

import net.kyori.examination.Examinable;
import net.kyori.examination.ExaminableProperty;
Expand All @@ -32,9 +32,9 @@
import java.util.Objects;
import java.util.stream.Stream;

public final class Frame implements Examinable {
public final class BoneFrame implements Examinable {

public static final Frame INITIAL = new Frame(
public static final BoneFrame INITIAL = new BoneFrame(
Vector3Float.ZERO,
Vector3Float.ZERO,
Vector3Float.ONE
Expand All @@ -44,7 +44,7 @@ public final class Frame implements Examinable {
private final Vector3Float rotation;
private final Vector3Float scale;

public Frame(
public BoneFrame(
Vector3Float position,
Vector3Float rotation,
Vector3Float scale
Expand Down Expand Up @@ -79,10 +79,10 @@ public Vector3Float scale() {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Frame frame = (Frame) o;
return position.equals(frame.position)
&& rotation.equals(frame.rotation)
&& scale.equals(frame.scale);
BoneFrame boneFrame = (BoneFrame) o;
return position.equals(boneFrame.position)
&& rotation.equals(boneFrame.rotation)
&& scale.equals(boneFrame.scale);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package team.unnamed.hephaestus.animation.timeline;

import team.unnamed.creative.base.Vector3Float;
import team.unnamed.hephaestus.animation.Frame;

/**
*
Expand Down Expand Up @@ -75,9 +74,9 @@ public int tick() {
return tick;
}

public Frame next() {
public BoneFrame next() {
tick++;
return new Frame(
return new BoneFrame(
positions.next(),
rotations.next(),
scales.next()
Expand Down

0 comments on commit 227b984

Please sign in to comment.