diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java index 24f42d4..c378c94 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java @@ -3,10 +3,10 @@ import com.google.common.collect.Maps; import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; +import com.trainguy9512.animationoverhaul.animation.data.AnimationData; import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerStateContainer; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; import net.minecraft.world.entity.Entity; @@ -16,7 +16,7 @@ public class EntityJointAnimatorDispatcher { public static final EntityJointAnimatorDispatcher INSTANCE = new EntityJointAnimatorDispatcher(); - private final HashMap entityAnimationDataContainerStorage; + private final HashMap entityAnimationDataContainerStorage; private final HashMap entityBakedAnimationPoseStorage; private final HashMap entityPoseSamplerStateContainerStorage; @@ -34,17 +34,17 @@ public void tick(T entity){ JointSkeleton jointSkeleton = entityJointAnimator.getJointSkeleton(); BakedAnimationPose bakedPose = this.getEntityBakedAnimationPose(entityUUID, jointSkeleton); - AnimationDataContainer animationDataContainer = this.getEntityAnimationDataContainer(entityUUID); - PoseSamplerStateContainer poseSamplerStateContainer = this.getEntityPoseSamplerStateContainer(entityUUID); + AnimationData animationData = this.getEntityAnimationDataContainer(entityUUID); + PoseSamplerStateContainer poseSamplerStateContainer = this.getEntityPoseSamplerStateContainer(entityUUID, jointSkeleton); // Step 1: Extract animation driver data - entityJointAnimator.extractAnimationData(entity, animationDataContainer); + entityJointAnimator.extractAnimationData(entity, animationData); // Step 2: Update pose samplers using animation driver data - poseSamplerStateContainer.tick(animationDataContainer); + poseSamplerStateContainer.tick(animationData); // Step 3: Calculate pose - AnimationPose calculatedAnimationPose = entityJointAnimator.calculatePose(animationDataContainer, poseSamplerStateContainer); + AnimationPose calculatedAnimationPose = entityJointAnimator.calculatePose(animationData, poseSamplerStateContainer); if (calculatedAnimationPose == null){ calculatedAnimationPose = AnimationPose.of(jointSkeleton); } @@ -52,6 +52,8 @@ public void tick(T entity){ // Step 4: Push the local space pose to the baked pose, and save the baked pose. bakedPose.pushPose(calculatedAnimationPose.getConvertedToLocalSpace()); this.saveBakedPose(entityUUID, bakedPose); + + } public > void saveBakedPose(UUID uuid, BakedAnimationPose bakedPose){ @@ -63,8 +65,8 @@ public > void saveBakedPose(UUID uuid, BakedAnimationPose bake * @param uuid Entity UUID * @return Animation data container */ - public PoseSamplerStateContainer getEntityPoseSamplerStateContainer(UUID uuid){ - return this.entityPoseSamplerStateContainerStorage.getOrDefault(uuid, new PoseSamplerStateContainer()); + public PoseSamplerStateContainer getEntityPoseSamplerStateContainer(UUID uuid, JointSkeleton jointSkeleton){ + return this.entityPoseSamplerStateContainerStorage.computeIfAbsent(uuid, (uuid1 -> new PoseSamplerStateContainer(jointSkeleton))); } /** @@ -81,8 +83,8 @@ public > BakedAnimationPose getEntityBakedAnimationPose(UUID u * @param uuid Entity UUID * @return Animation data container */ - private AnimationDataContainer getEntityAnimationDataContainer(UUID uuid){ - return this.entityAnimationDataContainerStorage.getOrDefault(uuid, new AnimationDataContainer()); + private AnimationData getEntityAnimationDataContainer(UUID uuid){ + return this.entityAnimationDataContainerStorage.getOrDefault(uuid, new AnimationData()); } /** diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java index f22ccb8..b015378 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java @@ -1,13 +1,13 @@ package com.trainguy9512.animationoverhaul.animation.animator; import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityJointAnimator; +import com.trainguy9512.animationoverhaul.animation.data.AnimationData; import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerKey; import com.trainguy9512.animationoverhaul.animation.data.AnimationVariableKey; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.sample.*; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import com.trainguy9512.animationoverhaul.animation.data.AnimationSequenceData; import com.trainguy9512.animationoverhaul.util.time.Easing; import net.minecraft.client.Minecraft; @@ -27,7 +27,7 @@ public class FirstPersonPlayerJointAnimator extends LivingEntityJointAnimator localBakedPose; @@ -112,13 +112,13 @@ public class FirstPersonPlayerJointAnimator extends LivingEntityJointAnimator> BiFunction, AnimationPose> getStatePose() { + public > BiFunction, AnimationPose> getStatePose() { return (animationDataContainer, fpPlayerLocatorsJointSkeleton) -> animationDataContainer.getPoseSampler(IDLE_SEQUENCE_PLAYER).sample(fpPlayerLocatorsJointSkeleton); } }, MOVING { @Override - public > BiFunction, AnimationPose> getStatePose() { + public > BiFunction, AnimationPose> getStatePose() { return (animationDataContainer, fpPlayerLocatorsJointSkeleton) -> animationDataContainer.getPoseSampler(IDLE_SEQUENCE_PLAYER_ALT).sample(fpPlayerLocatorsJointSkeleton); } } @@ -153,21 +153,21 @@ protected JointSkeleton.Builder buildSkeleton() { } @Override - public AnimationPose calculatePose(AnimationDataContainer animationDataContainer) { + public AnimationPose calculatePose(AnimationData animationData) { // Update main hand item based on the anim notify //animationDataContainer.getAnimationVariable(MAIN_HAND_ITEM).set(localPlayer.getMainHandItem().copy()); //setEntityAnimationVariable(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem().copy()); - AnimationPose pose = animationDataContainer.getPoseSampler(TEST_STATE_MACHINE).sample(this.getJointSkeleton()); + AnimationPose pose = animationData.getPoseSampler(TEST_STATE_MACHINE).sample(this.getJointSkeleton()); - pose = dampenArmRotation(pose, animationDataContainer); + pose = dampenArmRotation(pose, animationData); - Vector3f rotation = new Vector3f(Mth.sin(animationDataContainer.getAnimationVariable(TIME_TEST).get() * 0.2F) * Mth.HALF_PI * 0.7f, 0, 0); + Vector3f rotation = new Vector3f(Mth.sin(animationData.getAnimationVariable(TIME_TEST).get() * 0.2F) * Mth.HALF_PI * 0.7f, 0, 0); //Vector3f translation = new Vector3f(Mth.sin(getEntityAnimationVariable(TIME_TEST) * 1.3F) * 3F, 0, 0); //pose.translateJoint(FPPlayerLocators.rightArm, translation, AnimationPose.TransformSpace.ENTITY, false); //pose.rotateJoint(FPPlayerLocators.rightArm, rotation, AnimationPose.TransformSpace.ENTITY, false); @@ -179,9 +179,9 @@ public AnimationPose calculatePose(AnimationDataContainer animat /* Get the pose with the added dampened camera rotation */ - private AnimationPose dampenArmRotation(AnimationPose pose, AnimationDataContainer animationDataContainer){ - Vector3f cameraRotation = animationDataContainer.getAnimationVariable(CAMERA_ROTATION).get(); - Vector3f dampenedCameraRotation = animationDataContainer.getAnimationVariable(DAMPENED_CAMERA_ROTATION).get(); + private AnimationPose dampenArmRotation(AnimationPose pose, AnimationData animationData){ + Vector3f cameraRotation = animationData.getAnimationVariable(CAMERA_ROTATION).get(); + Vector3f dampenedCameraRotation = animationData.getAnimationVariable(DAMPENED_CAMERA_ROTATION).get(); Vector3f cameraDampWeight = new Vector3f(0.6F, 0.3F, 0.1F); @@ -200,12 +200,12 @@ private AnimationPose dampenArmRotation(AnimationPose(this.jointSkeleton); } - AnimationPose animationPose = this.calculatePose(animationDataContainer); + AnimationPose animationPose = this.calculatePose(animationData); if (animationPose == null){ animationPose = AnimationPose.of(this.jointSkeleton); } @@ -259,8 +259,8 @@ public void tickExternal(){ this.localBakedPose.pushPose(animationPose); } - private boolean compareVariableItemStackWithEntityItemStack(AnimationVariableKey itemStackDataKey, ItemStack entityItemStack, AnimationDataContainer animationDataContainer){ - ItemStack currentItemStack = animationDataContainer.getAnimationVariable(itemStackDataKey).get(); + private boolean compareVariableItemStackWithEntityItemStack(AnimationVariableKey itemStackDataKey, ItemStack entityItemStack, AnimationData animationData){ + ItemStack currentItemStack = animationData.getAnimationVariable(itemStackDataKey).get(); if(currentItemStack.getItem() != null && entityItemStack.getItem() == null || currentItemStack.getItem() == null && entityItemStack.getItem() != null) { return true; } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java index c6e00b1..0f535c8 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java @@ -1,6 +1,6 @@ package com.trainguy9512.animationoverhaul.animation.animator; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; +import com.trainguy9512.animationoverhaul.animation.data.AnimationData; import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerStateContainer; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; @@ -34,16 +34,16 @@ public JointSkeleton getJointSkeleton(){ /** * Uses an object for data reference and updates the animation data container. Called once per tick, prior to pose samplers updating and pose calculation. * @param dataReference Object used as reference for updating the animation data container - * @param animationDataContainer Data container from the previous tick + * @param animationData Data container from the previous tick * @return Resulting data container */ - public abstract AnimationDataContainer extractAnimationData(T dataReference, AnimationDataContainer animationDataContainer); + public abstract AnimationData extractAnimationData(T dataReference, AnimationData animationData); /** * Calculates and returns an animation pose once per tick, after pose sampler update and animation data extraction - * @param animationDataContainer Data container containing extracted animation variable data. + * @param animationData Data container containing extracted animation variable data. * @param poseSamplerStateContainer Data container containing pose sampler states, used for sampling poses. * @return Calculated animation pose to be passed off to the baked animation pose */ - public abstract AnimationPose calculatePose(AnimationDataContainer animationDataContainer, PoseSamplerStateContainer poseSamplerStateContainer); + public abstract AnimationPose calculatePose(AnimationData animationData, PoseSamplerStateContainer poseSamplerStateContainer); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java index ddaf2b4..77226dd 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java @@ -1,8 +1,8 @@ package com.trainguy9512.animationoverhaul.animation.animator.entity; +import com.trainguy9512.animationoverhaul.animation.data.AnimationData; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import net.minecraft.client.model.PlayerModel; import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.PartPose; @@ -86,15 +86,15 @@ protected JointSkeleton buildSkeleton() { // Ticking every sampleable animation state, in this case updating the state machine conditions @Override - public AnimationDataContainer extractAnimationData(Player dataReference, AnimationDataContainer animationDataContainer) { - return animationDataContainer; + public AnimationData extractAnimationData(Player dataReference, AnimationData animationData) { + return animationData; } // This is the function for getting the final pose every tick @Override - public AnimationPose calculatePose(AnimationDataContainer animationDataContainer) { + public AnimationPose calculatePose(AnimationData animationData) { return AnimationPose.of(this.jointSkeleton); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationData.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationData.java new file mode 100644 index 0000000..20ea0aa --- /dev/null +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationData.java @@ -0,0 +1,125 @@ +package com.trainguy9512.animationoverhaul.animation.data; + +import com.google.common.collect.Maps; +import com.trainguy9512.animationoverhaul.animation.pose.sample.*; + +import java.util.*; +import java.util.function.Supplier; + +/** + * Represents a container for data kept track of and updated by a part animator, such as: + *
    + *
  • Animation Variables
  • + *
  • Pose Samplers
  • + *
+ * + * @see AnimationVariableKey + * @see PoseSamplerKey + */ +public class AnimationData { + + private final HashMap, AnimationVariable> animationVariableMap; + + public AnimationData(){ + this.animationVariableMap = Maps.newHashMap(); + } + + + /** + * Returns this animation data container's hash map of animation variable keys to animation variables currently loaded. + * + * @return {@link HashMap} of {@link AnimationVariableKey} keys to {@link AnimationVariable} values. + */ + public HashMap, AnimationVariable> getAnimationVariableMap(){ + return this.animationVariableMap; + } + + /** + * Returns a collection of every animation variable currently loaded into this animation data container. + * + * @return {@link Collection} of {@link PoseSampler} values. + */ + public Collection> getAnimationVariables(){ + return this.getAnimationVariableMap().values(); + } + + /** + * Returns an animation variable from the given key. If one is not currently loaded into + * this animation data container, then a new one is created from the key's default + * value and loaded into this animation data container and returned. + * + * @param dataKey the {@link AnimationVariableKey} attached to the desired {@link AnimationVariable} + * + * @return an {@link AnimationVariable} object reference + */ + @SuppressWarnings("unchecked") + public AnimationVariable getAnimationVariable(AnimationVariableKey dataKey){ + if(!this.getAnimationVariableMap().containsKey(dataKey)){ + this.getAnimationVariableMap().put(dataKey, new AnimationVariable<>(dataKey)); + } + return (AnimationVariable) this.getAnimationVariableMap().get(dataKey); + } + + + public static class AnimationVariable{ + + private D value; + private D valueOld; + private final Supplier defaultValue; + + private AnimationVariable(AnimationVariableKey dataKey){ + this.defaultValue = dataKey.getDefaultValueSupplier(); + this.value = dataKey.getDefaultValueSupplier().get(); + this.valueOld = dataKey.getDefaultValueSupplier().get(); + } + + /** + * Returns the value of this animation variable. + * + * @return - value of the {@link AnimationVariable} instance's type + */ + public D get(){ + return this.value; + } + + /** + * Returns the value of this animation variable prior to the last time it was set. + * + * @return - value of the {@link AnimationVariable} instance's type + */ + public D getOld(){ + return this.valueOld; + } + + /** + * Sets the value of this animation variable. Also updates the old value, setting it + * to what it was prior to this method call. + * + * @param value new value of the {@link AnimationVariable} instance's type + */ + public void set(D value){ + this.valueOld = this.value; + if(value != null){ + this.value = value; + } else { + this.value = defaultValue.get(); + } + } + + /** + * Sets this animation variable's value to the default value, supplied from the + * default value supplier. + */ + public void setDefaultValue(){ + this.set(this.defaultValue.get()); + } + + /** + * Returns whether the animation variable's type is that of a float or not. + * @return {@link Boolean} true if the type is float. + */ + public boolean isFloat(){ + return this.value instanceof Float; + } + } +} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDataContainer.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDataContainer.java index 30896e5..16cddaf 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDataContainer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDataContainer.java @@ -1,125 +1,4 @@ package com.trainguy9512.animationoverhaul.animation.data; -import com.google.common.collect.Maps; -import com.trainguy9512.animationoverhaul.animation.pose.sample.*; - -import java.util.*; -import java.util.function.Supplier; - -/** - * Represents a container for data kept track of and updated by a part animator, such as: - *
    - *
  • Animation Variables
  • - *
  • Pose Samplers
  • - *
- * - * @see AnimationVariableKey - * @see PoseSamplerKey - */ -public class AnimationDataContainer { - - private final HashMap, AnimationVariable> animationVariableMap; - - public AnimationDataContainer(){ - this.animationVariableMap = Maps.newHashMap(); - } - - - /** - * Returns this animation data container's hash map of animation variable keys to animation variables currently loaded. - * - * @return {@link HashMap} of {@link AnimationVariableKey} keys to {@link AnimationVariable} values. - */ - public HashMap, AnimationVariable> getAnimationVariableMap(){ - return this.animationVariableMap; - } - - /** - * Returns a collection of every animation variable currently loaded into this animation data container. - * - * @return {@link Collection} of {@link PoseSampler} values. - */ - public Collection> getAnimationVariables(){ - return this.getAnimationVariableMap().values(); - } - - /** - * Returns an animation variable from the given key. If one is not currently loaded into - * this animation data container, then a new one is created from the key's default - * value and loaded into this animation data container and returned. - * - * @param dataKey the {@link AnimationVariableKey} attached to the desired {@link AnimationVariable} - * - * @return an {@link AnimationVariable} object reference - */ - @SuppressWarnings("unchecked") - public AnimationVariable getAnimationVariable(AnimationVariableKey dataKey){ - if(!this.getAnimationVariableMap().containsKey(dataKey)){ - this.getAnimationVariableMap().put(dataKey, new AnimationVariable<>(dataKey)); - } - return (AnimationVariable) this.getAnimationVariableMap().get(dataKey); - } - - - public static class AnimationVariable{ - - private D value; - private D valueOld; - private final Supplier defaultValue; - - private AnimationVariable(AnimationVariableKey dataKey){ - this.defaultValue = dataKey.getDefaultValueSupplier(); - this.value = dataKey.getDefaultValueSupplier().get(); - this.valueOld = dataKey.getDefaultValueSupplier().get(); - } - - /** - * Returns the value of this animation variable. - * - * @return - value of the {@link AnimationVariable} instance's type - */ - public D get(){ - return this.value; - } - - /** - * Returns the value of this animation variable prior to the last time it was set. - * - * @return - value of the {@link AnimationVariable} instance's type - */ - public D getOld(){ - return this.valueOld; - } - - /** - * Sets the value of this animation variable. Also updates the old value, setting it - * to what it was prior to this method call. - * - * @param value new value of the {@link AnimationVariable} instance's type - */ - public void set(D value){ - this.valueOld = this.value; - if(value != null){ - this.value = value; - } else { - this.value = defaultValue.get(); - } - } - - /** - * Sets this animation variable's value to the default value, supplied from the - * default value supplier. - */ - public void setDefaultValue(){ - this.set(this.defaultValue.get()); - } - - /** - * Returns whether the animation variable's type is that of a float or not. - * @return {@link Boolean} true if the type is float. - */ - public boolean isFloat(){ - return this.value instanceof Float; - } - } +public interface AnimationDataContainer { } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationVariableKey.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationVariableKey.java index 03de000..cbb2b62 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationVariableKey.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationVariableKey.java @@ -8,9 +8,9 @@ /** * Represents a key for associating with animation variables in animation data containers *

- * Animation Variable Keys are used in the static definition of {@link AnimationDataContainer.AnimationVariable} objects + * Animation Variable Keys are used in the static definition of {@link AnimationData.AnimationVariable} objects * in {@link JointAnimator} classes, which are created at runtime using the {@link AnimationVariableKey#defaultValue} as - * the template. These keys are then referenced when accessing those variables from {@link AnimationDataContainer} + * the template. These keys are then referenced when accessing those variables from {@link AnimationData} * objects, with a key-and-value design structure. *

* Rather than creating animation variable objects in the class and referencing them directly, @@ -21,7 +21,7 @@ * @param the type of data being stored * * @see PoseSampler - * @see AnimationDataContainer + * @see AnimationData */ public class AnimationVariableKey { @@ -68,7 +68,7 @@ public Supplier getDefaultValueSupplier(){ } /** - * A mutable builder for {@link AnimationDataContainer.AnimationVariable} objects. + * A mutable builder for {@link AnimationData.AnimationVariable} objects. * * @param the type of data */ diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/PoseSamplerKey.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/PoseSamplerKey.java index 6bafd04..951e8d8 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/PoseSamplerKey.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/PoseSamplerKey.java @@ -10,7 +10,7 @@ *

* Pose Sampler Keys are used in the static definition of {@link PoseSampler} objects in {@link JointAnimator} classes, which are * created at runtime using the {@link PoseSamplerKey#defaultValue} as the template. These keys are then referenced - * when accessing those pose samplers from {@link AnimationDataContainer} objects, with a key-and-value design structure. + * when accessing those pose samplers from {@link AnimationData} objects, with a key-and-value design structure. *

* Rather than creating pose sampler * objects in the class and referencing them directly, these static keys are used instead to reference @@ -23,7 +23,7 @@ * @param identifier String identifier used for debugging. * * @see PoseSampler - * @see AnimationDataContainer + * @see AnimationData */ public record PoseSamplerKey

(Supplier

defaultValue, String identifier) { diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/PoseSamplerStateContainer.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/PoseSamplerStateContainer.java index a5c42ce..9d9ca99 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/PoseSamplerStateContainer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/PoseSamplerStateContainer.java @@ -1,39 +1,41 @@ package com.trainguy9512.animationoverhaul.animation.data; import com.google.common.collect.Maps; -import com.trainguy9512.animationoverhaul.animation.pose.sample.AnimationStateMachine; +import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; +import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; import com.trainguy9512.animationoverhaul.animation.pose.sample.PoseSampler; +import com.trainguy9512.animationoverhaul.animation.pose.sample.Sampleable; +import com.trainguy9512.animationoverhaul.animation.pose.sample.SampleableFromInput; -import java.util.Collection; import java.util.HashMap; public class PoseSamplerStateContainer { private final HashMap, PoseSampler> poseSamplers; - private final HashMap>, AnimationStateMachine> stateMachines; + private final JointSkeleton jointSkeleton; - public PoseSamplerStateContainer() { + public PoseSamplerStateContainer(JointSkeleton jointSkeleton) { this.poseSamplers = Maps.newHashMap(); - this.stateMachines = Maps.newHashMap(); + this.jointSkeleton = jointSkeleton; } /** - * Iterates over every currently loaded pose sampler and executes the {@link PoseSampler#tick(AnimationDataContainer, PoseSamplerStateContainer)} method + * Iterates over every currently loaded pose sampler and executes the {@link PoseSampler#tick(AnimationData, PoseSamplerStateContainer)} method *

* The update order is as follows: State machines first, then all others. * - * @param animationDataContainer Extracted animation data + * @param animationData Extracted animation data * @implNote Only do this once per game tick! For entities, this is handled in the entity joint animator dispatcher. */ - public void tick(AnimationDataContainer animationDataContainer){ - this.tickUpdateOrderGroup(animationDataContainer, PoseSampler.UpdateOrder.STATE_MACHINES); - this.tickUpdateOrderGroup(animationDataContainer, PoseSampler.UpdateOrder.OTHER); + public void tick(AnimationData animationData){ + this.tickUpdateOrderGroup(animationData, PoseSampler.UpdateOrder.STATE_MACHINES); + this.tickUpdateOrderGroup(animationData, PoseSampler.UpdateOrder.OTHER); } - private void tickUpdateOrderGroup(AnimationDataContainer animationDataContainer, PoseSampler.UpdateOrder updateOrder){ + private void tickUpdateOrderGroup(AnimationData animationData, PoseSampler.UpdateOrder updateOrder){ this.poseSamplers.values().stream() .filter((poseSampler -> poseSampler.getUpdateOrder() == updateOrder)) - .forEach((poseSampler -> poseSampler.tick(animationDataContainer, this))); + .forEach((poseSampler -> poseSampler.tick(animationData, this))); } /** @@ -47,7 +49,14 @@ private void tickUpdateOrderGroup(AnimationDataContainer animationDataContainer, */ @SuppressWarnings("unchecked") public

P getPoseSampler(PoseSamplerKey

poseSamplerKey){ - this.poseSamplers.putIfAbsent(poseSamplerKey, poseSamplerKey.constructPoseSampler()); - return (P) this.poseSamplers.get(poseSamplerKey); + return (P) this.poseSamplers.computeIfAbsent(poseSamplerKey, PoseSamplerKey::constructPoseSampler); + } + + public AnimationPose sample(PoseSamplerKey poseSamplerKey){ + return this.getPoseSampler(poseSamplerKey).sample(this.jointSkeleton); + } + + public AnimationPose sample(PoseSamplerKey poseSamplerKey, AnimationPose animationPose){ + return this.getPoseSampler(poseSamplerKey).sample(this.jointSkeleton, animationPose); } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationSequencePlayer.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationSequencePlayer.java index bd46824..ed29ab4 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationSequencePlayer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationSequencePlayer.java @@ -1,16 +1,17 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; import com.google.common.collect.Maps; +import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerStateContainer; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; +import com.trainguy9512.animationoverhaul.animation.data.AnimationData; import com.trainguy9512.animationoverhaul.animation.data.AnimationSequenceData; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import java.util.HashMap; -public class AnimationSequencePlayer extends TimeBasedPoseSampler { +public class AnimationSequencePlayer extends TimeBasedPoseSampler implements Sampleable { private boolean looping; private ResourceLocation resourceLocation; @@ -35,6 +36,11 @@ public static Builder of(ResourceLocation resourceLocation){ return new Builder<>(resourceLocation); } + @Override + public AnimationPose sample(JointSkeleton jointSkeleton) { + return AnimationPose.fromAnimationSequence(jointSkeleton, this.resourceLocation, this.getTimeFromTicks()); + } + public static class Builder> extends TimeBasedPoseSampler.Builder { @@ -47,7 +53,7 @@ public static class Builder> extends TimeBasedPoseSampler.B protected Builder(ResourceLocation resourceLocation) { super(); this.resourceLocation = resourceLocation; - this.frameLength = AnimationSequenceData.INSTANCE.get(this.resourceLocation).getFrameLength(); + this.frameLength = AnimationSequenceData.INSTANCE.get(this.resourceLocation).frameLength(); this.endTime = frameLength; } @@ -76,7 +82,7 @@ public AnimationSequencePlayer build() { } @Override - public void tick(AnimationDataContainer animationDataContainer){ + public void tick(AnimationData animationData, PoseSamplerStateContainer poseSamplerStateContainer){ for(AnimNotify animNotify : animNotifyMap.values()){ if(animNotify.isActive()){ animNotify.setActive(false); @@ -88,7 +94,7 @@ public void tick(AnimationDataContainer animationDataContainer){ animNotify.setActive(true); } } - super.tick(animationDataContainer); + super.tick(animationData, poseSamplerStateContainer); } private float getTimeFromTicks(){ @@ -118,12 +124,6 @@ public boolean isAnimNotityActive(String identifier){ return false; } - @Override - public > AnimationPose sample(JointSkeleton jointSkeleton){ - return AnimationPose.fromAnimationSequence(jointSkeleton, this.resourceLocation, this.getTimeFromTicks()); - //return super.sample(locatorSkeleton); - } - //TODO: Rewrite this with functions private static class AnimNotify { diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationStateMachine.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationStateMachine.java index 2625347..5d55e0a 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationStateMachine.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationStateMachine.java @@ -2,9 +2,9 @@ import com.google.common.collect.Maps; import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; +import com.trainguy9512.animationoverhaul.animation.data.AnimationData; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import com.trainguy9512.animationoverhaul.util.time.Easing; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; @@ -152,7 +152,7 @@ private StateTransition getStateTransition(S origin, S destination){ } private AnimationPose getPoseFromState(S identifier, JointSkeleton jointSkeleton){ - BiFunction biFunction = identifier.getStatePose(); + BiFunction biFunction = identifier.getStatePose(); return biFunction.apply(this.getAnimationDataContainer(), jointSkeleton); } @@ -176,7 +176,7 @@ public AnimationPose sample(JointSkeleton jointSkeleton) { } @Override - public void tick(AnimationDataContainer animationDataContainer){ + public void tick(AnimationData animationData){ // Don't evaluate if the state machine has no states if(this.statesHashMap.isEmpty()){ AnimationOverhaulMain.LOGGER.warn("State machine {} not evaluated due to no active states", this.getIdentifier()); @@ -184,7 +184,7 @@ public void tick(AnimationDataContainer animationDataContainer){ } // Add to the current elapsed ticks - super.tick(animationDataContainer); + super.tick(animationData); // Get the previous active state S currentActiveStateIdentifier = this.activeStates.getLast(); @@ -198,7 +198,7 @@ public void tick(AnimationDataContainer animationDataContainer){ if(isValidTransition(currentActiveStateIdentifier, stateIdentifier)){ StateTransition currentStateTransition = currentActiveState.getTransition(stateIdentifier); assert currentStateTransition != null; - if(currentStateTransition.getCondition(animationDataContainer)){ + if(currentStateTransition.getCondition(animationData)){ // If the loop has already determined a state transition to be true, update the transition IF the new one has a higher priority if(canEnterTransition && currentStateTransition.getPriority() < stateTransition.getPriority()){ stateTransition = currentStateTransition; @@ -336,7 +336,7 @@ public static class StateTransition { private final float transitionTime; private final Easing easing; private final int priority; - private final Predicate conditionPredicate; + private final Predicate conditionPredicate; //private final Enum destinationStateIdentifier; //private boolean condition = false; @@ -348,7 +348,7 @@ private StateTransition(Builder builder) { this.conditionPredicate = builder.conditionPredicate; } - public static Builder of(Predicate stateConditionPredicate){ + public static Builder of(Predicate stateConditionPredicate){ return new Builder(stateConditionPredicate); } @@ -360,8 +360,8 @@ public float getTransitionTime() { return this.transitionTime; } - public boolean getCondition(AnimationDataContainer animationDataContainer){ - return this.conditionPredicate.test(animationDataContainer); + public boolean getCondition(AnimationData animationData){ + return this.conditionPredicate.test(animationData); } public int getPriority(){ @@ -372,9 +372,9 @@ public static class Builder { private float transitionTime = 1; private Easing easing = Easing.Linear.of(); private int priority = 1; - private final Predicate conditionPredicate; + private final Predicate conditionPredicate; - private Builder(Predicate conditionPredicate){ + private Builder(Predicate conditionPredicate){ this.conditionPredicate = conditionPredicate; } @@ -418,6 +418,6 @@ public StateTransition build(){ } public interface StateEnum { - BiFunction getStatePose(); + BiFunction getStatePose(); } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/PoseSampler.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/PoseSampler.java index b36b1c8..a8e86e4 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/PoseSampler.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/PoseSampler.java @@ -1,10 +1,7 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; -import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerKey; import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerStateContainer; -import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; +import com.trainguy9512.animationoverhaul.animation.data.AnimationData; public class PoseSampler { @@ -20,7 +17,6 @@ public static Builder of(){ public static class Builder> { protected Builder() { - PoseSamplerKey b = PoseSamplerKey.builder(() -> PoseSampler.of().build()).build(); } public PoseSampler build(){ @@ -28,21 +24,13 @@ public PoseSampler build(){ } } - public AnimationPose sample(JointSkeleton jointSkeleton){ - return AnimationPose.of(jointSkeleton); - } - - public AnimationPose sampleFromInputPose(AnimationPose inputPose, JointSkeleton jointSkeleton){ - return this.sample(jointSkeleton); - } - /** * Updates the pose sampler using information from the data container. Called once per tick after animation data is extracted by the joint animator but prior to pose calculation. * - * @param animationDataContainer Extracted animation data + * @param animationData Extracted animation data * @param poseSamplerStateContainer Pose sampler state container used for referencing information from other pose samplers. Only */ - public void tick(AnimationDataContainer animationDataContainer, PoseSamplerStateContainer poseSamplerStateContainer){ + public void tick(AnimationData animationData, PoseSamplerStateContainer poseSamplerStateContainer){ } public String getIdentifier(){ diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/Sampleable.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/Sampleable.java index 48d7e4f..e385f19 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/Sampleable.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/Sampleable.java @@ -1,9 +1,8 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; public interface Sampleable { - AnimationPose sample(JointSkeleton jointSkeleton, AnimationDataContainer animationDataContainer); + AnimationPose sample(JointSkeleton jointSkeleton); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/SampleableFromInput.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/SampleableFromInput.java index 1b3e637..bb42002 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/SampleableFromInput.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/SampleableFromInput.java @@ -1,9 +1,8 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; public interface SampleableFromInput { - AnimationPose sample(JointSkeleton jointSkeleton, AnimationDataContainer animationDataContainer, AnimationPose inputPose); + AnimationPose sample(JointSkeleton jointSkeleton, AnimationPose inputPose); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedPoseSampler.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedPoseSampler.java index d133f39..576b1eb 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedPoseSampler.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedPoseSampler.java @@ -1,7 +1,7 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; import com.google.common.collect.Maps; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; +import com.trainguy9512.animationoverhaul.animation.data.AnimationData; import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerKey; import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerStateContainer; @@ -143,11 +143,11 @@ public void progressTimeIfStateActive(PoseSamplerStateContainer poseSamplerState } @Override - public void tick(AnimationDataContainer animationDataContainer, PoseSamplerStateContainer poseSamplerStateContainer){ - progressTimeIfStateActive(); + public void tick(AnimationData animationData, PoseSamplerStateContainer poseSamplerStateContainer){ + progressTimeIfStateActive(poseSamplerStateContainer); if(this.getIsPlaying()){ this.timeElapsed += this.playRate; } - playFromStartOnStateActive(); + playFromStartOnStateActive(poseSamplerStateContainer); } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java index 1185b90..9ae9e74 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java @@ -130,7 +130,7 @@ private void overwriteItemInHandRendering(float f, PoseStack poseStack, MultiBuf - this.renderItemInHand(abstractClientPlayer, FirstPersonPlayerJointAnimator.INSTANCE.localAnimationDataContainer.getAnimationVariable(FirstPersonPlayerJointAnimator.MAIN_HAND_ITEM).get(), poseStack, HumanoidArm.RIGHT, animationPose, bufferSource, i); + this.renderItemInHand(abstractClientPlayer, FirstPersonPlayerJointAnimator.INSTANCE.localAnimationData.getAnimationVariable(FirstPersonPlayerJointAnimator.MAIN_HAND_ITEM).get(), poseStack, HumanoidArm.RIGHT, animationPose, bufferSource, i); //this.renderItemInHand(abstractClientPlayer, ItemStack.EMPTY, poseStack, HumanoidArm.LEFT, animationPose, bufferSource, i);