Skip to content

Commit

Permalink
Fix stuck sprite issue by directly swapping textures (See #45)
Browse files Browse the repository at this point in the history
- Directly swap out the texture of the character being lipsynced, rather than calling MODDrawBustshot
- This should avoid issues where MODDrawBustshot is called at an innapropriate time, causing the character to get stuck on the screen.
- If the MODLipSyncProcess is ever called at the wrong time, it won't ever cause the character to be stuck on the screen, however it may cause the wrong sprite to be displayed if the layer is re-used for another character immediately after. It should clear next time the sprite is re-drawn.
  • Loading branch information
drojf committed Sep 20, 2021
1 parent 74c247b commit 3f42f27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 131 deletions.
67 changes: 0 additions & 67 deletions Assets.Scripts.Core.Scene/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,72 +824,5 @@ private void Update()
public void MODOnlyRecompile()
{
}

public void MODDrawLayer(string textureName, Texture2D tex2d, int x, int y, int z, Vector2? origin, float alpha, bool isBustshot, int type, float wait, bool isBlocking)
{
cachedIsBustShot = isBustshot;
FinishAll();
if (textureName == string.Empty)
{
HideLayer();
}
else if (tex2d == null)
{
Logger.LogError("Failed to load texture " + textureName);
}
else
{
startRange = 0f;
targetRange = alpha;
targetAlpha = alpha;
meshRenderer.enabled = true;
shaderType = type;
PrimaryName = textureName;
float num = 1f;
if (z > 0)
{
num = 1f - (float)z / 400f;
}
if (z < 0)
{
num = 1f + (float)z / -400f;
}
EnsureCorrectlySizedMesh(
width: tex2d.width, height: tex2d.height,
alignment: ((x != 0 || y != 0) && !isBustshot) ? LayerAlignment.AlignTopleft : LayerAlignment.AlignCenter,
origin: origin,
isBustShot: isBustshot,
finalXOffset: x,
texturePath: null
);
if (primary != null)
{
material.shader = shaderCrossfade;
SetSecondaryTexture(primary);
SetPrimaryTexture(tex2d);
startRange = 1f;
targetRange = 0f;
targetAlpha = 1f;
}
else
{
material.shader = shaderDefault;
if (type == 3)
{
material.shader = shaderMultiply;
}
SetPrimaryTexture(tex2d);
}
SetRange(startRange);
base.transform.localPosition = new Vector3((float)x, 0f - (float)y, (float)Priority * -0.1f);
base.transform.localScale = new Vector3(num, num, 1f);
targetPosition = base.transform.localPosition;
targetScale = base.transform.localScale;
if (Mathf.Approximately(wait, 0f))
{
FinishFade();
}
}
}
}
}
64 changes: 8 additions & 56 deletions Assets.Scripts.Core.Scene/SceneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,54 +847,6 @@ public void MODOnlyRecompile()
{
}

public void MODDrawBustshot(int layer, string textureName, Texture2D tex2d, int x, int y, int z, int oldx, int oldy, int oldz, bool move, int priority, int type, float wait, bool isblocking)
{
if (MODSkipImage(textureName))
{
return;
}

Layer layer2 = GetLayer(layer);
while (layer2.FadingOut)
{
layer2.HideLayer();
layer2 = GetLayer(layer);
}
if (!move)
{
oldx = x;
oldy = y;
oldz = z;
}
layer2.MODDrawLayer(textureName, tex2d, oldx, oldy, oldz, null, 1f, /*isBustshot:*/ true, type, wait, isblocking);
layer2.SetPriority(priority);
if (move)
{
layer2.MoveLayer(x, y, z, 1f, 0, wait, isblocking, adjustAlpha: false);
}
iTween.Stop(layer2.gameObject);
if (Mathf.Approximately(wait, 0f))
{
layer2.FinishFade();
}
else
{
layer2.FadeInLayer(wait);
if (isblocking)
{
GameSystem.Instance.AddWait(new Wait(wait, WaitTypes.WaitForMove, layer2.FinishFade));
}
if (layer2.UsingCrossShader() && layer2.gameObject.layer != GetActiveLayerMask())
{
SetLayerActiveOnBothScenes(layer2);
}
else
{
UpdateLayerMask(layer2, priority);
}
}
}

public IEnumerator MODDrawLipSync(int character, int audiolayer, string audiofile)
{
ulong coroutineId = MODSystem.instance.modSceneController.MODLipSyncInvalidateAndGenerateId(character);
Expand Down Expand Up @@ -924,13 +876,13 @@ public IEnumerator MODDrawLipSync(int character, int audiolayer, string audiofil
switch (exparray[k])
{
case "2":
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "2", exp2, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp2, coroutineId);
break;
case "1":
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "1", exp3, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp3, coroutineId);
break;
case "0":
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "0", exp4, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp4, coroutineId);
break;
}
}
Expand All @@ -939,9 +891,9 @@ public IEnumerator MODDrawLipSync(int character, int audiolayer, string audiofil
}
else
{
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "0", exp4, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp4, coroutineId);
yield return (object)new WaitForSeconds(0.25f);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "1", exp3, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp3, coroutineId);
yield return (object)new WaitForSeconds(0.25f);
int k = 0;
if (GameSystem.Instance.AudioController.IsVoicePlaying(audiolayer))
Expand All @@ -956,14 +908,14 @@ public IEnumerator MODDrawLipSync(int character, int audiolayer, string audiofil
{
break;
}
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "0", exp4, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp4, coroutineId);
yield return (object)new WaitForSeconds(0.25f);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "1", exp3, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp3, coroutineId);
yield return (object)new WaitForSeconds(0.25f);
}
}
}
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "0", exp4, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp4, coroutineId);
}

public void MODLipSyncStart(int character, int audiolayer, string audiofile)
Expand Down
10 changes: 2 additions & 8 deletions MOD.Scripts.Core.Scene/MODSceneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,12 @@ public bool MODLipSyncIsAnimationCurrent(int character, ulong coroutineId)
return coroutineId == MODLipSync_CoroutineId[character];
}

public void MODLipSyncProcess(int charnum, string expressionnum, Texture2D tex2d, ulong coroutineId)
public void MODLipSyncProcess(int charnum, Texture2D tex2d, ulong coroutineId)
{
if (MODLipSyncIsAnimationCurrent(charnum, coroutineId))
{
int layer = MODLipSync_Layer[charnum];
string textureName = MODLipSync_Texture[charnum] + expressionnum;
int x = MODLipSync_X[charnum];
int y = MODLipSync_Y[charnum];
int z = MODLipSync_Z[charnum];
int priority = MODLipSync_Priority[charnum];
int type = MODLipSync_Type[charnum];
GameSystem.Instance.SceneController.MODDrawBustshot(layer, textureName, tex2d, x, y, z, 0, 0, 0, /*move:*/ false, priority, type, 0f, /*isblocking:*/ false);
GameSystem.Instance.SceneController.GetLayer(layer)?.SetPrimaryTexture(tex2d);
}
}
}
Expand Down

0 comments on commit 3f42f27

Please sign in to comment.