Improve RenderManager Object Structure

This commit is contained in:
copecone committed 2026-05-28 13:12:42 +09:00
1 parent 0a798de45c
commit d4b9e4b89c
10 files changed
+130 -108

No files matched your search

+52 -46
View File
@@ -9,23 +9,22 @@ using ADOFAIRenderer.Util.FFmpeg;
using MelonLoader;
using MelonLoader.Utils;
using UnityEngine;
using UnityEngine.Serialization;
namespace ADOFAIRenderer.Component
{
public class RenderManager : MonoBehaviour
{
public static int Countdown;
public static long FrameCount;
public static bool SkipPressToStart;
public static string LevelPath = "";
public static RenderManager Instance = null!;
private static int _originalInputOffset;
private static GameObject? _debugMonitorObj;
private static GameObject? _escapeHandlerObj;
private static string? _currentOutPath;
// Singleton Accessors
public static RenderManager Instance { get; private set; } = null!;
public static bool IsRenderCancelled = false;
public static RenderSettings Configuration;
// Core Render Configuration and Path (OOP Instance Fields)
public int countdown;
public long frameCount;
public bool skipPressToStart;
public string levelPath = "";
public bool isRenderCancelled;
public RenderSettings Configuration;
public struct RenderSettings
{
@@ -55,14 +54,20 @@ namespace ADOFAIRenderer.Component
}
}
public static SortedList<long, byte[]> ImageQueue = new SortedList<long, byte[]>();
public static Thread? RenderThread;
public static long PassCount;
public static bool EndRequested;
public static bool EndSuccessful;
public static long WonFrame = -1;
// Thread and Queue State (OOP Instance Fields)
public SortedList<long, byte[]> ImageQueue = new SortedList<long, byte[]>();
public Thread? RenderThread;
public long passCount;
public bool endRequested;
public bool endSuccessful;
public long wonFrame = -1;
private static bool _renderSetup;
// Private Instance Fields
private int _originalInputOffset;
private GameObject? _debugMonitorObj;
private GameObject? _escapeHandlerObj;
private string? _currentOutPath;
private bool _renderSetup;
private void Awake()
{
@@ -101,7 +106,8 @@ namespace ADOFAIRenderer.Component
RenderMod.FrameCountBase = Time.frameCount;
RenderMod.IsRendering = true;
Countdown = 3; WonFrame = -1;
countdown = 3;
wonFrame = -1;
if (!_escapeHandlerObj)
{
@@ -123,14 +129,14 @@ namespace ADOFAIRenderer.Component
}
else if (scrController.instance.state == States.Won)
{
if (WonFrame == -1)
if (wonFrame == -1)
{
WonFrame = FrameCount;
wonFrame = frameCount;
}
var extraFrames = (long)Math.Ceiling(Configuration.EndWaitTime * Configuration.TargetFPS);
if (FrameCount - WonFrame < extraFrames) return;
if (frameCount - wonFrame < extraFrames) return;
RenderMod.IsRendering = RenderMod.IsCapturing = false;
StopFFmpeg(true);
}
@@ -147,25 +153,25 @@ namespace ADOFAIRenderer.Component
public void SetupGameScene()
{
GCS.customLevelPaths = new[] { LevelPath };
GCS.customLevelPaths = new[] { levelPath };
GCS.checkpointNum = 0;
GCS.customLevelId = "";
GCS.nextSpeedRun = 1;
GCS.customLevelIndex = 0;
ADOBase.loader.LoadSceneWithTransition(WipeDirection.StartsFromRight, "scnGame");
SkipPressToStart = true;
skipPressToStart = true;
_renderSetup = true;
}
private IEnumerator SetupPlay()
{
for (; Countdown > 0; Countdown--)
for (; countdown > 0; countdown--)
{
yield return new WaitForSecondsRealtime(1);
}
FrameCount = 0;
frameCount = 0;
RenderMod.FrameReader?.Dispose();
RenderMod.FrameReader = new FrameReader();
@@ -179,7 +185,7 @@ namespace ADOFAIRenderer.Component
scrConductor.instance.song.time = -1000;
}
private static string FindFFmpegPath()
private string FindFFmpegPath()
{
var isWindows = Application.platform == RuntimePlatform.WindowsPlayer;
var ffmpegName = isWindows ? "ffmpeg.exe" : "ffmpeg";
@@ -218,16 +224,16 @@ namespace ADOFAIRenderer.Component
{
ImageQueue.Clear();
}
PassCount = 0;
IsRenderCancelled = false;
passCount = 0;
isRenderCancelled = false;
RenderMod.IsRenderCancelled = false;
RenderMod.FrameCountForVideo = 0;
RenderMod.LastVideoFrameIndex = -1;
RenderMod.LastRequestedVideoFrameIndex = -1;
RenderMod.RenderCheck = true;
RenderMod.SkipCount = 0;
EndRequested = false;
EndSuccessful = false;
endRequested = false;
endSuccessful = false;
var targetFps = Configuration.TargetFPS;
var videoFps = Configuration.VideoFPS;
@@ -274,16 +280,16 @@ namespace ADOFAIRenderer.Component
{
var firstKey = ImageQueue.Keys[0];
if (firstKey > PassCount && !RenderMod.IsCapturing)
if (firstKey > passCount && !RenderMod.IsCapturing)
{
PassCount = firstKey;
passCount = firstKey;
}
if (firstKey == PassCount)
if (firstKey == passCount)
{
buffer = ImageQueue[firstKey];
ImageQueue.RemoveAt(0);
PassCount++;
passCount++;
}
}
}
@@ -299,14 +305,14 @@ namespace ADOFAIRenderer.Component
continue;
}
if (IsRenderCancelled || RenderMod.IsRenderCancelled)
if (isRenderCancelled || RenderMod.IsRenderCancelled)
{
break;
}
if (EndRequested)
if (endRequested)
{
if (PassCount > RenderMod.LastRequestedVideoFrameIndex)
if (passCount > RenderMod.LastRequestedVideoFrameIndex)
{
break;
}
@@ -316,7 +322,7 @@ namespace ADOFAIRenderer.Component
}
videoFFmpeg.Close();
EndSuccessful = true;
endSuccessful = true;
}
catch (Exception ex)
{
@@ -330,7 +336,7 @@ namespace ADOFAIRenderer.Component
public void CancelRender()
{
RenderMod.IsRendering = RenderMod.IsCapturing = false;
IsRenderCancelled = true;
isRenderCancelled = true;
RenderMod.IsRenderCancelled = true;
StopFFmpeg(false);
@@ -339,13 +345,13 @@ namespace ADOFAIRenderer.Component
private void StopFFmpeg(bool success)
{
EndRequested = true;
endRequested = true;
if (!success)
{
IsRenderCancelled = true;
isRenderCancelled = true;
RenderMod.IsRenderCancelled = true;
}
SkipPressToStart = false;
skipPressToStart = false;
_renderSetup = false;
if (_escapeHandlerObj)
{
@@ -422,13 +428,13 @@ namespace ADOFAIRenderer.Component
}
}
private static IEnumerator StopRenderCoroutine()
private IEnumerator StopRenderCoroutine()
{
yield return new WaitUntil(() => EndSuccessful);
yield return new WaitUntil(() => endSuccessful);
EndRender();
}
private static void EndRender()
private void EndRender()
{
Time.timeScale = 1f;
Time.captureDeltaTime = 0f;