-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b259765
commit b6f7815
Showing
6 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...n/java/com/trainguy9512/animationoverhaul/animation/pose/function/CachedPoseFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.trainguy9512.animationoverhaul.animation.pose.function; | ||
|
||
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class CachedPoseFunction implements PoseFunction { | ||
@Override | ||
public @NotNull AnimationPose compute(FunctionInterpolationContext context) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void tick(FunctionEvaluationState context) { | ||
|
||
} | ||
} |
29 changes: 25 additions & 4 deletions
29
src/main/java/com/trainguy9512/animationoverhaul/animation/pose/function/PoseFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
package com.trainguy9512.animationoverhaul.animation.pose.function; | ||
|
||
import com.trainguy9512.animationoverhaul.animation.data.OnTickDataContainer; | ||
import com.trainguy9512.animationoverhaul.animation.data.PoseCalculationDataContainer; | ||
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface PoseFunction { | ||
|
||
AnimationPose calculate(PoseFunction.FunctionContext functionContext); | ||
@NotNull AnimationPose compute(PoseFunction.FunctionInterpolationContext context); | ||
|
||
void tick(FunctionEvaluationState evaluationState); | ||
|
||
public record FunctionEvaluationState(OnTickDataContainer dataContainer, boolean isRelevant, boolean shouldReset){ | ||
public static FunctionEvaluationState of(OnTickDataContainer dataContainer, boolean isRelevant, boolean shouldReset){ | ||
return new FunctionEvaluationState(dataContainer, isRelevant, shouldReset); | ||
} | ||
|
||
public FunctionEvaluationState modify(boolean isRelevant, boolean shouldReset){ | ||
return FunctionEvaluationState.of(this.dataContainer, isRelevant, shouldReset); | ||
} | ||
} | ||
|
||
|
||
public interface FunctionContext { | ||
PoseCalculationDataContainer getDataContainer(); | ||
float getPartialTicks(); | ||
public interface FunctionInterpolationContext { | ||
PoseCalculationDataContainer dataContainer(); | ||
float partialTicks(); | ||
} | ||
|
||
|
||
} |
7 changes: 0 additions & 7 deletions
7
...java/com/trainguy9512/animationoverhaul/animation/pose/function/TickablePoseFunction.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...ava/com/trainguy9512/animationoverhaul/animation/pose/function/TimeBasedPoseFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.trainguy9512.animationoverhaul.animation.pose.function; | ||
|
||
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.function.Function; | ||
|
||
public class TimeBasedPoseFunction implements PoseFunction { | ||
|
||
Function<FunctionEvaluationState, Float> playRateFunction; | ||
Function<FunctionEvaluationState, Boolean> isPlayingFunction; | ||
|
||
protected float timeTicksElapsed; | ||
protected float playRate; | ||
protected boolean isPlaying; | ||
|
||
private TimeBasedPoseFunction(){ | ||
this.playRateFunction = (interpolationContext) -> 1f; | ||
this.isPlayingFunction = (interpolationContext) -> true; | ||
this.timeTicksElapsed = 0; | ||
} | ||
|
||
@Override | ||
public @NotNull AnimationPose compute(FunctionInterpolationContext context) { | ||
return AnimationPose.of(context.dataContainer().getJointSkeleton()); | ||
} | ||
|
||
@Override | ||
public void tick(FunctionEvaluationState evaluationState) { | ||
if(evaluationState.isRelevant()){ | ||
this.playRate = playRateFunction.apply(evaluationState); | ||
this.isPlaying = isPlayingFunction.apply(evaluationState); | ||
|
||
if(evaluationState.shouldReset()){ | ||
this.timeTicksElapsed = 0; | ||
} | ||
if(this.isPlaying){ | ||
this.timeTicksElapsed += this.playRate; | ||
} | ||
} | ||
} | ||
|
||
protected float getInterpolatedTimeElapsed(FunctionInterpolationContext context){ | ||
return this.timeTicksElapsed - (1 - context.partialTicks()) * this.playRate; | ||
} | ||
} |