Update Cryville.Common.Logging.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Buffers;
|
||||
using Cryville.Common.Logging;
|
||||
using Cryville.Crtr.Config;
|
||||
using Cryville.Crtr.Event;
|
||||
using Cryville.Crtr.Ruleset;
|
||||
@@ -18,7 +19,6 @@ using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Scripting;
|
||||
using Coroutine = Cryville.Common.Coroutine;
|
||||
using Logger = Cryville.Common.Logging.Logger;
|
||||
using Stopwatch = System.Diagnostics.Stopwatch;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
@@ -44,6 +44,7 @@ namespace Cryville.Crtr {
|
||||
static bool initialized;
|
||||
TextMeshProUGUI logs;
|
||||
TextMeshProUGUI status;
|
||||
BufferedLoggerListener loggerListener;
|
||||
|
||||
static Vector2 screenSize;
|
||||
public static Rect hitRect;
|
||||
@@ -67,7 +68,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
#region MonoBehaviour
|
||||
void Start() {
|
||||
d_addLogEntry = new Action<int, string, string>(AddLogEntry);
|
||||
d_addLogEntry = AddLogEntry;
|
||||
|
||||
var logobj = GameObject.Find("Logs");
|
||||
if (logobj != null)
|
||||
@@ -80,6 +81,8 @@ namespace Cryville.Crtr {
|
||||
OnSettingsUpdate();
|
||||
|
||||
status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>();
|
||||
loggerListener = new BufferedLoggerListener();
|
||||
Game.MainLogger.AddListener(loggerListener);
|
||||
|
||||
try {
|
||||
Play();
|
||||
@@ -101,6 +104,8 @@ namespace Cryville.Crtr {
|
||||
if (loadThread != null) loadThread.Abort();
|
||||
if (inputProxy != null) inputProxy.Dispose();
|
||||
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
|
||||
Game.MainLogger.RemoveListener(loggerListener);
|
||||
loggerListener.Dispose();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
@@ -127,7 +132,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
else if (loadThread != null) LoadUpdate();
|
||||
if (logEnabled) LogUpdate();
|
||||
else Game.MainLogger.Enumerate((level, module, msg) => { });
|
||||
else loggerListener.Enumerate((level, module, msg) => { });
|
||||
}
|
||||
void GameUpdate() {
|
||||
try {
|
||||
@@ -180,7 +185,7 @@ namespace Cryville.Crtr {
|
||||
if (!texloaddone) texLoader.Tick(1.0 / Application.targetFrameRate);
|
||||
if (!loadThread.IsAlive) {
|
||||
if (threadException != null) {
|
||||
Logger.Log("main", 4, "Load/MainThread", "Load failed");
|
||||
Game.MainLogger.Log(4, "Load/MainThread", "Load failed");
|
||||
loadThread = null;
|
||||
Popup.CreateException(threadException);
|
||||
ReturnToMenu();
|
||||
@@ -201,7 +206,7 @@ namespace Cryville.Crtr {
|
||||
readonly StringBuffer logsbuf = new StringBuffer();
|
||||
readonly List<string> logEntries = new List<string>();
|
||||
int logsLength = 0;
|
||||
Action<int, string, string> d_addLogEntry;
|
||||
LogHandler d_addLogEntry;
|
||||
void AddLogEntry(int level, string module, string msg) {
|
||||
string color;
|
||||
switch (level) {
|
||||
@@ -222,7 +227,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
void LogUpdate() {
|
||||
logsbuf.Clear();
|
||||
Game.MainLogger.Enumerate(d_addLogEntry);
|
||||
loggerListener.Enumerate(d_addLogEntry);
|
||||
while (logsLength >= 4096) {
|
||||
logsLength -= logEntries[0].Length;
|
||||
logEntries.RemoveAt(0);
|
||||
@@ -335,7 +340,7 @@ namespace Cryville.Crtr {
|
||||
texloaddone = true;
|
||||
texLoader = null;
|
||||
if (loadThread.IsAlive) {
|
||||
Logger.Log("main", 2, "Game", "Stop requested while the chart is loading. Waiting for the loading thread to exit...");
|
||||
Game.MainLogger.Log(2, "Game", "Stop requested while the chart is loading. Waiting for the loading thread to exit...");
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -433,7 +438,7 @@ namespace Cryville.Crtr {
|
||||
skinFile = skinFile,
|
||||
});
|
||||
|
||||
Logger.Log("main", 0, "Load/MainThread", "Loading textures...");
|
||||
Game.MainLogger.Log(0, "Load/MainThread", "Loading textures...");
|
||||
frames = new Dictionary<string, SpriteFrame>();
|
||||
texs = new Dictionary<string, Texture2D>();
|
||||
var skinDir = skinFile.Directory.FullName;
|
||||
@@ -469,7 +474,7 @@ namespace Cryville.Crtr {
|
||||
var tex = texHandler.texture;
|
||||
tex.wrapMode = TextureWrapMode.Clamp;
|
||||
if (frames.ContainsKey(name)) {
|
||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", name);
|
||||
Game.MainLogger.Log(3, "Load/Prehandle", "Duplicated texture name: {0}", name);
|
||||
}
|
||||
else {
|
||||
frames.Add(name, new SpriteFrame(tex));
|
||||
@@ -477,7 +482,7 @@ namespace Cryville.Crtr {
|
||||
texs.Add(name, tex);
|
||||
}
|
||||
else {
|
||||
Logger.Log("main", 4, "Load/Prehandle", "Unable to load texture: {0}", name);
|
||||
Game.MainLogger.Log(4, "Load/Prehandle", "Unable to load texture: {0}", name);
|
||||
}
|
||||
texLoader.Dispose();
|
||||
texHandler.Dispose();
|
||||
@@ -493,39 +498,39 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
texloaddone = true;
|
||||
stopwatch.Stop();
|
||||
Logger.Log("main", 1, "Load/MainThread", "Main thread done ({0}ms)", stopwatch.Elapsed.TotalMilliseconds);
|
||||
Game.MainLogger.Log(1, "Load/MainThread", "Main thread done ({0}ms)", stopwatch.Elapsed.TotalMilliseconds);
|
||||
yield return 1;
|
||||
}
|
||||
|
||||
IEnumerator<float> Prehandle() {
|
||||
Stopwatch timer = new Stopwatch();
|
||||
timer.Reset(); timer.Start();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
|
||||
Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
|
||||
cbus.BroadcastPreInit();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return 0;
|
||||
Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return 0;
|
||||
using (var pbus = cbus.Clone(17)) {
|
||||
while (pbus.Time != double.PositiveInfinity) {
|
||||
pbus.ForwardOnce();
|
||||
yield return (float)pbus.EventId / pbus.EventCount;
|
||||
}
|
||||
}
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return 1;
|
||||
Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return 1;
|
||||
cbus.BroadcastPostInit();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Seeking to start offset"); yield return 1;
|
||||
Game.MainLogger.Log(0, "Load/Prehandle", "Seeking to start offset"); yield return 1;
|
||||
cbus.ForwardByTime(startOffset);
|
||||
bbus.ForwardByTime(startOffset);
|
||||
Game.AudioSequencer.SeekTime(startOffset, SeekOrigin.Current);
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return 1;
|
||||
Game.MainLogger.Log(0, "Load/Prehandle", "Cleaning up"); yield return 1;
|
||||
if (logEnabled && Settings.Default.HideLogOnPlay) ToggleLogs();
|
||||
Camera.main.cullingMask |= 1;
|
||||
GC.Collect();
|
||||
if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
|
||||
timer.Stop();
|
||||
Logger.Log("main", 1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds); yield return 1;
|
||||
Game.MainLogger.Log(1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds); yield return 1;
|
||||
if (Settings.Default.ClearLogOnPlay) {
|
||||
logEntries.Clear();
|
||||
logsLength = 0;
|
||||
Game.MainLogger.Enumerate((level, module, msg) => { });
|
||||
loggerListener.Enumerate((level, module, msg) => { });
|
||||
logs.text = "";
|
||||
}
|
||||
Game.AudioSequencer.Playing = true;
|
||||
@@ -536,7 +541,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
public void Stop() {
|
||||
try {
|
||||
Logger.Log("main", 1, "Game", "Stopping");
|
||||
Game.MainLogger.Log(1, "Game", "Stopping");
|
||||
Game.AudioClient.Start();
|
||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||
Camera.main.cullingMask &= ~1;
|
||||
@@ -555,7 +560,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
PdtEvaluator.Instance.Reset();
|
||||
motionRegistry = null;
|
||||
Logger.Log("main", 1, "Game", "Stopped");
|
||||
Game.MainLogger.Log(1, "Game", "Stopped");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (!logEnabled) ToggleLogs();
|
||||
@@ -597,7 +602,7 @@ namespace Cryville.Crtr {
|
||||
workerTimer.Start();
|
||||
LoadChart(info);
|
||||
workerTimer.Stop();
|
||||
Logger.Log("main", 1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
|
||||
Game.MainLogger.Log(1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Game.LogException("Load/WorkerThread", "An error occurred while loading the data", ex);
|
||||
@@ -606,7 +611,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
void LoadChart(LoadInfo info) {
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Loading chart: {0}", info.chartFile);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Loading chart: {0}", info.chartFile);
|
||||
|
||||
motionRegistry = new Dictionary<Identifier, MotionRegistry> {
|
||||
{ new Identifier("pt") , new MotionRegistry(typeof(Vec2)) },
|
||||
@@ -627,28 +632,28 @@ namespace Cryville.Crtr {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Applying ruleset (iteration 1)"); loadPregress = .10f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Applying ruleset (iteration 1)"); loadPregress = .10f;
|
||||
pruleset.PrePatch(chart);
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Batching events"); loadPregress = .20f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Batching events"); loadPregress = .20f;
|
||||
var batcher = new EventBatcher(chart);
|
||||
batcher.Forward();
|
||||
cbus = batcher.Batch(); loadPregress = .30f;
|
||||
|
||||
LoadSkin(info.skinFile);
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
|
||||
judge = new Judge(this, pruleset);
|
||||
PdtEvaluator.Instance.ContextJudge = judge;
|
||||
|
||||
inputProxy = new InputProxy(pruleset, judge, screenSize);
|
||||
inputProxy.LoadFrom(_rscfg.inputs);
|
||||
if (!inputProxy.IsCompleted()) {
|
||||
Logger.Log("main", 2, "Game", "Input config not completed. Input disabled");
|
||||
Game.MainLogger.Log(2, "Game", "Input config not completed. Input disabled");
|
||||
inputProxy.Clear();
|
||||
}
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f;
|
||||
var ch = new ChartHandler(chart);
|
||||
cbus.RootState.AttachHandler(ch);
|
||||
foreach (var gs in cbus.RootState.Children) {
|
||||
@@ -666,16 +671,16 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
cbus.AttachSystems(pskin, judge);
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 1)"); loadPregress = .60f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Prehandling (iteration 1)"); loadPregress = .60f;
|
||||
using (var pbus = cbus.Clone(16)) {
|
||||
pbus.Forward();
|
||||
}
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)"); loadPregress = .70f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 1)"); loadPregress = .70f;
|
||||
bbus = cbus.Clone(1, -clippingDist);
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 2)"); loadPregress = .80f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 2)"); loadPregress = .80f;
|
||||
tbus = bbus.Clone(2);
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 3)"); loadPregress = .90f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 3)"); loadPregress = .90f;
|
||||
nbus = bbus.Clone(3);
|
||||
loadPregress = 1;
|
||||
}
|
||||
@@ -683,7 +688,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
void LoadRuleset(FileInfo file) {
|
||||
DirectoryInfo dir = file.Directory;
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Loading ruleset: {0}", file);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Loading ruleset: {0}", file);
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
@@ -701,7 +706,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
void LoadSkin(FileInfo file) {
|
||||
DirectoryInfo dir = file.Directory;
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Loading skin: {0}", file);
|
||||
skin.LoadPdt(dir);
|
||||
pskin = skin.Root;
|
||||
pskin.Optimize(PdtEvaluator.Instance);
|
||||
|
Reference in New Issue
Block a user