diff --git a/1.5/Assemblies/Rimworld-Animations.dll b/1.5/Assemblies/Rimworld-Animations.dll index 1297fac..6aa83a8 100644 Binary files a/1.5/Assemblies/Rimworld-Animations.dll and b/1.5/Assemblies/Rimworld-Animations.dll differ diff --git a/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml b/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml index 58c6dd2..7fb19e6 100644 --- a/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml +++ b/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml @@ -24,46 +24,51 @@ - diff --git a/1.5/Defs/OffsetDefs/OffsetDef_GroinToAppropriateHeight.xml b/1.5/Defs/OffsetDefs/OffsetDef_GroinToAppropriateHeight.xml index 3fe9c46..4503f96 100644 --- a/1.5/Defs/OffsetDefs/OffsetDef_GroinToAppropriateHeight.xml +++ b/1.5/Defs/OffsetDefs/OffsetDef_GroinToAppropriateHeight.xml @@ -35,3 +35,4 @@ + \ No newline at end of file diff --git a/1.5/Source/AnimationWorkers/AnimationWorker_KeyframesExtended.cs b/1.5/Source/AnimationWorkers/AnimationWorker_KeyframesExtended.cs index 7546b67..acc531f 100644 --- a/1.5/Source/AnimationWorkers/AnimationWorker_KeyframesExtended.cs +++ b/1.5/Source/AnimationWorkers/AnimationWorker_KeyframesExtended.cs @@ -26,6 +26,7 @@ namespace Rimworld_Animations //use extendedkeyframes to determine addon facing public Rot4 facingAtTick(int tick) { + //if ticks are < first keyframe tick, just be stuck to first keyframe rot if (tick <= this.part.keyframes[0].tick) { @@ -64,8 +65,6 @@ namespace Rimworld_Animations return (keyframe as ExtendedKeyframe).rotation; } - - public bool visibleAtTick(int tick) { //if ticks are < first keyframe tick, just be stuck to first keyframe rot @@ -110,5 +109,15 @@ namespace Rimworld_Animations } + + public bool shouldRecache(int tick) + { + if (facingAtTick(tick) != facingAtTick(tick - 1) || visibleAtTick(tick) != visibleAtTick(tick - 1)) + { + return true; + } + + return true; + } } } diff --git a/1.5/Source/Comps/CompExtendedAnimator.cs b/1.5/Source/Comps/CompExtendedAnimator.cs index e1cb8cf..bd15457 100644 --- a/1.5/Source/Comps/CompExtendedAnimator.cs +++ b/1.5/Source/Comps/CompExtendedAnimator.cs @@ -14,7 +14,9 @@ namespace Rimworld_Animations { // CompExtendedAnimator // Helps manage AnimationQueue, AbsolutePosition - + //ticks of current animation + private int animationTicks; + private List animationQueue; private BaseExtendedAnimatorAnchor anchor; private bool isAnimating = false; @@ -41,8 +43,6 @@ namespace Rimworld_Animations { return anchor.getDrawPos(); } - //ticks of current animation - private int animationTicks; public override void CompTick() { @@ -111,20 +111,24 @@ namespace Rimworld_Animations { public void PlayGroupAnimation(List groupAnimation, BaseExtendedAnimatorAnchor anchor) { this.anchor = anchor; - animationQueue = groupAnimation; - PlayNextAnimation(); + PlayGroupAnimation(groupAnimation); } public override void PostExposeData() { base.PostExposeData(); Scribe_Values.Look(ref this.isAnimating, "animations_isAnimating", false); - + Scribe_Values.Look(ref this.animationTicks, "animations_ticks", 0); Scribe_Collections.Look(ref animationQueue, "animations_queue"); Scribe_Deep.Look(ref this.anchor, "animations_anchor"); } + public static void CheckRecacheNecessary(int anim) + { + + } + private Pawn pawn => base.parent as Pawn; } diff --git a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs index d482853..cf45a65 100644 --- a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs +++ b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs @@ -21,24 +21,14 @@ namespace Rimworld_Animations // ADJUST FACING get rotated textures // compare the previous tick to the current tick; if the current tick rotation is different, recache + parms.facing = extendedAnimWorker.facingAtTick(__instance.tree.AnimationTick); - Rot4 animFacing = extendedAnimWorker.facingAtTick(__instance.tree.AnimationTick); - - if (extendedAnimWorker.facingAtTick(__instance.tree.AnimationTick - 1) != extendedAnimWorker.facingAtTick(__instance.tree.AnimationTick)) - { - __instance.requestRecache = true; - parms.facing = animFacing; - } //INVIS IF ANIM CALLS FOR IT //replace maybe? //cheaper call now comparing prev tick to cur tick - if (extendedAnimWorker.visibleAtTick(__instance.tree.AnimationTick - 1) != extendedAnimWorker.visibleAtTick(__instance.tree.AnimationTick)) - { - __instance.requestRecache = true; - return extendedAnimWorker.visibleAtTick(__instance.tree.AnimationTick); - } + return extendedAnimWorker.visibleAtTick(__instance.tree.AnimationTick); } diff --git a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs index 6acbe35..5410d6a 100644 --- a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs +++ b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderTree.cs @@ -33,4 +33,39 @@ namespace Rimworld_Animations } } } + + + [HarmonyPatch(typeof(PawnRenderTree), "AdjustParms")] + public class HarmonyPatch_PawnRenderTree2 + { + public static void Prefix(PawnRenderTree __instance, ref PawnDrawParms parms) + { + + int animationTick = __instance.AnimationTick; + + if (__instance.rootNode.AnimationWorker is AnimationWorker_KeyframesExtended rootAnimWorkerExtended) + { + //recache during facing turn + if (rootAnimWorkerExtended.shouldRecache(animationTick)) + { + __instance.rootNode.requestRecache = true; + + } + } + + foreach (PawnRenderNode node in __instance.rootNode.children) + { + if (node.AnimationWorker is AnimationWorker_KeyframesExtended animWorkerExtended) + { + //recache during facing turn + if (animWorkerExtended.shouldRecache(animationTick)) + { + + node.requestRecache = true; + + } + } + } + } + } }