diff --git a/source/funkin/InitState.hx b/source/funkin/InitState.hx index fe34cb224..48dd5b570 100644 --- a/source/funkin/InitState.hx +++ b/source/funkin/InitState.hx @@ -86,6 +86,10 @@ class InitState extends FlxState // Disable the thing on Windows where it tries to send a bug report to Microsoft because why do they care? WindowUtil.disableCrashHandler(); + #if FEATURE_DEBUG_TRACY + funkin.util.WindowUtil.initTracy(); + #end + // This ain't a pixel art game! (most of the time) FlxSprite.defaultAntialiasing = true; diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 593c57f9b..18d656f70 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -799,8 +799,6 @@ class PlayState extends MusicBeatSubState public override function update(elapsed:Float):Void { - // TOTAL: 9.42% CPU Time when profiled in VS 2019. - if (criticalFailure) return; super.update(elapsed); diff --git a/source/funkin/play/character/AnimateAtlasCharacter.hx b/source/funkin/play/character/AnimateAtlasCharacter.hx index a221d86e4..fd94dbe82 100644 --- a/source/funkin/play/character/AnimateAtlasCharacter.hx +++ b/source/funkin/play/character/AnimateAtlasCharacter.hx @@ -74,10 +74,14 @@ class AnimateAtlasCharacter extends BaseCharacter override function onCreate(event:ScriptEvent):Void { - trace('Creating Animate Atlas character: ' + this.characterId); + // Display a custom scope for debugging purposes. + #if FEATURE_DEBUG_TRACY + cpp.vm.tracy.TracyProfiler.zoneScoped('AnimateAtlasCharacter.create(${this.characterId})'); + #end try { + trace('Loading assets for Animate Atlas character "${characterId}"', flixel.util.FlxColor.fromString("#89CFF0")); var atlasSprite:FlxAtlasSprite = loadAtlasSprite(); setSprite(atlasSprite); diff --git a/source/funkin/play/character/BaseCharacter.hx b/source/funkin/play/character/BaseCharacter.hx index a7fdee3fb..5f146a6b4 100644 --- a/source/funkin/play/character/BaseCharacter.hx +++ b/source/funkin/play/character/BaseCharacter.hx @@ -149,6 +149,7 @@ class BaseCharacter extends Bopper public function new(id:String, renderType:CharacterRenderType) { super(CharacterDataParser.DEFAULT_DANCEEVERY); + this.characterId = id; ignoreExclusionPref = ["sing"]; diff --git a/source/funkin/play/character/MultiSparrowCharacter.hx b/source/funkin/play/character/MultiSparrowCharacter.hx index 52bb257c7..6d9c34ac8 100644 --- a/source/funkin/play/character/MultiSparrowCharacter.hx +++ b/source/funkin/play/character/MultiSparrowCharacter.hx @@ -26,7 +26,10 @@ class MultiSparrowCharacter extends BaseCharacter override function onCreate(event:ScriptEvent):Void { - trace('Creating Multi-Sparrow character: ' + this.characterId); + // Display a custom scope for debugging purposes. + #if FEATURE_DEBUG_TRACY + cpp.vm.tracy.TracyProfiler.zoneScoped('MultiSparrowCharacter.create(${this.characterId})'); + #end buildSprites(); super.onCreate(event); @@ -53,6 +56,8 @@ class MultiSparrowCharacter extends BaseCharacter function buildSpritesheet():Void { + trace('Loading assets for Multi-Sparrow character "${characterId}"', flixel.util.FlxColor.fromString("#89CFF0")); + var assetList = []; for (anim in _data.animations) { diff --git a/source/funkin/play/character/PackerCharacter.hx b/source/funkin/play/character/PackerCharacter.hx index 5d004606c..5a6f5eab8 100644 --- a/source/funkin/play/character/PackerCharacter.hx +++ b/source/funkin/play/character/PackerCharacter.hx @@ -18,7 +18,10 @@ class PackerCharacter extends BaseCharacter override function onCreate(event:ScriptEvent):Void { - trace('Creating Packer character: ' + this.characterId); + // Display a custom scope for debugging purposes. + #if FEATURE_DEBUG_TRACY + cpp.vm.tracy.TracyProfiler.zoneScoped('PackerCharacter.create(${this.characterId})'); + #end loadSpritesheet(); loadAnimations(); @@ -28,7 +31,7 @@ class PackerCharacter extends BaseCharacter function loadSpritesheet():Void { - trace('[PACKERCHAR] Loading spritesheet ${_data.assetPath} for ${characterId}'); + trace('Loading assets for Packer character "${characterId}"', flixel.util.FlxColor.fromString("#89CFF0")); var tex:FlxFramesCollection = Paths.getPackerAtlas(_data.assetPath); if (tex == null) diff --git a/source/funkin/play/character/SparrowCharacter.hx b/source/funkin/play/character/SparrowCharacter.hx index eacf799d8..90fd51c79 100644 --- a/source/funkin/play/character/SparrowCharacter.hx +++ b/source/funkin/play/character/SparrowCharacter.hx @@ -21,7 +21,10 @@ class SparrowCharacter extends BaseCharacter override function onCreate(event:ScriptEvent):Void { - trace('Creating Sparrow character: ' + this.characterId); + // Display a custom scope for debugging purposes. + #if FEATURE_DEBUG_TRACY + cpp.vm.tracy.TracyProfiler.zoneScoped('SparrowCharacter.create(${this.characterId})'); + #end loadSpritesheet(); loadAnimations(); @@ -31,7 +34,7 @@ class SparrowCharacter extends BaseCharacter function loadSpritesheet() { - trace('[SPARROWCHAR] Loading spritesheet ${_data.assetPath} for ${characterId}'); + trace('Loading assets for Sparrow character "${characterId}"', flixel.util.FlxColor.fromString("#89CFF0")); var tex:FlxFramesCollection = Paths.getSparrowAtlas(_data.assetPath); if (tex == null) diff --git a/source/funkin/play/notes/Strumline.hx b/source/funkin/play/notes/Strumline.hx index 497b99986..aed701c73 100644 --- a/source/funkin/play/notes/Strumline.hx +++ b/source/funkin/play/notes/Strumline.hx @@ -807,7 +807,10 @@ class Strumline extends FlxSpriteGroup if (holdNoteSprite != null) { - var noteKindStyle:NoteStyle = NoteKindManager.getNoteStyle(note.kind, this.noteStyle.id) ?? this.noteStyle; + var noteKindStyle:NoteStyle = NoteKindManager.getNoteStyle(note.kind, this.noteStyle.id); + if (noteKindStyle == null) noteKindStyle = NoteKindManager.getNoteStyle(note.kind, null); + if (noteKindStyle == null) noteKindStyle = this.noteStyle; + holdNoteSprite.setupHoldNoteGraphic(noteKindStyle); holdNoteSprite.parentStrumline = this; diff --git a/source/funkin/play/notes/notekind/NoteKindManager.hx b/source/funkin/play/notes/notekind/NoteKindManager.hx index e17e103d1..d698ba5d0 100644 --- a/source/funkin/play/notes/notekind/NoteKindManager.hx +++ b/source/funkin/play/notes/notekind/NoteKindManager.hx @@ -1,5 +1,6 @@ package funkin.play.notes.notekind; +import funkin.data.song.SongData.SongNoteData; import funkin.modding.events.ScriptEventDispatcher; import funkin.modding.events.ScriptEvent; import funkin.ui.debug.charting.util.ChartEditorDropdowns; @@ -82,6 +83,16 @@ class NoteKindManager return NoteStyleRegistry.instance.fetchEntry(noteStyleId); } + public static function listNoteStyles(songNoteDatas:Array):Array + { + var results:Array = []; + for (songNoteData in songNoteDatas) + { + var noteStyle:NoteStyle = getNoteStyle(songNoteData.kind, null); + } + return results; + } + /** * Retrieve the note style id from the given note kind * @param noteKind Note kind name diff --git a/source/funkin/util/WindowUtil.hx b/source/funkin/util/WindowUtil.hx index b4e99f1cd..e42cb59b0 100644 --- a/source/funkin/util/WindowUtil.hx +++ b/source/funkin/util/WindowUtil.hx @@ -34,6 +34,30 @@ class WindowUtil #end } + #if FEATURE_DEBUG_TRACY + /** + * Initialize Tracy. + * NOTE: Call this from the main thread ONLY! + */ + public static function initTracy():Void + { + // Apply a marker to indicate frame end for the Tracy profiler. + // Do this only if Tracy is configured to prevent lag. + openfl.Lib.current.stage.addEventListener(openfl.events.Event.EXIT_FRAME, (e:openfl.events.Event) -> { + cpp.vm.tracy.TracyProfiler.frameMark(); + }); + + var appInfoMessage = funkin.util.logging.CrashHandler.buildSystemInfo(); + + trace("Friday Night Funkin': Connection to Tracy profiler successful."); + + // Post system info like Git hash + cpp.vm.tracy.TracyProfiler.messageAppInfo(appInfoMessage); + + cpp.vm.tracy.TracyProfiler.setThreadName("main"); + } + #end + /** * Runs platform-specific code to open a path in the file explorer. * @param targetPath The path to open. @@ -91,14 +115,6 @@ class WindowUtil windowExit.dispatch(exitCode); }); - #if FEATURE_DEBUG_TRACY - // Apply a marker to indicate frame end for the Tracy profiler. - // Do this only if Tracy is configured to prevent lag. - openfl.Lib.current.stage.addEventListener(openfl.events.Event.EXIT_FRAME, (e:openfl.events.Event) -> { - cpp.vm.tracy.TracyProfiler.frameMark(); - }); - #end - openfl.Lib.current.stage.addEventListener(openfl.events.KeyboardEvent.KEY_DOWN, (e:openfl.events.KeyboardEvent) -> { for (key in PlayerSettings.player1.controls.getKeysForAction(WINDOW_FULLSCREEN)) { diff --git a/source/funkin/util/logging/AnsiTrace.hx b/source/funkin/util/logging/AnsiTrace.hx index 0dc9f1a96..552489327 100644 --- a/source/funkin/util/logging/AnsiTrace.hx +++ b/source/funkin/util/logging/AnsiTrace.hx @@ -2,14 +2,20 @@ package funkin.util.logging; class AnsiTrace { - // mostly a copy of haxe.Log.trace() - // but adds nice cute ANSI things + /** + * Output a message to the log. + * Called when using `trace()`, and modified from the default to support ANSI colors. + * @param v The value to print. + */ public static function trace(v:Dynamic, ?info:haxe.PosInfos) { #if (NO_FEATURE_LOG_TRACE && !FEATURE_DEBUG_FUNCTIONS) return; #end var str = formatOutput(v, info); + #if FEATURE_DEBUG_TRACY + cpp.vm.tracy.TracyProfiler.message(str, flixel.util.FlxColor.WHITE); + #end #if js if (js.Syntax.typeof(untyped console) != "undefined" && (untyped console).log != null) (untyped console).log(str); #elseif lua @@ -31,7 +37,10 @@ class AnsiTrace public static inline var BOLD = "\x1b[1m"; public static inline var ITALIC = "\x1b[3m"; - // where the real mf magic happens with ansi stuff! + /** + * Format the output to use ANSI colors. + * Edited from the standard `trace()` implementation. + */ public static function formatOutput(v:Dynamic, infos:haxe.PosInfos):String { var str = Std.string(v); @@ -52,6 +61,9 @@ class AnsiTrace return pstr + ": " + str; } + /** + * Print color pixel art of BF in ANSI format. + */ public static function traceBF() { #if (sys && debug) @@ -74,7 +86,10 @@ class AnsiTrace return (colorSupported ? ansiCol : ""); } - // generated using https://dom111.github.io/image-to-ansi/ + /** + * Color pixel art of BF in ANSI format. + * Generated using https://dom111.github.io/image-to-ansi/ + */ public static var ansiBF:Array = [ "\x1b[39m\x1b[49m \x1b[48;2;154;23;70m \x1b[49m \x1b[m", "\x1b[39m\x1b[49m \x1b[48;2;154;23;70m \x1b[48;2;184;46;83m \x1b[48;2;246;87;102m \x1b[48;2;239;83;100m \x1b[48;2;154;23;70m \x1b[48;2;154;23;69m \x1b[49m \x1b[m", diff --git a/source/funkin/util/logging/CrashHandler.hx b/source/funkin/util/logging/CrashHandler.hx index 4ec578173..4c2ae4265 100644 --- a/source/funkin/util/logging/CrashHandler.hx +++ b/source/funkin/util/logging/CrashHandler.hx @@ -117,6 +117,7 @@ class CrashHandler sys.io.File.saveContent('$LOG_FOLDER/crash${critical ? '-critical' : ''}-${DateUtil.generateTimestamp()}.log', buildCrashReport(message)); } + #end static function buildCrashReport(message:String):String { @@ -126,21 +127,7 @@ class CrashHandler fullContents += '\n'; - fullContents += 'Generated by: ${Constants.GENERATED_BY}\n'; - fullContents += ' Git hash: ${Constants.GIT_HASH} (${Constants.GIT_HAS_LOCAL_CHANGES ? 'MODIFIED' : 'CLEAN'})\n'; - fullContents += 'System timestamp: ${DateUtil.generateTimestamp()}\n'; - var driverInfo = FlxG?.stage?.context3D?.driverInfo ?? 'N/A'; - fullContents += 'Driver info: ${driverInfo}\n'; - fullContents += 'Platform: ${Sys.systemName()}\n'; - fullContents += 'Render method: ${renderMethod()}\n'; - - fullContents += '\n'; - - fullContents += '=====================\n'; - - fullContents += '\n'; - - fullContents += MemoryUtil.buildGCInfo(); + fullContents += buildSystemInfo(); fullContents += '\n\n'; @@ -197,7 +184,27 @@ class CrashHandler return fullContents; } - #end + + public static function buildSystemInfo():String + { + var fullContents = 'Generated by: ${Constants.GENERATED_BY}\n'; + fullContents += ' Git hash: ${Constants.GIT_HASH} (${Constants.GIT_HAS_LOCAL_CHANGES ? 'MODIFIED' : 'CLEAN'})\n'; + fullContents += 'System timestamp: ${DateUtil.generateTimestamp()}\n'; + var driverInfo = FlxG?.stage?.context3D?.driverInfo ?? 'N/A'; + fullContents += 'Driver info: ${driverInfo}\n'; + fullContents += 'Platform: ${Sys.systemName()}\n'; + fullContents += 'Render method: ${renderMethod()}\n'; + + fullContents += '\n'; + + fullContents += '=====================\n'; + + fullContents += '\n'; + + fullContents += MemoryUtil.buildGCInfo(); + + return fullContents; + } static function generateErrorMessage(error:UncaughtErrorEvent):String {