Update Cryville.Common.Logging.

This commit is contained in:
2023-11-20 20:21:21 +08:00
parent e2c58c708f
commit c2e94afc1c
24 changed files with 280 additions and 140 deletions

View File

@@ -1,4 +1,3 @@
using Cryville.Common.Logging;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -15,7 +14,7 @@ namespace Cryville.Common.Font {
map1.Add(f.FullName, f);
}
else {
Logger.Log("main", 3, "UI", "Discarding a font with a duplicate full name {0}", f.FullName);
Shared.Logger.Log(3, "UI", "Discarding a font with a duplicate full name {0}", f.FullName);
continue;
}
List<Typeface> set2;

View File

@@ -1,4 +1,3 @@
using Cryville.Common.Logging;
using Cryville.Culture;
using System;
using System.Collections.Generic;
@@ -311,7 +310,7 @@ namespace Cryville.Common.Font {
bool flag = false;
while (_matcher.Match(lang, supported, out var match, out var distance)) {
if (distance > 40) break;
Logger.Log("main", 0, "UI", "Matching fonts for language {0}, distance = {1}", match, distance);
Shared.Logger.Log(0, "UI", "Matching fonts for language {0}, distance = {1}", match, distance);
if (match.Script.Equals(UltimateFallbackScript, StringComparison.OrdinalIgnoreCase)) {
flag = true;
}
@@ -322,7 +321,7 @@ namespace Cryville.Common.Font {
supported.Remove(match);
}
if (flag) yield break;
Logger.Log("main", 0, "UI", "Matching fallback fonts");
Shared.Logger.Log(0, "UI", "Matching fallback fonts");
foreach (var typeface in EnumerateTypefaces(MapScriptToTypefaces[UltimateFallbackScript], distinctFamily)) {
yield return typeface;
}

View File

@@ -1,4 +1,3 @@
using Cryville.Common.Logging;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
@@ -35,7 +34,7 @@ namespace Cryville.Common.Network.Http11 {
origPort = _baseUri.Port;
Headers = new Dictionary<string, string>();
_proxied = GetProxy(ref _directHost, ref _directPort);
Logger.Log("main", 0, "Network", "Connecting to {0}:{1}", DirectHost, DirectPort);
Shared.Logger.Log(0, "Network", "Connecting to {0}:{1}", DirectHost, DirectPort);
TcpClient = new TcpClient(DirectHost, DirectPort);
}
@@ -96,7 +95,7 @@ namespace Cryville.Common.Network.Http11 {
writer.Flush();
}
var response = new Http11Response(stream);
Logger.Log("main", 0, "Network", "{0}", response);
Shared.Logger.Log(0, "Network", "{0}", response);
return response;
}

View File

@@ -1,5 +1,4 @@
using Cryville.Common.Collections;
using Cryville.Common.Logging;
using Cryville.Common.Reflection;
using System;
using System.Collections.Generic;
@@ -203,7 +202,7 @@ namespace Cryville.Common.Pdt {
switch (GetIdentifier()) {
case "ver":
ws();
Logger.Log("main", 3, "PDT", "Legacy PDT directive #ver={0} found. Ignoring.", GetNumber());
Shared.Logger.Log(3, "PDT", "Legacy PDT directive #ver={0} found. Ignoring.", GetNumber());
break;
case "format":
ws();

View File

@@ -0,0 +1,7 @@
using Cryville.Common.Logging;
namespace Cryville.Common {
public static class Shared {
public static readonly Logger Logger = new Logger();
}
}

View File

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

View File

@@ -8,7 +8,6 @@ using TMPro;
using UnityEngine;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.TextCore.Text;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Common.Unity.UI {
[RequireComponent(typeof(TextMeshProUGUI))]
@@ -32,14 +31,14 @@ namespace Cryville.Common.Unity.UI {
else if (DefaultShader) ifont.material.shader = DefaultShader;
if (_font == null) {
_font = ifont;
Logger.Log("main", 1, "UI", "Using main font: {0}", typeface.FullName);
Shared.Logger.Log(1, "UI", "Using main font: {0}", typeface.FullName);
if (MaxFallbackCount <= 0) break;
}
else {
if (_font.fallbackFontAssetTable == null)
_font.fallbackFontAssetTable = new List<FontAsset>();
_font.fallbackFontAssetTable.Add(ifont);
Logger.Log("main", 1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
Shared.Logger.Log(1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
}
}

View File

@@ -1,4 +1,3 @@
using Cryville.Common.Logging;
using Cryville.Crtr.Extension;
using Mono.Cecil;
using System;
@@ -36,7 +35,7 @@ namespace Cryville.Crtr.Browsing {
modules.Enqueue(new ModuleItem(extension.OpenRead()));
}
catch (Exception ex) {
Logger.Log("main", 4, "Extension", "Failed to load DLL {0}: {1}", extension, ex);
Game.MainLogger.Log(4, "Extension", "Failed to load DLL {0}: {1}", extension, ex);
}
}
}
@@ -68,10 +67,10 @@ namespace Cryville.Crtr.Browsing {
LoadExtension(type);
}
}
Logger.Log("main", 1, "Extension", "Loaded module {0}", module.Definition.Name);
Game.MainLogger.Log(1, "Extension", "Loaded module {0}", module.Definition.Name);
}
catch (Exception ex) {
Logger.Log("main", 4, "Extension", "An error occurred while trying to load module {0}: {1}", module.Definition.Name, ex);
Game.MainLogger.Log(4, "Extension", "An error occurred while trying to load module {0}: {1}", module.Definition.Name, ex);
}
finally {
module.Definition.Dispose();
@@ -89,7 +88,7 @@ namespace Cryville.Crtr.Browsing {
missingList.Add(reference.Name);
}
}
Logger.Log("main", 4, "Extension", "Could not load the module {0} because the following dependencies were missing: {1}", module.Definition.Name, missingList.Aggregate((current, next) => current + ", " + next));
Game.MainLogger.Log(4, "Extension", "Could not load the module {0} because the following dependencies were missing: {1}", module.Definition.Name, missingList.Aggregate((current, next) => current + ", " + next));
module.Definition.Dispose();
module.Stream.Dispose();
}
@@ -128,10 +127,10 @@ namespace Cryville.Crtr.Browsing {
if (name != null && path != null) _localRes.Add(name, path);
}
}
Logger.Log("main", 1, "Extension", "Loaded extension {0}", type);
Game.MainLogger.Log(1, "Extension", "Loaded extension {0}", type);
}
catch (Exception ex) {
Logger.Log("main", 4, "Extension", "Failed to load extension {0}: {1}", type, ex);
Game.MainLogger.Log(4, "Extension", "Failed to load extension {0}: {1}", type, ex);
}
}
}

View File

@@ -11,7 +11,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Browsing {
internal class LegacyResourceManager : IPathedResourceManager<ChartDetail> {
@@ -41,7 +40,7 @@ namespace Cryville.Crtr.Browsing {
}
void OnFileWatcherError(object sender, ErrorEventArgs e) {
Logger.Log("main", 4, "Data", "An error occurred while watching file changes: {0}", e.GetException());
Game.MainLogger.Log(4, "Data", "An error occurred while watching file changes: {0}", e.GetException());
}
void OnFileChanged(object sender, FileSystemEventArgs e) {
@@ -235,13 +234,13 @@ namespace Cryville.Crtr.Browsing {
void LogAndPopup(int level, string format, params object[] args) {
var msg = string.Format(format, args);
Logger.Log("main", level, "Resource", msg);
Game.MainLogger.Log(level, "Resource", msg);
Popup.Create(msg);
}
void LogAndPopupExtra(int level, object extraLog, string format, params object[] args) {
var msg = string.Format(format, args);
Logger.Log("main", level, "Resource", "{0}\n{1}", msg, extraLog);
Game.MainLogger.Log(level, "Resource", "{0}\n{1}", msg, extraLog);
Popup.Create(msg);
}

View File

@@ -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);

View File

@@ -5,7 +5,6 @@ using System;
using System.IO;
using System.Text;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Config.UI {
public class ConfigPanelMaster : MonoBehaviour {
@@ -74,7 +73,7 @@ namespace Cryville.Crtr.Config.UI {
}
catch (Exception ex) {
Popup.CreateException(ex);
Logger.Log("main", 4, "Config", "An error occurred while loading the config: {0}", ex);
Game.MainLogger.Log(4, "Config", "An error occurred while loading the config: {0}", ex);
m_menu.Back();
}
}

View File

@@ -5,7 +5,6 @@
#if COMPILE
using Discord;
using System;
using Logger = Cryville.Common.Logging.Logger;
#endif
using UnityEngine;
@@ -25,7 +24,7 @@ namespace Cryville.Crtr {
launchTime = (long)(DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds;
try {
dc = new Discord.Discord(CLIENT_ID, (UInt64)CreateFlags.NoRequireDiscord);
Logger.Log("main", 1, "Discord", "Connected to Discord");
Game.MainLogger.Log(1, "Discord", "Connected to Discord");
am = dc.GetActivityManager();
SetIdle();
}
@@ -34,7 +33,7 @@ namespace Cryville.Crtr {
dc.Dispose();
dc = null;
}
Logger.Log("main", 3, "Discord", "Cannot connect to Discord");
Game.MainLogger.Log(3, "Discord", "Cannot connect to Discord");
}
}
@@ -46,7 +45,7 @@ namespace Cryville.Crtr {
catch (ResultException ex) {
dc.Dispose();
dc = null;
Logger.Log("main", 4, "Discord", "An error occurred while running callbacks: {0}", ex);
Game.MainLogger.Log(4, "Discord", "An error occurred while running callbacks: {0}", ex);
}
}

View File

@@ -43,7 +43,9 @@ namespace Cryville.Crtr {
DefaultValueHandling = DefaultValueHandling.Ignore,
};
public static BufferedLogger MainLogger { get; private set; }
public static Logger MainLogger { get; private set; }
static FileStream _logFileStream;
static StreamLoggerListener _logWriter;
static bool _init;
public static void Init() {
@@ -53,25 +55,41 @@ namespace Cryville.Crtr {
bool _bcflag = new Version(Settings.Default.LastRunVersion) < new Version("0.4");
if (_bcflag) Settings.Default.Reset();
Logger.SetLogPath(Settings.Default.GameDataPath + "/logs");
MainLogger = new BufferedLogger();
Application.logMessageReceivedThreaded += OnLog;
Logger.Create("main", MainLogger);
Logger.Log("main", 1, "Game", "Game Version: {0}", Application.version);
Logger.Log("main", 1, "Game", "Unity Version: {0}", Application.unityVersion);
Logger.Log("main", 1, "Game", "Operating System: {0}, Unity = {1}, Family = {2}", Environment.OSVersion, SystemInfo.operatingSystem, SystemInfo.operatingSystemFamily);
Logger.Log("main", 1, "Game", "Platform: Build = {0}, Unity = {1}", PlatformConfig.Name, Application.platform);
Logger.Log("main", 1, "Game", "Culture: {0}, UI = {1}, System = {2}, Unity = {3}", CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture, CultureInfo.InstalledUICulture, Application.systemLanguage);
Logger.Log("main", 1, "Game", "Device: Model = {0}, Name = {1}, Type = {2}", SystemInfo.deviceModel, SystemInfo.deviceName, SystemInfo.deviceType);
Logger.Log("main", 1, "Game", "Graphics: Name = {0}, Type = {1}, Vendor = {2}, Version = {3}", SystemInfo.graphicsDeviceName, SystemInfo.graphicsDeviceType, SystemInfo.graphicsDeviceVendor, SystemInfo.graphicsDeviceVersion);
Logger.Log("main", 1, "Game", "Processor: Count = {0}, Frequency = {1}MHz, Type = {2}", SystemInfo.processorCount, SystemInfo.processorFrequency, SystemInfo.processorType);
if (_bcflag) Logger.Log("main", 2, "Game", "Reset all settings");
GameDataPath = Settings.Default.GameDataPath;
UnityDataPath = Application.dataPath;
var logPath = Directory.CreateDirectory(Path.Combine(GameDataPath, "logs"));
_logFileStream = new FileStream(
Path.Combine(
logPath.FullName,
string.Format(
CultureInfo.InvariantCulture,
"{0}.log",
(int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
)
),
FileMode.Create, FileAccess.Write, FileShare.Read
);
_logWriter = new StreamLoggerListener(_logFileStream) { AutoFlush = true };
MainLogger = new Logger();
var listener = new InstantLoggerListener();
listener.Log += MainLogger.Log;
Common.Shared.Logger.AddListener(listener);
Input.Shared.Logger.AddListener(listener);
MainLogger.AddListener(_logWriter);
Application.logMessageReceivedThreaded += OnInternalLog;
MainLogger.Log(1, "Game", "Game Version: {0}", Application.version);
MainLogger.Log(1, "Game", "Unity Version: {0}", Application.unityVersion);
MainLogger.Log(1, "Game", "Operating System: {0}, Unity = {1}, Family = {2}", Environment.OSVersion, SystemInfo.operatingSystem, SystemInfo.operatingSystemFamily);
MainLogger.Log(1, "Game", "Platform: Build = {0}, Unity = {1}", PlatformConfig.Name, Application.platform);
MainLogger.Log(1, "Game", "Culture: {0}, UI = {1}, System = {2}, Unity = {3}", CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture, CultureInfo.InstalledUICulture, Application.systemLanguage);
MainLogger.Log(1, "Game", "Device: Model = {0}, Name = {1}, Type = {2}", SystemInfo.deviceModel, SystemInfo.deviceName, SystemInfo.deviceType);
MainLogger.Log(1, "Game", "Graphics: Name = {0}, Type = {1}, Vendor = {2}, Version = {3}", SystemInfo.graphicsDeviceName, SystemInfo.graphicsDeviceType, SystemInfo.graphicsDeviceVendor, SystemInfo.graphicsDeviceVersion);
MainLogger.Log(1, "Game", "Processor: Count = {0}, Frequency = {1}MHz, Type = {2}", SystemInfo.processorCount, SystemInfo.processorFrequency, SystemInfo.processorType);
if (_bcflag) MainLogger.Log(2, "Game", "Reset all settings");
#if UNITY_ANDROID && !UNITY_EDITOR
JavaVMManager.Register(JniInvoke.Instance);
#endif
@@ -120,14 +138,14 @@ namespace Cryville.Crtr {
AudioManager = EngineBuilder.Create();
if (AudioManager == null) {
Dialog.Show(null, "Fatal error: Cannot initialize audio engine");
Logger.Log("main", 5, "Audio", "Cannot initialize audio engine");
MainLogger.Log(5, "Audio", "Cannot initialize audio engine");
}
else {
Logger.Log("main", 1, "Audio", "Using audio API: {0}", AudioManager.GetType().Namespace);
MainLogger.Log(1, "Audio", "Using audio API: {0}", AudioManager.GetType().Namespace);
AudioDevice = AudioManager.GetDefaultDevice(DataFlow.Out);
AudioClient = AudioDevice.Connect(AudioDevice.DefaultFormat, AudioDevice.MinimumBufferSize + AudioDevice.BurstSize);
Logger.Log(
"main", 1, "Audio",
MainLogger.Log(
1, "Audio",
"Audio Output = {{ Name = \"{0}\", BurstSize = {1}, Format = {2}, BufferSize = {3} }}",
AudioDevice.Name, AudioDevice.BurstSize, AudioClient.Format, AudioClient.BufferSize
);
@@ -140,8 +158,8 @@ namespace Cryville.Crtr {
}
catch (Exception ex) {
Dialog.Show(null, "An error occurred while trying to initialize the recommended audio engine\nTrying to use fallback audio engines");
Logger.Log("main", 4, "Audio", "An error occurred when initializing the audio engine: {0}", ex);
Logger.Log("main", 2, "Audio", "Trying to use fallback audio engines");
MainLogger.Log(4, "Audio", "An error occurred when initializing the audio engine: {0}", ex);
MainLogger.Log(2, "Audio", "Trying to use fallback audio engines");
EngineBuilder.Engines.Remove(AudioManager.GetType());
}
}
@@ -159,7 +177,7 @@ namespace Cryville.Crtr {
Settings.Default.LastRunVersion = Application.version;
Settings.Default.Save();
Logger.Log("main", 1, "UI", "Initializing font manager");
MainLogger.Log(1, "UI", "Initializing font manager");
foreach (var res in Resources.LoadAll<TextAsset>("cldr/common/validity")) {
IdValidity.Load(LoadXmlDocument(res));
}
@@ -171,7 +189,7 @@ namespace Cryville.Crtr {
};
TMPAutoFont.DefaultShader = Resources.Load<Shader>(PlatformConfig.TextShader);
Logger.Log("main", 1, "Game", "Initialized");
MainLogger.Log(1, "Game", "Initialized");
}
static readonly Encoding _encoding = new UTF8Encoding(false, true);
@@ -194,7 +212,7 @@ namespace Cryville.Crtr {
if (_shutdown) return;
_shutdown = true;
Logger.Log("main", 1, "Game", "Shutting down");
MainLogger.Log(1, "Game", "Shutting down");
try {
AudioClient.Dispose();
AudioSequencer.Dispose();
@@ -205,15 +223,16 @@ namespace Cryville.Crtr {
LogException("Game", "An error occurred while shutting down", ex);
}
finally {
Logger.Close();
_logWriter.Dispose();
_logFileStream.Dispose();
}
}
public static void LogException(string module, string prefix, Exception ex) {
Logger.Log("main", 4, module, "{0}: {1}", prefix, ex);
MainLogger.Log(4, module, "{0}: {1}", prefix, ex);
}
static void OnLog(string condition, string stackTrace, LogType type) {
static void OnInternalLog(string condition, string stackTrace, LogType type) {
int l;
switch (type) {
case LogType.Log: l = 1; break;
@@ -223,7 +242,7 @@ namespace Cryville.Crtr {
case LogType.Exception: l = 4; break;
default: l = 1; break;
}
Logger.Log("main", l, "Internal", "{0}\n{1}", condition, stackTrace);
MainLogger.Log(l, "Internal", "{0}\n{1}", condition, stackTrace);
}
public static void SuspendBackgroundTasks() {

View File

@@ -13,7 +13,6 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
using ThreadPriority = System.Threading.ThreadPriority;
namespace Cryville.Crtr.Network {
@@ -39,10 +38,10 @@ namespace Cryville.Crtr.Network {
void ThreadLogic() {
try {
CheckVersion();
Logger.Log("main", 0, "Network", "Update checker exited normally");
Game.MainLogger.Log(0, "Network", "Update checker exited normally");
}
catch (Exception ex) {
Logger.Log("main", 4, "Network", "An error occurred while checking for update: {0}", ex);
Game.MainLogger.Log(4, "Network", "An error occurred while checking for update: {0}", ex);
Dialog.Show(null, "Failed to check for update.");
}
}

View File

@@ -8,7 +8,6 @@ using System.Runtime.Serialization;
using System.Threading;
using UnityEngine;
using UnityEngine.Profiling;
using Logger = Cryville.Common.Logging.Logger;
using RVector4 = UnityEngine.Vector4;
namespace Cryville.Crtr.Ruleset {
@@ -48,7 +47,7 @@ namespace Cryville.Crtr.Ruleset {
foreach (var cfg in config) {
var handler = Game.InputManager.GetHandlerByTypeName(cfg.Value.handler);
if (handler == null) {
Logger.Log("main", 3, "Input", "Uninitialized or unknown handler in ruleset config: {0}", cfg.Value.handler);
Game.MainLogger.Log(3, "Input", "Uninitialized or unknown handler in ruleset config: {0}", cfg.Value.handler);
continue;
}
Set(new InputProxyEntry {

View File

@@ -1,7 +1,6 @@
using Cryville.Common;
using System;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Skin.Components {
public class SkinAnimation : SkinComponent {
@@ -30,7 +29,7 @@ namespace Cryville.Crtr.Skin.Components {
var id = new Identifier(value);
AnimationSpan anim;
if (!ChartPlayer.pskin.animations.TryGetValue(id, out anim)) {
Logger.Log("main", 4, "Skin", "Animation {0} not found", id.Name);
Game.MainLogger.Log(4, "Skin", "Animation {0} not found", id.Name);
_anim = null;
return;
}

View File

@@ -1,6 +1,5 @@
using System;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Skin.Components {
public class SpriteInfo {
@@ -40,7 +39,7 @@ namespace Cryville.Crtr.Skin.Components {
Frame = ChartPlayer.frames[FrameName];
}
else {
Logger.Log("main", 4, "Skin", "Texture {0} not found", FrameName);
Game.MainLogger.Log(4, "Skin", "Texture {0} not found", FrameName);
Frame = null;
}
}

View File

@@ -3,7 +3,6 @@ using Cryville.Common.Pdt;
using System;
using System.Collections.Generic;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Skin.Components {
public class SpriteText : SpriteBase {
@@ -120,7 +119,7 @@ namespace Cryville.Crtr.Skin.Components {
foreach (var c in m_value) {
SpriteInfo f;
if (!m_frames.TryGetValue(c, out f)) {
Logger.Log("main", 3, "Skin", "Could not render the character '{0}' in the string \"{1}\" on the text component because no image is assigned to that character.", c, m_value);
Game.MainLogger.Log(3, "Skin", "Could not render the character '{0}' in the string \"{1}\" on the text component because no image is assigned to that character.", c, m_value);
continue;
}
var t = f.Frame.Texture;

View File

@@ -45,7 +45,7 @@ namespace Cryville.Input.Unity.Android {
Batch(timeSecs);
}
catch (Exception ex) {
Logger.Log("main", 4, "Input", "An error occurred while handling an Android sensor event: {0}", ex);
Shared.Logger.Log(4, "Input", "An error occurred while handling an Android sensor event: {0}", ex);
}
}
}

View File

@@ -52,7 +52,7 @@ namespace Cryville.Input.Unity.Android {
}
}
catch (Exception ex) {
Logger.Log("main", 4, "Input", "An error occurred while handling an Android touch event: {0}", ex);
Shared.Logger.Log(4, "Input", "An error occurred while handling an Android touch event: {0}", ex);
}
}
}

View File

@@ -9,75 +9,177 @@
A logger.
</summary>
</member>
<member name="M:Cryville.Common.Logging.Logger.SetLogPath(System.String)">
<member name="M:Cryville.Common.Logging.Logger.AddListener(Cryville.Common.Logging.LoggerListener)">
<summary>
Sets the path where the log files shall be stored.
Attaches a listener to the logger.
</summary>
<param name="path">The path.</param>
<param name="listener">The logger listener.</param>
</member>
<member name="M:Cryville.Common.Logging.Logger.Log(System.String,System.Int32,System.String,System.String,System.Object[])">
<member name="M:Cryville.Common.Logging.Logger.RemoveListener(Cryville.Common.Logging.LoggerListener)">
<summary>
Logs to the specified logger.
Detaches a listener from the logger.
</summary>
<param name="listener">The logger listener.</param>
</member>
<member name="M:Cryville.Common.Logging.Logger.Log(System.Int32,System.String,System.String,System.Object[])">
<summary>
Logs to the logger.
</summary>
<param name="key">The key of the logger.</param>
<param name="level">The severity level.</param>
<param name="module">The module that is logging.</param>
<param name="category">The category.</param>
<param name="format">The format string.</param>
<param name="args">The arguments for formatting.</param>
</member>
<member name="M:Cryville.Common.Logging.Logger.Create(System.String,Cryville.Common.Logging.Logger)">
<member name="M:Cryville.Common.Logging.Logger.Log(System.Int32,System.String,System.IFormatProvider,System.String,System.Object[])">
<summary>
Adds a created logger to the shared logger manager.
</summary>
<param name="key">The key of the logger.</param>
<param name="logger">The logger.</param>
</member>
<member name="M:Cryville.Common.Logging.Logger.Close">
<summary>
Closes all loggers and related file streams.
Logs to the logger.
</summary>
<param name="level">The severity level.</param>
<param name="category">The category.</param>
<param name="provider">The format provider.</param>
<param name="format">The format string.</param>
<param name="args">The arguments for formatting.</param>
</member>
<member name="M:Cryville.Common.Logging.Logger.Log(System.Int32,System.String,System.String)">
<summary>
Logs to the logger.
</summary>
<param name="level">The severity level.</param>
<param name="module">The module that is logging.</param>
<param name="msg">The message.</param>
<param name="category">The category.</param>
<param name="message">The message.</param>
</member>
<member name="T:Cryville.Common.Logging.InstantLogger">
<member name="M:Cryville.Common.Logging.Logger.Log(System.Int32,System.String,System.Char[])">
<summary>
A <see cref="T:Cryville.Common.Logging.Logger" /> that calls a callback function on log.
Logs to the logger.
</summary>
<param name="level">The severity level.</param>
<param name="category">The category.</param>
<param name="message">An array of <see cref="T:System.Char" /> containing the message.</param>
</member>
<member name="M:Cryville.Common.Logging.Logger.Log(System.Int32,System.String,System.Char[],System.Int32,System.Int32)">
<summary>
Logs to the logger.
</summary>
<param name="level">The severity level.</param>
<param name="category">The category.</param>
<param name="message">An array of <see cref="T:System.Char" /> containing the message.</param>
<param name="index">A zero-based index of the first character of the message within <paramref name="message" />.</param>
<param name="length">The length of the message.</param>
</member>
<member name="M:Cryville.Common.Logging.Logger.Log(System.Int32,System.String,System.Char*,System.Int32)">
<summary>
Logs to the logger.
</summary>
<param name="level">The severity level.</param>
<param name="category">The category.</param>
<param name="message">A pointer to the first character of the message.</param>
<param name="length">The length of the message.</param>
</member>
<member name="T:Cryville.Common.Logging.LoggerListener">
<summary>
A logger listener.
</summary>
</member>
<member name="M:Cryville.Common.Logging.InstantLogger.#ctor(System.Action{System.Int32,System.String,System.String})">
<member name="M:Cryville.Common.Logging.LoggerListener.Dispose(System.Boolean)">
<summary>
Creates an instance of the <see cref="T:Cryville.Common.Logging.InstantLogger" /> class.
Closes the logger listener and cleans up all the resources.
</summary>
<param name="callback">The callback function.</param>
<exception cref="T:System.ArgumentNullException"><paramref name="callback" /> is <see langword="null" />.</exception>
<param name="disposing">Whether to clean up managed resources.</param>
</member>
<member name="M:Cryville.Common.Logging.InstantLogger.Log(System.Int32,System.String,System.String)">
<member name="M:Cryville.Common.Logging.LoggerListener.Dispose">
<summary>
Closes the logger listener.
</summary>
</member>
<member name="M:Cryville.Common.Logging.LoggerListener.OnLog(System.Int32,System.String,System.String)">
<summary>
Handles an incoming log.
</summary>
<param name="level">The severity level.</param>
<param name="category">The category.</param>
<param name="message">The message.</param>
</member>
<member name="M:Cryville.Common.Logging.LoggerListener.OnLog(System.Int32,System.String,System.Char[],System.Int32,System.Int32)">
<summary>
Handles an incoming log.
</summary>
<param name="level">The severity level.</param>
<param name="category">The category.</param>
<param name="message">An array of <see cref="T:System.Char" /> containing the message.</param>
<param name="index">A zero-based index of the first character of the message within <paramref name="message" />.</param>
<param name="length">The length of the message.</param>
</member>
<member name="M:Cryville.Common.Logging.LoggerListener.OnLog(System.Int32,System.String,System.Char*,System.Int32)">
<summary>
Handles an incoming log.
</summary>
<param name="level">The severity level.</param>
<param name="category">The category.</param>
<param name="message">A pointer to the first character of the message.</param>
<param name="length">The length of the message.</param>
</member>
<member name="T:Cryville.Common.Logging.InstantLoggerListener">
<summary>
A <see cref="T:Cryville.Common.Logging.LoggerListener" /> that calls a callback function on log.
</summary>
</member>
<member name="E:Cryville.Common.Logging.InstantLoggerListener.Log">
<summary>
Occurs when a log is logged to the logger.
</summary>
</member>
<member name="M:Cryville.Common.Logging.InstantLoggerListener.OnLog(System.Int32,System.String,System.String)">
<inheritdoc />
</member>
<member name="T:Cryville.Common.Logging.BufferedLogger">
<member name="T:Cryville.Common.Logging.BufferedLoggerListener">
<summary>
A <see cref="T:Cryville.Common.Logging.Logger" /> that buffers the logs for enumeration.
A <see cref="T:Cryville.Common.Logging.LoggerListener" /> that buffers the logs for enumeration.
</summary>
</member>
<member name="M:Cryville.Common.Logging.BufferedLogger.#ctor">
<summary>
Creates an instance of the <see cref="T:Cryville.Common.Logging.BufferedLogger" /> class.
</summary>
</member>
<member name="M:Cryville.Common.Logging.BufferedLogger.Log(System.Int32,System.String,System.String)">
<member name="M:Cryville.Common.Logging.BufferedLoggerListener.OnLog(System.Int32,System.String,System.String)">
<inheritdoc />
</member>
<member name="M:Cryville.Common.Logging.BufferedLogger.Enumerate(System.Action{System.Int32,System.String,System.String})">
<member name="M:Cryville.Common.Logging.BufferedLoggerListener.Enumerate(Cryville.Common.Logging.LogHandler)">
<summary>
Enumerates the buffered logs.
</summary>
<param name="callback">The callback function to receive the logs.</param>
</member>
<member name="T:Cryville.Common.Logging.StreamLoggerListener">
<summary>
A <see cref="T:Cryville.Common.Logging.LoggerListener" /> that writes logs into a stream.
</summary>
<param name="stream">The stream.</param>
<param name="encoding">The encoding.</param>
</member>
<member name="M:Cryville.Common.Logging.StreamLoggerListener.#ctor(System.IO.Stream,System.Text.Encoding)">
<summary>
A <see cref="T:Cryville.Common.Logging.LoggerListener" /> that writes logs into a stream.
</summary>
<param name="stream">The stream.</param>
<param name="encoding">The encoding.</param>
</member>
<member name="M:Cryville.Common.Logging.StreamLoggerListener.#ctor(System.IO.Stream)">
<summary>
Creates an instance of the <see cref="T:Cryville.Common.Logging.StreamLoggerListener" /> class.
</summary>
<param name="stream">The stream.</param>
</member>
<member name="P:Cryville.Common.Logging.StreamLoggerListener.AutoFlush">
<summary>
Whether to flush the stream every time a log is written.
</summary>
</member>
<member name="M:Cryville.Common.Logging.StreamLoggerListener.OnLog(System.Int32,System.String,System.String)">
<inheritdoc />
</member>
<member name="T:Cryville.Common.Logging.LogHandler">
<summary>
Represents the method that will handle a log.
</summary>
<param name="level">The severity level.</param>
<param name="category">The category.</param>
<param name="message">The message.</param>
</member>
</members>
</doc>

Binary file not shown.

View File

@@ -537,6 +537,16 @@
反转 W 轴。
</summary>
</member>
<member name="T:Cryville.Input.Shared">
<summary>
库的共享对象。
</summary>
</member>
<member name="F:Cryville.Input.Shared.Logger">
<summary>
主日志记录器。
</summary>
</member>
<member name="T:Cryville.Input.SimpleInputConsumer">
<summary>
一个接收输入帧的简易输入接收器。