Skip to content

Commit

Permalink
0.6.0.37 - text console logging enhancement (#779)
Browse files Browse the repository at this point in the history
- [Fix] Saves.db3 failures no longer cause crashes
- [Fix] Prevent crashes if FX Script.lua has Lua errors
- [Fix] Gameplay debug info now shows at the right place
- [Feat] LogNotification messages now show on screen top (FX and BG Lua script error, preimage-not-found warning, complex number format warning, modal-window-not-closed error, TJA parsing error)
- [Feat] BG Lua script errors are now logged
- [Feat] TJA parsing errors are now logged and as warnings.
- [Feat] TextConsole messages now respect to font height
  • Loading branch information
IepIweidieng authored Jan 7, 2025
1 parent 912c8d1 commit 1e9fd20
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 185 deletions.
24 changes: 13 additions & 11 deletions FDK/src/00.Common/CCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ public CCounter() {
}

/// <summary>生成と同時に開始する。</summary>
public CCounter(double begin, double end, double msInterval, CTimer timer)
public CCounter(double begin, double end, double msInterval, CTimer? timer)
: this() {
this.Start(begin, end, msInterval, timer);
}

/// <summary>生成と同時に開始する。(double版)</summary>
public CCounter(double begin, double end, double secInterval, CSoundTimer timer)
public CCounter(double begin, double end, double secInterval, CSoundTimer? timer)
: this() {
this.Start(begin, end, secInterval * 1000.0f, timer);
}
Expand All @@ -95,12 +95,12 @@ public CCounter(double begin, double end, double secInterval, CSoundTimer timer)
/// <param name="end">最後のカウント値。</param>
/// <param name="msInterval">カウント値を1増加させるのにかける時間(ミリ秒単位)。</param>
/// <param name="timer">カウントに使用するタイマ。</param>
public void Start(double begin, double end, double msInterval, CTimer timer) {
public void Start(double begin, double end, double msInterval, CTimer? timer) {
this.BeginValue = begin;
this.EndValue = end;
this._msInterval = msInterval;
this.NormalTimer = timer;
this.msNowTime = this.NormalTimer.NowTimeMs;
this.msNowTime = this.NormalTimer?.NowTimeMs ?? CTimer.UnusedNum;
this.CurrentValue = (int)begin;
this.IsStarted = true;
}
Expand All @@ -112,12 +112,12 @@ public void Start(double begin, double end, double msInterval, CTimer timer) {
/// <param name="end">最後のカウント値。</param>
/// <param name="msInterval">カウント値を1増加させるのにかける時間(ミリ秒単位)。</param>
/// <param name="timer">カウントに使用するタイマ。</param>
public void Start(double begin, double end, double msInterval, CSoundTimer timer) {
public void Start(double begin, double end, double msInterval, CSoundTimer? timer) {
this.BeginValue = begin;
this.EndValue = end;
this._msInterval = msInterval;
this.TimerDB = timer;
this.msNowTime = this.TimerDB.SystemTimeMs_Double;
this.msNowTime = this.TimerDB?.SystemTimeMs_Double ?? CSoundTimer.UnusedNum;
this.CurrentValue = (int)begin;
this.IsStarted = true;
}
Expand Down Expand Up @@ -276,12 +276,14 @@ public void KeyIntervalFunc(bool pressFlag, KeyProcess keyProcess) {

keyProcess();
this.CurrentValue = second;
this.msNowTime = this.NormalTimer.NowTimeMs;
if (this.NormalTimer != null) {
this.msNowTime = this.NormalTimer.NowTimeMs;
}
return;

case second:

if ((this.NormalTimer.NowTimeMs - this.msNowTime) > 200) {
if (this.NormalTimer != null && (this.NormalTimer.NowTimeMs - this.msNowTime) > 200) {
keyProcess();
this.msNowTime = this.NormalTimer.NowTimeMs;
this.CurrentValue = later;
Expand All @@ -290,7 +292,7 @@ public void KeyIntervalFunc(bool pressFlag, KeyProcess keyProcess) {

case later:

if ((this.NormalTimer.NowTimeMs - this.msNowTime) > 30) {
if (this.NormalTimer != null && (this.NormalTimer.NowTimeMs - this.msNowTime) > 30) {
keyProcess();
this.msNowTime = this.NormalTimer.NowTimeMs;
}
Expand All @@ -307,8 +309,8 @@ public void KeyIntervalFunc(bool pressFlag, KeyProcess keyProcess) {

#region [ private ]
//-----------------
private CTimer NormalTimer;
private CSoundTimer TimerDB;
private CTimer? NormalTimer;
private CSoundTimer? TimerDB;
private double msInterval;
//-----------------
#endregion
Expand Down
13 changes: 9 additions & 4 deletions OpenTaiko/src/Common/CTextConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ public enum EFontType {
GraySlim
}

public void Print(int x, int y, EFontType font, string alphanumericString) {
public (int x, int y) Print(int x, int y, EFontType font, string alphanumericString)
=> this.Print(x, y, x, font, alphanumericString);

/// Print text with initial cursor position at (x, y) and set cursor to xLineBegin on line wraps
/// Returns (x, y) of final cursor position
public (int x, int y) Print(int x, int y, int xLineBegin, EFontType font, string alphanumericString) {
if (base.IsDeActivated || string.IsNullOrEmpty(alphanumericString)) {
return;
return (x, y);
}

int BOL = x;
foreach (var ch in alphanumericString) {
if (ch == '\n') {
x = BOL;
x = xLineBegin;
y += this.fontHeight;
} else {
int index = printableCharacters.IndexOf(ch);
Expand All @@ -34,6 +38,7 @@ public void Print(int x, int y, EFontType font, string alphanumericString) {
x += this.fontWidth;
}
}
return (x, y);
}

public override void DeActivate() {
Expand Down
35 changes: 4 additions & 31 deletions OpenTaiko/src/Common/LogNotification.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
using System.Diagnostics;
using FDK;

namespace OpenTaiko;

internal class LogNotification {
private static Queue<CLogNotification> Notifications = new Queue<CLogNotification>();

public enum ENotificationType {
EINFO,
ESUCCESS,
EWARNING,
EERROR,
}

public class CLogNotification {
public CLogNotification(ENotificationType nt, string msg) {
NotificationType = nt;
Message = msg;
}

public ENotificationType NotificationType = ENotificationType.EINFO;
public string Message = "";
public CCounter LifeTime = new CCounter(0, 1000, 1, OpenTaiko.Timer);
}


public static void PopError(string message) {
Notifications.Enqueue(new CLogNotification(ENotificationType.EERROR, message));
OpenTaiko.VisualLogManager?.PushCard(TraceEventType.Error, message);
Trace.TraceError("<Runtime Error>: " + message);
}

public static void PopWarning(string message) {
Notifications.Enqueue(new CLogNotification(ENotificationType.EWARNING, message));
OpenTaiko.VisualLogManager?.PushCard(TraceEventType.Warning, message);
Trace.TraceWarning("<Runtime Warning>: " + message);
}

public static void PopSuccess(string message) {
Notifications.Enqueue(new CLogNotification(ENotificationType.ESUCCESS, message));
OpenTaiko.VisualLogManager?.PushCard(TraceEventType.Verbose, message);
Trace.TraceInformation("<Runtime Success>: " + message);
}

public static void PopInfo(string message) {
Notifications.Enqueue(new CLogNotification(ENotificationType.EINFO, message));
OpenTaiko.VisualLogManager?.PushCard(TraceEventType.Information, message);
Trace.TraceInformation("<Runtime Info>: " + message);
}

public static void Display() {
while (Notifications.Count > 0 && Notifications.Peek().LifeTime.IsEnded) Notifications.Dequeue();
// Add an optimized method to display the notifications here
}
}
4 changes: 2 additions & 2 deletions OpenTaiko/src/Common/OpenTaiko.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,8 @@ private void tStartupProcess() {
SystemError = new CSystemError();
this.listTopLevelActivities.Add(SystemError);

VisualLogManager = new CVisualLogManager();


#region [ Read Config.ini and Database files ]
//---------------------
Expand All @@ -1543,8 +1545,6 @@ private void tStartupProcess() {
Databases = new Databases();
Databases.tDatabases();

VisualLogManager = new CVisualLogManager();

if (!File.Exists("Saves.db3")) {
File.Copy(@$".init{Path.DirectorySeparatorChar}Saves.db3", "Saves.db3");
}
Expand Down
49 changes: 27 additions & 22 deletions OpenTaiko/src/Components/CVisualLogManager.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
using FDK;
using System.Diagnostics;
using FDK;

namespace OpenTaiko;

class CVisualLogManager {
public enum ELogCardType {
LogInfo,
LogWarning,
LogError
}

class LogCard {
public LogCard(ELogCardType type, string message) {
public LogCard(TraceEventType type, string message) {
lct = type;
msg = message;
timeSinceCreation = new CCounter(0, 10000, 1, OpenTaiko.Timer);
InitTimeSinceCreation();
}

public void Display(int screenPosition) {
private void InitTimeSinceCreation()
=> timeSinceCreation = new CCounter(0, 10000, 1, OpenTaiko.Timer);

public int Display(int y) {
if (timeSinceCreation.IsStoped) {
// OpenTaiko.Timer was null. Reinitialize.
InitTimeSinceCreation();
}
timeSinceCreation.Tick();

// Display stuff here

int x = 0;
int y = 0 + (40 * screenPosition);

OpenTaiko.actTextConsole.Print(x, y, CTextConsole.EFontType.Cyan, msg);
if (OpenTaiko.actTextConsole != null) {
y = OpenTaiko.actTextConsole.Print(0, y, CTextConsole.EFontType.Cyan, msg).y;
y += OpenTaiko.actTextConsole.fontHeight + 24;
}
return y;
}

public bool IsExpired() {
return timeSinceCreation.IsEnded;
}

private CCounter timeSinceCreation;
private ELogCardType lct;
private TraceEventType lct;
private string msg;
}

public void PushCard(ELogCardType lct, string msg) {
cards.Add(new LogCard(lct, msg));
public void PushCard(TraceEventType lct, string msg) {
cards.Enqueue(new LogCard(lct, msg));
}

public void Display() {
for (int i = 0; i < cards.Count; i++)
cards[i].Display(i);
cards.RemoveAll(card => card.IsExpired());
while (this.cards.TryPeek(out var card) && card.IsExpired()) {
this.cards.Dequeue();
}
int y = 0;
foreach (var card in this.cards)
y = card.Display(y);
}

private List<LogCard> cards = new List<LogCard>();
private readonly Queue<LogCard> cards = new Queue<LogCard>();
}
45 changes: 25 additions & 20 deletions OpenTaiko/src/Lua/CLuaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,33 +170,38 @@ public CLuaScript(string dir, string? texturesDir = null, string? soundsDir = nu
LuaScript = new Lua();
LuaScript.LoadCLRPackage();
LuaScript.State.Encoding = Encoding.UTF8;
LuaScript.DoFile($"{strDir}/Script.lua");

LuaScript["info"] = luaInfo = new CLuaInfo(strDir);
LuaScript["fps"] = luaFPS;
try {
LuaScript.DoFile($"{strDir}/Script.lua");

LuaScript["info"] = luaInfo = new CLuaInfo(strDir);
LuaScript["fps"] = luaFPS;


lfLoadAssets = (LuaFunction)LuaScript["loadAssets"];
lfReloadLanguage = (LuaFunction)LuaScript["reloadLanguage"];
lfLoadAssets = (LuaFunction)LuaScript["loadAssets"];
lfReloadLanguage = (LuaFunction)LuaScript["reloadLanguage"];

LuaScript["loadConfig"] = LoadConfig;
LuaScript["loadTexture"] = LoadTexture;
LuaScript["loadSound"] = LoadSound;
LuaScript["loadFontRenderer"] = LoadFontRenderer;
LuaScript["createTitleTextureKey"] = CreateTitleTextureKey;
LuaScript["getTextTex"] = GetTextTex;
LuaScript["getNum"] = getNum;
LuaScript["getText"] = getText;
LuaScript["getNumArray"] = getNumArray;
LuaScript["getTextArray"] = getTextArray;
LuaScript["getLocalizedString"] = GetLocalizedString;
LuaScript["displayDanPlate"] = CActSelect段位リスト.tDisplayDanPlate;
LuaScript["debugLog"] = DebugLog;
LuaScript["loadConfig"] = LoadConfig;
LuaScript["loadTexture"] = LoadTexture;
LuaScript["loadSound"] = LoadSound;
LuaScript["loadFontRenderer"] = LoadFontRenderer;
LuaScript["createTitleTextureKey"] = CreateTitleTextureKey;
LuaScript["getTextTex"] = GetTextTex;
LuaScript["getNum"] = getNum;
LuaScript["getText"] = getText;
LuaScript["getNumArray"] = getNumArray;
LuaScript["getTextArray"] = getTextArray;
LuaScript["getLocalizedString"] = GetLocalizedString;
LuaScript["displayDanPlate"] = CActSelect段位リスト.tDisplayDanPlate;
LuaScript["debugLog"] = DebugLog;


if (loadAssets) LoadAssets();
if (loadAssets) LoadAssets();

listScripts.Add(this);
listScripts.Add(this);
} catch (Exception e) {
Crash(e);
}
}

public void LoadAssets(params object[] args) {
Expand Down
13 changes: 7 additions & 6 deletions OpenTaiko/src/Stages/01.StartUp/CStage起動.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public override void ReleaseManagedResource() {
public override int Draw() {
if (!base.IsDeActivated) {
if (base.IsFirstDraw) {
this.list進行文字列.Add("DTXManiaXG Ver.K powered by YAMAHA Silent Session Drums\n");
this.list進行文字列.Add("Product by.kairera0467\n");
this.list進行文字列.Add("DTXManiaXG Ver.K powered by YAMAHA Silent Session Drums");
this.list進行文字列.Add("Product by.kairera0467");
this.list進行文字列.Add("Release: " + OpenTaiko.VERSION + " [" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + "]");

this.list進行文字列.Add("");
Expand Down Expand Up @@ -171,11 +171,12 @@ void loadTexture() {
if (ePhaseID != EPhase.Startup_Complete) {
#region [ this.list進行文字列+this.現在進行中 の表示 ]
//-----------------
int x = 320;
int y = 20;
int x = (int)(320 * OpenTaiko.Skin.Resolution[0] / 1280.0);
int y = (int)(20 * OpenTaiko.Skin.Resolution[1] / 720.0);
int dy = (int)((OpenTaiko.actTextConsole.fontHeight + 8) * OpenTaiko.Skin.Resolution[1] / 720.0);
for (int i = 0; i < this.list進行文字列.Count; i++) {
OpenTaiko.actTextConsole.Print((int)(x * OpenTaiko.Skin.Resolution[0] / 1280.0), (int)(y * OpenTaiko.Skin.Resolution[1] / 720.0), CTextConsole.EFontType.White, this.list進行文字列[i]);
y += 24;
y = OpenTaiko.actTextConsole.Print(x, y, CTextConsole.EFontType.White, this.list進行文字列[i]).y;
y += dy;
}
//-----------------
#endregion
Expand Down
13 changes: 9 additions & 4 deletions OpenTaiko/src/Stages/02.Title/CStageTitle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,16 @@ public override int Draw() {
//string strVersion = "KTT:J:A:I:2017072200";
string strCreator = "https://github.com/0AuBSQ/OpenTaiko";
AssemblyName asmApp = Assembly.GetExecutingAssembly().GetName();
OpenTaiko.actTextConsole.Print(4, 44, CTextConsole.EFontType.White, "DEBUG BUILD");
OpenTaiko.actTextConsole.Print(4, 4, CTextConsole.EFontType.White, asmApp.Name + " Ver." + OpenTaiko.VERSION + " (" + strCreator + ")");
OpenTaiko.actTextConsole.Print(4, 24, CTextConsole.EFontType.White, "Skin:" + OpenTaiko.Skin.Skin_Name + " Ver." + OpenTaiko.Skin.Skin_Version + " (" + OpenTaiko.Skin.Skin_Creator + ")");
int dy = OpenTaiko.actTextConsole.fontHeight;
int y = 4;
y = OpenTaiko.actTextConsole.Print(4, y, CTextConsole.EFontType.White, asmApp.Name + " Ver." + OpenTaiko.VERSION + " (" + strCreator + ")").y;
y += dy + 4;
y = OpenTaiko.actTextConsole.Print(4, y, CTextConsole.EFontType.White, "Skin:" + OpenTaiko.Skin.Skin_Name + " Ver." + OpenTaiko.Skin.Skin_Version + " (" + OpenTaiko.Skin.Skin_Creator + ")").y;
y += dy + 4;
//CDTXMania.act文字コンソール.tPrint(4, 24, C文字コンソール.Eフォント種別.白, strSubTitle);
OpenTaiko.actTextConsole.Print(4, (OpenTaiko.Skin.Resolution[1] - 24), CTextConsole.EFontType.White, "TJAPlayer3 forked TJAPlayer2 forPC(kairera0467)");
OpenTaiko.actTextConsole.Print(4, y, CTextConsole.EFontType.White, "DEBUG BUILD");
y = OpenTaiko.Skin.Resolution[1] - 8 - dy;
OpenTaiko.actTextConsole.Print(4, y, CTextConsole.EFontType.White, "TJAPlayer3 forked TJAPlayer2 forPC(kairera0467)");

#endif
//TJAPlayer3.actTextConsole.tPrint(4, 64, CTextConsole.EFontType.White, CScoreIni_Importer.Status);
Expand Down
12 changes: 7 additions & 5 deletions OpenTaiko/src/Stages/04.Config/CActCalibrationMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ public override int Draw() {

offsettext?.t2D描画(OpenTaiko.Skin.Config_Calibration_OffsetText[0] - offsettext.szTextureSize.Width, OpenTaiko.Skin.Config_Calibration_OffsetText[1]);

OpenTaiko.actTextConsole.Print(OpenTaiko.Skin.Config_Calibration_InfoText[0], OpenTaiko.Skin.Config_Calibration_InfoText[1], CTextConsole.EFontType.Cyan,
"MEDIAN OFFSET : " + GetMedianOffset() + "ms\n");
OpenTaiko.actTextConsole.Print(OpenTaiko.Skin.Config_Calibration_InfoText[0], OpenTaiko.Skin.Config_Calibration_InfoText[1] + OpenTaiko.actTextConsole.fontHeight, CTextConsole.EFontType.White,
int xInfo = OpenTaiko.Skin.Config_Calibration_InfoText[0];
int yInfo = OpenTaiko.Skin.Config_Calibration_InfoText[1];
yInfo = OpenTaiko.actTextConsole.Print(xInfo, yInfo, CTextConsole.EFontType.Cyan,
"MEDIAN OFFSET : " + GetMedianOffset() + "ms\n").y;
yInfo = OpenTaiko.actTextConsole.Print(xInfo, yInfo, CTextConsole.EFontType.White,
"MIN OFFSET : " + GetLowestOffset() + "ms\n" +
"MAX OFFSET : " + GetHighestOffset() + "ms\n" +
"LAST OFFSET : " + LastOffset + "ms\n" +
"OFFSET COUNT : " + (Offsets != null ? Offsets.Count : 0));
OpenTaiko.actTextConsole.Print(OpenTaiko.Skin.Config_Calibration_InfoText[0], OpenTaiko.Skin.Config_Calibration_InfoText[1] + (OpenTaiko.actTextConsole.fontHeight * 5), CTextConsole.EFontType.White,
"OFFSET COUNT : " + (Offsets != null ? Offsets.Count : 0) + "\n").y;
OpenTaiko.actTextConsole.Print(xInfo, yInfo, CTextConsole.EFontType.White,
"CURRENT OFFSET: " + CurrentOffset() + "ms");

#endregion
Expand Down
Loading

0 comments on commit 1e9fd20

Please sign in to comment.