-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50% functional re-written rendering patches.
- Loading branch information
Showing
13 changed files
with
124 additions
and
111 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
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
28 changes: 0 additions & 28 deletions
28
Source/AnimationMod/Patches/Patch_GlobalTextureAtlasManager_TryGetPawnFrameSet.cs
This file was deleted.
Oops, something went wrong.
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
17 changes: 0 additions & 17 deletions
17
Source/AnimationMod/Patches/Patch_PawnRenderer_DrawInvisibleShadow.cs
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
Source/AnimationMod/Patches/Patch_PawnRenderer_DrawShadowInternal.cs
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,18 @@ | ||
using HarmonyLib; | ||
using JetBrains.Annotations; | ||
using Verse; | ||
|
||
namespace AM.Patches; | ||
|
||
/// <summary> | ||
/// Suppresses shadow draw done by PawnRenderer's DrawShadowInternal. | ||
/// </summary> | ||
[HarmonyPatch(typeof(PawnRenderer), nameof(PawnRenderer.DrawShadowInternal))] | ||
[UsedImplicitly] | ||
public class Patch_PawnRenderer_DrawShadowInternal | ||
{ | ||
public static bool Suppress = false; | ||
|
||
[HarmonyPriority(Priority.First)] | ||
public static bool Prefix() => !Suppress; | ||
} |
108 changes: 82 additions & 26 deletions
108
Source/AnimationMod/Patches/Patch_PawnRenderer_RenderPawnAt.cs
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,57 +1,113 @@ | ||
using AM.Grappling; | ||
using HarmonyLib; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
namespace AM.Patches; | ||
|
||
/// <summary> | ||
/// Simply prevents the regular RenderPawnAt method from running while a pawn in being animated. | ||
/// This disables the regular rendering whenever a pawn in being animated. | ||
/// Additionally, modifies PawnRenderer.results to make sure that the RenderPawnInternal method gets called every frame | ||
/// while in an animation. | ||
/// When a pawn is being animated, RenderPawnAt needs to be modified: | ||
/// first, the private field 'results' needs to be modified in order to ensure that RenderPawnDynamic is called. | ||
/// Next, call <see cref="PawnRenderTree.ParallelPreDraw(PawnDrawParms)"/> with the arguments that I want in order to modify how the pawn will actually be displayed. | ||
/// </summary> | ||
[HarmonyPatch(typeof(PawnRenderer), nameof(PawnRenderer.RenderPawnAt))] | ||
public static class Patch_PawnRenderer_RenderPawnAt | ||
{ | ||
public static bool AllowNext; | ||
|
||
private static PawnRenderer.PreRenderResults? storedResultsTemp; | ||
|
||
[HarmonyPriority(Priority.First)] | ||
public static bool Prefix(Pawn ___pawn, ref PawnRenderer.PreRenderResults ___results) | ||
public static bool Prefix(Pawn ___pawn, PawnRenderTree ___renderTree, ref PawnRenderer.PreRenderResults ___results, ref PawnRenderer.PreRenderResults? __state) | ||
{ | ||
var anim = PatchMaster.GetAnimator(___pawn); | ||
__state = null; // Harmony requires this to be initialized. | ||
|
||
if (anim != null && !AllowNext) | ||
{ | ||
return false; | ||
} | ||
// Draw the ropes that bind the pawn when being grappled. | ||
DrawGrappleRopeIfRequired(___pawn); | ||
|
||
var job = ___pawn.CurJob; | ||
if (job?.def == AM_DefOf.AM_GrapplePawn) | ||
// Try to get an active animator for this pawn. | ||
var animator = PatchMaster.GetAnimator(___pawn); | ||
if (animator == null) | ||
{ | ||
JobDriver_GrapplePawn.DrawEnsnaringRope(___pawn, job); | ||
return true; | ||
} | ||
|
||
if (AllowNext) | ||
// Ok, the pawn is in an active animation, but we want to suppress the regular draw call | ||
// in order to draw only when we want to. This is controlled by the AllowNext flag. | ||
if (!AllowNext) | ||
{ | ||
storedResultsTemp = ___results; | ||
___results.showBody = true; | ||
___results.useCached = false; | ||
___results.valid = true; | ||
return false; | ||
} | ||
|
||
// Auto-reset AllowNext flag. | ||
AllowNext = false; | ||
return true; | ||
|
||
// Pawn is being animated, so the 'results' field must be modified to | ||
// ensure that RenderPawnInternal gets called, as opposed to cached rendering. | ||
// Store the current value of results in 'state', so that is can be restored in the postfix. | ||
__state = ___results; | ||
|
||
// Setting these values ensures that RenderPawnInternal gets called: | ||
___results.valid = true; | ||
___results.draw = true; | ||
___results.useCached = false; | ||
|
||
// Make are the arguments that get passed into RenderPawnInternal and ParallelPreDraw. | ||
// Note that the original results.parms is used as a base, which is useful because we can inherit some | ||
// flags like 'coveredInFoam'. | ||
MakeDrawArgs(animator, ___pawn, ref ___results.parms); | ||
|
||
// Most importantly, need to call ParallelPreRender on the renderTree to actually | ||
// set up all the matrices and whatnot that gets used when renderTree draw is called. | ||
___renderTree.ParallelPreDraw(___results.parms); | ||
|
||
// Do run the regular RenderPawnAt method now. | ||
return true; | ||
} | ||
|
||
[HarmonyPriority(Priority.First)] | ||
public static void Postfix(ref PawnRenderer.PreRenderResults ___results) | ||
public static void Postfix(PawnRenderer.PreRenderResults? __state, ref PawnRenderer.PreRenderResults ___results) | ||
{ | ||
if (storedResultsTemp != null) | ||
// Restore private field 'results' to original value before modification, | ||
// if required. | ||
if (__state != null) | ||
{ | ||
___results = storedResultsTemp.Value; | ||
storedResultsTemp = null; | ||
___results = __state.Value; | ||
} | ||
} | ||
} | ||
|
||
private static void DrawGrappleRopeIfRequired(Pawn pawn) | ||
{ | ||
var job = pawn.CurJob; | ||
if (job?.def == AM_DefOf.AM_GrapplePawn) | ||
{ | ||
JobDriver_GrapplePawn.DrawEnsnaringRope(pawn, job); | ||
} | ||
} | ||
|
||
public static void MakeDrawArgs(AnimRenderer animator, Pawn pawn, ref PawnDrawParms parms) | ||
{ | ||
// Try to get the pawn snapshot. | ||
var part = animator.GetPawnBody(pawn); | ||
var snapshot = animator.GetSnapshot(part); | ||
|
||
// Dead pawns should not be animated, but make sure that it is not dead just in case. | ||
parms.dead = false; | ||
|
||
// Debug: | ||
parms.tint = Color.magenta; | ||
|
||
// Must be standing. | ||
parms.posture = RimWorld.PawnPosture.Standing; | ||
|
||
// Remove invisible flag. | ||
parms.flags &= ~PawnRenderFlags.Invisible; | ||
|
||
// Set facing direction: | ||
parms.facing = snapshot.GetWorldDirection(); | ||
|
||
// New transform matrix calculation: | ||
Vector3 worldPos = snapshot.GetWorldPosition(); | ||
float worldAngle = snapshot.GetWorldRotation(); | ||
Vector3 scale = snapshot.LocalScale; // Just use local part as scale, not currently used anyway but might be useful in future. | ||
parms.matrix = Matrix4x4.TRS(worldPos + pawn.ageTracker.CurLifeStage.bodyDrawOffset, Quaternion.Euler(0, worldAngle, 0), scale); | ||
} | ||
} |
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
23 changes: 0 additions & 23 deletions
23
Source/AnimationMod/Patches/Patch_PawnUtility_GetPosture.cs
This file was deleted.
Oops, something went wrong.
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