texture recaching issue fix

This commit is contained in:
c0ffee 2024-04-18 17:40:06 -07:00
parent 43843a398f
commit fbf8b3444d
7 changed files with 79 additions and 35 deletions

View file

@ -24,46 +24,51 @@
</li>
</loopOptions>
</li>
<!--
<li Class="Rimworld_Animations.AnimationStage_Branch">
<paths>
<li Class="Rimworld_Animations.AnimationStage_LoopRandomSelectChance">
<loops>10</loops>
<animationOptions>
<loopOptions>
<li>
<probability>3</probability>
<li>Pawn1_Stage2_Variant1</li>
<li>Pawn2_Stage2_Variant1</li>
<animationDefs>
<li>TestAnimation1</li>
<li>TestAnimation1</li>
</animationDefs>
</li>
<li>
<probability>1</probability>
<li>Pawn1_Stage2_Variant2</li>
<li>Pawn2_Stage2_Variant2</li>
<animationDefs>
<li>TestAnimation1</li>
<li>TestAnimation1</li>
</animationDefs>
</li>
</animationOptions>
</loopOptions>
</li>
<li Class="Rimworld_Animations.AnimationStage_LoopRandomSelectChance">
<loops>10</loops>
<animationOptions>
<loopOptions>
<li>
<probability>3</probability>
<li>Pawn1_Stage2_Variant1</li>
<li>Pawn2_Stage2_Variant1</li>
<animationDefs>
<li>TestAnimation2</li>
<li>TestAnimation2</li>
</animationDefs>
</li>
<li>
<probability>1</probability>
<li>Pawn1_Stage2_Variant2</li>
<li>Pawn2_Stage2_Variant2</li>
<animationDefs>
<li>TestAnimation2</li>
<li>TestAnimation2</li>
</animationDefs>
</li>
</animationOptions>
</loopOptions>
</li>
</paths>
</li>
-->
</animationStages>
<contexts>

View file

@ -35,3 +35,4 @@
</raceOffsets>
</Rimworld_Animations.OffsetDef>
</Defs>

View file

@ -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;
}
}
}

View file

@ -14,7 +14,9 @@ namespace Rimworld_Animations {
// CompExtendedAnimator
// Helps manage AnimationQueue, AbsolutePosition
//ticks of current animation
private int animationTicks;
private List<AnimationDef> 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<AnimationDef> groupAnimation, BaseExtendedAnimatorAnchor anchor)
{
this.anchor = anchor;
animationQueue = groupAnimation;
PlayNextAnimation();
PlayGroupAnimation(groupAnimation);
}
public override void PostExposeData()
{
base.PostExposeData();
Scribe_Values.Look<bool>(ref this.isAnimating, "animations_isAnimating", false);
Scribe_Values.Look<int>(ref this.animationTicks, "animations_ticks", 0);
Scribe_Collections.Look<AnimationDef>(ref animationQueue, "animations_queue");
Scribe_Deep.Look<BaseExtendedAnimatorAnchor>(ref this.anchor, "animations_anchor");
}
public static void CheckRecacheNecessary(int anim)
{
}
private Pawn pawn => base.parent as Pawn;
}

View file

@ -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);
}

View file

@ -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;
}
}
}
}
}
}