Code cleanup.

This commit is contained in:
2023-06-22 13:18:34 +08:00
parent 22cb8f0cb4
commit a7aff4d625
8 changed files with 321 additions and 302 deletions

View File

@@ -66,7 +66,7 @@ namespace Cryville.Crtr.Browsing {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
@@ -93,7 +93,7 @@ namespace Cryville.Crtr.Browsing {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}

View File

@@ -1,5 +1,3 @@
#define BUILD
using Cryville.Common;
using Cryville.Common.Buffers;
using Cryville.Crtr.Config;
@@ -82,7 +80,6 @@ namespace Cryville.Crtr {
status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>();
#if BUILD
try {
Play();
}
@@ -91,7 +88,6 @@ namespace Cryville.Crtr {
Popup.CreateException(ex);
ReturnToMenu();
}
#endif
// Camera.main.RenderToCubemap();
}
@@ -186,9 +182,7 @@ namespace Cryville.Crtr {
Logger.Log("main", 4, "Load/MainThread", "Load failed");
loadThread = null;
Popup.CreateException(threadException);
#if BUILD
ReturnToMenu();
#endif
}
else if (texloaddone) {
if (texLoader == null) Stop();
@@ -377,7 +371,7 @@ namespace Cryville.Crtr {
areaJudgePrecision = 1 << Settings.Default.AreaJudgePrecision;
forceSyncFrames = Settings.Default.ForceSyncFrames;
texloaddone = false;
Game.NetworkTaskWorker.SuspendBackgroundTasks();
Game.SuspendBackgroundTasks();
Game.AudioSession = Game.AudioSequencer.NewSession();
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
@@ -455,7 +449,7 @@ namespace Cryville.Crtr {
for (int i = 0; i < queue.Count; i++) {
#if UNITY_5_4_OR_NEWER
texHandler = new DownloadHandlerTexture();
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + queue[i], "GET", texHandler, null);
texLoader = new UnityWebRequest(PlatformConfig.FileProtocolPrefix + queue[i], "GET", texHandler, null);
texLoader.SendWebRequest();
#else
texLoader = new WWW(Game.FileProtocolPrefix + queue[i]);
@@ -568,10 +562,8 @@ namespace Cryville.Crtr {
started = false;
}
}
Game.NetworkTaskWorker.ResumeBackgroundTasks();
#if BUILD
Game.ResumeBackgroundTasks();
ReturnToMenu();
#endif
}
void OnSettingsUpdate() {
@@ -588,11 +580,9 @@ namespace Cryville.Crtr {
}
Exception threadException;
#if !NO_THREAD
Thread loadThread = null;
volatile float loadPregress;
Stopwatch workerTimer;
#endif
void Load(object _info) {
var info = (LoadInfo)_info;
try {

View File

@@ -22,14 +22,6 @@ namespace Cryville.Crtr {
get;
private set;
}
public static readonly string FileProtocolPrefix
#if UNITY_STANDALONE_WIN
= "file:///";
#elif UNITY_ANDROID
= "file://";
#else
#error No file protocol prefix is defined.
#endif
public static IAudioDeviceManager AudioManager;
public static AudioClient AudioClient;
public static SimpleSequencerSource AudioSequencer;
@@ -129,19 +121,10 @@ namespace Cryville.Crtr {
Settings.Default.Save();
Logger.Log("main", 1, "UI", "Initializing font manager");
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
var fontMatcher = new FallbackListFontMatcher(new FontManagerWindows());
fontMatcher.LoadDefaultWindowsFallbackList();
TMPAutoFont.FontMatcher = fontMatcher;
TMPAutoFont.DefaultShader = Resources.Load<Shader>("TextMesh Pro/Shaders/TMP_SDF SSD");
#elif UNITY_ANDROID
var fontMatcher = new FallbackListFontMatcher(new FontManagerAndroid());
fontMatcher.LoadDefaultAndroidFallbackList();
TMPAutoFont.FontMatcher = fontMatcher;
TMPAutoFont.DefaultShader = Resources.Load<Shader>("TextMesh Pro/Shaders/TMP_SDF-Mobile SSD");
#else
#error No font manager initialization logic.
#endif
TMPAutoFont.FontMatcher = new FallbackListFontMatcher(PlatformConfig.FontManager) {
MapScriptToTypefaces = PlatformConfig.ScriptFontMap
};
TMPAutoFont.DefaultShader = Resources.Load<Shader>(PlatformConfig.TextShader);
Logger.Log("main", 1, "Game", "Initialized");
}
@@ -181,5 +164,14 @@ namespace Cryville.Crtr {
}
Logger.Log("main", l, "Internal", "{0}\n{1}", condition, stackTrace);
}
public static void SuspendBackgroundTasks() {
NetworkTaskWorker.SuspendBackgroundTasks();
Dialog.Suppress();
}
public static void ResumeBackgroundTasks() {
Dialog.Release();
NetworkTaskWorker.ResumeBackgroundTasks();
}
}
}

View File

@@ -262,10 +262,9 @@ namespace Cryville.Crtr {
frame.Vector = vec;
}
else frame = rc.InverseTransform(frame);
bool locked = false;
Monitor.Enter(_etor);
try {
Profiler.BeginSample("InputProxy.OnInput");
Monitor.Enter(_etor, ref locked);
InputProxyEntry proxy;
if (_sproxies.TryGetValue(id.Source, out proxy)) {
float ft, tt = (float)GetSyncedTime(frame.Time, id.Source.Handler);
@@ -289,8 +288,8 @@ namespace Cryville.Crtr {
}
}
finally {
if (locked) Monitor.Exit(_etor);
Profiler.EndSample();
Monitor.Exit(_etor);
}
}
static readonly int _var_fv = IdentifierManager.Shared.Request("input_vec_from");

View File

@@ -58,7 +58,7 @@ namespace Cryville.Crtr {
void OnEnable() {
Application.targetFrameRate = 60;
if (animatorState != null) m_targetAnimator.PlayInFixedTime(animatorState, 0, 0);
Game.NetworkTaskWorker.ResumeBackgroundTasks();
Game.ResumeBackgroundTasks();
}
#pragma warning restore IDE0051

View File

@@ -0,0 +1,27 @@
using Cryville.Common.Font;
using System.Collections.Generic;
namespace Cryville.Crtr {
internal static class PlatformConfig {
#if UNITY_STANDALONE_WIN
public static readonly string Name = "windows";
#elif UNITY_ANDROID
public static readonly string Name = "android";
#else
#error Unknown platform.
#endif
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
public static readonly string FileProtocolPrefix = "file:///";
public static readonly FontManager FontManager = new FontManagerWindows();
public static readonly Dictionary<string, List<string>> ScriptFontMap = FallbackListFontMatcher.GetDefaultWindowsFallbackMap();
public static readonly string TextShader = "TextMesh Pro/Shaders/TMP_SDF SSD";
#elif UNITY_ANDROID
public static readonly string FileProtocolPrefix = "file://";
public static readonly FontManager FontManager = new FontManagerAndroid();
public static readonly Dictionary<string, List<string>> ScriptFontMap = FallbackListFontMatcher.GetDefaultAndroidFallbackMap();
public static readonly string TextShader = "TextMesh Pro/Shaders/TMP_SDF-Mobile SSD";
#else
#error Unknown platform.
#endif
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5b9be7f84b72ac9468dacec2d44003a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: