From 4aafbcc5ec9fa7ebd596921e6e08ac80643bcb4a Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 16:29:08 +0800 Subject: [PATCH 01/57] Add log system --- src/desktop/main.c | 6 +++ src/log.c | 111 +++++++++++++++++++++++++++++++++++++++++++++ src/log.h | 22 +++++++++ 3 files changed, 139 insertions(+) create mode 100644 src/log.c create mode 100644 src/log.h diff --git a/src/desktop/main.c b/src/desktop/main.c index d55cb3bc1..468cd6ca5 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -996,6 +996,8 @@ char* collapseNewlines(const char *input) { return result; } +#include "log.h" + // ===[ MAIN ]=== int main(int argc, char* argv[]) { setbuf(stderr, NULL); @@ -1003,6 +1005,10 @@ int main(int argc, char* argv[]) { timeBeginPeriod(1); #endif + Log_log("Hello world!\n"); + Log_logWarning("This is a WARNING!\n"); + Log_logError("This is an ERROR!\n"); + CommandLineArgs args; parseCommandLineArgs(&args, argc, argv); diff --git a/src/log.c b/src/log.c new file mode 100644 index 000000000..3a31b3013 --- /dev/null +++ b/src/log.c @@ -0,0 +1,111 @@ +#include "log.h" + +#include +#include +#include + +bool logToTerminal = true; +bool logToFile = true; + +bool logWithColours = true; + +enum { + LOG_TYPE_NORMAL=0, + LOG_TYPE_WARNING=1, + LOG_TYPE_ERROR=2 +}; + +#define ANSI_COLOUR_CODE_WHITE "\e[0;37m" +#define ANSI_COLOUR_CODE_BOLD_YELLOW "\e[1;33m" +#define ANSI_COLOUR_CODE_BOLD_RED "\e[1;31m" + +void Log_vLogToTerminal(const int type, const char* fmt, va_list va) { + if (!logToTerminal) return; + + const FILE* out = type == LOG_TYPE_NORMAL ? stdout : stderr; + + if (logWithColours) { + fprintf((FILE*)out, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); + } + + vfprintf((FILE*)out, fmt, va); + + if (logWithColours) { + fprintf((FILE*)out, ANSI_COLOUR_CODE_WHITE); + } +} + +void Log_vLogToFile(const int type, const char* fmt, va_list va) {} + +void Log_logToTerminal(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + Log_vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); + va_end(va); +} + +void Log_logToFile(const char* fmt, ...) {} + +void Log_log(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + + if (logToTerminal) { + Log_vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); + } + if (logToFile) { + Log_vLogToFile(LOG_TYPE_NORMAL, fmt, va); + } + + va_end(va); +} + +void Log_logWarningToTerminal(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + Log_vLogToTerminal(LOG_TYPE_WARNING, fmt, va); + va_end(va); +} + +void Log_logWarningToFile(const char* fmt, ...); +void Log_logWarning(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + + if (logToTerminal) { + Log_vLogToTerminal(LOG_TYPE_WARNING, fmt, va); + } + if (logToFile) { + Log_vLogToFile(LOG_TYPE_WARNING, fmt, va); + } + + va_end(va); +} + +void Log_logErrorToTerminal(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + Log_vLogToTerminal(LOG_TYPE_ERROR, fmt, va); + va_end(va); +} + +void Log_logErrorToFile(const char* fmt, ...); +void Log_logError(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + + if (logToTerminal) { + Log_vLogToTerminal(LOG_TYPE_ERROR, fmt, va); + } + if (logToFile) { + Log_vLogToFile(LOG_TYPE_ERROR, fmt, va); + } + + va_end(va); +} diff --git a/src/log.h b/src/log.h new file mode 100644 index 000000000..a44cc278a --- /dev/null +++ b/src/log.h @@ -0,0 +1,22 @@ +#ifndef _BS_LOG_H +#define _BS_LOG_H + +#include +#include + +void Log_vLogToTerminal(int type, const char* fmt, va_list va); +void Log_vLogToFile(int type, const char* fmt, va_list va); + +void Log_logToTerminal(const char* fmt, ...); +void Log_logToFile(const char* fmt, ...); +void Log_log(const char* fmt, ...); + +void Log_logWarningToTerminal(const char* fmt, ...); +void Log_logWarningToFile(const char* fmt, ...); +void Log_logWarning(const char* fmt, ...); + +void Log_logErrorToTerminal(const char* fmt, ...); +void Log_logErrorToFile(const char* fmt, ...); +void Log_logError(const char* fmt, ...); + +#endif /* _BS_LOG_H */ From b6ea83171dc71d8f01b27c1ad79ba0e25994d2ca Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 16:30:03 +0800 Subject: [PATCH 02/57] Make the vLog* funcs internal --- src/log.c | 22 +++++++++++----------- src/log.h | 3 --- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/log.c b/src/log.c index 3a31b3013..ce4a387f7 100644 --- a/src/log.c +++ b/src/log.c @@ -19,7 +19,7 @@ enum { #define ANSI_COLOUR_CODE_BOLD_YELLOW "\e[1;33m" #define ANSI_COLOUR_CODE_BOLD_RED "\e[1;31m" -void Log_vLogToTerminal(const int type, const char* fmt, va_list va) { +static void vLogToTerminal(const int type, const char* fmt, va_list va) { if (!logToTerminal) return; const FILE* out = type == LOG_TYPE_NORMAL ? stdout : stderr; @@ -35,13 +35,13 @@ void Log_vLogToTerminal(const int type, const char* fmt, va_list va) { } } -void Log_vLogToFile(const int type, const char* fmt, va_list va) {} +static void vLogToFile(const int type, const char* fmt, va_list va) {} void Log_logToTerminal(const char* fmt, ...) { va_list va; va_start(va, fmt); - Log_vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); + vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); va_end(va); } @@ -53,10 +53,10 @@ void Log_log(const char* fmt, ...) { va_start(va, fmt); if (logToTerminal) { - Log_vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); + vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); } if (logToFile) { - Log_vLogToFile(LOG_TYPE_NORMAL, fmt, va); + vLogToFile(LOG_TYPE_NORMAL, fmt, va); } va_end(va); @@ -66,7 +66,7 @@ void Log_logWarningToTerminal(const char* fmt, ...) { va_list va; va_start(va, fmt); - Log_vLogToTerminal(LOG_TYPE_WARNING, fmt, va); + vLogToTerminal(LOG_TYPE_WARNING, fmt, va); va_end(va); } @@ -77,10 +77,10 @@ void Log_logWarning(const char* fmt, ...) { va_start(va, fmt); if (logToTerminal) { - Log_vLogToTerminal(LOG_TYPE_WARNING, fmt, va); + vLogToTerminal(LOG_TYPE_WARNING, fmt, va); } if (logToFile) { - Log_vLogToFile(LOG_TYPE_WARNING, fmt, va); + vLogToFile(LOG_TYPE_WARNING, fmt, va); } va_end(va); @@ -90,7 +90,7 @@ void Log_logErrorToTerminal(const char* fmt, ...) { va_list va; va_start(va, fmt); - Log_vLogToTerminal(LOG_TYPE_ERROR, fmt, va); + vLogToTerminal(LOG_TYPE_ERROR, fmt, va); va_end(va); } @@ -101,10 +101,10 @@ void Log_logError(const char* fmt, ...) { va_start(va, fmt); if (logToTerminal) { - Log_vLogToTerminal(LOG_TYPE_ERROR, fmt, va); + vLogToTerminal(LOG_TYPE_ERROR, fmt, va); } if (logToFile) { - Log_vLogToFile(LOG_TYPE_ERROR, fmt, va); + vLogToFile(LOG_TYPE_ERROR, fmt, va); } va_end(va); diff --git a/src/log.h b/src/log.h index a44cc278a..b69a4efbb 100644 --- a/src/log.h +++ b/src/log.h @@ -4,9 +4,6 @@ #include #include -void Log_vLogToTerminal(int type, const char* fmt, va_list va); -void Log_vLogToFile(int type, const char* fmt, va_list va); - void Log_logToTerminal(const char* fmt, ...); void Log_logToFile(const char* fmt, ...); void Log_log(const char* fmt, ...); From 649db2c8596008542daae7331b209452abdbe7fe Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 16:46:53 +0800 Subject: [PATCH 03/57] Add file logging --- .gitignore | 1 + src/desktop/main.c | 2 ++ src/log.c | 55 ++++++++++++++++++++++++++++++++++++++++++---- src/log.h | 2 ++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 53c59cff8..fb3756c01 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ CMakeUserPresets.json .devcontainer/ compat/config.mk /.vs +*.log diff --git a/src/desktop/main.c b/src/desktop/main.c index 468cd6ca5..3a7667098 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -1005,6 +1005,8 @@ int main(int argc, char* argv[]) { timeBeginPeriod(1); #endif + Log_init(); + Log_log("Hello world!\n"); Log_logWarning("This is a WARNING!\n"); Log_logError("This is an ERROR!\n"); diff --git a/src/log.c b/src/log.c index ce4a387f7..b2096f176 100644 --- a/src/log.c +++ b/src/log.c @@ -4,11 +4,15 @@ #include #include +#include "common.h" + bool logToTerminal = true; bool logToFile = true; bool logWithColours = true; +char* logFile = "./butterscotch.log"; + enum { LOG_TYPE_NORMAL=0, LOG_TYPE_WARNING=1, @@ -35,7 +39,30 @@ static void vLogToTerminal(const int type, const char* fmt, va_list va) { } } -static void vLogToFile(const int type, const char* fmt, va_list va) {} +static void vLogToFile(const int type, const char* fmt, va_list va) { + if (!logToFile) return; + + FILE *file = fopen(logFile, "a"); + + if (logWithColours) { + fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); + } + + vfprintf(file, fmt, va); + + if (logWithColours) { + fprintf(file, ANSI_COLOUR_CODE_WHITE); + } + + fclose(file); +} + +void Log_init() { + FILE* file = fopen(logFile, "w"); + if (file != nullptr) { + fclose(file); + } +} void Log_logToTerminal(const char* fmt, ...) { va_list va; @@ -45,7 +72,13 @@ void Log_logToTerminal(const char* fmt, ...) { va_end(va); } -void Log_logToFile(const char* fmt, ...) {} +void Log_logToFile(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + vLogToFile(LOG_TYPE_NORMAL, fmt, va); + va_end(va); +} void Log_log(const char* fmt, ...) { va_list va; @@ -70,7 +103,14 @@ void Log_logWarningToTerminal(const char* fmt, ...) { va_end(va); } -void Log_logWarningToFile(const char* fmt, ...); +void Log_logWarningToFile(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + vLogToFile(LOG_TYPE_WARNING, fmt, va); + va_end(va); +} + void Log_logWarning(const char* fmt, ...) { va_list va; @@ -94,7 +134,14 @@ void Log_logErrorToTerminal(const char* fmt, ...) { va_end(va); } -void Log_logErrorToFile(const char* fmt, ...); +void Log_logErrorToFile(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + vLogToFile(LOG_TYPE_WARNING, fmt, va); + va_end(va); +} + void Log_logError(const char* fmt, ...) { va_list va; diff --git a/src/log.h b/src/log.h index b69a4efbb..7116b8faa 100644 --- a/src/log.h +++ b/src/log.h @@ -4,6 +4,8 @@ #include #include +void Log_init(); + void Log_logToTerminal(const char* fmt, ...); void Log_logToFile(const char* fmt, ...); void Log_log(const char* fmt, ...); From dd5e47e85f77919f5403cc371e2ff8fdf13ad519 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 16:55:04 +0800 Subject: [PATCH 04/57] Fix --- src/log.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/log.c b/src/log.c index b2096f176..d5d191f35 100644 --- a/src/log.c +++ b/src/log.c @@ -9,7 +9,8 @@ bool logToTerminal = true; bool logToFile = true; -bool logWithColours = true; +bool logColourTerminal = true; +bool logColourFile = false; char* logFile = "./butterscotch.log"; @@ -19,38 +20,39 @@ enum { LOG_TYPE_ERROR=2 }; -#define ANSI_COLOUR_CODE_WHITE "\e[0;37m" -#define ANSI_COLOUR_CODE_BOLD_YELLOW "\e[1;33m" -#define ANSI_COLOUR_CODE_BOLD_RED "\e[1;31m" +#define ANSI_COLOUR_CODE_WHITE "\x1b[0;37m" +#define ANSI_COLOUR_CODE_BOLD_YELLOW "\x1b[1;33m" +#define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" static void vLogToTerminal(const int type, const char* fmt, va_list va) { if (!logToTerminal) return; - const FILE* out = type == LOG_TYPE_NORMAL ? stdout : stderr; + FILE* out = type == LOG_TYPE_NORMAL ? stdout : stderr; - if (logWithColours) { - fprintf((FILE*)out, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); + if (logColourTerminal) { + fprintf(out, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); } - vfprintf((FILE*)out, fmt, va); + vfprintf(out, fmt, va); - if (logWithColours) { - fprintf((FILE*)out, ANSI_COLOUR_CODE_WHITE); + if (logColourTerminal) { + fprintf(out, ANSI_COLOUR_CODE_WHITE); } } static void vLogToFile(const int type, const char* fmt, va_list va) { if (!logToFile) return; - FILE *file = fopen(logFile, "a"); + FILE* file = fopen(logFile, "a"); + if (file == nullptr) return; - if (logWithColours) { + if (logColourFile) { fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); } vfprintf(file, fmt, va); - if (logWithColours) { + if (logColourFile) { fprintf(file, ANSI_COLOUR_CODE_WHITE); } @@ -81,18 +83,20 @@ void Log_logToFile(const char* fmt, ...) { } void Log_log(const char* fmt, ...) { - va_list va; + va_list va, va2; va_start(va, fmt); + va_copy(va2, va); if (logToTerminal) { vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); } if (logToFile) { - vLogToFile(LOG_TYPE_NORMAL, fmt, va); + vLogToFile(LOG_TYPE_NORMAL, fmt, va2); } va_end(va); + va_end(va2); } void Log_logWarningToTerminal(const char* fmt, ...) { @@ -112,18 +116,20 @@ void Log_logWarningToFile(const char* fmt, ...) { } void Log_logWarning(const char* fmt, ...) { - va_list va; + va_list va, va2; va_start(va, fmt); + va_copy(va2, va); if (logToTerminal) { vLogToTerminal(LOG_TYPE_WARNING, fmt, va); } if (logToFile) { - vLogToFile(LOG_TYPE_WARNING, fmt, va); + vLogToFile(LOG_TYPE_WARNING, fmt, va2); } va_end(va); + va_end(va2); } void Log_logErrorToTerminal(const char* fmt, ...) { @@ -138,21 +144,23 @@ void Log_logErrorToFile(const char* fmt, ...) { va_list va; va_start(va, fmt); - vLogToFile(LOG_TYPE_WARNING, fmt, va); + vLogToFile(LOG_TYPE_ERROR, fmt, va); va_end(va); } void Log_logError(const char* fmt, ...) { - va_list va; + va_list va, va2; va_start(va, fmt); + va_copy(va2, va); if (logToTerminal) { vLogToTerminal(LOG_TYPE_ERROR, fmt, va); } if (logToFile) { - vLogToFile(LOG_TYPE_ERROR, fmt, va); + vLogToFile(LOG_TYPE_ERROR, fmt, va2); } va_end(va); + va_end(va2); } From 5237a7932e34ea1a430764bbf07d90afe4ce15e3 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 17:01:57 +0800 Subject: [PATCH 05/57] Add vLog function variants and update utils.h to use log --- src/log.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/log.h | 12 ++++++++++ src/utils.h | 34 ++++++++++++++------------- 3 files changed, 96 insertions(+), 16 deletions(-) diff --git a/src/log.c b/src/log.c index d5d191f35..512fcc162 100644 --- a/src/log.c +++ b/src/log.c @@ -99,6 +99,28 @@ void Log_log(const char* fmt, ...) { va_end(va2); } +void Log_vLogToTerminal(const char* fmt, va_list va) { + vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); +} + +void Log_vLogToFile(const char* fmt, va_list va) { + vLogToFile(LOG_TYPE_NORMAL, fmt, va); +} + +void Log_vLog(const char* fmt, va_list va) { + va_list va2; + va_copy(va2, va); + + if (logToTerminal) { + vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); + } + if (logToFile) { + vLogToFile(LOG_TYPE_NORMAL, fmt, va2); + } + + va_end(va2); +} + void Log_logWarningToTerminal(const char* fmt, ...) { va_list va; @@ -132,6 +154,28 @@ void Log_logWarning(const char* fmt, ...) { va_end(va2); } +void Log_vLogWarningToTerminal(const char* fmt, va_list va) { + vLogToTerminal(LOG_TYPE_WARNING, fmt, va); +} + +void Log_vLogWarningToFile(const char* fmt, va_list va) { + vLogToFile(LOG_TYPE_WARNING, fmt, va); +} + +void Log_vLogWarning(const char* fmt, va_list va) { + va_list va2; + va_copy(va2, va); + + if (logToTerminal) { + vLogToTerminal(LOG_TYPE_WARNING, fmt, va); + } + if (logToFile) { + vLogToFile(LOG_TYPE_WARNING, fmt, va2); + } + + va_end(va2); +} + void Log_logErrorToTerminal(const char* fmt, ...) { va_list va; @@ -164,3 +208,25 @@ void Log_logError(const char* fmt, ...) { va_end(va); va_end(va2); } + +void Log_vLogErrorToTerminal(const char* fmt, va_list va) { + vLogToTerminal(LOG_TYPE_ERROR, fmt, va); +} + +void Log_vLogErrorToFile(const char* fmt, va_list va) { + vLogToFile(LOG_TYPE_ERROR, fmt, va); +} + +void Log_vLogError(const char* fmt, va_list va) { + va_list va2; + va_copy(va2, va); + + if (logToTerminal) { + vLogToTerminal(LOG_TYPE_ERROR, fmt, va); + } + if (logToFile) { + vLogToFile(LOG_TYPE_ERROR, fmt, va2); + } + + va_end(va2); +} diff --git a/src/log.h b/src/log.h index 7116b8faa..7350466c8 100644 --- a/src/log.h +++ b/src/log.h @@ -10,12 +10,24 @@ void Log_logToTerminal(const char* fmt, ...); void Log_logToFile(const char* fmt, ...); void Log_log(const char* fmt, ...); +void Log_vLogToTerminal(const char* fmt, va_list va); +void Log_vLogToFile(const char* fmt, va_list va); +void Log_vLog(const char* fmt, va_list va); + void Log_logWarningToTerminal(const char* fmt, ...); void Log_logWarningToFile(const char* fmt, ...); void Log_logWarning(const char* fmt, ...); +void Log_vLogWarningToTerminal(const char* fmt, va_list va); +void Log_vLogWarningToFile(const char* fmt, va_list va); +void Log_vLogWarning(const char* fmt, va_list va); + void Log_logErrorToTerminal(const char* fmt, ...); void Log_logErrorToFile(const char* fmt, ...); void Log_logError(const char* fmt, ...); +void Log_vLogErrorToTerminal(const char* fmt, va_list va); +void Log_vLogErrorToFile(const char* fmt, va_list va); +void Log_vLogError(const char* fmt, va_list va); + #endif /* _BS_LOG_H */ diff --git a/src/utils.h b/src/utils.h index c527822ba..322aea474 100644 --- a/src/utils.h +++ b/src/utils.h @@ -12,6 +12,8 @@ #include "real_type.h" +#include "log.h" + #ifdef PLATFORM_PS2 #include #endif @@ -45,34 +47,34 @@ #define require(condition) \ do { \ if (!(condition)) { \ - fprintf(stderr, "Requirement failed at %s:%d\n", __FILE__, __LINE__); \ + Log_logError("Requirement failed at %s:%d\n", __FILE__, __LINE__); \ abort(); \ } \ } while (0) #define requireMessage(condition, message) \ -do { \ -if (!(condition)) { \ -fprintf(stderr, "Requirement failed at %s:%d: %s\n", __FILE__, __LINE__, message); \ -abort(); \ -} \ + do { \ + if (!(condition)) { \ + Log_logError("Requirement failed at %s:%d: %s\n", __FILE__, __LINE__, message); \ + abort(); \ + } \ } while (0) static inline void requireMessageFormatted(const char *file, int line, bool condition, const char *fmt, ...) { if (condition) return; va_list args; - fprintf(stderr, "Requirement failed at %s:%d: ", file, line); + Log_logError("Requirement failed at %s:%d: ", file, line); va_start(args, fmt); - vfprintf(stderr, fmt, args); + Log_vLogError(fmt, args); va_end(args); - fputc('\n', stderr); + Log_logError("\n"); abort(); } static inline void* requireNotNullFunction(void* ptr, const char* file, int line, const char* name) { if (!ptr) { - fprintf(stderr, "%s:%d: requireNotNull failed: '%s'\n", file, line, name); + Log_logError("%s:%d: requireNotNull failed: '%s'\n", file, line, name); abort(); } return ptr; @@ -84,7 +86,7 @@ static inline void* requireNotNullFunction(void* ptr, const char* file, int line static inline void *safeMallocFunction(size_t size, const char *file, int line) { void *ret = malloc(size); if (!ret) { - fprintf(stderr, "FATAL: malloc(%zu) failed at %s:%d\n", size, file, line); + Log_logError("FATAL: malloc(%zu) failed at %s:%d\n", size, file, line); abort(); } return ret; @@ -94,7 +96,7 @@ static inline void *safeMallocFunction(size_t size, const char *file, int line) static inline void *safeCallocFunction(size_t count, size_t size, const char *file, int line) { void *ret = calloc(count, size); if (!ret) { - fprintf(stderr, "FATAL: calloc(%zu, %zu) failed at %s:%d\n", count, size, file, line); + Log_logError("FATAL: calloc(%zu, %zu) failed at %s:%d\n", count, size, file, line); abort(); } return ret; @@ -104,7 +106,7 @@ static inline void *safeCallocFunction(size_t count, size_t size, const char *fi static inline void *safeReallocFunction(void *ptr, size_t size, const char *file, int line) { void *ret = realloc(ptr, size); if (!ret) { - fprintf(stderr, "FATAL: realloc(%zu) failed at %s:%d\n", size, file, line); + Log_logError("FATAL: realloc(%zu) failed at %s:%d\n", size, file, line); abort(); } return ret; @@ -116,7 +118,7 @@ static inline void *safeReallocFunction(void *ptr, size_t size, const char *file static inline void *safeMemalignFunction(size_t alignment, size_t size, const char *file, int line) { void *ret = memalign(alignment, size); if (!ret) { - fprintf(stderr, "FATAL: memalign(%zu, %zu) failed at %s:%d\n", alignment, size, file, line); + Log_logError("FATAL: memalign(%zu, %zu) failed at %s:%d\n", alignment, size, file, line); abort(); } return ret; @@ -128,7 +130,7 @@ static inline void *safeMemalignFunction(size_t alignment, size_t size, const ch // Reads exactly n bytes or aborts with the "pathForError" that caused the error. static inline void safeFreadFunction(void *dst, size_t n, FILE *read_file, const char *pathForError, const char *file, int line) { if (fread(dst, 1, n, read_file) != n) { - fprintf(stderr, "FATAL: failed to read %zu bytes from %s at %s:%d\n", n, pathForError, file, line); + Log_logError("FATAL: failed to read %zu bytes from %s at %s:%d\n", n, pathForError, file, line); abort(); } } @@ -137,7 +139,7 @@ static inline void safeFreadFunction(void *dst, size_t n, FILE *read_file, const static inline char *safeStrdupFunction(const char *str, const char *file, int line) { char *ret = strdup(str); if (!ret) { - fprintf(stderr, "FATAL: strdup() failed at %s:%d\n", file, line); + Log_logError("FATAL: strdup() failed at %s:%d\n", file, line); abort(); } return ret; From 3ebd225a0fe4158de4930e4e682dbfbe7095f871 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 18:47:22 +0800 Subject: [PATCH 06/57] Replace most calls of fprintf(stderr, ...) with Log_log* functions --- src/android/main.c | 2 +- src/audio/miniaudio/ma_audio_system.c | 38 ++++----- src/audio/openal/al_audio_system.c | 48 +++++------ src/audio/ps2/ps2_audio_system.c | 68 ++++++++-------- src/audio/web/web_audio_system.c | 32 ++++---- src/binary_reader.c | 10 +-- src/data_win.c | 26 +++--- src/desktop/backends/glfw2.c | 8 +- src/desktop/backends/glfw3.c | 16 ++-- src/desktop/backends/sdl1.c | 22 ++--- src/desktop/backends/sdl2.c | 32 ++++---- src/desktop/backends/sdl3.c | 26 +++--- src/desktop/main.c | 112 +++++++++++++------------- src/event_table.c | 2 +- src/gl/gl_renderer.c | 82 +++++++++---------- src/gl_legacy/gl_legacy_renderer.c | 64 +++++++-------- src/image/image_decoder.c | 4 +- src/ini.c | 2 +- src/input_recording.c | 12 +-- src/json_reader.c | 24 +++--- src/ps2/debug_font_renderer.c | 4 +- src/ps2/gs_renderer.c | 64 +++++++-------- src/ps2/main.c | 14 ++-- src/ps2/ps2_file_system.c | 12 +-- src/ps2/ps2_utils.c | 20 ++--- src/ps3/main.c | 8 +- src/ps3/ps3_overlay.c | 2 +- src/ps3/ps3_textures.c | 10 +-- src/runner.c | 84 +++++++++---------- src/runner.h | 4 +- src/spatial_grid.c | 4 +- src/vm.c | 98 +++++++++++----------- src/vm.h | 2 +- src/vm_builtins.c | 112 +++++++++++++------------- src/web/main.c | 12 +-- 35 files changed, 541 insertions(+), 539 deletions(-) diff --git a/src/android/main.c b/src/android/main.c index 741eb4df9..d1ec5bdb6 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -633,7 +633,7 @@ static bool performGameChange(const char* workingDirectory, char* launchParamete } if (dataWinFilename == nullptr) { - fprintf(stderr, "Runner: Launch parameters '%s' did not contain a '-game ' entry! Shutting down...\n", launchParameters); + Log_logError("Runner: Launch parameters '%s' did not contain a '-game ' entry! Shutting down...\n", launchParameters); repeat(arrlen(newArguments), i) { free(newArguments[i]); } diff --git a/src/audio/miniaudio/ma_audio_system.c b/src/audio/miniaudio/ma_audio_system.c index 3ec79ec7c..8752011b8 100644 --- a/src/audio/miniaudio/ma_audio_system.c +++ b/src/audio/miniaudio/ma_audio_system.c @@ -109,14 +109,14 @@ static void maInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem) deviceConfig.pUserData = &ma->engine; ma_result deviceResult = ma_device_init(NULL, &deviceConfig, &ma->device); if (deviceResult != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to initialize playback device (error %d)\n", deviceResult); + Log_logError("Audio: Failed to initialize playback device (error %d)\n", deviceResult); return; } ma_engine_config config = ma_engine_config_init(); config.pDevice = &ma->device; ma_result result = ma_engine_init(&config, &ma->engine); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to initialize miniaudio engine (error %d)\n", result); + Log_logError("Audio: Failed to initialize miniaudio engine (error %d)\n", result); ma_device_uninit(&ma->device); return; } @@ -130,7 +130,7 @@ static void maInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem) ma->listenerGains[i] = 1.0f; } - fprintf(stderr, "Audio: miniaudio engine initialized\n"); + Log_log("Audio: miniaudio engine initialized\n"); } static void maDestroy(AudioSystem* audio) { @@ -215,7 +215,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior if (isStream) { int32_t streamSlot = soundIndex - AUDIO_STREAM_INDEX_BASE; if (0 > streamSlot || streamSlot >= MAX_AUDIO_STREAMS || !ma->streams[streamSlot].active) { - fprintf(stderr, "Audio: Invalid stream index %d\n", soundIndex); + Log_logWarning("Audio: Invalid stream index %d\n", soundIndex); return -1; } AudioStreamEntry* stream = &ma->streams[streamSlot]; @@ -225,7 +225,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior } else { DataWin* dw = ma->base.audioGroups[0]; // Audio Group 0 should always be data.win if (0 > soundIndex || (uint32_t) soundIndex >= dw->sond.count) { - fprintf(stderr, "Audio: Invalid sound index %d\n", soundIndex); + Log_logWarning("Audio: Invalid sound index %d\n", soundIndex); return -1; } sound = &dw->sond.sounds[soundIndex]; @@ -233,7 +233,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior SoundInstance* slot = findFreeSlot(ma); if (slot == nullptr) { - fprintf(stderr, "Audio: No free sound slots for sound %d\n", soundIndex); + Log_logWarning("Audio: No free sound slots for sound %d\n", soundIndex); return -1; } @@ -244,7 +244,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior // Stream audio: load from file path stored in stream entry result = ma_sound_init_from_file(&ma->engine, streamPath, MA_SOUND_FLAG_ASYNC, &ma->listenerGroups[0], nullptr, &slot->maSound); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to load stream file '%s' (error %d)\n", streamPath, result); + Log_logWarning("Audio: Failed to load stream file '%s' (error %d)\n", streamPath, result); return -1; } slot->ownsDecoder = false; @@ -257,7 +257,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior if (inAudo) { // Embedded audio: decode from AUDO chunk memory if (0 > sound->audioFile || (uint32_t) sound->audioFile >= ma->base.audioGroups[sound->audioGroup]->audo.count) { - fprintf(stderr, "Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); + Log_logWarning("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); return -1; } @@ -266,14 +266,14 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior ma_decoder_config decoderConfig = ma_decoder_config_init_default(); result = ma_decoder_init_memory(entry->data, entry->dataSize, &decoderConfig, &slot->decoder); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to init decoder for '%s' (error %d)\n", sound->name, result); + Log_logWarning("Audio: Failed to init decoder for '%s' (error %d)\n", sound->name, result); return -1; } slot->ownsDecoder = true; result = ma_sound_init_from_data_source(&ma->engine, &slot->decoder, 0, &ma->listenerGroups[0], &slot->maSound); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to init sound from decoder for '%s' (error %d)\n", sound->name, result); + Log_logWarning("Audio: Failed to init sound from decoder for '%s' (error %d)\n", sound->name, result); ma_decoder_uninit(&slot->decoder); return -1; } @@ -281,13 +281,13 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior // External audio: load from file char* path = resolveExternalPath(ma, sound); if (path == nullptr) { - fprintf(stderr, "Audio: Could not resolve path for sound '%s'\n", sound->name); + Log_logWarning("Audio: Could not resolve path for sound '%s'\n", sound->name); return -1; } result = ma_sound_init_from_file(&ma->engine, path, MA_SOUND_FLAG_ASYNC, &ma->listenerGroups[0], nullptr, &slot->maSound); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to load file for '%s' at '%s' (error %d)\n", sound->name, path, result); + Log_logWarning("Audio: Failed to load file for '%s' at '%s' (error %d)\n", sound->name, path, result); free(path); return -1; } @@ -741,7 +741,7 @@ static void maGroupLoad(AudioSystem* audio, int32_t groupIndex) { // The original runner does not care if the file doesn't exist (this may happen if someone uses "audio_group_load" on a non-existent group) FileSystem* fileSystem = ((MaAudioSystem*)audio)->fileSystem; if (!fileSystem->vtable->fileExists(fileSystem, buf)) { - fprintf(stderr, "Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the file system!\n", groupIndex, groupIndex); + Log_logWarning("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the file system!\n", groupIndex, groupIndex); free(buf); DataWin* dw = (DataWin *)safeCalloc(1, sizeof(DataWin)); arrput(audio->audioGroups, dw); @@ -754,7 +754,7 @@ static void maGroupLoad(AudioSystem* audio, int32_t groupIndex) { arrput(audio->audioGroups, audioGroup); free(buf); } else { - fprintf(stderr, "Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the AGPR!\n", groupIndex, groupIndex); + Log_logWarning("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the AGPR!\n", groupIndex, groupIndex); } } @@ -777,13 +777,13 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { } if (0 > freeSlot) { - fprintf(stderr, "Audio: No free stream slots for '%s'\n", filename); + Log_logWarning("Audio: No free stream slots for '%s'\n", filename); return -1; } char* resolved = ma->fileSystem->vtable->resolvePath(ma->fileSystem, filename); if (resolved == nullptr) { - fprintf(stderr, "Audio: Could not resolve path for stream '%s'\n", filename); + Log_logWarning("Audio: Could not resolve path for stream '%s'\n", filename); return -1; } @@ -793,7 +793,7 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { ma->streams[freeSlot].initialPitch = 1.0f; int32_t streamIndex = AUDIO_STREAM_INDEX_BASE + freeSlot; - fprintf(stderr, "Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); + Log_logWarning("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); return streamIndex; } @@ -802,7 +802,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { int32_t slotIndex = streamIndex - AUDIO_STREAM_INDEX_BASE; if (0 > slotIndex || slotIndex >= MAX_AUDIO_STREAMS) { - fprintf(stderr, "Audio: Invalid stream index %d for destroy\n", streamIndex); + Log_logWarning("Audio: Invalid stream index %d for destroy\n", streamIndex); return false; } @@ -825,7 +825,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { free(entry->filePath); entry->filePath = nullptr; entry->active = false; - fprintf(stderr, "Audio: Destroyed stream %d\n", streamIndex); + Log_logWarning("Audio: Destroyed stream %d\n", streamIndex); return true; } diff --git a/src/audio/openal/al_audio_system.c b/src/audio/openal/al_audio_system.c index a2223b03f..758d325f9 100644 --- a/src/audio/openal/al_audio_system.c +++ b/src/audio/openal/al_audio_system.c @@ -170,14 +170,14 @@ static void maInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem) ma->alContext = alcCreateContext(ma->alDevice, nullptr); alcMakeContextCurrent(ma->alContext); if (ma->alDevice == nullptr || ma->alContext == nullptr) { - fprintf(stderr, "Audio: Failed to initialize OpenAL engine (error %d)\n", alGetError()); + Log_logError("Audio: Failed to initialize OpenAL engine (error %d)\n", alGetError()); return; } memset(ma->instances, 0, sizeof(ma->instances)); ma->nextInstanceCounter = 0; - fprintf(stderr, "Audio: OpenAL engine initialized\n"); + Log_log("Audio: OpenAL engine initialized\n"); } static void maDestroy(AudioSystem* audio) { @@ -289,14 +289,14 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior if (isStream) { int32_t streamSlot = soundIndex - AUDIO_STREAM_INDEX_BASE; if (0 > streamSlot || streamSlot >= MAX_AUDIO_STREAMS || !ma->streams[streamSlot].active) { - fprintf(stderr, "Audio: Invalid stream index %d\n", soundIndex); + Log_logWarning("Audio: Invalid stream index %d\n", soundIndex); return -1; } streamPath = ma->streams[streamSlot].filePath; } else { DataWin* dw = ma->base.audioGroups[0]; // Audio Group 0 should always be data.win if (0 > soundIndex || (uint32_t) soundIndex >= dw->sond.count) { - fprintf(stderr, "Audio: Invalid sound index %d\n", soundIndex); + Log_logWarning("Audio: Invalid sound index %d\n", soundIndex); return -1; } sound = &dw->sond.sounds[soundIndex]; @@ -304,7 +304,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior SoundInstance* slot = findFreeSlot(ma); if (slot == nullptr) { - fprintf(stderr, "Audio: No free sound slots for sound %d\n", soundIndex); + Log_logWarning("Audio: No free sound slots for sound %d\n", soundIndex); return -1; } @@ -322,7 +322,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior int err = 0; stb_vorbis* v = stb_vorbis_open_filename(streamPath, &err, nullptr); if (v == nullptr) { - fprintf(stderr, "Audio: Failed to open stream '%s' (stb_vorbis err %d)\n", streamPath, err); + Log_logWarning("Audio: Failed to open stream '%s' (stb_vorbis err %d)\n", streamPath, err); return -1; } stb_vorbis_info info = stb_vorbis_get_info(v); @@ -368,7 +368,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior if (inAudo) { // Embedded audio: decode from AUDO chunk memory if (0 > sound->audioFile || (uint32_t) sound->audioFile >= ma->base.audioGroups[sound->audioGroup]->audo.count) { - fprintf(stderr, "Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); + Log_logWarning("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); return -1; } @@ -380,7 +380,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior { if (wav.header.bits_per_sample == 8) format = AL_FORMAT_MONO8; - else + else format = AL_FORMAT_MONO16; } else { @@ -390,10 +390,10 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior format = AL_FORMAT_STEREO16; } alBufferData( - slot->alBuffer, - format, - wav.data, - wav.data_length, + slot->alBuffer, + format, + wav.data, + wav.data_length, wav.header.sample_rate ); alSourcei(slot->alSource, AL_BUFFER, slot->alBuffer); @@ -402,7 +402,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior // External audio: load from file char* path = resolveExternalPath(ma, sound); if (path == nullptr) { - fprintf(stderr, "Audio: Could not resolve path for sound '%s'\n", sound->name); + Log_logWarning("Audio: Could not resolve path for sound '%s'\n", sound->name); return -1; } @@ -411,10 +411,10 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior short* data = NULL; int len = stb_vorbis_decode_filename(path, &channels, &sample_rate, &data); alBufferData( - slot->alBuffer, - (channels == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, - (void*)data, - len*channels*sizeof(uint16_t), + slot->alBuffer, + (channels == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, + (void*)data, + len*channels*sizeof(uint16_t), sample_rate ); alSourcei(slot->alSource, AL_BUFFER, slot->alBuffer); @@ -684,7 +684,7 @@ static float maGetSoundPitch(AudioSystem* audio, int32_t soundOrInstance) { static float streamCursorSeconds(SoundInstance* inst) { if (0 >= inst->streamSampleRate) return 0.0f; - + ALint sampleOffset = 0; alGetSourcei(inst->alSource, AL_SAMPLE_OFFSET, &sampleOffset); uint64_t total = inst->playedSamples + (uint64_t) sampleOffset; @@ -817,7 +817,7 @@ static void maGroupLoad(AudioSystem* audio, int32_t groupIndex) { FileSystem* fileSystem = ((AlAudioSystem*)audio)->fileSystem; char* resolvedPath = (((AlAudioSystem*)audio)->fileSystem->vtable->resolvePath(((AlAudioSystem*)audio)->fileSystem, buf)); if (!fileSystem->vtable->fileExists(fileSystem, resolvedPath)) { - fprintf(stderr, "Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist!\n", groupIndex, groupIndex); + Log_logWarning("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist!\n", groupIndex, groupIndex); free(buf); return; } @@ -849,13 +849,13 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { } if (0 > freeSlot) { - fprintf(stderr, "Audio: No free stream slots for '%s'\n", filename); + Log_logWarning("Audio: No free stream slots for '%s'\n", filename); return -1; } char* resolved = ma->fileSystem->vtable->resolvePath(ma->fileSystem, filename); if (resolved == nullptr) { - fprintf(stderr, "Audio: Could not resolve path for stream '%s'\n", filename); + Log_logWarning("Audio: Could not resolve path for stream '%s'\n", filename); return -1; } @@ -863,7 +863,7 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { ma->streams[freeSlot].filePath = resolved; int32_t streamIndex = AUDIO_STREAM_INDEX_BASE + freeSlot; - fprintf(stderr, "Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); + Log_log("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); return streamIndex; } @@ -872,7 +872,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { int32_t slotIndex = streamIndex - AUDIO_STREAM_INDEX_BASE; if (0 > slotIndex || slotIndex >= MAX_AUDIO_STREAMS) { - fprintf(stderr, "Audio: Invalid stream index %d for destroy\n", streamIndex); + Log_logWarning("Audio: Invalid stream index %d for destroy\n", streamIndex); return false; } @@ -890,7 +890,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { free(entry->filePath); entry->filePath = nullptr; entry->active = false; - fprintf(stderr, "Audio: Destroyed stream %d\n", streamIndex); + Log_log("Audio: Destroyed stream %d\n", streamIndex); return true; } diff --git a/src/audio/ps2/ps2_audio_system.c b/src/audio/ps2/ps2_audio_system.c index 29bf9fa7f..697a03522 100644 --- a/src/audio/ps2/ps2_audio_system.c +++ b/src/audio/ps2/ps2_audio_system.c @@ -82,7 +82,7 @@ static void parseSoundBank(Ps2AudioSystem* ps2) { FILE* f = fopen(path, "rb"); free(path); if (f == nullptr) { - fprintf(stderr, "PS2AudioSystem: Could not open SOUNDBNK.BIN\n"); + Log_logError("PS2AudioSystem: Could not open SOUNDBNK.BIN\n"); return; } @@ -93,7 +93,7 @@ static void parseSoundBank(Ps2AudioSystem* ps2) { fread(&ps2->audoEntryCount, 2, 1, f); fread(&ps2->musEntryCount, 2, 1, f); - fprintf(stderr, "PS2AudioSystem: SOUNDBNK v%d, %d SOND entries, %d AUDO entries, %d MUS entries\n", version, ps2->sondEntryCount, ps2->audoEntryCount, ps2->musEntryCount); + Log_log("PS2AudioSystem: SOUNDBNK v%d, %d SOND entries, %d AUDO entries, %d MUS entries\n", version, ps2->sondEntryCount, ps2->audoEntryCount, ps2->musEntryCount); // Parse SOND entries (12 bytes each) ps2->sondEntries = safeMalloc(ps2->sondEntryCount * sizeof(Ps2SondEntry)); @@ -148,7 +148,7 @@ static void parseSoundBank(Ps2AudioSystem* ps2) { } if (ps2->musEntryCount > 0) { - fprintf(stderr, "PS2AudioSystem: Loaded %d MUS entries\n", ps2->musEntryCount); + Log_log("PS2AudioSystem: Loaded %d MUS entries\n", ps2->musEntryCount); } fclose(f); @@ -163,12 +163,12 @@ static void openSoundsBin(Ps2AudioSystem* ps2) { ps2->soundsFile = fopen(path, "rb"); if (ps2->soundsFile == nullptr) { - fprintf(stderr, "PS2AudioSystem: Could not open SOUNDS.BIN at %s\n", path); + Log_logWarning("PS2AudioSystem: Could not open SOUNDS.BIN at %s\n", path); free(path); return; } - fprintf(stderr, "PS2AudioSystem: Opened SOUNDS.BIN for streaming (%s)\n", path); + Log_log("PS2AudioSystem: Opened SOUNDS.BIN for streaming (%s)\n", path); free(path); } @@ -221,7 +221,7 @@ static DecodedPcmEntry* cacheInsert(Ps2AudioSystem* ps2, int32_t audoIndex) { } if (slot == nullptr) { - // fprintf(stderr, "PS2AudioSystem: Cache full, all entries in use! Cannot decode audoIndex %" PRId32 "\n", audoIndex); + // Log_logWarning("PS2AudioSystem: Cache full, all entries in use! Cannot decode audoIndex %" PRId32 "\n", audoIndex); return nullptr; } @@ -533,14 +533,14 @@ static void ps2Init(AudioSystem* audio, MAYBE_UNUSED DataWin* dataWin, MAYBE_UNU // Parse sound bank index parseSoundBank(ps2); if (ps2->sondEntries == nullptr || ps2->audoEntries == nullptr) { - fprintf(stderr, "PS2AudioSystem: Failed to parse SOUNDBNK.BIN, audio disabled\n"); + Log_logWarning("PS2AudioSystem: Failed to parse SOUNDBNK.BIN, audio disabled\n"); return; } // Open SOUNDS.BIN for streaming (kept open for on-demand reads) openSoundsBin(ps2); if (ps2->soundsFile == nullptr) { - fprintf(stderr, "PS2AudioSystem: Failed to open SOUNDS.BIN, audio disabled\n"); + Log_logWarning("PS2AudioSystem: Failed to open SOUNDS.BIN, audio disabled\n"); return; } @@ -559,7 +559,7 @@ static void ps2Init(AudioSystem* audio, MAYBE_UNUSED DataWin* dataWin, MAYBE_UNU // Initialize audsrv int ret = audsrv_init(); if (ret != 0) { - fprintf(stderr, "PS2AudioSystem: audsrv_init failed (%d)\n", ret); + Log_logWarning("PS2AudioSystem: audsrv_init failed (%d)\n", ret); return; } @@ -570,7 +570,7 @@ static void ps2Init(AudioSystem* audio, MAYBE_UNUSED DataWin* dataWin, MAYBE_UNU ret = audsrv_set_format(&format); if (ret != 0) { - fprintf(stderr, "PS2AudioSystem: audsrv_set_format failed (%d)\n", ret); + Log_logWarning("PS2AudioSystem: audsrv_set_format failed (%d)\n", ret); audsrv_quit(); return; } @@ -578,7 +578,7 @@ static void ps2Init(AudioSystem* audio, MAYBE_UNUSED DataWin* dataWin, MAYBE_UNU audsrv_set_volume(MAX_VOLUME); ps2->initialized = true; - fprintf(stderr, "PS2AudioSystem: Initialized (output: %d Hz, 16-bit, stereo)\n", AUDSRV_OUTPUT_FREQ); + Log_log("PS2AudioSystem: Initialized (output: %d Hz, 16-bit, stereo)\n", AUDSRV_OUTPUT_FREQ); } static void ps2Destroy(AudioSystem* audio) { @@ -657,7 +657,7 @@ static void ps2Update(AudioSystem* audio, float deltaTime) { repeat(MAX_MUSIC_STREAMS, i) { Ps2MusicStream* stream = &ps2->musicStreams[i]; if (!stream->active || !stream->needsRefill) continue; - // fprintf(stderr, "PS2AudioSystem: Filling music stream %d back buffers...\n", stream->soundIndex); + // Log_log("PS2AudioSystem: Filling music stream %d back buffers...\n", stream->soundIndex); int backBuffer = stream->activeBuffer ^ 1; streamFillBuffer(ps2, stream, backBuffer); @@ -667,16 +667,16 @@ static void ps2Update(AudioSystem* audio, float deltaTime) { // Fill audsrv ring buffer int32_t chunkBytes = MIX_BUFFER_SAMPLES * 2 * (int32_t) sizeof(int16_t); while (audsrv_available() >= chunkBytes) { - // fprintf(stderr, "PS2AudioSystem: Filling audsrv ring buffer... audsrv_available: %d, chunkBytes: %d\n", audsrv_available(), chunkBytes); + // Log_log("PS2AudioSystem: Filling audsrv ring buffer... audsrv_available: %d, chunkBytes: %d\n", audsrv_available(), chunkBytes); mixAudio(ps2, ps2->mixBuffer, MIX_BUFFER_SAMPLES); audsrv_play_audio((char*) ps2->mixBuffer, chunkBytes); } - // fprintf(stderr, "PS2AudioSystem: Finished ticking the audio system\n"); + // Log_log("PS2AudioSystem: Finished ticking the audio system\n"); } static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t priority, bool loop) { - // fprintf(stderr, "PS2AudioSystem: Attempting to play sound index %d with priority %d, should loop? %d\n", soundIndex, priority, loop); + // Log_log("PS2AudioSystem: Attempting to play sound index %d with priority %d, should loop? %d\n", soundIndex, priority, loop); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; if (!ps2->initialized) return -1; @@ -732,13 +732,13 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio stream->readPosition = 0; stream->needsRefill = false; - // fprintf(stderr, "PS2AudioSystem: Streaming MUS '%s', size=%" PRIu32 " bytes, instanceId=%" PRId32 "\n", mus->name, mus->dataSize, instanceId); + // Log_log("PS2AudioSystem: Streaming MUS '%s', size=%" PRIu32 " bytes, instanceId=%" PRId32 "\n", mus->name, mus->dataSize, instanceId); return instanceId; } if (0 > soundIndex || (uint16_t) soundIndex >= ps2->sondEntryCount) { - // fprintf(stderr, "PS2AudioSystem: Invalid sound index %" PRId32 "\n", soundIndex); + // Log_logWarning("PS2AudioSystem: Invalid sound index %" PRId32 "\n", soundIndex); return -1; } @@ -750,7 +750,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio } if (sond->audoIndex >= ps2->audoEntryCount) { - // fprintf(stderr, "PS2AudioSystem: Invalid audo index %d for sound %" PRId32 "\n", sond->audoIndex, soundIndex); + // Log_logWarning("PS2AudioSystem: Invalid audo index %d for sound %" PRId32 "\n", sond->audoIndex, soundIndex); return -1; } @@ -767,7 +767,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio Ps2AudoEntry* audoForSize = &ps2->audoEntries[sond->audoIndex]; uint32_t decodedPcmBytes = audoForSize->dataSize * 2 * (uint32_t) sizeof(int16_t); if ((isEmbedded || isCompressed) && decodedPcmBytes > PS2_SFX_CACHE_MAX_BYTES) { - fprintf(stderr, "PS2AudioSystem: Sound %" PRId32 " (audo %d) would need %" PRIu32 " bytes of PCM in the cache! isEmbedded? %s; isCompressed? %s; Streaming instead...\n", soundIndex, sond->audoIndex, decodedPcmBytes, isEmbedded ? "true" : "false", isCompressed ? "true" : "false"); + Log_logWarning("PS2AudioSystem: Sound %" PRId32 " (audo %d) would need %" PRIu32 " bytes of PCM in the cache! isEmbedded? %s; isCompressed? %s; Streaming instead...\n", soundIndex, sond->audoIndex, decodedPcmBytes, isEmbedded ? "true" : "false", isCompressed ? "true" : "false"); isEmbedded = false; isCompressed = false; } @@ -786,7 +786,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio } if (stream == nullptr) { - // fprintf(stderr, "PS2AudioSystem: No free music stream slots for sound %" PRId32 "\n", soundIndex); + // Log_logWarning("PS2AudioSystem: No free music stream slots for sound %" PRId32 "\n", soundIndex); return -1; } @@ -825,7 +825,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio stream->readPosition = 0; stream->needsRefill = false; - // fprintf(stderr, "PS2AudioSystem: Streaming music soundIndex=%" PRId32 " audoIndex=%d, size=%" PRIu32 " bytes, instanceId=%" PRId32 "\n", soundIndex, sond->audoIndex, audo->dataSize, instanceId); + // Log_log("PS2AudioSystem: Streaming music soundIndex=%" PRId32 " audoIndex=%d, size=%" PRIu32 " bytes, instanceId=%" PRId32 "\n", soundIndex, sond->audoIndex, audo->dataSize, instanceId); return instanceId; } @@ -836,7 +836,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio if (cached == nullptr) { cached = cacheInsert(ps2, sond->audoIndex); if (cached == nullptr) { - // fprintf(stderr, "PS2AudioSystem: Failed to cache decoded audio for sound %" PRId32 "\n", soundIndex); + // Log_logWarning("PS2AudioSystem: Failed to cache decoded audio for sound %" PRId32 "\n", soundIndex); return -1; } } @@ -844,7 +844,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio // Find a free SFX instance slot Ps2SoundInstance* slot = findFreeSlot(ps2); if (slot == nullptr) { - // fprintf(stderr, "PS2AudioSystem: No free sound slots for sound %" PRId32 "\n", soundIndex); + // Log_logWarning("PS2AudioSystem: No free sound slots for sound %" PRId32 "\n", soundIndex); return -1; } @@ -978,12 +978,12 @@ static void actionSetPitch(Ps2SoundInstance* sfx, Ps2MusicStream* music, void* u // ===[ Vtable: Stop/Pause/Resume/Gain/Pitch ]=== static void ps2StopSound(AudioSystem* audio, int32_t soundOrInstance) { - // fprintf(stderr, "PS2AudioSystem: Stopping sound %d\n", soundOrInstance); + // Log_log("PS2AudioSystem: Stopping sound %d\n", soundOrInstance); forEachInstance((Ps2AudioSystem*) audio, soundOrInstance, actionStop, nullptr); } static void ps2StopAll(AudioSystem* audio) { - // fprintf(stderr, "PS2AudioSystem: Stopping all audios!\n"); + // Log_log("PS2AudioSystem: Stopping all audios!\n"); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; repeat(MAX_PS2_SOUND_INSTANCES, i) { ps2->instances[i].active = false; @@ -1023,17 +1023,17 @@ static bool ps2IsPlaying(AudioSystem* audio, int32_t soundOrInstance) { } static void ps2PauseSound(AudioSystem* audio, int32_t soundOrInstance) { - // fprintf(stderr, "PS2AudioSystem: Pausing sound %d\n", soundOrInstance); + // Log_log("PS2AudioSystem: Pausing sound %d\n", soundOrInstance); forEachInstance((Ps2AudioSystem*) audio, soundOrInstance, actionPause, nullptr); } static void ps2ResumeSound(AudioSystem* audio, int32_t soundOrInstance) { - // fprintf(stderr, "PS2AudioSystem: Resuming sound %d\n", soundOrInstance); + // Log_log("PS2AudioSystem: Resuming sound %d\n", soundOrInstance); forEachInstance((Ps2AudioSystem*) audio, soundOrInstance, actionResume, nullptr); } static void ps2PauseAll(AudioSystem* audio) { - // fprintf(stderr, "PS2AudioSystem: Pausing all sounds!\n"); + // Log_log("PS2AudioSystem: Pausing all sounds!\n"); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; repeat(MAX_PS2_SOUND_INSTANCES, i) { if (ps2->instances[i].active) ps2->instances[i].paused = true; @@ -1044,7 +1044,7 @@ static void ps2PauseAll(AudioSystem* audio) { } static void ps2ResumeAll(AudioSystem* audio) { - // fprintf(stderr, "PS2AudioSystem: Resuming all sounds!\n"); + // Log_log("PS2AudioSystem: Resuming all sounds!\n"); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; repeat(MAX_PS2_SOUND_INSTANCES, i) { if (ps2->instances[i].active) ps2->instances[i].paused = false; @@ -1082,7 +1082,7 @@ static float ps2GetSoundGain(AudioSystem* audio, int32_t soundOrInstance) { } static void ps2SetSoundPitch(AudioSystem* audio, int32_t soundOrInstance, float pitch) { - // fprintf(stderr, "PS2AudioSystem: Setting pitch of sound %d to %f\n", soundOrInstance, pitch); + // Log_log("PS2AudioSystem: Setting pitch of sound %d to %f\n", soundOrInstance, pitch); forEachInstance((Ps2AudioSystem*) audio, soundOrInstance, actionSetPitch, &pitch); } @@ -1175,7 +1175,7 @@ static void seekMusicStream(Ps2AudioSystem* ps2, Ps2MusicStream* music, float po } static void ps2SetTrackPosition(AudioSystem* audio, int32_t soundOrInstance, float positionSeconds) { - // fprintf(stderr, "PS2AudioSystem: Setting track position of sound %d to %f\n", soundOrInstance, positionSeconds); + // Log_log("PS2AudioSystem: Setting track position of sound %d to %f\n", soundOrInstance, positionSeconds); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; if (soundOrInstance >= PS2_AUDIO_STREAM_INDEX_BASE) { @@ -1264,7 +1264,7 @@ static float ps2GetSoundLength(AudioSystem* audio, int32_t soundOrInstance) { } static void ps2SetMasterGain(AudioSystem* audio, float gain) { - // fprintf(stderr, "PS2AudioSystem: Setting master gain to %f\n", gain); + // Log_log("PS2AudioSystem: Setting master gain to %f\n", gain); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; ps2->masterGain = gain; } @@ -1295,12 +1295,12 @@ static int32_t ps2CreateStream(AudioSystem* audio, const char* filename) { for (int i = 0; ps2->musEntryCount > i; i++) { if (strcmp(ps2->musEntries[i].name, filename) == 0) { int32_t streamIndex = PS2_AUDIO_STREAM_INDEX_BASE + i; - fprintf(stderr, "PS2AudioSystem: Created stream %" PRId32 " for '%s'\n", streamIndex, filename); + Log_log("PS2AudioSystem: Created stream %" PRId32 " for '%s'\n", streamIndex, filename); return streamIndex; } } - fprintf(stderr, "PS2AudioSystem: audio_create_stream: '%s' not found in MUS entries\n", filename); + Log_logWarning("PS2AudioSystem: audio_create_stream: '%s' not found in MUS entries\n", filename); return -1; } diff --git a/src/audio/web/web_audio_system.c b/src/audio/web/web_audio_system.c index 479913222..25f92b5f6 100644 --- a/src/audio/web/web_audio_system.c +++ b/src/audio/web/web_audio_system.c @@ -79,7 +79,7 @@ static void webInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem ma_result result = ma_engine_init(&config, &ma->engine); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to initialize miniaudio engine in noDevice mode (error %d)\n", result); + Log_logError("Audio: Failed to initialize miniaudio engine in noDevice mode (error %d)\n", result); ma->engineReady = false; return; } @@ -88,7 +88,7 @@ static void webInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem memset(ma->instances, 0, sizeof(ma->instances)); ma->nextInstanceCounter = 0; - fprintf(stderr, "Audio: web miniaudio engine initialized (noDevice, %d Hz, 2 ch)\n", ma->sampleRate); + Log_log("Audio: web miniaudio engine initialized (noDevice, %d Hz, 2 ch)\n", ma->sampleRate); } static void webDestroy(AudioSystem* audio) { @@ -166,14 +166,14 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio if (isStream) { int32_t streamSlot = soundIndex - WEB_AUDIO_STREAM_INDEX_BASE; if (0 > streamSlot || streamSlot >= WEB_MAX_AUDIO_STREAMS || !ma->streams[streamSlot].active) { - fprintf(stderr, "Audio: Invalid stream index %d\n", soundIndex); + Log_logWarning("Audio: Invalid stream index %d\n", soundIndex); return -1; } streamPath = ma->streams[streamSlot].filePath; } else { DataWin* dw = ma->base.audioGroups[0]; if (0 > soundIndex || (uint32_t) soundIndex >= dw->sond.count) { - fprintf(stderr, "Audio: Invalid sound index %d\n", soundIndex); + Log_logWarning("Audio: Invalid sound index %d\n", soundIndex); return -1; } sound = &dw->sond.sounds[soundIndex]; @@ -181,7 +181,7 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio WebSoundInstance* slot = findFreeSlot(ma); if (slot == nullptr) { - fprintf(stderr, "Audio: No free sound slots for sound %d\n", soundIndex); + Log_logWarning("Audio: No free sound slots for sound %d\n", soundIndex); return -1; } @@ -191,7 +191,7 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio if (isStream) { result = ma_sound_init_from_file(&ma->engine, streamPath, MA_SOUND_FLAG_ASYNC, nullptr, nullptr, &slot->maSound); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to load stream file '%s' (error %d)\n", streamPath, result); + Log_logWarning("Audio: Failed to load stream file '%s' (error %d)\n", streamPath, result); return -1; } slot->ownsDecoder = false; @@ -203,7 +203,7 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio if (inAudo) { if (0 > sound->audioFile || (uint32_t) sound->audioFile >= ma->base.audioGroups[sound->audioGroup]->audo.count) { - fprintf(stderr, "Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); + Log_logWarning("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); return -1; } @@ -212,27 +212,27 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio ma_decoder_config decoderConfig = ma_decoder_config_init_default(); result = ma_decoder_init_memory(entry->data, entry->dataSize, &decoderConfig, &slot->decoder); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to init decoder for '%s' (error %d)\n", sound->name, result); + Log_logWarning("Audio: Failed to init decoder for '%s' (error %d)\n", sound->name, result); return -1; } slot->ownsDecoder = true; result = ma_sound_init_from_data_source(&ma->engine, &slot->decoder, 0, nullptr, &slot->maSound); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to init sound from decoder for '%s' (error %d)\n", sound->name, result); + Log_logWarning("Audio: Failed to init sound from decoder for '%s' (error %d)\n", sound->name, result); ma_decoder_uninit(&slot->decoder); return -1; } } else { char* path = resolveExternalPath(ma, sound); if (path == nullptr) { - fprintf(stderr, "Audio: Could not resolve path for sound '%s'\n", sound->name); + Log_logWarning("Audio: Could not resolve path for sound '%s'\n", sound->name); return -1; } result = ma_sound_init_from_file(&ma->engine, path, MA_SOUND_FLAG_ASYNC, nullptr, nullptr, &slot->maSound); if (result != MA_SUCCESS) { - fprintf(stderr, "Audio: Failed to load file for '%s' at '%s' (error %d)\n", sound->name, path, result); + Log_logWarning("Audio: Failed to load file for '%s' at '%s' (error %d)\n", sound->name, path, result); free(path); return -1; } @@ -605,7 +605,7 @@ static void webGroupLoad(AudioSystem* audio, int32_t groupIndex) { // The original runner does not care if the file doesn't exist (this may happen if someone uses "audio_group_load" on a non-existent group) FileSystem* fileSystem = ((WebAudioSystem*)audio)->fileSystem; if (!fileSystem->vtable->fileExists(fileSystem, buf)) { - fprintf(stderr, "Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the file system!\n", groupIndex, groupIndex); + Log_logWarning("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the file system!\n", groupIndex, groupIndex); free(buf); return; } @@ -634,13 +634,13 @@ static int32_t webCreateStream(AudioSystem* audio, const char* filename) { } if (0 > freeSlot) { - fprintf(stderr, "Audio: No free stream slots for '%s'\n", filename); + Log_logWarning("Audio: No free stream slots for '%s'\n", filename); return -1; } char* resolved = ma->fileSystem->vtable->resolvePath(ma->fileSystem, filename); if (resolved == nullptr) { - fprintf(stderr, "Audio: Could not resolve path for stream '%s'\n", filename); + Log_logWarning("Audio: Could not resolve path for stream '%s'\n", filename); return -1; } @@ -648,7 +648,7 @@ static int32_t webCreateStream(AudioSystem* audio, const char* filename) { ma->streams[freeSlot].filePath = resolved; int32_t streamIndex = WEB_AUDIO_STREAM_INDEX_BASE + freeSlot; - fprintf(stderr, "Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); + Log_logWarning("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); return streamIndex; } @@ -658,7 +658,7 @@ static bool webDestroyStream(AudioSystem* audio, int32_t streamIndex) { int32_t slotIndex = streamIndex - WEB_AUDIO_STREAM_INDEX_BASE; if (0 > slotIndex || slotIndex >= WEB_MAX_AUDIO_STREAMS) { - fprintf(stderr, "Audio: Invalid stream index %d for destroy\n", streamIndex); + Log_logWarning("Audio: Invalid stream index %d for destroy\n", streamIndex); return false; } diff --git a/src/binary_reader.c b/src/binary_reader.c index 6490c0884..1f3e7891b 100644 --- a/src/binary_reader.c +++ b/src/binary_reader.c @@ -30,7 +30,7 @@ static void readCheck(BinaryReader* reader, void* dest, size_t bytes) { if (reader->buffer != nullptr) { if (reader->bufferPos + bytes > reader->bufferSize) { size_t absPos = reader->bufferBase + reader->bufferPos; - fprintf(stderr, "BinaryReader: buffer read error at position 0x%zX (requested %zu bytes, buffer has %zu remaining)\n", absPos, bytes, reader->bufferSize - reader->bufferPos); + Log_logError("BinaryReader: buffer read error at position 0x%zX (requested %zu bytes, buffer has %zu remaining)\n", absPos, bytes, reader->bufferSize - reader->bufferPos); abort(); } memcpy(dest, reader->buffer + reader->bufferPos, bytes); @@ -41,7 +41,7 @@ static void readCheck(BinaryReader* reader, void* dest, size_t bytes) { size_t read = fread(dest, 1, bytes, reader->file); if (read != bytes) { long pos = ftell(reader->file) - (long) read; - fprintf(stderr, "BinaryReader: read error at position 0x%lX (requested %zu bytes, got %zu, file size 0x%zX)\n", pos, bytes, read, reader->fileSize); + Log_logError("BinaryReader: read error at position 0x%lX (requested %zu bytes, got %zu, file size 0x%zX)\n", pos, bytes, read, reader->fileSize); abort(); } } @@ -110,7 +110,7 @@ uint8_t* BinaryReader_readBytesAt(BinaryReader* reader, size_t offset, size_t co if (reader->buffer != nullptr) { if (offset < reader->bufferBase || offset + count > reader->bufferBase + reader->bufferSize) { - fprintf(stderr, "BinaryReader: readBytesAt offset 0x%zX+%zu out of buffer range [0x%zX, 0x%zX)\n", offset, count, reader->bufferBase, reader->bufferBase + reader->bufferSize); + Log_logError("BinaryReader: readBytesAt offset 0x%zX+%zu out of buffer range [0x%zX, 0x%zX)\n", offset, count, reader->bufferBase, reader->bufferBase + reader->bufferSize); abort(); } size_t savedPos = reader->bufferPos; @@ -137,7 +137,7 @@ void BinaryReader_skip(BinaryReader* reader, size_t bytes) { void BinaryReader_seek(BinaryReader* reader, size_t position) { if (reader->buffer != nullptr) { if (position < reader->bufferBase || position > reader->bufferBase + reader->bufferSize) { - fprintf(stderr, "BinaryReader: buffer seek to 0x%zX out of buffer range [0x%zX, 0x%zX]\n", position, reader->bufferBase, reader->bufferBase + reader->bufferSize); + Log_logError("BinaryReader: buffer seek to 0x%zX out of buffer range [0x%zX, 0x%zX]\n", position, reader->bufferBase, reader->bufferBase + reader->bufferSize); abort(); } reader->bufferPos = position - reader->bufferBase; @@ -145,7 +145,7 @@ void BinaryReader_seek(BinaryReader* reader, size_t position) { } if (position > reader->fileSize) { - fprintf(stderr, "BinaryReader: seek to 0x%zX out of bounds (file size 0x%zX)\n", position, reader->fileSize); + Log_logError("BinaryReader: seek to 0x%zX out of bounds (file size 0x%zX)\n", position, reader->fileSize); abort(); } fseek(reader->file, (long) position, SEEK_SET); diff --git a/src/data_win.c b/src/data_win.c index 23e9e4839..53014f941 100644 --- a/src/data_win.c +++ b/src/data_win.c @@ -822,7 +822,7 @@ static void parseSPRT(BinaryReader* reader, DataWin* dw, bool skipLoadingPrecise check = 0; } } else { - fprintf(stderr, "DataWin: Detected special sprite type %u (%s), but we don't support it yet!\n", spr->sSpriteType, spr->sSpriteType == 2 ? "Spine" : spr->sSpriteType == 1 ? "SWF" : "Unknown"); + Log_logWarning("DataWin: Detected special sprite type %u (%s), but we don't support it yet!\n", spr->sSpriteType, spr->sSpriteType == 2 ? "Spine" : spr->sSpriteType == 1 ? "SWF" : "Unknown"); spr->textureCount = 0; spr->tpagIndices = nullptr; spr->maskCount = 0; @@ -1077,7 +1077,7 @@ static void parseACRV(BinaryReader* reader, DataWin* dw) { uint32_t version = BinaryReader_readUint32(reader); if (version != 1) { - fprintf(stderr, "ACRV: unexpected version %u (expected 1)\n", version); + Log_logError("ACRV: unexpected version %u (expected 1)\n", version); return; } @@ -1858,7 +1858,7 @@ static void readRoomLayers(BinaryReader* reader, DataWin* dw, Room* room, uint32 break; } default: { - fprintf(stderr, "Unsupported Room Layer Type %u\n", layer->type); + Log_logError("Unsupported Room Layer Type %u\n", layer->type); exit(0); } } @@ -2114,7 +2114,7 @@ static void parseROOM(BinaryReader* reader, DataWin* dw, bool lazyLoadRooms, Str static int32_t parseTexturePageItem(BinaryReader* reader, DataWin* dw, int32_t i) { int32_t position = i; if (i == -1) { - fprintf(stderr, "DataWin: Allocated new TPAG! Was the WAD built with WinPack? (TranslaTale)\n"); + Log_logWarning("DataWin: Allocated new TPAG! Was the WAD built with WinPack? (TranslaTale)\n"); uint32_t newCount = dw->tpag.count + 1; TexturePageItem* newItems = (TexturePageItem *)safeCalloc(newCount, sizeof(TexturePageItem)); memcpy(newItems, dw->tpag.items, dw->tpag.count * sizeof(TexturePageItem)); @@ -2552,7 +2552,7 @@ void DataWin_loadTxtrIfNeeded(DataWin* dw, uint32_t textureId) { if (tex->blobData != nullptr) return; if (!dw->lazyLoadFile) { - fprintf(stderr, "loadTxtrIfNeeded: called without a lazy load file.\n"); + Log_logError("loadTxtrIfNeeded: called without a lazy load file.\n"); return; } @@ -2565,7 +2565,7 @@ void DataWin_loadTxtrIfNeeded(DataWin* dw, uint32_t textureId) { fseek(dw->lazyLoadFile, old_seek, SEEK_SET); if (read != tex->blobSize) { - fprintf(stderr, "loadTxtrIfNeeded: couldn't read %u bytes to load a texture.\n", tex->blobSize); + Log_logError("loadTxtrIfNeeded: couldn't read %u bytes to load a texture.\n", tex->blobSize); } } @@ -2603,7 +2603,7 @@ static void parseAUDO(BinaryReader* reader, DataWin* dw) { DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { FILE* file = fopen(filePath, "rb"); if (!file) { - fprintf(stderr, "Failed to open file: %s\n", filePath); + Log_logError("Failed to open file: %s\n", filePath); exit(1); } @@ -2617,7 +2617,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { fseek(file, 0, SEEK_SET); if (0 >= fileSizeRaw) { - fprintf(stderr, "Invalid file size: %ld\n", fileSizeRaw); + Log_logError("Invalid file size: %ld\n", fileSizeRaw); fclose(file); exit(1); } @@ -2639,7 +2639,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { } else if (options.loadType == DATAWINLOADTYPE_MAP_FILE) { wholeFileData = mapFile(file, fileSize); if (!wholeFileData) { - fprintf(stderr, "Failed to map file\n"); + Log_logError("Failed to map file\n"); fclose(file); exit(1); } @@ -2653,7 +2653,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { // Some games may purposely corrupt the magic value so that UndertaleModTool doesn't open it // The native runner does not care about verifying the magic value, so we'll validate it and warn, but we won't exit if (memcmp(formMagic, "FORM", 4) != 0) { - fprintf(stderr, "The file does not have the expected FORM magic, got '%.4s'. The file may not be a WAD or it may have been tampered with!\n", formMagic); + Log_logWarning("The file does not have the expected FORM magic, got '%.4s'. The file may not be a WAD or it may have been tampered with!\n", formMagic); } uint32_t formLength = BinaryReader_readUint32(&reader); @@ -2700,7 +2700,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { } if (chunkDataStart + chunkLength > fileSize) { - fprintf(stderr, "Chunk data extends beyond file size: chunkDataStart=%zu, chunkLength=%u, fileSize=%zu! Are you running a GameMaker Raspberry Pi game? Skipping bytes out of bounds...\n", chunkDataStart, chunkLength, fileSize); + Log_logWarning("Chunk data extends beyond file size: chunkDataStart=%zu, chunkLength=%u, fileSize=%zu! Are you running a GameMaker Raspberry Pi game? Skipping bytes out of bounds...\n", chunkDataStart, chunkLength, fileSize); break; } @@ -2709,7 +2709,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { } if (!codeExists && options.parseCode) { - fprintf(stderr, "CODE chunk does not exist or is empty! This usually means you're loading a YYC game.\n"); + Log_logError("CODE chunk does not exist or is empty! This usually means you're loading a YYC game.\n"); fclose(file); exit(1); } @@ -2767,7 +2767,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { if (chunkBuffer) { size_t read = fread(chunkBuffer, 1, chunkLength, reader.file); if (read != chunkLength) { - fprintf(stderr, "DataWin: short read on chunk %.4s (expected %u, got %zu)\n", chunkName, chunkLength, read); + Log_logError("DataWin: short read on chunk %.4s (expected %u, got %zu)\n", chunkName, chunkLength, read); exit(1); } BinaryReader_setBuffer(&reader, chunkBuffer, chunkDataStart, chunkLength); diff --git a/src/desktop/backends/glfw2.c b/src/desktop/backends/glfw2.c index b97b41764..b5106afba 100644 --- a/src/desktop/backends/glfw2.c +++ b/src/desktop/backends/glfw2.c @@ -29,7 +29,7 @@ static bool tryOpenWindow(int reqW, int reqH) { for (size_t i = 0; i < sizeof(GLCommon_versions)/sizeof(GLCommon_versions[0]); i++) { glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, GLCommon_versions[i].major); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, GLCommon_versions[i].minor); - + if (GLCommon_versions[i].major >= 3) { glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); if (GLCommon_versions[i].major == 3 && GLCommon_versions[i].minor == 2) { @@ -186,18 +186,18 @@ static void GLFWCALL scrollCallback(int pos) { bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) { if (headless) { - fprintf(stderr, "Headless mode is not supported with GLFW 2\n"); + Log_logError("Headless mode is not supported with GLFW 2\n"); return false; } // Init GLFW if (!glfwInit()) { - fprintf(stderr, "Failed to initialize GLFW\n"); + Log_logError("Failed to initialize GLFW\n"); return false; } if (!tryOpenWindow(reqW, reqH)) { - fprintf(stderr, "Failed to create GLFW window\n"); + Log_logError("Failed to create GLFW window\n"); glfwTerminate(); return false; } diff --git a/src/desktop/backends/glfw3.c b/src/desktop/backends/glfw3.c index 28cba4c2b..037a8a7c3 100644 --- a/src/desktop/backends/glfw3.c +++ b/src/desktop/backends/glfw3.c @@ -33,11 +33,11 @@ static GLFWwindow *tryOpenWindow(int reqW, int reqH, const char* title) { glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, (gfx == SOFTWARE) ? 0 : 1); - + #ifndef NDEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif - + return glfwCreateWindow(reqW, reqH, title, NULL, NULL); } @@ -127,7 +127,7 @@ static bool platformGetWindowFocus(void) { } static void glfwErrorCallback(int code, const char* description) { - fprintf(stderr, "GLFW error 0x%x: %s\n", code, description); + Log_logError("GLFW error 0x%x: %s\n", code, description); } static int32_t glfwKeyToGml(int glfwKey) { @@ -224,7 +224,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) // Init GLFW glfwSetErrorCallback(glfwErrorCallback); if (!glfwInit()) { - fprintf(stderr, "Failed to initialize GLFW\n"); + Log_logError("Failed to initialize GLFW\n"); return false; } @@ -241,23 +241,23 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) buffer[len] = '\0'; if (buffer[0] != '\0') { if (glfwUpdateGamepadMappings(buffer)) { - fprintf(stderr, "Gamepad: Loaded SDL gamecontroller mappings successfully\n"); + Log_logError("Gamepad: Loaded SDL gamecontroller mappings successfully\n"); } else { - fprintf(stderr, "Gamepad: Failed to load SDL gamecontroller mappings\n"); + Log_logWarning("Gamepad: Failed to load SDL gamecontroller mappings\n"); } } free(buffer); } fclose(f); } else - fprintf(stderr, "Gamepad: SDL gamecontrollerdb.txt not found at %s, using defaults\n", dbPath); + Log_logWarning("Gamepad: SDL gamecontrollerdb.txt not found at %s, using defaults\n", dbPath); if (headless) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); window = tryOpenWindow(reqW, reqH, title); if (!window) { - fprintf(stderr, "Failed to create GLFW window\n"); + Log_logError("Failed to create GLFW window\n"); glfwTerminate(); return false; } diff --git a/src/desktop/backends/sdl1.c b/src/desktop/backends/sdl1.c index ad9beba10..80ebd9139 100644 --- a/src/desktop/backends/sdl1.c +++ b/src/desktop/backends/sdl1.c @@ -137,7 +137,7 @@ static void loadGamepadMappings(void) { const char* dbPath = "gamecontrollerdb.txt"; FILE* f = fopen(dbPath, "rb"); if (!f) { - fprintf(stderr, "Gamepad: SDL gamecontrollerdb.txt not found at %s, ignoring mappings\n", dbPath); + Log_logWarning("Gamepad: SDL gamecontrollerdb.txt not found at %s, ignoring mappings\n", dbPath); return; } @@ -194,7 +194,7 @@ static void loadGamepadMappings(void) { const char* jname = SDL_JoystickName(i); if (jname && strcasecmp(jname, name) == 0) { joystickMappings[i] = temp; - fprintf(stderr, "Gamepad: Mapped '%s' (slot %d)\n", jname, i); + Log_log("Gamepad: Mapped '%s' (slot %d)\n", jname, i); } } } @@ -240,13 +240,13 @@ static bool platformGetWindowFocus(void) { bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) { if (headless && gfx != SOFTWARE) { - fprintf(stderr, "Headless mode on SDL 1.2 requires the software renderer!\n"); + Log_logError("Headless mode on SDL 1.2 requires the software renderer!\n"); return false; } // Init SDL if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK)) { - fprintf(stderr, "Failed to initialize SDL\n"); + Log_logError("Failed to initialize SDL\n"); return false; } @@ -271,7 +271,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) if (!scr && gfx == SOFTWARE) { SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN); if (modes && modes != (SDL_Rect**) -1 && modes[0]) { - fprintf(stderr, "Warning: %dx%d unavailable, falling back to %dx%d: %s\n", + Log_logWarning("Warning: %dx%d unavailable, falling back to %dx%d: %s\n", reqW, reqH, modes[0]->w, modes[0]->h, SDL_GetError()); scr = SDL_SetVideoMode(modes[0]->w, modes[0]->h, 0, 0); fbWidth = modes[0]->w; @@ -279,7 +279,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) } } if (!scr) { - fprintf(stderr, "Fatal: Could not set any video mode: %s\n", SDL_GetError()); + Log_logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); return false; } } @@ -416,11 +416,11 @@ static void platformResetJoysticks(void) { openJoysticks[i] = NULL; } } - + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); SDL_InitSubSystem(SDL_INIT_JOYSTICK); SDL_JoystickEventState(SDL_IGNORE); - + int numJoysticks = SDL_NumJoysticks(); bool needsRemap = false; for (int i = 0; i < numJoysticks && i < MAX_GAMEPADS; i++) { @@ -432,11 +432,11 @@ static void platformResetJoysticks(void) { needsRemap = true; } } - + for (int i = numJoysticks; i < MAX_GAMEPADS; i++) { joystickMappings[i].valid = false; } - + if (needsRemap) { loadGamepadMappings(); } @@ -502,7 +502,7 @@ bool platformHandleEvents(void) { float norm = val / 32767.0f; if (map->axis_button_sign[btn] < 0) norm = -norm; if (norm < 0.0f) norm = 0.0f; - + if (norm > slot->buttonValue[btn]) { slot->buttonValue[btn] = norm; } diff --git a/src/desktop/backends/sdl2.c b/src/desktop/backends/sdl2.c index c677ffd8d..10b747449 100644 --- a/src/desktop/backends/sdl2.c +++ b/src/desktop/backends/sdl2.c @@ -28,7 +28,7 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0); - + SDL_Window *newWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, @@ -45,7 +45,7 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f } return NULL; } - for (size_t i = 0; i < sizeof(GLCommon_versions)/sizeof(GLCommon_versions[0]); i++) { + for (size_t i = 0; i < sizeof(GLCommon_versions)/sizeof(GLCommon_versions[0]); i++) { SDL_Window *newWindow; int contextFlags = 0; @@ -60,16 +60,16 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f if (GLCommon_versions[i].gles) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - } else { + } else { if (GLCommon_versions[i].major >= 3) { if (GLCommon_versions[i].major == 3 && GLCommon_versions[i].minor == 2) { contextFlags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG; } } else { - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0); } } - + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextFlags); newWindow = SDL_CreateWindow( @@ -86,7 +86,7 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f } SDL_DestroyWindow(newWindow); } - + } return NULL; } @@ -167,14 +167,14 @@ static bool platformGetWindowFocus(void) { bool platformInit(int reqW, int reqH, const char *title, bool headless) { // Init SDL if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_GAMECONTROLLER)) { - fprintf(stderr, "Failed to initialize SDL\n"); + Log_logError("Failed to initialize SDL\n"); return false; } for (int i = 0; i < MAX_GAMEPADS; i++) { openControllers[i] = NULL; } - + Uint32 flags; if (headless) flags = (gfx == SOFTWARE ? 0 : SDL_WINDOW_OPENGL) | SDL_WINDOW_HIDDEN; @@ -183,18 +183,18 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { #if SDL_VERSION_ATLEAST(2, 0, 1) flags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif - + window = tryOpenWindow(reqW, reqH, title, flags); - + if (!window && gfx != SOFTWARE) { - fprintf(stderr, "Fatal: Could not open window: %s\n", SDL_GetError()); + Log_logError("Fatal: Could not open window: %s\n", SDL_GetError()); return false; } - + if (!window && gfx == SOFTWARE) { SDL_DisplayMode mode; if (SDL_GetDisplayMode(0, 0, &mode) == 0) { - fprintf(stderr, "Warning: %dx%d unavailable, falling back to %dx%d: %s\n", + Log_logWarning("Warning: %dx%d unavailable, falling back to %dx%d: %s\n", reqW, reqH, mode.w, mode.h, SDL_GetError()); reqW = mode.w; reqH = mode.h; @@ -208,7 +208,7 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { } } if (!window) { - fprintf(stderr, "Fatal: Could not set any video mode: %s\n", SDL_GetError()); + Log_logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); return false; } if (gfx != SOFTWARE) { @@ -222,9 +222,9 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { // init gamepad mappings const char* dbPath = "gamecontrollerdb.txt"; if (SDL_GameControllerAddMappingsFromFile(dbPath) >= 0) { - fprintf(stderr, "Gamepad: Loaded SDL gamecontroller mappings successfully\n"); + Log_log("Gamepad: Loaded SDL gamecontroller mappings successfully\n"); } else { - fprintf(stderr, "Gamepad: SDL gamecontrollerdb.txt not found at %s or failed to load, using defaults\n", dbPath); + Log_logWarning("Gamepad: SDL gamecontrollerdb.txt not found at %s or failed to load, using defaults\n", dbPath); } return true; diff --git a/src/desktop/backends/sdl3.c b/src/desktop/backends/sdl3.c index 7cf229eb8..a45fa528e 100644 --- a/src/desktop/backends/sdl3.c +++ b/src/desktop/backends/sdl3.c @@ -48,7 +48,7 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0); - + SDL_Window *newWindow = SDL_CreateWindow( title, reqW, @@ -78,16 +78,16 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f if (GLCommon_versions[i].gles) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - } else { + } else { if (GLCommon_versions[i].major >= 3) { if (GLCommon_versions[i].major == 3 && GLCommon_versions[i].minor == 2) { contextFlags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG; } } else { - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0); } } - + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextFlags); newWindow = SDL_CreateWindow( @@ -103,7 +103,7 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f } SDL_DestroyWindow(newWindow); } - + } return NULL; } @@ -149,7 +149,7 @@ static bool platformGetWindowFocus(void) { bool platformInit(int reqW, int reqH, const char *title, bool headless) { // Init SDL if (!SDL_Init(SDL_INIT_VIDEO|SDL_INIT_GAMEPAD)) { - fprintf(stderr, "Failed to initialize SDL\n"); + Log_logError("Failed to initialize SDL\n"); return false; } @@ -162,27 +162,27 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { fbHeight = reqH; window = tryOpenWindow(fbWidth, fbHeight, title, flags); - + if (!window && gfx != SOFTWARE) { - fprintf(stderr, "Fatal: Could not open window: %s\n", SDL_GetError()); + Log_logError("Fatal: Could not open window: %s\n", SDL_GetError()); return false; } - + if (!window && gfx == SOFTWARE) { const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay()); if (mode != NULL) { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: %dx%d unavailable, falling back to %dx%d: %s", fbWidth, fbHeight, mode->w, mode->h, SDL_GetError()); - + fbWidth = mode->w; fbHeight = mode->h; - + window = SDL_CreateWindow(title, fbWidth, fbHeight, flags); } } if (!window) { - fprintf(stderr, "Fatal: Could not set any video mode: %s\n", SDL_GetError()); + Log_logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); return false; } if (gfx != SOFTWARE) { diff --git a/src/desktop/main.c b/src/desktop/main.c index 3a7667098..8c6175607 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -114,7 +114,7 @@ static bool platformInitGlad(void) { if (!glGetString) return 0; - fprintf(stderr, "OpenGL Version: %s\n", (const char*)glGetString(GL_VERSION)); + Log_log("OpenGL Version: %s\n", (const char*)glGetString(GL_VERSION)); GLVer ver = GLCommon_getGLVersion(); if (ver.isGLES) { @@ -164,7 +164,7 @@ static void APIENTRY glDebugCallback(GLenum source, GLenum type, GLuint id, GLen default: severityStr = "Unknown"; break; } - fprintf(stderr, "[OpenGL %s] id=%u Type: %s; Severity: %s; Message: %.*s\n", sourceStr, id, typeStr, severityStr, (int) length, message); + Log_log("[OpenGL %s] id=%u Type: %s; Severity: %s; Message: %.*s\n", sourceStr, id, typeStr, severityStr, (int) length, message); } static void installGLDebugCallback(void) { @@ -532,7 +532,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - fprintf(stderr, "Error: Invalid frame number '%s'\n", optarg); + Log_logError("Error: Invalid frame number '%s'\n", optarg); exit(1); } @@ -546,7 +546,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - fprintf(stderr, "Error: Invalid frame number '%s' for --screenshot-surfaces-at-frame\n", optarg); + Log_logError("Error: Invalid frame number '%s' for --screenshot-surfaces-at-frame\n", optarg); exit(1); } hmput(args->screenshotSurfacesFrames, frame, true); @@ -614,7 +614,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - fprintf(stderr, "Error: Invalid frame number '%s' for --exit-at-frame\n", optarg); + Log_logError("Error: Invalid frame number '%s' for --exit-at-frame\n", optarg); exit(1); } args->exitAtFrame = frame; @@ -624,7 +624,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - fprintf(stderr, "Error: Invalid frame number '%s' for --trace-bytecode-after-frame\n", optarg); + Log_logError("Error: Invalid frame number '%s' for --trace-bytecode-after-frame\n", optarg); exit(1); } args->traceBytecodeAfterFrame = frame; @@ -634,7 +634,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - fprintf(stderr, "Error: Invalid frame number '%s' for --dump-frame\n", optarg); + Log_logError("Error: Invalid frame number '%s' for --dump-frame\n", optarg); exit(1); } hmput(args->dumpFrames, frame, true); @@ -644,7 +644,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - fprintf(stderr, "Error: Invalid frame number '%s' for --dump-frame-json\n", optarg); + Log_logError("Error: Invalid frame number '%s' for --dump-frame-json\n", optarg); exit(1); } hmput(args->dumpJsonFrames, frame, true); @@ -657,7 +657,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; double speed = strtod(optarg, &endPtr); if (*endPtr != '\0' || speed <= 0.0) { - fprintf(stderr, "Error: Invalid speed multiplier '%s' for --speed (must be > 0)\n", optarg); + Log_logError("Error: Invalid speed multiplier '%s' for --speed (must be > 0)\n", optarg); exit(1); } args->speedMultiplier = speed; @@ -667,7 +667,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; double speed = strtod(optarg, &endPtr); if (*endPtr != '\0' || speed <= 0.0) { - fprintf(stderr, "Error: Invalid speed '%s' for --fast-forward-speed (must be > 0)\n", optarg); + Log_logError("Error: Invalid speed '%s' for --fast-forward-speed (must be > 0)\n", optarg); exit(1); } args->fastForwardSpeed = speed; @@ -698,7 +698,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int seedVal = strtol(optarg, &endPtr, 10); if (*endPtr != '\0') { - fprintf(stderr, "Error: Invalid seed value '%s' for --seed\n", optarg); + Log_logError("Error: Invalid seed value '%s' for --seed\n", optarg); exit(1); } args->seed = seedVal; @@ -715,7 +715,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int framesBetween = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || framesBetween <= 0) { - fprintf(stderr, "Error: Invalid frame count '%s' for --profile-gml-scripts (must be > 0)\n", optarg); + Log_logError("Error: Invalid frame count '%s' for --profile-gml-scripts (must be > 0)\n", optarg); exit(1); } args->profilerFramesBetween = framesBetween; @@ -739,16 +739,16 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) #endif case 'O': if (!parseOsTypeArg(optarg, &args->osType)) { - fprintf(stderr, "Error: Invalid --os-type value '%s' (expected: ", optarg); + Log_logError("Error: Invalid --os-type value '%s' (expected: ", optarg); printOsTypeNames(stderr); - fprintf(stderr, ")\n"); + Log_logError(")\n"); exit(1); } break; case 'w': { int32_t w = 0, h = 0; if (sscanf(optarg, "%dx%d", &w, &h) != 2 || 0 >= w || 0 >= h) { - fprintf(stderr, "Error: Invalid --window-size value '%s' (expected WxH, e.g. 960x544)\n", optarg); + Log_logError("Error: Invalid --window-size value '%s' (expected WxH, e.g. 960x544)\n", optarg); exit(1); } args->windowWidth = w; @@ -763,7 +763,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } else if (strcmp(optarg, "load-per-chunk") == 0) { args->loadType = DATAWINLOADTYPE_LOAD_PER_CHUNK; } else { - fprintf(stderr, "Error: Unknown load type '%s'\n", optarg); + Log_logError("Error: Unknown load type '%s'\n", optarg); exit(1); } break; @@ -781,7 +781,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } else if ((ratio = strtod(optarg, &endPtr)), *endPtr == '\0' && ratio > 0.0) { args->widescreenAspect = (float) ratio; } else { - fprintf(stderr, "Error: Invalid --widescreen-hack value '%s' (expected W:H like 16:9, or a decimal like 1.7778)\n", optarg); + Log_logError("Error: Invalid --widescreen-hack value '%s' (expected W:H like 16:9, or a decimal like 1.7778)\n", optarg); exit(1); } break; @@ -793,24 +793,24 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } if (optind >= argc) { - fprintf(stderr, "Usage: %s \n", argv[0]); + Log_logError("Usage: %s \n", argv[0]); exit(1); } args->dataWinPath = argv[optind]; if (hmlen(args->screenshotFrames) > 0 && args->screenshotPattern == nullptr) { - fprintf(stderr, "Error: --screenshot-at-frame requires --screenshot to be set\n"); + Log_logError("Error: --screenshot-at-frame requires --screenshot to be set\n"); exit(1); } if (hmlen(args->screenshotSurfacesFrames) > 0 && args->screenshotSurfacesPattern == nullptr) { - fprintf(stderr, "Error: --screenshot-surfaces-at-frame requires --screenshot-surfaces to be set\n"); + Log_logError("Error: --screenshot-surfaces-at-frame requires --screenshot-surfaces to be set\n"); exit(1); } if (args->headless && args->speedMultiplier != 1.0) { - fprintf(stderr, "You can't set the speed multiplier while running in headless mode! Headless mode always run in real time\n"); + Log_logError("You can't set the speed multiplier while running in headless mode! Headless mode always run in real time\n"); exit(1); } } @@ -846,7 +846,7 @@ static void writeFramebufferAsPng(GLuint fbo, int width, int height, const char* int stride = width * 4; unsigned char* pixels = (unsigned char *)safeMalloc(stride * height); if (pixels == nullptr) { - fprintf(stderr, "Error: Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height); + Log_logWarning("Error: Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height); return; } @@ -866,7 +866,7 @@ static void writeFramebufferAsPng(GLuint fbo, int width, int height, const char* } free(pixels); - fprintf(stderr, "%s: %s (%dx%d)\n", logPrefix, filename, width, height); + Log_log("%s: %s (%dx%d)\n", logPrefix, filename, width, height); } static void captureScreenshot(GLuint fbo, const char* filenamePattern, int frameNumber, int width, int height, bool flipY) { @@ -1026,7 +1026,7 @@ int main(int argc, char* argv[]) { int32_t inputFrameCount = 0; while (true) { - fprintf(stderr, "Loading %s...\n", args.dataWinPath); + Log_log("Loading %s...\n", args.dataWinPath); DataWinParserOptions options = {0}; options.parseGen8 = true; @@ -1063,12 +1063,12 @@ int main(int argc, char* argv[]) { DataWin* dataWin = DataWin_parse(currentDataWinPath, options); Gen8* gen8 = &dataWin->gen8; - fprintf(stderr, "Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); + Log_log("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); #ifdef HAVE_MALLINFO2 { struct mallinfo2 mi = mallinfo2(); - fprintf(stderr, "Memory after data.win parsing: used=%zu bytes (%.1f KB)\n", mi.uordblks, mi.uordblks / 1024.0f); + Log_log("Memory after data.win parsing: used=%zu bytes (%.1f KB)\n", mi.uordblks, mi.uordblks / 1024.0f); } #endif @@ -1091,7 +1091,7 @@ int main(int argc, char* argv[]) { if (args.hasSeed) { srand((unsigned int) args.seed); vm->hasFixedSeed = true; - fprintf(stderr, "Using fixed RNG seed: %d\n", args.seed); + Log_log("Using fixed RNG seed: %d\n", args.seed); } if (args.printRooms) { @@ -1219,7 +1219,7 @@ int main(int argc, char* argv[]) { if (args.printUnknownFunctions) { uint32_t unimplementedCount = 0; - fprintf(stderr, "Unknown Functions:\n"); + Log_log("Unknown Functions:\n"); repeat(dataWin->func.functionCount, i) { const char* name = dataWin->func.functions[i].name; if (name == nullptr) @@ -1233,14 +1233,14 @@ int main(int argc, char* argv[]) { if (VM_findBuiltin(vm, name) != nullptr) continue; - fprintf(stderr, "- %s\n", name); + Log_logError("- %s\n", name); unimplementedCount++; } if (unimplementedCount == 0) { - fprintf(stderr, "All %u referenced functions are implemented! :3\n", dataWin->func.functionCount); + Log_log("All %u referenced functions are implemented! :3\n", dataWin->func.functionCount); } else { - fprintf(stderr, "%u unknown function(s) out of %u referenced\n", unimplementedCount, dataWin->func.functionCount); + Log_log("%u unknown function(s) out of %u referenced\n", unimplementedCount, dataWin->func.functionCount); } VM_free(vm); DataWin_free(dataWin); @@ -1260,7 +1260,7 @@ int main(int argc, char* argv[]) { if (idx >= 0) { VM_disassemble(vm, vm->codeIndexByName[idx].value); } else { - fprintf(stderr, "Error: Script '%s' not found in funcMap\n", name); + Log_logWarning("Error: Script '%s' not found in funcMap\n", name); } } } @@ -1297,31 +1297,31 @@ int main(int argc, char* argv[]) { else if (strcmp(args.renderer, "software") == 0) gfx = SOFTWARE; else { - fprintf(stderr, "Unknown renderer: %s!\n", args.renderer); + Log_logError("Unknown renderer: %s!\n", args.renderer); return 1; } #ifndef ENABLE_LEGACY_GL if (gfx == LEGACY_GL) { - fprintf(stderr, "The legacy gl renderer is not available in this build!\n"); + Log_logError("The legacy gl renderer is not available in this build!\n"); return 0; } #endif #ifndef ENABLE_MODERN_GL if (gfx == MODERN_GL) { - fprintf(stderr, "The modern gl renderer is not available in this build!\n"); + Log_logError("The modern gl renderer is not available in this build!\n"); return 0; } #endif #ifndef ENABLE_SW_RENDERER if (gfx == SOFTWARE) { - fprintf(stderr, "The software renderer is not available in this build!\n"); + Log_logError("The software renderer is not available in this build!\n"); return 0; } #endif if (gfx != MODERN_GL && hmlen(args.screenshotSurfacesFrames)) { - fprintf(stderr, "You can only use --screenshot-surfaces with the modern gl renderer!\n"); + Log_logError("You can only use --screenshot-surfaces with the modern gl renderer!\n"); return 0; } @@ -1343,7 +1343,7 @@ int main(int argc, char* argv[]) { if (gfx == LEGACY_GL || gfx == MODERN_GL) { #endif if (!platformInitGlad()) { - fprintf(stderr, "Failed to initialize GLAD\n"); + Log_logError("Failed to initialize GLAD\n"); platformExit(); DataWin_free(dataWin); freeCommandLineArgs(&args); @@ -1385,7 +1385,7 @@ int main(int argc, char* argv[]) { } #endif if (!renderer) { - fprintf(stderr, "Failed to initialize a renderer\n"); + Log_logError("Failed to initialize a renderer\n"); platformExit(); DataWin_free(dataWin); freeCommandLineArgs(&args); @@ -1512,7 +1512,7 @@ int main(int argc, char* argv[]) { // Pause if (RunnerKeyboard_checkPressed(runner->keyboard, 'P')) { debugPaused = !debugPaused; - fprintf(stderr, "Debug: %s\n", debugPaused ? "Paused" : "Resumed"); + Log_log("Debug: %s\n", debugPaused ? "Paused" : "Resumed"); } } @@ -1520,7 +1520,7 @@ int main(int argc, char* argv[]) { bool shouldStep = true; if (runner->debugMode && debugPaused) { shouldStep = RunnerKeyboard_checkPressed(runner->keyboard, 'O'); - if (shouldStep) fprintf(stderr, "Debug: Frame advance (frame %d)\n", runner->frameCount); + if (shouldStep) Log_log("Debug: Frame advance (frame %d)\n", runner->frameCount); } uint64_t frameStartTime = 0; @@ -1528,7 +1528,7 @@ int main(int argc, char* argv[]) { if (shouldStep) { if (args.traceFrames) { frameStartTime = nowNanos(); - fprintf(stderr, "Frame %d (Start)\n", runner->frameCount); + Log_log("Frame %d (Start)\n", runner->frameCount); } // Process input recording/playback (must happen after platformHandleEvents, before Runner_step) @@ -1541,7 +1541,7 @@ int main(int argc, char* argv[]) { int32_t nextIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition + 1]; runner->pendingRoom = nextIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - fprintf(stderr, "Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); + Log_log("Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); } } @@ -1552,18 +1552,18 @@ int main(int argc, char* argv[]) { int32_t prevIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition - 1]; runner->pendingRoom = prevIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - fprintf(stderr, "Debug: Going to previous room -> %s\n", dw->room.rooms[prevIdx].name); + Log_log("Debug: Going to previous room -> %s\n", dw->room.rooms[prevIdx].name); } } // Dump runner state to console if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F12)) { - fprintf(stderr, "Debug: Dumping runner state at frame %d\n", runner->frameCount); + Log_log("Debug: Dumping runner state at frame %d\n", runner->frameCount); Runner_dumpState(runner); } if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F11)) { - fprintf(stderr, "Debug: Dumping runner state at frame %d\n", runner->frameCount); + Log_log("Debug: Dumping runner state at frame %d\n", runner->frameCount); char* json = Runner_dumpStateJson(runner); if (args.dumpJsonFilePattern != nullptr) { @@ -1576,7 +1576,7 @@ int main(int argc, char* argv[]) { fclose(f); printf("JSON dump saved: %s\n", filename); } else { - fprintf(stderr, "Error: Could not write JSON dump to '%s'\n", filename); + Log_logWarning("Error: Could not write JSON dump to '%s'\n", filename); } } else { printf("%s\n", json); @@ -1588,7 +1588,7 @@ int main(int argc, char* argv[]) { // Toggle the collision mask debug overlay if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F2)) { debugShowCollisionMasks = !debugShowCollisionMasks; - fprintf(stderr, "Debug: Collision mask overlay %s!\n", debugShowCollisionMasks ? "enabled" : "disabled"); + Log_log("Debug: Collision mask overlay %s!\n", debugShowCollisionMasks ? "enabled" : "disabled"); } // Enable free cam @@ -1598,7 +1598,7 @@ int main(int argc, char* argv[]) { runner->freeCamZoom = 1.0f; freeCamActive = !freeCamActive; - fprintf(stderr, "Debug: Free cam %s!\n", freeCamActive ? "enabled" : "disabled"); + Log_log("Debug: Free cam %s!\n", freeCamActive ? "enabled" : "disabled"); } if (freeCamActive) { @@ -1654,7 +1654,7 @@ int main(int argc, char* argv[]) { if (args.profilerFramesBetween > 0 && runner->frameCount > 0 && runner->frameCount % args.profilerFramesBetween == 0) { char* profilerReport = Profiler_createReport(vm->profiler, 20, args.profilerFramesBetween); if (profilerReport != nullptr) { - fprintf(stderr, "%s\n", profilerReport); + Log_log("%s\n", profilerReport); free(profilerReport); } Profiler_reset(vm->profiler); @@ -1684,7 +1684,7 @@ int main(int argc, char* argv[]) { fclose(f); printf("JSON dump saved: %s\n", filename); } else { - fprintf(stderr, "Error: Could not write JSON dump to '%s'\n", filename); + Log_logWarning("Error: Could not write JSON dump to '%s'\n", filename); } } else { printf("%s\n", json); @@ -1791,7 +1791,7 @@ int main(int argc, char* argv[]) { if (shouldStep && args.traceFrames) { double frameElapsedMs = (nowNanos() - frameStartTime) / 1000000.0; - fprintf(stderr, "Frame %d (End, %.2f ms)\n", runner->frameCount, frameElapsedMs); + Log_log("Frame %d (End, %.2f ms)\n", runner->frameCount, frameElapsedMs); } // Only swap when there isn't a room change to match the original runner. @@ -1803,9 +1803,9 @@ int main(int argc, char* argv[]) { if (RunnerKeyboard_checkPressed(runner->keyboard, VK_BACKSPACE)) { size_t bytes_used = get_used_memory(); if (bytes_used == 0) - fprintf(stderr, "Unable to get memory usage\n"); + Log_logWarning("Unable to get memory usage\n"); else - fprintf(stderr, "Memory use right now: %zu bytes (%.1f MB)\n", bytes_used, bytes_used / 1024.0f / 1024.0f); + Log_log("Memory use right now: %zu bytes (%.1f MB)\n", bytes_used, bytes_used / 1024.0f / 1024.0f); } // Limit frame rate to room speed (skip in headless mode for max speed!!) @@ -1860,7 +1860,7 @@ int main(int argc, char* argv[]) { free(currentGameArgs[i]); } arrfree(currentGameArgs); - fprintf(stderr, "Bye! :3\n"); + Log_log("Bye! :3\n"); #ifdef _WIN32 timeEndPeriod(1); #endif @@ -1890,7 +1890,7 @@ int main(int argc, char* argv[]) { } if (dataWinFilename == nullptr) { - fprintf(stderr, "Runner: Launch parameters '%s' did not contain a '-game ' entry! Shutting down...\n", nextLaunchParameters); + Log_logError("Runner: Launch parameters '%s' did not contain a '-game ' entry! Shutting down...\n", nextLaunchParameters); free(nextWorkingDirectory); free(nextLaunchParameters); freeCommandLineArgs(&args); diff --git a/src/event_table.c b/src/event_table.c index 74bccab96..c83e90723 100644 --- a/src/event_table.c +++ b/src/event_table.c @@ -115,7 +115,7 @@ void ResolvedEventTable_build(ResolvedEventTable* outTable, DataWin* dw, const E int32_t slotCount = slotMap->slotCount; if (objectCount > MAX_EVENT_TABLE_OBJECT_COUNT) { - fprintf(stderr, "ResolvedEventTable: objectCount=%d exceeds max %d!\n", objectCount, MAX_EVENT_TABLE_OBJECT_COUNT); + Log_logError("ResolvedEventTable: objectCount=%d exceeds max %d!\n", objectCount, MAX_EVENT_TABLE_OBJECT_COUNT); abort(); } diff --git a/src/gl/gl_renderer.c b/src/gl/gl_renderer.c index 60a42ca9f..3925ff35d 100644 --- a/src/gl/gl_renderer.c +++ b/src/gl/gl_renderer.c @@ -86,7 +86,7 @@ static GLuint compileShader(GLenum type, const char* source, bool* ok) { if (!success) { char infoLog[512]; glGetShaderInfoLog(shader, sizeof(infoLog), nullptr, infoLog); - fprintf(stderr, "GL: Shader compilation failed: %s\n", infoLog); + Log_logError("GL: Shader compilation failed: %s\n", infoLog); *ok = false; return 0; } @@ -110,11 +110,11 @@ static GLuint linkProgram(const char* name, uint32_t vertexAttributeCount, const if (!success) { char infoLog[512]; glGetProgramInfoLog(program, sizeof(infoLog), nullptr, infoLog); - fprintf(stderr, "GL: Shader %s linking failed: %s\n", name, infoLog); + Log_logError("GL: Shader %s linking failed: %s\n", name, infoLog); *success2 = false; } else { *success2 = true; - fprintf(stderr, "GL: Shader %s succesfully linked!\n", name); + Log_log("GL: Shader %s succesfully linked!\n", name); } return program; } @@ -201,18 +201,18 @@ static void flushIfNeededAndSetActiveState(GLRenderer* gl, BatchType batchType, // ===[ Vtable Implementations ]=== static bool compileProgram(GMLShader* gmlShader, const char* name, const char* vertexShaderSource, const char* fragmentShaderSource, uint32_t vertexAttributeCount, const char** vertexAttributes) { - fprintf(stderr, "GL: Compiling %s vertex shader\n", name); + Log_log("GL: Compiling %s vertex shader\n", name); bool vertexShaderOK = false; bool fragmentShaderOK = false; GLuint vertShaderT = compileShader(GL_VERTEX_SHADER, vertexShaderSource, &vertexShaderOK); if (!vertexShaderOK) { - fprintf(stderr, "GL: Failed to compile %s vertex shader!\n", name); + Log_logError("GL: Failed to compile %s vertex shader!\n", name); return false; } - fprintf(stderr, "GL: Compiling %s fragment shader\n", name); + Log_log("GL: Compiling %s fragment shader\n", name); GLuint fragShaderT = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource, &fragmentShaderOK); if (!fragmentShaderOK) { - fprintf(stderr, "GL: Failed to compile %s fragment shader!\n", name); + Log_logError("GL: Failed to compile %s fragment shader!\n", name); return false; } @@ -269,14 +269,14 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { GMLShader* defaultShader = (GMLShader*)safeCalloc(1, sizeof(GMLShader)); GLVer ver = GLCommon_getGLVersion(); if (ver.major < 2) { - fprintf(stderr, "GL: The modern-gl renderer requires OpenGL 2.0 or newer\n"); + Log_logError("GL: The modern-gl renderer requires OpenGL 2.0 or newer\n"); abort(); } gl->isGL3 = (ver.major >= 3); gl->isGLES = ver.isGLES; if (!hasFBO()) { - fprintf(stderr, "GL: The modern-gl renderer requires FBO support\n"); + Log_logError("GL: The modern-gl renderer requires FBO support\n"); abort(); } @@ -336,14 +336,14 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { const char* defaultAttributes[] = { "aPos", "aColor", "aTexCoord" }; bool success = compileProgram(defaultShader, "default", vertSrc, fragSrc, 3, defaultAttributes); if (!success) { - fprintf(stderr, "GL: Failed to compile default shaders! Bailing...\n"); + Log_logError("GL: Failed to compile default shaders! Bailing...\n"); abort(); } gl->defaultShaderProgram = defaultShader; gl->gmlShaders = (GMLShader *)safeCalloc(dataWin->shdr.count, sizeof(GMLShader)); - fprintf(stderr, "GL: %u Shaders Found\n", dataWin->shdr.count); + Log_log("GL: %u Shaders Found\n", dataWin->shdr.count); repeat(dataWin->shdr.count, i) { Shader* shdr = &dataWin->shdr.shaders[i]; @@ -351,11 +351,11 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { if (!shdr->present) { gl->gmlShaderCount++; - fprintf(stderr, "GL: Skipping shader %d because it isn't present!\n", (int)i); + Log_logWarning("GL: Skipping shader %d because it isn't present!\n", (int)i); continue; } - fprintf(stderr, "GL: Compiling %s\n", shdr->name); + Log_log("GL: Compiling %s\n", shdr->name); const char* vertexShaderSource = gl->isGLES ? shdr->glslES_Vertex : shdr->glsl_Vertex; const char* fragmentShaderSource = gl->isGLES ? shdr->glslES_Fragment : shdr->glsl_Fragment; @@ -481,7 +481,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { gl->originalTpagCount = dataWin->tpag.count; gl->originalSpriteCount = dataWin->sprt.count; - fprintf(stderr, "GL: Renderer initialized (%u texture pages)\n", gl->textureCount); + Log_log("GL: Renderer initialized (%u texture pages)\n", gl->textureCount); } static void glGpuSetShader(Renderer* renderer, int32_t shaderIndex) { @@ -555,7 +555,7 @@ static void glShaderSettingsRefresh(Renderer* renderer) { // camera_apply: swap the active world->clip projection on the current target without touching its viewport. static void glApplyProjection(Renderer* renderer, const Matrix4f* viewMatrix,const Matrix4f* projectionMatrix) { GLRenderer* gl = (GLRenderer*) renderer; - + // Flush first so pending quads draw under the projection they were issued with. flushBatch(gl); @@ -568,13 +568,13 @@ static void glApplyProjection(Renderer* renderer, const Matrix4f* viewMatrix,con Matrix4f worldViewProjection; Matrix4f_multiply(&worldViewProjection, &projection, &worldView); - - renderer->gmlMatrices[MATRIX_VIEW] = view; + + renderer->gmlMatrices[MATRIX_VIEW] = view; renderer->gmlMatrices[MATRIX_PROJECTION] = projection; - renderer->gmlMatrices[MATRIX_WORLD_VIEW] = worldView; + renderer->gmlMatrices[MATRIX_WORLD_VIEW] = worldView; renderer->gmlMatrices[MATRIX_WORLD_VIEW_PROJECTION] = worldViewProjection; //oh my I hope it's good enough. - glShaderSettingsRefresh(renderer); + glShaderSettingsRefresh(renderer); } static void glGpuResetShader(Renderer* renderer) { @@ -866,7 +866,7 @@ bool GLRenderer_ensureTextureLoaded(GLRenderer* gl, uint32_t pageId) { bool gm2022_5 = DataWin_isVersionAtLeast(dw, 2022, 5, 0, 0); uint8_t* pixels = ImageDecoder_decodeToRgba(txtr->blobData, (size_t) txtr->blobSize, gm2022_5, &w, &h); if (pixels == nullptr) { - fprintf(stderr, "GL: Failed to decode TXTR page %u\n", pageId); + Log_logError("GL: Failed to decode TXTR page %u\n", pageId); return false; } if (!txtr->mapped) { @@ -890,7 +890,7 @@ bool GLRenderer_ensureTextureLoaded(GLRenderer* gl, uint32_t pageId) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode); - fprintf(stderr, "GL: Loaded TXTR page %u (%dx%d)\n", pageId, w, h); + Log_log("GL: Loaded TXTR page %u (%dx%d)\n", pageId, w, h); return true; } @@ -1577,11 +1577,11 @@ static void glDrawTriangle(Renderer *renderer, float x1, float y1, float x2, flo // This gets the vertex data for the new triangle batch Vertex* verts = gl->vertexData + gl->batchCount * VERTICES_PER_TRIANGLE; uint8_t ca = floatToUnormByte(alpha); - + verts[0].x = x1; verts[0].y = y1; verts[0].u = 0.0f; verts[0].v = 0.0f; verts[0].r = (uint8_t) BGR_R(color1); verts[0].g = (uint8_t) BGR_G(color1); verts[0].b = (uint8_t) BGR_B(color1); verts[0].a = ca; verts[1].x = x2; verts[1].y = y2; verts[1].u = 0.0f; verts[1].v = 0.0f; verts[1].r = (uint8_t) BGR_R(color2); verts[1].g = (uint8_t) BGR_G(color2); verts[1].b = (uint8_t) BGR_B(color2); verts[1].a = ca; verts[2].x = x3; verts[2].y = y3; verts[2].u = 0.0f; verts[2].v = 0.0f; verts[2].r = (uint8_t) BGR_R(color3); verts[2].g = (uint8_t) BGR_G(color3); verts[2].b = (uint8_t) BGR_B(color3); verts[2].a = ca; - + gl->batchCount++; } } @@ -1940,7 +1940,7 @@ static int32_t glCreateSurface(Renderer* renderer, int32_t width, int32_t height gl->surfaceWidth[surfaceIndex] = width; gl->surfaceHeight[surfaceIndex] = height; - fprintf(stderr, "GL: Created surface %u with size (%dx%d)\n", surfaceIndex, width, height); + Log_log("GL: Created surface %u with size (%dx%d)\n", surfaceIndex, width, height); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint) prevBinding); return (int32_t) surfaceIndex; @@ -1979,7 +1979,7 @@ static void glSurfaceFree(Renderer* renderer, int32_t surfaceID) { gl->surfaceTexture[surfaceID] = 0; gl->surfaceWidth[surfaceID] = 0; gl->surfaceHeight[surfaceID] = 0; - fprintf(stderr, "GL: Freed Surface %u\n", surfaceID); + Log_log("GL: Freed Surface %u\n", surfaceID); } static void glSurfaceResize(Renderer* renderer, int32_t surfaceID, int32_t width, int32_t height) { @@ -2009,7 +2009,7 @@ static void glSurfaceResize(Renderer* renderer, int32_t surfaceID, int32_t width gl->surfaceWidth[surfaceID] = width; gl->surfaceHeight[surfaceID] = height; - fprintf(stderr, "GL: Resized Surface %u Size (%dx%d)\n", surfaceID, width, height); + Log_logError("GL: Resized Surface %u Size (%dx%d)\n", surfaceID, width, height); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint) prevBinding); } @@ -2287,7 +2287,7 @@ static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID, sprite->maskCount = 0; sprite->masks = nullptr; - fprintf(stderr, "GL: Created dynamic sprite %u (%dx%d) from surface %d at (%d,%d)\n", spriteIndex, w, h, surfaceID, x, y); + Log_log("GL: Created dynamic sprite %u (%dx%d) from surface %d at (%d,%d)\n", spriteIndex, w, h, surfaceID, x, y); return (int32_t) spriteIndex; } @@ -2299,7 +2299,7 @@ static void glDeleteSprite(Renderer* renderer, int32_t spriteIndex) { // Refuse to delete original data.win sprites if (gl->originalSpriteCount > (uint32_t) spriteIndex) { - fprintf(stderr, "GL: Cannot delete data.win sprite %d\n", spriteIndex); + Log_logWarning("GL: Cannot delete data.win sprite %d\n", spriteIndex); return; } @@ -2328,15 +2328,15 @@ static void glDeleteSprite(Renderer* renderer, int32_t spriteIndex) { memset(sprite, 0, sizeof(Sprite)); sprite->name = keepName; - fprintf(stderr, "GL: Deleted sprite %d\n", spriteIndex); + Log_log("GL: Deleted sprite %d\n", spriteIndex); } static BlendFactors glGpuGetBlendFactors(Renderer* renderer) { GLRenderer* gl = (GLRenderer*)renderer; return (BlendFactors){ - gl->currentSFactor, - gl->currentDFactor, - gl->currentSFactorAlpha, + gl->currentSFactor, + gl->currentDFactor, + gl->currentSFactorAlpha, gl->currentDFactorAlpha }; } @@ -2353,7 +2353,7 @@ static void glGpuSetBlendMode(Renderer* renderer, int32_t mode) { gl->currentBlendMode = mode; gl->currentSFactor = GLCommon_blendModeToSFactor(mode); gl->currentDFactor = GLCommon_blendModeToDFactor(mode); - gl->currentSFactorAlpha = gl->currentSFactor; + gl->currentSFactorAlpha = gl->currentSFactor; gl->currentDFactorAlpha = gl->currentDFactor; glBlendEquation(GLCommon_blendModeToEquation(mode)); @@ -2370,9 +2370,9 @@ static void glGpuSetBlendModeExt(Renderer* renderer, int32_t sfactor, int32_t df gl->currentDFactorAlpha = dfactor_alpha; glBlendFuncSeparate( - GLCommon_blendFactorToGL(sfactor), - GLCommon_blendFactorToGL(dfactor), - GLCommon_blendFactorToGL(sfactor_alpha), + GLCommon_blendFactorToGL(sfactor), + GLCommon_blendFactorToGL(dfactor), + GLCommon_blendFactorToGL(sfactor_alpha), GLCommon_blendFactorToGL(dfactor_alpha) ); } @@ -2451,7 +2451,7 @@ static int32_t glShaderGetSamplerIndex(Renderer* renderer, int32_t shaderIndex, } } - fprintf(stderr, "GL: Sampler Index %s not found for shader %d!\n", uniform, shaderIndex); + Log_logWarning("GL: Sampler Index %s not found for shader %d!\n", uniform, shaderIndex); return -1; } @@ -2546,7 +2546,7 @@ static void glTextureSetStage(Renderer* renderer, int32_t slot, uint32_t texHand GLRenderer* gl = (GLRenderer*) renderer; flushBatch(gl); if (slot < 0) { - fprintf(stderr, "GL: Invalid Texture Stage\n"); + Log_logWarning("GL: Invalid Texture Stage\n"); return; } TexturePageItem* tpag; @@ -2557,7 +2557,7 @@ static void glTextureSetStage(Renderer* renderer, int32_t slot, uint32_t texHand gl->currentTextureId = texID; } if (slot > MAX_TEXTURE_STAGES) { - fprintf(stderr, "GL: Texture Stage Higher Than Max\n"); + Log_logWarning("GL: Texture Stage Higher Than Max\n"); return; } glActiveTexture(GL_TEXTURE0 + slot); @@ -2651,8 +2651,8 @@ static void glSetMatrix(Renderer* renderer, int32_t matrixType, Matrix4f matrix) Matrix4f worldViewProjection; Matrix4f_multiply(&worldViewProjection, &projection, &worldView); - - renderer->gmlMatrices[MATRIX_WORLD_VIEW] = worldView; + + renderer->gmlMatrices[MATRIX_WORLD_VIEW] = worldView; renderer->gmlMatrices[MATRIX_WORLD_VIEW_PROJECTION] = worldViewProjection; diff --git a/src/gl_legacy/gl_legacy_renderer.c b/src/gl_legacy/gl_legacy_renderer.c index 09999262f..284c0c8dc 100644 --- a/src/gl_legacy/gl_legacy_renderer.c +++ b/src/gl_legacy/gl_legacy_renderer.c @@ -115,10 +115,10 @@ static void glApplyProjection(Renderer* renderer, const Matrix4f* viewMatrix, co Matrix4f worldViewProjection; Matrix4f_multiply(&worldViewProjection, &projection, &worldView); - - renderer->gmlMatrices[MATRIX_VIEW] = view; + + renderer->gmlMatrices[MATRIX_VIEW] = view; renderer->gmlMatrices[MATRIX_PROJECTION] = projection; - renderer->gmlMatrices[MATRIX_WORLD_VIEW] = worldView; + renderer->gmlMatrices[MATRIX_WORLD_VIEW] = worldView; renderer->gmlMatrices[MATRIX_WORLD_VIEW_PROJECTION] = worldViewProjection; Matrix4f_flipClipY(&projection); @@ -140,7 +140,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { renderer->gmlMatrices[MATRIX_WORLD] = world; if (!hasFBO()) { - fprintf(stderr, "GL: The legacy-gl renderer requires FBO support!\n"); + Log_logError("GL: The legacy-gl renderer requires FBO support!\n"); abort(); } @@ -206,7 +206,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { gl->surfaceHeight = nullptr; gl->surfaceCount = 0; - fprintf(stderr, "GL: Renderer initialized (%u texture pages)\n", gl->textureCount); + Log_log("GL: Renderer initialized (%u texture pages)\n", gl->textureCount); } static void glDestroy(Renderer* renderer) { @@ -408,7 +408,7 @@ bool GLLegacyRenderer_ensureTextureLoaded(GLLegacyRenderer* gl, uint32_t pageId) // We'll load the textures on demand. uint8_t* pixels; if (!PS3Textures_loadPage(pageId, &w, &h, &pixels)) { - fprintf(stderr, "GL: PS3 page %u has no pixels\n", pageId); + Log_logWarning("GL: PS3 page %u has no pixels\n", pageId); return false; } gl->textureWidths[pageId] = w; @@ -433,7 +433,7 @@ bool GLLegacyRenderer_ensureTextureLoaded(GLLegacyRenderer* gl, uint32_t pageId) bool gm2022_5 = DataWin_isVersionAtLeast(dw, 2022, 5, 0, 0); uint8_t* pixels = ImageDecoder_decodeToRgba(txtr->blobData, (size_t) txtr->blobSize, gm2022_5, &w, &h); if (pixels == nullptr) { - fprintf(stderr, "GL: Failed to decode TXTR page %u\n", pageId); + Log_logWarning("GL: Failed to decode TXTR page %u\n", pageId); return false; } if (!txtr->mapped) { @@ -454,7 +454,7 @@ bool GLLegacyRenderer_ensureTextureLoaded(GLLegacyRenderer* gl, uint32_t pageId) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); #endif - fprintf(stderr, "GL: Loaded TXTR page %u (%dx%d)\n", pageId, w, h); + Log_log("GL: Loaded TXTR page %u (%dx%d)\n", pageId, w, h); return true; } @@ -807,7 +807,7 @@ static void glDrawRectangleColor(Renderer* renderer, float x1, float y1, float x // Vertex 0: top-left glColor4f(r1, g1, b1, alpha); glTexCoord2f(0.5f, 0.5f); - glVertex2f(x1, y1); + glVertex2f(x1, y1); // Vertex 1: top-right glColor4f(r2, g2, b2, alpha); @@ -822,7 +822,7 @@ static void glDrawRectangleColor(Renderer* renderer, float x1, float y1, float x // Vertex 3: bottom-left glColor4f(r4, g4, b4, alpha); glTexCoord2f(0.5f, 0.5f); - glVertex2f(x1, y2+1); + glVertex2f(x1, y2+1); glEnd(); } @@ -900,22 +900,22 @@ static void glDrawLineColor(Renderer* renderer, float x1, float y1, float x2, fl // Vertex 0: start + perpendicular (color1) glColor4f(r1, g1, b1, alpha); glTexCoord2f(0.5f, 0.5f); - glVertex2f(x1 + px, y1 + py); + glVertex2f(x1 + px, y1 + py); // Vertex 1: start - perpendicular (color1) glColor4f(r1, g1, b1, alpha); glTexCoord2f(0.5f, 0.5f); - glVertex2f(x1 - px, y1 - py); + glVertex2f(x1 - px, y1 - py); // Vertex 2: end - perpendicular (color2) glColor4f(r2, g2, b2, alpha); glTexCoord2f(0.5f, 0.5f); - glVertex2f(x2 - px, y2 - py); + glVertex2f(x2 - px, y2 - py); // Vertex 3: end + perpendicular (color2) glColor4f(r2, g2, b2, alpha); glTexCoord2f(0.5f, 0.5f); - glVertex2f(x2 + px, y2 + py); + glVertex2f(x2 + px, y2 + py); glEnd(); } @@ -1419,7 +1419,7 @@ static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID, sprite->maskCount = 0; sprite->masks = nullptr; - fprintf(stderr, "GL: Created dynamic sprite %u (%dx%d) from surface at (%d,%d)\n", spriteIndex, w, h, x, y); + Log_log("GL: Created dynamic sprite %u (%dx%d) from surface at (%d,%d)\n", spriteIndex, w, h, x, y); return (int32_t) spriteIndex; } @@ -1431,7 +1431,7 @@ static void glDeleteSprite(Renderer* renderer, int32_t spriteIndex) { // Refuse to delete original data.win sprites if (gl->originalSpriteCount > (uint32_t) spriteIndex) { - fprintf(stderr, "GL: Cannot delete data.win sprite %d\n", spriteIndex); + Log_logWarning("GL: Cannot delete data.win sprite %d\n", spriteIndex); return; } @@ -1460,15 +1460,15 @@ static void glDeleteSprite(Renderer* renderer, int32_t spriteIndex) { memset(sprite, 0, sizeof(Sprite)); sprite->name = keepName; - fprintf(stderr, "GL: Deleted sprite %d\n", spriteIndex); + Log_log("GL: Deleted sprite %d\n", spriteIndex); } static BlendFactors glGpuGetBlendFactors(Renderer* renderer) { GLLegacyRenderer* gl = (GLLegacyRenderer*)renderer; return (BlendFactors){ - gl->currentSFactor, - gl->currentDFactor, - gl->currentSFactorAlpha, + gl->currentSFactor, + gl->currentDFactor, + gl->currentSFactorAlpha, gl->currentDFactorAlpha }; } @@ -1480,11 +1480,11 @@ static int32_t glGpuGetBlendMode(Renderer* renderer) { static void glGpuSetBlendMode(Renderer* renderer, int32_t mode) { GLLegacyRenderer* gl = (GLLegacyRenderer*) renderer; - + gl->currentBlendMode = mode; gl->currentSFactor = GLCommon_blendModeToSFactor(mode); gl->currentDFactor = GLCommon_blendModeToDFactor(mode); - gl->currentSFactorAlpha = gl->currentSFactor; + gl->currentSFactorAlpha = gl->currentSFactor; gl->currentDFactorAlpha = gl->currentDFactor; glBlendEquation(GLCommon_blendModeToEquation(mode)); glBlendFunc(gl->currentSFactor, gl->currentDFactor); @@ -1492,17 +1492,17 @@ static void glGpuSetBlendMode(Renderer* renderer, int32_t mode) { static void glGpuSetBlendModeExt(Renderer* renderer, int32_t sfactor, int32_t dfactor, int32_t sfactor_alpha, int32_t dfactor_alpha) { GLLegacyRenderer* gl = (GLLegacyRenderer*) renderer; - + gl->currentBlendMode = bm_complex; gl->currentSFactor = sfactor; gl->currentDFactor = dfactor; gl->currentSFactorAlpha = sfactor_alpha; gl->currentDFactorAlpha = dfactor_alpha; - + glBlendFuncSeparate( - GLCommon_blendFactorToGL(sfactor), - GLCommon_blendFactorToGL(dfactor), - GLCommon_blendFactorToGL(sfactor_alpha), + GLCommon_blendFactorToGL(sfactor), + GLCommon_blendFactorToGL(dfactor), + GLCommon_blendFactorToGL(sfactor_alpha), GLCommon_blendFactorToGL(dfactor_alpha) ); } @@ -1513,7 +1513,7 @@ static void glGpuSetBlendEnable(Renderer* renderer, bool enable) { } static bool glGpuGetBlendEnable(MAYBE_UNUSED Renderer* renderer) { - + return glIsEnabled(GL_BLEND); } @@ -1570,13 +1570,13 @@ static int32_t glLegacyCreateSurface(Renderer* renderer, int32_t width, int32_t GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { - fprintf(stderr, "GL: Surface FBO incomplete (status=0x%X)\n", status); + Log_logWarning("GL: Surface FBO incomplete (status=0x%X)\n", status); } gl->surfaceWidth[surfaceIndex] = width; gl->surfaceHeight[surfaceIndex] = height; - fprintf(stderr, "GL: Created surface %u with size (%dx%d)\n", surfaceIndex, width, height); + Log_log("GL: Created surface %u with size (%dx%d)\n", surfaceIndex, width, height); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint) prevBinding); return (int32_t) surfaceIndex; } @@ -1647,7 +1647,7 @@ static void glLegacySurfaceResize(Renderer* renderer, int32_t surfaceId, int32_t gl->surfaceWidth[surfaceId] = width; gl->surfaceHeight[surfaceId] = height; - fprintf(stderr, "GL: Resized Surface %u to (%dx%d)\n", surfaceId, width, height); + Log_log("GL: Resized Surface %u to (%dx%d)\n", surfaceId, width, height); } static void glLegacySurfaceFree(Renderer* renderer, int32_t surfaceId) { @@ -1661,7 +1661,7 @@ static void glLegacySurfaceFree(Renderer* renderer, int32_t surfaceId) { gl->surfaceTexture[surfaceId] = 0; gl->surfaceWidth[surfaceId] = 0; gl->surfaceHeight[surfaceId] = 0; - fprintf(stderr, "GL: Freed Surface %d\n", surfaceId); + Log_log("GL: Freed Surface %d\n", surfaceId); } static bool glLegacySetRenderTarget(Renderer* renderer, int32_t surfaceId, bool implicitApplicationSurface) { diff --git a/src/image/image_decoder.c b/src/image/image_decoder.c index 16b2aacc9..b1d29ba3b 100644 --- a/src/image/image_decoder.c +++ b/src/image/image_decoder.c @@ -5,6 +5,8 @@ #include #include +#include "log.h" + #include "stb_image.h" #define QOI_HEADER_SIZE 12 @@ -134,7 +136,7 @@ static uint8_t* decodeBz2Qoi(const uint8_t* blob, size_t blobSize, bool gm2022_5 unsigned int destLen = (unsigned int) uncompressedCapacity; int rc = BZ2_bzBuffToBuffDecompress((char*) uncompressed, &destLen, (char*)(blob + headerSize), (unsigned int)(blobSize - headerSize), 0, 0); if (rc != BZ_OK) { - fprintf(stderr, "ImageDecoder: BZ2 decompress failed (rc=%d)\n", rc); + Log_logWarning("ImageDecoder: BZ2 decompress failed (rc=%d)\n", rc); free(uncompressed); return nullptr; } diff --git a/src/ini.c b/src/ini.c index 44afa5fb4..6b8acbbd8 100644 --- a/src/ini.c +++ b/src/ini.c @@ -114,7 +114,7 @@ IniFile* Ini_parse(const char* text) { currentSection = addSection(ini, nameStart); } } else { - fprintf(stderr, "Ini: malformed section header: %s\n", trimmed); + Log_logWarning("Ini: malformed section header: %s\n", trimmed); } } else { // Key=value pair diff --git a/src/input_recording.c b/src/input_recording.c index 51ec4623c..cfb12821c 100644 --- a/src/input_recording.c +++ b/src/input_recording.c @@ -21,7 +21,7 @@ InputRecording* InputRecording_createPlayer(const char* playbackFilePath, const // Read the file contents FILE* f = fopen(playbackFilePath, "rb"); if (f == nullptr) { - fprintf(stderr, "Error: Could not open input recording file '%s'\n", playbackFilePath); + Log_logError("Error: Could not open input recording file '%s'\n", playbackFilePath); exit(1); } @@ -39,7 +39,7 @@ InputRecording* InputRecording_createPlayer(const char* playbackFilePath, const free(contents); if (root == nullptr || !JsonReader_isObject(root)) { - fprintf(stderr, "Error: Invalid JSON in input recording file '%s'\n", playbackFilePath); + Log_logError("Error: Invalid JSON in input recording file '%s'\n", playbackFilePath); exit(1); } @@ -94,7 +94,7 @@ InputRecording* InputRecording_createPlayer(const char* playbackFilePath, const } JsonReader_free(root); - fprintf(stderr, "InputRecording: Loaded %d frames from '%s'\n", rec->playbackFrameCount, playbackFilePath); + Log_log("InputRecording: Loaded %d frames from '%s'\n", rec->playbackFrameCount, playbackFilePath); return rec; } @@ -143,7 +143,7 @@ void InputRecording_processFrame(InputRecording* recording, RunnerKeyboardState* } } else { if (!recording->playbackEnded) { - fprintf(stderr, "InputRecording: Playback ended at frame %d (recorded %d frames)\n", frameNumber, recording->playbackFrameCount); + Log_log("InputRecording: Playback ended at frame %d (recorded %d frames)\n", frameNumber, recording->playbackFrameCount); recording->playbackEnded = true; } } @@ -214,7 +214,7 @@ bool InputRecording_save(InputRecording* recording) { FILE* f = fopen(recording->recordFilePath, "wb"); if (f == nullptr) { - fprintf(stderr, "Error: Could not write input recording to '%s'\n", recording->recordFilePath); + Log_logError("Error: Could not write input recording to '%s'\n", recording->recordFilePath); JsonWriter_free(&w); return false; } @@ -224,7 +224,7 @@ bool InputRecording_save(InputRecording* recording) { fputc('\n', f); fclose(f); - fprintf(stderr, "InputRecording: Saved %d frames to '%s'\n", frameCount, recording->recordFilePath); + Log_log("InputRecording: Saved %d frames to '%s'\n", frameCount, recording->recordFilePath); JsonWriter_free(&w); return true; } diff --git a/src/json_reader.c b/src/json_reader.c index c863648ae..89cdbca62 100644 --- a/src/json_reader.c +++ b/src/json_reader.c @@ -107,7 +107,7 @@ static JsonValue* parseString(JsonParser* parser) { break; } default: - fprintf(stderr, "JsonReader: unknown escape sequence '\\%c'\n", escaped); + Log_logError("JsonReader: unknown escape sequence '\\%c'\n", escaped); free(buffer); return nullptr; } @@ -122,7 +122,7 @@ static JsonValue* parseString(JsonParser* parser) { } // Unterminated string - fprintf(stderr, "JsonReader: unterminated string\n"); + Log_logError("JsonReader: unterminated string\n"); free(buffer); return nullptr; } @@ -132,7 +132,7 @@ static JsonValue* parseNumber(JsonParser* parser) { char* end = nullptr; double number = strtod(start, &end); if (end == start) { - fprintf(stderr, "JsonReader: invalid number\n"); + Log_logError("JsonReader: invalid number\n"); return nullptr; } parser->position += (size_t) (end - start); @@ -183,7 +183,7 @@ static JsonValue* parseArray(JsonParser* parser) { advance(parser); return value; } else { - fprintf(stderr, "JsonReader: expected ',' or ']' in array\n"); + Log_logError("JsonReader: expected ',' or ']' in array\n"); JsonReader_free(value); return nullptr; } @@ -209,7 +209,7 @@ static JsonValue* parseObject(JsonParser* parser) { while (true) { skipWhitespace(parser); if (peek(parser) != '"') { - fprintf(stderr, "JsonReader: expected string key in object\n"); + Log_logError("JsonReader: expected string key in object\n"); JsonReader_free(value); return nullptr; } @@ -225,7 +225,7 @@ static JsonValue* parseObject(JsonParser* parser) { skipWhitespace(parser); if (peek(parser) != ':') { - fprintf(stderr, "JsonReader: expected ':' after object key\n"); + Log_logError("JsonReader: expected ':' after object key\n"); free(key); JsonReader_free(value); return nullptr; @@ -260,7 +260,7 @@ static JsonValue* parseObject(JsonParser* parser) { advance(parser); return value; } else { - fprintf(stderr, "JsonReader: expected ',' or '}' in object\n"); + Log_logError("JsonReader: expected ',' or '}' in object\n"); JsonReader_free(value); return nullptr; } @@ -292,7 +292,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 't': { JsonValue* value = parseLiteral(parser, "true", 4); if (value == nullptr) { - fprintf(stderr, "JsonReader: invalid literal\n"); + Log_logError("JsonReader: invalid literal\n"); return nullptr; } value->type = JSON_BOOL; @@ -302,7 +302,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 'f': { JsonValue* value = parseLiteral(parser, "false", 5); if (value == nullptr) { - fprintf(stderr, "JsonReader: invalid literal\n"); + Log_logError("JsonReader: invalid literal\n"); return nullptr; } value->type = JSON_BOOL; @@ -312,7 +312,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 'n': { JsonValue* value = parseLiteral(parser, "null", 4); if (value == nullptr) { - fprintf(stderr, "JsonReader: invalid literal\n"); + Log_logError("JsonReader: invalid literal\n"); return nullptr; } return value; @@ -321,7 +321,7 @@ static JsonValue* parseValue(JsonParser* parser) { if (c == '-' || (c >= '0' && c <= '9')) { return parseNumber(parser); } - fprintf(stderr, "JsonReader: unexpected character '%c' at position %zu\n", c, parser->position); + Log_logError("JsonReader: unexpected character '%c' at position %zu\n", c, parser->position); return nullptr; } } @@ -348,7 +348,7 @@ JsonValue* JsonReader_parse(const char* json) { if (result != nullptr) { skipWhitespace(&parser); if (parser.position < parser.length) { - fprintf(stderr, "JsonReader: trailing content after JSON value at position %zu\n", parser.position); + Log_logError("JsonReader: trailing content after JSON value at position %zu\n", parser.position); JsonReader_free(result); return nullptr; } diff --git a/src/ps2/debug_font_renderer.c b/src/ps2/debug_font_renderer.c index 02ec124a9..0999e21b6 100644 --- a/src/ps2/debug_font_renderer.c +++ b/src/ps2/debug_font_renderer.c @@ -20,7 +20,7 @@ static uint32_t uploadTable(GSGLOBAL* gsGlobal, const void* srcData, size_t srcB uint32_t vramSize = gsKit_texture_size(width, height, psm); uint32_t vramAddr = gsKit_vram_alloc(gsGlobal, vramSize, GSKIT_ALLOC_USERBUFFER); if (vramAddr == GSKIT_ALLOC_ERROR) { - fprintf(stderr, "DebugFontRenderer: Failed to allocate VRAM for %s\n", what); + Log_logWarning("DebugFontRenderer: Failed to allocate VRAM for %s\n", what); abort(); } @@ -58,7 +58,7 @@ DebugFontRenderer* DebugFontRenderer_create(GSGLOBAL* gsGlobal) { tex->Filter = GS_FILTER_LINEAR; tex->ClutStorageMode = GS_CLUT_STORAGE_CSM1; - fprintf(stderr, "DebugFontRenderer: uploaded - CLUT 0x%08lX, atlas 0x%08lX\n", (unsigned long) clutVram, (unsigned long) atlasVram); + Log_log("DebugFontRenderer: uploaded - CLUT 0x%08lX, atlas 0x%08lX\n", (unsigned long) clutVram, (unsigned long) atlasVram); return r; } diff --git a/src/ps2/gs_renderer.c b/src/ps2/gs_renderer.c index 75cbbea33..2e47a6c39 100644 --- a/src/ps2/gs_renderer.c +++ b/src/ps2/gs_renderer.c @@ -22,7 +22,7 @@ static void rendererPrintf(const char* fmt, ...) { va_list args; va_start(args, fmt); - vfprintf(stderr, fmt, args); + Log_vLogError(fmt, args); va_end(args); } #else @@ -47,7 +47,7 @@ static uint8_t* loadFileRaw(const char* path, uint32_t* outSize) { FILE* f = fopen(textureBinPath, "rb"); if (f == nullptr) { - fprintf(stderr, "GsRenderer: Failed to open %s\n", path); + Log_logError("GsRenderer: Failed to open %s\n", path); abort(); } @@ -62,7 +62,7 @@ static uint8_t* loadFileRaw(const char* path, uint32_t* outSize) { fclose(f); if (read != (size_t) size) { - fprintf(stderr, "GsRenderer: Short read on %s (expected %ld, got %zu)\n", path, size, read); + Log_logError("GsRenderer: Short read on %s (expected %ld, got %zu)\n", path, size, read); abort(); } @@ -76,7 +76,7 @@ static void loadAtlas(GsRenderer* gs) { char* atlasBinPath = PS2Utils_createDevicePath("ATLAS.BIN"); FILE* f = fopen(atlasBinPath, "rb"); if (f == nullptr) { - fprintf(stderr, "GsRenderer: Failed to open %s\n", atlasBinPath); + Log_logError("GsRenderer: Failed to open %s\n", atlasBinPath); abort(); } @@ -88,7 +88,7 @@ static void loadAtlas(GsRenderer* gs) { uint8_t version = BinaryReader_readUint8(&reader); if (version != 0) { - fprintf(stderr, "GsRenderer: Unsupported ATLAS.BIN version %u\n", version); + Log_logError("GsRenderer: Unsupported ATLAS.BIN version %u\n", version); abort(); } @@ -111,7 +111,7 @@ static void loadAtlas(GsRenderer* gs) { gs->atlasDataSizes[i] = BinaryReader_readUint32(&reader); gs->atlasCompressionType[i] = BinaryReader_readUint8(&reader); if (gs->atlasBpp[i] != 4 && gs->atlasBpp[i] != 8) { - fprintf(stderr, "GsRenderer: Atlas %u has unsupported bpp %u\n", i, gs->atlasBpp[i]); + Log_logError("GsRenderer: Atlas %u has unsupported bpp %u\n", i, gs->atlasBpp[i]); abort(); } } @@ -175,7 +175,7 @@ static void loadAtlas(GsRenderer* gs) { gs->atlasToChunk[i] = -1; } - fprintf(stderr, "GsRenderer: ATLAS.BIN loaded - %u TPAG entries, %u tile entries, %u atlases\n", gs->atlasTPAGCount, gs->atlasTileCount, gs->atlasCount); + Log_log("GsRenderer: ATLAS.BIN loaded - %u TPAG entries, %u tile entries, %u atlases\n", gs->atlasTPAGCount, gs->atlasTileCount, gs->atlasCount); free(atlasBinPath); } @@ -197,7 +197,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { uint32_t clut4FileSize; uint8_t* clut4Data = loadFileRaw("CLUT4.BIN", &clut4FileSize); gs->clut4Count = clut4FileSize / CLUT4_ENTRY_SIZE; - fprintf(stderr, "GsRenderer: CLUT4.BIN loaded - %u CLUTs (%u bytes)\n", gs->clut4Count, clut4FileSize); + Log_log("GsRenderer: CLUT4.BIN loaded - %u CLUTs (%u bytes)\n", gs->clut4Count, clut4FileSize); gs->clut4VramAddrs = (uint32_t *)safeMalloc(gs->clut4Count * sizeof(uint32_t)); @@ -206,7 +206,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { uint32_t vramSize = gsKit_texture_size(8, 2, GS_PSM_CT32); uint32_t vramAddr = gsKit_vram_alloc(gsGlobal, vramSize, GSKIT_ALLOC_USERBUFFER); if (vramAddr == GSKIT_ALLOC_ERROR) { - fprintf(stderr, "GsRenderer: Failed to allocate VRAM for CLUT4 index %u\n", i); + Log_logError("GsRenderer: Failed to allocate VRAM for CLUT4 index %u\n", i); abort(); } @@ -216,7 +216,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { gs->clut4VramAddrs[i] = vramAddr; } - fprintf(stderr, "GsRenderer: CLUT4 uploaded (%u CLUTs)\n", gs->clut4Count); + Log_log("GsRenderer: CLUT4 uploaded (%u CLUTs)\n", gs->clut4Count); free(clut4Data); } @@ -225,7 +225,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { uint32_t clut8FileSize; uint8_t* clut8Data = loadFileRaw("CLUT8.BIN", &clut8FileSize); gs->clut8Count = clut8FileSize / CLUT8_ENTRY_SIZE; - fprintf(stderr, "GsRenderer: CLUT8.BIN loaded - %u CLUTs (%u bytes)\n", gs->clut8Count, clut8FileSize); + Log_log("GsRenderer: CLUT8.BIN loaded - %u CLUTs (%u bytes)\n", gs->clut8Count, clut8FileSize); gs->clut8VramAddrs = (uint32_t *)safeMalloc(gs->clut8Count * sizeof(uint32_t)); @@ -234,7 +234,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { uint32_t vramSize = gsKit_texture_size(16, 16, GS_PSM_CT32); uint32_t vramAddr = gsKit_vram_alloc(gsGlobal, vramSize, GSKIT_ALLOC_USERBUFFER); if (vramAddr == GSKIT_ALLOC_ERROR) { - fprintf(stderr, "GsRenderer: Failed to allocate VRAM for CLUT8 index %u\n", i); + Log_logError("GsRenderer: Failed to allocate VRAM for CLUT8 index %u\n", i); abort(); } @@ -243,13 +243,13 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { gs->clut8VramAddrs[i] = vramAddr; } - fprintf(stderr, "GsRenderer: CLUT8 uploaded (%u CLUTs)\n", gs->clut8Count); + Log_log("GsRenderer: CLUT8 uploaded (%u CLUTs)\n", gs->clut8Count); free(clut8Data); } free(tempBuf); - fprintf(stderr, "GsRenderer: VRAM after CLUTs: 0x%08X / 0x%08X\n", gsGlobal->CurrentPointer, GS_VRAM_SIZE); + Log_log("GsRenderer: VRAM after CLUTs: 0x%08X / 0x%08X\n", gsGlobal->CurrentPointer, GS_VRAM_SIZE); } // ===[ VRAM Texture Cache (Buddy System with LRU Eviction) ]=== @@ -283,7 +283,7 @@ static void initTextureCache(GsRenderer* gs) { // Advance CurrentPointer past our chunk pool so any future gsKit allocations fail loudly. gs->gsGlobal->CurrentPointer = gs->textureVramBase + gs->chunkCount * VRAM_CHUNK_SIZE; - fprintf(stderr, "GsRenderer: Texture cache initialized - %u chunks (%u KB each), base 0x%08X, %u KB for textures\n", gs->chunkCount, VRAM_CHUNK_SIZE / 1024, gs->textureVramBase, gs->chunkCount * (VRAM_CHUNK_SIZE / 1024)); + Log_log("GsRenderer: Texture cache initialized - %u chunks (%u KB each), base 0x%08X, %u KB for textures\n", gs->chunkCount, VRAM_CHUNK_SIZE / 1024, gs->textureVramBase, gs->chunkCount * (VRAM_CHUNK_SIZE / 1024)); } // A chunk is free if no atlas, snapshot, or surface occupies it. Snapshots and surfaces both pin the chunk against LRU eviction. @@ -470,7 +470,7 @@ static void computeAtlasReservation(GsRenderer* gs) { } if (worst > gs->chunkCount) worst = gs->chunkCount; gs->reservedAtlasChunks = worst; - fprintf(stderr, "GsRenderer: Reserving first %u chunk(s) (%u KB) as atlas-only fail-safe (largest atlas @ 8bpp)\n", worst, worst * (VRAM_CHUNK_SIZE / 1024)); + Log_log("GsRenderer: Reserving first %u chunk(s) (%u KB) as atlas-only fail-safe (largest atlas @ 8bpp)\n", worst, worst * (VRAM_CHUNK_SIZE / 1024)); } // Initialize the EE RAM cache. Called from gsInit after opening TEXTURES.BIN. @@ -607,7 +607,7 @@ static void uploadAtlasToChunk(GsRenderer* gs, uint16_t atlasId, int32_t firstCh fseek(gs->texturesFile, (long) gs->atlasOffsets[atlasId], SEEK_SET); size_t bytesRead = fread(compressedBuf, 1, dataSize, gs->texturesFile); if (bytesRead != dataSize) { - fprintf(stderr, "GsRenderer: Short read for atlas %u (expected %u, got %zu)\n", atlasId, dataSize, bytesRead); + Log_logError("GsRenderer: Short read for atlas %u (expected %u, got %zu)\n", atlasId, dataSize, bytesRead); abort(); } @@ -668,7 +668,7 @@ static void uploadAtlasToChunk(GsRenderer* gs, uint16_t atlasId, int32_t firstCh // Returns true on success, false on failure. static bool ensureAtlasLoaded(GsRenderer* gs, uint16_t atlasId) { if (atlasId >= gs->atlasCount) { - fprintf(stderr, "GsRenderer: Atlas ID %u out of range (max %u)\n", atlasId, gs->atlasCount - 1); + Log_logWarning("GsRenderer: Atlas ID %u out of range (max %u)\n", atlasId, gs->atlasCount - 1); return false; } @@ -693,7 +693,7 @@ static bool ensureAtlasLoaded(GsRenderer* gs, uint16_t atlasId) { // Determine how many chunks we need uint8_t bpp = gs->atlasBpp[atlasId]; if (bpp != 4 && bpp != 8) { - fprintf(stderr, "GsRenderer: Atlas %u has unknown bpp %u\n", atlasId, bpp); + Log_logWarning("GsRenderer: Atlas %u has unknown bpp %u\n", atlasId, bpp); return false; } int chunksNeeded = atlasChunkCount(gs->atlasWidth[atlasId], gs->atlasHeight[atlasId], bpp); @@ -705,7 +705,7 @@ static bool ensureAtlasLoaded(GsRenderer* gs, uint16_t atlasId) { // Allocate chunks (may evict or defrag) int32_t chunkIdx = allocateChunks(gs, chunksNeeded, 0); if (0 > chunkIdx) { - fprintf(stderr, "GsRenderer: VRAM exhausted! Cannot allocate %d chunk(s) for atlas %u (%ubpp)\n", chunksNeeded, atlasId, bpp); + Log_logError("GsRenderer: VRAM exhausted! Cannot allocate %d chunk(s) for atlas %u (%ubpp)\n", chunksNeeded, atlasId, bpp); abort(); } @@ -903,7 +903,7 @@ static bool setupTextureForTPAG(GsRenderer* gs, GSTEXTURE* tex, int32_t tpagInde tex->ClutPSM = GS_PSM_CT32; if (entry->clutIndex >= gs->clut4Count) { - fprintf(stderr, "GsRenderer: CLUT4 index %u out of range (max %u) for TPAG %d\n", entry->clutIndex, gs->clut4Count - 1, tpagIndex); + Log_logError("GsRenderer: CLUT4 index %u out of range (max %u) for TPAG %d\n", entry->clutIndex, gs->clut4Count - 1, tpagIndex); abort(); } @@ -913,7 +913,7 @@ static bool setupTextureForTPAG(GsRenderer* gs, GSTEXTURE* tex, int32_t tpagInde tex->ClutPSM = GS_PSM_CT32; if (entry->clutIndex >= gs->clut8Count) { - fprintf(stderr, "GsRenderer: CLUT8 index %u out of range (max %u) for TPAG %d\n", entry->clutIndex, gs->clut8Count - 1, tpagIndex); + Log_logError("GsRenderer: CLUT8 index %u out of range (max %u) for TPAG %d\n", entry->clutIndex, gs->clut8Count - 1, tpagIndex); abort(); } @@ -965,7 +965,7 @@ static bool setupTextureForTile(GsRenderer* gs, GSTEXTURE* tex, AtlasTileEntry* tex->ClutPSM = GS_PSM_CT32; if (entry->clutIndex >= gs->clut4Count) { - fprintf(stderr, "GsRenderer: CLUT4 index %u out of range (max %u) for tile (bg=%d)\n", entry->clutIndex, gs->clut4Count - 1, entry->bgDef); + Log_logError("GsRenderer: CLUT4 index %u out of range (max %u) for tile (bg=%d)\n", entry->clutIndex, gs->clut4Count - 1, entry->bgDef); abort(); } @@ -975,7 +975,7 @@ static bool setupTextureForTile(GsRenderer* gs, GSTEXTURE* tex, AtlasTileEntry* tex->ClutPSM = GS_PSM_CT32; if (entry->clutIndex >= gs->clut8Count) { - fprintf(stderr, "GsRenderer: CLUT8 index %u out of range (max %u) for tile (bg=%d)\n", entry->clutIndex, gs->clut8Count - 1, entry->bgDef); + Log_logError("GsRenderer: CLUT8 index %u out of range (max %u) for tile (bg=%d)\n", entry->clutIndex, gs->clut8Count - 1, entry->bgDef); abort(); } @@ -1060,7 +1060,7 @@ static void gsInit(Renderer* renderer, DataWin* dataWin) { char* texturesBinPath = PS2Utils_createDevicePath("TEXTURES.BIN"); gs->texturesFile = fopen(texturesBinPath, "rb"); if (gs->texturesFile == nullptr) { - fprintf(stderr, "GsRenderer: Failed to open %s\n", texturesBinPath); + Log_logError("GsRenderer: Failed to open %s\n", texturesBinPath); abort(); } setvbuf(gs->texturesFile, nullptr, _IOFBF, 128 * 1024); @@ -1081,7 +1081,7 @@ static void gsInit(Renderer* renderer, DataWin* dataWin) { // Initialize EE RAM cache for compressed atlas data initEeCache(gs); - fprintf(stderr, "GsRenderer: Initialized (textured mode)\n"); + Log_log("GsRenderer: Initialized (textured mode)\n"); } static void gsDestroy(Renderer* renderer) { @@ -2295,7 +2295,7 @@ static void gsDeleteSprite(Renderer* renderer, int32_t spriteIndex) { if (0 > spriteIndex || (uint32_t) spriteIndex >= dw->sprt.count) return; // Refuse to delete original data.win sprites - their tpagIndices point into the static atlas, not snapshot pool. if (gs->originalSpriteCount > (uint32_t) spriteIndex) { - fprintf(stderr, "GsRenderer: Cannot delete data.win sprite %d\n", spriteIndex); + Log_logWarning("GsRenderer: Cannot delete data.win sprite %d\n", spriteIndex); return; } @@ -2378,9 +2378,9 @@ static u64 gmsBlendModeToGSAlpha(int32_t mode) { static BlendFactors gsGpuGetBlendFactors(Renderer* renderer) { GsRenderer* gs = (GsRenderer*)renderer; return (BlendFactors){ - gs->currentSFactor, - gs->currentDFactor, - gs->currentSFactorAlpha, + gs->currentSFactor, + gs->currentDFactor, + gs->currentSFactorAlpha, gs->currentDFactorAlpha }; } @@ -2405,7 +2405,7 @@ static void gsGpuSetBlendModeExt(Renderer* renderer, int32_t sfactor, int32_t df gs->currentDFactorAlpha = dfactor_alpha; u64 alpha; if (!gmsFactorPairToGSAlpha(sfactor, dfactor, &alpha) && !gs->blendModeWarned) { - fprintf(stderr, "GsRenderer: blend mode (sf=%d, df=%d) not exactly representable on PS2; approximating\n", sfactor, dfactor); + Log_logWarning("GsRenderer: blend mode (sf=%d, df=%d) not exactly representable on PS2; approximating\n", sfactor, dfactor); gs->blendModeWarned = true; } gs->currentBlendAlpha = alpha; @@ -2668,7 +2668,7 @@ static int32_t gsCreateSurface(Renderer* renderer, int32_t width, int32_t height } if (phantomReason != nullptr) { - fprintf(stderr, "GsRenderer: surface_create(%d, %d) phantom (%s); needed %d chunks (%u bytes)\n", width, height, phantomReason, chunksNeeded, bytes); + Log_logWarning("GsRenderer: surface_create(%d, %d) phantom (%s); needed %d chunks (%u bytes)\n", width, height, phantomReason, chunksNeeded, bytes); Surface* s = &gs->surfaces[row]; s->firstChunk = 0; s->chunkCount = 0; diff --git a/src/ps2/main.c b/src/ps2/main.c index 1a13127d6..560c0b953 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -253,11 +253,11 @@ int main(int argc, char* argv[]) { PS2Utils_extractDeviceKey(argv[0]); - fprintf(stderr, "argv0 is %s, device key is %s\n", argv[0], deviceKey.key); + Log_log("argv0 is %s, device key is %s\n", argv[0], deviceKey.key); PS2Utils_loadFSDrivers(); - fprintf(stderr, "Loaded FS drivers!\n"); + Log_log("Loaded FS drivers!\n"); char* dataWinPath = PS2Utils_createDevicePath("DATA.WIN"); @@ -431,7 +431,7 @@ int main(int argc, char* argv[]) { options.eagerlyLoadedRooms = eagerRooms; options.progressCallback = PS2Overlay_statusScreenCallback; options.progressCallbackUserData = PS2Overlay_getCallbackData(); - + DataWin* dataWin = DataWin_parse(dataWinPath, options); free(dataWinPath); shfree(eagerRooms); @@ -538,7 +538,7 @@ int main(int argc, char* argv[]) { PS2Utils_loadMassStorageDrivers(); gprof_start(); - fprintf(stderr, "gprof: Profiling started!\n"); + Log_log("gprof: Profiling started!\n"); #endif Gen8* gen8 = &dataWin->gen8; @@ -607,7 +607,7 @@ int main(int argc, char* argv[]) { int32_t nextIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition + 1]; runner->pendingRoom = nextIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - fprintf(stderr, "Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); + Log_log("Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); } } @@ -708,9 +708,9 @@ int main(int argc, char* argv[]) { } else { gprofPath = "mass:gmon.out"; } - fprintf(stderr, "gprof: Writing profiling data to %s\n", gprofPath); + Log_log("gprof: Writing profiling data to %s\n", gprofPath); gprof_stop(gprofPath, 1); - fprintf(stderr, "gprof: Done\n"); + Log_log("gprof: Done\n"); } #endif diff --git a/src/ps2/ps2_file_system.c b/src/ps2/ps2_file_system.c index cf7e4412b..6b39da8d1 100644 --- a/src/ps2/ps2_file_system.c +++ b/src/ps2/ps2_file_system.c @@ -184,9 +184,9 @@ static void copyIconIcoIfMissing(const char* dirPath) { // Copy from boot device char* srcPath = PS2Utils_createDevicePath("ICON.ICO"); if (copyFile(srcPath, dstPath)) { - fprintf(stderr, "Ps2FileSystem: Copied ICON.ICO to %s\n", dirPath); + Log_log("Ps2FileSystem: Copied ICON.ICO to %s\n", dirPath); } else { - fprintf(stderr, "Ps2FileSystem: Failed to copy ICON.ICO from %s to %s\n", srcPath, dstPath); + Log_logWarning("Ps2FileSystem: Failed to copy ICON.ICO from %s to %s\n", srcPath, dstPath); } free(srcPath); @@ -217,9 +217,9 @@ static void writeIconSysIfMissing(const char* dirPath, const char* gameTitle, co if (f != nullptr) { fwrite(buffer, 1, ICON_SYS_SIZE, f); fclose(f); - fprintf(stderr, "Ps2FileSystem: Created icon.sys in %s\n", dirPath); + Log_log("Ps2FileSystem: Created icon.sys in %s\n", dirPath); } else { - fprintf(stderr, "Ps2FileSystem: Failed to create icon.sys in %s\n", dirPath); + Log_logWarning("Ps2FileSystem: Failed to create icon.sys in %s\n", dirPath); } free(iconSysPath); @@ -612,13 +612,13 @@ FileSystem* Ps2FileSystem_create(JsonValue* configRoot, const char* gameTitle) { const char* rawPath = JsonReader_getString(pathElement); char* resolved = expandBootPrefix(rawPath); arrput(resolvedPaths, resolved); - fprintf(stderr, "Ps2FileSystem: '%s' -> '%s'\n", gameFileName, resolved); + Log_log("Ps2FileSystem: '%s' -> '%s'\n", gameFileName, resolved); } shput(pfs->mappings, gameFileName, resolvedPaths); } - fprintf(stderr, "Ps2FileSystem: Loaded %d file mappings\n", (int) shlen(pfs->mappings)); + Log_log("Ps2FileSystem: Loaded %d file mappings\n", (int) shlen(pfs->mappings)); return (FileSystem*) pfs; } diff --git a/src/ps2/ps2_utils.c b/src/ps2/ps2_utils.c index bdb0021d9..0a6f883ca 100644 --- a/src/ps2/ps2_utils.c +++ b/src/ps2/ps2_utils.c @@ -33,23 +33,23 @@ void PS2Utils_loadFSDrivers() { require(deviceKeyLoaded); if (deviceKey.usesISO9660) { - fprintf(stderr, "PS2Utils: Loading CDVD drivers for device key '%s'\n", deviceKey.key); + Log_log("PS2Utils: Loading CDVD drivers for device key '%s'\n", deviceKey.key); int ret; ret = SifLoadModule("rom0:CDVDMAN", 0, nullptr); if (0 > ret) { - fprintf(stderr, "PS2Utils: Failed to load CDVDMAN: %d\n", ret); + Log_logError("PS2Utils: Failed to load CDVDMAN: %d\n", ret); abort(); } ret = SifLoadModule("rom0:CDVDFSV", 0, nullptr); if (0 > ret) { - fprintf(stderr, "PS2Utils: Failed to load CDVDFSV: %d\n", ret); + Log_logError("PS2Utils: Failed to load CDVDFSV: %d\n", ret); abort(); } sceCdInit(SCECdINIT); - fprintf(stderr, "PS2Utils: CDVD initialized\n"); + Log_log("PS2Utils: CDVD initialized\n"); } } @@ -67,33 +67,33 @@ extern unsigned int size_usbmass_bd_irx; void PS2Utils_loadMassStorageDrivers() { require(deviceKeyLoaded); - fprintf(stderr, "PS2Utils: Loading USB mass storage drivers for gprof output...\n"); + Log_log("PS2Utils: Loading USB mass storage drivers for gprof output...\n"); int ret; ret = SifExecModuleBuffer(usbd_irx, size_usbd_irx, 0, nullptr, nullptr); if (0 > ret) { - fprintf(stderr, "PS2Utils: Failed to load usbd: %d\n", ret); + Log_logWarning("PS2Utils: Failed to load usbd: %d\n", ret); } ret = SifExecModuleBuffer(bdm_irx, size_bdm_irx, 0, nullptr, nullptr); if (0 > ret) { - fprintf(stderr, "PS2Utils: Failed to load bdm: %d\n", ret); + Log_logWarning("PS2Utils: Failed to load bdm: %d\n", ret); } ret = SifExecModuleBuffer(bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, nullptr, nullptr); if (0 > ret) { - fprintf(stderr, "PS2Utils: Failed to load bdmfs_fatfs: %d\n", ret); + Log_logWarning("PS2Utils: Failed to load bdmfs_fatfs: %d\n", ret); } ret = SifExecModuleBuffer(usbmass_bd_irx, size_usbmass_bd_irx, 0, nullptr, nullptr); if (0 > ret) { - fprintf(stderr, "PS2Utils: Failed to load usbmass_bd: %d\n", ret); + Log_logWarning("PS2Utils: Failed to load usbmass_bd: %d\n", ret); } // Wait for USB device detection sleep(3); - fprintf(stderr, "PS2Utils: USB mass storage drivers loaded\n"); + Log_log("PS2Utils: USB mass storage drivers loaded\n"); } #endif diff --git a/src/ps3/main.c b/src/ps3/main.c index 4eabdb9a1..55be2d019 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -81,7 +81,7 @@ const StickMapping STICK_MAPPINGS[] = { static bool prevStickState[sizeof(STICK_MAPPINGS) / sizeof(STICK_MAPPINGS[0])] = {0}; // ===[ MAIN ]=== -static double freq = 0; +static double freq = 0; #define PS3_GET_TIME ((double)__builtin_ppc_get_timebase() / (double)freq) bool shouldExit = false; @@ -94,7 +94,7 @@ static void sys_callback(uint64_t status, uint64_t param, void* userdata) { case SYSUTIL_EXIT_GAME: shouldExit = true; break; - + case SYSUTIL_MENU_OPEN: case SYSUTIL_MENU_CLOSE: break; @@ -254,7 +254,7 @@ int main(int argc, char* argv[]) { memcpy(texturesBinPath, dataWinDir, dirLen); strcpy(texturesBinPath + dirLen, "textures.bin"); if (!PS3Textures_init(texturesBinPath)) { - fprintf(stderr, "FATAL: failed to load %s\n", texturesBinPath); + Log_logError("Fatal: failed to load %s\n", texturesBinPath); return 1; } free(texturesBinPath); @@ -310,7 +310,7 @@ int main(int argc, char* argv[]) { bool shouldStep = true; if (runner->debugMode && debugPaused) { shouldStep = RunnerKeyboard_checkPressed(runner->keyboard, 'O'); - if (shouldStep) fprintf(stderr, "Debug: Frame advance (frame %d)\n", runner->frameCount); + if (shouldStep) Log_log("Debug: Frame advance (frame %d)\n", runner->frameCount); } diff --git a/src/ps3/ps3_overlay.c b/src/ps3/ps3_overlay.c index 5eaa4cacd..6fd125968 100644 --- a/src/ps3/ps3_overlay.c +++ b/src/ps3/ps3_overlay.c @@ -31,7 +31,7 @@ void PS3Overlay_init(void) { // Convert the 8bpp atlas into RGBA uint8_t* rgba = (uint8_t*) malloc((size_t) (DEBUGFONT_ATLAS_W * DEBUGFONT_ATLAS_H * 4)); if (rgba == nullptr) { - fprintf(stderr, "PS3Overlay: failed to allocate %d bytes for the font atlas\n", DEBUGFONT_ATLAS_W * DEBUGFONT_ATLAS_H * 4); + Log_logWarning("PS3Overlay: failed to allocate %d bytes for the font atlas\n", DEBUGFONT_ATLAS_W * DEBUGFONT_ATLAS_H * 4); return; } diff --git a/src/ps3/ps3_textures.c b/src/ps3/ps3_textures.c index b05cbc474..7e57361c8 100644 --- a/src/ps3/ps3_textures.c +++ b/src/ps3/ps3_textures.c @@ -44,7 +44,7 @@ bool PS3Textures_init(const char* texturesBinPath) { gFp = fopen(texturesBinPath, "rb"); if (gFp == NULL) { - fprintf(stderr, "PS3Textures: cannot open %s\n", texturesBinPath); + Log_logWarning("PS3Textures: cannot open %s\n", texturesBinPath); return false; } @@ -52,7 +52,7 @@ bool PS3Textures_init(const char* texturesBinPath) { uint8_t headerBuf[7]; if (fread(headerBuf, 1, 7, gFp) != 7) goto fail; if (headerBuf[0] != 0) { - fprintf(stderr, "PS3Textures: unsupported version %u\n", headerBuf[0]); + Log_logWarning("PS3Textures: unsupported version %u\n", headerBuf[0]); goto fail; } gClutCount = readU16BE(headerBuf + 1); @@ -63,7 +63,7 @@ bool PS3Textures_init(const char* texturesBinPath) { size_t clutBytes = (size_t) gClutCount * 256 * 4; uint8_t* clutBuf = (uint8_t*) malloc(clutBytes); if (clutBuf == NULL) { - fprintf(stderr, "PS3Textures: malloc(%zu) for CLUT failed\n", clutBytes); + Log_logWarning("PS3Textures: malloc(%zu) for CLUT failed\n", clutBytes); goto fail; } if (fread(clutBuf, 1, clutBytes, gFp) != clutBytes) { @@ -112,7 +112,7 @@ bool PS3Textures_init(const char* texturesBinPath) { // Pixel block starts here. Pages are streamed from disk on demand. gPixelBlockBase = ftell(gFp); - fprintf(stderr, "PS3Textures: opened %s (clutCount=%u pages=%u tpags=%u, streaming pixels)\n", texturesBinPath, gClutCount, gPageCount, gTpagCount); + Log_logWarning("PS3Textures: opened %s (clutCount=%u pages=%u tpags=%u, streaming pixels)\n", texturesBinPath, gClutCount, gPageCount, gTpagCount); gInitialized = true; return true; @@ -152,7 +152,7 @@ bool PS3Textures_loadPage(uint32_t pageId, int* outW, int* outH, uint8_t** outPi uint8_t* buf = (uint8_t*) malloc(h->pixelDataSize); if (buf == NULL) { - fprintf(stderr, "PS3Textures: malloc(%u) for page %u failed\n", h->pixelDataSize, pageId); + Log_logWarning("PS3Textures: malloc(%u) for page %u failed\n", h->pixelDataSize, pageId); return false; } diff --git a/src/runner.c b/src/runner.c index a147ced1d..0f0f73ed5 100644 --- a/src/runner.c +++ b/src/runner.c @@ -59,7 +59,7 @@ void Runner_updateCameraViewSimple(GMLCamera* camera) { Matrix4f projectionMatrix; Matrix4f_Orthographic(&projectionMatrix, (float) camera->viewWidth, -((float) camera->viewHeight), 32000.0, 0.0); - + camera->viewMatrix = viewMatrix; camera->projectionMatrix = projectionMatrix; @@ -394,9 +394,9 @@ static void Runner_executeResolvedEvent(Runner* runner, Instance* instance, int3 if (shouldTrace) { if (eventType == EVENT_ALARM) { - fprintf(stderr, "Runner: [%s] %s %d (instanceId=%d)\n", objectName, eventName, eventSubtype, instance->instanceId); + Log_log("Runner: [%s] %s %d (instanceId=%d)\n", objectName, eventName, eventSubtype, instance->instanceId); } else { - fprintf(stderr, "Runner: [%s] %s (instanceId=%d)\n", objectName, eventName, instance->instanceId); + Log_log("Runner: [%s] %s (instanceId=%d)\n", objectName, eventName, instance->instanceId); } } } @@ -687,7 +687,7 @@ void Runner_drawTileLayer(Runner* runner, RoomLayerTilesData* data, float layerO bool rotate = (cell & GMS2_TILE_ROTATE_MASK) != 0; if (rotate && !rotateWarned) { - fprintf(stderr, "Runner: WARNING: GMS2 tile layer has rotated tiles; rotation not yet implemented, drawing unrotated\n"); + Log_logWarning("Runner: WARNING: GMS2 tile layer has rotated tiles; rotation not yet implemented, drawing unrotated\n"); rotateWarned = true; } @@ -881,14 +881,14 @@ void Runner_draw(Runner* runner) { int32_t tpagIndex = Renderer_resolveObjectTPAGIndex(dataWin, tile); if (tpagIndex >= 0) { TexturePageItem* tpag = &dataWin->tpag.items[tpagIndex]; - fprintf(stderr, "Runner: [%s] Drawing tile #%d bg=%s(%d) tpag(srcX=%d srcY=%d srcW=%d srcH=%d tgtX=%d tgtY=%d bndW=%d bndH=%d page=%d) tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tpag->sourceX, tpag->sourceY, tpag->sourceWidth, tpag->sourceHeight, tpag->targetX, tpag->targetY, tpag->boundingWidth, tpag->boundingHeight, tpag->texturePageId, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); + Log_log("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag(srcX=%d srcY=%d srcW=%d srcH=%d tgtX=%d tgtY=%d bndW=%d bndH=%d page=%d) tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tpag->sourceX, tpag->sourceY, tpag->sourceWidth, tpag->sourceHeight, tpag->targetX, tpag->targetY, tpag->boundingWidth, tpag->boundingHeight, tpag->texturePageId, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); // Warn if tile source rect exceeds TPAG content bounds if ((uint32_t) (tile->sourceX + tile->width) > (uint32_t) tpag->sourceWidth || (uint32_t) (tile->sourceY + tile->height) > (uint32_t) tpag->sourceHeight) { - fprintf(stderr, "Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); + Log_logWarning("Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); } } else { - fprintf(stderr, "Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); + Log_log("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); } } } @@ -915,14 +915,14 @@ void Runner_draw(Runner* runner) { Instance* savedInstance = ctx->currentInstance; int32_t savedEventType = ctx->currentEventType; int32_t savedEventSubtype = ctx->currentEventSubtype; - + ctx->currentInstance = ctx->globalScopeInstance; ctx->currentEventType = EVENT_DRAW; ctx->currentEventSubtype = DRAW_NORMAL; - + if (runtimeLayer->beginScript >= 0) VM_callCodeIndex(ctx, runtimeLayer->beginScript, nullptr, 0); - + ctx->currentInstance = savedInstance; ctx->currentEventType = savedEventType; ctx->currentEventSubtype = savedEventSubtype; @@ -983,14 +983,14 @@ void Runner_draw(Runner* runner) { int32_t tpagIndex = Renderer_resolveObjectTPAGIndex(dataWin, tile); if (tpagIndex >= 0) { TexturePageItem* tpag = &dataWin->tpag.items[tpagIndex]; - fprintf(stderr, "Runner: [%s] Drawing tile #%d bg=%s(%d) tpag(srcX=%d srcY=%d srcW=%d srcH=%d tgtX=%d tgtY=%d bndW=%d bndH=%d page=%d) tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tpag->sourceX, tpag->sourceY, tpag->sourceWidth, tpag->sourceHeight, tpag->targetX, tpag->targetY, tpag->boundingWidth, tpag->boundingHeight, tpag->texturePageId, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); + Log_log("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag(srcX=%d srcY=%d srcW=%d srcH=%d tgtX=%d tgtY=%d bndW=%d bndH=%d page=%d) tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tpag->sourceX, tpag->sourceY, tpag->sourceWidth, tpag->sourceHeight, tpag->targetX, tpag->targetY, tpag->boundingWidth, tpag->boundingHeight, tpag->texturePageId, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); // Warn if tile source rect exceeds TPAG content bounds if ((uint32_t) (tile->sourceX + tile->width) > (uint32_t) tpag->sourceWidth || (uint32_t) (tile->sourceY + tile->height) > (uint32_t) tpag->sourceHeight) { - fprintf(stderr, "Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); + Log_logWarning("Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); } } else { - fprintf(stderr, "Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); + Log_log("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); } } } @@ -1031,10 +1031,10 @@ void Runner_draw(Runner* runner) { ctx->currentInstance = ctx->globalScopeInstance; ctx->currentEventType = EVENT_DRAW; ctx->currentEventSubtype = DRAW_NORMAL; - + if (runtimeLayer->endScript >= 0) VM_callCodeIndex(ctx, runtimeLayer->endScript, nullptr, 0); - + ctx->currentInstance = savedInstance; ctx->currentEventType = savedEventType; ctx->currentEventSubtype = savedEventSubtype; @@ -1288,7 +1288,7 @@ static Instance* createAndInitInstance(Runner* runner, int32_t instanceId, int32 #ifdef ENABLE_VM_TRACING if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, objDef->name) != -1) { - fprintf(stderr, "VM: Instance %s (instanceId=%d,objectIndex=%d) created at (%f, %f)\n", objDef->name, instanceId, inst->objectIndex, x, y); + Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) created at (%f, %f)\n", objDef->name, instanceId, inst->objectIndex, x, y); } #endif @@ -1308,7 +1308,7 @@ static Instance** takePersistentInstances(Runner* runner) { #ifdef ENABLE_VM_TRACING GameObject* gameObject = &runner->dataWin->objt.objects[inst->objectIndex]; if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, gameObject->name) != -1) { - fprintf(stderr, "VM: Instance %s (instanceId=%d,objectIndex=%d) has been persisted at (%f, %f) due to room change\n", gameObject->name, inst->instanceId, inst->objectIndex, inst->x, inst->y); + Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) has been persisted at (%f, %f) due to room change\n", gameObject->name, inst->instanceId, inst->objectIndex, inst->x, inst->y); } #endif @@ -1321,7 +1321,7 @@ static Instance** takePersistentInstances(Runner* runner) { #ifdef ENABLE_VM_TRACING GameObject* gameObject = &runner->dataWin->objt.objects[inst->objectIndex]; if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, gameObject->name) != -1) { - fprintf(stderr, "VM: Instance %s (instanceId=%d,objectIndex=%d) destroyed at (%f, %f) due to room change\n", gameObject->name, inst->instanceId, inst->objectIndex, inst->x, inst->y); + Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) destroyed at (%f, %f) due to room change\n", gameObject->name, inst->instanceId, inst->objectIndex, inst->x, inst->y); } #endif @@ -1467,7 +1467,7 @@ static void initRoom(Runner* runner, int32_t roomIndex) { returnPersistentInstances(runner, carriedPersistent); // No Create events, no preCreateCode, no creationCode, no room creation code - fprintf(stderr, "Runner: Room restored (persistent): %s (room %d) with %d instances\n", room->name, roomIndex, (int) arrlen(runner->instances)); + Log_log("Runner: Room restored (persistent): %s (room %d) with %d instances\n", room->name, roomIndex, (int) arrlen(runner->instances)); return; } @@ -1674,7 +1674,7 @@ static void initRoom(Runner* runner, int32_t roomIndex) { RoomGameObject* roomObj = &room->gameObjects[i]; if (roomObj->objectDefinition == -1) { - fprintf(stderr, "Runner: Object %d in room %s does not have a valid object definition reference! Was it deleted in the editor?\n", roomObj->instanceID, room->name); + Log_logWarning("Runner: Object %d in room %s does not have a valid object definition reference! Was it deleted in the editor?\n", roomObj->instanceID, room->name); continue; } @@ -1752,7 +1752,7 @@ static void initRoom(Runner* runner, int32_t roomIndex) { // Mark this room as initialized for persistent room support savedState->initialized = true; - fprintf(stderr, "Runner: Room loaded: %s (room %d) with %d instances\n", room->name, roomIndex, (int) arrlen(runner->instances)); + Log_log("Runner: Room loaded: %s (room %d) with %d instances\n", room->name, roomIndex, (int) arrlen(runner->instances)); } // Cleans up the runner state, used when freeing the Runner or when restarting the Runner @@ -2256,7 +2256,7 @@ Runner* Runner_create(DataWin* dataWin, VMContext* vm, Renderer* renderer, FileS repeat(shlen(vm->builtinMap), i) { bool isRegistered = shgeti(vm->codeIndexByName, vm->builtinMap[i].key) != -1; if (isRegistered) { - fprintf(stderr, "Runner: Builtin function %s has the same name as a GML script! The script may be a compatibility script provided by GM:S 2+, and the game may have issues due to the builtin overriding it!\n", vm->builtinMap[i].key); + Log_logWarning("Runner: Builtin function %s has the same name as a GML script! The script may be a compatibility script provided by GM:S 2+, and the game may have issues due to the builtin overriding it!\n", vm->builtinMap[i].key); } } @@ -2308,7 +2308,7 @@ Instance* Runner_createInstanceWithLayer(Runner* runner, GMLReal x, GMLReal y, i if (isObjectDisabled(runner, objectIndex)) return nullptr; RuntimeLayer* rl = Runner_findRuntimeLayerById(runner, layerId); if (rl == nullptr) { - fprintf(stderr, "Runner: instance_create_layer: Layer ID %d not found!\n", layerId); + Log_logError("Runner: instance_create_layer: Layer ID %d not found!\n", layerId); return nullptr; } Instance* inst = createAndInitInstance(runner, runner->nextInstanceId++, objectIndex, x, y); @@ -2355,7 +2355,7 @@ void Runner_destroyInstance(MAYBE_UNUSED Runner* runner, Instance* inst, bool ru #ifdef ENABLE_VM_TRACING GameObject* gameObject = &runner->dataWin->objt.objects[inst->objectIndex]; if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, gameObject->name) != -1) { - fprintf(stderr, "VM: Instance %s (instanceId=%d,objectIndex=%d) destroyed\n", gameObject->name, inst->instanceId, inst->objectIndex); + Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) destroyed\n", gameObject->name, inst->instanceId, inst->objectIndex); } #endif } @@ -2503,7 +2503,7 @@ void Runner_initFirstRoom(Runner* runner) { repeat(dataWin->glob.count, i) { int32_t codeId = dataWin->glob.codeIds[i]; if (codeId >= 0 && dataWin->code.count > (uint32_t) codeId) { - fprintf(stderr, "Runner: Executing global init script: %s\n", dataWin->code.entries[codeId].name); + Log_log("Runner: Executing global init script: %s\n", dataWin->code.entries[codeId].name); RValue result = VM_executeCode(runner->vmContext, codeId); RValue_free(&result); } @@ -2518,12 +2518,12 @@ void Runner_initFirstRoom(Runner* runner) { if (initScript == nullptr || initScript[0] == '\0') continue; int32_t scriptIndex = shget(runner->assetsByName, initScript); if (0 > scriptIndex || (uint32_t) scriptIndex >= dataWin->scpt.count) { - fprintf(stderr, "Runner: Extension init script '%s' not found, skipping\n", initScript); + Log_logWarning("Runner: Extension init script '%s' not found, skipping\n", initScript); continue; } int32_t codeId = dataWin->scpt.scripts[scriptIndex].codeId; if (codeId >= 0 && dataWin->code.count > (uint32_t) codeId) { - fprintf(stderr, "Runner: Executing extension init script: %s\n", initScript); + Log_log("Runner: Executing extension init script: %s\n", initScript); RValue result = VM_executeCode(runner->vmContext, codeId); RValue_free(&result); } @@ -2608,7 +2608,7 @@ static void executeCollisionEvent(Runner* runner, Instance* self, Instance* othe const char* targetName = runner->dataWin->objt.objects[targetObjectIndex].name; bool shouldTrace = shgeti(vm->eventsToBeTraced, "*") != -1 || shgeti(vm->eventsToBeTraced, "Collision") != -1 || shgeti(vm->eventsToBeTraced, selfName) != -1; if (shouldTrace) { - fprintf(stderr, "Runner: [%s] Collision with %s (instanceId=%d, otherId=%d)\n", selfName, targetName, self->instanceId, other->instanceId); + Log_log("Runner: [%s] Collision with %s (instanceId=%d, otherId=%d)\n", selfName, targetName, self->instanceId, other->instanceId); } } #endif @@ -3076,7 +3076,7 @@ static void dispatchCollisionEvents(Runner* runner) { #ifdef ENABLE_VM_TRACING bool traceThisPair = shouldTraceCollisionPair(runner->vmContext, dataWin, self, other); if (traceThisPair && (!bboxSelf.valid || !bboxOther.valid)) { - fprintf(stderr, "Collision: [%s id=%d] vs [%s id=%d] bbox-invalid (selfValid=%d otherValid=%d)\n", + Log_log("Collision: [%s id=%d] vs [%s id=%d] bbox-invalid (selfValid=%d otherValid=%d)\n", dataWin->objt.objects[self->objectIndex].name, self->instanceId, dataWin->objt.objects[other->objectIndex].name, other->instanceId, bboxSelf.valid, bboxOther.valid); @@ -3088,7 +3088,7 @@ static void dispatchCollisionEvents(Runner* runner) { bool aabbMiss = bboxSelf.left >= bboxOther.right || bboxOther.left >= bboxSelf.right || bboxSelf.top >= bboxOther.bottom || bboxOther.top >= bboxSelf.bottom; #ifdef ENABLE_VM_TRACING if (traceThisPair) { - fprintf(stderr, "Collision: [%s id=%d pos=(%g,%g)] vs [%s id=%d pos=(%g,%g)] selfBB=(%g,%g,%g,%g %gx%g) otherBB=(%g,%g,%g,%g %gx%g) selfSolid=%d otherSolid=%d AABB=%s\n", + Log_log("Collision: [%s id=%d pos=(%g,%g)] vs [%s id=%d pos=(%g,%g)] selfBB=(%g,%g,%g,%g %gx%g) otherBB=(%g,%g,%g,%g %gx%g) selfSolid=%d otherSolid=%d AABB=%s\n", dataWin->objt.objects[self->objectIndex].name, self->instanceId, self->x, self->y, dataWin->objt.objects[other->objectIndex].name, other->instanceId, other->x, other->y, bboxSelf.left, bboxSelf.top, bboxSelf.right, bboxSelf.bottom, bboxSelf.right - bboxSelf.left, bboxSelf.bottom - bboxSelf.top, @@ -3105,7 +3105,7 @@ static void dispatchCollisionEvents(Runner* runner) { if (needsPrecise) { bool preciseHit = Collision_instancesOverlapPrecise(runner, self, other, bboxSelf, bboxOther); #ifdef ENABLE_VM_TRACING - if (traceThisPair) fprintf(stderr, " precise=%s (selfSepMasks=%d otherSepMasks=%d)\n", preciseHit ? "hit" : "miss", sprSelf ? (int32_t)sprSelf->sepMasks : -1, sprOther ? (int32_t)sprOther->sepMasks : -1); + if (traceThisPair) Log_log(" precise=%s (selfSepMasks=%d otherSepMasks=%d)\n", preciseHit ? "hit" : "miss", sprSelf ? (int32_t)sprSelf->sepMasks : -1, sprOther ? (int32_t)sprOther->sepMasks : -1); #endif if (!preciseHit) continue; } @@ -3114,7 +3114,7 @@ static void dispatchCollisionEvents(Runner* runner) { bool hadSolid = self->solid || other->solid; if (hadSolid) { #ifdef ENABLE_VM_TRACING - if (traceThisPair) fprintf(stderr, " solid-restore: self.solid=%d other.solid=%d self=(%g,%g)->(%g,%g) other=(%g,%g)->(%g,%g)\n", self->solid, other->solid, self->x, self->y, self->xprevious, self->yprevious, other->x, other->y, other->xprevious, other->yprevious); + if (traceThisPair) Log_log(" solid-restore: self.solid=%d other.solid=%d self=(%g,%g)->(%g,%g) other=(%g,%g)->(%g,%g)\n", self->solid, other->solid, self->x, self->y, self->xprevious, self->yprevious, other->x, other->y, other->xprevious, other->yprevious); #endif self->x = self->xprevious; self->y = self->yprevious; @@ -3130,7 +3130,7 @@ static void dispatchCollisionEvents(Runner* runner) { // And if it DOES move via GML, the variable write handlers will set it to dirty #ifdef ENABLE_VM_TRACING - if (traceThisPair) fprintf(stderr, " fire self->other: subtype=%d (%s) owner=%d (%s) codeId=%d codeName=%s\n", targetObjIndex, dataWin->objt.objects[targetObjIndex].name, evt->ownerObjectIndex, dataWin->objt.objects[evt->ownerObjectIndex].name, evt->codeId, dataWin->code.entries[evt->codeId].name); + if (traceThisPair) Log_log(" fire self->other: subtype=%d (%s) owner=%d (%s) codeId=%d codeName=%s\n", targetObjIndex, dataWin->objt.objects[targetObjIndex].name, evt->ownerObjectIndex, dataWin->objt.objects[evt->ownerObjectIndex].name, evt->codeId, dataWin->code.entries[evt->codeId].name); #endif executeCollisionEvent(runner, self, other, targetObjIndex, evt->codeId, evt->ownerObjectIndex); @@ -3143,8 +3143,8 @@ static void dispatchCollisionEvents(Runner* runner) { FlattenedCollisionEvent* reverseEvt = findSymmetricCollisionEvent(runner, other, self); #ifdef ENABLE_VM_TRACING if (traceThisPair) { - if (reverseEvt != nullptr) fprintf(stderr, " fire other->self: subtype=%u (%s) owner=%d (%s) codeId=%d codeName=%s [symmetric]\n", reverseEvt->targetObjectIndex, dataWin->objt.objects[reverseEvt->targetObjectIndex].name, reverseEvt->ownerObjectIndex, dataWin->objt.objects[reverseEvt->ownerObjectIndex].name, reverseEvt->codeId, dataWin->code.entries[evt->codeId].name); - else fprintf(stderr, " fire other->self: none (no matching handler) [symmetric]\n"); + if (reverseEvt != nullptr) Log_log(" fire other->self: subtype=%u (%s) owner=%d (%s) codeId=%d codeName=%s [symmetric]\n", reverseEvt->targetObjectIndex, dataWin->objt.objects[reverseEvt->targetObjectIndex].name, reverseEvt->ownerObjectIndex, dataWin->objt.objects[reverseEvt->ownerObjectIndex].name, reverseEvt->codeId, dataWin->code.entries[evt->codeId].name); + else Log_log(" fire other->self: none (no matching handler) [symmetric]\n"); } #endif if (reverseEvt != nullptr) @@ -3187,7 +3187,7 @@ static void dispatchCollisionEvents(Runner* runner) { } if (stillColliding) { #ifdef ENABLE_VM_TRACING - if (traceThisPair) fprintf(stderr, " post-event re-revert: still colliding, restoring self=(%g,%g)->(%g,%g) other=(%g,%g)->(%g,%g)\n", self->x, self->y, self->xprevious, self->yprevious, other->x, other->y, other->xprevious, other->yprevious); + if (traceThisPair) Log_log(" post-event re-revert: still colliding, restoring self=(%g,%g)->(%g,%g) other=(%g,%g)->(%g,%g)\n", self->x, self->y, self->xprevious, self->yprevious, other->x, other->y, other->xprevious, other->yprevious); #endif self->x = self->xprevious; self->y = self->yprevious; @@ -3483,7 +3483,7 @@ void Runner_handlePendingRoomChange(Runner* runner) { require(runner->dataWin->room.count > (uint32_t) newRoomIndex); const char* newRoomName = runner->dataWin->room.rooms[newRoomIndex].name; - fprintf(stderr, "Room changed: %s (room %d) -> %s (room %d)\n", oldRoomName, oldRoomIndex, newRoomName, newRoomIndex); + Log_log("Room changed: %s (room %d) -> %s (room %d)\n", oldRoomName, oldRoomIndex, newRoomName, newRoomIndex); // If the old room is persistent, save its instance and visual state if (oldRoom->persistent) { @@ -3645,10 +3645,10 @@ void Runner_step(Runner* runner) { inst->imageIndex += inst->imageSpeed * sprite->gms2PlaybackSpeed; } else { inst->imageIndex += (1.0/runner->currentRoom->speed) * sprite->gms2PlaybackSpeed * inst->imageSpeed; - } + } } } else { - inst->imageIndex += inst->imageSpeed; + inst->imageIndex += inst->imageSpeed; } float frameCount = (float) sprite->textureCount; bool wrapped = false; @@ -3713,7 +3713,7 @@ void Runner_step(Runner* runner) { #ifdef ENABLE_VM_TRACING GameObject* object = &runner->dataWin->objt.objects[inst->objectIndex]; if (shgeti(runner->vmContext->alarmsToBeTraced, "*") != -1 || shgeti(runner->vmContext->alarmsToBeTraced, object->name) != -1) { - fprintf(stderr, "VM: [%s] Ticking down Alarm[%d] (instanceId=%d), current tick is %d\n", object->name, (int)alarmIdx, inst->instanceId, inst->alarm[alarmIdx]); + Log_log("VM: [%s] Ticking down Alarm[%d] (instanceId=%d), current tick is %d\n", object->name, (int)alarmIdx, inst->instanceId, inst->alarm[alarmIdx]); } #endif @@ -3724,7 +3724,7 @@ void Runner_step(Runner* runner) { #ifdef ENABLE_VM_TRACING if (shgeti(runner->vmContext->alarmsToBeTraced, "*") != -1 || shgeti(runner->vmContext->alarmsToBeTraced, object->name) != -1) { - fprintf(stderr, "VM: [%s] Firing Alarm[%d] (instanceId=%d)\n", object->name, (int)alarmIdx, inst->instanceId); + Log_log("VM: [%s] Firing Alarm[%d] (instanceId=%d)\n", object->name, (int)alarmIdx, inst->instanceId); } #endif @@ -4413,7 +4413,7 @@ void Runner_free(Runner* runner) { free(runner->flattenedCollisionEvents); runner->flattenedCollisionEvents = nullptr; } - + arrfree(runner->cachedDrawables); runner->cachedDrawables = nullptr; arrfree(runner->instanceSnapshots); diff --git a/src/runner.h b/src/runner.h index 78bbfaa87..b545dd18e 100644 --- a/src/runner.h +++ b/src/runner.h @@ -542,7 +542,7 @@ struct Runner { DsMapEntry** dsMapPool; // stb_ds array of stb_ds hashmaps DsList* dsListPool; // stb_ds array of DsList DsQueue* dsQueuePool; // stb_ds array of DsQueue - DsStack* dsStackPool; // stb_ds array of DsStack + DsStack* dsStackPool; // stb_ds array of DsStack DsPriority* dsPriorityPool; // stb_ds array of DsPriority DsGrid* dsGridPool; // stb_ds array of DsGrid GmlBuffer* gmlBufferPool; // stb_ds array of GmlBuffer @@ -722,7 +722,7 @@ static inline void Runner_setActiveState(Runner* runner, Instance* instance, boo GameObject* objDef = &runner->dataWin->objt.objects[instance->objectIndex]; if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, objDef->name) != -1) { - fprintf(stderr, "VM: Instance %s (instanceId=%d,objectIndex=%d) marked as %s at (%f, %f)\n", objDef->name, instance->instanceId, instance->objectIndex, active ? "active" : "inactive", instance->x, instance->y); + Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) marked as %s at (%f, %f)\n", objDef->name, instance->instanceId, instance->objectIndex, active ? "active" : "inactive", instance->x, instance->y); } } #else diff --git a/src/spatial_grid.c b/src/spatial_grid.c index e3f9a31f4..cc9584ebe 100644 --- a/src/spatial_grid.c +++ b/src/spatial_grid.c @@ -13,7 +13,7 @@ SpatialGrid* SpatialGrid_create(uint32_t roomWidth, uint32_t roomHeight) { uint32_t gridHeight = (roomHeight / SPATIAL_GRID_CELL_SIZE) + 1; #ifdef ENABLE_SPATIAL_GRID_LOGS - fprintf(stderr, "SpatialGrid: Grid size: %dx%d\n", gridWidth, gridHeight); + Log_log("SpatialGrid: Grid size: %dx%d\n", gridWidth, gridHeight); #endif grid->gridWidth = gridWidth; grid->gridHeight = gridHeight; @@ -53,7 +53,7 @@ void SpatialGrid_syncGrid(Runner* runner, SpatialGrid* grid) { if (!requiresResync) return; #ifdef ENABLE_SPATIAL_GRID_LOGS - fprintf(stderr, "SpatialGrid: Syncing grid with %d dirty instances\n", arrlen(grid->dirtyInstances)); + Log_log("SpatialGrid: Syncing grid with %d dirty instances\n", arrlen(grid->dirtyInstances)); #endif repeat(arrlen(grid->dirtyInstances), i) { diff --git a/src/vm.c b/src/vm.c index c7085f574..3c4251785 100644 --- a/src/vm.c +++ b/src/vm.c @@ -64,7 +64,7 @@ static void stackPush(VMContext* ctx, RValue val) { char* valStr = RValue_toStringTyped(val); ctx->stack.slots[ctx->stack.top++] = val; char* stackBuf = formatStackContents(ctx); - fprintf(stderr, "VM: [%s] PUSH %s [stack=%d -> %d] %s\n", ctx->currentCodeName, valStr, ctx->stack.top - 1, ctx->stack.top, stackBuf); + Log_log("VM: [%s] PUSH %s [stack=%d -> %d] %s\n", ctx->currentCodeName, valStr, ctx->stack.top - 1, ctx->stack.top, stackBuf); free(stackBuf); free(valStr); return; @@ -85,7 +85,7 @@ static RValue stackPop(VMContext* ctx) { if (shouldTraceStack(ctx)) { char* valStr = RValue_toStringTyped(val); char* stackBuf = formatStackContents(ctx); - fprintf(stderr, "VM: [%s] POP %s [stack=%d -> %d] %s\n", ctx->currentCodeName, valStr, ctx->stack.top + 1, ctx->stack.top, stackBuf); + Log_log("VM: [%s] POP %s [stack=%d -> %d] %s\n", ctx->currentCodeName, valStr, ctx->stack.top + 1, ctx->stack.top, stackBuf); free(stackBuf); free(valStr); } @@ -680,9 +680,9 @@ static RValue resolveVariableRead(VMContext* ctx, int32_t instanceType, uint32_t const char* varTypeName = varTypeToString((varRef >> 24) & 0xF8); if (instanceType < INSTANCE_ID_BASE && (uint32_t) instanceType < ctx->dataWin->objt.count) { GameObject* gameObject = &ctx->dataWin->objt.objects[instanceType]; - fprintf(stderr, "VM: [%s] READ var '%s' on object index %d (%s) but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, gameObject->name, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); + Log_logWarning("VM: [%s] READ var '%s' on object index %d (%s) but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, gameObject->name, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); } else { - fprintf(stderr, "VM: [%s] READ var '%s' on instance %d but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); + Log_logWarning("VM: [%s] READ var '%s' on instance %d but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); } return RValue_makeReal(0.0); } @@ -730,7 +730,7 @@ static RValue resolveVariableRead(VMContext* ctx, int32_t instanceType, uint32_t result = RValue_makeUndefined(); } } else { - fprintf(stderr, "VM: [%s] INSTANCE_ARG read on unknown variable '%s' (builtinVarId=%d)\n", ctx->currentCodeName, varDef->name, builtinVarId); + Log_logWarning("VM: [%s] INSTANCE_ARG read on unknown variable '%s' (builtinVarId=%d)\n", ctx->currentCodeName, varDef->name, builtinVarId); result = RValue_makeUndefined(); } return result; @@ -779,7 +779,7 @@ static RValue resolveVariableRead(VMContext* ctx, int32_t instanceType, uint32_t Instance* inst = targetInstance; if (inst == nullptr) { const char* varTypeName = varTypeToString((varRef >> 24) & 0xF8); - fprintf(stderr, "VM: [%s] Read on self var '%s' but no current instance (instanceType=%d, varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); + Log_logWarning("VM: [%s] Read on self var '%s' but no current instance (instanceType=%d, varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); return RValue_makeReal(0.0); } slot = IntRValueHashMap_findSlot(&inst->selfVars, varDef->varID); @@ -954,7 +954,7 @@ static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t if (ctx->dataWin->objt.count > (uint32_t) instanceType) { GameObject* gameObject = &ctx->dataWin->objt.objects[instanceType]; char* valAsString = RValue_toString(val); - fprintf(stderr, "VM: [%s] WRITE var '%s' on object %d (%s) but no instances found (value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, gameObject->name, valAsString); + Log_logWarning("VM: [%s] WRITE var '%s' on object %d (%s) but no instances found (value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, gameObject->name, valAsString); free(valAsString); } } @@ -969,7 +969,7 @@ static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t if (targetInstance == nullptr) { const char* varTypeName = varTypeToString((varRef >> 24) & 0xF8); char* valAsString = RValue_toString(val); - fprintf(stderr, "VM: [%s] WRITE var '%s' on instance %d but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID, valAsString); + Log_logWarning("VM: [%s] WRITE var '%s' on instance %d but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID, valAsString); free(valAsString); return; } @@ -986,7 +986,7 @@ static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t } else if (bid == BUILTIN_VAR_ARGUMENT) { writeIndex = access.arrayIndex; } else { - fprintf(stderr, "VM: [%s] INSTANCE_ARG write on unknown variable '%s' (builtinVarId=%d)\n", ctx->currentCodeName, varDef->name, bid); + Log_logWarning("VM: [%s] INSTANCE_ARG write on unknown variable '%s' (builtinVarId=%d)\n", ctx->currentCodeName, varDef->name, bid); } if (writeIndex >= 0) { VM_writeToScriptArgs(ctx, writeIndex, val); @@ -1031,7 +1031,7 @@ static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t if (inst == nullptr) { const char* varTypeName = varTypeToString((varRef >> 24) & 0xF8); char* valAsString = RValue_toString(val); - fprintf(stderr, "VM: [%s] Write on self var '%s' but no current instance (instanceType=%d, varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID, valAsString); + Log_logWarning("VM: [%s] Write on self var '%s' but no current instance (instanceType=%d, varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID, valAsString); free(valAsString); RValue_free(&val); return; @@ -1106,7 +1106,7 @@ static RValue convertValue(RValue val, uint8_t targetType) { // Variable type on stack is just an RValue passthrough return val; default: - fprintf(stderr, "VM: Unknown target type 0x%X for conversion\n", targetType); + Log_logWarning("VM: Unknown target type 0x%X for conversion\n", targetType); return val; } } @@ -1175,7 +1175,7 @@ static void handlePush(VMContext* ctx, uint32_t instr, const uint8_t* extraData, // Positive scopes are real instance IDs resolved by lookup. Instance* inst = (0 > scope) ? (Instance*) ctx->currentInstance : VM_findInstanceByTarget(ctx, scope); if (inst == nullptr) { - fprintf(stderr, "VM: ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); + Log_logWarning("VM: ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); abort(); } slot = IntRValueHashMap_getOrInsertUndefined(&inst->selfVars, varDef->varID); @@ -1229,7 +1229,7 @@ static void handlePush(VMContext* ctx, uint32_t instr, const uint8_t* extraData, break; } default: - fprintf(stderr, "VM: Push with unknown type 0x%X\n", type1); + Log_logWarning("VM: Push with unknown type 0x%X\n", type1); abort(); } } @@ -1270,7 +1270,7 @@ static void handlePushBltn(VMContext* ctx, uint32_t instr, const uint8_t* extraD inst = (Instance*) ctx->currentInstance; } if (inst == nullptr) { - fprintf(stderr, "VM: PushBltn ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); + Log_logWarning("VM: PushBltn ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); abort(); } RValue* slot = IntRValueHashMap_getOrInsertUndefined(&inst->selfVars, varDef->varID); @@ -1427,9 +1427,9 @@ static void handlePop(VMContext* ctx, uint8_t type1, uint8_t type2, uint32_t var const char* varTypeName = varTypeToString(varType); char* valAsString = RValue_toString(val); if (instanceType < INSTANCE_ID_BASE && (uint32_t) instanceType < ctx->dataWin->objt.count) { - fprintf(stderr, "VM: [%s] WRITE array var '%s[%d]' on object index %d (%s) but no instance found (varType=%s, originalInstanceType=%d, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, arrayIndex, instanceType, ctx->dataWin->objt.objects[instanceType].name, varTypeName, originalInstanceType, varDef->varID, valAsString); + Log_logWarning("VM: [%s] WRITE array var '%s[%d]' on object index %d (%s) but no instance found (varType=%s, originalInstanceType=%d, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, arrayIndex, instanceType, ctx->dataWin->objt.objects[instanceType].name, varTypeName, originalInstanceType, varDef->varID, valAsString); } else { - fprintf(stderr, "VM: [%s] WRITE array var '%s[%d]' on instance %d but no instance found (varType=%s, originalInstanceType=%d, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, arrayIndex, instanceType, varTypeName, originalInstanceType, varDef->varID, valAsString); + Log_logWarning("VM: [%s] WRITE array var '%s[%d]' on instance %d but no instance found (varType=%s, originalInstanceType=%d, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, arrayIndex, instanceType, varTypeName, originalInstanceType, varDef->varID, valAsString); } free(valAsString); RValue_free(&val); @@ -1700,7 +1700,7 @@ static void handleConv(VMContext* ctx, uint8_t srcType, uint8_t dstType, uint8_t case 0x5F: result = val; break; default: - fprintf(stderr, "VM: [%s] Conv unhandled conversion 0x%02X (src=0x%X dst=0x%X)\n", ctx->currentCodeName, convKey, srcType, dstType); + Log_logWarning("VM: [%s] Conv unhandled conversion 0x%02X (src=0x%X dst=0x%X)\n", ctx->currentCodeName, convKey, srcType, dstType); result = val; break; } @@ -1960,7 +1960,7 @@ static void handleCall(VMContext* ctx, uint32_t instr, const uint8_t* extraData) free(display); } - fprintf(stderr, "VM: [%s] Calling function \"%s(%s)\"\n", ctx->currentCodeName, funcName, functionArgumentList); + Log_log("VM: [%s] Calling function \"%s(%s)\"\n", ctx->currentCodeName, funcName, functionArgumentList); } #endif @@ -1982,7 +1982,7 @@ static void handleCall(VMContext* ctx, uint32_t instr, const uint8_t* extraData) #ifdef ENABLE_VM_TRACING if (functionIsBeingTraced) { char* returnValueAsString = RValue_toStringFancy(result); - fprintf(stderr, "VM: [%s] Built-in function \"%s(%s)\" returned %s\n", ctx->currentCodeName, funcName, functionArgumentList, returnValueAsString); + Log_log("VM: [%s] Built-in function \"%s(%s)\" returned %s\n", ctx->currentCodeName, funcName, functionArgumentList, returnValueAsString); free(returnValueAsString); free(functionArgumentList); } @@ -1999,7 +1999,7 @@ static void handleCall(VMContext* ctx, uint32_t instr, const uint8_t* extraData) #ifdef ENABLE_VM_TRACING if (functionIsBeingTraced) { char* returnValueAsString = RValue_toStringFancy(result); - fprintf(stderr, "VM: [%s] Script function \"%s(%s)\" returned %s\n", ctx->currentCodeName, funcName, functionArgumentList, returnValueAsString); + Log_log("VM: [%s] Script function \"%s(%s)\" returned %s\n", ctx->currentCodeName, funcName, functionArgumentList, returnValueAsString); free(returnValueAsString); free(functionArgumentList); } @@ -2027,7 +2027,7 @@ static void handleCall(VMContext* ctx, uint32_t instr, const uint8_t* extraData) if (ctx->alwaysLogUnknownFunctions || 0 > shgeti(ctx->loggedUnknownFuncs, dedupKey)) { shput(ctx->loggedUnknownFuncs, dedupKey, true); - fprintf(stderr, "VM: [%s] Unknown function \"%s\"!\n", callerName, unknownFuncName); + Log_logWarning("VM: [%s] Unknown function \"%s\"!\n", callerName, unknownFuncName); } else { free(dedupKey); } @@ -2114,14 +2114,14 @@ static void handleCallV(VMContext* ctx, uint32_t instr) { char* dedupKey = VM_createDedupKey(callerName, unresolvedName); if (ctx->alwaysLogUnknownFunctions || 0 > shgeti(ctx->loggedUnknownFuncs, dedupKey)) { shput(ctx->loggedUnknownFuncs, dedupKey, true); - fprintf(stderr, "VM: [%s] Unknown function \"%s\"! (via CallV)\n", callerName, unresolvedName); + Log_logWarning("VM: [%s] Unknown function \"%s\"! (via CallV)\n", callerName, unresolvedName); } else { free(dedupKey); } #endif result = RValue_makeUndefined(); } else { - fprintf(stderr, "VM: [%s] CALLV with unresolvable function reference (type=%d, codeIndex=%d)\n", ctx->currentCodeName, function.type, codeIndex); + Log_logWarning("VM: [%s] CALLV with unresolvable function reference (type=%d, codeIndex=%d)\n", ctx->currentCodeName, function.type, codeIndex); #ifdef ENABLE_WAD17 VMException* exception = (VMException *)safeCalloc(1, sizeof(VMException)); exception->message = safeStrdup("CALLV with unresolvable function reference"); @@ -2312,9 +2312,9 @@ static void handlePushEnv(VMContext* ctx, uint32_t instr, uint32_t instrAddr) { } if (0 > target) { - fprintf(stderr, "VM: [%s] PushEnv with negative target %d, this could be a Int64 number that is getting truncated to Int32!\n", ctx->currentCodeName, target); + Log_logWarning("VM: [%s] PushEnv with negative target %d, this could be a Int64 number that is getting truncated to Int32!\n", ctx->currentCodeName, target); } else { - fprintf(stderr, "VM: [%s] PushEnv with unhandled target %d\n", ctx->currentCodeName, target); + Log_logWarning("VM: [%s] PushEnv with unhandled target %d\n", ctx->currentCodeName, target); } ctx->ip = instrAddr + jumpOffset; } @@ -2463,17 +2463,17 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { entries[j] = tmp; } - fprintf(stderr, "=== Opcode Profiler Report ===\n"); - fprintf(stderr, "Total instructions executed: %llu\n", (unsigned long long) total); - fprintf(stderr, "%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); + Log_log("=== Opcode Profiler Report ===\n"); + Log_log("Total instructions executed: %llu\n", (unsigned long long) total); + Log_logToFile("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); forEachIndexed(CountEntry, entry, i, entries, entryCount) { (void) i; double pct = total > 0 ? (100.0 * (double) entry->count / (double) total) : 0.0; - fprintf(stderr, "%-12s 0x%02X %16llu %7.2f%%\n", opcodeName((uint8_t) entry->key), (uint8_t) entry->key, (unsigned long long) entry->count, pct); + Log_log("%-12s 0x%02X %16llu %7.2f%%\n", opcodeName((uint8_t) entry->key), (uint8_t) entry->key, (unsigned long long) entry->count, pct); } // Per-opcode breakdown by type variant. Sorted within each opcode by count desc. - fprintf(stderr, "\n--- Type variant breakdown (per opcode) ---\n"); + Log_log("\n--- Type variant breakdown (per opcode) ---\n"); forEachIndexed(CountEntry, entry, idx, entries, entryCount) { (void) idx; uint8_t opcode = (uint8_t) entry->key; @@ -2498,13 +2498,13 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { variantEntries[j] = tmp; } - fprintf(stderr, "%s (0x%02X): %llu total\n", opcodeName(opcode), opcode, (unsigned long long) entry->count); + Log_log("%s (0x%02X): %llu total\n", opcodeName(opcode), opcode, (unsigned long long) entry->count); forEachIndexed(CountEntry, ve, vi, variantEntries, variantCount) { (void) vi; uint8_t type1 = (uint8_t) ((ve->key >> 4) & 0xF); uint8_t type2 = (uint8_t) (ve->key & 0xF); double vpct = entry->count > 0 ? (100.0 * (double) ve->count / (double) entry->count) : 0.0; - fprintf(stderr, " .%c.%c %16llu %7.2f%%\n", gmlTypeChar(type1), gmlTypeChar(type2), (unsigned long long) ve->count, vpct); + Log_log(" .%c.%c %16llu %7.2f%%\n", gmlTypeChar(type1), gmlTypeChar(type2), (unsigned long long) ve->count, vpct); } // Runtime RValue type breakdown (a, b types observed at execution time) @@ -2531,13 +2531,13 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { } rvEntries[j] = tmp; } - fprintf(stderr, " -- runtime types (a, b):\n"); + Log_log(" -- runtime types (a, b):\n"); forEachIndexed(CountEntry, re, ri, rvEntries, rvCount) { (void) ri; uint8_t typeA = (uint8_t) ((re->key >> 4) & 0xF); uint8_t typeB = (uint8_t) (re->key & 0xF); double rpct = rvTotal > 0 ? (100.0 * (double) re->count / (double) rvTotal) : 0.0; - fprintf(stderr, " (%-6s, %-6s) %16llu %7.2f%%\n", rvalueTypeName(typeA), rvalueTypeName(typeB), (unsigned long long) re->count, rpct); + Log_log(" (%-6s, %-6s) %16llu %7.2f%%\n", rvalueTypeName(typeA), rvalueTypeName(typeB), (unsigned long long) re->count, rpct); } } } @@ -2562,16 +2562,16 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { } breakEntries[j] = tmp; } - fprintf(stderr, " -- sub-opcodes:\n"); + Log_log(" -- sub-opcodes:\n"); forEachIndexed(CountEntry, be, bi, breakEntries, breakCount) { (void) bi; int16_t breakType = (int16_t) -((int) be->key); double bpct = entry->count > 0 ? (100.0 * (double) be->count / (double) entry->count) : 0.0; - fprintf(stderr, " %-12s (%4d) %16llu %7.2f%%\n", breakSubOpName(breakType), (int) breakType, (unsigned long long) be->count, bpct); + Log_log(" %-12s (%4d) %16llu %7.2f%%\n", breakSubOpName(breakType), (int) breakType, (unsigned long long) be->count, bpct); } } } - fprintf(stderr, "==============================\n"); + Log_log("==============================\n"); } #endif // ENABLE_VM_OPCODE_PROFILER @@ -2586,7 +2586,7 @@ static void handleBreakChkIndex(VMContext* ctx, uint32_t instrAddr) { RValue* top = stackPeek(ctx); int32_t idx = RValue_toInt32(*top); if (0 > idx || 32000 <= idx) { - fprintf(stderr, "VM: chkindex out of bounds: %d at offset %u in %s\n", idx, instrAddr, ctx->currentCodeName); + Log_logWarning("VM: chkindex out of bounds: %d at offset %u in %s\n", idx, instrAddr, ctx->currentCodeName); abort(); } } @@ -2629,7 +2629,7 @@ static void handleBreakPushAC(VMContext* ctx, uint32_t instrAddr) { int32_t idx = stackPopInt32(ctx); RValue arrayRef = stackPop(ctx); if (arrayRef.type != RVALUE_ARRAY || arrayRef.array == nullptr) { - fprintf(stderr, "VM: pushac on non-array (type=%d) at offset %u in %s\n", arrayRef.type, instrAddr, ctx->currentCodeName); + Log_logWarning("VM: pushac on non-array (type=%d) at offset %u in %s\n", arrayRef.type, instrAddr, ctx->currentCodeName); abort(); } GMLArray* parent = arrayRef.array; @@ -2740,7 +2740,7 @@ static void handleBreak(VMContext* ctx, uint32_t instr, uint32_t instrAddr, cons case BREAK_ISNULLISH: handleBreakIsNullish(ctx); break; case BREAK_PUSHREF: handleBreakPushRef(ctx, extraData); break; default: - fprintf(stderr, "VM: Unknown BREAK sub-opcode %d at offset %u in %s\n", breakType, instrAddr, ctx->currentCodeName); + Log_logWarning("VM: Unknown BREAK sub-opcode %d at offset %u in %s\n", breakType, instrAddr, ctx->currentCodeName); abort(); } } @@ -2780,11 +2780,11 @@ static RValue executeLoop(VMContext* ctx) { #ifdef ENABLE_WAD17 if (ctx->exception != nullptr) { #ifdef ENABLE_VM_EXCEPTIONS_LOGS - fprintf(stderr, "VM: Exception thrown! Stack Top is %d\n", ctx->exceptionHandlerStackTop); + Log_logError("VM: Exception thrown! Stack Top is %d\n", ctx->exceptionHandlerStackTop); #endif if (ctx->exceptionHandlerStackTop == 0) { // TODO: When Butterscotch is better, we could have a strict mode that DOES throw a error - fprintf(stderr, "VM: The exception handler frame stack is 0, but we have a pending exception to be dispatched! This would've technically crashed the game in the original runner... or we aren't handling exceptions correctly. We'll swallow the exception and hope for the best... (Exception: %s)\n", ctx->exception->message); + Log_logError("VM: The exception handler frame stack is 0, but we have a pending exception to be dispatched! This would've technically crashed the game in the original runner... or we aren't handling exceptions correctly. We'll swallow the exception and hope for the best... (Exception: %s)\n", ctx->exception->message); free(ctx->exception->message); free(ctx->exception); ctx->exception = nullptr; @@ -2797,7 +2797,7 @@ static RValue executeLoop(VMContext* ctx) { // Not for us, propagate the exception! if (exceptionHandlerFrame->boundToCallDepth != ctx->callDepth) { #ifdef ENABLE_VM_EXCEPTIONS_LOGS - fprintf(stderr, "VM: We wanted %d but we are %d - Propagating...\n", exceptionHandlerFrame->boundToCallDepth, ctx->callDepth); + Log_logWarning("VM: We wanted %d but we are %d - Propagating...\n", exceptionHandlerFrame->boundToCallDepth, ctx->callDepth); #endif return RValue_makeUndefined(); } @@ -2810,7 +2810,7 @@ static RValue executeLoop(VMContext* ctx) { VM_SYNC_IP(); #ifdef ENABLE_VM_EXCEPTIONS_LOGS - fprintf(stderr, "VM: Jumped to %d due to exception handler, is this a exception? %d\n", ip, isException); + Log_logWarning("VM: Jumped to %d due to exception handler, is this a exception? %d\n", ip, isException); #endif if (isException) { @@ -2892,9 +2892,9 @@ static RValue executeLoop(VMContext* ctx) { char* stackBuf = formatStackContents(ctx); if (operandStr[0] != '\0') { - fprintf(stderr, "VM: [%s] @%04X (%d) [0x%08X] %s %s [stack=%d] %s\n", ctx->currentCodeName, instrAddr, instrAddr, instr, opcodeStr, operandStr, ctx->stack.top, stackBuf); + Log_log("VM: [%s] @%04X (%d) [0x%08X] %s %s [stack=%d] %s\n", ctx->currentCodeName, instrAddr, instrAddr, instr, opcodeStr, operandStr, ctx->stack.top, stackBuf); } else { - fprintf(stderr, "VM: [%s] @%04X (%d) [0x%08X] %s [stack=%d] %s\n", ctx->currentCodeName, instrAddr, instrAddr, instr, opcodeStr, ctx->stack.top, stackBuf); + Log_log("VM: [%s] @%04X (%d) [0x%08X] %s [stack=%d] %s\n", ctx->currentCodeName, instrAddr, instrAddr, instr, opcodeStr, ctx->stack.top, stackBuf); } free(stackBuf); } @@ -3294,7 +3294,7 @@ static RValue executeLoop(VMContext* ctx) { break; default: - fprintf(stderr, "VM: Unknown opcode 0x%02X at offset %u\n", opcode, instrAddr); + Log_logWarning("VM: Unknown opcode 0x%02X at offset %u\n", opcode, instrAddr); abort(); } } @@ -3576,7 +3576,7 @@ VMContext* VM_create(DataWin* dataWin) { } } - fprintf(stderr, "VM: Initialized with %u functions mapped\n", (uint32_t) shlen(ctx->codeIndexByName)); + Log_log("VM: Initialized with %u functions mapped\n", (uint32_t) shlen(ctx->codeIndexByName)); return ctx; } @@ -3643,7 +3643,7 @@ void VM_reset(VMContext* ctx) { } #endif - fprintf(stderr, "VM: Reset complete\n"); + Log_log("VM: Reset complete\n"); } static CodeLocals* resolveCodeLocals(VMContext* ctx, const char* codeName) { diff --git a/src/vm.h b/src/vm.h index 2fa33b73e..41fdfc0e1 100644 --- a/src/vm.h +++ b/src/vm.h @@ -402,7 +402,7 @@ static inline void VM_checkIfVariableShouldBeTracedAndLog(VMContext* ctx, const if (arrayIndex >= 0) snprintf(indexBuf, sizeof(indexBuf), "[%d]", arrayIndex); char instanceIdBuf[28] = ""; if (instanceId >= 0) snprintf(instanceIdBuf, sizeof(instanceIdBuf), " (instanceId=%d)", instanceId); - fprintf(stderr, "VM: [%s] %s %s.%s%s %s %s%s%s\n", ctx->currentCodeName, verb, scopeName, name, indexBuf, arrow, rvalueAsString, instanceIdBuf, additional); + Log_log("VM: [%s] %s %s.%s%s %s %s%s%s\n", ctx->currentCodeName, verb, scopeName, name, indexBuf, arrow, rvalueAsString, instanceIdBuf, additional); free(rvalueAsString); } #endif diff --git a/src/vm_builtins.c b/src/vm_builtins.c index ffd1c0b51..a60bc0fa5 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -107,7 +107,7 @@ static void logStubbedFunction(VMContext* ctx, const char* funcName) { if (ctx->alwaysLogStubbedFunctions || 0 > shgeti(ctx->loggedStubbedFuncs, dedupKey)) { // shput stores the key pointer, so don't free it when inserting shput(ctx->loggedStubbedFuncs, dedupKey, true); - fprintf(stderr, "VM: [%s] Stubbed function \"%s\"!\n", callerName, funcName); + Log_logWarning("VM: [%s] Stubbed function \"%s\"!\n", callerName, funcName); } else { free(dedupKey); } @@ -120,7 +120,7 @@ static void logSemiStubbedFunction(VMContext* ctx, const char* funcName) { if (ctx->alwaysLogStubbedFunctions || 0 > shgeti(ctx->loggedStubbedFuncs, dedupKey)) { // shput stores the key pointer, so don't free it when inserting shput(ctx->loggedStubbedFuncs, dedupKey, true); - fprintf(stderr, "VM: [%s] Semi-Stubbed function \"%s\"!\n", callerName, funcName); + Log_logWarning("VM: [%s] Semi-Stubbed function \"%s\"!\n", callerName, funcName); } else { free(dedupKey); } @@ -1259,7 +1259,7 @@ RValue VMBuiltins_getVariable(VMContext* ctx, Instance* inst, int16_t builtinVar break; } - fprintf(stderr, "VM: [%s] Unhandled built-in variable read '%s' (arrayIndex=%d)\n", ctx->currentCodeName, name, arrayIndex); + Log_logWarning("VM: [%s] Unhandled built-in variable read '%s' (arrayIndex=%d)\n", ctx->currentCodeName, name, arrayIndex); return RValue_makeReal(0.0); } @@ -1476,7 +1476,7 @@ void VMBuiltins_setVariable(VMContext* ctx, Instance* inst, int16_t builtinVarId #ifdef ENABLE_VM_TRACING if (inst->objectIndex >= 0 && (shgeti(ctx->alarmsToBeTraced, "*") != -1 || shgeti(ctx->alarmsToBeTraced, runner->dataWin->objt.objects[inst->objectIndex].name) != -1)) { - fprintf(stderr, "VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, arrayIndex, newValue, inst->instanceId); + Log_log("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, arrayIndex, newValue, inst->instanceId); } #endif @@ -1770,18 +1770,18 @@ void VMBuiltins_setVariable(VMContext* ctx, Instance* inst, int16_t builtinVarId case BUILTIN_VAR_DEBUG_MODE: case BUILTIN_VAR_ROOM_FIRST: case BUILTIN_VAR_ROOM_LAST: - fprintf(stderr, "VM: [%s] Attempted write to read-only built-in '%s'\n", ctx->currentCodeName, name); + Log_logWarning("VM: [%s] Attempted write to read-only built-in '%s'\n", ctx->currentCodeName, name); return; } - fprintf(stderr, "VM: [%s] Unhandled built-in variable write '%s' (arrayIndex=%d)\n", ctx->currentCodeName, name, arrayIndex); + Log_logWarning("VM: [%s] Unhandled built-in variable write '%s' (arrayIndex=%d)\n", ctx->currentCodeName, name, arrayIndex); } // ===[ BUILTIN FUNCTION IMPLEMENTATIONS ]=== static RValue builtin_show_debug_message(MAYBE_UNUSED VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - fprintf(stderr, "[show_debug_message] Expected at least 1 argument\n"); + Log_logError("[show_debug_message] Expected at least 1 argument\n"); return RValue_makeUndefined(); } @@ -3289,7 +3289,7 @@ static RValue builtin_room_goto_next(VMContext* ctx, MAYBE_UNUSED RValue* args, if ((int32_t) runner->dataWin->gen8.roomOrderCount > nextPos) { runner->pendingRoom = runner->dataWin->gen8.roomOrder[nextPos]; } else { - fprintf(stderr, "VM: room_goto_next - already at last room!\n"); + Log_logWarning("VM: room_goto_next - already at last room!\n"); } return RValue_makeUndefined(); } @@ -3301,7 +3301,7 @@ static RValue builtin_room_goto_previous(VMContext* ctx, MAYBE_UNUSED RValue* ar if (previousPos >= 0) { runner->pendingRoom = runner->dataWin->gen8.roomOrder[previousPos]; } else { - fprintf(stderr, "VM: room_goto_previous - already at first room!\n"); + Log_logWarning("VM: room_goto_previous - already at first room!\n"); } return RValue_makeUndefined(); } @@ -3638,7 +3638,7 @@ static RValue builtin_camera_set_view_angle(VMContext* ctx, RValue* args, int32_ if (2 > argCount) return RValue_makeUndefined(); Runner* runner = ctx->runner; GMLCamera* camera = Runner_getCameraById(runner, RValue_toInt32(args[0])); - if (camera != nullptr) { + if (camera != nullptr) { camera->viewAngle = (float) RValue_toReal(args[1]); Runner_updateCameraViewSimple(camera); } @@ -3706,7 +3706,7 @@ static RValue builtin_camera_create_view(VMContext* ctx, RValue* args, int32_t a if (argCount > 9) camera->borderY = (uint32_t) RValue_toInt32(args[9]); Runner_updateCameraViewSimple(camera); - + return RValue_makeReal(id); } @@ -4076,7 +4076,7 @@ static RValue builtin_script_execute(VMContext* ctx, RValue* args, int32_t argCo // Fallback: treat as SCPT index (BC16 and earlier, or when FUNC lookup failed) if (0 > codeId) { if (0 > rawArg || (uint32_t) rawArg >= ctx->dataWin->scpt.count) { - fprintf(stderr, "VM: script_execute - invalid script index %d\n", rawArg); + Log_logWarning("VM: script_execute - invalid script index %d\n", rawArg); return RValue_makeUndefined(); } codeId = ctx->dataWin->scpt.scripts[rawArg].codeId; @@ -4084,7 +4084,7 @@ static RValue builtin_script_execute(VMContext* ctx, RValue* args, int32_t argCo } if (0 > codeId || ctx->dataWin->code.count <= (uint32_t) codeId) { - fprintf(stderr, "VM: script_execute - invalid codeId %d\n", codeId); + Log_logWarning("VM: script_execute - invalid codeId %d\n", codeId); return RValue_makeUndefined(); } @@ -6577,7 +6577,7 @@ static RValue builtin_audio_group_is_loaded(VMContext* ctx, RValue* args, MAYBE_ static RValue builtin_audio_play_music(VMContext* ctx, RValue* args, MAYBE_UNUSED int32_t argCount) { if (ctx->dataWin->gen8.wadVersion >= 14) { - fprintf(stderr, "VM: [%s] audio_play_music is no-op in WAD version 14+!\n", ctx->currentCodeName); + Log_logWarning("VM: [%s] audio_play_music is no-op in WAD version 14+!\n", ctx->currentCodeName); return RValue_makeUndefined(); } @@ -6593,7 +6593,7 @@ static RValue builtin_audio_play_music(VMContext* ctx, RValue* args, MAYBE_UNUSE static RValue builtin_audio_stop_music(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { if (ctx->dataWin->gen8.wadVersion >= 14) { - fprintf(stderr, "VM: [%s] audio_stop_music is no-op in WAD version 14+!\n", ctx->currentCodeName); + Log_logWarning("VM: [%s] audio_stop_music is no-op in WAD version 14+!\n", ctx->currentCodeName); return RValue_makeUndefined(); } @@ -7105,7 +7105,7 @@ static RValue builtin_file_text_open_read(VMContext* ctx, RValue* args, int32_t int32_t slot = findFreeTextFileSlot(runner); if (0 > slot) { - fprintf(stderr, "Warning: Too many open text files!\n"); + Log_logError("Warning: Too many open text files!\n"); abort(); } @@ -7135,7 +7135,7 @@ static RValue builtin_file_text_open_write(VMContext* ctx, RValue* args, int32_t int32_t slot = findFreeTextFileSlot(runner); if (0 > slot) { - fprintf(stderr, "Warning: Too many open text files!\n"); + Log_logError("Warning: Too many open text files!\n"); abort(); } @@ -7444,7 +7444,7 @@ static RValue builtin_file_bin_open(VMContext* ctx, RValue* args, int32_t argCou int32_t slot = findFreeBinaryFileSlot(runner); if (0 > slot) { - fprintf(stderr, "Warning: Too many open binary files!\n"); + Log_logWarning("Warning: Too many open binary files!\n"); return RValue_makeReal(-1.0); } @@ -7994,7 +7994,7 @@ static RValue builtin_instance_create(VMContext* ctx, RValue* args, int32_t argC GMLReal y = RValue_toReal(args[1]); int32_t objectIndex = RValue_toInt32(args[2]); if (0 > objectIndex || runner->dataWin->objt.count <= (uint32_t) objectIndex) { - fprintf(stderr, "VM: instance_create: objectIndex %d out of range\n", objectIndex); + Log_logWarning("VM: instance_create: objectIndex %d out of range\n", objectIndex); return RValue_makeReal(0.0); } Instance* callerInst = ctx->currentInstance; @@ -8010,7 +8010,7 @@ static RValue builtin_instance_copy(VMContext* ctx, RValue* args, int32_t argCou Runner* runner = ctx->runner; Instance* source = ctx->currentInstance; if (source == nullptr) { - fprintf(stderr, "VM: instance_copy: no current instance\n"); + Log_logWarning("VM: instance_copy: no current instance\n"); return RValue_makeReal(INSTANCE_NOONE); } bool performEvent = argCount > 0 ? RValue_toBool(args[0]) : false; @@ -8068,7 +8068,7 @@ static RValue builtin_instance_create_depth(VMContext* ctx, RValue* args, int32_ int32_t depth = RValue_toInt32(args[2]); int32_t objectIndex = RValue_toInt32(args[3]); if (0 > objectIndex || runner->dataWin->objt.count <= (uint32_t) objectIndex) { - fprintf(stderr, "VM: instance_create: objectIndex %d out of range\n", objectIndex); + Log_logWarning("VM: instance_create: objectIndex %d out of range\n", objectIndex); return RValue_makeReal(0.0); } Instance* callerInst = ctx->currentInstance; @@ -8091,7 +8091,7 @@ static RValue builtin_instance_change(VMContext* ctx, RValue* args, int32_t argC bool performEvents = RValue_toBool(args[1]); if (0 > objectIndex || (uint32_t) objectIndex >= runner->dataWin->objt.count) { - fprintf(stderr, "VM: instance_change: objectIndex %d out of range\n", objectIndex); + Log_logWarning("VM: instance_change: objectIndex %d out of range\n", objectIndex); return RValue_makeUndefined(); } @@ -8270,20 +8270,20 @@ static RValue builtin_event_inherited(VMContext* ctx, MAYBE_UNUSED RValue* args, Runner* runner = ctx->runner; Instance* inst = ctx->currentInstance; if (inst == nullptr || 0 > ctx->currentEventObjectIndex || 0 > ctx->currentEventType) { - fprintf(stderr, "VM: event_inherited called with no event context (inst=%p, eventObjIdx=%d, eventType=%d)\n", (void*) inst, ctx->currentEventObjectIndex, ctx->currentEventType); + Log_logWarning("VM: event_inherited called with no event context (inst=%p, eventObjIdx=%d, eventType=%d)\n", (void*) inst, ctx->currentEventObjectIndex, ctx->currentEventType); return RValue_makeReal(0.0); } DataWin* dataWin = ctx->dataWin; int32_t ownerObjectIndex = ctx->currentEventObjectIndex; if ((uint32_t) ownerObjectIndex >= dataWin->objt.count) { - fprintf(stderr, "VM: event_inherited ownerObjectIndex %d out of range\n", ownerObjectIndex); + Log_logWarning("VM: event_inherited ownerObjectIndex %d out of range\n", ownerObjectIndex); return RValue_makeReal(0.0); } int32_t parentObjectIndex = dataWin->objt.objects[ownerObjectIndex].parentId; if (ctx->traceEventInherited) { - fprintf(stderr, "VM: [%s] event_inherited owner=%s(%d) parent=%s(%d) event=%s (instanceId=%d)\n", dataWin->objt.objects[inst->objectIndex].name, dataWin->objt.objects[ownerObjectIndex].name, ownerObjectIndex, (0 > parentObjectIndex) ? "none" : dataWin->objt.objects[parentObjectIndex].name, parentObjectIndex, Runner_getEventName(ctx->currentEventType, ctx->currentEventSubtype), inst->instanceId); + Log_logWarning("VM: [%s] event_inherited owner=%s(%d) parent=%s(%d) event=%s (instanceId=%d)\n", dataWin->objt.objects[inst->objectIndex].name, dataWin->objt.objects[ownerObjectIndex].name, ownerObjectIndex, (0 > parentObjectIndex) ? "none" : dataWin->objt.objects[parentObjectIndex].name, parentObjectIndex, Runner_getEventName(ctx->currentEventType, ctx->currentEventSubtype), inst->instanceId); } if (0 > parentObjectIndex) return RValue_makeReal(0.0); @@ -8332,7 +8332,7 @@ static RValue builtin_action_create_object(VMContext* ctx, RValue* args, int32_t GMLReal x = RValue_toReal(args[1]); GMLReal y = RValue_toReal(args[2]); if (0 > objectIndex || runner->dataWin->objt.count <= (uint32_t) objectIndex) { - fprintf(stderr, "VM: action_create_object: objectIndex %d out of range\n", objectIndex); + Log_logError("VM: action_create_object: objectIndex %d out of range\n", objectIndex); return RValue_makeUndefined(); } Instance* callerInst = ctx->currentInstance; @@ -8855,7 +8855,7 @@ static RValue builtin_buffer_write(MAYBE_UNUSED VMContext* ctx, RValue* args, MA break; } default: - fprintf(stderr, "buffer_write: unsupported data type %d\n", dataType); + Log_logWarning("buffer_write: unsupported data type %d\n", dataType); break; } @@ -8966,7 +8966,7 @@ static RValue builtin_buffer_read(MAYBE_UNUSED VMContext* ctx, RValue* args, MAY break; } default: - fprintf(stderr, "buffer_read: unsupported data type %d\n", dataType); + Log_logWarning("buffer_read: unsupported data type %d\n", dataType); break; } @@ -9186,7 +9186,7 @@ static RValue builtin_buffer_save_async(MAYBE_UNUSED VMContext* ctx, RValue* arg static RValue builtin_buffer_async_group_begin(MAYBE_UNUSED VMContext* ctx, RValue* args, MAYBE_UNUSED int32_t argCount) { Runner* runner = ctx->runner; if (runner->asyncBufferGroupActive) { - fprintf(stderr, "buffer_async_group_begin: a buffer group is already open\n"); + Log_logWarning("buffer_async_group_begin: a buffer group is already open\n"); return RValue_makeUndefined(); } free(runner->asyncBufferGroupName); @@ -9198,7 +9198,7 @@ static RValue builtin_buffer_async_group_begin(MAYBE_UNUSED VMContext* ctx, RVal static RValue builtin_buffer_async_group_end(MAYBE_UNUSED VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { Runner* runner = ctx->runner; if (!runner->asyncBufferGroupActive) { - fprintf(stderr, "buffer_async_group_end: no matching buffer_async_group_begin\n"); + Log_logWarning("buffer_async_group_end: no matching buffer_async_group_begin\n"); return RValue_makeReal(-1.0); } @@ -10543,7 +10543,7 @@ static RValue builtin_surface_copy_part(VMContext* ctx, RValue* args, MAYBE_UNUS float ys = (float) RValue_toReal(args[5]); float ws = (float) RValue_toReal(args[6]); float hs = (float) RValue_toReal(args[7]); - //fprintf(stderr, "Set Surface Target Yes\n"); + // Log_log("Set Surface Target Yes\n"); Runner* runner = ctx->runner; if (runner->renderer != nullptr) { runner->renderer->vtable->surfaceCopy(runner->renderer, sourceID, x, y, destinationID, xs, ys, ws, hs, true); @@ -10556,7 +10556,7 @@ static RValue builtin_surface_copy(VMContext* ctx, RValue* args, MAYBE_UNUSED in float x = (float) RValue_toReal(args[1]); float y = (float) RValue_toReal(args[2]); int32_t destinationID = (int32_t) RValue_toReal(args[3]); - //fprintf(stderr, "Set Surface Target Yes\n"); + // Log_log("Set Surface Target Yes\n"); Runner* runner = ctx->runner; if (runner->renderer != nullptr) { runner->renderer->vtable->surfaceCopy(runner->renderer, sourceID, x, y, destinationID, 0.0, 0.0, 0.0, 0.0, false); @@ -12134,7 +12134,7 @@ static RValue builtin_action_set_alarm(VMContext* ctx, MAYBE_UNUSED RValue* args #ifdef ENABLE_VM_TRACING Runner* runner = ctx->runner; if (shgeti(ctx->alarmsToBeTraced, "*") != -1 || shgeti(ctx->alarmsToBeTraced, runner->dataWin->objt.objects[inst->objectIndex].name) != -1) { - fprintf(stderr, "VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, steps, inst->instanceId); + Log_log("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, steps, inst->instanceId); } #endif @@ -12160,7 +12160,7 @@ static RValue builtin_alarm_set(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE #ifdef ENABLE_VM_TRACING Runner* runner = ctx->runner; if (shgeti(ctx->alarmsToBeTraced, "*") != -1 || shgeti(ctx->alarmsToBeTraced, runner->dataWin->objt.objects[inst->objectIndex].name) != -1) { - fprintf(stderr, "VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, value, inst->instanceId); + Log_log("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, value, inst->instanceId); } #endif @@ -12545,7 +12545,7 @@ static RValue builtin_action_sprite_color(VMContext* ctx, RValue* args, MAYBE_UN // action_message(text) - shows a dialog. static RValue builtin_action_message(MAYBE_UNUSED VMContext* ctx, RValue* args, MAYBE_UNUSED int32_t argCount) { char* text = RValue_toString(args[0]); - fprintf(stderr, "VM: action_message: %s\n", text); + Log_log("VM: action_message: %s\n", text); free(text); return RValue_makeUndefined(); } @@ -12571,7 +12571,7 @@ static RValue builtin_action_next_room(VMContext* ctx, MAYBE_UNUSED RValue* args if ((int32_t) runner->dataWin->gen8.roomOrderCount > nextPos) { runner->pendingRoom = runner->dataWin->gen8.roomOrder[nextPos]; } else { - fprintf(stderr, "VM: action_next_room - already at last room!\n"); + Log_logWarning("VM: action_next_room - already at last room!\n"); } return RValue_makeUndefined(); } @@ -12716,7 +12716,7 @@ static RValue builtin_tile_add(VMContext* ctx, RValue* args, MAYBE_UNUSED int32_ int32_t backgroundIndex = RValue_toInt32(args[0]); if (0 > backgroundIndex || backgroundIndex >= (int32_t) ctx->dataWin->bgnd.count) { - fprintf(stderr, "VM: tile_add: background does not exist (%d)\n", backgroundIndex); + Log_logWarning("VM: tile_add: background does not exist (%d)\n", backgroundIndex); return RValue_makeReal(-1.0); } @@ -12809,7 +12809,7 @@ static RValue builtin_tile_delete(VMContext* ctx, RValue* args, MAYBE_UNUSED int runner->drawableListStructureDirty = true; return RValue_makeUndefined(); } - fprintf(stderr, "VM: tile_delete: tile does not exist (%u)\n", id); + Log_logWarning("VM: tile_delete: tile does not exist (%u)\n", id); return RValue_makeUndefined(); } @@ -12825,7 +12825,7 @@ static RValue builtin_tile_set_alpha(VMContext* ctx, RValue* args, MAYBE_UNUSED room->tiles[i].alpha = alpha; return RValue_makeUndefined(); } - fprintf(stderr, "VM: tile_set_alpha: tile does not exist (%u)\n", id); + Log_logWarning("VM: tile_set_alpha: tile does not exist (%u)\n", id); return RValue_makeUndefined(); } @@ -13961,7 +13961,7 @@ static RValue builtin_tilemap_set(VMContext* ctx, RValue* args, MAYBE_UNUSED int uint32_t cell = (uint32_t) RValue_toInt32(args[1]); uint32_t tileIndex = (cell >> 0) & TILEINDEX_SHIFTEDMASK; if (tileset != nullptr && tileset->gms2TileCount != 0 && tileIndex >= tileset->gms2TileCount) { - fprintf(stderr, "VM: [%s] tilemap_set() - tile index outside tile set count\n", ctx->currentCodeName); + Log_logWarning("VM: [%s] tilemap_set() - tile index outside tile set count\n", ctx->currentCodeName); return RValue_makeBool(false); } @@ -13985,7 +13985,7 @@ static RValue builtin_tilemap_set_at_pixel(VMContext* ctx, RValue* args, MAYBE_U uint32_t cell = (uint32_t) RValue_toInt32(args[1]); uint32_t tileIndex = cell & TILEINDEX_SHIFTEDMASK; if (tileset->gms2TileCount != 0 && tileIndex >= tileset->gms2TileCount) { - fprintf(stderr, "VM: [%s] tilemap_set_at_pixel() - tile index outside tile set count\n", ctx->currentCodeName); + Log_logWarning("VM: [%s] tilemap_set_at_pixel() - tile index outside tile set count\n", ctx->currentCodeName); return RValue_makeBool(false); } @@ -14138,7 +14138,7 @@ static RValue builtin_SetStatic(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE // We reuse Instance (with objectIndex = STRUCT_OBJECT_INDEX) the same way globalScopeInstance is used for GLOB scripts, instead of introducing a separate struct type. static RValue builtin_NewGMLObject(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - fprintf(stderr, "VM: @@NewGMLObject@@ called with no arguments\n"); + Log_logWarning("VM: @@NewGMLObject@@ called with no arguments\n"); return RValue_makeUndefined(); } @@ -14160,7 +14160,7 @@ static RValue builtin_NewGMLObject(VMContext* ctx, RValue* args, int32_t argCoun } } if (0 > codeIndex || (uint32_t) codeIndex > ctx->dataWin->code.count) { - fprintf(stderr, "VM: @@NewGMLObject@@ method has invalid codeIndex %d\n", codeIndex); + Log_logWarning("VM: @@NewGMLObject@@ method has invalid codeIndex %d\n", codeIndex); return RValue_makeUndefined(); } @@ -14220,7 +14220,7 @@ static RValue builtin_try_hook(VMContext* ctx, RValue* args, int32_t argCount) { exceptionStackHandler->stackTop = ctx->stack.top; #ifdef ENABLE_VM_EXCEPTIONS_LOGS - fprintf(stderr, "VM: Configured exception handler for jump on exception: %d, jump on success: %d\n", jumpToOnException, jumpToOnSuccess); + Log_log("VM: Configured exception handler for jump on exception: %d, jump on success: %d\n", jumpToOnException, jumpToOnSuccess); #endif return RValue_makeUndefined(); @@ -15271,7 +15271,7 @@ static RValue jsonDecodeValue(VMContext* ctx, JsonValue* json) { static RValue builtin_json_decode(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - fprintf(stderr, "[json_decode] Expected at least 1 argument\n"); + Log_logWarning("[json_decode] Expected at least 1 argument\n"); return RValue_makeUndefined(); } @@ -15336,7 +15336,7 @@ static RValue builtin_object_get_solid(VMContext* ctx, RValue* args, int32_t arg static RValue builtin_object_get_sprite(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - fprintf(stderr, "[object_get_sprite] Expected at least 1 argument\n"); + Log_logWarning("[object_get_sprite] Expected at least 1 argument\n"); return RValue_makeUndefined(); } @@ -15476,7 +15476,7 @@ static RValue fontAddSpriteImpl(VMContext* ctx, int32_t spriteIndex, uint16_t* c DataWin* dw = ctx->dataWin; if (0 > spriteIndex || (uint32_t) spriteIndex >= dw->sprt.count) { - fprintf(stderr, "[font_add_sprite] Invalid sprite index %d\n", spriteIndex); + Log_logWarning("[font_add_sprite] Invalid sprite index %d\n", spriteIndex); return RValue_makeReal(-1.0); } @@ -15596,7 +15596,7 @@ static RValue fontAddSpriteImpl(VMContext* ctx, int32_t spriteIndex, uint16_t* c static RValue builtin_font_get_name(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - fprintf(stderr, "[font_get_name] Expected 1 argument, got 0"); + Log_logWarning("[font_get_name] Expected 1 argument, got 0"); return RValue_makeUndefined(); } @@ -15647,7 +15647,7 @@ static RValue builtin_font_get_info(VMContext* ctx, RValue* args, int32_t argCou // font_add_sprite_ext(sprite, string_map, prop, sep) static RValue builtin_font_add_sprite_ext(VMContext* ctx, RValue* args, int32_t argCount) { if (4 > argCount) { - fprintf(stderr, "[font_add_sprite_ext] Expected 4 arguments, got %d\n", argCount); + Log_logWarning("[font_add_sprite_ext] Expected 4 arguments, got %d\n", argCount); return RValue_makeReal(-1.0); } @@ -15672,7 +15672,7 @@ static RValue builtin_font_add_sprite_ext(VMContext* ctx, RValue* args, int32_t // font_add_sprite(sprite, first, prop, sep) static RValue builtin_font_add_sprite(VMContext* ctx, RValue* args, int32_t argCount) { if (4 > argCount) { - fprintf(stderr, "[font_add_sprite] Expected 4 arguments, got %d\n", argCount); + Log_logWarning("[font_add_sprite] Expected 4 arguments, got %d\n", argCount); return RValue_makeReal(-1.0); } @@ -15699,7 +15699,7 @@ static RValue builtin_font_add_sprite(VMContext* ctx, RValue* args, int32_t argC static RValue builtin_asset_get_index(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - fprintf(stderr, "[asset_get_index] Expected at least 1 argument\n"); + Log_logWarning("[asset_get_index] Expected at least 1 argument\n"); return RValue_makeUndefined(); } @@ -15863,8 +15863,8 @@ static RValue builtin_parameter_string(VMContext* ctx, RValue* args, int32_t arg static RValue builtin_shader_set(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { int32_t ShaderID = (int32_t) RValue_toReal(args[0]); - //fprintf(stderr, "Set Shader ID %u\n", ShaderID); - //gpuSetShader + // Log_log("Set Shader ID %u\n", ShaderID); + // gpuSetShader ctx->runner->renderer->vtable->gpuSetShader(ctx->runner->renderer, ShaderID); return RValue_makeUndefined(); } @@ -15920,7 +15920,7 @@ static RValue builtin_texture_set_stage(VMContext* ctx, MAYBE_UNUSED RValue* arg static RValue builtin_shader_set_uniformF(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { int32_t handle = (int32_t) RValue_toReal(args[0]); float value1, value2, value3, value4; - //fprintf(stderr, "Set ARG Count %u\n", argCount); + // Log_log("Set ARG Count %u\n", argCount); if (argCount == 2) { value1 = (float) RValue_toReal(args[1]); ctx->runner->renderer->vtable->shaderSetUniformF(ctx->runner->renderer, handle, 1, value1, 0.0, 0.0, 0.0); @@ -15938,7 +15938,7 @@ static RValue builtin_shader_set_uniformF(VMContext* ctx, MAYBE_UNUSED RValue* a value2 = (float) RValue_toReal(args[2]); value3 = (float) RValue_toReal(args[3]); value4 = (float) RValue_toReal(args[4]); - //fprintf(stderr, "Value4 %.8f\n", value4); + // Log_log("Value4 %.8f\n", value4); ctx->runner->renderer->vtable->shaderSetUniformF(ctx->runner->renderer, handle, 4, value1, value2, value3, value4); } return RValue_makeUndefined(); @@ -16245,7 +16245,7 @@ void VMBuiltins_registerAll(VMContext* ctx) { VM_registerBuiltin(ctx, "matrix_build_projection_ortho", builtin_matrix_build_projection_ortho); VM_registerBuiltin(ctx, "matrix_build_projection_perspective_fov", builtin_matrix_build_projection_perspective_fov); VM_registerBuiltin(ctx, "matrix_get", builtin_matrix_get); - VM_registerBuiltin(ctx, "matrix_set", builtin_matrix_set); + VM_registerBuiltin(ctx, "matrix_set", builtin_matrix_set); // Random VM_registerBuiltin(ctx, "random", builtin_random); VM_registerBuiltin(ctx, "random_range", builtin_random_range); diff --git a/src/web/main.c b/src/web/main.c index dd3380e47..8df35a353 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -62,12 +62,12 @@ int main() { int mountOpfs(void) { backend_t opfs = wasmfs_create_opfs_backend(); if (!opfs) { - fprintf(stderr, "Failed to create OPFS backend\n"); + Log_logWarning("Failed to create OPFS backend\n"); return -1; } int rc = wasmfs_create_directory("/butterscotch", 0777, opfs); if (rc != 0) { - fprintf(stderr, "Failed to mount OPFS at /butterscotch: %s\n", strerror(errno)); + Log_logWarning("Failed to mount OPFS at /butterscotch: %s\n", strerror(errno)); return -1; } return 0; @@ -163,7 +163,7 @@ void* loop() { } // Cleanup - fprintf(stderr, "Cleaning up runner!\n"); + Log_logError("Cleaning up runner!\n"); gRunner->audioSystem->vtable->destroy(gRunner->audioSystem); gRunner->audioSystem = nullptr; @@ -189,7 +189,7 @@ void setWindowTitle(const char* title) { // gamePath: WASMFS path to the data.win to load (example: "/butterscotch/games/undertale/data.win"). // savesPath: WASMFS directory where saves should live (example: "/butterscotch/saves/undertale" - Created if it does not exist). void startRunner(const char* gamePath, const char* savesPath) { - fprintf(stderr, "Starting runner! gamePath=%s savesPath=%s\n", gamePath, savesPath); + Log_logError("Starting runner! gamePath=%s savesPath=%s\n", gamePath, savesPath); EmscriptenWebGLContextAttributes attrs; emscripten_webgl_init_context_attributes(&attrs); @@ -218,7 +218,7 @@ void startRunner(const char* gamePath, const char* savesPath) { // Make sure the saves directory exists. The FileSystem impl will write into it. if (savesPath != nullptr && savesPath[0] != '\0') { if (mkdirP(savesPath) != 0) { - fprintf(stderr, "Warning: failed to ensure saves dir exists at %s: %s\n", savesPath, strerror(errno)); + Log_logError("Warning: failed to ensure saves dir exists at %s: %s\n", savesPath, strerror(errno)); } } @@ -295,6 +295,6 @@ void startRunner(const char* gamePath, const char* savesPath) { } void stopRunner() { - fprintf(stderr, "Marked runner to exit!\n"); + Log_logError("Marked runner to exit!\n"); gRunner->shouldExit = true; } From 927fd6c3fb218948792ed76ddd58b96057450e75 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 18:53:39 +0800 Subject: [PATCH 07/57] Replace printf with Log_log --- src/data_win.c | 2 +- src/data_win_print.c | 238 +++++++++++++++++++++--------------------- src/desktop/main.c | 68 ++++++------ src/ps2/main.c | 42 ++++---- src/ps2/ps2_gamepad.c | 8 +- src/ps3/main.c | 10 +- src/runner.c | 42 ++++---- src/vm.c | 28 ++--- src/vm_builtins.c | 4 +- src/web/main.c | 4 +- 10 files changed, 223 insertions(+), 223 deletions(-) diff --git a/src/data_win.c b/src/data_win.c index 53014f941..07e26b415 100644 --- a/src/data_win.c +++ b/src/data_win.c @@ -2840,7 +2840,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { } else if (options.parseAudo && memcmp(chunkName, "AUDO", 4) == 0) { parseAUDO(&reader, dw); } else { - printf("Unknown chunk: %.4s (length %u at offset 0x%zX)\n", chunkName, chunkLength, chunkDataStart - 8); + Log_log("Unknown chunk: %.4s (length %u at offset 0x%zX)\n", chunkName, chunkLength, chunkDataStart - 8); } // Free the chunk buffer and revert to FILE*-based reads for the next header diff --git a/src/data_win_print.c b/src/data_win_print.c index fc357e198..f3968a365 100644 --- a/src/data_win_print.c +++ b/src/data_win_print.c @@ -6,139 +6,139 @@ #include "utils.h" void DataWin_printDebugSummary(DataWin* dataWin) { - printf("===== data.win Summary =====\n\n"); + Log_log("===== data.win Summary =====\n\n"); // GEN8 Gen8* g = &dataWin->gen8; - printf("-- GEN8 (General Info) --\n"); - printf(" Game Name: %s\n", g->name ? g->name : "(null)"); - printf(" Display Name: %s\n", g->displayName ? g->displayName : "(null)"); - printf(" File Name: %s\n", g->fileName ? g->fileName : "(null)"); - printf(" Config: %s\n", g->config ? g->config : "(null)"); - printf(" WAD Version: %u\n", g->wadVersion); - printf(" Game ID: %u\n", g->gameID); - printf(" Version: %u.%u.%u.%u\n", g->major, g->minor, g->release, g->build); - printf(" Window Size: %ux%u\n", g->defaultWindowWidth, g->defaultWindowHeight); - printf(" Steam App ID: %d\n", g->steamAppID); - printf(" Room Order: %u rooms\n", g->roomOrderCount); - printf("\n"); + Log_log("-- GEN8 (General Info) --\n"); + Log_log(" Game Name: %s\n", g->name ? g->name : "(null)"); + Log_log(" Display Name: %s\n", g->displayName ? g->displayName : "(null)"); + Log_log(" File Name: %s\n", g->fileName ? g->fileName : "(null)"); + Log_log(" Config: %s\n", g->config ? g->config : "(null)"); + Log_log(" WAD Version: %u\n", g->wadVersion); + Log_log(" Game ID: %u\n", g->gameID); + Log_log(" Version: %u.%u.%u.%u\n", g->major, g->minor, g->release, g->build); + Log_log(" Window Size: %ux%u\n", g->defaultWindowWidth, g->defaultWindowHeight); + Log_log(" Steam App ID: %d\n", g->steamAppID); + Log_log(" Room Order: %u rooms\n", g->roomOrderCount); + Log_log("\n"); // OPTN - printf("-- OPTN (Options) --\n"); - printf(" Constants: %u\n", dataWin->optn.constantCount); + Log_log("-- OPTN (Options) --\n"); + Log_log(" Constants: %u\n", dataWin->optn.constantCount); if (dataWin->optn.constantCount > 0) { uint32_t show = dataWin->optn.constantCount < 3 ? dataWin->optn.constantCount : 3; forEachIndexed(OptnConstant, constant, idx, dataWin->optn.constants, show) { - printf(" [%u] %s = %s\n", (unsigned int)idx, constant->name ? constant->name : "?", constant->value ? constant->value : "?"); + Log_log(" [%u] %s = %s\n", (unsigned int)idx, constant->name ? constant->name : "?", constant->value ? constant->value : "?"); } - if (dataWin->optn.constantCount > 3) printf(" ... and %u more\n", dataWin->optn.constantCount - 3); + if (dataWin->optn.constantCount > 3) Log_log(" ... and %u more\n", dataWin->optn.constantCount - 3); } - printf("\n"); + Log_log("\n"); // LANG - printf("-- LANG (Languages) --\n"); - printf(" Languages: %u\n", dataWin->lang.languageCount); - printf(" Entries: %u\n", dataWin->lang.entryCount); - printf("\n"); + Log_log("-- LANG (Languages) --\n"); + Log_log(" Languages: %u\n", dataWin->lang.languageCount); + Log_log(" Entries: %u\n", dataWin->lang.entryCount); + Log_log("\n"); // EXTN - printf("-- EXTN (Extensions) --\n"); - printf(" Extensions: %u\n", dataWin->extn.count); + Log_log("-- EXTN (Extensions) --\n"); + Log_log(" Extensions: %u\n", dataWin->extn.count); forEachIndexed(Extension, ext, idx, dataWin->extn.extensions, dataWin->extn.count) { - printf(" [%u] %s (%u files)\n", (unsigned int)idx, ext->name ? ext->name : "?", ext->fileCount); + Log_log(" [%u] %s (%u files)\n", (unsigned int)idx, ext->name ? ext->name : "?", ext->fileCount); } - printf("\n"); + Log_log("\n"); // SOND - printf("-- SOND (Sounds) --\n"); - printf(" Sounds: %u\n", dataWin->sond.count); + Log_log("-- SOND (Sounds) --\n"); + Log_log(" Sounds: %u\n", dataWin->sond.count); if (dataWin->sond.count > 0) { uint32_t show = dataWin->sond.count < 3 ? dataWin->sond.count : 3; forEachIndexed(Sound, snd, idx, dataWin->sond.sounds, show) { - printf(" [%u] %s (%s)\n", (unsigned int)idx, snd->name ? snd->name : "?", snd->type ? snd->type : "?"); + Log_log(" [%u] %s (%s)\n", (unsigned int)idx, snd->name ? snd->name : "?", snd->type ? snd->type : "?"); } - if (dataWin->sond.count > 3) printf(" ... and %u more\n", dataWin->sond.count - 3); + if (dataWin->sond.count > 3) Log_log(" ... and %u more\n", dataWin->sond.count - 3); } - printf("\n"); + Log_log("\n"); // AGRP - printf("-- AGRP (Audio Groups) --\n"); - printf(" Audio Groups: %u\n", dataWin->agrp.count); + Log_log("-- AGRP (Audio Groups) --\n"); + Log_log(" Audio Groups: %u\n", dataWin->agrp.count); forEachIndexed(AudioGroup, ag, idx, dataWin->agrp.audioGroups, dataWin->agrp.count) { - printf(" [%u] %s\n", (unsigned int)idx, ag->name ? ag->name : "?"); + Log_log(" [%u] %s\n", (unsigned int)idx, ag->name ? ag->name : "?"); } - printf("\n"); + Log_log("\n"); // SPRT - printf("-- SPRT (Sprites) --\n"); - printf(" Sprites: %u\n", dataWin->sprt.count); + Log_log("-- SPRT (Sprites) --\n"); + Log_log(" Sprites: %u\n", dataWin->sprt.count); if (dataWin->sprt.count > 0) { uint32_t show = dataWin->sprt.count < 3 ? dataWin->sprt.count : 3; forEachIndexed(Sprite, spr, idx, dataWin->sprt.sprites, show) { - printf(" [%u] %s (%ux%u, %u frames)\n", (unsigned int)idx, spr->name ? spr->name : "?", spr->width, spr->height, spr->textureCount); + Log_log(" [%u] %s (%ux%u, %u frames)\n", (unsigned int)idx, spr->name ? spr->name : "?", spr->width, spr->height, spr->textureCount); } - if (dataWin->sprt.count > 3) printf(" ... and %u more\n", dataWin->sprt.count - 3); + if (dataWin->sprt.count > 3) Log_log(" ... and %u more\n", dataWin->sprt.count - 3); } - printf("\n"); + Log_log("\n"); // BGND - printf("-- BGND (Backgrounds) --\n"); - printf(" Backgrounds: %u\n", dataWin->bgnd.count); + Log_log("-- BGND (Backgrounds) --\n"); + Log_log(" Backgrounds: %u\n", dataWin->bgnd.count); if (dataWin->bgnd.count > 0) { uint32_t show = dataWin->bgnd.count < 3 ? dataWin->bgnd.count : 3; forEachIndexed(Background, bg, idx, dataWin->bgnd.backgrounds, show) { - printf(" [%u] %s\n", (unsigned int)idx, bg->name ? bg->name : "?"); + Log_log(" [%u] %s\n", (unsigned int)idx, bg->name ? bg->name : "?"); } - if (dataWin->bgnd.count > 3) printf(" ... and %u more\n", dataWin->bgnd.count - 3); + if (dataWin->bgnd.count > 3) Log_log(" ... and %u more\n", dataWin->bgnd.count - 3); } - printf("\n"); + Log_log("\n"); // PATH - printf("-- PATH (Paths) --\n"); - printf(" Paths: %u\n", dataWin->path.count); - printf("\n"); + Log_log("-- PATH (Paths) --\n"); + Log_log(" Paths: %u\n", dataWin->path.count); + Log_log("\n"); // SCPT - printf("-- SCPT (Scripts) --\n"); - printf(" Scripts: %u\n", dataWin->scpt.count); + Log_log("-- SCPT (Scripts) --\n"); + Log_log(" Scripts: %u\n", dataWin->scpt.count); if (dataWin->scpt.count > 0) { uint32_t show = dataWin->scpt.count < 3 ? dataWin->scpt.count : 3; forEachIndexed(Script, scr, idx, dataWin->scpt.scripts, show) { - printf(" [%u] %s -> code[%d]\n", (unsigned int)idx, scr->name ? scr->name : "?", scr->codeId); + Log_log(" [%u] %s -> code[%d]\n", (unsigned int)idx, scr->name ? scr->name : "?", scr->codeId); } - if (dataWin->scpt.count > 3) printf(" ... and %u more\n", dataWin->scpt.count - 3); + if (dataWin->scpt.count > 3) Log_log(" ... and %u more\n", dataWin->scpt.count - 3); } - printf("\n"); + Log_log("\n"); // GLOB - printf("-- GLOB (Global Init Scripts) --\n"); - printf(" Init Scripts: %u\n", dataWin->glob.count); - printf("\n"); + Log_log("-- GLOB (Global Init Scripts) --\n"); + Log_log(" Init Scripts: %u\n", dataWin->glob.count); + Log_log("\n"); // SHDR - printf("-- SHDR (Shaders) --\n"); - printf(" Shaders: %u\n", dataWin->shdr.count); + Log_log("-- SHDR (Shaders) --\n"); + Log_log(" Shaders: %u\n", dataWin->shdr.count); forEachIndexed(Shader, shdr, idx, dataWin->shdr.shaders, dataWin->shdr.count) { - printf(" [%u] %s (version %d)\n", (unsigned int)idx, shdr->name ? shdr->name : "?", shdr->version); + Log_log(" [%u] %s (version %d)\n", (unsigned int)idx, shdr->name ? shdr->name : "?", shdr->version); } - printf("\n"); + Log_log("\n"); // FONT - printf("-- FONT (Fonts) --\n"); - printf(" Fonts: %u\n", dataWin->font.count); + Log_log("-- FONT (Fonts) --\n"); + Log_log(" Fonts: %u\n", dataWin->font.count); forEachIndexed(Font, fnt, idx, dataWin->font.fonts, dataWin->font.count) { - printf(" [%u] %s (%s, em=%u, %u glyphs)\n", (unsigned int)idx, fnt->name ? fnt->name : "?", fnt->displayName ? fnt->displayName : "?", fnt->emSize, fnt->glyphCount); + Log_log(" [%u] %s (%s, em=%u, %u glyphs)\n", (unsigned int)idx, fnt->name ? fnt->name : "?", fnt->displayName ? fnt->displayName : "?", fnt->emSize, fnt->glyphCount); } - printf("\n"); + Log_log("\n"); // TMLN - printf("-- TMLN (Timelines) --\n"); - printf(" Timelines: %u\n", dataWin->tmln.count); - printf("\n"); + Log_log("-- TMLN (Timelines) --\n"); + Log_log(" Timelines: %u\n", dataWin->tmln.count); + Log_log("\n"); // OBJT - printf("-- OBJT (Game Objects) --\n"); - printf(" Objects: %u\n", dataWin->objt.count); + Log_log("-- OBJT (Game Objects) --\n"); + Log_log(" Objects: %u\n", dataWin->objt.count); if (dataWin->objt.count > 0) { uint32_t show = dataWin->objt.count < 3 ? dataWin->objt.count : 3; forEachIndexed(GameObject, obj, idx, dataWin->objt.objects, show) { @@ -146,75 +146,75 @@ void DataWin_printDebugSummary(DataWin* dataWin) { repeat(OBJT_EVENT_TYPE_COUNT, e) { totalEvents += obj->eventLists[e].eventCount; } - printf(" [%u] %s (sprite=%d, depth=%d, %u events)\n", (unsigned int)idx, obj->name ? obj->name : "?", obj->spriteId, obj->depth, totalEvents); + Log_log(" [%u] %s (sprite=%d, depth=%d, %u events)\n", (unsigned int)idx, obj->name ? obj->name : "?", obj->spriteId, obj->depth, totalEvents); } - if (dataWin->objt.count > 3) printf(" ... and %u more\n", dataWin->objt.count - 3); + if (dataWin->objt.count > 3) Log_log(" ... and %u more\n", dataWin->objt.count - 3); } - printf("\n"); + Log_log("\n"); // ROOM - printf("-- ROOM (Rooms) --\n"); - printf(" Rooms: %u\n", dataWin->room.count); + Log_log("-- ROOM (Rooms) --\n"); + Log_log(" Rooms: %u\n", dataWin->room.count); if (dataWin->room.count > 0) { uint32_t show = dataWin->room.count < 3 ? dataWin->room.count : 3; forEachIndexed(Room, rm, idx, dataWin->room.rooms, show) { if (rm->payloadLoaded) { - printf(" [%u] %s (%ux%u, %u objects, %u tiles)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height, rm->gameObjectCount, rm->tileCount); + Log_log(" [%u] %s (%ux%u, %u objects, %u tiles)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height, rm->gameObjectCount, rm->tileCount); } else { // Lazy room with payload not yet loaded: gameObjectCount/tileCount would be 0 and misleading. - printf(" [%u] %s (%ux%u, payload not loaded)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height); + Log_log(" [%u] %s (%ux%u, payload not loaded)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height); } } - if (dataWin->room.count > 3) printf(" ... and %u more\n", dataWin->room.count - 3); + if (dataWin->room.count > 3) Log_log(" ... and %u more\n", dataWin->room.count - 3); } - printf("\n"); + Log_log("\n"); // TPAG - printf("-- TPAG (Texture Page Items) --\n"); - printf(" Items: %u\n", dataWin->tpag.count); - printf("\n"); + Log_log("-- TPAG (Texture Page Items) --\n"); + Log_log(" Items: %u\n", dataWin->tpag.count); + Log_log("\n"); // CODE - printf("-- CODE (Code Entries) --\n"); - printf(" Entries: %u\n", dataWin->code.count); + Log_log("-- CODE (Code Entries) --\n"); + Log_log(" Entries: %u\n", dataWin->code.count); if (dataWin->code.count > 0) { uint32_t show = dataWin->code.count < 3 ? dataWin->code.count : 3; forEachIndexed(CodeEntry, entry, idx, dataWin->code.entries, show) { - printf(" [%u] %s (%u bytes, %u locals, %u args)\n", (unsigned int)idx, entry->name ? entry->name : "?", entry->length, entry->localsCount, entry->argumentsCount); + Log_log(" [%u] %s (%u bytes, %u locals, %u args)\n", (unsigned int)idx, entry->name ? entry->name : "?", entry->length, entry->localsCount, entry->argumentsCount); } - if (dataWin->code.count > 3) printf(" ... and %u more\n", dataWin->code.count - 3); + if (dataWin->code.count > 3) Log_log(" ... and %u more\n", dataWin->code.count - 3); } - printf("\n"); + Log_log("\n"); // VARI - printf("-- VARI (Variables) --\n"); - printf(" Variables: %u\n", dataWin->vari.variableCount); - printf(" Max Locals: %u\n", dataWin->vari.maxLocalVarCount); + Log_log("-- VARI (Variables) --\n"); + Log_log(" Variables: %u\n", dataWin->vari.variableCount); + Log_log(" Max Locals: %u\n", dataWin->vari.maxLocalVarCount); if (dataWin->vari.variableCount > 0) { uint32_t show = dataWin->vari.variableCount < 3 ? dataWin->vari.variableCount : 3; forEachIndexed(Variable, var, idx, dataWin->vari.variables, show) { - printf(" [%u] %s (type=%d, id=%d, %u refs)\n", (unsigned int)idx, var->name ? var->name : "?", var->instanceType, var->varID, var->occurrences); + Log_log(" [%u] %s (type=%d, id=%d, %u refs)\n", (unsigned int)idx, var->name ? var->name : "?", var->instanceType, var->varID, var->occurrences); } - if (dataWin->vari.variableCount > 3) printf(" ... and %u more\n", dataWin->vari.variableCount - 3); + if (dataWin->vari.variableCount > 3) Log_log(" ... and %u more\n", dataWin->vari.variableCount - 3); } - printf("\n"); + Log_log("\n"); // FUNC - printf("-- FUNC (Functions) --\n"); - printf(" Functions: %u\n", dataWin->func.functionCount); - printf(" Code Locals: %u\n", dataWin->func.codeLocalsCount); + Log_log("-- FUNC (Functions) --\n"); + Log_log(" Functions: %u\n", dataWin->func.functionCount); + Log_log(" Code Locals: %u\n", dataWin->func.codeLocalsCount); if (dataWin->func.functionCount > 0) { uint32_t show = dataWin->func.functionCount < 3 ? dataWin->func.functionCount : 3; forEachIndexed(Function, fn, idx, dataWin->func.functions, show) { - printf(" [%u] %s (%u refs)\n", (unsigned int)idx, fn->name ? fn->name : "?", fn->occurrences); + Log_log(" [%u] %s (%u refs)\n", (unsigned int)idx, fn->name ? fn->name : "?", fn->occurrences); } - if (dataWin->func.functionCount > 3) printf(" ... and %u more\n", dataWin->func.functionCount - 3); + if (dataWin->func.functionCount > 3) Log_log(" ... and %u more\n", dataWin->func.functionCount - 3); } - printf("\n"); + Log_log("\n"); // STRG - printf("-- STRG (Strings) --\n"); - printf(" Strings: %u\n", dataWin->strg.count); + Log_log("-- STRG (Strings) --\n"); + Log_log(" Strings: %u\n", dataWin->strg.count); if (dataWin->strg.count > 0) { uint32_t show = dataWin->strg.count < 5 ? dataWin->strg.count : 5; repeat(show, i) { @@ -223,56 +223,56 @@ void DataWin_printDebugSummary(DataWin* dataWin) { if (str) { size_t len = strlen(str); if (len > 60) { - printf(" [%u] \"%.60s...\" (%zu chars)\n", (unsigned int)i, str, len); + Log_log(" [%u] \"%.60s...\" (%zu chars)\n", (unsigned int)i, str, len); } else { - printf(" [%u] \"%s\"\n", (unsigned int)i, str); + Log_log(" [%u] \"%s\"\n", (unsigned int)i, str); } } else { - printf(" [%u] (null)\n", (unsigned int)i); + Log_log(" [%u] (null)\n", (unsigned int)i); } } - if (dataWin->strg.count > 5) printf(" ... and %u more\n", dataWin->strg.count - 5); + if (dataWin->strg.count > 5) Log_log(" ... and %u more\n", dataWin->strg.count - 5); } - printf("\n"); + Log_log("\n"); // TXTR - printf("-- TXTR (Textures) --\n"); - printf(" Textures: %u\n", dataWin->txtr.count); + Log_log("-- TXTR (Textures) --\n"); + Log_log(" Textures: %u\n", dataWin->txtr.count); if (dataWin->txtr.count > 0) { forEachIndexed(Texture, tex, idx, dataWin->txtr.textures, dataWin->txtr.count) { - printf(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, tex->blobOffset, tex->blobSize); + Log_log(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, tex->blobOffset, tex->blobSize); } } - printf("\n"); + Log_log("\n"); // AUDO - printf("-- AUDO (Audio) --\n"); - printf(" Audio Entries: %u\n", dataWin->audo.count); + Log_log("-- AUDO (Audio) --\n"); + Log_log(" Audio Entries: %u\n", dataWin->audo.count); if (dataWin->audo.count > 0) { uint32_t show = dataWin->audo.count < 3 ? dataWin->audo.count : 3; forEachIndexed(AudioEntry, ae, idx, dataWin->audo.entries, show) { - printf(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, ae->dataOffset, ae->dataSize); + Log_log(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, ae->dataOffset, ae->dataSize); } - if (dataWin->audo.count > 3) printf(" ... and %u more\n", dataWin->audo.count - 3); + if (dataWin->audo.count > 3) Log_log(" ... and %u more\n", dataWin->audo.count - 3); } - printf("\n"); + Log_log("\n"); - printf("-- Room Instances --\n"); + Log_log("-- Room Instances --\n"); forEach(Room, room, dataWin->room.rooms, dataWin->room.count) { - printf("Room %s\n", room->name); + Log_log("Room %s\n", room->name); if (!room->payloadLoaded) { - printf(" (payload not loaded)\n"); + Log_log(" (payload not loaded)\n"); continue; } forEachIndexed(RoomGameObject, roomGameObject, idx, room->gameObjects, room->gameObjectCount) { int32_t objectDefinitionId = roomGameObject->objectDefinition; GameObject* objectDefinition = &dataWin->objt.objects[objectDefinitionId]; - printf(" Object %d (%s, x=%d, y=%d)\n", objectDefinitionId, objectDefinition->name, roomGameObject->x, roomGameObject->y); + Log_log(" Object %d (%s, x=%d, y=%d)\n", objectDefinitionId, objectDefinition->name, roomGameObject->x, roomGameObject->y); } } // Overall summary - printf("===== DataWin parse complete =====\n"); + Log_log("===== DataWin parse complete =====\n"); } diff --git a/src/desktop/main.c b/src/desktop/main.c index 8c6175607..b9daefc0e 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -1099,7 +1099,7 @@ int main(int argc, char* argv[]) { // reflects what each room contains without keeping all of them resident simultaneously. forEachIndexed(Room, room, idx, dataWin->room.rooms, dataWin->room.count) { if (!room->present) { - printf("[%d] \n", (int)idx); + Log_log("[%d] \n", (int)idx); continue; } bool loadedHere = false; @@ -1108,15 +1108,15 @@ int main(int argc, char* argv[]) { loadedHere = true; } - printf("[%d] %s ()\n", (int)idx, room->name); + Log_log("[%d] %s ()\n", (int)idx, room->name); forEachIndexed(RoomGameObject, roomGameObject, idx2, room->gameObjects, room->gameObjectCount) { if (roomGameObject->objectDefinition < 0 || (uint32_t) roomGameObject->objectDefinition >= dataWin->objt.count) { - printf(" [%d] (x=%d,y=%d)\n", (int)idx2, roomGameObject->x, roomGameObject->y); + Log_log(" [%d] (x=%d,y=%d)\n", (int)idx2, roomGameObject->x, roomGameObject->y); continue; } GameObject* gameObject = &dataWin->objt.objects[roomGameObject->objectDefinition]; - printf( + Log_log( " [%d] %s (x=%d,y=%d,persistent=%d,solid=%d,spriteId=%d,preCreateCode=%d,creationCode=%d)\n", (int)idx2, gameObject->name, @@ -1145,22 +1145,22 @@ int main(int argc, char* argv[]) { repeat(OBJT_EVENT_TYPE_COUNT, e) { totalEvents += obj->eventLists[e].eventCount; } - printf("[%u] %s:\n", (unsigned int)idx, obj->name); + Log_log("[%u] %s:\n", (unsigned int)idx, obj->name); if (obj->parentId >= 0 && (uint32_t) obj->parentId < dataWin->objt.count) { - printf(" Parent: %s (%d)\n", dataWin->objt.objects[obj->parentId].name, obj->parentId); + Log_log(" Parent: %s (%d)\n", dataWin->objt.objects[obj->parentId].name, obj->parentId); } else { - printf(" Parent: none\n"); + Log_log(" Parent: none\n"); } if (obj->spriteId >= 0 && (uint32_t) obj->spriteId < dataWin->sprt.count) { - printf(" Sprite: %s (%d)\n", dataWin->sprt.sprites[obj->spriteId].name, obj->spriteId); + Log_log(" Sprite: %s (%d)\n", dataWin->sprt.sprites[obj->spriteId].name, obj->spriteId); } else { - printf(" Sprite: none\n"); + Log_log(" Sprite: none\n"); } - printf(" Solid: %d\n", obj->solid); - printf(" Persistent: %d\n", obj->persistent); - printf(" Visible: %d\n", obj->visible); - printf(" Depth: %d\n", obj->depth); - printf(" Events (%u):\n", totalEvents); + Log_log(" Solid: %d\n", obj->solid); + Log_log(" Persistent: %d\n", obj->persistent); + Log_log(" Visible: %d\n", obj->visible); + Log_log(" Depth: %d\n", obj->depth); + Log_log(" Events (%u):\n", totalEvents); repeat(OBJT_EVENT_TYPE_COUNT, e) { ObjectEventList* list = &obj->eventLists[e]; repeat(list->eventCount, eIdx) { @@ -1168,10 +1168,10 @@ int main(int argc, char* argv[]) { const char* eventName = Runner_getEventName((int32_t) e, (int32_t) event->eventSubtype); int32_t codeId = -1; if (event->actionCount > 0) codeId = event->actions[0].codeId; - printf(" %s:\n", eventName); - printf(" Sub Type: %u\n", event->eventSubtype); - printf(" Code ID: %d\n", codeId); - printf(" Actions: %u\n", event->actionCount); + Log_log(" %s:\n", eventName); + Log_log(" Sub Type: %u\n", event->eventSubtype); + Log_log(" Code ID: %d\n", codeId); + Log_log(" Actions: %u\n", event->actionCount); } } } @@ -1182,25 +1182,25 @@ int main(int argc, char* argv[]) { if (args.printShaders) { forEachIndexed(Shader, shader, idx, dataWin->shdr.shaders, dataWin->shdr.count) { - printf("[%u] %s:\n", (unsigned int)idx, shader->name); - printf("GLSL Vertex Shader:\n"); + Log_log("[%u] %s:\n", (unsigned int)idx, shader->name); + Log_log("GLSL Vertex Shader:\n"); char* glslVertex = collapseNewlines(shader->glsl_Vertex); - printf("%s\n", glslVertex); + Log_log("%s\n", glslVertex); free(glslVertex); - printf("GLSL Fragment Shader:\n"); + Log_log("GLSL Fragment Shader:\n"); char* glslFragment = collapseNewlines(shader->glsl_Fragment); - printf("%s\n", glslFragment); + Log_log("%s\n", glslFragment); free(glslFragment); - printf("GLSL ES Vertex Shader:\n"); + Log_log("GLSL ES Vertex Shader:\n"); char* glslESVertex = collapseNewlines(shader->glslES_Vertex); - printf("%s\n", glslESVertex); + Log_log("%s\n", glslESVertex); free(glslESVertex); - printf("GLSL ES Fragment Shader:\n"); + Log_log("GLSL ES Fragment Shader:\n"); char* glslESFragment = collapseNewlines(shader->glslES_Fragment); - printf("%s\n", glslESFragment); + Log_log("%s\n", glslESFragment); free(glslESFragment); } VM_free(vm); @@ -1210,7 +1210,7 @@ int main(int argc, char* argv[]) { if (args.printDeclaredFunctions) { repeat(hmlen(vm->codeIndexByName), i) { - printf("[%d] %s\n", vm->codeIndexByName[i].value, vm->codeIndexByName[i].key); + Log_log("[%d] %s\n", vm->codeIndexByName[i].value, vm->codeIndexByName[i].key); } VM_free(vm); DataWin_free(dataWin); @@ -1574,12 +1574,12 @@ int main(int argc, char* argv[]) { fwrite(json, 1, strlen(json), f); fputc('\n', f); fclose(f); - printf("JSON dump saved: %s\n", filename); + Log_log("JSON dump saved: %s\n", filename); } else { Log_logWarning("Error: Could not write JSON dump to '%s'\n", filename); } } else { - printf("%s\n", json); + Log_log("%s\n", json); } free(json); @@ -1624,7 +1624,7 @@ int main(int argc, char* argv[]) { int32_t interactVarId = shget(runner->vmContext->varNameMap, "interact"); Instance_setSelfVar(runner->vmContext->globalScopeInstance, interactVarId, RValue_makeInt32(0)); - printf("Changed global.interact [%d] value!\n", interactVarId); + Log_log("Changed global.interact [%d] value!\n", interactVarId); } bool currentKeyDown[GML_KEY_COUNT]; @@ -1682,12 +1682,12 @@ int main(int argc, char* argv[]) { fwrite(json, 1, strlen(json), f); fputc('\n', f); fclose(f); - printf("JSON dump saved: %s\n", filename); + Log_log("JSON dump saved: %s\n", filename); } else { Log_logWarning("Error: Could not write JSON dump to '%s'\n", filename); } } else { - printf("%s\n", json); + Log_log("%s\n", json); } free(json); } @@ -1785,7 +1785,7 @@ int main(int argc, char* argv[]) { #endif if (args.exitAtFrame >= 0 && runner->frameCount >= args.exitAtFrame) { - printf("Exiting at frame %d (--exit-at-frame)\n", runner->frameCount); + Log_log("Exiting at frame %d (--exit-at-frame)\n", runner->frameCount); shouldWindowClose = true; } diff --git a/src/ps2/main.c b/src/ps2/main.c index 560c0b953..0642de1bb 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -98,7 +98,7 @@ static void parsePadMappings(JsonValue* configRoot, const char* key, PadMapping* JsonValue* gmlKeyVal = JsonReader_getJsonValueByIndex(mappingsObj, i); mappings[i].padButton = (uint16_t) atoi(padButtonStr); mappings[i].gmlKey = (int32_t) JsonReader_getInt(gmlKeyVal); - printf("CONFIG.JSN: %s mapping pad=%d -> gmlKey=%d\n", logLabel, mappings[i].padButton, mappings[i].gmlKey); + Log_log("CONFIG.JSN: %s mapping pad=%d -> gmlKey=%d\n", logLabel, mappings[i].padButton, mappings[i].gmlKey); } *outMappings = mappings; *outCount = count; @@ -261,7 +261,7 @@ int main(int argc, char* argv[]) { char* dataWinPath = PS2Utils_createDevicePath("DATA.WIN"); - printf("Butterscotch PS2 - Loading %s\n", dataWinPath); + Log_log("Butterscotch PS2 - Loading %s\n", dataWinPath); // ===[ Initialize gsKit ]=== // This must happen first so we can show the loading screen during other init steps @@ -294,51 +294,51 @@ int main(int argc, char* argv[]) { int ret; ret = SifExecModuleBuffer(freesio2_irx, size_freesio2_irx, 0, nullptr, nullptr); if (0 > ret) { - printf("Failed to load freesio2: %d\n", ret); + Log_log("Failed to load freesio2: %d\n", ret); return 1; } ret = SifExecModuleBuffer(mcman_irx, size_mcman_irx, 0, nullptr, nullptr); if (0 > ret) { - printf("Failed to load mcman: %d\n", ret); + Log_log("Failed to load mcman: %d\n", ret); return 1; } ret = SifExecModuleBuffer(mcserv_irx, size_mcserv_irx, 0, nullptr, nullptr); if (0 > ret) { - printf("Failed to load mcserv: %d\n", ret); + Log_log("Failed to load mcserv: %d\n", ret); return 1; } ret = mcInit(MC_TYPE_MC); if (0 > ret) { - printf("Failed to init libmc: %d\n", ret); + Log_log("Failed to init libmc: %d\n", ret); return 1; } ret = SifExecModuleBuffer(freepad_irx, size_freepad_irx, 0, nullptr, nullptr); if (0 > ret) { - printf("Failed to load freepad: %d\n", ret); + Log_log("Failed to load freepad: %d\n", ret); return 1; } padInit(0); padOpened[0] = (padPortOpen(0, 0, padBuf[0]) != 0); padOpened[1] = (padPortOpen(1, 0, padBuf[1]) != 0); - if (!padOpened[0]) printf("Warning: failed to open pad port 0\n"); - if (!padOpened[1]) printf("Warning: failed to open pad port 1\n"); + if (!padOpened[0])Log_log("Warning: failed to open pad port 0\n"); + if (!padOpened[1])Log_log("Warning: failed to open pad port 1\n"); // ===[ Load USB Keyboard IOP Modules ]=== int usbdRet = SifExecModuleBuffer(usbd_irx, size_usbd_irx, 0, nullptr, nullptr); if (0 > usbdRet) { - printf("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); + Log_log("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); } else { int kbdRet = SifExecModuleBuffer(ps2kbd_irx, size_ps2kbd_irx, 0, nullptr, nullptr); if (0 > kbdRet) { - printf("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); + Log_log("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); } else if (PS2KbdInit() == 0) { - printf("Warning: PS2KbdInit failed (keyboard disabled)\n"); + Log_log("Warning: PS2KbdInit failed (keyboard disabled)\n"); } else { PS2KbdSetReadmode(PS2KBD_READMODE_RAW); PS2KbdSetBlockingMode(PS2KBD_NONBLOCKING); kbdAvailable = true; - printf("USB keyboard initialized\n"); + Log_log("USB keyboard initialized\n"); } } @@ -346,11 +346,11 @@ int main(int argc, char* argv[]) { // ===[ Load Audio IOP Modules ]=== ret = SifExecModuleBuffer(freesd_irx, size_freesd_irx, 0, nullptr, nullptr); if (0 > ret) { - printf("Failed to load freesd: %d\n", ret); + Log_log("Failed to load freesd: %d\n", ret); } ret = SifExecModuleBuffer(audsrv_irx, size_audsrv_irx, 0, nullptr, nullptr); if (0 > ret) { - printf("Failed to load audsrv: %d\n", ret); + Log_log("Failed to load audsrv: %d\n", ret); } #endif @@ -361,7 +361,7 @@ int main(int argc, char* argv[]) { padState = padGetState(0, 0); } while (PAD_STATE_STABLE != padState && PAD_STATE_FINDCTP1 != padState); - printf("Controller initialized\n"); + Log_log("Controller initialized\n"); // ===[ Load CONFIG.JSN ]=== PS2Overlay_drawStatusScreen(nullptr, "Loading CONFIG.JSN...", false); @@ -458,7 +458,7 @@ int main(int argc, char* argv[]) { void* heapTop = sbrk(0); int32_t usedBytes = (int32_t) (uintptr_t) heapTop; int32_t freeBytes = MAX_MEMORY_BYTES - usedBytes; - printf("Memory after data.win parsing: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); + Log_log("Memory after data.win parsing: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); } FileSystem* fileSystem = Ps2FileSystem_create(configRoot, dataWin->gen8.displayName); @@ -499,7 +499,7 @@ int main(int argc, char* argv[]) { if (elem != nullptr && JsonReader_isString(elem)) { const char* objName = JsonReader_getString(elem); shput(runner->disabledObjects, objName, 1); - printf("Disabled object: %s\n", objName); + Log_log("Disabled object: %s\n", objName); } } } @@ -513,14 +513,14 @@ int main(int argc, char* argv[]) { gamepadApiEnabled = JsonReader_getBool(JsonReader_getJsonValueByKey(gamepadObj, "enabled")); } if (gamepadApiEnabled) { - printf("CONFIG.JSN: GameMaker gamepad API enabled\n"); + Log_log("CONFIG.JSN: GameMaker gamepad API enabled\n"); } { void* heapTop = sbrk(0); int32_t usedBytes = (int32_t) (uintptr_t) heapTop; int32_t freeBytes = MAX_MEMORY_BYTES - usedBytes; - printf("Memory after VM and runner creation: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); + Log_log("Memory after VM and runner creation: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); } PS2Overlay_drawStatusScreen(dataWin->gen8.displayName, "Initializing first room...", true); @@ -632,7 +632,7 @@ int main(int argc, char* argv[]) { int32_t interactVarId = shget(runner->vmContext->varNameMap, "interact"); Instance_setSelfVar(runner->vmContext->globalScopeInstance, interactVarId, RValue_makeInt32(0)); - printf("Changed global.interact [%d] value!\n", interactVarId); + Log_log("Changed global.interact [%d] value!\n", interactVarId); } // ===[ Game Logic ]=== diff --git a/src/ps2/ps2_gamepad.c b/src/ps2/ps2_gamepad.c index 1c2aaa4aa..38e35191f 100644 --- a/src/ps2/ps2_gamepad.c +++ b/src/ps2/ps2_gamepad.c @@ -33,21 +33,21 @@ static void setupAnalogMode(int port) { } } if (!supportsDualshock) { - printf("Ps2Gamepad: port %d does not support DualShock mode\n", port); + Log_log("Ps2Gamepad: port %d does not support DualShock mode\n", port); analogModeReady[port] = true; return; } if (padSetMainMode(port, 0, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK) == 0) { - printf("Ps2Gamepad: padSetMainMode failed on port %d\n", port); + Log_log("Ps2Gamepad: padSetMainMode failed on port %d\n", port); return; } if (!waitForRequest(port)) { - printf("Ps2Gamepad: DualShock mode request did not complete on port %d\n", port); + Log_log("Ps2Gamepad: DualShock mode request did not complete on port %d\n", port); return; } analogModeReady[port] = true; - printf("Ps2Gamepad: port %d set to DualShock analog mode\n", port); + Log_log("Ps2Gamepad: port %d set to DualShock analog mode\n", port); } void Ps2Gamepad_poll(RunnerGamepadState* gp, int port) { diff --git a/src/ps3/main.c b/src/ps3/main.c index 55be2d019..8505662d2 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -157,7 +157,7 @@ char *str_replace(char *orig, char *rep, char *with) { static char buffer[9999]; int main(int argc, char* argv[]) { - printf("%s\n", argv[0]); + Log_log("%s\n", argv[0]); if (argc > 0) strcpy(buffer, argv[0]); char* tmp = str_replace(buffer, "butterscotch.elf", ""); @@ -176,7 +176,7 @@ int main(int argc, char* argv[]) { sysUtilRegisterCallback(SYSUTIL_EVENT_SLOT0, sys_callback, NULL); freq = sysGetTimebaseFrequency(); - printf("Loading %s...\n", dataWinPath); + Log_log("Loading %s...\n", dataWinPath); DataWinParserOptions options = {0}; options.parseGen8 = true; @@ -210,7 +210,7 @@ int main(int argc, char* argv[]) { DataWin* dataWin = DataWin_parse(dataWinPath, options); Gen8* gen8 = &dataWin->gen8; - printf("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); + Log_log("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); // Initialize VM VMContext* vm = VM_create(dataWin); @@ -285,7 +285,7 @@ int main(int argc, char* argv[]) { glUseProgram(gPalettedProgram); glUniform1i(uPaletteLoc, 1); glUseProgram(0); - printf("Paletted shader: program=%u uPaletteV=%d uPalette=%d\n", gPalettedProgram, gPalettedUPaletteVLoc, uPaletteLoc); + Log_log("Paletted shader: program=%u uPaletteV=%d uPalette=%d\n", gPalettedProgram, gPalettedUPaletteVLoc, uPaletteLoc); } // Initialize the runner @@ -450,6 +450,6 @@ int main(int argc, char* argv[]) { sysUtilUnregisterCallback(SYSUTIL_EVENT_SLOT0); gcmSetWaitFlip(context); rsxFinish(context,1); - printf("Bye! :3\n"); + Log_log("Bye! :3\n"); return 0; } diff --git a/src/runner.c b/src/runner.c index 0f0f73ed5..3800049be 100644 --- a/src/runner.c +++ b/src/runner.c @@ -4032,9 +4032,9 @@ void Runner_dumpState(Runner* runner) { DataWin* dataWin = runner->dataWin; int32_t instanceCount = (int32_t) arrlen(runner->instances); - printf("=== Frame %d State Dump ===\n", runner->frameCount); - printf("Room: %s (index %d)\n", runner->currentRoom->name, runner->currentRoomIndex); - printf("Instance count: %d\n", instanceCount); + Log_log("=== Frame %d State Dump ===\n", runner->frameCount); + Log_log("Room: %s (index %d)\n", runner->currentRoom->name, runner->currentRoomIndex); + Log_log("Instance count: %d\n", instanceCount); repeat(instanceCount, i) { Instance* inst = runner->instances[i]; @@ -4057,23 +4057,23 @@ void Runner_dumpState(Runner* runner) { parentName = dataWin->objt.objects[gameObject->parentId].name; } - printf("\n--- Instance #%d (%s, objectIndex=%d) ---\n", inst->instanceId, objName, inst->objectIndex); - printf(" Position: (%g, %g)\n", (double) inst->x, (double) inst->y); - printf(" Depth: %d\n", inst->depth); - printf(" Sprite: %s (index %d), imageIndex=%g, imageSpeed=%g\n", spriteName, inst->spriteIndex, (double) inst->imageIndex, (double) inst->imageSpeed); - printf(" Scale: (%g, %g), Angle: %g, Alpha: %g, Blend: 0x%06X\n", (double) inst->imageXscale, (double) inst->imageYscale, (double) inst->imageAngle, (double) inst->imageAlpha, inst->imageBlend); - printf(" Visible: %s, Active: %s, Solid: %s, Persistent: %s\n", inst->visible ? "true" : "false", inst->active ? "true" : "false", inst->solid ? "true" : "false", inst->persistent ? "true" : "false"); - printf(" Parent: %s (parentId=%d)\n", parentName, gameObject != nullptr ? gameObject->parentId : -1); + Log_log("\n--- Instance #%d (%s, objectIndex=%d) ---\n", inst->instanceId, objName, inst->objectIndex); + Log_log(" Position: (%g, %g)\n", (double) inst->x, (double) inst->y); + Log_log(" Depth: %d\n", inst->depth); + Log_log(" Sprite: %s (index %d), imageIndex=%g, imageSpeed=%g\n", spriteName, inst->spriteIndex, (double) inst->imageIndex, (double) inst->imageSpeed); + Log_log(" Scale: (%g, %g), Angle: %g, Alpha: %g, Blend: 0x%06X\n", (double) inst->imageXscale, (double) inst->imageYscale, (double) inst->imageAngle, (double) inst->imageAlpha, inst->imageBlend); + Log_log(" Visible: %s, Active: %s, Solid: %s, Persistent: %s\n", inst->visible ? "true" : "false", inst->active ? "true" : "false", inst->solid ? "true" : "false", inst->persistent ? "true" : "false"); + Log_log(" Parent: %s (parentId=%d)\n", parentName, gameObject != nullptr ? gameObject->parentId : -1); // Active alarms bool hasAlarm = false; repeat(GML_ALARM_COUNT, alarmIdx) { if (inst->alarm[alarmIdx] >= 0) { - if (!hasAlarm) { printf(" Alarms:"); hasAlarm = true; } - printf(" [%d]=%d", (int)alarmIdx, inst->alarm[alarmIdx]); + if (!hasAlarm) { Log_log(" Alarms:"); hasAlarm = true; } + Log_log(" [%d]=%d", (int)alarmIdx, inst->alarm[alarmIdx]); } } - if (hasAlarm) printf("\n"); + if (hasAlarm) Log_log("\n"); // Self variables bool hasSelfVars = false; @@ -4095,25 +4095,25 @@ void Runner_dumpState(Runner* runner) { } if (val.type == RVALUE_ARRAY && val.array != nullptr) { - if (!hasSelfArrays) { printf(" Self Arrays:\n"); hasSelfArrays = true; } + if (!hasSelfArrays) { Log_log(" Self Arrays:\n"); hasSelfArrays = true; } repeat(GMLArray_length1D(val.array), ai) { RValue* cell = GMLArray_slot(val.array, ai); if (cell == nullptr || cell->type == RVALUE_UNDEFINED) continue; char* innerStr = RValue_toStringFancy(*cell); - printf(" %s[%d] = %s\n", varName, (int) ai, innerStr); + Log_log(" %s[%d] = %s\n", varName, (int) ai, innerStr); free(innerStr); } } else { - if (!hasSelfVars) { printf(" Self Variables:\n"); hasSelfVars = true; } + if (!hasSelfVars) { Log_log(" Self Variables:\n"); hasSelfVars = true; } char* valStr = RValue_toStringFancy(val); - printf(" %s = %s\n", varName, valStr); + Log_log(" %s = %s\n", varName, valStr); free(valStr); } } } // Global variables (non-array) - printf("\n=== Global Variables ===\n"); + Log_log("\n=== Global Variables ===\n"); repeat(runner->vmContext->globalScopeInstance->selfVars.capacity, i) { IntRValueEntry entryOnTheVarStruct = runner->vmContext->globalScopeInstance->selfVars.entries[i]; @@ -4127,18 +4127,18 @@ void Runner_dumpState(Runner* runner) { RValue* cell = GMLArray_slot(target.array, ai); if (cell == nullptr || cell->type == RVALUE_UNDEFINED) continue; char* innerStr = RValue_toStringFancy(*cell); - printf(" %s[%d] = %s\n", name, (int) ai, innerStr); + Log_log(" %s[%d] = %s\n", name, (int) ai, innerStr); free(innerStr); } } char* valStr = RValue_toStringTyped(target); - printf(" %s = %s\n", name, valStr); + Log_log(" %s = %s\n", name, valStr); free(valStr); } } - printf("\n=== End Frame %d State Dump ===\n", runner->frameCount); + Log_log("\n=== End Frame %d State Dump ===\n", runner->frameCount); } // ===[ JSON State Dump ]=== diff --git a/src/vm.c b/src/vm.c index 3c4251785..e3f06b60c 100644 --- a/src/vm.c +++ b/src/vm.c @@ -4290,17 +4290,17 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { CodeEntry* code = &dw->code.entries[codeIndex]; // Header - printf("=== %s (length=%u, locals=%u, args=%u) ===\n", code->name, code->length, code->localsCount, code->argumentsCount); + Log_log("=== %s (length=%u, locals=%u, args=%u) ===\n", code->name, code->length, code->localsCount, code->argumentsCount); // CodeLocals CodeLocals* locals = resolveCodeLocals(ctx, code->name); if (locals != nullptr && locals->localVarCount > 0) { - printf("Locals:"); + Log_log("Locals:"); repeat(locals->localVarCount, i) { - if (i > 0) printf(","); - printf(" [%u] %s", locals->locals[i].varID, locals->locals[i].name); + if (i > 0) Log_log(","); + Log_log(" [%u] %s", locals->locals[i].varID, locals->locals[i].name); } - printf("\n"); + Log_log("\n"); } // Cross-references @@ -4308,16 +4308,16 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { ptrdiff_t mapIdx = hmgeti(ctx->crossRefMap, codeIndex); if (mapIdx >= 0) { int32_t* callers = ctx->crossRefMap[mapIdx].value; - printf("Called by:"); + Log_log("Called by:"); for (ptrdiff_t i = 0; arrlen(callers) > i; i++) { - if (i > 0) printf(","); - printf(" %s", dw->code.entries[callers[i]].name); + if (i > 0) Log_log(","); + Log_log(" %s", dw->code.entries[callers[i]].name); } - printf("\n"); + Log_log("\n"); } } - printf("\n"); + Log_log("\n"); const uint8_t* bytecodeBase = dw->bytecodeBuffer + (code->bytecodeAbsoluteOffset - dw->bytecodeBufferBase); uint32_t codeLength = code->length; @@ -4369,7 +4369,7 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { // Print label if this address is a branch target if (hmgeti(branchTargets, instrAddr) >= 0) { - printf(" %04X: L_%04X:\n", instrAddr, instrAddr); + Log_log(" %04X: L_%04X:\n", instrAddr, instrAddr); } int32_t indent = 2 + envDepth * 4; @@ -4381,9 +4381,9 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { // Print the formatted line if (commentStr[0] != '\0') { - printf("%*s%04X (%6d): [0x%08X] %-16s %-45s %s\n", indent, "", instrAddr, instrAddr, instr, opcodeStr, operandStr, commentStr); + Log_log("%*s%04X (%6d): [0x%08X] %-16s %-45s %s\n", indent, "", instrAddr, instrAddr, instr, opcodeStr, operandStr, commentStr); } else { - printf("%*s%04X (%6d): [0x%08X] %-16s %s\n", indent, "", instrAddr, instrAddr, instr, opcodeStr, operandStr); + Log_log("%*s%04X (%6d): [0x%08X] %-16s %s\n", indent, "", instrAddr, instrAddr, instr, opcodeStr, operandStr); } // PushEnv increases depth after printing @@ -4391,7 +4391,7 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { } hmfree(branchTargets); - printf("\n"); + Log_log("\n"); } void VM_registerBuiltin(VMContext* ctx, const char* name, BuiltinFunc func) { diff --git a/src/vm_builtins.c b/src/vm_builtins.c index a60bc0fa5..95be2011f 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -1786,7 +1786,7 @@ static RValue builtin_show_debug_message(MAYBE_UNUSED VMContext* ctx, RValue* ar } char* val = RValue_toString(args[0]); - printf("Game: %s\n", val); + Log_log("Game: %s\n", val); free(val); return RValue_makeUndefined(); @@ -7826,7 +7826,7 @@ static RValue builtin_window_set_caption(VMContext* ctx, MAYBE_UNUSED RValue* ar runner->windowTitle = safeStrdup(val); if (runner->setWindowTitle) { runner->setWindowTitle(val); - printf("Runner: Window title set to: %s\n", val); + Log_log("Runner: Window title set to: %s\n", val); } } diff --git a/src/web/main.c b/src/web/main.c index 8df35a353..e1d35053c 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -53,7 +53,7 @@ int getKeyCount() { } int main() { - printf("Howdy! Loritta is so cute! lol\n"); + Log_log("Howdy! Loritta is so cute! lol\n"); emscripten_exit_with_live_runtime(); return 0; } @@ -206,7 +206,7 @@ void startRunner(const char* gamePath, const char* savesPath) { // But that's how Emscripten works for SOME REASON ctx = emscripten_webgl_create_context("#canvas", &attrs); if (0 >= ctx) { - printf("Failed to create WebGL context: %d\n", (int)ctx); + Log_log("Failed to create WebGL context: %d\n", (int)ctx); abort(); } From 40325ea596ef976de0ce01d64bde1761eb701cf3 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 19:49:00 +0800 Subject: [PATCH 08/57] Fix some things --- src/audio/miniaudio/ma_audio_system.c | 4 ++-- src/audio/web/web_audio_system.c | 2 +- src/desktop/backends/glfw3.c | 2 +- src/desktop/main.c | 2 +- src/gl/gl_renderer.c | 2 +- src/json_reader.c | 24 ++++++++++++------------ src/log.c | 26 ++++++++++++++++---------- src/ps2/gs_renderer.c | 2 +- src/ps3/ps3_textures.c | 2 +- src/vm.c | 2 +- src/vm_builtins.c | 4 ++-- src/web/main.c | 8 ++++---- 12 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/audio/miniaudio/ma_audio_system.c b/src/audio/miniaudio/ma_audio_system.c index 8752011b8..3ff1a71f1 100644 --- a/src/audio/miniaudio/ma_audio_system.c +++ b/src/audio/miniaudio/ma_audio_system.c @@ -793,7 +793,7 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { ma->streams[freeSlot].initialPitch = 1.0f; int32_t streamIndex = AUDIO_STREAM_INDEX_BASE + freeSlot; - Log_logWarning("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); + Log_log("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); return streamIndex; } @@ -825,7 +825,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { free(entry->filePath); entry->filePath = nullptr; entry->active = false; - Log_logWarning("Audio: Destroyed stream %d\n", streamIndex); + Log_log("Audio: Destroyed stream %d\n", streamIndex); return true; } diff --git a/src/audio/web/web_audio_system.c b/src/audio/web/web_audio_system.c index 25f92b5f6..73779f760 100644 --- a/src/audio/web/web_audio_system.c +++ b/src/audio/web/web_audio_system.c @@ -648,7 +648,7 @@ static int32_t webCreateStream(AudioSystem* audio, const char* filename) { ma->streams[freeSlot].filePath = resolved; int32_t streamIndex = WEB_AUDIO_STREAM_INDEX_BASE + freeSlot; - Log_logWarning("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); + Log_log("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); return streamIndex; } diff --git a/src/desktop/backends/glfw3.c b/src/desktop/backends/glfw3.c index 037a8a7c3..32543cff7 100644 --- a/src/desktop/backends/glfw3.c +++ b/src/desktop/backends/glfw3.c @@ -241,7 +241,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) buffer[len] = '\0'; if (buffer[0] != '\0') { if (glfwUpdateGamepadMappings(buffer)) { - Log_logError("Gamepad: Loaded SDL gamecontroller mappings successfully\n"); + Log_log("Gamepad: Loaded SDL gamecontroller mappings successfully\n"); } else { Log_logWarning("Gamepad: Failed to load SDL gamecontroller mappings\n"); } diff --git a/src/desktop/main.c b/src/desktop/main.c index b9daefc0e..153d3b9b2 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -1233,7 +1233,7 @@ int main(int argc, char* argv[]) { if (VM_findBuiltin(vm, name) != nullptr) continue; - Log_logError("- %s\n", name); + Log_log("- %s\n", name); unimplementedCount++; } diff --git a/src/gl/gl_renderer.c b/src/gl/gl_renderer.c index 3925ff35d..02378a556 100644 --- a/src/gl/gl_renderer.c +++ b/src/gl/gl_renderer.c @@ -2009,7 +2009,7 @@ static void glSurfaceResize(Renderer* renderer, int32_t surfaceID, int32_t width gl->surfaceWidth[surfaceID] = width; gl->surfaceHeight[surfaceID] = height; - Log_logError("GL: Resized Surface %u Size (%dx%d)\n", surfaceID, width, height); + Log_log("GL: Resized Surface %u Size (%dx%d)\n", surfaceID, width, height); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint) prevBinding); } diff --git a/src/json_reader.c b/src/json_reader.c index 89cdbca62..5bc06abc8 100644 --- a/src/json_reader.c +++ b/src/json_reader.c @@ -107,7 +107,7 @@ static JsonValue* parseString(JsonParser* parser) { break; } default: - Log_logError("JsonReader: unknown escape sequence '\\%c'\n", escaped); + Log_logWarning("JsonReader: unknown escape sequence '\\%c'\n", escaped); free(buffer); return nullptr; } @@ -122,7 +122,7 @@ static JsonValue* parseString(JsonParser* parser) { } // Unterminated string - Log_logError("JsonReader: unterminated string\n"); + Log_logWarning("JsonReader: unterminated string\n"); free(buffer); return nullptr; } @@ -132,7 +132,7 @@ static JsonValue* parseNumber(JsonParser* parser) { char* end = nullptr; double number = strtod(start, &end); if (end == start) { - Log_logError("JsonReader: invalid number\n"); + Log_logWarning("JsonReader: invalid number\n"); return nullptr; } parser->position += (size_t) (end - start); @@ -183,7 +183,7 @@ static JsonValue* parseArray(JsonParser* parser) { advance(parser); return value; } else { - Log_logError("JsonReader: expected ',' or ']' in array\n"); + Log_logWarning("JsonReader: expected ',' or ']' in array\n"); JsonReader_free(value); return nullptr; } @@ -209,7 +209,7 @@ static JsonValue* parseObject(JsonParser* parser) { while (true) { skipWhitespace(parser); if (peek(parser) != '"') { - Log_logError("JsonReader: expected string key in object\n"); + Log_logWarning("JsonReader: expected string key in object\n"); JsonReader_free(value); return nullptr; } @@ -225,7 +225,7 @@ static JsonValue* parseObject(JsonParser* parser) { skipWhitespace(parser); if (peek(parser) != ':') { - Log_logError("JsonReader: expected ':' after object key\n"); + Log_logWarning("JsonReader: expected ':' after object key\n"); free(key); JsonReader_free(value); return nullptr; @@ -260,7 +260,7 @@ static JsonValue* parseObject(JsonParser* parser) { advance(parser); return value; } else { - Log_logError("JsonReader: expected ',' or '}' in object\n"); + Log_logWarning("JsonReader: expected ',' or '}' in object\n"); JsonReader_free(value); return nullptr; } @@ -292,7 +292,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 't': { JsonValue* value = parseLiteral(parser, "true", 4); if (value == nullptr) { - Log_logError("JsonReader: invalid literal\n"); + Log_logWarning("JsonReader: invalid literal\n"); return nullptr; } value->type = JSON_BOOL; @@ -302,7 +302,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 'f': { JsonValue* value = parseLiteral(parser, "false", 5); if (value == nullptr) { - Log_logError("JsonReader: invalid literal\n"); + Log_logWarning("JsonReader: invalid literal\n"); return nullptr; } value->type = JSON_BOOL; @@ -312,7 +312,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 'n': { JsonValue* value = parseLiteral(parser, "null", 4); if (value == nullptr) { - Log_logError("JsonReader: invalid literal\n"); + Log_logWarning("JsonReader: invalid literal\n"); return nullptr; } return value; @@ -321,7 +321,7 @@ static JsonValue* parseValue(JsonParser* parser) { if (c == '-' || (c >= '0' && c <= '9')) { return parseNumber(parser); } - Log_logError("JsonReader: unexpected character '%c' at position %zu\n", c, parser->position); + Log_logWarning("JsonReader: unexpected character '%c' at position %zu\n", c, parser->position); return nullptr; } } @@ -348,7 +348,7 @@ JsonValue* JsonReader_parse(const char* json) { if (result != nullptr) { skipWhitespace(&parser); if (parser.position < parser.length) { - Log_logError("JsonReader: trailing content after JSON value at position %zu\n", parser.position); + Log_logWarning("JsonReader: trailing content after JSON value at position %zu\n", parser.position); JsonReader_free(result); return nullptr; } diff --git a/src/log.c b/src/log.c index 512fcc162..9b79fe2b2 100644 --- a/src/log.c +++ b/src/log.c @@ -14,6 +14,8 @@ bool logColourFile = false; char* logFile = "./butterscotch.log"; +static FILE* logFileHandle = nullptr; + enum { LOG_TYPE_NORMAL=0, LOG_TYPE_WARNING=1, @@ -43,26 +45,30 @@ static void vLogToTerminal(const int type, const char* fmt, va_list va) { static void vLogToFile(const int type, const char* fmt, va_list va) { if (!logToFile) return; - FILE* file = fopen(logFile, "a"); - if (file == nullptr) return; + if (logFileHandle == nullptr) { + logFileHandle = fopen(logFile, "a"); + if (logFileHandle == nullptr) return; + setvbuf(logFileHandle, nullptr, _IONBF, 0); + } if (logColourFile) { - fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); + fprintf(logFileHandle, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); } - vfprintf(file, fmt, va); + vfprintf(logFileHandle, fmt, va); if (logColourFile) { - fprintf(file, ANSI_COLOUR_CODE_WHITE); + fprintf(logFileHandle, ANSI_COLOUR_CODE_WHITE); } - - fclose(file); } void Log_init() { - FILE* file = fopen(logFile, "w"); - if (file != nullptr) { - fclose(file); + if (logFileHandle != nullptr) { + fclose(logFileHandle); + } + logFileHandle = fopen(logFile, "w"); + if (logFileHandle != nullptr) { + setvbuf(logFileHandle, nullptr, _IONBF, 0); } } diff --git a/src/ps2/gs_renderer.c b/src/ps2/gs_renderer.c index 2e47a6c39..bab8f7563 100644 --- a/src/ps2/gs_renderer.c +++ b/src/ps2/gs_renderer.c @@ -22,7 +22,7 @@ static void rendererPrintf(const char* fmt, ...) { va_list args; va_start(args, fmt); - Log_vLogError(fmt, args); + Log_vLog(fmt, args); va_end(args); } #else diff --git a/src/ps3/ps3_textures.c b/src/ps3/ps3_textures.c index 7e57361c8..d2491dd34 100644 --- a/src/ps3/ps3_textures.c +++ b/src/ps3/ps3_textures.c @@ -112,7 +112,7 @@ bool PS3Textures_init(const char* texturesBinPath) { // Pixel block starts here. Pages are streamed from disk on demand. gPixelBlockBase = ftell(gFp); - Log_logWarning("PS3Textures: opened %s (clutCount=%u pages=%u tpags=%u, streaming pixels)\n", texturesBinPath, gClutCount, gPageCount, gTpagCount); + Log_log("PS3Textures: opened %s (clutCount=%u pages=%u tpags=%u, streaming pixels)\n", texturesBinPath, gClutCount, gPageCount, gTpagCount); gInitialized = true; return true; diff --git a/src/vm.c b/src/vm.c index e3f06b60c..83a3a1856 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2465,7 +2465,7 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { Log_log("=== Opcode Profiler Report ===\n"); Log_log("Total instructions executed: %llu\n", (unsigned long long) total); - Log_logToFile("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); + Log_log("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); forEachIndexed(CountEntry, entry, i, entries, entryCount) { (void) i; double pct = total > 0 ? (100.0 * (double) entry->count / (double) total) : 0.0; diff --git a/src/vm_builtins.c b/src/vm_builtins.c index 95be2011f..87799b966 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -1781,7 +1781,7 @@ void VMBuiltins_setVariable(VMContext* ctx, Instance* inst, int16_t builtinVarId static RValue builtin_show_debug_message(MAYBE_UNUSED VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - Log_logError("[show_debug_message] Expected at least 1 argument\n"); + Log_logWarning("[show_debug_message] Expected at least 1 argument\n"); return RValue_makeUndefined(); } @@ -8332,7 +8332,7 @@ static RValue builtin_action_create_object(VMContext* ctx, RValue* args, int32_t GMLReal x = RValue_toReal(args[1]); GMLReal y = RValue_toReal(args[2]); if (0 > objectIndex || runner->dataWin->objt.count <= (uint32_t) objectIndex) { - Log_logError("VM: action_create_object: objectIndex %d out of range\n", objectIndex); + Log_logWarning("VM: action_create_object: objectIndex %d out of range\n", objectIndex); return RValue_makeUndefined(); } Instance* callerInst = ctx->currentInstance; diff --git a/src/web/main.c b/src/web/main.c index e1d35053c..8ca1d4655 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -163,7 +163,7 @@ void* loop() { } // Cleanup - Log_logError("Cleaning up runner!\n"); + Log_log("Cleaning up runner!\n"); gRunner->audioSystem->vtable->destroy(gRunner->audioSystem); gRunner->audioSystem = nullptr; @@ -189,7 +189,7 @@ void setWindowTitle(const char* title) { // gamePath: WASMFS path to the data.win to load (example: "/butterscotch/games/undertale/data.win"). // savesPath: WASMFS directory where saves should live (example: "/butterscotch/saves/undertale" - Created if it does not exist). void startRunner(const char* gamePath, const char* savesPath) { - Log_logError("Starting runner! gamePath=%s savesPath=%s\n", gamePath, savesPath); + Log_log("Starting runner! gamePath=%s savesPath=%s\n", gamePath, savesPath); EmscriptenWebGLContextAttributes attrs; emscripten_webgl_init_context_attributes(&attrs); @@ -218,7 +218,7 @@ void startRunner(const char* gamePath, const char* savesPath) { // Make sure the saves directory exists. The FileSystem impl will write into it. if (savesPath != nullptr && savesPath[0] != '\0') { if (mkdirP(savesPath) != 0) { - Log_logError("Warning: failed to ensure saves dir exists at %s: %s\n", savesPath, strerror(errno)); + Log_logWarning("Warning: failed to ensure saves dir exists at %s: %s\n", savesPath, strerror(errno)); } } @@ -295,6 +295,6 @@ void startRunner(const char* gamePath, const char* savesPath) { } void stopRunner() { - Log_logError("Marked runner to exit!\n"); + Log_log("Marked runner to exit!\n"); gRunner->shouldExit = true; } From 0a2dfe48ceaa649d978beae68735af08b8d06b5d Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 20:07:51 +0800 Subject: [PATCH 09/57] Fix --- src/android/main.c | 1 + src/desktop/main.c | 3 +-- src/log.c | 8 ++++++++ src/ps2/main.c | 2 ++ src/ps3/main.c | 3 ++- src/web/main.c | 3 ++- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/android/main.c b/src/android/main.c index d1ec5bdb6..2807f6039 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -68,6 +68,7 @@ static JNIEnv* getEnvNoAttach(void) { } JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, MAYBE_UNUSED void* reserved) { + Log_init(); gJvm = vm; JNIEnv* env = nullptr; if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) return JNI_ERR; diff --git a/src/desktop/main.c b/src/desktop/main.c index 153d3b9b2..8a952988b 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -383,8 +383,7 @@ static char** extractRunnerArguments(char* rawArguments) { } static void printUsage(const char *argv0) { - fprintf( - stderr, + Log_log( "Usage: %s \n" " --help - Show this message\n" " --screenshot - Specify the filename for screenshots\n" diff --git a/src/log.c b/src/log.c index 9b79fe2b2..ecd7246bd 100644 --- a/src/log.c +++ b/src/log.c @@ -26,6 +26,14 @@ enum { #define ANSI_COLOUR_CODE_BOLD_YELLOW "\x1b[1;33m" #define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" +void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, char* pLogFile) { + logToTerminal = bLogToTerminal; + logToFile = bLogToFile; + logColourTerminal = bLogColourTerminal; + logColourFile = bLogColourFile; + logFile = pLogFile; +} + static void vLogToTerminal(const int type, const char* fmt, va_list va) { if (!logToTerminal) return; diff --git a/src/ps2/main.c b/src/ps2/main.c index 0642de1bb..fc5a0bce5 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -242,6 +242,8 @@ int main(int argc, char* argv[]) { SifInitRpc(0); sbv_patch_enable_lmb(); + Log_init(); + // Ask the kernel how much main RAM we actually have. MAX_MEMORY_BYTES = (int) GetMemorySize(); diff --git a/src/ps3/main.c b/src/ps3/main.c index 8505662d2..1fde277e9 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -157,7 +157,8 @@ char *str_replace(char *orig, char *rep, char *with) { static char buffer[9999]; int main(int argc, char* argv[]) { - Log_log("%s\n", argv[0]); + Log_init(); + Log_log("%s\n", argv[0]); if (argc > 0) strcpy(buffer, argv[0]); char* tmp = str_replace(buffer, "butterscotch.elf", ""); diff --git a/src/web/main.c b/src/web/main.c index 8ca1d4655..36ac64f02 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -53,7 +53,8 @@ int getKeyCount() { } int main() { - Log_log("Howdy! Loritta is so cute! lol\n"); + Log_init(); + Log_log("Howdy! Loritta is so cute! lol\n"); emscripten_exit_with_live_runtime(); return 0; } From a6153ca02300e134c63265cf2e21f0c6ecfc5d87 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 20:40:30 +0800 Subject: [PATCH 10/57] Add log arguments to desktop --- README.md | 11 ++++++++--- src/desktop/main.c | 38 +++++++++++++++++++++++++++++++++++--- src/log.c | 8 +------- src/log.h | 2 ++ 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ef4d7e23c..7984f95d8 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

-> [!IMPORTANT] +> [!IMPORTANT] > Butterscotch is still VERY early in development and it is NOT that good yet. When you create a game in GameMaker: Studio and export it, GameMaker: Studio exports the game code as bytecode instead of native compiled code, and that bytecode is compatible with any other GameMaker: Studio runner (also known as YoYo runner), as long as they have matching GameMaker: Studio versions. This is similar to how Java applications work. @@ -52,7 +52,7 @@ However, that doesn't mean that a game that uses a compatible version WILL run! Of course, there are exceptions that break game compatibility altogether: -* Games compiled with YYC, because they use native code instead of bytecode. +* Games compiled with YYC, because they use native code instead of bytecode. * Games compiled with the new [GMRT](https://github.com/YoYoGames/GMRT-Beta/tree/main), because they use native code instead of bytecode. ## Supported Platforms @@ -152,6 +152,11 @@ The desktop target has a lot of nifty CLI parameters that you can use to trace a --profile-opcodes - Rank which GML opcodes were executed the most --lazy-textures - Load textures into VRAM on first use, improving startup times --load-type - Specify how data.win is loaded, per-chunk or all at once +--disable-terminal-log - Disables logging to the terminal +--disable-file-log - Disable logging to a file +--log-file - File to log to +--disable-terminal-log-colours - Disable colours for warning and error logs in terminal +--enable-file-log-colours - Enables colours for warning and error logs in file ``` ## Debug Features @@ -172,7 +177,7 @@ Performance is pretty good on any modern computer, but when running on low end t ## Then why not have a transpiler? -The issue with a transpiler is that, if you try transpiling the game in the "naive" way, that is, emitting VM calls like it was the original bytecode, you won't get any +The issue with a transpiler is that, if you try transpiling the game in the "naive" way, that is, emitting VM calls like it was the original bytecode, you won't get any *improvement* from it, you would need to create a *good* transpiler that actually transpiles it into *good* code, and that's way harder. Having a transpiler also have other disadvantages: diff --git a/src/desktop/main.c b/src/desktop/main.c index 8a952988b..04bbdcb89 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -254,6 +254,11 @@ typedef struct { #ifdef ENABLE_VM_OPCODE_PROFILER bool opcodeProfiler; #endif + bool disableTerminalLog; + bool disableFileLog; + const char* logFile; + bool disableTerminalLogColours; + bool enableFileLogColours; } CommandLineArgs; typedef struct { const char* name; YoYoOperatingSystem value; } OsTypeNameEntry; @@ -435,6 +440,11 @@ static void printUsage(const char *argv0) { " --game-args - Arguments to pass to the game\n" " --lazy-textures - Load textures into VRAM on first use, improving startup times\n" " --load-type - Specify how data.win is loaded, per-chunk or all at once\n" + " --disable-terminal-log - Disables logging to the terminal\n" + " --disable-file-log - Disable logging to a file\n" + " --log-file - File to log to\n" + " --disable-terminal-log-colours - Disable colours for warning and error logs in terminal\n" + " --enable-file-log-colours - Enables colours for warning and error logs in file\n" #ifdef EABLE_VM_OPCODE_PROFILER " --profile-opcodes - Rank which GML opcodes were executed the most\n" #endif @@ -494,6 +504,11 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) {"game-args", required_argument, nullptr, 'N'}, {"lazy-textures", no_argument, nullptr, 'L'}, {"load-type", required_argument, nullptr, 999}, + {"disable-terminal-log", no_argument, nullptr, 1001}, + {"disable-file-log", no_argument, nullptr, 1002}, + {"log-file", required_argument, nullptr, 1003}, + {"disable-terminal-log-colours", no_argument, nullptr, 1004}, + {"enable-file-log-colours", no_argument, nullptr, 1005}, #ifdef ENABLE_VM_OPCODE_PROFILER {"profile-opcodes", no_argument, nullptr, 'Q'}, #endif @@ -785,6 +800,21 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } break; } + case 1001: + args->disableTerminalLog = true; + break; + case 1002: + args->disableFileLog = true; + break; + case 1003: + args->logFile = optarg; + break; + case 1004: + args->disableTerminalLogColours = true; + break; + case 1005: + args->enableFileLogColours = true; + break; default: printUsage(argv[0]); exit(1); @@ -1004,15 +1034,17 @@ int main(int argc, char* argv[]) { timeBeginPeriod(1); #endif - Log_init(); - Log_log("Hello world!\n"); Log_logWarning("This is a WARNING!\n"); Log_logError("This is an ERROR!\n"); - CommandLineArgs args; + CommandLineArgs args; parseCommandLineArgs(&args, argc, argv); + Log_setOptions(!args.disableTerminalLog, !args.disableFileLog, !args.disableTerminalLogColours, args.enableFileLogColours, args.logFile ? (char*)args.logFile : "./butterscotch.log"); + + Log_init(); + char* currentDataWinPath = safeStrdup(args.dataWinPath); char** currentGameArgs = args.gameArgs; repeat(arrlen(args.gameArgs), i) { diff --git a/src/log.c b/src/log.c index ecd7246bd..e15057201 100644 --- a/src/log.c +++ b/src/log.c @@ -51,13 +51,7 @@ static void vLogToTerminal(const int type, const char* fmt, va_list va) { } static void vLogToFile(const int type, const char* fmt, va_list va) { - if (!logToFile) return; - - if (logFileHandle == nullptr) { - logFileHandle = fopen(logFile, "a"); - if (logFileHandle == nullptr) return; - setvbuf(logFileHandle, nullptr, _IONBF, 0); - } + if (!logToFile || !logFileHandle) return; if (logColourFile) { fprintf(logFileHandle, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); diff --git a/src/log.h b/src/log.h index 7350466c8..1ae2db2ed 100644 --- a/src/log.h +++ b/src/log.h @@ -2,9 +2,11 @@ #define _BS_LOG_H #include +#include #include void Log_init(); +void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, char* pLogFile); void Log_logToTerminal(const char* fmt, ...); void Log_logToFile(const char* fmt, ...); From 24a7fe743d422cb4574e288a4114a3a4e5b77e29 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Wed, 15 Jul 2026 20:47:48 +0800 Subject: [PATCH 11/57] Fix some things and remove debug logs --- src/desktop/main.c | 4 ---- src/vm.c | 10 +++++----- src/vm_builtins.c | 2 +- src/web/main.c | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index 04bbdcb89..eeb4720f2 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -1034,10 +1034,6 @@ int main(int argc, char* argv[]) { timeBeginPeriod(1); #endif - Log_log("Hello world!\n"); - Log_logWarning("This is a WARNING!\n"); - Log_logError("This is an ERROR!\n"); - CommandLineArgs args; parseCommandLineArgs(&args, argc, argv); diff --git a/src/vm.c b/src/vm.c index 83a3a1856..977349131 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2586,7 +2586,7 @@ static void handleBreakChkIndex(VMContext* ctx, uint32_t instrAddr) { RValue* top = stackPeek(ctx); int32_t idx = RValue_toInt32(*top); if (0 > idx || 32000 <= idx) { - Log_logWarning("VM: chkindex out of bounds: %d at offset %u in %s\n", idx, instrAddr, ctx->currentCodeName); + Log_logError("VM: chkindex out of bounds: %d at offset %u in %s\n", idx, instrAddr, ctx->currentCodeName); abort(); } } @@ -2629,7 +2629,7 @@ static void handleBreakPushAC(VMContext* ctx, uint32_t instrAddr) { int32_t idx = stackPopInt32(ctx); RValue arrayRef = stackPop(ctx); if (arrayRef.type != RVALUE_ARRAY || arrayRef.array == nullptr) { - Log_logWarning("VM: pushac on non-array (type=%d) at offset %u in %s\n", arrayRef.type, instrAddr, ctx->currentCodeName); + Log_logError("VM: pushac on non-array (type=%d) at offset %u in %s\n", arrayRef.type, instrAddr, ctx->currentCodeName); abort(); } GMLArray* parent = arrayRef.array; @@ -2740,7 +2740,7 @@ static void handleBreak(VMContext* ctx, uint32_t instr, uint32_t instrAddr, cons case BREAK_ISNULLISH: handleBreakIsNullish(ctx); break; case BREAK_PUSHREF: handleBreakPushRef(ctx, extraData); break; default: - Log_logWarning("VM: Unknown BREAK sub-opcode %d at offset %u in %s\n", breakType, instrAddr, ctx->currentCodeName); + Log_logError("VM: Unknown BREAK sub-opcode %d at offset %u in %s\n", breakType, instrAddr, ctx->currentCodeName); abort(); } } @@ -2780,7 +2780,7 @@ static RValue executeLoop(VMContext* ctx) { #ifdef ENABLE_WAD17 if (ctx->exception != nullptr) { #ifdef ENABLE_VM_EXCEPTIONS_LOGS - Log_logError("VM: Exception thrown! Stack Top is %d\n", ctx->exceptionHandlerStackTop); + Log_logWarning("VM: Exception thrown! Stack Top is %d\n", ctx->exceptionHandlerStackTop); #endif if (ctx->exceptionHandlerStackTop == 0) { // TODO: When Butterscotch is better, we could have a strict mode that DOES throw a error @@ -3294,7 +3294,7 @@ static RValue executeLoop(VMContext* ctx) { break; default: - Log_logWarning("VM: Unknown opcode 0x%02X at offset %u\n", opcode, instrAddr); + Log_logError("VM: Unknown opcode 0x%02X at offset %u\n", opcode, instrAddr); abort(); } } diff --git a/src/vm_builtins.c b/src/vm_builtins.c index 87799b966..5acaaec40 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -8283,7 +8283,7 @@ static RValue builtin_event_inherited(VMContext* ctx, MAYBE_UNUSED RValue* args, int32_t parentObjectIndex = dataWin->objt.objects[ownerObjectIndex].parentId; if (ctx->traceEventInherited) { - Log_logWarning("VM: [%s] event_inherited owner=%s(%d) parent=%s(%d) event=%s (instanceId=%d)\n", dataWin->objt.objects[inst->objectIndex].name, dataWin->objt.objects[ownerObjectIndex].name, ownerObjectIndex, (0 > parentObjectIndex) ? "none" : dataWin->objt.objects[parentObjectIndex].name, parentObjectIndex, Runner_getEventName(ctx->currentEventType, ctx->currentEventSubtype), inst->instanceId); + Log_log("VM: [%s] event_inherited owner=%s(%d) parent=%s(%d) event=%s (instanceId=%d)\n", dataWin->objt.objects[inst->objectIndex].name, dataWin->objt.objects[ownerObjectIndex].name, ownerObjectIndex, (0 > parentObjectIndex) ? "none" : dataWin->objt.objects[parentObjectIndex].name, parentObjectIndex, Runner_getEventName(ctx->currentEventType, ctx->currentEventSubtype), inst->instanceId); } if (0 > parentObjectIndex) return RValue_makeReal(0.0); diff --git a/src/web/main.c b/src/web/main.c index 36ac64f02..8501e1ea5 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -207,7 +207,7 @@ void startRunner(const char* gamePath, const char* savesPath) { // But that's how Emscripten works for SOME REASON ctx = emscripten_webgl_create_context("#canvas", &attrs); if (0 >= ctx) { - Log_log("Failed to create WebGL context: %d\n", (int)ctx); + Log_logError("Failed to create WebGL context: %d\n", (int)ctx); abort(); } From d98e1dd7889ef10304001f2b3b188a89961a209b Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 08:03:39 +0800 Subject: [PATCH 12/57] Fix some things --- src/desktop/backends/glfw3.c | 2 +- src/desktop/main.c | 2 +- src/vm.c | 2 +- src/vm_builtins.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/desktop/backends/glfw3.c b/src/desktop/backends/glfw3.c index 32543cff7..e6ad00f88 100644 --- a/src/desktop/backends/glfw3.c +++ b/src/desktop/backends/glfw3.c @@ -127,7 +127,7 @@ static bool platformGetWindowFocus(void) { } static void glfwErrorCallback(int code, const char* description) { - Log_logError("GLFW error 0x%x: %s\n", code, description); + Log_logWarning("GLFW error 0x%x: %s\n", code, description); } static int32_t glfwKeyToGml(int glfwKey) { diff --git a/src/desktop/main.c b/src/desktop/main.c index eeb4720f2..bed339b96 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -875,7 +875,7 @@ static void writeFramebufferAsPng(GLuint fbo, int width, int height, const char* int stride = width * 4; unsigned char* pixels = (unsigned char *)safeMalloc(stride * height); if (pixels == nullptr) { - Log_logWarning("Error: Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height); + Log_logWarning("Warning: Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height); return; } diff --git a/src/vm.c b/src/vm.c index 977349131..ec34b4f2e 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2780,7 +2780,7 @@ static RValue executeLoop(VMContext* ctx) { #ifdef ENABLE_WAD17 if (ctx->exception != nullptr) { #ifdef ENABLE_VM_EXCEPTIONS_LOGS - Log_logWarning("VM: Exception thrown! Stack Top is %d\n", ctx->exceptionHandlerStackTop); + Log_logError("VM: Exception thrown! Stack Top is %d\n", ctx->exceptionHandlerStackTop); #endif if (ctx->exceptionHandlerStackTop == 0) { // TODO: When Butterscotch is better, we could have a strict mode that DOES throw a error diff --git a/src/vm_builtins.c b/src/vm_builtins.c index 5acaaec40..e2e1c2d91 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -7105,7 +7105,7 @@ static RValue builtin_file_text_open_read(VMContext* ctx, RValue* args, int32_t int32_t slot = findFreeTextFileSlot(runner); if (0 > slot) { - Log_logError("Warning: Too many open text files!\n"); + Log_logError("Error: Too many open text files!\n"); abort(); } @@ -7135,7 +7135,7 @@ static RValue builtin_file_text_open_write(VMContext* ctx, RValue* args, int32_t int32_t slot = findFreeTextFileSlot(runner); if (0 > slot) { - Log_logError("Warning: Too many open text files!\n"); + Log_logError("Error: Too many open text files!\n"); abort(); } From 848211e37cb0491f8bf7b531dd15c06aa73a410c Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 08:11:43 +0800 Subject: [PATCH 13/57] Fix some more things --- src/log.c | 10 +++++----- src/ps2/debug_font_renderer.c | 2 +- src/ps2/main.c | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/log.c b/src/log.c index e15057201..62fc5cdd3 100644 --- a/src/log.c +++ b/src/log.c @@ -6,13 +6,13 @@ #include "common.h" -bool logToTerminal = true; -bool logToFile = true; +static bool logToTerminal = true; +static bool logToFile = true; -bool logColourTerminal = true; -bool logColourFile = false; +static bool logColourTerminal = true; +static bool logColourFile = false; -char* logFile = "./butterscotch.log"; +static char* logFile = "./butterscotch.log"; static FILE* logFileHandle = nullptr; diff --git a/src/ps2/debug_font_renderer.c b/src/ps2/debug_font_renderer.c index 0999e21b6..0ba85df12 100644 --- a/src/ps2/debug_font_renderer.c +++ b/src/ps2/debug_font_renderer.c @@ -20,7 +20,7 @@ static uint32_t uploadTable(GSGLOBAL* gsGlobal, const void* srcData, size_t srcB uint32_t vramSize = gsKit_texture_size(width, height, psm); uint32_t vramAddr = gsKit_vram_alloc(gsGlobal, vramSize, GSKIT_ALLOC_USERBUFFER); if (vramAddr == GSKIT_ALLOC_ERROR) { - Log_logWarning("DebugFontRenderer: Failed to allocate VRAM for %s\n", what); + Log_logError("DebugFontRenderer: Failed to allocate VRAM for %s\n", what); abort(); } diff --git a/src/ps2/main.c b/src/ps2/main.c index fc5a0bce5..592deaef3 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -296,46 +296,46 @@ int main(int argc, char* argv[]) { int ret; ret = SifExecModuleBuffer(freesio2_irx, size_freesio2_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_log("Failed to load freesio2: %d\n", ret); + Log_logError("Failed to load freesio2: %d\n", ret); return 1; } ret = SifExecModuleBuffer(mcman_irx, size_mcman_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_log("Failed to load mcman: %d\n", ret); + Log_logError("Failed to load mcman: %d\n", ret); return 1; } ret = SifExecModuleBuffer(mcserv_irx, size_mcserv_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_log("Failed to load mcserv: %d\n", ret); + Log_logError("Failed to load mcserv: %d\n", ret); return 1; } ret = mcInit(MC_TYPE_MC); if (0 > ret) { - Log_log("Failed to init libmc: %d\n", ret); + Log_logError("Failed to init libmc: %d\n", ret); return 1; } ret = SifExecModuleBuffer(freepad_irx, size_freepad_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_log("Failed to load freepad: %d\n", ret); + Log_logError("Failed to load freepad: %d\n", ret); return 1; } padInit(0); padOpened[0] = (padPortOpen(0, 0, padBuf[0]) != 0); padOpened[1] = (padPortOpen(1, 0, padBuf[1]) != 0); - if (!padOpened[0])Log_log("Warning: failed to open pad port 0\n"); - if (!padOpened[1])Log_log("Warning: failed to open pad port 1\n"); + if (!padOpened[0]) Log_logWarning("Warning: failed to open pad port 0\n"); + if (!padOpened[1]) Log_logWarning("Warning: failed to open pad port 1\n"); // ===[ Load USB Keyboard IOP Modules ]=== int usbdRet = SifExecModuleBuffer(usbd_irx, size_usbd_irx, 0, nullptr, nullptr); if (0 > usbdRet) { - Log_log("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); + Log_logWarning("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); } else { int kbdRet = SifExecModuleBuffer(ps2kbd_irx, size_ps2kbd_irx, 0, nullptr, nullptr); if (0 > kbdRet) { - Log_log("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); + Log_logWarning("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); } else if (PS2KbdInit() == 0) { - Log_log("Warning: PS2KbdInit failed (keyboard disabled)\n"); + Log_logWarning("Warning: PS2KbdInit failed (keyboard disabled)\n"); } else { PS2KbdSetReadmode(PS2KBD_READMODE_RAW); PS2KbdSetBlockingMode(PS2KBD_NONBLOCKING); @@ -348,11 +348,11 @@ int main(int argc, char* argv[]) { // ===[ Load Audio IOP Modules ]=== ret = SifExecModuleBuffer(freesd_irx, size_freesd_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_log("Failed to load freesd: %d\n", ret); + Log_logError("Failed to load freesd: %d\n", ret); } ret = SifExecModuleBuffer(audsrv_irx, size_audsrv_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_log("Failed to load audsrv: %d\n", ret); + Log_logError("Failed to load audsrv: %d\n", ret); } #endif @@ -363,7 +363,7 @@ int main(int argc, char* argv[]) { padState = padGetState(0, 0); } while (PAD_STATE_STABLE != padState && PAD_STATE_FINDCTP1 != padState); - Log_log("Controller initialized\n"); + Log_log("Controller initialized\n"); // ===[ Load CONFIG.JSN ]=== PS2Overlay_drawStatusScreen(nullptr, "Loading CONFIG.JSN...", false); From 9a9cae5a1539511c138a2c46979f4bee59afc11d Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 08:17:45 +0800 Subject: [PATCH 14/57] Add support for temporarily changing log file --- src/desktop/main.c | 4 +++- src/log.c | 26 ++++++++++++++++++-------- src/log.h | 3 +++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index bed339b96..862bd0102 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -302,9 +302,11 @@ static bool parseOsTypeArg(const char* s, YoYoOperatingSystem* out) { } static void printOsTypeNames(FILE* out) { + Log_setFile(out); forEachIndexed(const OsTypeNameEntry, entry, i, OS_TYPE_NAMES, OS_TYPE_NAMES_COUNT) { - fprintf(out, "%s%s", i > 0 ? ", " : "", entry->name); + Log_log(out, "%s%s", i > 0 ? ", " : "", entry->name); } + Log_resetFile(); } // Resolves the window size for the specified operating system. diff --git a/src/log.c b/src/log.c index 62fc5cdd3..f016a56d9 100644 --- a/src/log.c +++ b/src/log.c @@ -14,6 +14,7 @@ static bool logColourFile = false; static char* logFile = "./butterscotch.log"; +static FILE* logFileHandleBackup = nullptr; static FILE* logFileHandle = nullptr; enum { @@ -26,14 +27,6 @@ enum { #define ANSI_COLOUR_CODE_BOLD_YELLOW "\x1b[1;33m" #define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" -void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, char* pLogFile) { - logToTerminal = bLogToTerminal; - logToFile = bLogToFile; - logColourTerminal = bLogColourTerminal; - logColourFile = bLogColourFile; - logFile = pLogFile; -} - static void vLogToTerminal(const int type, const char* fmt, va_list va) { if (!logToTerminal) return; @@ -71,9 +64,26 @@ void Log_init() { logFileHandle = fopen(logFile, "w"); if (logFileHandle != nullptr) { setvbuf(logFileHandle, nullptr, _IONBF, 0); + logFileHandleBackup = logFileHandle; } } +void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, char* pLogFile) { + logToTerminal = bLogToTerminal; + logToFile = bLogToFile; + logColourTerminal = bLogColourTerminal; + logColourFile = bLogColourFile; + logFile = pLogFile; +} + +void Log_setFile(FILE* file) { + logFileHandle = file; +} + +void Log_resetFile() { + logFileHandle = logFileHandleBackup; +} + void Log_logToTerminal(const char* fmt, ...) { va_list va; diff --git a/src/log.h b/src/log.h index 1ae2db2ed..18727d13f 100644 --- a/src/log.h +++ b/src/log.h @@ -8,6 +8,9 @@ void Log_init(); void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, char* pLogFile); +void Log_setFile(FILE* file); +void Log_resetFile(); + void Log_logToTerminal(const char* fmt, ...); void Log_logToFile(const char* fmt, ...); void Log_log(const char* fmt, ...); From 2a126e2f1a1ac7b070128ecff98a360c929d3688 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 08:35:57 +0800 Subject: [PATCH 15/57] Add support for adding custom files to log to --- src/desktop/main.c | 8 +++----- src/log.c | 51 +++++++++++++++++++++++++++++++++++++++++----- src/log.h | 5 +++++ 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index 862bd0102..9ca00c86b 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -302,11 +302,11 @@ static bool parseOsTypeArg(const char* s, YoYoOperatingSystem* out) { } static void printOsTypeNames(FILE* out) { - Log_setFile(out); + Log_addFile(out); forEachIndexed(const OsTypeNameEntry, entry, i, OS_TYPE_NAMES, OS_TYPE_NAMES_COUNT) { - Log_log(out, "%s%s", i > 0 ? ", " : "", entry->name); + Log_log("%s%s", i > 0 ? ", " : "", entry->name); } - Log_resetFile(); + Log_removeFile(out); } // Resolves the window size for the specified operating system. @@ -1027,8 +1027,6 @@ char* collapseNewlines(const char *input) { return result; } -#include "log.h" - // ===[ MAIN ]=== int main(int argc, char* argv[]) { setbuf(stderr, NULL); diff --git a/src/log.c b/src/log.c index f016a56d9..f1bda2331 100644 --- a/src/log.c +++ b/src/log.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "common.h" @@ -17,6 +18,9 @@ static char* logFile = "./butterscotch.log"; static FILE* logFileHandleBackup = nullptr; static FILE* logFileHandle = nullptr; +static FILE* logFiles[LOG_MAX_FILES]; +static int logFileCount = 0; + enum { LOG_TYPE_NORMAL=0, LOG_TYPE_WARNING=1, @@ -43,24 +47,38 @@ static void vLogToTerminal(const int type, const char* fmt, va_list va) { } } -static void vLogToFile(const int type, const char* fmt, va_list va) { - if (!logToFile || !logFileHandle) return; +static void vLogToFileInternal(FILE* file, const int type, const char* fmt, va_list va) { if (logColourFile) { - fprintf(logFileHandle, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); + fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); } - vfprintf(logFileHandle, fmt, va); + vfprintf(file, fmt, va); if (logColourFile) { - fprintf(logFileHandle, ANSI_COLOUR_CODE_WHITE); + fprintf(file, ANSI_COLOUR_CODE_WHITE); + } +} + + +static void vLogToFile(const int type, const char* fmt, va_list va) { + if (!logToFile || !logFileHandle) return; + + vLogToFileInternal(logFileHandle, type, fmt, va); + + for (int i=0; logFiles[i] != nullptr && i < LOG_MAX_FILES; i++) { + vLogToFileInternal(logFiles[i], type, fmt, va); } } void Log_init() { + memset(logFiles, 0, sizeof(logFiles)); + logFileCount = 0; + if (logFileHandle != nullptr) { fclose(logFileHandle); } + logFileHandle = fopen(logFile, "w"); if (logFileHandle != nullptr) { setvbuf(logFileHandle, nullptr, _IONBF, 0); @@ -84,6 +102,29 @@ void Log_resetFile() { logFileHandle = logFileHandleBackup; } +bool Log_addFile(FILE* file) { + if (logFileCount >= LOG_MAX_FILES) return false; + for (int i=0; logFiles[i] != nullptr && i < LOG_MAX_FILES; i++) { + if (logFiles[i] == file) { + return true; + } + } + logFiles[logFileCount] = file; + logFileCount++; + return true; +} + +bool Log_removeFile(FILE* file) { + for (int i=0; logFiles[i] != nullptr && i < LOG_MAX_FILES; i++) { + if (logFiles[i] == file) { + logFiles[i] = nullptr; + logFileCount--; + return true; + } + } + return false; +} + void Log_logToTerminal(const char* fmt, ...) { va_list va; diff --git a/src/log.h b/src/log.h index 18727d13f..9733fd9f5 100644 --- a/src/log.h +++ b/src/log.h @@ -5,12 +5,17 @@ #include #include +#define LOG_MAX_FILES 16 + void Log_init(); void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, char* pLogFile); void Log_setFile(FILE* file); void Log_resetFile(); +bool Log_addFile(FILE* file); +bool Log_removeFile(FILE* file); + void Log_logToTerminal(const char* fmt, ...); void Log_logToFile(const char* fmt, ...); void Log_log(const char* fmt, ...); From 4bd77883d1af24a8859c03417ab9a60cae514cc3 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 08:56:55 +0800 Subject: [PATCH 16/57] Fix some things --- src/audio/ps2/ps2_audio_system.c | 2 +- src/gl/gl_renderer.c | 2 +- src/input_recording.c | 2 +- src/runner.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/audio/ps2/ps2_audio_system.c b/src/audio/ps2/ps2_audio_system.c index 697a03522..dd87da6d2 100644 --- a/src/audio/ps2/ps2_audio_system.c +++ b/src/audio/ps2/ps2_audio_system.c @@ -82,7 +82,7 @@ static void parseSoundBank(Ps2AudioSystem* ps2) { FILE* f = fopen(path, "rb"); free(path); if (f == nullptr) { - Log_logError("PS2AudioSystem: Could not open SOUNDBNK.BIN\n"); + Log_logWarning("PS2AudioSystem: Could not open SOUNDBNK.BIN\n"); return; } diff --git a/src/gl/gl_renderer.c b/src/gl/gl_renderer.c index 02378a556..e739fde93 100644 --- a/src/gl/gl_renderer.c +++ b/src/gl/gl_renderer.c @@ -866,7 +866,7 @@ bool GLRenderer_ensureTextureLoaded(GLRenderer* gl, uint32_t pageId) { bool gm2022_5 = DataWin_isVersionAtLeast(dw, 2022, 5, 0, 0); uint8_t* pixels = ImageDecoder_decodeToRgba(txtr->blobData, (size_t) txtr->blobSize, gm2022_5, &w, &h); if (pixels == nullptr) { - Log_logError("GL: Failed to decode TXTR page %u\n", pageId); + Log_logWarning("GL: Failed to decode TXTR page %u\n", pageId); return false; } if (!txtr->mapped) { diff --git a/src/input_recording.c b/src/input_recording.c index cfb12821c..35a5c2148 100644 --- a/src/input_recording.c +++ b/src/input_recording.c @@ -214,7 +214,7 @@ bool InputRecording_save(InputRecording* recording) { FILE* f = fopen(recording->recordFilePath, "wb"); if (f == nullptr) { - Log_logError("Error: Could not write input recording to '%s'\n", recording->recordFilePath); + Log_logWarning("Warning: Could not write input recording to '%s'\n", recording->recordFilePath); JsonWriter_free(&w); return false; } diff --git a/src/runner.c b/src/runner.c index 3800049be..bcda96e66 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2308,7 +2308,7 @@ Instance* Runner_createInstanceWithLayer(Runner* runner, GMLReal x, GMLReal y, i if (isObjectDisabled(runner, objectIndex)) return nullptr; RuntimeLayer* rl = Runner_findRuntimeLayerById(runner, layerId); if (rl == nullptr) { - Log_logError("Runner: instance_create_layer: Layer ID %d not found!\n", layerId); + Log_logWarning("Runner: instance_create_layer: Layer ID %d not found!\n", layerId); return nullptr; } Instance* inst = createAndInitInstance(runner, runner->nextInstanceId++, objectIndex, x, y); From 6789f2e1657915fe22c1dc300378f24304b21935 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 09:23:16 +0800 Subject: [PATCH 17/57] Fix some things --- src/data_win.c | 6 +++--- src/desktop/main.c | 4 +--- src/log.c | 6 +++--- src/vm.c | 6 +++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/data_win.c b/src/data_win.c index 07e26b415..de46983bd 100644 --- a/src/data_win.c +++ b/src/data_win.c @@ -1077,7 +1077,7 @@ static void parseACRV(BinaryReader* reader, DataWin* dw) { uint32_t version = BinaryReader_readUint32(reader); if (version != 1) { - Log_logError("ACRV: unexpected version %u (expected 1)\n", version); + Log_logWarning("ACRV: unexpected version %u (expected 1)\n", version); return; } @@ -2552,7 +2552,7 @@ void DataWin_loadTxtrIfNeeded(DataWin* dw, uint32_t textureId) { if (tex->blobData != nullptr) return; if (!dw->lazyLoadFile) { - Log_logError("loadTxtrIfNeeded: called without a lazy load file.\n"); + Log_logWarning("loadTxtrIfNeeded: called without a lazy load file.\n"); return; } @@ -2565,7 +2565,7 @@ void DataWin_loadTxtrIfNeeded(DataWin* dw, uint32_t textureId) { fseek(dw->lazyLoadFile, old_seek, SEEK_SET); if (read != tex->blobSize) { - Log_logError("loadTxtrIfNeeded: couldn't read %u bytes to load a texture.\n", tex->blobSize); + Log_logWarning("loadTxtrIfNeeded: couldn't read %u bytes to load a texture.\n", tex->blobSize); } } diff --git a/src/desktop/main.c b/src/desktop/main.c index 9ca00c86b..adfe40d9b 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -302,11 +302,9 @@ static bool parseOsTypeArg(const char* s, YoYoOperatingSystem* out) { } static void printOsTypeNames(FILE* out) { - Log_addFile(out); forEachIndexed(const OsTypeNameEntry, entry, i, OS_TYPE_NAMES, OS_TYPE_NAMES_COUNT) { - Log_log("%s%s", i > 0 ? ", " : "", entry->name); + fprintf(out, "%s%s", i > 0 ? ", " : "", entry->name); } - Log_removeFile(out); } // Resolves the window size for the specified operating system. diff --git a/src/log.c b/src/log.c index f1bda2331..c42947c57 100644 --- a/src/log.c +++ b/src/log.c @@ -66,7 +66,7 @@ static void vLogToFile(const int type, const char* fmt, va_list va) { vLogToFileInternal(logFileHandle, type, fmt, va); - for (int i=0; logFiles[i] != nullptr && i < LOG_MAX_FILES; i++) { + for (int i=0; i < LOG_MAX_FILES && logFiles[i] != nullptr; i++) { vLogToFileInternal(logFiles[i], type, fmt, va); } } @@ -104,7 +104,7 @@ void Log_resetFile() { bool Log_addFile(FILE* file) { if (logFileCount >= LOG_MAX_FILES) return false; - for (int i=0; logFiles[i] != nullptr && i < LOG_MAX_FILES; i++) { + for (int i=0; i < LOG_MAX_FILES && logFiles[i] != nullptr; i++) { if (logFiles[i] == file) { return true; } @@ -115,7 +115,7 @@ bool Log_addFile(FILE* file) { } bool Log_removeFile(FILE* file) { - for (int i=0; logFiles[i] != nullptr && i < LOG_MAX_FILES; i++) { + for (int i=0; i < LOG_MAX_FILES && logFiles[i] != nullptr; i++) { if (logFiles[i] == file) { logFiles[i] = nullptr; logFileCount--; diff --git a/src/vm.c b/src/vm.c index ec34b4f2e..e90deb2ec 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1175,7 +1175,7 @@ static void handlePush(VMContext* ctx, uint32_t instr, const uint8_t* extraData, // Positive scopes are real instance IDs resolved by lookup. Instance* inst = (0 > scope) ? (Instance*) ctx->currentInstance : VM_findInstanceByTarget(ctx, scope); if (inst == nullptr) { - Log_logWarning("VM: ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); + Log_logError("VM: ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); abort(); } slot = IntRValueHashMap_getOrInsertUndefined(&inst->selfVars, varDef->varID); @@ -1229,7 +1229,7 @@ static void handlePush(VMContext* ctx, uint32_t instr, const uint8_t* extraData, break; } default: - Log_logWarning("VM: Push with unknown type 0x%X\n", type1); + Log_logError("VM: Push with unknown type 0x%X\n", type1); abort(); } } @@ -1270,7 +1270,7 @@ static void handlePushBltn(VMContext* ctx, uint32_t instr, const uint8_t* extraD inst = (Instance*) ctx->currentInstance; } if (inst == nullptr) { - Log_logWarning("VM: PushBltn ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); + Log_logError("VM: PushBltn ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); abort(); } RValue* slot = IntRValueHashMap_getOrInsertUndefined(&inst->selfVars, varDef->varID); From 1308c5b99ba6c20f5a97221ced04c17f6c2e421a Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 09:27:43 +0800 Subject: [PATCH 18/57] Fix --- src/log.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/log.c b/src/log.c index c42947c57..5db74ad51 100644 --- a/src/log.c +++ b/src/log.c @@ -19,7 +19,6 @@ static FILE* logFileHandleBackup = nullptr; static FILE* logFileHandle = nullptr; static FILE* logFiles[LOG_MAX_FILES]; -static int logFileCount = 0; enum { LOG_TYPE_NORMAL=0, @@ -66,14 +65,14 @@ static void vLogToFile(const int type, const char* fmt, va_list va) { vLogToFileInternal(logFileHandle, type, fmt, va); - for (int i=0; i < LOG_MAX_FILES && logFiles[i] != nullptr; i++) { + for (int i=0; i < LOG_MAX_FILES; i++) { + if (!logFiles[i]) continue; vLogToFileInternal(logFiles[i], type, fmt, va); } } void Log_init() { memset(logFiles, 0, sizeof(logFiles)); - logFileCount = 0; if (logFileHandle != nullptr) { fclose(logFileHandle); @@ -103,25 +102,34 @@ void Log_resetFile() { } bool Log_addFile(FILE* file) { - if (logFileCount >= LOG_MAX_FILES) return false; - for (int i=0; i < LOG_MAX_FILES && logFiles[i] != nullptr; i++) { + if (file == nullptr) return false; + + int availableSlot = -1; + for (int i=0; i < LOG_MAX_FILES; i++) { if (logFiles[i] == file) { return true; } + if (logFiles[i] == nullptr) { + availableSlot = i; + } } - logFiles[logFileCount] = file; - logFileCount++; + + if (availableSlot == -1) return false; + + logFiles[availableSlot] = file; return true; } bool Log_removeFile(FILE* file) { - for (int i=0; i < LOG_MAX_FILES && logFiles[i] != nullptr; i++) { + if (file == nullptr) return false; + + for (int i=0; i < LOG_MAX_FILES; i++) { if (logFiles[i] == file) { logFiles[i] = nullptr; - logFileCount--; return true; } } + return false; } From 97ca355859e4285f61c07accf48f34cc2d9f526e Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 09:58:20 +0800 Subject: [PATCH 19/57] Fix some things --- src/android/main.c | 3 ++- src/desktop/main.c | 20 +++++++++++--------- src/log.c | 18 +++++++++++------- src/log.h | 2 +- src/web/main.c | 5 +++-- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/android/main.c b/src/android/main.c index 2807f6039..e05a6f37c 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -68,7 +68,8 @@ static JNIEnv* getEnvNoAttach(void) { } JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, MAYBE_UNUSED void* reserved) { - Log_init(); + Log_setOptions(true, false, false, false, nullptr); + Log_init(); gJvm = vm; JNIEnv* env = nullptr; if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) return JNI_ERR; diff --git a/src/desktop/main.c b/src/desktop/main.c index adfe40d9b..33d9a3dbb 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -302,9 +302,11 @@ static bool parseOsTypeArg(const char* s, YoYoOperatingSystem* out) { } static void printOsTypeNames(FILE* out) { + Log_addFile(out); forEachIndexed(const OsTypeNameEntry, entry, i, OS_TYPE_NAMES, OS_TYPE_NAMES_COUNT) { - fprintf(out, "%s%s", i > 0 ? ", " : "", entry->name); + Log_logToFile("%s%s", i > 0 ? ", " : "", entry->name); } + Log_removeFile(out); } // Resolves the window size for the specified operating system. @@ -440,11 +442,11 @@ static void printUsage(const char *argv0) { " --game-args - Arguments to pass to the game\n" " --lazy-textures - Load textures into VRAM on first use, improving startup times\n" " --load-type - Specify how data.win is loaded, per-chunk or all at once\n" - " --disable-terminal-log - Disables logging to the terminal\n" - " --disable-file-log - Disable logging to a file\n" - " --log-file - File to log to\n" - " --disable-terminal-log-colours - Disable colours for warning and error logs in terminal\n" - " --enable-file-log-colours - Enables colours for warning and error logs in file\n" + " --disable-terminal-log - Disables logging to the terminal\n" + " --disable-file-log - Disable logging to a file\n" + " --log-file - File to log to\n" + " --disable-terminal-log-colours - Disable colours for warning and error logs in terminal\n" + " --enable-file-log-colours - Enables colours for warning and error logs in file\n" #ifdef EABLE_VM_OPCODE_PROFILER " --profile-opcodes - Rank which GML opcodes were executed the most\n" #endif @@ -1032,12 +1034,12 @@ int main(int argc, char* argv[]) { timeBeginPeriod(1); #endif - CommandLineArgs args; + CommandLineArgs args; parseCommandLineArgs(&args, argc, argv); - Log_setOptions(!args.disableTerminalLog, !args.disableFileLog, !args.disableTerminalLogColours, args.enableFileLogColours, args.logFile ? (char*)args.logFile : "./butterscotch.log"); + Log_setOptions(!args.disableTerminalLog, !args.disableFileLog, !args.disableTerminalLogColours, args.enableFileLogColours, args.logFile ? args.logFile : "./butterscotch.log"); - Log_init(); + Log_init(); char* currentDataWinPath = safeStrdup(args.dataWinPath); char** currentGameArgs = args.gameArgs; diff --git a/src/log.c b/src/log.c index 5db74ad51..961034aa8 100644 --- a/src/log.c +++ b/src/log.c @@ -13,7 +13,7 @@ static bool logToFile = true; static bool logColourTerminal = true; static bool logColourFile = false; -static char* logFile = "./butterscotch.log"; +static const char* logFile = "./butterscotch.log"; static FILE* logFileHandleBackup = nullptr; static FILE* logFileHandle = nullptr; @@ -78,19 +78,23 @@ void Log_init() { fclose(logFileHandle); } - logFileHandle = fopen(logFile, "w"); - if (logFileHandle != nullptr) { - setvbuf(logFileHandle, nullptr, _IONBF, 0); - logFileHandleBackup = logFileHandle; + if (logFile != nullptr) { + logFileHandle = fopen(logFile, "w"); + if (logFileHandle != nullptr) { + setvbuf(logFileHandle, nullptr, _IONBF, 0); + logFileHandleBackup = logFileHandle; + } } } -void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, char* pLogFile) { +void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, const char* pLogFile) { logToTerminal = bLogToTerminal; logToFile = bLogToFile; logColourTerminal = bLogColourTerminal; logColourFile = bLogColourFile; - logFile = pLogFile; + if (pLogFile != nullptr) { + logFile = pLogFile; + } } void Log_setFile(FILE* file) { diff --git a/src/log.h b/src/log.h index 9733fd9f5..ad9f74065 100644 --- a/src/log.h +++ b/src/log.h @@ -8,7 +8,7 @@ #define LOG_MAX_FILES 16 void Log_init(); -void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, char* pLogFile); +void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, const char* pLogFile); void Log_setFile(FILE* file); void Log_resetFile(); diff --git a/src/web/main.c b/src/web/main.c index 8501e1ea5..9882f0f7d 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -53,8 +53,9 @@ int getKeyCount() { } int main() { - Log_init(); - Log_log("Howdy! Loritta is so cute! lol\n"); + Log_setOptions(true, false, true, false, nullptr); + Log_init(); + Log_log("Howdy! Loritta is so cute! lol\n"); emscripten_exit_with_live_runtime(); return 0; } From 19ff1f90306fee374c00581a4e871725e14c50f3 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 10:23:02 +0800 Subject: [PATCH 20/57] Fix --- src/desktop/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index 33d9a3dbb..7e28d4561 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -1287,7 +1287,7 @@ int main(int argc, char* argv[]) { if (idx >= 0) { VM_disassemble(vm, vm->codeIndexByName[idx].value); } else { - Log_logWarning("Error: Script '%s' not found in funcMap\n", name); + Log_logWarning("Warning: Script '%s' not found in funcMap\n", name); } } } @@ -1601,9 +1601,9 @@ int main(int argc, char* argv[]) { fwrite(json, 1, strlen(json), f); fputc('\n', f); fclose(f); - Log_log("JSON dump saved: %s\n", filename); + Log_log("JSON dump saved: %s\n", filename); } else { - Log_logWarning("Error: Could not write JSON dump to '%s'\n", filename); + Log_logWarning("Warning: Could not write JSON dump to '%s'\n", filename); } } else { Log_log("%s\n", json); @@ -1709,9 +1709,9 @@ int main(int argc, char* argv[]) { fwrite(json, 1, strlen(json), f); fputc('\n', f); fclose(f); - Log_log("JSON dump saved: %s\n", filename); + Log_log("JSON dump saved: %s\n", filename); } else { - Log_logWarning("Error: Could not write JSON dump to '%s'\n", filename); + Log_logWarning("Warning: Could not write JSON dump to '%s'\n", filename); } } else { Log_log("%s\n", json); From 79b68ff8e4081e645459f094b5391f5d35af3bd9 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 10:56:48 +0800 Subject: [PATCH 21/57] Fix more --- src/ps2/main.c | 4 ++-- src/ps2/ps2_gamepad.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ps2/main.c b/src/ps2/main.c index 592deaef3..c499f1c4a 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -348,11 +348,11 @@ int main(int argc, char* argv[]) { // ===[ Load Audio IOP Modules ]=== ret = SifExecModuleBuffer(freesd_irx, size_freesd_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load freesd: %d\n", ret); + Log_logWarning("Failed to load freesd: %d\n", ret); } ret = SifExecModuleBuffer(audsrv_irx, size_audsrv_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load audsrv: %d\n", ret); + Log_logWarning("Failed to load audsrv: %d\n", ret); } #endif diff --git a/src/ps2/ps2_gamepad.c b/src/ps2/ps2_gamepad.c index 38e35191f..1954ee117 100644 --- a/src/ps2/ps2_gamepad.c +++ b/src/ps2/ps2_gamepad.c @@ -33,17 +33,17 @@ static void setupAnalogMode(int port) { } } if (!supportsDualshock) { - Log_log("Ps2Gamepad: port %d does not support DualShock mode\n", port); + Log_logWarning("Ps2Gamepad: port %d does not support DualShock mode\n", port); analogModeReady[port] = true; return; } if (padSetMainMode(port, 0, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK) == 0) { - Log_log("Ps2Gamepad: padSetMainMode failed on port %d\n", port); + Log_logWarning("Ps2Gamepad: padSetMainMode failed on port %d\n", port); return; } if (!waitForRequest(port)) { - Log_log("Ps2Gamepad: DualShock mode request did not complete on port %d\n", port); + Log_logWarning("Ps2Gamepad: DualShock mode request did not complete on port %d\n", port); return; } analogModeReady[port] = true; From dbaee1df76990ce47b466f200f018e50ac21cf79 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 11:07:57 +0800 Subject: [PATCH 22/57] Add va_copy compatibility macro for msvc --- src/log.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/log.c b/src/log.c index 961034aa8..b0cc2cfde 100644 --- a/src/log.c +++ b/src/log.c @@ -26,6 +26,10 @@ enum { LOG_TYPE_ERROR=2 }; +#if defined(_MSC_VER) && !defined(va_copy) +#define va_copy(d, s) ((d) = (s)) +#endif + #define ANSI_COLOUR_CODE_WHITE "\x1b[0;37m" #define ANSI_COLOUR_CODE_BOLD_YELLOW "\x1b[1;33m" #define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" From a96314f772efaa37e38a4d52c84c088eeff2ba2f Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 11:35:41 +0800 Subject: [PATCH 23/57] Remove msvc va_copy define requirement --- src/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/log.c b/src/log.c index b0cc2cfde..7d597867e 100644 --- a/src/log.c +++ b/src/log.c @@ -26,7 +26,7 @@ enum { LOG_TYPE_ERROR=2 }; -#if defined(_MSC_VER) && !defined(va_copy) +#ifndef va_copy #define va_copy(d, s) ((d) = (s)) #endif From 94ed5fa2ec90f5ebf637d7af0ff0354d2dfafcf5 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 11:44:15 +0800 Subject: [PATCH 24/57] Fix some indentation issues --- src/ps2/main.c | 36 ++++++++++++++++++------------------ src/ps2/ps2_gamepad.c | 10 ++++++---- src/ps3/main.c | 8 ++++---- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/ps2/main.c b/src/ps2/main.c index c499f1c4a..20d96d57a 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -98,7 +98,7 @@ static void parsePadMappings(JsonValue* configRoot, const char* key, PadMapping* JsonValue* gmlKeyVal = JsonReader_getJsonValueByIndex(mappingsObj, i); mappings[i].padButton = (uint16_t) atoi(padButtonStr); mappings[i].gmlKey = (int32_t) JsonReader_getInt(gmlKeyVal); - Log_log("CONFIG.JSN: %s mapping pad=%d -> gmlKey=%d\n", logLabel, mappings[i].padButton, mappings[i].gmlKey); + Log_log("CONFIG.JSN: %s mapping pad=%d -> gmlKey=%d\n", logLabel, mappings[i].padButton, mappings[i].gmlKey); } *outMappings = mappings; *outCount = count; @@ -263,7 +263,7 @@ int main(int argc, char* argv[]) { char* dataWinPath = PS2Utils_createDevicePath("DATA.WIN"); - Log_log("Butterscotch PS2 - Loading %s\n", dataWinPath); + Log_log("Butterscotch PS2 - Loading %s\n", dataWinPath); // ===[ Initialize gsKit ]=== // This must happen first so we can show the loading screen during other init steps @@ -296,27 +296,27 @@ int main(int argc, char* argv[]) { int ret; ret = SifExecModuleBuffer(freesio2_irx, size_freesio2_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load freesio2: %d\n", ret); + Log_logError("Failed to load freesio2: %d\n", ret); return 1; } ret = SifExecModuleBuffer(mcman_irx, size_mcman_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load mcman: %d\n", ret); + Log_logError("Failed to load mcman: %d\n", ret); return 1; } ret = SifExecModuleBuffer(mcserv_irx, size_mcserv_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load mcserv: %d\n", ret); + Log_logError("Failed to load mcserv: %d\n", ret); return 1; } ret = mcInit(MC_TYPE_MC); if (0 > ret) { - Log_logError("Failed to init libmc: %d\n", ret); + Log_logError("Failed to init libmc: %d\n", ret); return 1; } ret = SifExecModuleBuffer(freepad_irx, size_freepad_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load freepad: %d\n", ret); + Log_logError("Failed to load freepad: %d\n", ret); return 1; } @@ -329,18 +329,18 @@ int main(int argc, char* argv[]) { // ===[ Load USB Keyboard IOP Modules ]=== int usbdRet = SifExecModuleBuffer(usbd_irx, size_usbd_irx, 0, nullptr, nullptr); if (0 > usbdRet) { - Log_logWarning("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); + Log_logWarning("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); } else { int kbdRet = SifExecModuleBuffer(ps2kbd_irx, size_ps2kbd_irx, 0, nullptr, nullptr); if (0 > kbdRet) { - Log_logWarning("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); + Log_logWarning("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); } else if (PS2KbdInit() == 0) { - Log_logWarning("Warning: PS2KbdInit failed (keyboard disabled)\n"); + Log_logWarning("Warning: PS2KbdInit failed (keyboard disabled)\n"); } else { PS2KbdSetReadmode(PS2KBD_READMODE_RAW); PS2KbdSetBlockingMode(PS2KBD_NONBLOCKING); kbdAvailable = true; - Log_log("USB keyboard initialized\n"); + Log_log("USB keyboard initialized\n"); } } @@ -348,11 +348,11 @@ int main(int argc, char* argv[]) { // ===[ Load Audio IOP Modules ]=== ret = SifExecModuleBuffer(freesd_irx, size_freesd_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logWarning("Failed to load freesd: %d\n", ret); + Log_logWarning("Failed to load freesd: %d\n", ret); } ret = SifExecModuleBuffer(audsrv_irx, size_audsrv_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logWarning("Failed to load audsrv: %d\n", ret); + Log_logWarning("Failed to load audsrv: %d\n", ret); } #endif @@ -460,7 +460,7 @@ int main(int argc, char* argv[]) { void* heapTop = sbrk(0); int32_t usedBytes = (int32_t) (uintptr_t) heapTop; int32_t freeBytes = MAX_MEMORY_BYTES - usedBytes; - Log_log("Memory after data.win parsing: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); + Log_log("Memory after data.win parsing: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); } FileSystem* fileSystem = Ps2FileSystem_create(configRoot, dataWin->gen8.displayName); @@ -501,7 +501,7 @@ int main(int argc, char* argv[]) { if (elem != nullptr && JsonReader_isString(elem)) { const char* objName = JsonReader_getString(elem); shput(runner->disabledObjects, objName, 1); - Log_log("Disabled object: %s\n", objName); + Log_log("Disabled object: %s\n", objName); } } } @@ -515,14 +515,14 @@ int main(int argc, char* argv[]) { gamepadApiEnabled = JsonReader_getBool(JsonReader_getJsonValueByKey(gamepadObj, "enabled")); } if (gamepadApiEnabled) { - Log_log("CONFIG.JSN: GameMaker gamepad API enabled\n"); + Log_log("CONFIG.JSN: GameMaker gamepad API enabled\n"); } { void* heapTop = sbrk(0); int32_t usedBytes = (int32_t) (uintptr_t) heapTop; int32_t freeBytes = MAX_MEMORY_BYTES - usedBytes; - Log_log("Memory after VM and runner creation: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); + Log_log("Memory after VM and runner creation: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); } PS2Overlay_drawStatusScreen(dataWin->gen8.displayName, "Initializing first room...", true); @@ -634,7 +634,7 @@ int main(int argc, char* argv[]) { int32_t interactVarId = shget(runner->vmContext->varNameMap, "interact"); Instance_setSelfVar(runner->vmContext->globalScopeInstance, interactVarId, RValue_makeInt32(0)); - Log_log("Changed global.interact [%d] value!\n", interactVarId); + Log_log("Changed global.interact [%d] value!\n", interactVarId); } // ===[ Game Logic ]=== diff --git a/src/ps2/ps2_gamepad.c b/src/ps2/ps2_gamepad.c index 1954ee117..67d21386b 100644 --- a/src/ps2/ps2_gamepad.c +++ b/src/ps2/ps2_gamepad.c @@ -5,6 +5,8 @@ #include #include +#include "log.h" + // Track DualShock-mode handshake completion per port so poll() can lazily kick it off if it hasn't run yet. static bool analogModeReady[2] = {false, false}; @@ -33,21 +35,21 @@ static void setupAnalogMode(int port) { } } if (!supportsDualshock) { - Log_logWarning("Ps2Gamepad: port %d does not support DualShock mode\n", port); + Log_logWarning("Ps2Gamepad: port %d does not support DualShock mode\n", port); analogModeReady[port] = true; return; } if (padSetMainMode(port, 0, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK) == 0) { - Log_logWarning("Ps2Gamepad: padSetMainMode failed on port %d\n", port); + Log_logWarning("Ps2Gamepad: padSetMainMode failed on port %d\n", port); return; } if (!waitForRequest(port)) { - Log_logWarning("Ps2Gamepad: DualShock mode request did not complete on port %d\n", port); + Log_logWarning("Ps2Gamepad: DualShock mode request did not complete on port %d\n", port); return; } analogModeReady[port] = true; - Log_log("Ps2Gamepad: port %d set to DualShock analog mode\n", port); + Log_log("Ps2Gamepad: port %d set to DualShock analog mode\n", port); } void Ps2Gamepad_poll(RunnerGamepadState* gp, int port) { diff --git a/src/ps3/main.c b/src/ps3/main.c index 1fde277e9..f959e2e00 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) { sysUtilRegisterCallback(SYSUTIL_EVENT_SLOT0, sys_callback, NULL); freq = sysGetTimebaseFrequency(); - Log_log("Loading %s...\n", dataWinPath); + Log_log("Loading %s...\n", dataWinPath); DataWinParserOptions options = {0}; options.parseGen8 = true; @@ -211,7 +211,7 @@ int main(int argc, char* argv[]) { DataWin* dataWin = DataWin_parse(dataWinPath, options); Gen8* gen8 = &dataWin->gen8; - Log_log("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); + Log_log("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); // Initialize VM VMContext* vm = VM_create(dataWin); @@ -286,7 +286,7 @@ int main(int argc, char* argv[]) { glUseProgram(gPalettedProgram); glUniform1i(uPaletteLoc, 1); glUseProgram(0); - Log_log("Paletted shader: program=%u uPaletteV=%d uPalette=%d\n", gPalettedProgram, gPalettedUPaletteVLoc, uPaletteLoc); + Log_log("Paletted shader: program=%u uPaletteV=%d uPalette=%d\n", gPalettedProgram, gPalettedUPaletteVLoc, uPaletteLoc); } // Initialize the runner @@ -451,6 +451,6 @@ int main(int argc, char* argv[]) { sysUtilUnregisterCallback(SYSUTIL_EVENT_SLOT0); gcmSetWaitFlip(context); rsxFinish(context,1); - Log_log("Bye! :3\n"); + Log_log("Bye! :3\n"); return 0; } From eda431b8ea756cd30bd9a28caf9b58a6aea03020 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 11:45:47 +0800 Subject: [PATCH 25/57] Fix --- src/log.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/log.c b/src/log.c index 7d597867e..99d1f5e78 100644 --- a/src/log.c +++ b/src/log.c @@ -51,7 +51,6 @@ static void vLogToTerminal(const int type, const char* fmt, va_list va) { } static void vLogToFileInternal(FILE* file, const int type, const char* fmt, va_list va) { - if (logColourFile) { fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); } From 912e1548b76efbf97b3e8315a86a55c0ef72c973 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 11:52:00 +0800 Subject: [PATCH 26/57] Reduce redundancy --- src/log.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/log.c b/src/log.c index 99d1f5e78..690d49155 100644 --- a/src/log.c +++ b/src/log.c @@ -34,43 +34,34 @@ enum { #define ANSI_COLOUR_CODE_BOLD_YELLOW "\x1b[1;33m" #define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" -static void vLogToTerminal(const int type, const char* fmt, va_list va) { - if (!logToTerminal) return; - - FILE* out = type == LOG_TYPE_NORMAL ? stdout : stderr; - - if (logColourTerminal) { - fprintf(out, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); - } - - vfprintf(out, fmt, va); - - if (logColourTerminal) { - fprintf(out, ANSI_COLOUR_CODE_WHITE); - } -} - -static void vLogToFileInternal(FILE* file, const int type, const char* fmt, va_list va) { - if (logColourFile) { +static void vLogInternal(FILE* file, bool logColour, const int type, const char* fmt, va_list va) { + if (logColour) { fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); } vfprintf(file, fmt, va); - if (logColourFile) { + if (logColour) { fprintf(file, ANSI_COLOUR_CODE_WHITE); } } +static void vLogToTerminal(const int type, const char* fmt, va_list va) { + if (!logToTerminal) return; + + FILE* out = type == LOG_TYPE_NORMAL ? stdout : stderr; + + vLogInternal(out, logColourTerminal, type, fmt, va); +} static void vLogToFile(const int type, const char* fmt, va_list va) { if (!logToFile || !logFileHandle) return; - vLogToFileInternal(logFileHandle, type, fmt, va); + vLogInternal(logFileHandle, logColourFile, type, fmt, va); for (int i=0; i < LOG_MAX_FILES; i++) { if (!logFiles[i]) continue; - vLogToFileInternal(logFiles[i], type, fmt, va); + vLogInternal(logFiles[i], logColourFile, type, fmt, va); } } From 78da838db2800f004fc2a8726e6c18376170d741 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 11:52:27 +0800 Subject: [PATCH 27/57] No out variable needed --- src/log.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/log.c b/src/log.c index 690d49155..5e26543ac 100644 --- a/src/log.c +++ b/src/log.c @@ -49,9 +49,7 @@ static void vLogInternal(FILE* file, bool logColour, const int type, const char* static void vLogToTerminal(const int type, const char* fmt, va_list va) { if (!logToTerminal) return; - FILE* out = type == LOG_TYPE_NORMAL ? stdout : stderr; - - vLogInternal(out, logColourTerminal, type, fmt, va); + vLogInternal(type == LOG_TYPE_NORMAL ? stdout : stderr, logColourTerminal, type, fmt, va); } static void vLogToFile(const int type, const char* fmt, va_list va) { From a9a97ccff40e65d98ec7bf396f53b5fa56810861 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 11:56:49 +0800 Subject: [PATCH 28/57] Change Log_setFile and Log_resetFile --- src/log.c | 6 +++++- src/log.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/log.c b/src/log.c index 5e26543ac..93980e7bf 100644 --- a/src/log.c +++ b/src/log.c @@ -14,6 +14,7 @@ static bool logColourTerminal = true; static bool logColourFile = false; static const char* logFile = "./butterscotch.log"; +static const char* logFileBackup = "./butterscotch.log"; static FILE* logFileHandleBackup = nullptr; static FILE* logFileHandle = nullptr; @@ -75,6 +76,7 @@ void Log_init() { if (logFileHandle != nullptr) { setvbuf(logFileHandle, nullptr, _IONBF, 0); logFileHandleBackup = logFileHandle; + logFileBackup = logFile; } } } @@ -89,12 +91,14 @@ void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTermina } } -void Log_setFile(FILE* file) { +void Log_setFile(FILE* file, const char* path) { logFileHandle = file; + logFile = path; } void Log_resetFile() { logFileHandle = logFileHandleBackup; + logFile = logFileBackup; } bool Log_addFile(FILE* file) { diff --git a/src/log.h b/src/log.h index ad9f74065..2eebb9fa4 100644 --- a/src/log.h +++ b/src/log.h @@ -10,7 +10,7 @@ void Log_init(); void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, const char* pLogFile); -void Log_setFile(FILE* file); +void Log_setFile(FILE* file, const char* path); void Log_resetFile(); bool Log_addFile(FILE* file); From 92a6f20bde004988093d750b956ee504b8f22e44 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 12:17:19 +0800 Subject: [PATCH 29/57] Fix some indentation issues --- src/desktop/main.c | 62 +++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index 7e28d4561..07e9a1562 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -1126,7 +1126,7 @@ int main(int argc, char* argv[]) { // reflects what each room contains without keeping all of them resident simultaneously. forEachIndexed(Room, room, idx, dataWin->room.rooms, dataWin->room.count) { if (!room->present) { - Log_log("[%d] \n", (int)idx); + Log_log("[%d] \n", (int)idx); continue; } bool loadedHere = false; @@ -1135,7 +1135,7 @@ int main(int argc, char* argv[]) { loadedHere = true; } - Log_log("[%d] %s ()\n", (int)idx, room->name); + Log_log("[%d] %s ()\n", (int)idx, room->name); forEachIndexed(RoomGameObject, roomGameObject, idx2, room->gameObjects, room->gameObjectCount) { if (roomGameObject->objectDefinition < 0 || (uint32_t) roomGameObject->objectDefinition >= dataWin->objt.count) { @@ -1143,7 +1143,7 @@ int main(int argc, char* argv[]) { continue; } GameObject* gameObject = &dataWin->objt.objects[roomGameObject->objectDefinition]; - Log_log( + Log_log( " [%d] %s (x=%d,y=%d,persistent=%d,solid=%d,spriteId=%d,preCreateCode=%d,creationCode=%d)\n", (int)idx2, gameObject->name, @@ -1172,22 +1172,22 @@ int main(int argc, char* argv[]) { repeat(OBJT_EVENT_TYPE_COUNT, e) { totalEvents += obj->eventLists[e].eventCount; } - Log_log("[%u] %s:\n", (unsigned int)idx, obj->name); + Log_log("[%u] %s:\n", (unsigned int)idx, obj->name); if (obj->parentId >= 0 && (uint32_t) obj->parentId < dataWin->objt.count) { - Log_log(" Parent: %s (%d)\n", dataWin->objt.objects[obj->parentId].name, obj->parentId); + Log_log(" Parent: %s (%d)\n", dataWin->objt.objects[obj->parentId].name, obj->parentId); } else { - Log_log(" Parent: none\n"); + Log_log(" Parent: none\n"); } if (obj->spriteId >= 0 && (uint32_t) obj->spriteId < dataWin->sprt.count) { - Log_log(" Sprite: %s (%d)\n", dataWin->sprt.sprites[obj->spriteId].name, obj->spriteId); + Log_log(" Sprite: %s (%d)\n", dataWin->sprt.sprites[obj->spriteId].name, obj->spriteId); } else { - Log_log(" Sprite: none\n"); + Log_log(" Sprite: none\n"); } - Log_log(" Solid: %d\n", obj->solid); - Log_log(" Persistent: %d\n", obj->persistent); - Log_log(" Visible: %d\n", obj->visible); - Log_log(" Depth: %d\n", obj->depth); - Log_log(" Events (%u):\n", totalEvents); + Log_log(" Solid: %d\n", obj->solid); + Log_log(" Persistent: %d\n", obj->persistent); + Log_log(" Visible: %d\n", obj->visible); + Log_log(" Depth: %d\n", obj->depth); + Log_log(" Events (%u):\n", totalEvents); repeat(OBJT_EVENT_TYPE_COUNT, e) { ObjectEventList* list = &obj->eventLists[e]; repeat(list->eventCount, eIdx) { @@ -1195,10 +1195,10 @@ int main(int argc, char* argv[]) { const char* eventName = Runner_getEventName((int32_t) e, (int32_t) event->eventSubtype); int32_t codeId = -1; if (event->actionCount > 0) codeId = event->actions[0].codeId; - Log_log(" %s:\n", eventName); - Log_log(" Sub Type: %u\n", event->eventSubtype); - Log_log(" Code ID: %d\n", codeId); - Log_log(" Actions: %u\n", event->actionCount); + Log_log(" %s:\n", eventName); + Log_log(" Sub Type: %u\n", event->eventSubtype); + Log_log(" Code ID: %d\n", codeId); + Log_log(" Actions: %u\n", event->actionCount); } } } @@ -1209,25 +1209,25 @@ int main(int argc, char* argv[]) { if (args.printShaders) { forEachIndexed(Shader, shader, idx, dataWin->shdr.shaders, dataWin->shdr.count) { - Log_log("[%u] %s:\n", (unsigned int)idx, shader->name); - Log_log("GLSL Vertex Shader:\n"); + Log_log("[%u] %s:\n", (unsigned int)idx, shader->name); + Log_log("GLSL Vertex Shader:\n"); char* glslVertex = collapseNewlines(shader->glsl_Vertex); - Log_log("%s\n", glslVertex); + Log_log("%s\n", glslVertex); free(glslVertex); - Log_log("GLSL Fragment Shader:\n"); + Log_log("GLSL Fragment Shader:\n"); char* glslFragment = collapseNewlines(shader->glsl_Fragment); - Log_log("%s\n", glslFragment); + Log_log("%s\n", glslFragment); free(glslFragment); - Log_log("GLSL ES Vertex Shader:\n"); + Log_log("GLSL ES Vertex Shader:\n"); char* glslESVertex = collapseNewlines(shader->glslES_Vertex); - Log_log("%s\n", glslESVertex); + Log_log("%s\n", glslESVertex); free(glslESVertex); - Log_log("GLSL ES Fragment Shader:\n"); + Log_log("GLSL ES Fragment Shader:\n"); char* glslESFragment = collapseNewlines(shader->glslES_Fragment); - Log_log("%s\n", glslESFragment); + Log_log("%s\n", glslESFragment); free(glslESFragment); } VM_free(vm); @@ -1237,7 +1237,7 @@ int main(int argc, char* argv[]) { if (args.printDeclaredFunctions) { repeat(hmlen(vm->codeIndexByName), i) { - Log_log("[%d] %s\n", vm->codeIndexByName[i].value, vm->codeIndexByName[i].key); + Log_log("[%d] %s\n", vm->codeIndexByName[i].value, vm->codeIndexByName[i].key); } VM_free(vm); DataWin_free(dataWin); @@ -1606,7 +1606,7 @@ int main(int argc, char* argv[]) { Log_logWarning("Warning: Could not write JSON dump to '%s'\n", filename); } } else { - Log_log("%s\n", json); + Log_log("%s\n", json); } free(json); @@ -1651,7 +1651,7 @@ int main(int argc, char* argv[]) { int32_t interactVarId = shget(runner->vmContext->varNameMap, "interact"); Instance_setSelfVar(runner->vmContext->globalScopeInstance, interactVarId, RValue_makeInt32(0)); - Log_log("Changed global.interact [%d] value!\n", interactVarId); + Log_log("Changed global.interact [%d] value!\n", interactVarId); } bool currentKeyDown[GML_KEY_COUNT]; @@ -1714,7 +1714,7 @@ int main(int argc, char* argv[]) { Log_logWarning("Warning: Could not write JSON dump to '%s'\n", filename); } } else { - Log_log("%s\n", json); + Log_log("%s\n", json); } free(json); } @@ -1812,7 +1812,7 @@ int main(int argc, char* argv[]) { #endif if (args.exitAtFrame >= 0 && runner->frameCount >= args.exitAtFrame) { - Log_log("Exiting at frame %d (--exit-at-frame)\n", runner->frameCount); + Log_log("Exiting at frame %d (--exit-at-frame)\n", runner->frameCount); shouldWindowClose = true; } From 1568d417298a17b6eb08a3018c3da85d9834aa4d Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 12:23:35 +0800 Subject: [PATCH 30/57] Add missing log.h in ps3_textures.c --- src/ps3/ps3_textures.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ps3/ps3_textures.c b/src/ps3/ps3_textures.c index d2491dd34..83f38473b 100644 --- a/src/ps3/ps3_textures.c +++ b/src/ps3/ps3_textures.c @@ -4,6 +4,8 @@ #include #include +#include "log.h" + // We stream the texture pages on demand from the file instead of loading everything in RAM. #define PAGE_HEADER_SIZE 12 // u16 w, u16 h, u32 pixelOffset, u32 pixelDataSize From bda338b4c217eb1e49a71a6c30787bdff736bc83 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 12:24:06 +0800 Subject: [PATCH 31/57] Add log.c to web-meta --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 924d470fa..48746cc78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,7 @@ if(PLATFORM STREQUAL "web-meta") set(SOURCES src/data_win.c src/binary_reader.c + src/log.c ) else() file(GLOB SOURCES src/*.c) From 82c76e4741c498b45376d916e151a8d1e3f60e15 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 12:32:22 +0800 Subject: [PATCH 32/57] Fix tests hopefully --- tests/tests.conf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/tests.conf b/tests/tests.conf index 67ea97802..b4a06ccb5 100644 --- a/tests/tests.conf +++ b/tests/tests.conf @@ -1,7 +1,7 @@ tests = [ { name = "Test if collisions are executed sorted in object index order NOT in instance creation order" - butterscotchArgs = ["object-index-iteration-test/data.win", "--headless", "--exit-at-frame", "1"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "object-index-iteration-test/data.win", "--headless", "--exit-at-frame", "1"] expectedStdoutOutput = [ [ "Game: start frame", @@ -13,7 +13,7 @@ tests = [ }, { name = "Test Loritta and the Stars" - butterscotchArgs = ["loritta-and-the-stars/data.win", "--playback-inputs", "loritta-and-the-stars/gameplay.json", "--exit-at-frame", "9000", "--screenshot-surfaces-at-frame", "9000", "--screenshot-surfaces", "loritta-and-the-stars/actual.%d.%d.png", "--headless"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "loritta-and-the-stars/data.win", "--playback-inputs", "loritta-and-the-stars/gameplay.json", "--exit-at-frame", "9000", "--screenshot-surfaces-at-frame", "9000", "--screenshot-surfaces", "loritta-and-the-stars/actual.%d.%d.png", "--headless"] expectedScreenshots = [ { expected = "loritta-and-the-stars/expected.9000.0.png" @@ -24,7 +24,7 @@ tests = [ { name = "Test Undertale PT-BR (WinPack/TranslaTale WAD)" commercialGame = true - butterscotchArgs = ["undertale-ptbr-winpack/data.win", "--playback-inputs", "undertale-ptbr-winpack/gameplay.json", "--exit-at-frame", "730", "--screenshot-surfaces-at-frame", "730", "--screenshot-surfaces", "undertale-ptbr-winpack/actual.%d.%d.png", "--headless", "--lazy-textures"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "undertale-ptbr-winpack/data.win", "--playback-inputs", "undertale-ptbr-winpack/gameplay.json", "--exit-at-frame", "730", "--screenshot-surfaces-at-frame", "730", "--screenshot-surfaces", "undertale-ptbr-winpack/actual.%d.%d.png", "--headless", "--lazy-textures"] expectedStderrOutput = [ [ "DataWin: Allocated new TPAG! Was the WAD built with WinPack? (TranslaTale)" @@ -40,7 +40,7 @@ tests = [ { name = "Test Underfavela (Bogus Sprite Types and Bogus AGPR padding checks)" commercialGame = true - butterscotchArgs = ["underfavela/data.win", "--seed", "0", "--playback-inputs", "underfavela/gameplay.json", "--screenshot-surfaces", "underfavela/actual.%d.%d.png", "--screenshot-surfaces-at-frame", "2000", "--exit-at-frame", "2000", "--headless", "--lazy-textures"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "underfavela/data.win", "--seed", "0", "--playback-inputs", "underfavela/gameplay.json", "--screenshot-surfaces", "underfavela/actual.%d.%d.png", "--screenshot-surfaces-at-frame", "2000", "--exit-at-frame", "2000", "--headless", "--lazy-textures"] expectedScreenshots = [ { expected = "underfavela/expected.2000.0.png" @@ -51,7 +51,7 @@ tests = [ { name = "Test Simple Structs, Methods and Dynamic Methods" commercialGame = false - butterscotchArgs = ["simple-structs-methods-and-dynamic-methods/data.win", "--exit-at-frame", "1"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "simple-structs-methods-and-dynamic-methods/data.win", "--exit-at-frame", "1"] expectedStdoutOutput = [ [ "Game: My name is Loritta Morenitta!", @@ -71,7 +71,7 @@ tests = [ { name = "Test Out of Lives Event Ordering" commercialGame = false - butterscotchArgs = ["lives-and-health-events-check/data.win", "--exit-at-frame", "20", "--headless"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "lives-and-health-events-check/data.win", "--exit-at-frame", "20", "--headless"] expectedStdoutOutput = [ [ "Game: Current lives is 10, decreasing one...", @@ -97,7 +97,7 @@ tests = [ { name = "Test if path_add is creating paths closed by default (DELTARUNE Chapter 4 - Jackenstein)" commercialGame = true - butterscotchArgs = ["deltarune-chapter4-105-beta/data.win", "--playback-inputs", "deltarune-chapter4-105-beta/jackenstein-path-test.json", "--lazy-textures", "--seed", "0", "--screenshot-surfaces", "deltarune-chapter4-105-beta/actual.jackenstein-path-test.%d.%d.png", "--screenshot-surfaces-at-frame", "9473", "--screenshot-surfaces-at-frame", "9474", "--headless", "--exit-at-frame", "9474", "--save-folder", "deltarune-chapter4-105-beta/jackenstein/"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "deltarune-chapter4-105-beta/data.win", "--playback-inputs", "deltarune-chapter4-105-beta/jackenstein-path-test.json", "--lazy-textures", "--seed", "0", "--screenshot-surfaces", "deltarune-chapter4-105-beta/actual.jackenstein-path-test.%d.%d.png", "--screenshot-surfaces-at-frame", "9473", "--screenshot-surfaces-at-frame", "9474", "--headless", "--exit-at-frame", "9474", "--save-folder", "deltarune-chapter4-105-beta/jackenstein/"] expectedScreenshots = [ { expected = "deltarune-chapter4-105-beta/expected.jackenstein-path-test.9473.0.png" @@ -112,7 +112,7 @@ tests = [ { name = "Test struct_get_names and variable_instance_get_names" commercialGame = false - butterscotchArgs = ["struct-get-names-test/data.win", "--exit-at-frame", "1", "--headless"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "struct-get-names-test/data.win", "--exit-at-frame", "1", "--headless"] # The order is not guaranteed by GameMaker, so we also won't check for the exact order expectedStdoutOutput = [ [ "Game: [struct(struct_get_names)] Name is gabrielaName" ], @@ -150,7 +150,7 @@ tests = [ { name = "Test Stack Unwinding" commercialGame = false - butterscotchArgs = ["stack-unwinding/data.win", "--exit-at-frame", "1", "--headless"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "stack-unwinding/data.win", "--exit-at-frame", "1", "--headless"] expectedStdoutOutput = [ [ "Game: Exited loop! Current count is 2047" ], ] @@ -158,7 +158,7 @@ tests = [ { name = "Test try ... catch ... finally" commercialGame = false - butterscotchArgs = ["try-catch-finally-test/data.win", "--exit-at-frame", "1", "--headless"] + butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "try-catch-finally-test/data.win", "--exit-at-frame", "1", "--headless"] expectedStderrOutput = [ [ "VM: The exception handler frame stack is 0, but we have a pending exception to be dispatched! This would've technically crashed the game in the original runner... or we aren't handling exceptions correctly. We'll swallow the exception and hope for the best... (Exception: b)" ] From 08d928d218ff286fa4684c2278e4fecd81ea8287 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 12:43:47 +0800 Subject: [PATCH 33/57] Add logDebug functions --- src/log.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/log.h | 8 ++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/log.c b/src/log.c index 93980e7bf..3ee2c7b4a 100644 --- a/src/log.c +++ b/src/log.c @@ -24,7 +24,8 @@ static FILE* logFiles[LOG_MAX_FILES]; enum { LOG_TYPE_NORMAL=0, LOG_TYPE_WARNING=1, - LOG_TYPE_ERROR=2 + LOG_TYPE_ERROR=2, + LOG_TYPE_DEBUG=3 }; #ifndef va_copy @@ -34,10 +35,11 @@ enum { #define ANSI_COLOUR_CODE_WHITE "\x1b[0;37m" #define ANSI_COLOUR_CODE_BOLD_YELLOW "\x1b[1;33m" #define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" +#define ANSI_COLOUR_CODE_BOLD_PURPLE "\x1b[1;35m" static void vLogInternal(FILE* file, bool logColour, const int type, const char* fmt, va_list va) { if (logColour) { - fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : ANSI_COLOUR_CODE_BOLD_RED))); + fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : (type == LOG_TYPE_ERROR ? ANSI_COLOUR_CODE_BOLD_RED : ANSI_COLOUR_CODE_BOLD_PURPLE)))); } vfprintf(file, fmt, va); @@ -297,3 +299,58 @@ void Log_vLogError(const char* fmt, va_list va) { va_end(va2); } + +void Log_logDebugToTerminal(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); + va_end(va); +} + +void Log_logDebugToFile(const char* fmt, ...) { + va_list va; + + va_start(va, fmt); + vLogToFile(LOG_TYPE_DEBUG, fmt, va); + va_end(va); +} + +void Log_logDebug(const char* fmt, ...) { + va_list va, va2; + + va_start(va, fmt); + va_copy(va2, va); + + if (logToTerminal) { + vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); + } + if (logToFile) { + vLogToFile(LOG_TYPE_DEBUG, fmt, va2); + } + + va_end(va); + va_end(va2); +} + +void Log_vLogDebugToTerminal(const char* fmt, va_list va) { + vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); +} + +void Log_vLogDebugToFile(const char* fmt, va_list va) { + vLogToFile(LOG_TYPE_DEBUG, fmt, va); +} + +void Log_vLogDebug(const char* fmt, va_list va) { + va_list va2; + va_copy(va2, va); + + if (logToTerminal) { + vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); + } + if (logToFile) { + vLogToFile(LOG_TYPE_DEBUG, fmt, va2); + } + + va_end(va2); +} diff --git a/src/log.h b/src/log.h index 2eebb9fa4..8569716d9 100644 --- a/src/log.h +++ b/src/log.h @@ -40,4 +40,12 @@ void Log_vLogErrorToTerminal(const char* fmt, va_list va); void Log_vLogErrorToFile(const char* fmt, va_list va); void Log_vLogError(const char* fmt, va_list va); +void Log_logDebugToTerminal(const char* fmt, ...); +void Log_logDebugToFile(const char* fmt, ...); +void Log_logDebug(const char* fmt, ...); + +void Log_vLogDebugToTerminal(const char* fmt, va_list va); +void Log_vLogDebugToFile(const char* fmt, va_list va); +void Log_vLogDebug(const char* fmt, va_list va); + #endif /* _BS_LOG_H */ From 0928730c8e70c14cb2ff2cd72478d4b3f99f8e93 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 12:50:44 +0800 Subject: [PATCH 34/57] Use the logDebug functions --- src/data_win_print.c | 238 +++++++++++++++++++++---------------------- src/desktop/main.c | 16 +-- src/ps2/main.c | 2 +- src/ps3/main.c | 2 +- src/runner.c | 36 +++---- src/vm.c | 24 ++--- 6 files changed, 159 insertions(+), 159 deletions(-) diff --git a/src/data_win_print.c b/src/data_win_print.c index f3968a365..c17d04fc6 100644 --- a/src/data_win_print.c +++ b/src/data_win_print.c @@ -6,139 +6,139 @@ #include "utils.h" void DataWin_printDebugSummary(DataWin* dataWin) { - Log_log("===== data.win Summary =====\n\n"); + Log_logDebug("===== data.win Summary =====\n\n"); // GEN8 Gen8* g = &dataWin->gen8; - Log_log("-- GEN8 (General Info) --\n"); - Log_log(" Game Name: %s\n", g->name ? g->name : "(null)"); - Log_log(" Display Name: %s\n", g->displayName ? g->displayName : "(null)"); - Log_log(" File Name: %s\n", g->fileName ? g->fileName : "(null)"); - Log_log(" Config: %s\n", g->config ? g->config : "(null)"); - Log_log(" WAD Version: %u\n", g->wadVersion); - Log_log(" Game ID: %u\n", g->gameID); - Log_log(" Version: %u.%u.%u.%u\n", g->major, g->minor, g->release, g->build); - Log_log(" Window Size: %ux%u\n", g->defaultWindowWidth, g->defaultWindowHeight); - Log_log(" Steam App ID: %d\n", g->steamAppID); - Log_log(" Room Order: %u rooms\n", g->roomOrderCount); - Log_log("\n"); + Log_logDebug("-- GEN8 (General Info) --\n"); + Log_logDebug(" Game Name: %s\n", g->name ? g->name : "(null)"); + Log_logDebug(" Display Name: %s\n", g->displayName ? g->displayName : "(null)"); + Log_logDebug(" File Name: %s\n", g->fileName ? g->fileName : "(null)"); + Log_logDebug(" Config: %s\n", g->config ? g->config : "(null)"); + Log_logDebug(" WAD Version: %u\n", g->wadVersion); + Log_logDebug(" Game ID: %u\n", g->gameID); + Log_logDebug(" Version: %u.%u.%u.%u\n", g->major, g->minor, g->release, g->build); + Log_logDebug(" Window Size: %ux%u\n", g->defaultWindowWidth, g->defaultWindowHeight); + Log_logDebug(" Steam App ID: %d\n", g->steamAppID); + Log_logDebug(" Room Order: %u rooms\n", g->roomOrderCount); + Log_logDebug("\n"); // OPTN - Log_log("-- OPTN (Options) --\n"); - Log_log(" Constants: %u\n", dataWin->optn.constantCount); + Log_logDebug("-- OPTN (Options) --\n"); + Log_logDebug(" Constants: %u\n", dataWin->optn.constantCount); if (dataWin->optn.constantCount > 0) { uint32_t show = dataWin->optn.constantCount < 3 ? dataWin->optn.constantCount : 3; forEachIndexed(OptnConstant, constant, idx, dataWin->optn.constants, show) { - Log_log(" [%u] %s = %s\n", (unsigned int)idx, constant->name ? constant->name : "?", constant->value ? constant->value : "?"); + Log_logDebug(" [%u] %s = %s\n", (unsigned int)idx, constant->name ? constant->name : "?", constant->value ? constant->value : "?"); } - if (dataWin->optn.constantCount > 3) Log_log(" ... and %u more\n", dataWin->optn.constantCount - 3); + if (dataWin->optn.constantCount > 3) Log_logDebug(" ... and %u more\n", dataWin->optn.constantCount - 3); } - Log_log("\n"); + Log_logDebug("\n"); // LANG - Log_log("-- LANG (Languages) --\n"); - Log_log(" Languages: %u\n", dataWin->lang.languageCount); - Log_log(" Entries: %u\n", dataWin->lang.entryCount); - Log_log("\n"); + Log_logDebug("-- LANG (Languages) --\n"); + Log_logDebug(" Languages: %u\n", dataWin->lang.languageCount); + Log_logDebug(" Entries: %u\n", dataWin->lang.entryCount); + Log_logDebug("\n"); // EXTN - Log_log("-- EXTN (Extensions) --\n"); - Log_log(" Extensions: %u\n", dataWin->extn.count); + Log_logDebug("-- EXTN (Extensions) --\n"); + Log_logDebug(" Extensions: %u\n", dataWin->extn.count); forEachIndexed(Extension, ext, idx, dataWin->extn.extensions, dataWin->extn.count) { - Log_log(" [%u] %s (%u files)\n", (unsigned int)idx, ext->name ? ext->name : "?", ext->fileCount); + Log_logDebug(" [%u] %s (%u files)\n", (unsigned int)idx, ext->name ? ext->name : "?", ext->fileCount); } - Log_log("\n"); + Log_logDebug("\n"); // SOND - Log_log("-- SOND (Sounds) --\n"); - Log_log(" Sounds: %u\n", dataWin->sond.count); + Log_logDebug("-- SOND (Sounds) --\n"); + Log_logDebug(" Sounds: %u\n", dataWin->sond.count); if (dataWin->sond.count > 0) { uint32_t show = dataWin->sond.count < 3 ? dataWin->sond.count : 3; forEachIndexed(Sound, snd, idx, dataWin->sond.sounds, show) { - Log_log(" [%u] %s (%s)\n", (unsigned int)idx, snd->name ? snd->name : "?", snd->type ? snd->type : "?"); + Log_logDebug(" [%u] %s (%s)\n", (unsigned int)idx, snd->name ? snd->name : "?", snd->type ? snd->type : "?"); } - if (dataWin->sond.count > 3) Log_log(" ... and %u more\n", dataWin->sond.count - 3); + if (dataWin->sond.count > 3) Log_logDebug(" ... and %u more\n", dataWin->sond.count - 3); } - Log_log("\n"); + Log_logDebug("\n"); // AGRP - Log_log("-- AGRP (Audio Groups) --\n"); - Log_log(" Audio Groups: %u\n", dataWin->agrp.count); + Log_logDebug("-- AGRP (Audio Groups) --\n"); + Log_logDebug(" Audio Groups: %u\n", dataWin->agrp.count); forEachIndexed(AudioGroup, ag, idx, dataWin->agrp.audioGroups, dataWin->agrp.count) { - Log_log(" [%u] %s\n", (unsigned int)idx, ag->name ? ag->name : "?"); + Log_logDebug(" [%u] %s\n", (unsigned int)idx, ag->name ? ag->name : "?"); } - Log_log("\n"); + Log_logDebug("\n"); // SPRT - Log_log("-- SPRT (Sprites) --\n"); - Log_log(" Sprites: %u\n", dataWin->sprt.count); + Log_logDebug("-- SPRT (Sprites) --\n"); + Log_logDebug(" Sprites: %u\n", dataWin->sprt.count); if (dataWin->sprt.count > 0) { uint32_t show = dataWin->sprt.count < 3 ? dataWin->sprt.count : 3; forEachIndexed(Sprite, spr, idx, dataWin->sprt.sprites, show) { - Log_log(" [%u] %s (%ux%u, %u frames)\n", (unsigned int)idx, spr->name ? spr->name : "?", spr->width, spr->height, spr->textureCount); + Log_logDebug(" [%u] %s (%ux%u, %u frames)\n", (unsigned int)idx, spr->name ? spr->name : "?", spr->width, spr->height, spr->textureCount); } - if (dataWin->sprt.count > 3) Log_log(" ... and %u more\n", dataWin->sprt.count - 3); + if (dataWin->sprt.count > 3) Log_logDebug(" ... and %u more\n", dataWin->sprt.count - 3); } - Log_log("\n"); + Log_logDebug("\n"); // BGND - Log_log("-- BGND (Backgrounds) --\n"); - Log_log(" Backgrounds: %u\n", dataWin->bgnd.count); + Log_logDebug("-- BGND (Backgrounds) --\n"); + Log_logDebug(" Backgrounds: %u\n", dataWin->bgnd.count); if (dataWin->bgnd.count > 0) { uint32_t show = dataWin->bgnd.count < 3 ? dataWin->bgnd.count : 3; forEachIndexed(Background, bg, idx, dataWin->bgnd.backgrounds, show) { - Log_log(" [%u] %s\n", (unsigned int)idx, bg->name ? bg->name : "?"); + Log_logDebug(" [%u] %s\n", (unsigned int)idx, bg->name ? bg->name : "?"); } - if (dataWin->bgnd.count > 3) Log_log(" ... and %u more\n", dataWin->bgnd.count - 3); + if (dataWin->bgnd.count > 3) Log_logDebug(" ... and %u more\n", dataWin->bgnd.count - 3); } - Log_log("\n"); + Log_logDebug("\n"); // PATH - Log_log("-- PATH (Paths) --\n"); - Log_log(" Paths: %u\n", dataWin->path.count); - Log_log("\n"); + Log_logDebug("-- PATH (Paths) --\n"); + Log_logDebug(" Paths: %u\n", dataWin->path.count); + Log_logDebug("\n"); // SCPT - Log_log("-- SCPT (Scripts) --\n"); - Log_log(" Scripts: %u\n", dataWin->scpt.count); + Log_logDebug("-- SCPT (Scripts) --\n"); + Log_logDebug(" Scripts: %u\n", dataWin->scpt.count); if (dataWin->scpt.count > 0) { uint32_t show = dataWin->scpt.count < 3 ? dataWin->scpt.count : 3; forEachIndexed(Script, scr, idx, dataWin->scpt.scripts, show) { - Log_log(" [%u] %s -> code[%d]\n", (unsigned int)idx, scr->name ? scr->name : "?", scr->codeId); + Log_logDebug(" [%u] %s -> code[%d]\n", (unsigned int)idx, scr->name ? scr->name : "?", scr->codeId); } - if (dataWin->scpt.count > 3) Log_log(" ... and %u more\n", dataWin->scpt.count - 3); + if (dataWin->scpt.count > 3) Log_logDebug(" ... and %u more\n", dataWin->scpt.count - 3); } - Log_log("\n"); + Log_logDebug("\n"); // GLOB - Log_log("-- GLOB (Global Init Scripts) --\n"); - Log_log(" Init Scripts: %u\n", dataWin->glob.count); - Log_log("\n"); + Log_logDebug("-- GLOB (Global Init Scripts) --\n"); + Log_logDebug(" Init Scripts: %u\n", dataWin->glob.count); + Log_logDebug("\n"); // SHDR - Log_log("-- SHDR (Shaders) --\n"); - Log_log(" Shaders: %u\n", dataWin->shdr.count); + Log_logDebug("-- SHDR (Shaders) --\n"); + Log_logDebug(" Shaders: %u\n", dataWin->shdr.count); forEachIndexed(Shader, shdr, idx, dataWin->shdr.shaders, dataWin->shdr.count) { - Log_log(" [%u] %s (version %d)\n", (unsigned int)idx, shdr->name ? shdr->name : "?", shdr->version); + Log_logDebug(" [%u] %s (version %d)\n", (unsigned int)idx, shdr->name ? shdr->name : "?", shdr->version); } - Log_log("\n"); + Log_logDebug("\n"); // FONT - Log_log("-- FONT (Fonts) --\n"); - Log_log(" Fonts: %u\n", dataWin->font.count); + Log_logDebug("-- FONT (Fonts) --\n"); + Log_logDebug(" Fonts: %u\n", dataWin->font.count); forEachIndexed(Font, fnt, idx, dataWin->font.fonts, dataWin->font.count) { - Log_log(" [%u] %s (%s, em=%u, %u glyphs)\n", (unsigned int)idx, fnt->name ? fnt->name : "?", fnt->displayName ? fnt->displayName : "?", fnt->emSize, fnt->glyphCount); + Log_logDebug(" [%u] %s (%s, em=%u, %u glyphs)\n", (unsigned int)idx, fnt->name ? fnt->name : "?", fnt->displayName ? fnt->displayName : "?", fnt->emSize, fnt->glyphCount); } - Log_log("\n"); + Log_logDebug("\n"); // TMLN - Log_log("-- TMLN (Timelines) --\n"); - Log_log(" Timelines: %u\n", dataWin->tmln.count); - Log_log("\n"); + Log_logDebug("-- TMLN (Timelines) --\n"); + Log_logDebug(" Timelines: %u\n", dataWin->tmln.count); + Log_logDebug("\n"); // OBJT - Log_log("-- OBJT (Game Objects) --\n"); - Log_log(" Objects: %u\n", dataWin->objt.count); + Log_logDebug("-- OBJT (Game Objects) --\n"); + Log_logDebug(" Objects: %u\n", dataWin->objt.count); if (dataWin->objt.count > 0) { uint32_t show = dataWin->objt.count < 3 ? dataWin->objt.count : 3; forEachIndexed(GameObject, obj, idx, dataWin->objt.objects, show) { @@ -146,75 +146,75 @@ void DataWin_printDebugSummary(DataWin* dataWin) { repeat(OBJT_EVENT_TYPE_COUNT, e) { totalEvents += obj->eventLists[e].eventCount; } - Log_log(" [%u] %s (sprite=%d, depth=%d, %u events)\n", (unsigned int)idx, obj->name ? obj->name : "?", obj->spriteId, obj->depth, totalEvents); + Log_logDebug(" [%u] %s (sprite=%d, depth=%d, %u events)\n", (unsigned int)idx, obj->name ? obj->name : "?", obj->spriteId, obj->depth, totalEvents); } - if (dataWin->objt.count > 3) Log_log(" ... and %u more\n", dataWin->objt.count - 3); + if (dataWin->objt.count > 3) Log_logDebug(" ... and %u more\n", dataWin->objt.count - 3); } - Log_log("\n"); + Log_logDebug("\n"); // ROOM - Log_log("-- ROOM (Rooms) --\n"); - Log_log(" Rooms: %u\n", dataWin->room.count); + Log_logDebug("-- ROOM (Rooms) --\n"); + Log_logDebug(" Rooms: %u\n", dataWin->room.count); if (dataWin->room.count > 0) { uint32_t show = dataWin->room.count < 3 ? dataWin->room.count : 3; forEachIndexed(Room, rm, idx, dataWin->room.rooms, show) { if (rm->payloadLoaded) { - Log_log(" [%u] %s (%ux%u, %u objects, %u tiles)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height, rm->gameObjectCount, rm->tileCount); + Log_logDebug(" [%u] %s (%ux%u, %u objects, %u tiles)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height, rm->gameObjectCount, rm->tileCount); } else { // Lazy room with payload not yet loaded: gameObjectCount/tileCount would be 0 and misleading. - Log_log(" [%u] %s (%ux%u, payload not loaded)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height); + Log_logDebug(" [%u] %s (%ux%u, payload not loaded)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height); } } - if (dataWin->room.count > 3) Log_log(" ... and %u more\n", dataWin->room.count - 3); + if (dataWin->room.count > 3) Log_logDebug(" ... and %u more\n", dataWin->room.count - 3); } - Log_log("\n"); + Log_logDebug("\n"); // TPAG - Log_log("-- TPAG (Texture Page Items) --\n"); - Log_log(" Items: %u\n", dataWin->tpag.count); - Log_log("\n"); + Log_logDebug("-- TPAG (Texture Page Items) --\n"); + Log_logDebug(" Items: %u\n", dataWin->tpag.count); + Log_logDebug("\n"); // CODE - Log_log("-- CODE (Code Entries) --\n"); - Log_log(" Entries: %u\n", dataWin->code.count); + Log_logDebug("-- CODE (Code Entries) --\n"); + Log_logDebug(" Entries: %u\n", dataWin->code.count); if (dataWin->code.count > 0) { uint32_t show = dataWin->code.count < 3 ? dataWin->code.count : 3; forEachIndexed(CodeEntry, entry, idx, dataWin->code.entries, show) { - Log_log(" [%u] %s (%u bytes, %u locals, %u args)\n", (unsigned int)idx, entry->name ? entry->name : "?", entry->length, entry->localsCount, entry->argumentsCount); + Log_logDebug(" [%u] %s (%u bytes, %u locals, %u args)\n", (unsigned int)idx, entry->name ? entry->name : "?", entry->length, entry->localsCount, entry->argumentsCount); } - if (dataWin->code.count > 3) Log_log(" ... and %u more\n", dataWin->code.count - 3); + if (dataWin->code.count > 3) Log_logDebug(" ... and %u more\n", dataWin->code.count - 3); } - Log_log("\n"); + Log_logDebug("\n"); // VARI - Log_log("-- VARI (Variables) --\n"); - Log_log(" Variables: %u\n", dataWin->vari.variableCount); - Log_log(" Max Locals: %u\n", dataWin->vari.maxLocalVarCount); + Log_logDebug("-- VARI (Variables) --\n"); + Log_logDebug(" Variables: %u\n", dataWin->vari.variableCount); + Log_logDebug(" Max Locals: %u\n", dataWin->vari.maxLocalVarCount); if (dataWin->vari.variableCount > 0) { uint32_t show = dataWin->vari.variableCount < 3 ? dataWin->vari.variableCount : 3; forEachIndexed(Variable, var, idx, dataWin->vari.variables, show) { - Log_log(" [%u] %s (type=%d, id=%d, %u refs)\n", (unsigned int)idx, var->name ? var->name : "?", var->instanceType, var->varID, var->occurrences); + Log_logDebug(" [%u] %s (type=%d, id=%d, %u refs)\n", (unsigned int)idx, var->name ? var->name : "?", var->instanceType, var->varID, var->occurrences); } - if (dataWin->vari.variableCount > 3) Log_log(" ... and %u more\n", dataWin->vari.variableCount - 3); + if (dataWin->vari.variableCount > 3) Log_logDebug(" ... and %u more\n", dataWin->vari.variableCount - 3); } - Log_log("\n"); + Log_logDebug("\n"); // FUNC - Log_log("-- FUNC (Functions) --\n"); - Log_log(" Functions: %u\n", dataWin->func.functionCount); - Log_log(" Code Locals: %u\n", dataWin->func.codeLocalsCount); + Log_logDebug("-- FUNC (Functions) --\n"); + Log_logDebug(" Functions: %u\n", dataWin->func.functionCount); + Log_logDebug(" Code Locals: %u\n", dataWin->func.codeLocalsCount); if (dataWin->func.functionCount > 0) { uint32_t show = dataWin->func.functionCount < 3 ? dataWin->func.functionCount : 3; forEachIndexed(Function, fn, idx, dataWin->func.functions, show) { - Log_log(" [%u] %s (%u refs)\n", (unsigned int)idx, fn->name ? fn->name : "?", fn->occurrences); + Log_logDebug(" [%u] %s (%u refs)\n", (unsigned int)idx, fn->name ? fn->name : "?", fn->occurrences); } - if (dataWin->func.functionCount > 3) Log_log(" ... and %u more\n", dataWin->func.functionCount - 3); + if (dataWin->func.functionCount > 3) Log_logDebug(" ... and %u more\n", dataWin->func.functionCount - 3); } - Log_log("\n"); + Log_logDebug("\n"); // STRG - Log_log("-- STRG (Strings) --\n"); - Log_log(" Strings: %u\n", dataWin->strg.count); + Log_logDebug("-- STRG (Strings) --\n"); + Log_logDebug(" Strings: %u\n", dataWin->strg.count); if (dataWin->strg.count > 0) { uint32_t show = dataWin->strg.count < 5 ? dataWin->strg.count : 5; repeat(show, i) { @@ -223,56 +223,56 @@ void DataWin_printDebugSummary(DataWin* dataWin) { if (str) { size_t len = strlen(str); if (len > 60) { - Log_log(" [%u] \"%.60s...\" (%zu chars)\n", (unsigned int)i, str, len); + Log_logDebug(" [%u] \"%.60s...\" (%zu chars)\n", (unsigned int)i, str, len); } else { - Log_log(" [%u] \"%s\"\n", (unsigned int)i, str); + Log_logDebug(" [%u] \"%s\"\n", (unsigned int)i, str); } } else { - Log_log(" [%u] (null)\n", (unsigned int)i); + Log_logDebug(" [%u] (null)\n", (unsigned int)i); } } - if (dataWin->strg.count > 5) Log_log(" ... and %u more\n", dataWin->strg.count - 5); + if (dataWin->strg.count > 5) Log_logDebug(" ... and %u more\n", dataWin->strg.count - 5); } - Log_log("\n"); + Log_logDebug("\n"); // TXTR - Log_log("-- TXTR (Textures) --\n"); - Log_log(" Textures: %u\n", dataWin->txtr.count); + Log_logDebug("-- TXTR (Textures) --\n"); + Log_logDebug(" Textures: %u\n", dataWin->txtr.count); if (dataWin->txtr.count > 0) { forEachIndexed(Texture, tex, idx, dataWin->txtr.textures, dataWin->txtr.count) { - Log_log(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, tex->blobOffset, tex->blobSize); + Log_logDebug(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, tex->blobOffset, tex->blobSize); } } - Log_log("\n"); + Log_logDebug("\n"); // AUDO - Log_log("-- AUDO (Audio) --\n"); - Log_log(" Audio Entries: %u\n", dataWin->audo.count); + Log_logDebug("-- AUDO (Audio) --\n"); + Log_logDebug(" Audio Entries: %u\n", dataWin->audo.count); if (dataWin->audo.count > 0) { uint32_t show = dataWin->audo.count < 3 ? dataWin->audo.count : 3; forEachIndexed(AudioEntry, ae, idx, dataWin->audo.entries, show) { - Log_log(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, ae->dataOffset, ae->dataSize); + Log_logDebug(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, ae->dataOffset, ae->dataSize); } - if (dataWin->audo.count > 3) Log_log(" ... and %u more\n", dataWin->audo.count - 3); + if (dataWin->audo.count > 3) Log_logDebug(" ... and %u more\n", dataWin->audo.count - 3); } - Log_log("\n"); + Log_logDebug("\n"); - Log_log("-- Room Instances --\n"); + Log_logDebug("-- Room Instances --\n"); forEach(Room, room, dataWin->room.rooms, dataWin->room.count) { - Log_log("Room %s\n", room->name); + Log_logDebug("Room %s\n", room->name); if (!room->payloadLoaded) { - Log_log(" (payload not loaded)\n"); + Log_logDebug(" (payload not loaded)\n"); continue; } forEachIndexed(RoomGameObject, roomGameObject, idx, room->gameObjects, room->gameObjectCount) { int32_t objectDefinitionId = roomGameObject->objectDefinition; GameObject* objectDefinition = &dataWin->objt.objects[objectDefinitionId]; - Log_log(" Object %d (%s, x=%d, y=%d)\n", objectDefinitionId, objectDefinition->name, roomGameObject->x, roomGameObject->y); + Log_logDebug(" Object %d (%s, x=%d, y=%d)\n", objectDefinitionId, objectDefinition->name, roomGameObject->x, roomGameObject->y); } } // Overall summary - Log_log("===== DataWin parse complete =====\n"); + Log_logDebug("===== DataWin parse complete =====\n"); } diff --git a/src/desktop/main.c b/src/desktop/main.c index 07e9a1562..ae70f2384 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -1539,7 +1539,7 @@ int main(int argc, char* argv[]) { // Pause if (RunnerKeyboard_checkPressed(runner->keyboard, 'P')) { debugPaused = !debugPaused; - Log_log("Debug: %s\n", debugPaused ? "Paused" : "Resumed"); + Log_logDebug("Debug: %s\n", debugPaused ? "Paused" : "Resumed"); } } @@ -1547,7 +1547,7 @@ int main(int argc, char* argv[]) { bool shouldStep = true; if (runner->debugMode && debugPaused) { shouldStep = RunnerKeyboard_checkPressed(runner->keyboard, 'O'); - if (shouldStep) Log_log("Debug: Frame advance (frame %d)\n", runner->frameCount); + if (shouldStep) Log_logDebug("Debug: Frame advance (frame %d)\n", runner->frameCount); } uint64_t frameStartTime = 0; @@ -1568,7 +1568,7 @@ int main(int argc, char* argv[]) { int32_t nextIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition + 1]; runner->pendingRoom = nextIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_log("Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); + Log_logDebug("Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); } } @@ -1579,18 +1579,18 @@ int main(int argc, char* argv[]) { int32_t prevIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition - 1]; runner->pendingRoom = prevIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_log("Debug: Going to previous room -> %s\n", dw->room.rooms[prevIdx].name); + Log_logDebug("Debug: Going to previous room -> %s\n", dw->room.rooms[prevIdx].name); } } // Dump runner state to console if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F12)) { - Log_log("Debug: Dumping runner state at frame %d\n", runner->frameCount); + Log_logDebug("Debug: Dumping runner state at frame %d\n", runner->frameCount); Runner_dumpState(runner); } if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F11)) { - Log_log("Debug: Dumping runner state at frame %d\n", runner->frameCount); + Log_logDebug("Debug: Dumping runner state at frame %d\n", runner->frameCount); char* json = Runner_dumpStateJson(runner); if (args.dumpJsonFilePattern != nullptr) { @@ -1615,7 +1615,7 @@ int main(int argc, char* argv[]) { // Toggle the collision mask debug overlay if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F2)) { debugShowCollisionMasks = !debugShowCollisionMasks; - Log_log("Debug: Collision mask overlay %s!\n", debugShowCollisionMasks ? "enabled" : "disabled"); + Log_logDebug("Debug: Collision mask overlay %s!\n", debugShowCollisionMasks ? "enabled" : "disabled"); } // Enable free cam @@ -1625,7 +1625,7 @@ int main(int argc, char* argv[]) { runner->freeCamZoom = 1.0f; freeCamActive = !freeCamActive; - Log_log("Debug: Free cam %s!\n", freeCamActive ? "enabled" : "disabled"); + Log_logDebug("Debug: Free cam %s!\n", freeCamActive ? "enabled" : "disabled"); } if (freeCamActive) { diff --git a/src/ps2/main.c b/src/ps2/main.c index 20d96d57a..dd2fafd4e 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -609,7 +609,7 @@ int main(int argc, char* argv[]) { int32_t nextIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition + 1]; runner->pendingRoom = nextIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_log("Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); + Log_logDebug("Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); } } diff --git a/src/ps3/main.c b/src/ps3/main.c index f959e2e00..33b644c00 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -311,7 +311,7 @@ int main(int argc, char* argv[]) { bool shouldStep = true; if (runner->debugMode && debugPaused) { shouldStep = RunnerKeyboard_checkPressed(runner->keyboard, 'O'); - if (shouldStep) Log_log("Debug: Frame advance (frame %d)\n", runner->frameCount); + if (shouldStep) Log_logDebug("Debug: Frame advance (frame %d)\n", runner->frameCount); } diff --git a/src/runner.c b/src/runner.c index bcda96e66..f29de472d 100644 --- a/src/runner.c +++ b/src/runner.c @@ -4032,9 +4032,9 @@ void Runner_dumpState(Runner* runner) { DataWin* dataWin = runner->dataWin; int32_t instanceCount = (int32_t) arrlen(runner->instances); - Log_log("=== Frame %d State Dump ===\n", runner->frameCount); - Log_log("Room: %s (index %d)\n", runner->currentRoom->name, runner->currentRoomIndex); - Log_log("Instance count: %d\n", instanceCount); + Log_logDebug("=== Frame %d State Dump ===\n", runner->frameCount); + Log_logDebug("Room: %s (index %d)\n", runner->currentRoom->name, runner->currentRoomIndex); + Log_logDebug("Instance count: %d\n", instanceCount); repeat(instanceCount, i) { Instance* inst = runner->instances[i]; @@ -4057,23 +4057,23 @@ void Runner_dumpState(Runner* runner) { parentName = dataWin->objt.objects[gameObject->parentId].name; } - Log_log("\n--- Instance #%d (%s, objectIndex=%d) ---\n", inst->instanceId, objName, inst->objectIndex); - Log_log(" Position: (%g, %g)\n", (double) inst->x, (double) inst->y); - Log_log(" Depth: %d\n", inst->depth); - Log_log(" Sprite: %s (index %d), imageIndex=%g, imageSpeed=%g\n", spriteName, inst->spriteIndex, (double) inst->imageIndex, (double) inst->imageSpeed); - Log_log(" Scale: (%g, %g), Angle: %g, Alpha: %g, Blend: 0x%06X\n", (double) inst->imageXscale, (double) inst->imageYscale, (double) inst->imageAngle, (double) inst->imageAlpha, inst->imageBlend); - Log_log(" Visible: %s, Active: %s, Solid: %s, Persistent: %s\n", inst->visible ? "true" : "false", inst->active ? "true" : "false", inst->solid ? "true" : "false", inst->persistent ? "true" : "false"); - Log_log(" Parent: %s (parentId=%d)\n", parentName, gameObject != nullptr ? gameObject->parentId : -1); + Log_logDebug("\n--- Instance #%d (%s, objectIndex=%d) ---\n", inst->instanceId, objName, inst->objectIndex); + Log_logDebug(" Position: (%g, %g)\n", (double) inst->x, (double) inst->y); + Log_logDebug(" Depth: %d\n", inst->depth); + Log_logDebug(" Sprite: %s (index %d), imageIndex=%g, imageSpeed=%g\n", spriteName, inst->spriteIndex, (double) inst->imageIndex, (double) inst->imageSpeed); + Log_logDebug(" Scale: (%g, %g), Angle: %g, Alpha: %g, Blend: 0x%06X\n", (double) inst->imageXscale, (double) inst->imageYscale, (double) inst->imageAngle, (double) inst->imageAlpha, inst->imageBlend); + Log_logDebug(" Visible: %s, Active: %s, Solid: %s, Persistent: %s\n", inst->visible ? "true" : "false", inst->active ? "true" : "false", inst->solid ? "true" : "false", inst->persistent ? "true" : "false"); + Log_logDebug(" Parent: %s (parentId=%d)\n", parentName, gameObject != nullptr ? gameObject->parentId : -1); // Active alarms bool hasAlarm = false; repeat(GML_ALARM_COUNT, alarmIdx) { if (inst->alarm[alarmIdx] >= 0) { if (!hasAlarm) { Log_log(" Alarms:"); hasAlarm = true; } - Log_log(" [%d]=%d", (int)alarmIdx, inst->alarm[alarmIdx]); + Log_logDebug(" [%d]=%d", (int)alarmIdx, inst->alarm[alarmIdx]); } } - if (hasAlarm) Log_log("\n"); + if (hasAlarm) Log_logDebug("\n"); // Self variables bool hasSelfVars = false; @@ -4100,20 +4100,20 @@ void Runner_dumpState(Runner* runner) { RValue* cell = GMLArray_slot(val.array, ai); if (cell == nullptr || cell->type == RVALUE_UNDEFINED) continue; char* innerStr = RValue_toStringFancy(*cell); - Log_log(" %s[%d] = %s\n", varName, (int) ai, innerStr); + Log_logDebug(" %s[%d] = %s\n", varName, (int) ai, innerStr); free(innerStr); } } else { if (!hasSelfVars) { Log_log(" Self Variables:\n"); hasSelfVars = true; } char* valStr = RValue_toStringFancy(val); - Log_log(" %s = %s\n", varName, valStr); + Log_logDebug(" %s = %s\n", varName, valStr); free(valStr); } } } // Global variables (non-array) - Log_log("\n=== Global Variables ===\n"); + Log_logDebug("\n=== Global Variables ===\n"); repeat(runner->vmContext->globalScopeInstance->selfVars.capacity, i) { IntRValueEntry entryOnTheVarStruct = runner->vmContext->globalScopeInstance->selfVars.entries[i]; @@ -4127,18 +4127,18 @@ void Runner_dumpState(Runner* runner) { RValue* cell = GMLArray_slot(target.array, ai); if (cell == nullptr || cell->type == RVALUE_UNDEFINED) continue; char* innerStr = RValue_toStringFancy(*cell); - Log_log(" %s[%d] = %s\n", name, (int) ai, innerStr); + Log_logDebug(" %s[%d] = %s\n", name, (int) ai, innerStr); free(innerStr); } } char* valStr = RValue_toStringTyped(target); - Log_log(" %s = %s\n", name, valStr); + Log_logDebug(" %s = %s\n", name, valStr); free(valStr); } } - Log_log("\n=== End Frame %d State Dump ===\n", runner->frameCount); + Log_logDebug("\n=== End Frame %d State Dump ===\n", runner->frameCount); } // ===[ JSON State Dump ]=== diff --git a/src/vm.c b/src/vm.c index e90deb2ec..80d860ed8 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2463,17 +2463,17 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { entries[j] = tmp; } - Log_log("=== Opcode Profiler Report ===\n"); - Log_log("Total instructions executed: %llu\n", (unsigned long long) total); - Log_log("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); + Log_logDebug("=== Opcode Profiler Report ===\n"); + Log_logDebug("Total instructions executed: %llu\n", (unsigned long long) total); + Log_logDebug("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); forEachIndexed(CountEntry, entry, i, entries, entryCount) { (void) i; double pct = total > 0 ? (100.0 * (double) entry->count / (double) total) : 0.0; - Log_log("%-12s 0x%02X %16llu %7.2f%%\n", opcodeName((uint8_t) entry->key), (uint8_t) entry->key, (unsigned long long) entry->count, pct); + Log_logDebug("%-12s 0x%02X %16llu %7.2f%%\n", opcodeName((uint8_t) entry->key), (uint8_t) entry->key, (unsigned long long) entry->count, pct); } // Per-opcode breakdown by type variant. Sorted within each opcode by count desc. - Log_log("\n--- Type variant breakdown (per opcode) ---\n"); + Log_logDebug("\n--- Type variant breakdown (per opcode) ---\n"); forEachIndexed(CountEntry, entry, idx, entries, entryCount) { (void) idx; uint8_t opcode = (uint8_t) entry->key; @@ -2498,13 +2498,13 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { variantEntries[j] = tmp; } - Log_log("%s (0x%02X): %llu total\n", opcodeName(opcode), opcode, (unsigned long long) entry->count); + Log_logDebug("%s (0x%02X): %llu total\n", opcodeName(opcode), opcode, (unsigned long long) entry->count); forEachIndexed(CountEntry, ve, vi, variantEntries, variantCount) { (void) vi; uint8_t type1 = (uint8_t) ((ve->key >> 4) & 0xF); uint8_t type2 = (uint8_t) (ve->key & 0xF); double vpct = entry->count > 0 ? (100.0 * (double) ve->count / (double) entry->count) : 0.0; - Log_log(" .%c.%c %16llu %7.2f%%\n", gmlTypeChar(type1), gmlTypeChar(type2), (unsigned long long) ve->count, vpct); + Log_logDebug(" .%c.%c %16llu %7.2f%%\n", gmlTypeChar(type1), gmlTypeChar(type2), (unsigned long long) ve->count, vpct); } // Runtime RValue type breakdown (a, b types observed at execution time) @@ -2531,13 +2531,13 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { } rvEntries[j] = tmp; } - Log_log(" -- runtime types (a, b):\n"); + Log_logDebug(" -- runtime types (a, b):\n"); forEachIndexed(CountEntry, re, ri, rvEntries, rvCount) { (void) ri; uint8_t typeA = (uint8_t) ((re->key >> 4) & 0xF); uint8_t typeB = (uint8_t) (re->key & 0xF); double rpct = rvTotal > 0 ? (100.0 * (double) re->count / (double) rvTotal) : 0.0; - Log_log(" (%-6s, %-6s) %16llu %7.2f%%\n", rvalueTypeName(typeA), rvalueTypeName(typeB), (unsigned long long) re->count, rpct); + Log_logDebug(" (%-6s, %-6s) %16llu %7.2f%%\n", rvalueTypeName(typeA), rvalueTypeName(typeB), (unsigned long long) re->count, rpct); } } } @@ -2562,16 +2562,16 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { } breakEntries[j] = tmp; } - Log_log(" -- sub-opcodes:\n"); + Log_logDebug(" -- sub-opcodes:\n"); forEachIndexed(CountEntry, be, bi, breakEntries, breakCount) { (void) bi; int16_t breakType = (int16_t) -((int) be->key); double bpct = entry->count > 0 ? (100.0 * (double) be->count / (double) entry->count) : 0.0; - Log_log(" %-12s (%4d) %16llu %7.2f%%\n", breakSubOpName(breakType), (int) breakType, (unsigned long long) be->count, bpct); + Log_logDebug(" %-12s (%4d) %16llu %7.2f%%\n", breakSubOpName(breakType), (int) breakType, (unsigned long long) be->count, bpct); } } } - Log_log("==============================\n"); + Log_logDebug("==============================\n"); } #endif // ENABLE_VM_OPCODE_PROFILER From 6a6c1704dd290777cd3427fe3809934c77fa3bcd Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 13:47:30 +0800 Subject: [PATCH 35/57] Add "Debug: " prefix to logDebug --- src/data_win_print.c | 238 +++++++++++++++++++++---------------------- src/desktop/main.c | 20 ++-- src/log.c | 4 + src/ps2/main.c | 2 +- src/ps3/main.c | 2 +- src/runner.c | 36 +++---- src/vm.c | 24 ++--- 7 files changed, 165 insertions(+), 161 deletions(-) diff --git a/src/data_win_print.c b/src/data_win_print.c index c17d04fc6..f3968a365 100644 --- a/src/data_win_print.c +++ b/src/data_win_print.c @@ -6,139 +6,139 @@ #include "utils.h" void DataWin_printDebugSummary(DataWin* dataWin) { - Log_logDebug("===== data.win Summary =====\n\n"); + Log_log("===== data.win Summary =====\n\n"); // GEN8 Gen8* g = &dataWin->gen8; - Log_logDebug("-- GEN8 (General Info) --\n"); - Log_logDebug(" Game Name: %s\n", g->name ? g->name : "(null)"); - Log_logDebug(" Display Name: %s\n", g->displayName ? g->displayName : "(null)"); - Log_logDebug(" File Name: %s\n", g->fileName ? g->fileName : "(null)"); - Log_logDebug(" Config: %s\n", g->config ? g->config : "(null)"); - Log_logDebug(" WAD Version: %u\n", g->wadVersion); - Log_logDebug(" Game ID: %u\n", g->gameID); - Log_logDebug(" Version: %u.%u.%u.%u\n", g->major, g->minor, g->release, g->build); - Log_logDebug(" Window Size: %ux%u\n", g->defaultWindowWidth, g->defaultWindowHeight); - Log_logDebug(" Steam App ID: %d\n", g->steamAppID); - Log_logDebug(" Room Order: %u rooms\n", g->roomOrderCount); - Log_logDebug("\n"); + Log_log("-- GEN8 (General Info) --\n"); + Log_log(" Game Name: %s\n", g->name ? g->name : "(null)"); + Log_log(" Display Name: %s\n", g->displayName ? g->displayName : "(null)"); + Log_log(" File Name: %s\n", g->fileName ? g->fileName : "(null)"); + Log_log(" Config: %s\n", g->config ? g->config : "(null)"); + Log_log(" WAD Version: %u\n", g->wadVersion); + Log_log(" Game ID: %u\n", g->gameID); + Log_log(" Version: %u.%u.%u.%u\n", g->major, g->minor, g->release, g->build); + Log_log(" Window Size: %ux%u\n", g->defaultWindowWidth, g->defaultWindowHeight); + Log_log(" Steam App ID: %d\n", g->steamAppID); + Log_log(" Room Order: %u rooms\n", g->roomOrderCount); + Log_log("\n"); // OPTN - Log_logDebug("-- OPTN (Options) --\n"); - Log_logDebug(" Constants: %u\n", dataWin->optn.constantCount); + Log_log("-- OPTN (Options) --\n"); + Log_log(" Constants: %u\n", dataWin->optn.constantCount); if (dataWin->optn.constantCount > 0) { uint32_t show = dataWin->optn.constantCount < 3 ? dataWin->optn.constantCount : 3; forEachIndexed(OptnConstant, constant, idx, dataWin->optn.constants, show) { - Log_logDebug(" [%u] %s = %s\n", (unsigned int)idx, constant->name ? constant->name : "?", constant->value ? constant->value : "?"); + Log_log(" [%u] %s = %s\n", (unsigned int)idx, constant->name ? constant->name : "?", constant->value ? constant->value : "?"); } - if (dataWin->optn.constantCount > 3) Log_logDebug(" ... and %u more\n", dataWin->optn.constantCount - 3); + if (dataWin->optn.constantCount > 3) Log_log(" ... and %u more\n", dataWin->optn.constantCount - 3); } - Log_logDebug("\n"); + Log_log("\n"); // LANG - Log_logDebug("-- LANG (Languages) --\n"); - Log_logDebug(" Languages: %u\n", dataWin->lang.languageCount); - Log_logDebug(" Entries: %u\n", dataWin->lang.entryCount); - Log_logDebug("\n"); + Log_log("-- LANG (Languages) --\n"); + Log_log(" Languages: %u\n", dataWin->lang.languageCount); + Log_log(" Entries: %u\n", dataWin->lang.entryCount); + Log_log("\n"); // EXTN - Log_logDebug("-- EXTN (Extensions) --\n"); - Log_logDebug(" Extensions: %u\n", dataWin->extn.count); + Log_log("-- EXTN (Extensions) --\n"); + Log_log(" Extensions: %u\n", dataWin->extn.count); forEachIndexed(Extension, ext, idx, dataWin->extn.extensions, dataWin->extn.count) { - Log_logDebug(" [%u] %s (%u files)\n", (unsigned int)idx, ext->name ? ext->name : "?", ext->fileCount); + Log_log(" [%u] %s (%u files)\n", (unsigned int)idx, ext->name ? ext->name : "?", ext->fileCount); } - Log_logDebug("\n"); + Log_log("\n"); // SOND - Log_logDebug("-- SOND (Sounds) --\n"); - Log_logDebug(" Sounds: %u\n", dataWin->sond.count); + Log_log("-- SOND (Sounds) --\n"); + Log_log(" Sounds: %u\n", dataWin->sond.count); if (dataWin->sond.count > 0) { uint32_t show = dataWin->sond.count < 3 ? dataWin->sond.count : 3; forEachIndexed(Sound, snd, idx, dataWin->sond.sounds, show) { - Log_logDebug(" [%u] %s (%s)\n", (unsigned int)idx, snd->name ? snd->name : "?", snd->type ? snd->type : "?"); + Log_log(" [%u] %s (%s)\n", (unsigned int)idx, snd->name ? snd->name : "?", snd->type ? snd->type : "?"); } - if (dataWin->sond.count > 3) Log_logDebug(" ... and %u more\n", dataWin->sond.count - 3); + if (dataWin->sond.count > 3) Log_log(" ... and %u more\n", dataWin->sond.count - 3); } - Log_logDebug("\n"); + Log_log("\n"); // AGRP - Log_logDebug("-- AGRP (Audio Groups) --\n"); - Log_logDebug(" Audio Groups: %u\n", dataWin->agrp.count); + Log_log("-- AGRP (Audio Groups) --\n"); + Log_log(" Audio Groups: %u\n", dataWin->agrp.count); forEachIndexed(AudioGroup, ag, idx, dataWin->agrp.audioGroups, dataWin->agrp.count) { - Log_logDebug(" [%u] %s\n", (unsigned int)idx, ag->name ? ag->name : "?"); + Log_log(" [%u] %s\n", (unsigned int)idx, ag->name ? ag->name : "?"); } - Log_logDebug("\n"); + Log_log("\n"); // SPRT - Log_logDebug("-- SPRT (Sprites) --\n"); - Log_logDebug(" Sprites: %u\n", dataWin->sprt.count); + Log_log("-- SPRT (Sprites) --\n"); + Log_log(" Sprites: %u\n", dataWin->sprt.count); if (dataWin->sprt.count > 0) { uint32_t show = dataWin->sprt.count < 3 ? dataWin->sprt.count : 3; forEachIndexed(Sprite, spr, idx, dataWin->sprt.sprites, show) { - Log_logDebug(" [%u] %s (%ux%u, %u frames)\n", (unsigned int)idx, spr->name ? spr->name : "?", spr->width, spr->height, spr->textureCount); + Log_log(" [%u] %s (%ux%u, %u frames)\n", (unsigned int)idx, spr->name ? spr->name : "?", spr->width, spr->height, spr->textureCount); } - if (dataWin->sprt.count > 3) Log_logDebug(" ... and %u more\n", dataWin->sprt.count - 3); + if (dataWin->sprt.count > 3) Log_log(" ... and %u more\n", dataWin->sprt.count - 3); } - Log_logDebug("\n"); + Log_log("\n"); // BGND - Log_logDebug("-- BGND (Backgrounds) --\n"); - Log_logDebug(" Backgrounds: %u\n", dataWin->bgnd.count); + Log_log("-- BGND (Backgrounds) --\n"); + Log_log(" Backgrounds: %u\n", dataWin->bgnd.count); if (dataWin->bgnd.count > 0) { uint32_t show = dataWin->bgnd.count < 3 ? dataWin->bgnd.count : 3; forEachIndexed(Background, bg, idx, dataWin->bgnd.backgrounds, show) { - Log_logDebug(" [%u] %s\n", (unsigned int)idx, bg->name ? bg->name : "?"); + Log_log(" [%u] %s\n", (unsigned int)idx, bg->name ? bg->name : "?"); } - if (dataWin->bgnd.count > 3) Log_logDebug(" ... and %u more\n", dataWin->bgnd.count - 3); + if (dataWin->bgnd.count > 3) Log_log(" ... and %u more\n", dataWin->bgnd.count - 3); } - Log_logDebug("\n"); + Log_log("\n"); // PATH - Log_logDebug("-- PATH (Paths) --\n"); - Log_logDebug(" Paths: %u\n", dataWin->path.count); - Log_logDebug("\n"); + Log_log("-- PATH (Paths) --\n"); + Log_log(" Paths: %u\n", dataWin->path.count); + Log_log("\n"); // SCPT - Log_logDebug("-- SCPT (Scripts) --\n"); - Log_logDebug(" Scripts: %u\n", dataWin->scpt.count); + Log_log("-- SCPT (Scripts) --\n"); + Log_log(" Scripts: %u\n", dataWin->scpt.count); if (dataWin->scpt.count > 0) { uint32_t show = dataWin->scpt.count < 3 ? dataWin->scpt.count : 3; forEachIndexed(Script, scr, idx, dataWin->scpt.scripts, show) { - Log_logDebug(" [%u] %s -> code[%d]\n", (unsigned int)idx, scr->name ? scr->name : "?", scr->codeId); + Log_log(" [%u] %s -> code[%d]\n", (unsigned int)idx, scr->name ? scr->name : "?", scr->codeId); } - if (dataWin->scpt.count > 3) Log_logDebug(" ... and %u more\n", dataWin->scpt.count - 3); + if (dataWin->scpt.count > 3) Log_log(" ... and %u more\n", dataWin->scpt.count - 3); } - Log_logDebug("\n"); + Log_log("\n"); // GLOB - Log_logDebug("-- GLOB (Global Init Scripts) --\n"); - Log_logDebug(" Init Scripts: %u\n", dataWin->glob.count); - Log_logDebug("\n"); + Log_log("-- GLOB (Global Init Scripts) --\n"); + Log_log(" Init Scripts: %u\n", dataWin->glob.count); + Log_log("\n"); // SHDR - Log_logDebug("-- SHDR (Shaders) --\n"); - Log_logDebug(" Shaders: %u\n", dataWin->shdr.count); + Log_log("-- SHDR (Shaders) --\n"); + Log_log(" Shaders: %u\n", dataWin->shdr.count); forEachIndexed(Shader, shdr, idx, dataWin->shdr.shaders, dataWin->shdr.count) { - Log_logDebug(" [%u] %s (version %d)\n", (unsigned int)idx, shdr->name ? shdr->name : "?", shdr->version); + Log_log(" [%u] %s (version %d)\n", (unsigned int)idx, shdr->name ? shdr->name : "?", shdr->version); } - Log_logDebug("\n"); + Log_log("\n"); // FONT - Log_logDebug("-- FONT (Fonts) --\n"); - Log_logDebug(" Fonts: %u\n", dataWin->font.count); + Log_log("-- FONT (Fonts) --\n"); + Log_log(" Fonts: %u\n", dataWin->font.count); forEachIndexed(Font, fnt, idx, dataWin->font.fonts, dataWin->font.count) { - Log_logDebug(" [%u] %s (%s, em=%u, %u glyphs)\n", (unsigned int)idx, fnt->name ? fnt->name : "?", fnt->displayName ? fnt->displayName : "?", fnt->emSize, fnt->glyphCount); + Log_log(" [%u] %s (%s, em=%u, %u glyphs)\n", (unsigned int)idx, fnt->name ? fnt->name : "?", fnt->displayName ? fnt->displayName : "?", fnt->emSize, fnt->glyphCount); } - Log_logDebug("\n"); + Log_log("\n"); // TMLN - Log_logDebug("-- TMLN (Timelines) --\n"); - Log_logDebug(" Timelines: %u\n", dataWin->tmln.count); - Log_logDebug("\n"); + Log_log("-- TMLN (Timelines) --\n"); + Log_log(" Timelines: %u\n", dataWin->tmln.count); + Log_log("\n"); // OBJT - Log_logDebug("-- OBJT (Game Objects) --\n"); - Log_logDebug(" Objects: %u\n", dataWin->objt.count); + Log_log("-- OBJT (Game Objects) --\n"); + Log_log(" Objects: %u\n", dataWin->objt.count); if (dataWin->objt.count > 0) { uint32_t show = dataWin->objt.count < 3 ? dataWin->objt.count : 3; forEachIndexed(GameObject, obj, idx, dataWin->objt.objects, show) { @@ -146,75 +146,75 @@ void DataWin_printDebugSummary(DataWin* dataWin) { repeat(OBJT_EVENT_TYPE_COUNT, e) { totalEvents += obj->eventLists[e].eventCount; } - Log_logDebug(" [%u] %s (sprite=%d, depth=%d, %u events)\n", (unsigned int)idx, obj->name ? obj->name : "?", obj->spriteId, obj->depth, totalEvents); + Log_log(" [%u] %s (sprite=%d, depth=%d, %u events)\n", (unsigned int)idx, obj->name ? obj->name : "?", obj->spriteId, obj->depth, totalEvents); } - if (dataWin->objt.count > 3) Log_logDebug(" ... and %u more\n", dataWin->objt.count - 3); + if (dataWin->objt.count > 3) Log_log(" ... and %u more\n", dataWin->objt.count - 3); } - Log_logDebug("\n"); + Log_log("\n"); // ROOM - Log_logDebug("-- ROOM (Rooms) --\n"); - Log_logDebug(" Rooms: %u\n", dataWin->room.count); + Log_log("-- ROOM (Rooms) --\n"); + Log_log(" Rooms: %u\n", dataWin->room.count); if (dataWin->room.count > 0) { uint32_t show = dataWin->room.count < 3 ? dataWin->room.count : 3; forEachIndexed(Room, rm, idx, dataWin->room.rooms, show) { if (rm->payloadLoaded) { - Log_logDebug(" [%u] %s (%ux%u, %u objects, %u tiles)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height, rm->gameObjectCount, rm->tileCount); + Log_log(" [%u] %s (%ux%u, %u objects, %u tiles)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height, rm->gameObjectCount, rm->tileCount); } else { // Lazy room with payload not yet loaded: gameObjectCount/tileCount would be 0 and misleading. - Log_logDebug(" [%u] %s (%ux%u, payload not loaded)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height); + Log_log(" [%u] %s (%ux%u, payload not loaded)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height); } } - if (dataWin->room.count > 3) Log_logDebug(" ... and %u more\n", dataWin->room.count - 3); + if (dataWin->room.count > 3) Log_log(" ... and %u more\n", dataWin->room.count - 3); } - Log_logDebug("\n"); + Log_log("\n"); // TPAG - Log_logDebug("-- TPAG (Texture Page Items) --\n"); - Log_logDebug(" Items: %u\n", dataWin->tpag.count); - Log_logDebug("\n"); + Log_log("-- TPAG (Texture Page Items) --\n"); + Log_log(" Items: %u\n", dataWin->tpag.count); + Log_log("\n"); // CODE - Log_logDebug("-- CODE (Code Entries) --\n"); - Log_logDebug(" Entries: %u\n", dataWin->code.count); + Log_log("-- CODE (Code Entries) --\n"); + Log_log(" Entries: %u\n", dataWin->code.count); if (dataWin->code.count > 0) { uint32_t show = dataWin->code.count < 3 ? dataWin->code.count : 3; forEachIndexed(CodeEntry, entry, idx, dataWin->code.entries, show) { - Log_logDebug(" [%u] %s (%u bytes, %u locals, %u args)\n", (unsigned int)idx, entry->name ? entry->name : "?", entry->length, entry->localsCount, entry->argumentsCount); + Log_log(" [%u] %s (%u bytes, %u locals, %u args)\n", (unsigned int)idx, entry->name ? entry->name : "?", entry->length, entry->localsCount, entry->argumentsCount); } - if (dataWin->code.count > 3) Log_logDebug(" ... and %u more\n", dataWin->code.count - 3); + if (dataWin->code.count > 3) Log_log(" ... and %u more\n", dataWin->code.count - 3); } - Log_logDebug("\n"); + Log_log("\n"); // VARI - Log_logDebug("-- VARI (Variables) --\n"); - Log_logDebug(" Variables: %u\n", dataWin->vari.variableCount); - Log_logDebug(" Max Locals: %u\n", dataWin->vari.maxLocalVarCount); + Log_log("-- VARI (Variables) --\n"); + Log_log(" Variables: %u\n", dataWin->vari.variableCount); + Log_log(" Max Locals: %u\n", dataWin->vari.maxLocalVarCount); if (dataWin->vari.variableCount > 0) { uint32_t show = dataWin->vari.variableCount < 3 ? dataWin->vari.variableCount : 3; forEachIndexed(Variable, var, idx, dataWin->vari.variables, show) { - Log_logDebug(" [%u] %s (type=%d, id=%d, %u refs)\n", (unsigned int)idx, var->name ? var->name : "?", var->instanceType, var->varID, var->occurrences); + Log_log(" [%u] %s (type=%d, id=%d, %u refs)\n", (unsigned int)idx, var->name ? var->name : "?", var->instanceType, var->varID, var->occurrences); } - if (dataWin->vari.variableCount > 3) Log_logDebug(" ... and %u more\n", dataWin->vari.variableCount - 3); + if (dataWin->vari.variableCount > 3) Log_log(" ... and %u more\n", dataWin->vari.variableCount - 3); } - Log_logDebug("\n"); + Log_log("\n"); // FUNC - Log_logDebug("-- FUNC (Functions) --\n"); - Log_logDebug(" Functions: %u\n", dataWin->func.functionCount); - Log_logDebug(" Code Locals: %u\n", dataWin->func.codeLocalsCount); + Log_log("-- FUNC (Functions) --\n"); + Log_log(" Functions: %u\n", dataWin->func.functionCount); + Log_log(" Code Locals: %u\n", dataWin->func.codeLocalsCount); if (dataWin->func.functionCount > 0) { uint32_t show = dataWin->func.functionCount < 3 ? dataWin->func.functionCount : 3; forEachIndexed(Function, fn, idx, dataWin->func.functions, show) { - Log_logDebug(" [%u] %s (%u refs)\n", (unsigned int)idx, fn->name ? fn->name : "?", fn->occurrences); + Log_log(" [%u] %s (%u refs)\n", (unsigned int)idx, fn->name ? fn->name : "?", fn->occurrences); } - if (dataWin->func.functionCount > 3) Log_logDebug(" ... and %u more\n", dataWin->func.functionCount - 3); + if (dataWin->func.functionCount > 3) Log_log(" ... and %u more\n", dataWin->func.functionCount - 3); } - Log_logDebug("\n"); + Log_log("\n"); // STRG - Log_logDebug("-- STRG (Strings) --\n"); - Log_logDebug(" Strings: %u\n", dataWin->strg.count); + Log_log("-- STRG (Strings) --\n"); + Log_log(" Strings: %u\n", dataWin->strg.count); if (dataWin->strg.count > 0) { uint32_t show = dataWin->strg.count < 5 ? dataWin->strg.count : 5; repeat(show, i) { @@ -223,56 +223,56 @@ void DataWin_printDebugSummary(DataWin* dataWin) { if (str) { size_t len = strlen(str); if (len > 60) { - Log_logDebug(" [%u] \"%.60s...\" (%zu chars)\n", (unsigned int)i, str, len); + Log_log(" [%u] \"%.60s...\" (%zu chars)\n", (unsigned int)i, str, len); } else { - Log_logDebug(" [%u] \"%s\"\n", (unsigned int)i, str); + Log_log(" [%u] \"%s\"\n", (unsigned int)i, str); } } else { - Log_logDebug(" [%u] (null)\n", (unsigned int)i); + Log_log(" [%u] (null)\n", (unsigned int)i); } } - if (dataWin->strg.count > 5) Log_logDebug(" ... and %u more\n", dataWin->strg.count - 5); + if (dataWin->strg.count > 5) Log_log(" ... and %u more\n", dataWin->strg.count - 5); } - Log_logDebug("\n"); + Log_log("\n"); // TXTR - Log_logDebug("-- TXTR (Textures) --\n"); - Log_logDebug(" Textures: %u\n", dataWin->txtr.count); + Log_log("-- TXTR (Textures) --\n"); + Log_log(" Textures: %u\n", dataWin->txtr.count); if (dataWin->txtr.count > 0) { forEachIndexed(Texture, tex, idx, dataWin->txtr.textures, dataWin->txtr.count) { - Log_logDebug(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, tex->blobOffset, tex->blobSize); + Log_log(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, tex->blobOffset, tex->blobSize); } } - Log_logDebug("\n"); + Log_log("\n"); // AUDO - Log_logDebug("-- AUDO (Audio) --\n"); - Log_logDebug(" Audio Entries: %u\n", dataWin->audo.count); + Log_log("-- AUDO (Audio) --\n"); + Log_log(" Audio Entries: %u\n", dataWin->audo.count); if (dataWin->audo.count > 0) { uint32_t show = dataWin->audo.count < 3 ? dataWin->audo.count : 3; forEachIndexed(AudioEntry, ae, idx, dataWin->audo.entries, show) { - Log_logDebug(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, ae->dataOffset, ae->dataSize); + Log_log(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, ae->dataOffset, ae->dataSize); } - if (dataWin->audo.count > 3) Log_logDebug(" ... and %u more\n", dataWin->audo.count - 3); + if (dataWin->audo.count > 3) Log_log(" ... and %u more\n", dataWin->audo.count - 3); } - Log_logDebug("\n"); + Log_log("\n"); - Log_logDebug("-- Room Instances --\n"); + Log_log("-- Room Instances --\n"); forEach(Room, room, dataWin->room.rooms, dataWin->room.count) { - Log_logDebug("Room %s\n", room->name); + Log_log("Room %s\n", room->name); if (!room->payloadLoaded) { - Log_logDebug(" (payload not loaded)\n"); + Log_log(" (payload not loaded)\n"); continue; } forEachIndexed(RoomGameObject, roomGameObject, idx, room->gameObjects, room->gameObjectCount) { int32_t objectDefinitionId = roomGameObject->objectDefinition; GameObject* objectDefinition = &dataWin->objt.objects[objectDefinitionId]; - Log_logDebug(" Object %d (%s, x=%d, y=%d)\n", objectDefinitionId, objectDefinition->name, roomGameObject->x, roomGameObject->y); + Log_log(" Object %d (%s, x=%d, y=%d)\n", objectDefinitionId, objectDefinition->name, roomGameObject->x, roomGameObject->y); } } // Overall summary - Log_logDebug("===== DataWin parse complete =====\n"); + Log_log("===== DataWin parse complete =====\n"); } diff --git a/src/desktop/main.c b/src/desktop/main.c index ae70f2384..974e5465e 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -302,11 +302,11 @@ static bool parseOsTypeArg(const char* s, YoYoOperatingSystem* out) { } static void printOsTypeNames(FILE* out) { - Log_addFile(out); + bool addFileSucceeded = Log_addFile(out); forEachIndexed(const OsTypeNameEntry, entry, i, OS_TYPE_NAMES, OS_TYPE_NAMES_COUNT) { Log_logToFile("%s%s", i > 0 ? ", " : "", entry->name); } - Log_removeFile(out); + if (addFileSucceeded) Log_removeFile(out); } // Resolves the window size for the specified operating system. @@ -1539,7 +1539,7 @@ int main(int argc, char* argv[]) { // Pause if (RunnerKeyboard_checkPressed(runner->keyboard, 'P')) { debugPaused = !debugPaused; - Log_logDebug("Debug: %s\n", debugPaused ? "Paused" : "Resumed"); + Log_logDebug("%s\n", debugPaused ? "Paused" : "Resumed"); } } @@ -1547,7 +1547,7 @@ int main(int argc, char* argv[]) { bool shouldStep = true; if (runner->debugMode && debugPaused) { shouldStep = RunnerKeyboard_checkPressed(runner->keyboard, 'O'); - if (shouldStep) Log_logDebug("Debug: Frame advance (frame %d)\n", runner->frameCount); + if (shouldStep) Log_logDebug("Frame advance (frame %d)\n", runner->frameCount); } uint64_t frameStartTime = 0; @@ -1568,7 +1568,7 @@ int main(int argc, char* argv[]) { int32_t nextIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition + 1]; runner->pendingRoom = nextIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_logDebug("Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); + Log_logDebug("Going to next room -> %s\n", dw->room.rooms[nextIdx].name); } } @@ -1579,18 +1579,18 @@ int main(int argc, char* argv[]) { int32_t prevIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition - 1]; runner->pendingRoom = prevIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_logDebug("Debug: Going to previous room -> %s\n", dw->room.rooms[prevIdx].name); + Log_logDebug("Going to previous room -> %s\n", dw->room.rooms[prevIdx].name); } } // Dump runner state to console if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F12)) { - Log_logDebug("Debug: Dumping runner state at frame %d\n", runner->frameCount); + Log_logDebug("Dumping runner state at frame %d\n", runner->frameCount); Runner_dumpState(runner); } if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F11)) { - Log_logDebug("Debug: Dumping runner state at frame %d\n", runner->frameCount); + Log_logDebug("Dumping runner state at frame %d\n", runner->frameCount); char* json = Runner_dumpStateJson(runner); if (args.dumpJsonFilePattern != nullptr) { @@ -1615,7 +1615,7 @@ int main(int argc, char* argv[]) { // Toggle the collision mask debug overlay if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F2)) { debugShowCollisionMasks = !debugShowCollisionMasks; - Log_logDebug("Debug: Collision mask overlay %s!\n", debugShowCollisionMasks ? "enabled" : "disabled"); + Log_logDebug("Collision mask overlay %s!\n", debugShowCollisionMasks ? "enabled" : "disabled"); } // Enable free cam @@ -1625,7 +1625,7 @@ int main(int argc, char* argv[]) { runner->freeCamZoom = 1.0f; freeCamActive = !freeCamActive; - Log_logDebug("Debug: Free cam %s!\n", freeCamActive ? "enabled" : "disabled"); + Log_logDebug("Free cam %s!\n", freeCamActive ? "enabled" : "disabled"); } if (freeCamActive) { diff --git a/src/log.c b/src/log.c index 3ee2c7b4a..8219b8b63 100644 --- a/src/log.c +++ b/src/log.c @@ -42,6 +42,10 @@ static void vLogInternal(FILE* file, bool logColour, const int type, const char* fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : (type == LOG_TYPE_ERROR ? ANSI_COLOUR_CODE_BOLD_RED : ANSI_COLOUR_CODE_BOLD_PURPLE)))); } + if (type == LOG_TYPE_DEBUG) { + fprintf(file, "Debug: "); + } + vfprintf(file, fmt, va); if (logColour) { diff --git a/src/ps2/main.c b/src/ps2/main.c index dd2fafd4e..effb8b4fd 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -609,7 +609,7 @@ int main(int argc, char* argv[]) { int32_t nextIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition + 1]; runner->pendingRoom = nextIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_logDebug("Debug: Going to next room -> %s\n", dw->room.rooms[nextIdx].name); + Log_logDebug("Going to next room -> %s\n", dw->room.rooms[nextIdx].name); } } diff --git a/src/ps3/main.c b/src/ps3/main.c index 33b644c00..66d6356a2 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -311,7 +311,7 @@ int main(int argc, char* argv[]) { bool shouldStep = true; if (runner->debugMode && debugPaused) { shouldStep = RunnerKeyboard_checkPressed(runner->keyboard, 'O'); - if (shouldStep) Log_logDebug("Debug: Frame advance (frame %d)\n", runner->frameCount); + if (shouldStep) Log_logDebug("Frame advance (frame %d)\n", runner->frameCount); } diff --git a/src/runner.c b/src/runner.c index f29de472d..bcda96e66 100644 --- a/src/runner.c +++ b/src/runner.c @@ -4032,9 +4032,9 @@ void Runner_dumpState(Runner* runner) { DataWin* dataWin = runner->dataWin; int32_t instanceCount = (int32_t) arrlen(runner->instances); - Log_logDebug("=== Frame %d State Dump ===\n", runner->frameCount); - Log_logDebug("Room: %s (index %d)\n", runner->currentRoom->name, runner->currentRoomIndex); - Log_logDebug("Instance count: %d\n", instanceCount); + Log_log("=== Frame %d State Dump ===\n", runner->frameCount); + Log_log("Room: %s (index %d)\n", runner->currentRoom->name, runner->currentRoomIndex); + Log_log("Instance count: %d\n", instanceCount); repeat(instanceCount, i) { Instance* inst = runner->instances[i]; @@ -4057,23 +4057,23 @@ void Runner_dumpState(Runner* runner) { parentName = dataWin->objt.objects[gameObject->parentId].name; } - Log_logDebug("\n--- Instance #%d (%s, objectIndex=%d) ---\n", inst->instanceId, objName, inst->objectIndex); - Log_logDebug(" Position: (%g, %g)\n", (double) inst->x, (double) inst->y); - Log_logDebug(" Depth: %d\n", inst->depth); - Log_logDebug(" Sprite: %s (index %d), imageIndex=%g, imageSpeed=%g\n", spriteName, inst->spriteIndex, (double) inst->imageIndex, (double) inst->imageSpeed); - Log_logDebug(" Scale: (%g, %g), Angle: %g, Alpha: %g, Blend: 0x%06X\n", (double) inst->imageXscale, (double) inst->imageYscale, (double) inst->imageAngle, (double) inst->imageAlpha, inst->imageBlend); - Log_logDebug(" Visible: %s, Active: %s, Solid: %s, Persistent: %s\n", inst->visible ? "true" : "false", inst->active ? "true" : "false", inst->solid ? "true" : "false", inst->persistent ? "true" : "false"); - Log_logDebug(" Parent: %s (parentId=%d)\n", parentName, gameObject != nullptr ? gameObject->parentId : -1); + Log_log("\n--- Instance #%d (%s, objectIndex=%d) ---\n", inst->instanceId, objName, inst->objectIndex); + Log_log(" Position: (%g, %g)\n", (double) inst->x, (double) inst->y); + Log_log(" Depth: %d\n", inst->depth); + Log_log(" Sprite: %s (index %d), imageIndex=%g, imageSpeed=%g\n", spriteName, inst->spriteIndex, (double) inst->imageIndex, (double) inst->imageSpeed); + Log_log(" Scale: (%g, %g), Angle: %g, Alpha: %g, Blend: 0x%06X\n", (double) inst->imageXscale, (double) inst->imageYscale, (double) inst->imageAngle, (double) inst->imageAlpha, inst->imageBlend); + Log_log(" Visible: %s, Active: %s, Solid: %s, Persistent: %s\n", inst->visible ? "true" : "false", inst->active ? "true" : "false", inst->solid ? "true" : "false", inst->persistent ? "true" : "false"); + Log_log(" Parent: %s (parentId=%d)\n", parentName, gameObject != nullptr ? gameObject->parentId : -1); // Active alarms bool hasAlarm = false; repeat(GML_ALARM_COUNT, alarmIdx) { if (inst->alarm[alarmIdx] >= 0) { if (!hasAlarm) { Log_log(" Alarms:"); hasAlarm = true; } - Log_logDebug(" [%d]=%d", (int)alarmIdx, inst->alarm[alarmIdx]); + Log_log(" [%d]=%d", (int)alarmIdx, inst->alarm[alarmIdx]); } } - if (hasAlarm) Log_logDebug("\n"); + if (hasAlarm) Log_log("\n"); // Self variables bool hasSelfVars = false; @@ -4100,20 +4100,20 @@ void Runner_dumpState(Runner* runner) { RValue* cell = GMLArray_slot(val.array, ai); if (cell == nullptr || cell->type == RVALUE_UNDEFINED) continue; char* innerStr = RValue_toStringFancy(*cell); - Log_logDebug(" %s[%d] = %s\n", varName, (int) ai, innerStr); + Log_log(" %s[%d] = %s\n", varName, (int) ai, innerStr); free(innerStr); } } else { if (!hasSelfVars) { Log_log(" Self Variables:\n"); hasSelfVars = true; } char* valStr = RValue_toStringFancy(val); - Log_logDebug(" %s = %s\n", varName, valStr); + Log_log(" %s = %s\n", varName, valStr); free(valStr); } } } // Global variables (non-array) - Log_logDebug("\n=== Global Variables ===\n"); + Log_log("\n=== Global Variables ===\n"); repeat(runner->vmContext->globalScopeInstance->selfVars.capacity, i) { IntRValueEntry entryOnTheVarStruct = runner->vmContext->globalScopeInstance->selfVars.entries[i]; @@ -4127,18 +4127,18 @@ void Runner_dumpState(Runner* runner) { RValue* cell = GMLArray_slot(target.array, ai); if (cell == nullptr || cell->type == RVALUE_UNDEFINED) continue; char* innerStr = RValue_toStringFancy(*cell); - Log_logDebug(" %s[%d] = %s\n", name, (int) ai, innerStr); + Log_log(" %s[%d] = %s\n", name, (int) ai, innerStr); free(innerStr); } } char* valStr = RValue_toStringTyped(target); - Log_logDebug(" %s = %s\n", name, valStr); + Log_log(" %s = %s\n", name, valStr); free(valStr); } } - Log_logDebug("\n=== End Frame %d State Dump ===\n", runner->frameCount); + Log_log("\n=== End Frame %d State Dump ===\n", runner->frameCount); } // ===[ JSON State Dump ]=== diff --git a/src/vm.c b/src/vm.c index 80d860ed8..e90deb2ec 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2463,17 +2463,17 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { entries[j] = tmp; } - Log_logDebug("=== Opcode Profiler Report ===\n"); - Log_logDebug("Total instructions executed: %llu\n", (unsigned long long) total); - Log_logDebug("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); + Log_log("=== Opcode Profiler Report ===\n"); + Log_log("Total instructions executed: %llu\n", (unsigned long long) total); + Log_log("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); forEachIndexed(CountEntry, entry, i, entries, entryCount) { (void) i; double pct = total > 0 ? (100.0 * (double) entry->count / (double) total) : 0.0; - Log_logDebug("%-12s 0x%02X %16llu %7.2f%%\n", opcodeName((uint8_t) entry->key), (uint8_t) entry->key, (unsigned long long) entry->count, pct); + Log_log("%-12s 0x%02X %16llu %7.2f%%\n", opcodeName((uint8_t) entry->key), (uint8_t) entry->key, (unsigned long long) entry->count, pct); } // Per-opcode breakdown by type variant. Sorted within each opcode by count desc. - Log_logDebug("\n--- Type variant breakdown (per opcode) ---\n"); + Log_log("\n--- Type variant breakdown (per opcode) ---\n"); forEachIndexed(CountEntry, entry, idx, entries, entryCount) { (void) idx; uint8_t opcode = (uint8_t) entry->key; @@ -2498,13 +2498,13 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { variantEntries[j] = tmp; } - Log_logDebug("%s (0x%02X): %llu total\n", opcodeName(opcode), opcode, (unsigned long long) entry->count); + Log_log("%s (0x%02X): %llu total\n", opcodeName(opcode), opcode, (unsigned long long) entry->count); forEachIndexed(CountEntry, ve, vi, variantEntries, variantCount) { (void) vi; uint8_t type1 = (uint8_t) ((ve->key >> 4) & 0xF); uint8_t type2 = (uint8_t) (ve->key & 0xF); double vpct = entry->count > 0 ? (100.0 * (double) ve->count / (double) entry->count) : 0.0; - Log_logDebug(" .%c.%c %16llu %7.2f%%\n", gmlTypeChar(type1), gmlTypeChar(type2), (unsigned long long) ve->count, vpct); + Log_log(" .%c.%c %16llu %7.2f%%\n", gmlTypeChar(type1), gmlTypeChar(type2), (unsigned long long) ve->count, vpct); } // Runtime RValue type breakdown (a, b types observed at execution time) @@ -2531,13 +2531,13 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { } rvEntries[j] = tmp; } - Log_logDebug(" -- runtime types (a, b):\n"); + Log_log(" -- runtime types (a, b):\n"); forEachIndexed(CountEntry, re, ri, rvEntries, rvCount) { (void) ri; uint8_t typeA = (uint8_t) ((re->key >> 4) & 0xF); uint8_t typeB = (uint8_t) (re->key & 0xF); double rpct = rvTotal > 0 ? (100.0 * (double) re->count / (double) rvTotal) : 0.0; - Log_logDebug(" (%-6s, %-6s) %16llu %7.2f%%\n", rvalueTypeName(typeA), rvalueTypeName(typeB), (unsigned long long) re->count, rpct); + Log_log(" (%-6s, %-6s) %16llu %7.2f%%\n", rvalueTypeName(typeA), rvalueTypeName(typeB), (unsigned long long) re->count, rpct); } } } @@ -2562,16 +2562,16 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { } breakEntries[j] = tmp; } - Log_logDebug(" -- sub-opcodes:\n"); + Log_log(" -- sub-opcodes:\n"); forEachIndexed(CountEntry, be, bi, breakEntries, breakCount) { (void) bi; int16_t breakType = (int16_t) -((int) be->key); double bpct = entry->count > 0 ? (100.0 * (double) be->count / (double) entry->count) : 0.0; - Log_logDebug(" %-12s (%4d) %16llu %7.2f%%\n", breakSubOpName(breakType), (int) breakType, (unsigned long long) be->count, bpct); + Log_log(" %-12s (%4d) %16llu %7.2f%%\n", breakSubOpName(breakType), (int) breakType, (unsigned long long) be->count, bpct); } } } - Log_logDebug("==============================\n"); + Log_log("==============================\n"); } #endif // ENABLE_VM_OPCODE_PROFILER From 4b7735f4f2f6b71ca1272c85501934213f821953 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 13:57:44 +0800 Subject: [PATCH 36/57] Rename log functions to what uniq said --- src/android/main.c | 2 +- src/audio/miniaudio/ma_audio_system.c | 38 ++-- src/audio/openal/al_audio_system.c | 28 +-- src/audio/ps2/ps2_audio_system.c | 68 ++++---- src/audio/web/web_audio_system.c | 32 ++-- src/binary_reader.c | 10 +- src/data_win.c | 28 +-- src/data_win_print.c | 238 +++++++++++++------------- src/desktop/backends/glfw2.c | 6 +- src/desktop/backends/glfw3.c | 12 +- src/desktop/backends/sdl1.c | 12 +- src/desktop/backends/sdl2.c | 12 +- src/desktop/backends/sdl3.c | 6 +- src/desktop/main.c | 184 ++++++++++---------- src/event_table.c | 2 +- src/gl/gl_renderer.c | 50 +++--- src/gl_legacy/gl_legacy_renderer.c | 24 +-- src/image/image_decoder.c | 2 +- src/ini.c | 2 +- src/input_recording.c | 12 +- src/json_reader.c | 24 +-- src/log.c | 48 +++--- src/log.h | 48 +++--- src/ps2/debug_font_renderer.c | 4 +- src/ps2/gs_renderer.c | 58 +++---- src/ps2/main.c | 54 +++--- src/ps2/ps2_file_system.c | 12 +- src/ps2/ps2_gamepad.c | 8 +- src/ps2/ps2_utils.c | 20 +-- src/ps3/main.c | 14 +- src/ps3/ps3_overlay.c | 2 +- src/ps3/ps3_textures.c | 10 +- src/runner.c | 108 ++++++------ src/runner.h | 2 +- src/spatial_grid.c | 4 +- src/utils.h | 24 +-- src/vm.c | 126 +++++++------- src/vm.h | 2 +- src/vm_builtins.c | 108 ++++++------ src/web/main.c | 16 +- 40 files changed, 730 insertions(+), 730 deletions(-) diff --git a/src/android/main.c b/src/android/main.c index e05a6f37c..11de88812 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -635,7 +635,7 @@ static bool performGameChange(const char* workingDirectory, char* launchParamete } if (dataWinFilename == nullptr) { - Log_logError("Runner: Launch parameters '%s' did not contain a '-game ' entry! Shutting down...\n", launchParameters); + logError("Runner: Launch parameters '%s' did not contain a '-game ' entry! Shutting down...\n", launchParameters); repeat(arrlen(newArguments), i) { free(newArguments[i]); } diff --git a/src/audio/miniaudio/ma_audio_system.c b/src/audio/miniaudio/ma_audio_system.c index 3ff1a71f1..c44f613b8 100644 --- a/src/audio/miniaudio/ma_audio_system.c +++ b/src/audio/miniaudio/ma_audio_system.c @@ -109,14 +109,14 @@ static void maInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem) deviceConfig.pUserData = &ma->engine; ma_result deviceResult = ma_device_init(NULL, &deviceConfig, &ma->device); if (deviceResult != MA_SUCCESS) { - Log_logError("Audio: Failed to initialize playback device (error %d)\n", deviceResult); + logError("Audio: Failed to initialize playback device (error %d)\n", deviceResult); return; } ma_engine_config config = ma_engine_config_init(); config.pDevice = &ma->device; ma_result result = ma_engine_init(&config, &ma->engine); if (result != MA_SUCCESS) { - Log_logError("Audio: Failed to initialize miniaudio engine (error %d)\n", result); + logError("Audio: Failed to initialize miniaudio engine (error %d)\n", result); ma_device_uninit(&ma->device); return; } @@ -130,7 +130,7 @@ static void maInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem) ma->listenerGains[i] = 1.0f; } - Log_log("Audio: miniaudio engine initialized\n"); + logInfo("Audio: miniaudio engine initialized\n"); } static void maDestroy(AudioSystem* audio) { @@ -215,7 +215,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior if (isStream) { int32_t streamSlot = soundIndex - AUDIO_STREAM_INDEX_BASE; if (0 > streamSlot || streamSlot >= MAX_AUDIO_STREAMS || !ma->streams[streamSlot].active) { - Log_logWarning("Audio: Invalid stream index %d\n", soundIndex); + logWarn("Audio: Invalid stream index %d\n", soundIndex); return -1; } AudioStreamEntry* stream = &ma->streams[streamSlot]; @@ -225,7 +225,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior } else { DataWin* dw = ma->base.audioGroups[0]; // Audio Group 0 should always be data.win if (0 > soundIndex || (uint32_t) soundIndex >= dw->sond.count) { - Log_logWarning("Audio: Invalid sound index %d\n", soundIndex); + logWarn("Audio: Invalid sound index %d\n", soundIndex); return -1; } sound = &dw->sond.sounds[soundIndex]; @@ -233,7 +233,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior SoundInstance* slot = findFreeSlot(ma); if (slot == nullptr) { - Log_logWarning("Audio: No free sound slots for sound %d\n", soundIndex); + logWarn("Audio: No free sound slots for sound %d\n", soundIndex); return -1; } @@ -244,7 +244,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior // Stream audio: load from file path stored in stream entry result = ma_sound_init_from_file(&ma->engine, streamPath, MA_SOUND_FLAG_ASYNC, &ma->listenerGroups[0], nullptr, &slot->maSound); if (result != MA_SUCCESS) { - Log_logWarning("Audio: Failed to load stream file '%s' (error %d)\n", streamPath, result); + logWarn("Audio: Failed to load stream file '%s' (error %d)\n", streamPath, result); return -1; } slot->ownsDecoder = false; @@ -257,7 +257,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior if (inAudo) { // Embedded audio: decode from AUDO chunk memory if (0 > sound->audioFile || (uint32_t) sound->audioFile >= ma->base.audioGroups[sound->audioGroup]->audo.count) { - Log_logWarning("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); + logWarn("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); return -1; } @@ -266,14 +266,14 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior ma_decoder_config decoderConfig = ma_decoder_config_init_default(); result = ma_decoder_init_memory(entry->data, entry->dataSize, &decoderConfig, &slot->decoder); if (result != MA_SUCCESS) { - Log_logWarning("Audio: Failed to init decoder for '%s' (error %d)\n", sound->name, result); + logWarn("Audio: Failed to init decoder for '%s' (error %d)\n", sound->name, result); return -1; } slot->ownsDecoder = true; result = ma_sound_init_from_data_source(&ma->engine, &slot->decoder, 0, &ma->listenerGroups[0], &slot->maSound); if (result != MA_SUCCESS) { - Log_logWarning("Audio: Failed to init sound from decoder for '%s' (error %d)\n", sound->name, result); + logWarn("Audio: Failed to init sound from decoder for '%s' (error %d)\n", sound->name, result); ma_decoder_uninit(&slot->decoder); return -1; } @@ -281,13 +281,13 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior // External audio: load from file char* path = resolveExternalPath(ma, sound); if (path == nullptr) { - Log_logWarning("Audio: Could not resolve path for sound '%s'\n", sound->name); + logWarn("Audio: Could not resolve path for sound '%s'\n", sound->name); return -1; } result = ma_sound_init_from_file(&ma->engine, path, MA_SOUND_FLAG_ASYNC, &ma->listenerGroups[0], nullptr, &slot->maSound); if (result != MA_SUCCESS) { - Log_logWarning("Audio: Failed to load file for '%s' at '%s' (error %d)\n", sound->name, path, result); + logWarn("Audio: Failed to load file for '%s' at '%s' (error %d)\n", sound->name, path, result); free(path); return -1; } @@ -741,7 +741,7 @@ static void maGroupLoad(AudioSystem* audio, int32_t groupIndex) { // The original runner does not care if the file doesn't exist (this may happen if someone uses "audio_group_load" on a non-existent group) FileSystem* fileSystem = ((MaAudioSystem*)audio)->fileSystem; if (!fileSystem->vtable->fileExists(fileSystem, buf)) { - Log_logWarning("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the file system!\n", groupIndex, groupIndex); + logWarn("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the file system!\n", groupIndex, groupIndex); free(buf); DataWin* dw = (DataWin *)safeCalloc(1, sizeof(DataWin)); arrput(audio->audioGroups, dw); @@ -754,7 +754,7 @@ static void maGroupLoad(AudioSystem* audio, int32_t groupIndex) { arrput(audio->audioGroups, audioGroup); free(buf); } else { - Log_logWarning("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the AGPR!\n", groupIndex, groupIndex); + logWarn("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the AGPR!\n", groupIndex, groupIndex); } } @@ -777,13 +777,13 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { } if (0 > freeSlot) { - Log_logWarning("Audio: No free stream slots for '%s'\n", filename); + logWarn("Audio: No free stream slots for '%s'\n", filename); return -1; } char* resolved = ma->fileSystem->vtable->resolvePath(ma->fileSystem, filename); if (resolved == nullptr) { - Log_logWarning("Audio: Could not resolve path for stream '%s'\n", filename); + logWarn("Audio: Could not resolve path for stream '%s'\n", filename); return -1; } @@ -793,7 +793,7 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { ma->streams[freeSlot].initialPitch = 1.0f; int32_t streamIndex = AUDIO_STREAM_INDEX_BASE + freeSlot; - Log_log("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); + logInfo("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); return streamIndex; } @@ -802,7 +802,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { int32_t slotIndex = streamIndex - AUDIO_STREAM_INDEX_BASE; if (0 > slotIndex || slotIndex >= MAX_AUDIO_STREAMS) { - Log_logWarning("Audio: Invalid stream index %d for destroy\n", streamIndex); + logWarn("Audio: Invalid stream index %d for destroy\n", streamIndex); return false; } @@ -825,7 +825,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { free(entry->filePath); entry->filePath = nullptr; entry->active = false; - Log_log("Audio: Destroyed stream %d\n", streamIndex); + logInfo("Audio: Destroyed stream %d\n", streamIndex); return true; } diff --git a/src/audio/openal/al_audio_system.c b/src/audio/openal/al_audio_system.c index 758d325f9..2bc43f805 100644 --- a/src/audio/openal/al_audio_system.c +++ b/src/audio/openal/al_audio_system.c @@ -170,14 +170,14 @@ static void maInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem) ma->alContext = alcCreateContext(ma->alDevice, nullptr); alcMakeContextCurrent(ma->alContext); if (ma->alDevice == nullptr || ma->alContext == nullptr) { - Log_logError("Audio: Failed to initialize OpenAL engine (error %d)\n", alGetError()); + logError("Audio: Failed to initialize OpenAL engine (error %d)\n", alGetError()); return; } memset(ma->instances, 0, sizeof(ma->instances)); ma->nextInstanceCounter = 0; - Log_log("Audio: OpenAL engine initialized\n"); + logInfo("Audio: OpenAL engine initialized\n"); } static void maDestroy(AudioSystem* audio) { @@ -289,14 +289,14 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior if (isStream) { int32_t streamSlot = soundIndex - AUDIO_STREAM_INDEX_BASE; if (0 > streamSlot || streamSlot >= MAX_AUDIO_STREAMS || !ma->streams[streamSlot].active) { - Log_logWarning("Audio: Invalid stream index %d\n", soundIndex); + logWarn("Audio: Invalid stream index %d\n", soundIndex); return -1; } streamPath = ma->streams[streamSlot].filePath; } else { DataWin* dw = ma->base.audioGroups[0]; // Audio Group 0 should always be data.win if (0 > soundIndex || (uint32_t) soundIndex >= dw->sond.count) { - Log_logWarning("Audio: Invalid sound index %d\n", soundIndex); + logWarn("Audio: Invalid sound index %d\n", soundIndex); return -1; } sound = &dw->sond.sounds[soundIndex]; @@ -304,7 +304,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior SoundInstance* slot = findFreeSlot(ma); if (slot == nullptr) { - Log_logWarning("Audio: No free sound slots for sound %d\n", soundIndex); + logWarn("Audio: No free sound slots for sound %d\n", soundIndex); return -1; } @@ -322,7 +322,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior int err = 0; stb_vorbis* v = stb_vorbis_open_filename(streamPath, &err, nullptr); if (v == nullptr) { - Log_logWarning("Audio: Failed to open stream '%s' (stb_vorbis err %d)\n", streamPath, err); + logWarn("Audio: Failed to open stream '%s' (stb_vorbis err %d)\n", streamPath, err); return -1; } stb_vorbis_info info = stb_vorbis_get_info(v); @@ -368,7 +368,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior if (inAudo) { // Embedded audio: decode from AUDO chunk memory if (0 > sound->audioFile || (uint32_t) sound->audioFile >= ma->base.audioGroups[sound->audioGroup]->audo.count) { - Log_logWarning("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); + logWarn("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); return -1; } @@ -402,7 +402,7 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior // External audio: load from file char* path = resolveExternalPath(ma, sound); if (path == nullptr) { - Log_logWarning("Audio: Could not resolve path for sound '%s'\n", sound->name); + logWarn("Audio: Could not resolve path for sound '%s'\n", sound->name); return -1; } @@ -817,7 +817,7 @@ static void maGroupLoad(AudioSystem* audio, int32_t groupIndex) { FileSystem* fileSystem = ((AlAudioSystem*)audio)->fileSystem; char* resolvedPath = (((AlAudioSystem*)audio)->fileSystem->vtable->resolvePath(((AlAudioSystem*)audio)->fileSystem, buf)); if (!fileSystem->vtable->fileExists(fileSystem, resolvedPath)) { - Log_logWarning("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist!\n", groupIndex, groupIndex); + logWarn("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist!\n", groupIndex, groupIndex); free(buf); return; } @@ -849,13 +849,13 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { } if (0 > freeSlot) { - Log_logWarning("Audio: No free stream slots for '%s'\n", filename); + logWarn("Audio: No free stream slots for '%s'\n", filename); return -1; } char* resolved = ma->fileSystem->vtable->resolvePath(ma->fileSystem, filename); if (resolved == nullptr) { - Log_logWarning("Audio: Could not resolve path for stream '%s'\n", filename); + logWarn("Audio: Could not resolve path for stream '%s'\n", filename); return -1; } @@ -863,7 +863,7 @@ static int32_t maCreateStream(AudioSystem* audio, const char* filename) { ma->streams[freeSlot].filePath = resolved; int32_t streamIndex = AUDIO_STREAM_INDEX_BASE + freeSlot; - Log_log("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); + logInfo("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); return streamIndex; } @@ -872,7 +872,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { int32_t slotIndex = streamIndex - AUDIO_STREAM_INDEX_BASE; if (0 > slotIndex || slotIndex >= MAX_AUDIO_STREAMS) { - Log_logWarning("Audio: Invalid stream index %d for destroy\n", streamIndex); + logWarn("Audio: Invalid stream index %d for destroy\n", streamIndex); return false; } @@ -890,7 +890,7 @@ static bool maDestroyStream(AudioSystem* audio, int32_t streamIndex) { free(entry->filePath); entry->filePath = nullptr; entry->active = false; - Log_log("Audio: Destroyed stream %d\n", streamIndex); + logInfo("Audio: Destroyed stream %d\n", streamIndex); return true; } diff --git a/src/audio/ps2/ps2_audio_system.c b/src/audio/ps2/ps2_audio_system.c index dd87da6d2..0fbd0d712 100644 --- a/src/audio/ps2/ps2_audio_system.c +++ b/src/audio/ps2/ps2_audio_system.c @@ -82,7 +82,7 @@ static void parseSoundBank(Ps2AudioSystem* ps2) { FILE* f = fopen(path, "rb"); free(path); if (f == nullptr) { - Log_logWarning("PS2AudioSystem: Could not open SOUNDBNK.BIN\n"); + logWarn("PS2AudioSystem: Could not open SOUNDBNK.BIN\n"); return; } @@ -93,7 +93,7 @@ static void parseSoundBank(Ps2AudioSystem* ps2) { fread(&ps2->audoEntryCount, 2, 1, f); fread(&ps2->musEntryCount, 2, 1, f); - Log_log("PS2AudioSystem: SOUNDBNK v%d, %d SOND entries, %d AUDO entries, %d MUS entries\n", version, ps2->sondEntryCount, ps2->audoEntryCount, ps2->musEntryCount); + logInfo("PS2AudioSystem: SOUNDBNK v%d, %d SOND entries, %d AUDO entries, %d MUS entries\n", version, ps2->sondEntryCount, ps2->audoEntryCount, ps2->musEntryCount); // Parse SOND entries (12 bytes each) ps2->sondEntries = safeMalloc(ps2->sondEntryCount * sizeof(Ps2SondEntry)); @@ -148,7 +148,7 @@ static void parseSoundBank(Ps2AudioSystem* ps2) { } if (ps2->musEntryCount > 0) { - Log_log("PS2AudioSystem: Loaded %d MUS entries\n", ps2->musEntryCount); + logInfo("PS2AudioSystem: Loaded %d MUS entries\n", ps2->musEntryCount); } fclose(f); @@ -163,12 +163,12 @@ static void openSoundsBin(Ps2AudioSystem* ps2) { ps2->soundsFile = fopen(path, "rb"); if (ps2->soundsFile == nullptr) { - Log_logWarning("PS2AudioSystem: Could not open SOUNDS.BIN at %s\n", path); + logWarn("PS2AudioSystem: Could not open SOUNDS.BIN at %s\n", path); free(path); return; } - Log_log("PS2AudioSystem: Opened SOUNDS.BIN for streaming (%s)\n", path); + logInfo("PS2AudioSystem: Opened SOUNDS.BIN for streaming (%s)\n", path); free(path); } @@ -221,7 +221,7 @@ static DecodedPcmEntry* cacheInsert(Ps2AudioSystem* ps2, int32_t audoIndex) { } if (slot == nullptr) { - // Log_logWarning("PS2AudioSystem: Cache full, all entries in use! Cannot decode audoIndex %" PRId32 "\n", audoIndex); + // logWarn("PS2AudioSystem: Cache full, all entries in use! Cannot decode audoIndex %" PRId32 "\n", audoIndex); return nullptr; } @@ -533,14 +533,14 @@ static void ps2Init(AudioSystem* audio, MAYBE_UNUSED DataWin* dataWin, MAYBE_UNU // Parse sound bank index parseSoundBank(ps2); if (ps2->sondEntries == nullptr || ps2->audoEntries == nullptr) { - Log_logWarning("PS2AudioSystem: Failed to parse SOUNDBNK.BIN, audio disabled\n"); + logWarn("PS2AudioSystem: Failed to parse SOUNDBNK.BIN, audio disabled\n"); return; } // Open SOUNDS.BIN for streaming (kept open for on-demand reads) openSoundsBin(ps2); if (ps2->soundsFile == nullptr) { - Log_logWarning("PS2AudioSystem: Failed to open SOUNDS.BIN, audio disabled\n"); + logWarn("PS2AudioSystem: Failed to open SOUNDS.BIN, audio disabled\n"); return; } @@ -559,7 +559,7 @@ static void ps2Init(AudioSystem* audio, MAYBE_UNUSED DataWin* dataWin, MAYBE_UNU // Initialize audsrv int ret = audsrv_init(); if (ret != 0) { - Log_logWarning("PS2AudioSystem: audsrv_init failed (%d)\n", ret); + logWarn("PS2AudioSystem: audsrv_init failed (%d)\n", ret); return; } @@ -570,7 +570,7 @@ static void ps2Init(AudioSystem* audio, MAYBE_UNUSED DataWin* dataWin, MAYBE_UNU ret = audsrv_set_format(&format); if (ret != 0) { - Log_logWarning("PS2AudioSystem: audsrv_set_format failed (%d)\n", ret); + logWarn("PS2AudioSystem: audsrv_set_format failed (%d)\n", ret); audsrv_quit(); return; } @@ -578,7 +578,7 @@ static void ps2Init(AudioSystem* audio, MAYBE_UNUSED DataWin* dataWin, MAYBE_UNU audsrv_set_volume(MAX_VOLUME); ps2->initialized = true; - Log_log("PS2AudioSystem: Initialized (output: %d Hz, 16-bit, stereo)\n", AUDSRV_OUTPUT_FREQ); + logInfo("PS2AudioSystem: Initialized (output: %d Hz, 16-bit, stereo)\n", AUDSRV_OUTPUT_FREQ); } static void ps2Destroy(AudioSystem* audio) { @@ -657,7 +657,7 @@ static void ps2Update(AudioSystem* audio, float deltaTime) { repeat(MAX_MUSIC_STREAMS, i) { Ps2MusicStream* stream = &ps2->musicStreams[i]; if (!stream->active || !stream->needsRefill) continue; - // Log_log("PS2AudioSystem: Filling music stream %d back buffers...\n", stream->soundIndex); + // logInfo("PS2AudioSystem: Filling music stream %d back buffers...\n", stream->soundIndex); int backBuffer = stream->activeBuffer ^ 1; streamFillBuffer(ps2, stream, backBuffer); @@ -667,16 +667,16 @@ static void ps2Update(AudioSystem* audio, float deltaTime) { // Fill audsrv ring buffer int32_t chunkBytes = MIX_BUFFER_SAMPLES * 2 * (int32_t) sizeof(int16_t); while (audsrv_available() >= chunkBytes) { - // Log_log("PS2AudioSystem: Filling audsrv ring buffer... audsrv_available: %d, chunkBytes: %d\n", audsrv_available(), chunkBytes); + // logInfo("PS2AudioSystem: Filling audsrv ring buffer... audsrv_available: %d, chunkBytes: %d\n", audsrv_available(), chunkBytes); mixAudio(ps2, ps2->mixBuffer, MIX_BUFFER_SAMPLES); audsrv_play_audio((char*) ps2->mixBuffer, chunkBytes); } - // Log_log("PS2AudioSystem: Finished ticking the audio system\n"); + // logInfo("PS2AudioSystem: Finished ticking the audio system\n"); } static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t priority, bool loop) { - // Log_log("PS2AudioSystem: Attempting to play sound index %d with priority %d, should loop? %d\n", soundIndex, priority, loop); + // logInfo("PS2AudioSystem: Attempting to play sound index %d with priority %d, should loop? %d\n", soundIndex, priority, loop); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; if (!ps2->initialized) return -1; @@ -732,13 +732,13 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio stream->readPosition = 0; stream->needsRefill = false; - // Log_log("PS2AudioSystem: Streaming MUS '%s', size=%" PRIu32 " bytes, instanceId=%" PRId32 "\n", mus->name, mus->dataSize, instanceId); + // logInfo("PS2AudioSystem: Streaming MUS '%s', size=%" PRIu32 " bytes, instanceId=%" PRId32 "\n", mus->name, mus->dataSize, instanceId); return instanceId; } if (0 > soundIndex || (uint16_t) soundIndex >= ps2->sondEntryCount) { - // Log_logWarning("PS2AudioSystem: Invalid sound index %" PRId32 "\n", soundIndex); + // logWarn("PS2AudioSystem: Invalid sound index %" PRId32 "\n", soundIndex); return -1; } @@ -750,7 +750,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio } if (sond->audoIndex >= ps2->audoEntryCount) { - // Log_logWarning("PS2AudioSystem: Invalid audo index %d for sound %" PRId32 "\n", sond->audoIndex, soundIndex); + // logWarn("PS2AudioSystem: Invalid audo index %d for sound %" PRId32 "\n", sond->audoIndex, soundIndex); return -1; } @@ -767,7 +767,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio Ps2AudoEntry* audoForSize = &ps2->audoEntries[sond->audoIndex]; uint32_t decodedPcmBytes = audoForSize->dataSize * 2 * (uint32_t) sizeof(int16_t); if ((isEmbedded || isCompressed) && decodedPcmBytes > PS2_SFX_CACHE_MAX_BYTES) { - Log_logWarning("PS2AudioSystem: Sound %" PRId32 " (audo %d) would need %" PRIu32 " bytes of PCM in the cache! isEmbedded? %s; isCompressed? %s; Streaming instead...\n", soundIndex, sond->audoIndex, decodedPcmBytes, isEmbedded ? "true" : "false", isCompressed ? "true" : "false"); + logWarn("PS2AudioSystem: Sound %" PRId32 " (audo %d) would need %" PRIu32 " bytes of PCM in the cache! isEmbedded? %s; isCompressed? %s; Streaming instead...\n", soundIndex, sond->audoIndex, decodedPcmBytes, isEmbedded ? "true" : "false", isCompressed ? "true" : "false"); isEmbedded = false; isCompressed = false; } @@ -786,7 +786,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio } if (stream == nullptr) { - // Log_logWarning("PS2AudioSystem: No free music stream slots for sound %" PRId32 "\n", soundIndex); + // logWarn("PS2AudioSystem: No free music stream slots for sound %" PRId32 "\n", soundIndex); return -1; } @@ -825,7 +825,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio stream->readPosition = 0; stream->needsRefill = false; - // Log_log("PS2AudioSystem: Streaming music soundIndex=%" PRId32 " audoIndex=%d, size=%" PRIu32 " bytes, instanceId=%" PRId32 "\n", soundIndex, sond->audoIndex, audo->dataSize, instanceId); + // logInfo("PS2AudioSystem: Streaming music soundIndex=%" PRId32 " audoIndex=%d, size=%" PRIu32 " bytes, instanceId=%" PRId32 "\n", soundIndex, sond->audoIndex, audo->dataSize, instanceId); return instanceId; } @@ -836,7 +836,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio if (cached == nullptr) { cached = cacheInsert(ps2, sond->audoIndex); if (cached == nullptr) { - // Log_logWarning("PS2AudioSystem: Failed to cache decoded audio for sound %" PRId32 "\n", soundIndex); + // logWarn("PS2AudioSystem: Failed to cache decoded audio for sound %" PRId32 "\n", soundIndex); return -1; } } @@ -844,7 +844,7 @@ static int32_t ps2PlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio // Find a free SFX instance slot Ps2SoundInstance* slot = findFreeSlot(ps2); if (slot == nullptr) { - // Log_logWarning("PS2AudioSystem: No free sound slots for sound %" PRId32 "\n", soundIndex); + // logWarn("PS2AudioSystem: No free sound slots for sound %" PRId32 "\n", soundIndex); return -1; } @@ -978,12 +978,12 @@ static void actionSetPitch(Ps2SoundInstance* sfx, Ps2MusicStream* music, void* u // ===[ Vtable: Stop/Pause/Resume/Gain/Pitch ]=== static void ps2StopSound(AudioSystem* audio, int32_t soundOrInstance) { - // Log_log("PS2AudioSystem: Stopping sound %d\n", soundOrInstance); + // logInfo("PS2AudioSystem: Stopping sound %d\n", soundOrInstance); forEachInstance((Ps2AudioSystem*) audio, soundOrInstance, actionStop, nullptr); } static void ps2StopAll(AudioSystem* audio) { - // Log_log("PS2AudioSystem: Stopping all audios!\n"); + // logInfo("PS2AudioSystem: Stopping all audios!\n"); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; repeat(MAX_PS2_SOUND_INSTANCES, i) { ps2->instances[i].active = false; @@ -1023,17 +1023,17 @@ static bool ps2IsPlaying(AudioSystem* audio, int32_t soundOrInstance) { } static void ps2PauseSound(AudioSystem* audio, int32_t soundOrInstance) { - // Log_log("PS2AudioSystem: Pausing sound %d\n", soundOrInstance); + // logInfo("PS2AudioSystem: Pausing sound %d\n", soundOrInstance); forEachInstance((Ps2AudioSystem*) audio, soundOrInstance, actionPause, nullptr); } static void ps2ResumeSound(AudioSystem* audio, int32_t soundOrInstance) { - // Log_log("PS2AudioSystem: Resuming sound %d\n", soundOrInstance); + // logInfo("PS2AudioSystem: Resuming sound %d\n", soundOrInstance); forEachInstance((Ps2AudioSystem*) audio, soundOrInstance, actionResume, nullptr); } static void ps2PauseAll(AudioSystem* audio) { - // Log_log("PS2AudioSystem: Pausing all sounds!\n"); + // logInfo("PS2AudioSystem: Pausing all sounds!\n"); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; repeat(MAX_PS2_SOUND_INSTANCES, i) { if (ps2->instances[i].active) ps2->instances[i].paused = true; @@ -1044,7 +1044,7 @@ static void ps2PauseAll(AudioSystem* audio) { } static void ps2ResumeAll(AudioSystem* audio) { - // Log_log("PS2AudioSystem: Resuming all sounds!\n"); + // logInfo("PS2AudioSystem: Resuming all sounds!\n"); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; repeat(MAX_PS2_SOUND_INSTANCES, i) { if (ps2->instances[i].active) ps2->instances[i].paused = false; @@ -1082,7 +1082,7 @@ static float ps2GetSoundGain(AudioSystem* audio, int32_t soundOrInstance) { } static void ps2SetSoundPitch(AudioSystem* audio, int32_t soundOrInstance, float pitch) { - // Log_log("PS2AudioSystem: Setting pitch of sound %d to %f\n", soundOrInstance, pitch); + // logInfo("PS2AudioSystem: Setting pitch of sound %d to %f\n", soundOrInstance, pitch); forEachInstance((Ps2AudioSystem*) audio, soundOrInstance, actionSetPitch, &pitch); } @@ -1175,7 +1175,7 @@ static void seekMusicStream(Ps2AudioSystem* ps2, Ps2MusicStream* music, float po } static void ps2SetTrackPosition(AudioSystem* audio, int32_t soundOrInstance, float positionSeconds) { - // Log_log("PS2AudioSystem: Setting track position of sound %d to %f\n", soundOrInstance, positionSeconds); + // logInfo("PS2AudioSystem: Setting track position of sound %d to %f\n", soundOrInstance, positionSeconds); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; if (soundOrInstance >= PS2_AUDIO_STREAM_INDEX_BASE) { @@ -1264,7 +1264,7 @@ static float ps2GetSoundLength(AudioSystem* audio, int32_t soundOrInstance) { } static void ps2SetMasterGain(AudioSystem* audio, float gain) { - // Log_log("PS2AudioSystem: Setting master gain to %f\n", gain); + // logInfo("PS2AudioSystem: Setting master gain to %f\n", gain); Ps2AudioSystem* ps2 = (Ps2AudioSystem*) audio; ps2->masterGain = gain; } @@ -1295,12 +1295,12 @@ static int32_t ps2CreateStream(AudioSystem* audio, const char* filename) { for (int i = 0; ps2->musEntryCount > i; i++) { if (strcmp(ps2->musEntries[i].name, filename) == 0) { int32_t streamIndex = PS2_AUDIO_STREAM_INDEX_BASE + i; - Log_log("PS2AudioSystem: Created stream %" PRId32 " for '%s'\n", streamIndex, filename); + logInfo("PS2AudioSystem: Created stream %" PRId32 " for '%s'\n", streamIndex, filename); return streamIndex; } } - Log_logWarning("PS2AudioSystem: audio_create_stream: '%s' not found in MUS entries\n", filename); + logWarn("PS2AudioSystem: audio_create_stream: '%s' not found in MUS entries\n", filename); return -1; } diff --git a/src/audio/web/web_audio_system.c b/src/audio/web/web_audio_system.c index 73779f760..914b325d1 100644 --- a/src/audio/web/web_audio_system.c +++ b/src/audio/web/web_audio_system.c @@ -79,7 +79,7 @@ static void webInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem ma_result result = ma_engine_init(&config, &ma->engine); if (result != MA_SUCCESS) { - Log_logError("Audio: Failed to initialize miniaudio engine in noDevice mode (error %d)\n", result); + logError("Audio: Failed to initialize miniaudio engine in noDevice mode (error %d)\n", result); ma->engineReady = false; return; } @@ -88,7 +88,7 @@ static void webInit(AudioSystem* audio, DataWin* dataWin, FileSystem* fileSystem memset(ma->instances, 0, sizeof(ma->instances)); ma->nextInstanceCounter = 0; - Log_log("Audio: web miniaudio engine initialized (noDevice, %d Hz, 2 ch)\n", ma->sampleRate); + logInfo("Audio: web miniaudio engine initialized (noDevice, %d Hz, 2 ch)\n", ma->sampleRate); } static void webDestroy(AudioSystem* audio) { @@ -166,14 +166,14 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio if (isStream) { int32_t streamSlot = soundIndex - WEB_AUDIO_STREAM_INDEX_BASE; if (0 > streamSlot || streamSlot >= WEB_MAX_AUDIO_STREAMS || !ma->streams[streamSlot].active) { - Log_logWarning("Audio: Invalid stream index %d\n", soundIndex); + logWarn("Audio: Invalid stream index %d\n", soundIndex); return -1; } streamPath = ma->streams[streamSlot].filePath; } else { DataWin* dw = ma->base.audioGroups[0]; if (0 > soundIndex || (uint32_t) soundIndex >= dw->sond.count) { - Log_logWarning("Audio: Invalid sound index %d\n", soundIndex); + logWarn("Audio: Invalid sound index %d\n", soundIndex); return -1; } sound = &dw->sond.sounds[soundIndex]; @@ -181,7 +181,7 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio WebSoundInstance* slot = findFreeSlot(ma); if (slot == nullptr) { - Log_logWarning("Audio: No free sound slots for sound %d\n", soundIndex); + logWarn("Audio: No free sound slots for sound %d\n", soundIndex); return -1; } @@ -191,7 +191,7 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio if (isStream) { result = ma_sound_init_from_file(&ma->engine, streamPath, MA_SOUND_FLAG_ASYNC, nullptr, nullptr, &slot->maSound); if (result != MA_SUCCESS) { - Log_logWarning("Audio: Failed to load stream file '%s' (error %d)\n", streamPath, result); + logWarn("Audio: Failed to load stream file '%s' (error %d)\n", streamPath, result); return -1; } slot->ownsDecoder = false; @@ -203,7 +203,7 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio if (inAudo) { if (0 > sound->audioFile || (uint32_t) sound->audioFile >= ma->base.audioGroups[sound->audioGroup]->audo.count) { - Log_logWarning("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); + logWarn("Audio: Invalid audio file index %d for sound '%s'\n", sound->audioFile, sound->name); return -1; } @@ -212,27 +212,27 @@ static int32_t webPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prio ma_decoder_config decoderConfig = ma_decoder_config_init_default(); result = ma_decoder_init_memory(entry->data, entry->dataSize, &decoderConfig, &slot->decoder); if (result != MA_SUCCESS) { - Log_logWarning("Audio: Failed to init decoder for '%s' (error %d)\n", sound->name, result); + logWarn("Audio: Failed to init decoder for '%s' (error %d)\n", sound->name, result); return -1; } slot->ownsDecoder = true; result = ma_sound_init_from_data_source(&ma->engine, &slot->decoder, 0, nullptr, &slot->maSound); if (result != MA_SUCCESS) { - Log_logWarning("Audio: Failed to init sound from decoder for '%s' (error %d)\n", sound->name, result); + logWarn("Audio: Failed to init sound from decoder for '%s' (error %d)\n", sound->name, result); ma_decoder_uninit(&slot->decoder); return -1; } } else { char* path = resolveExternalPath(ma, sound); if (path == nullptr) { - Log_logWarning("Audio: Could not resolve path for sound '%s'\n", sound->name); + logWarn("Audio: Could not resolve path for sound '%s'\n", sound->name); return -1; } result = ma_sound_init_from_file(&ma->engine, path, MA_SOUND_FLAG_ASYNC, nullptr, nullptr, &slot->maSound); if (result != MA_SUCCESS) { - Log_logWarning("Audio: Failed to load file for '%s' at '%s' (error %d)\n", sound->name, path, result); + logWarn("Audio: Failed to load file for '%s' at '%s' (error %d)\n", sound->name, path, result); free(path); return -1; } @@ -605,7 +605,7 @@ static void webGroupLoad(AudioSystem* audio, int32_t groupIndex) { // The original runner does not care if the file doesn't exist (this may happen if someone uses "audio_group_load" on a non-existent group) FileSystem* fileSystem = ((WebAudioSystem*)audio)->fileSystem; if (!fileSystem->vtable->fileExists(fileSystem, buf)) { - Log_logWarning("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the file system!\n", groupIndex, groupIndex); + logWarn("Audio: Wanted to load Audio Group %d, but Audio Group %d does not exist in the file system!\n", groupIndex, groupIndex); free(buf); return; } @@ -634,13 +634,13 @@ static int32_t webCreateStream(AudioSystem* audio, const char* filename) { } if (0 > freeSlot) { - Log_logWarning("Audio: No free stream slots for '%s'\n", filename); + logWarn("Audio: No free stream slots for '%s'\n", filename); return -1; } char* resolved = ma->fileSystem->vtable->resolvePath(ma->fileSystem, filename); if (resolved == nullptr) { - Log_logWarning("Audio: Could not resolve path for stream '%s'\n", filename); + logWarn("Audio: Could not resolve path for stream '%s'\n", filename); return -1; } @@ -648,7 +648,7 @@ static int32_t webCreateStream(AudioSystem* audio, const char* filename) { ma->streams[freeSlot].filePath = resolved; int32_t streamIndex = WEB_AUDIO_STREAM_INDEX_BASE + freeSlot; - Log_log("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); + logInfo("Audio: Created stream %d for '%s' -> '%s'\n", streamIndex, filename, resolved); return streamIndex; } @@ -658,7 +658,7 @@ static bool webDestroyStream(AudioSystem* audio, int32_t streamIndex) { int32_t slotIndex = streamIndex - WEB_AUDIO_STREAM_INDEX_BASE; if (0 > slotIndex || slotIndex >= WEB_MAX_AUDIO_STREAMS) { - Log_logWarning("Audio: Invalid stream index %d for destroy\n", streamIndex); + logWarn("Audio: Invalid stream index %d for destroy\n", streamIndex); return false; } diff --git a/src/binary_reader.c b/src/binary_reader.c index 1f3e7891b..9ced421bd 100644 --- a/src/binary_reader.c +++ b/src/binary_reader.c @@ -30,7 +30,7 @@ static void readCheck(BinaryReader* reader, void* dest, size_t bytes) { if (reader->buffer != nullptr) { if (reader->bufferPos + bytes > reader->bufferSize) { size_t absPos = reader->bufferBase + reader->bufferPos; - Log_logError("BinaryReader: buffer read error at position 0x%zX (requested %zu bytes, buffer has %zu remaining)\n", absPos, bytes, reader->bufferSize - reader->bufferPos); + logError("BinaryReader: buffer read error at position 0x%zX (requested %zu bytes, buffer has %zu remaining)\n", absPos, bytes, reader->bufferSize - reader->bufferPos); abort(); } memcpy(dest, reader->buffer + reader->bufferPos, bytes); @@ -41,7 +41,7 @@ static void readCheck(BinaryReader* reader, void* dest, size_t bytes) { size_t read = fread(dest, 1, bytes, reader->file); if (read != bytes) { long pos = ftell(reader->file) - (long) read; - Log_logError("BinaryReader: read error at position 0x%lX (requested %zu bytes, got %zu, file size 0x%zX)\n", pos, bytes, read, reader->fileSize); + logError("BinaryReader: read error at position 0x%lX (requested %zu bytes, got %zu, file size 0x%zX)\n", pos, bytes, read, reader->fileSize); abort(); } } @@ -110,7 +110,7 @@ uint8_t* BinaryReader_readBytesAt(BinaryReader* reader, size_t offset, size_t co if (reader->buffer != nullptr) { if (offset < reader->bufferBase || offset + count > reader->bufferBase + reader->bufferSize) { - Log_logError("BinaryReader: readBytesAt offset 0x%zX+%zu out of buffer range [0x%zX, 0x%zX)\n", offset, count, reader->bufferBase, reader->bufferBase + reader->bufferSize); + logError("BinaryReader: readBytesAt offset 0x%zX+%zu out of buffer range [0x%zX, 0x%zX)\n", offset, count, reader->bufferBase, reader->bufferBase + reader->bufferSize); abort(); } size_t savedPos = reader->bufferPos; @@ -137,7 +137,7 @@ void BinaryReader_skip(BinaryReader* reader, size_t bytes) { void BinaryReader_seek(BinaryReader* reader, size_t position) { if (reader->buffer != nullptr) { if (position < reader->bufferBase || position > reader->bufferBase + reader->bufferSize) { - Log_logError("BinaryReader: buffer seek to 0x%zX out of buffer range [0x%zX, 0x%zX]\n", position, reader->bufferBase, reader->bufferBase + reader->bufferSize); + logError("BinaryReader: buffer seek to 0x%zX out of buffer range [0x%zX, 0x%zX]\n", position, reader->bufferBase, reader->bufferBase + reader->bufferSize); abort(); } reader->bufferPos = position - reader->bufferBase; @@ -145,7 +145,7 @@ void BinaryReader_seek(BinaryReader* reader, size_t position) { } if (position > reader->fileSize) { - Log_logError("BinaryReader: seek to 0x%zX out of bounds (file size 0x%zX)\n", position, reader->fileSize); + logError("BinaryReader: seek to 0x%zX out of bounds (file size 0x%zX)\n", position, reader->fileSize); abort(); } fseek(reader->file, (long) position, SEEK_SET); diff --git a/src/data_win.c b/src/data_win.c index de46983bd..b0fc801da 100644 --- a/src/data_win.c +++ b/src/data_win.c @@ -822,7 +822,7 @@ static void parseSPRT(BinaryReader* reader, DataWin* dw, bool skipLoadingPrecise check = 0; } } else { - Log_logWarning("DataWin: Detected special sprite type %u (%s), but we don't support it yet!\n", spr->sSpriteType, spr->sSpriteType == 2 ? "Spine" : spr->sSpriteType == 1 ? "SWF" : "Unknown"); + logWarn("DataWin: Detected special sprite type %u (%s), but we don't support it yet!\n", spr->sSpriteType, spr->sSpriteType == 2 ? "Spine" : spr->sSpriteType == 1 ? "SWF" : "Unknown"); spr->textureCount = 0; spr->tpagIndices = nullptr; spr->maskCount = 0; @@ -1077,7 +1077,7 @@ static void parseACRV(BinaryReader* reader, DataWin* dw) { uint32_t version = BinaryReader_readUint32(reader); if (version != 1) { - Log_logWarning("ACRV: unexpected version %u (expected 1)\n", version); + logWarn("ACRV: unexpected version %u (expected 1)\n", version); return; } @@ -1858,7 +1858,7 @@ static void readRoomLayers(BinaryReader* reader, DataWin* dw, Room* room, uint32 break; } default: { - Log_logError("Unsupported Room Layer Type %u\n", layer->type); + logError("Unsupported Room Layer Type %u\n", layer->type); exit(0); } } @@ -2114,7 +2114,7 @@ static void parseROOM(BinaryReader* reader, DataWin* dw, bool lazyLoadRooms, Str static int32_t parseTexturePageItem(BinaryReader* reader, DataWin* dw, int32_t i) { int32_t position = i; if (i == -1) { - Log_logWarning("DataWin: Allocated new TPAG! Was the WAD built with WinPack? (TranslaTale)\n"); + logWarn("DataWin: Allocated new TPAG! Was the WAD built with WinPack? (TranslaTale)\n"); uint32_t newCount = dw->tpag.count + 1; TexturePageItem* newItems = (TexturePageItem *)safeCalloc(newCount, sizeof(TexturePageItem)); memcpy(newItems, dw->tpag.items, dw->tpag.count * sizeof(TexturePageItem)); @@ -2552,7 +2552,7 @@ void DataWin_loadTxtrIfNeeded(DataWin* dw, uint32_t textureId) { if (tex->blobData != nullptr) return; if (!dw->lazyLoadFile) { - Log_logWarning("loadTxtrIfNeeded: called without a lazy load file.\n"); + logWarn("loadTxtrIfNeeded: called without a lazy load file.\n"); return; } @@ -2565,7 +2565,7 @@ void DataWin_loadTxtrIfNeeded(DataWin* dw, uint32_t textureId) { fseek(dw->lazyLoadFile, old_seek, SEEK_SET); if (read != tex->blobSize) { - Log_logWarning("loadTxtrIfNeeded: couldn't read %u bytes to load a texture.\n", tex->blobSize); + logWarn("loadTxtrIfNeeded: couldn't read %u bytes to load a texture.\n", tex->blobSize); } } @@ -2603,7 +2603,7 @@ static void parseAUDO(BinaryReader* reader, DataWin* dw) { DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { FILE* file = fopen(filePath, "rb"); if (!file) { - Log_logError("Failed to open file: %s\n", filePath); + logError("Failed to open file: %s\n", filePath); exit(1); } @@ -2617,7 +2617,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { fseek(file, 0, SEEK_SET); if (0 >= fileSizeRaw) { - Log_logError("Invalid file size: %ld\n", fileSizeRaw); + logError("Invalid file size: %ld\n", fileSizeRaw); fclose(file); exit(1); } @@ -2639,7 +2639,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { } else if (options.loadType == DATAWINLOADTYPE_MAP_FILE) { wholeFileData = mapFile(file, fileSize); if (!wholeFileData) { - Log_logError("Failed to map file\n"); + logError("Failed to map file\n"); fclose(file); exit(1); } @@ -2653,7 +2653,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { // Some games may purposely corrupt the magic value so that UndertaleModTool doesn't open it // The native runner does not care about verifying the magic value, so we'll validate it and warn, but we won't exit if (memcmp(formMagic, "FORM", 4) != 0) { - Log_logWarning("The file does not have the expected FORM magic, got '%.4s'. The file may not be a WAD or it may have been tampered with!\n", formMagic); + logWarn("The file does not have the expected FORM magic, got '%.4s'. The file may not be a WAD or it may have been tampered with!\n", formMagic); } uint32_t formLength = BinaryReader_readUint32(&reader); @@ -2700,7 +2700,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { } if (chunkDataStart + chunkLength > fileSize) { - Log_logWarning("Chunk data extends beyond file size: chunkDataStart=%zu, chunkLength=%u, fileSize=%zu! Are you running a GameMaker Raspberry Pi game? Skipping bytes out of bounds...\n", chunkDataStart, chunkLength, fileSize); + logWarn("Chunk data extends beyond file size: chunkDataStart=%zu, chunkLength=%u, fileSize=%zu! Are you running a GameMaker Raspberry Pi game? Skipping bytes out of bounds...\n", chunkDataStart, chunkLength, fileSize); break; } @@ -2709,7 +2709,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { } if (!codeExists && options.parseCode) { - Log_logError("CODE chunk does not exist or is empty! This usually means you're loading a YYC game.\n"); + logError("CODE chunk does not exist or is empty! This usually means you're loading a YYC game.\n"); fclose(file); exit(1); } @@ -2767,7 +2767,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { if (chunkBuffer) { size_t read = fread(chunkBuffer, 1, chunkLength, reader.file); if (read != chunkLength) { - Log_logError("DataWin: short read on chunk %.4s (expected %u, got %zu)\n", chunkName, chunkLength, read); + logError("DataWin: short read on chunk %.4s (expected %u, got %zu)\n", chunkName, chunkLength, read); exit(1); } BinaryReader_setBuffer(&reader, chunkBuffer, chunkDataStart, chunkLength); @@ -2840,7 +2840,7 @@ DataWin* DataWin_parse(const char* filePath, DataWinParserOptions options) { } else if (options.parseAudo && memcmp(chunkName, "AUDO", 4) == 0) { parseAUDO(&reader, dw); } else { - Log_log("Unknown chunk: %.4s (length %u at offset 0x%zX)\n", chunkName, chunkLength, chunkDataStart - 8); + logInfo("Unknown chunk: %.4s (length %u at offset 0x%zX)\n", chunkName, chunkLength, chunkDataStart - 8); } // Free the chunk buffer and revert to FILE*-based reads for the next header diff --git a/src/data_win_print.c b/src/data_win_print.c index f3968a365..28c78a96b 100644 --- a/src/data_win_print.c +++ b/src/data_win_print.c @@ -6,139 +6,139 @@ #include "utils.h" void DataWin_printDebugSummary(DataWin* dataWin) { - Log_log("===== data.win Summary =====\n\n"); + logInfo("===== data.win Summary =====\n\n"); // GEN8 Gen8* g = &dataWin->gen8; - Log_log("-- GEN8 (General Info) --\n"); - Log_log(" Game Name: %s\n", g->name ? g->name : "(null)"); - Log_log(" Display Name: %s\n", g->displayName ? g->displayName : "(null)"); - Log_log(" File Name: %s\n", g->fileName ? g->fileName : "(null)"); - Log_log(" Config: %s\n", g->config ? g->config : "(null)"); - Log_log(" WAD Version: %u\n", g->wadVersion); - Log_log(" Game ID: %u\n", g->gameID); - Log_log(" Version: %u.%u.%u.%u\n", g->major, g->minor, g->release, g->build); - Log_log(" Window Size: %ux%u\n", g->defaultWindowWidth, g->defaultWindowHeight); - Log_log(" Steam App ID: %d\n", g->steamAppID); - Log_log(" Room Order: %u rooms\n", g->roomOrderCount); - Log_log("\n"); + logInfo("-- GEN8 (General Info) --\n"); + logInfo(" Game Name: %s\n", g->name ? g->name : "(null)"); + logInfo(" Display Name: %s\n", g->displayName ? g->displayName : "(null)"); + logInfo(" File Name: %s\n", g->fileName ? g->fileName : "(null)"); + logInfo(" Config: %s\n", g->config ? g->config : "(null)"); + logInfo(" WAD Version: %u\n", g->wadVersion); + logInfo(" Game ID: %u\n", g->gameID); + logInfo(" Version: %u.%u.%u.%u\n", g->major, g->minor, g->release, g->build); + logInfo(" Window Size: %ux%u\n", g->defaultWindowWidth, g->defaultWindowHeight); + logInfo(" Steam App ID: %d\n", g->steamAppID); + logInfo(" Room Order: %u rooms\n", g->roomOrderCount); + logInfo("\n"); // OPTN - Log_log("-- OPTN (Options) --\n"); - Log_log(" Constants: %u\n", dataWin->optn.constantCount); + logInfo("-- OPTN (Options) --\n"); + logInfo(" Constants: %u\n", dataWin->optn.constantCount); if (dataWin->optn.constantCount > 0) { uint32_t show = dataWin->optn.constantCount < 3 ? dataWin->optn.constantCount : 3; forEachIndexed(OptnConstant, constant, idx, dataWin->optn.constants, show) { - Log_log(" [%u] %s = %s\n", (unsigned int)idx, constant->name ? constant->name : "?", constant->value ? constant->value : "?"); + logInfo(" [%u] %s = %s\n", (unsigned int)idx, constant->name ? constant->name : "?", constant->value ? constant->value : "?"); } - if (dataWin->optn.constantCount > 3) Log_log(" ... and %u more\n", dataWin->optn.constantCount - 3); + if (dataWin->optn.constantCount > 3) logInfo(" ... and %u more\n", dataWin->optn.constantCount - 3); } - Log_log("\n"); + logInfo("\n"); // LANG - Log_log("-- LANG (Languages) --\n"); - Log_log(" Languages: %u\n", dataWin->lang.languageCount); - Log_log(" Entries: %u\n", dataWin->lang.entryCount); - Log_log("\n"); + logInfo("-- LANG (Languages) --\n"); + logInfo(" Languages: %u\n", dataWin->lang.languageCount); + logInfo(" Entries: %u\n", dataWin->lang.entryCount); + logInfo("\n"); // EXTN - Log_log("-- EXTN (Extensions) --\n"); - Log_log(" Extensions: %u\n", dataWin->extn.count); + logInfo("-- EXTN (Extensions) --\n"); + logInfo(" Extensions: %u\n", dataWin->extn.count); forEachIndexed(Extension, ext, idx, dataWin->extn.extensions, dataWin->extn.count) { - Log_log(" [%u] %s (%u files)\n", (unsigned int)idx, ext->name ? ext->name : "?", ext->fileCount); + logInfo(" [%u] %s (%u files)\n", (unsigned int)idx, ext->name ? ext->name : "?", ext->fileCount); } - Log_log("\n"); + logInfo("\n"); // SOND - Log_log("-- SOND (Sounds) --\n"); - Log_log(" Sounds: %u\n", dataWin->sond.count); + logInfo("-- SOND (Sounds) --\n"); + logInfo(" Sounds: %u\n", dataWin->sond.count); if (dataWin->sond.count > 0) { uint32_t show = dataWin->sond.count < 3 ? dataWin->sond.count : 3; forEachIndexed(Sound, snd, idx, dataWin->sond.sounds, show) { - Log_log(" [%u] %s (%s)\n", (unsigned int)idx, snd->name ? snd->name : "?", snd->type ? snd->type : "?"); + logInfo(" [%u] %s (%s)\n", (unsigned int)idx, snd->name ? snd->name : "?", snd->type ? snd->type : "?"); } - if (dataWin->sond.count > 3) Log_log(" ... and %u more\n", dataWin->sond.count - 3); + if (dataWin->sond.count > 3) logInfo(" ... and %u more\n", dataWin->sond.count - 3); } - Log_log("\n"); + logInfo("\n"); // AGRP - Log_log("-- AGRP (Audio Groups) --\n"); - Log_log(" Audio Groups: %u\n", dataWin->agrp.count); + logInfo("-- AGRP (Audio Groups) --\n"); + logInfo(" Audio Groups: %u\n", dataWin->agrp.count); forEachIndexed(AudioGroup, ag, idx, dataWin->agrp.audioGroups, dataWin->agrp.count) { - Log_log(" [%u] %s\n", (unsigned int)idx, ag->name ? ag->name : "?"); + logInfo(" [%u] %s\n", (unsigned int)idx, ag->name ? ag->name : "?"); } - Log_log("\n"); + logInfo("\n"); // SPRT - Log_log("-- SPRT (Sprites) --\n"); - Log_log(" Sprites: %u\n", dataWin->sprt.count); + logInfo("-- SPRT (Sprites) --\n"); + logInfo(" Sprites: %u\n", dataWin->sprt.count); if (dataWin->sprt.count > 0) { uint32_t show = dataWin->sprt.count < 3 ? dataWin->sprt.count : 3; forEachIndexed(Sprite, spr, idx, dataWin->sprt.sprites, show) { - Log_log(" [%u] %s (%ux%u, %u frames)\n", (unsigned int)idx, spr->name ? spr->name : "?", spr->width, spr->height, spr->textureCount); + logInfo(" [%u] %s (%ux%u, %u frames)\n", (unsigned int)idx, spr->name ? spr->name : "?", spr->width, spr->height, spr->textureCount); } - if (dataWin->sprt.count > 3) Log_log(" ... and %u more\n", dataWin->sprt.count - 3); + if (dataWin->sprt.count > 3) logInfo(" ... and %u more\n", dataWin->sprt.count - 3); } - Log_log("\n"); + logInfo("\n"); // BGND - Log_log("-- BGND (Backgrounds) --\n"); - Log_log(" Backgrounds: %u\n", dataWin->bgnd.count); + logInfo("-- BGND (Backgrounds) --\n"); + logInfo(" Backgrounds: %u\n", dataWin->bgnd.count); if (dataWin->bgnd.count > 0) { uint32_t show = dataWin->bgnd.count < 3 ? dataWin->bgnd.count : 3; forEachIndexed(Background, bg, idx, dataWin->bgnd.backgrounds, show) { - Log_log(" [%u] %s\n", (unsigned int)idx, bg->name ? bg->name : "?"); + logInfo(" [%u] %s\n", (unsigned int)idx, bg->name ? bg->name : "?"); } - if (dataWin->bgnd.count > 3) Log_log(" ... and %u more\n", dataWin->bgnd.count - 3); + if (dataWin->bgnd.count > 3) logInfo(" ... and %u more\n", dataWin->bgnd.count - 3); } - Log_log("\n"); + logInfo("\n"); // PATH - Log_log("-- PATH (Paths) --\n"); - Log_log(" Paths: %u\n", dataWin->path.count); - Log_log("\n"); + logInfo("-- PATH (Paths) --\n"); + logInfo(" Paths: %u\n", dataWin->path.count); + logInfo("\n"); // SCPT - Log_log("-- SCPT (Scripts) --\n"); - Log_log(" Scripts: %u\n", dataWin->scpt.count); + logInfo("-- SCPT (Scripts) --\n"); + logInfo(" Scripts: %u\n", dataWin->scpt.count); if (dataWin->scpt.count > 0) { uint32_t show = dataWin->scpt.count < 3 ? dataWin->scpt.count : 3; forEachIndexed(Script, scr, idx, dataWin->scpt.scripts, show) { - Log_log(" [%u] %s -> code[%d]\n", (unsigned int)idx, scr->name ? scr->name : "?", scr->codeId); + logInfo(" [%u] %s -> code[%d]\n", (unsigned int)idx, scr->name ? scr->name : "?", scr->codeId); } - if (dataWin->scpt.count > 3) Log_log(" ... and %u more\n", dataWin->scpt.count - 3); + if (dataWin->scpt.count > 3) logInfo(" ... and %u more\n", dataWin->scpt.count - 3); } - Log_log("\n"); + logInfo("\n"); // GLOB - Log_log("-- GLOB (Global Init Scripts) --\n"); - Log_log(" Init Scripts: %u\n", dataWin->glob.count); - Log_log("\n"); + logInfo("-- GLOB (Global Init Scripts) --\n"); + logInfo(" Init Scripts: %u\n", dataWin->glob.count); + logInfo("\n"); // SHDR - Log_log("-- SHDR (Shaders) --\n"); - Log_log(" Shaders: %u\n", dataWin->shdr.count); + logInfo("-- SHDR (Shaders) --\n"); + logInfo(" Shaders: %u\n", dataWin->shdr.count); forEachIndexed(Shader, shdr, idx, dataWin->shdr.shaders, dataWin->shdr.count) { - Log_log(" [%u] %s (version %d)\n", (unsigned int)idx, shdr->name ? shdr->name : "?", shdr->version); + logInfo(" [%u] %s (version %d)\n", (unsigned int)idx, shdr->name ? shdr->name : "?", shdr->version); } - Log_log("\n"); + logInfo("\n"); // FONT - Log_log("-- FONT (Fonts) --\n"); - Log_log(" Fonts: %u\n", dataWin->font.count); + logInfo("-- FONT (Fonts) --\n"); + logInfo(" Fonts: %u\n", dataWin->font.count); forEachIndexed(Font, fnt, idx, dataWin->font.fonts, dataWin->font.count) { - Log_log(" [%u] %s (%s, em=%u, %u glyphs)\n", (unsigned int)idx, fnt->name ? fnt->name : "?", fnt->displayName ? fnt->displayName : "?", fnt->emSize, fnt->glyphCount); + logInfo(" [%u] %s (%s, em=%u, %u glyphs)\n", (unsigned int)idx, fnt->name ? fnt->name : "?", fnt->displayName ? fnt->displayName : "?", fnt->emSize, fnt->glyphCount); } - Log_log("\n"); + logInfo("\n"); // TMLN - Log_log("-- TMLN (Timelines) --\n"); - Log_log(" Timelines: %u\n", dataWin->tmln.count); - Log_log("\n"); + logInfo("-- TMLN (Timelines) --\n"); + logInfo(" Timelines: %u\n", dataWin->tmln.count); + logInfo("\n"); // OBJT - Log_log("-- OBJT (Game Objects) --\n"); - Log_log(" Objects: %u\n", dataWin->objt.count); + logInfo("-- OBJT (Game Objects) --\n"); + logInfo(" Objects: %u\n", dataWin->objt.count); if (dataWin->objt.count > 0) { uint32_t show = dataWin->objt.count < 3 ? dataWin->objt.count : 3; forEachIndexed(GameObject, obj, idx, dataWin->objt.objects, show) { @@ -146,75 +146,75 @@ void DataWin_printDebugSummary(DataWin* dataWin) { repeat(OBJT_EVENT_TYPE_COUNT, e) { totalEvents += obj->eventLists[e].eventCount; } - Log_log(" [%u] %s (sprite=%d, depth=%d, %u events)\n", (unsigned int)idx, obj->name ? obj->name : "?", obj->spriteId, obj->depth, totalEvents); + logInfo(" [%u] %s (sprite=%d, depth=%d, %u events)\n", (unsigned int)idx, obj->name ? obj->name : "?", obj->spriteId, obj->depth, totalEvents); } - if (dataWin->objt.count > 3) Log_log(" ... and %u more\n", dataWin->objt.count - 3); + if (dataWin->objt.count > 3) logInfo(" ... and %u more\n", dataWin->objt.count - 3); } - Log_log("\n"); + logInfo("\n"); // ROOM - Log_log("-- ROOM (Rooms) --\n"); - Log_log(" Rooms: %u\n", dataWin->room.count); + logInfo("-- ROOM (Rooms) --\n"); + logInfo(" Rooms: %u\n", dataWin->room.count); if (dataWin->room.count > 0) { uint32_t show = dataWin->room.count < 3 ? dataWin->room.count : 3; forEachIndexed(Room, rm, idx, dataWin->room.rooms, show) { if (rm->payloadLoaded) { - Log_log(" [%u] %s (%ux%u, %u objects, %u tiles)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height, rm->gameObjectCount, rm->tileCount); + logInfo(" [%u] %s (%ux%u, %u objects, %u tiles)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height, rm->gameObjectCount, rm->tileCount); } else { // Lazy room with payload not yet loaded: gameObjectCount/tileCount would be 0 and misleading. - Log_log(" [%u] %s (%ux%u, payload not loaded)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height); + logInfo(" [%u] %s (%ux%u, payload not loaded)\n", (unsigned int)idx, rm->name ? rm->name : "?", rm->width, rm->height); } } - if (dataWin->room.count > 3) Log_log(" ... and %u more\n", dataWin->room.count - 3); + if (dataWin->room.count > 3) logInfo(" ... and %u more\n", dataWin->room.count - 3); } - Log_log("\n"); + logInfo("\n"); // TPAG - Log_log("-- TPAG (Texture Page Items) --\n"); - Log_log(" Items: %u\n", dataWin->tpag.count); - Log_log("\n"); + logInfo("-- TPAG (Texture Page Items) --\n"); + logInfo(" Items: %u\n", dataWin->tpag.count); + logInfo("\n"); // CODE - Log_log("-- CODE (Code Entries) --\n"); - Log_log(" Entries: %u\n", dataWin->code.count); + logInfo("-- CODE (Code Entries) --\n"); + logInfo(" Entries: %u\n", dataWin->code.count); if (dataWin->code.count > 0) { uint32_t show = dataWin->code.count < 3 ? dataWin->code.count : 3; forEachIndexed(CodeEntry, entry, idx, dataWin->code.entries, show) { - Log_log(" [%u] %s (%u bytes, %u locals, %u args)\n", (unsigned int)idx, entry->name ? entry->name : "?", entry->length, entry->localsCount, entry->argumentsCount); + logInfo(" [%u] %s (%u bytes, %u locals, %u args)\n", (unsigned int)idx, entry->name ? entry->name : "?", entry->length, entry->localsCount, entry->argumentsCount); } - if (dataWin->code.count > 3) Log_log(" ... and %u more\n", dataWin->code.count - 3); + if (dataWin->code.count > 3) logInfo(" ... and %u more\n", dataWin->code.count - 3); } - Log_log("\n"); + logInfo("\n"); // VARI - Log_log("-- VARI (Variables) --\n"); - Log_log(" Variables: %u\n", dataWin->vari.variableCount); - Log_log(" Max Locals: %u\n", dataWin->vari.maxLocalVarCount); + logInfo("-- VARI (Variables) --\n"); + logInfo(" Variables: %u\n", dataWin->vari.variableCount); + logInfo(" Max Locals: %u\n", dataWin->vari.maxLocalVarCount); if (dataWin->vari.variableCount > 0) { uint32_t show = dataWin->vari.variableCount < 3 ? dataWin->vari.variableCount : 3; forEachIndexed(Variable, var, idx, dataWin->vari.variables, show) { - Log_log(" [%u] %s (type=%d, id=%d, %u refs)\n", (unsigned int)idx, var->name ? var->name : "?", var->instanceType, var->varID, var->occurrences); + logInfo(" [%u] %s (type=%d, id=%d, %u refs)\n", (unsigned int)idx, var->name ? var->name : "?", var->instanceType, var->varID, var->occurrences); } - if (dataWin->vari.variableCount > 3) Log_log(" ... and %u more\n", dataWin->vari.variableCount - 3); + if (dataWin->vari.variableCount > 3) logInfo(" ... and %u more\n", dataWin->vari.variableCount - 3); } - Log_log("\n"); + logInfo("\n"); // FUNC - Log_log("-- FUNC (Functions) --\n"); - Log_log(" Functions: %u\n", dataWin->func.functionCount); - Log_log(" Code Locals: %u\n", dataWin->func.codeLocalsCount); + logInfo("-- FUNC (Functions) --\n"); + logInfo(" Functions: %u\n", dataWin->func.functionCount); + logInfo(" Code Locals: %u\n", dataWin->func.codeLocalsCount); if (dataWin->func.functionCount > 0) { uint32_t show = dataWin->func.functionCount < 3 ? dataWin->func.functionCount : 3; forEachIndexed(Function, fn, idx, dataWin->func.functions, show) { - Log_log(" [%u] %s (%u refs)\n", (unsigned int)idx, fn->name ? fn->name : "?", fn->occurrences); + logInfo(" [%u] %s (%u refs)\n", (unsigned int)idx, fn->name ? fn->name : "?", fn->occurrences); } - if (dataWin->func.functionCount > 3) Log_log(" ... and %u more\n", dataWin->func.functionCount - 3); + if (dataWin->func.functionCount > 3) logInfo(" ... and %u more\n", dataWin->func.functionCount - 3); } - Log_log("\n"); + logInfo("\n"); // STRG - Log_log("-- STRG (Strings) --\n"); - Log_log(" Strings: %u\n", dataWin->strg.count); + logInfo("-- STRG (Strings) --\n"); + logInfo(" Strings: %u\n", dataWin->strg.count); if (dataWin->strg.count > 0) { uint32_t show = dataWin->strg.count < 5 ? dataWin->strg.count : 5; repeat(show, i) { @@ -223,56 +223,56 @@ void DataWin_printDebugSummary(DataWin* dataWin) { if (str) { size_t len = strlen(str); if (len > 60) { - Log_log(" [%u] \"%.60s...\" (%zu chars)\n", (unsigned int)i, str, len); + logInfo(" [%u] \"%.60s...\" (%zu chars)\n", (unsigned int)i, str, len); } else { - Log_log(" [%u] \"%s\"\n", (unsigned int)i, str); + logInfo(" [%u] \"%s\"\n", (unsigned int)i, str); } } else { - Log_log(" [%u] (null)\n", (unsigned int)i); + logInfo(" [%u] (null)\n", (unsigned int)i); } } - if (dataWin->strg.count > 5) Log_log(" ... and %u more\n", dataWin->strg.count - 5); + if (dataWin->strg.count > 5) logInfo(" ... and %u more\n", dataWin->strg.count - 5); } - Log_log("\n"); + logInfo("\n"); // TXTR - Log_log("-- TXTR (Textures) --\n"); - Log_log(" Textures: %u\n", dataWin->txtr.count); + logInfo("-- TXTR (Textures) --\n"); + logInfo(" Textures: %u\n", dataWin->txtr.count); if (dataWin->txtr.count > 0) { forEachIndexed(Texture, tex, idx, dataWin->txtr.textures, dataWin->txtr.count) { - Log_log(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, tex->blobOffset, tex->blobSize); + logInfo(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, tex->blobOffset, tex->blobSize); } } - Log_log("\n"); + logInfo("\n"); // AUDO - Log_log("-- AUDO (Audio) --\n"); - Log_log(" Audio Entries: %u\n", dataWin->audo.count); + logInfo("-- AUDO (Audio) --\n"); + logInfo(" Audio Entries: %u\n", dataWin->audo.count); if (dataWin->audo.count > 0) { uint32_t show = dataWin->audo.count < 3 ? dataWin->audo.count : 3; forEachIndexed(AudioEntry, ae, idx, dataWin->audo.entries, show) { - Log_log(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, ae->dataOffset, ae->dataSize); + logInfo(" [%u] offset=0x%08X size=%u bytes\n", (unsigned int)idx, ae->dataOffset, ae->dataSize); } - if (dataWin->audo.count > 3) Log_log(" ... and %u more\n", dataWin->audo.count - 3); + if (dataWin->audo.count > 3) logInfo(" ... and %u more\n", dataWin->audo.count - 3); } - Log_log("\n"); + logInfo("\n"); - Log_log("-- Room Instances --\n"); + logInfo("-- Room Instances --\n"); forEach(Room, room, dataWin->room.rooms, dataWin->room.count) { - Log_log("Room %s\n", room->name); + logInfo("Room %s\n", room->name); if (!room->payloadLoaded) { - Log_log(" (payload not loaded)\n"); + logInfo(" (payload not loaded)\n"); continue; } forEachIndexed(RoomGameObject, roomGameObject, idx, room->gameObjects, room->gameObjectCount) { int32_t objectDefinitionId = roomGameObject->objectDefinition; GameObject* objectDefinition = &dataWin->objt.objects[objectDefinitionId]; - Log_log(" Object %d (%s, x=%d, y=%d)\n", objectDefinitionId, objectDefinition->name, roomGameObject->x, roomGameObject->y); + logInfo(" Object %d (%s, x=%d, y=%d)\n", objectDefinitionId, objectDefinition->name, roomGameObject->x, roomGameObject->y); } } // Overall summary - Log_log("===== DataWin parse complete =====\n"); + logInfo("===== DataWin parse complete =====\n"); } diff --git a/src/desktop/backends/glfw2.c b/src/desktop/backends/glfw2.c index b5106afba..9a0181f9c 100644 --- a/src/desktop/backends/glfw2.c +++ b/src/desktop/backends/glfw2.c @@ -186,18 +186,18 @@ static void GLFWCALL scrollCallback(int pos) { bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) { if (headless) { - Log_logError("Headless mode is not supported with GLFW 2\n"); + logError("Headless mode is not supported with GLFW 2\n"); return false; } // Init GLFW if (!glfwInit()) { - Log_logError("Failed to initialize GLFW\n"); + logError("Failed to initialize GLFW\n"); return false; } if (!tryOpenWindow(reqW, reqH)) { - Log_logError("Failed to create GLFW window\n"); + logError("Failed to create GLFW window\n"); glfwTerminate(); return false; } diff --git a/src/desktop/backends/glfw3.c b/src/desktop/backends/glfw3.c index e6ad00f88..bb4b4bd74 100644 --- a/src/desktop/backends/glfw3.c +++ b/src/desktop/backends/glfw3.c @@ -127,7 +127,7 @@ static bool platformGetWindowFocus(void) { } static void glfwErrorCallback(int code, const char* description) { - Log_logWarning("GLFW error 0x%x: %s\n", code, description); + logWarn("GLFW error 0x%x: %s\n", code, description); } static int32_t glfwKeyToGml(int glfwKey) { @@ -224,7 +224,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) // Init GLFW glfwSetErrorCallback(glfwErrorCallback); if (!glfwInit()) { - Log_logError("Failed to initialize GLFW\n"); + logError("Failed to initialize GLFW\n"); return false; } @@ -241,23 +241,23 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) buffer[len] = '\0'; if (buffer[0] != '\0') { if (glfwUpdateGamepadMappings(buffer)) { - Log_log("Gamepad: Loaded SDL gamecontroller mappings successfully\n"); + logInfo("Gamepad: Loaded SDL gamecontroller mappings successfully\n"); } else { - Log_logWarning("Gamepad: Failed to load SDL gamecontroller mappings\n"); + logWarn("Gamepad: Failed to load SDL gamecontroller mappings\n"); } } free(buffer); } fclose(f); } else - Log_logWarning("Gamepad: SDL gamecontrollerdb.txt not found at %s, using defaults\n", dbPath); + logWarn("Gamepad: SDL gamecontrollerdb.txt not found at %s, using defaults\n", dbPath); if (headless) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); window = tryOpenWindow(reqW, reqH, title); if (!window) { - Log_logError("Failed to create GLFW window\n"); + logError("Failed to create GLFW window\n"); glfwTerminate(); return false; } diff --git a/src/desktop/backends/sdl1.c b/src/desktop/backends/sdl1.c index 80ebd9139..0eccb4ba4 100644 --- a/src/desktop/backends/sdl1.c +++ b/src/desktop/backends/sdl1.c @@ -137,7 +137,7 @@ static void loadGamepadMappings(void) { const char* dbPath = "gamecontrollerdb.txt"; FILE* f = fopen(dbPath, "rb"); if (!f) { - Log_logWarning("Gamepad: SDL gamecontrollerdb.txt not found at %s, ignoring mappings\n", dbPath); + logWarn("Gamepad: SDL gamecontrollerdb.txt not found at %s, ignoring mappings\n", dbPath); return; } @@ -194,7 +194,7 @@ static void loadGamepadMappings(void) { const char* jname = SDL_JoystickName(i); if (jname && strcasecmp(jname, name) == 0) { joystickMappings[i] = temp; - Log_log("Gamepad: Mapped '%s' (slot %d)\n", jname, i); + logInfo("Gamepad: Mapped '%s' (slot %d)\n", jname, i); } } } @@ -240,13 +240,13 @@ static bool platformGetWindowFocus(void) { bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) { if (headless && gfx != SOFTWARE) { - Log_logError("Headless mode on SDL 1.2 requires the software renderer!\n"); + logError("Headless mode on SDL 1.2 requires the software renderer!\n"); return false; } // Init SDL if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK)) { - Log_logError("Failed to initialize SDL\n"); + logError("Failed to initialize SDL\n"); return false; } @@ -271,7 +271,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) if (!scr && gfx == SOFTWARE) { SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN); if (modes && modes != (SDL_Rect**) -1 && modes[0]) { - Log_logWarning("Warning: %dx%d unavailable, falling back to %dx%d: %s\n", + logWarn("Warning: %dx%d unavailable, falling back to %dx%d: %s\n", reqW, reqH, modes[0]->w, modes[0]->h, SDL_GetError()); scr = SDL_SetVideoMode(modes[0]->w, modes[0]->h, 0, 0); fbWidth = modes[0]->w; @@ -279,7 +279,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) } } if (!scr) { - Log_logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); + logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); return false; } } diff --git a/src/desktop/backends/sdl2.c b/src/desktop/backends/sdl2.c index 10b747449..3d3b1511c 100644 --- a/src/desktop/backends/sdl2.c +++ b/src/desktop/backends/sdl2.c @@ -167,7 +167,7 @@ static bool platformGetWindowFocus(void) { bool platformInit(int reqW, int reqH, const char *title, bool headless) { // Init SDL if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_GAMECONTROLLER)) { - Log_logError("Failed to initialize SDL\n"); + logError("Failed to initialize SDL\n"); return false; } @@ -187,14 +187,14 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { window = tryOpenWindow(reqW, reqH, title, flags); if (!window && gfx != SOFTWARE) { - Log_logError("Fatal: Could not open window: %s\n", SDL_GetError()); + logError("Fatal: Could not open window: %s\n", SDL_GetError()); return false; } if (!window && gfx == SOFTWARE) { SDL_DisplayMode mode; if (SDL_GetDisplayMode(0, 0, &mode) == 0) { - Log_logWarning("Warning: %dx%d unavailable, falling back to %dx%d: %s\n", + logWarn("Warning: %dx%d unavailable, falling back to %dx%d: %s\n", reqW, reqH, mode.w, mode.h, SDL_GetError()); reqW = mode.w; reqH = mode.h; @@ -208,7 +208,7 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { } } if (!window) { - Log_logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); + logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); return false; } if (gfx != SOFTWARE) { @@ -222,9 +222,9 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { // init gamepad mappings const char* dbPath = "gamecontrollerdb.txt"; if (SDL_GameControllerAddMappingsFromFile(dbPath) >= 0) { - Log_log("Gamepad: Loaded SDL gamecontroller mappings successfully\n"); + logInfo("Gamepad: Loaded SDL gamecontroller mappings successfully\n"); } else { - Log_logWarning("Gamepad: SDL gamecontrollerdb.txt not found at %s or failed to load, using defaults\n", dbPath); + logWarn("Gamepad: SDL gamecontrollerdb.txt not found at %s or failed to load, using defaults\n", dbPath); } return true; diff --git a/src/desktop/backends/sdl3.c b/src/desktop/backends/sdl3.c index a45fa528e..217e7c802 100644 --- a/src/desktop/backends/sdl3.c +++ b/src/desktop/backends/sdl3.c @@ -149,7 +149,7 @@ static bool platformGetWindowFocus(void) { bool platformInit(int reqW, int reqH, const char *title, bool headless) { // Init SDL if (!SDL_Init(SDL_INIT_VIDEO|SDL_INIT_GAMEPAD)) { - Log_logError("Failed to initialize SDL\n"); + logError("Failed to initialize SDL\n"); return false; } @@ -164,7 +164,7 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { window = tryOpenWindow(fbWidth, fbHeight, title, flags); if (!window && gfx != SOFTWARE) { - Log_logError("Fatal: Could not open window: %s\n", SDL_GetError()); + logError("Fatal: Could not open window: %s\n", SDL_GetError()); return false; } @@ -182,7 +182,7 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { } } if (!window) { - Log_logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); + logError("Fatal: Could not set any video mode: %s\n", SDL_GetError()); return false; } if (gfx != SOFTWARE) { diff --git a/src/desktop/main.c b/src/desktop/main.c index 974e5465e..ed86aae92 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -114,7 +114,7 @@ static bool platformInitGlad(void) { if (!glGetString) return 0; - Log_log("OpenGL Version: %s\n", (const char*)glGetString(GL_VERSION)); + logInfo("OpenGL Version: %s\n", (const char*)glGetString(GL_VERSION)); GLVer ver = GLCommon_getGLVersion(); if (ver.isGLES) { @@ -164,7 +164,7 @@ static void APIENTRY glDebugCallback(GLenum source, GLenum type, GLuint id, GLen default: severityStr = "Unknown"; break; } - Log_log("[OpenGL %s] id=%u Type: %s; Severity: %s; Message: %.*s\n", sourceStr, id, typeStr, severityStr, (int) length, message); + logInfo("[OpenGL %s] id=%u Type: %s; Severity: %s; Message: %.*s\n", sourceStr, id, typeStr, severityStr, (int) length, message); } static void installGLDebugCallback(void) { @@ -304,7 +304,7 @@ static bool parseOsTypeArg(const char* s, YoYoOperatingSystem* out) { static void printOsTypeNames(FILE* out) { bool addFileSucceeded = Log_addFile(out); forEachIndexed(const OsTypeNameEntry, entry, i, OS_TYPE_NAMES, OS_TYPE_NAMES_COUNT) { - Log_logToFile("%s%s", i > 0 ? ", " : "", entry->name); + logInfoToFile("%s%s", i > 0 ? ", " : "", entry->name); } if (addFileSucceeded) Log_removeFile(out); } @@ -390,7 +390,7 @@ static char** extractRunnerArguments(char* rawArguments) { } static void printUsage(const char *argv0) { - Log_log( + logInfo( "Usage: %s \n" " --help - Show this message\n" " --screenshot - Specify the filename for screenshots\n" @@ -548,7 +548,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - Log_logError("Error: Invalid frame number '%s'\n", optarg); + logError("Error: Invalid frame number '%s'\n", optarg); exit(1); } @@ -562,7 +562,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - Log_logError("Error: Invalid frame number '%s' for --screenshot-surfaces-at-frame\n", optarg); + logError("Error: Invalid frame number '%s' for --screenshot-surfaces-at-frame\n", optarg); exit(1); } hmput(args->screenshotSurfacesFrames, frame, true); @@ -630,7 +630,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - Log_logError("Error: Invalid frame number '%s' for --exit-at-frame\n", optarg); + logError("Error: Invalid frame number '%s' for --exit-at-frame\n", optarg); exit(1); } args->exitAtFrame = frame; @@ -640,7 +640,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - Log_logError("Error: Invalid frame number '%s' for --trace-bytecode-after-frame\n", optarg); + logError("Error: Invalid frame number '%s' for --trace-bytecode-after-frame\n", optarg); exit(1); } args->traceBytecodeAfterFrame = frame; @@ -650,7 +650,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - Log_logError("Error: Invalid frame number '%s' for --dump-frame\n", optarg); + logError("Error: Invalid frame number '%s' for --dump-frame\n", optarg); exit(1); } hmput(args->dumpFrames, frame, true); @@ -660,7 +660,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - Log_logError("Error: Invalid frame number '%s' for --dump-frame-json\n", optarg); + logError("Error: Invalid frame number '%s' for --dump-frame-json\n", optarg); exit(1); } hmput(args->dumpJsonFrames, frame, true); @@ -673,7 +673,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; double speed = strtod(optarg, &endPtr); if (*endPtr != '\0' || speed <= 0.0) { - Log_logError("Error: Invalid speed multiplier '%s' for --speed (must be > 0)\n", optarg); + logError("Error: Invalid speed multiplier '%s' for --speed (must be > 0)\n", optarg); exit(1); } args->speedMultiplier = speed; @@ -683,7 +683,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; double speed = strtod(optarg, &endPtr); if (*endPtr != '\0' || speed <= 0.0) { - Log_logError("Error: Invalid speed '%s' for --fast-forward-speed (must be > 0)\n", optarg); + logError("Error: Invalid speed '%s' for --fast-forward-speed (must be > 0)\n", optarg); exit(1); } args->fastForwardSpeed = speed; @@ -714,7 +714,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int seedVal = strtol(optarg, &endPtr, 10); if (*endPtr != '\0') { - Log_logError("Error: Invalid seed value '%s' for --seed\n", optarg); + logError("Error: Invalid seed value '%s' for --seed\n", optarg); exit(1); } args->seed = seedVal; @@ -731,7 +731,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int framesBetween = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || framesBetween <= 0) { - Log_logError("Error: Invalid frame count '%s' for --profile-gml-scripts (must be > 0)\n", optarg); + logError("Error: Invalid frame count '%s' for --profile-gml-scripts (must be > 0)\n", optarg); exit(1); } args->profilerFramesBetween = framesBetween; @@ -755,16 +755,16 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) #endif case 'O': if (!parseOsTypeArg(optarg, &args->osType)) { - Log_logError("Error: Invalid --os-type value '%s' (expected: ", optarg); + logError("Error: Invalid --os-type value '%s' (expected: ", optarg); printOsTypeNames(stderr); - Log_logError(")\n"); + logError(")\n"); exit(1); } break; case 'w': { int32_t w = 0, h = 0; if (sscanf(optarg, "%dx%d", &w, &h) != 2 || 0 >= w || 0 >= h) { - Log_logError("Error: Invalid --window-size value '%s' (expected WxH, e.g. 960x544)\n", optarg); + logError("Error: Invalid --window-size value '%s' (expected WxH, e.g. 960x544)\n", optarg); exit(1); } args->windowWidth = w; @@ -779,7 +779,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } else if (strcmp(optarg, "load-per-chunk") == 0) { args->loadType = DATAWINLOADTYPE_LOAD_PER_CHUNK; } else { - Log_logError("Error: Unknown load type '%s'\n", optarg); + logError("Error: Unknown load type '%s'\n", optarg); exit(1); } break; @@ -797,7 +797,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } else if ((ratio = strtod(optarg, &endPtr)), *endPtr == '\0' && ratio > 0.0) { args->widescreenAspect = (float) ratio; } else { - Log_logError("Error: Invalid --widescreen-hack value '%s' (expected W:H like 16:9, or a decimal like 1.7778)\n", optarg); + logError("Error: Invalid --widescreen-hack value '%s' (expected W:H like 16:9, or a decimal like 1.7778)\n", optarg); exit(1); } break; @@ -824,24 +824,24 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } if (optind >= argc) { - Log_logError("Usage: %s \n", argv[0]); + logError("Usage: %s \n", argv[0]); exit(1); } args->dataWinPath = argv[optind]; if (hmlen(args->screenshotFrames) > 0 && args->screenshotPattern == nullptr) { - Log_logError("Error: --screenshot-at-frame requires --screenshot to be set\n"); + logError("Error: --screenshot-at-frame requires --screenshot to be set\n"); exit(1); } if (hmlen(args->screenshotSurfacesFrames) > 0 && args->screenshotSurfacesPattern == nullptr) { - Log_logError("Error: --screenshot-surfaces-at-frame requires --screenshot-surfaces to be set\n"); + logError("Error: --screenshot-surfaces-at-frame requires --screenshot-surfaces to be set\n"); exit(1); } if (args->headless && args->speedMultiplier != 1.0) { - Log_logError("You can't set the speed multiplier while running in headless mode! Headless mode always run in real time\n"); + logError("You can't set the speed multiplier while running in headless mode! Headless mode always run in real time\n"); exit(1); } } @@ -877,7 +877,7 @@ static void writeFramebufferAsPng(GLuint fbo, int width, int height, const char* int stride = width * 4; unsigned char* pixels = (unsigned char *)safeMalloc(stride * height); if (pixels == nullptr) { - Log_logWarning("Warning: Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height); + logWarn("Warning: Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height); return; } @@ -897,7 +897,7 @@ static void writeFramebufferAsPng(GLuint fbo, int width, int height, const char* } free(pixels); - Log_log("%s: %s (%dx%d)\n", logPrefix, filename, width, height); + logInfo("%s: %s (%dx%d)\n", logPrefix, filename, width, height); } static void captureScreenshot(GLuint fbo, const char* filenamePattern, int frameNumber, int width, int height, bool flipY) { @@ -1053,7 +1053,7 @@ int main(int argc, char* argv[]) { int32_t inputFrameCount = 0; while (true) { - Log_log("Loading %s...\n", args.dataWinPath); + logInfo("Loading %s...\n", args.dataWinPath); DataWinParserOptions options = {0}; options.parseGen8 = true; @@ -1090,12 +1090,12 @@ int main(int argc, char* argv[]) { DataWin* dataWin = DataWin_parse(currentDataWinPath, options); Gen8* gen8 = &dataWin->gen8; - Log_log("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); + logInfo("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); #ifdef HAVE_MALLINFO2 { struct mallinfo2 mi = mallinfo2(); - Log_log("Memory after data.win parsing: used=%zu bytes (%.1f KB)\n", mi.uordblks, mi.uordblks / 1024.0f); + logInfo("Memory after data.win parsing: used=%zu bytes (%.1f KB)\n", mi.uordblks, mi.uordblks / 1024.0f); } #endif @@ -1118,7 +1118,7 @@ int main(int argc, char* argv[]) { if (args.hasSeed) { srand((unsigned int) args.seed); vm->hasFixedSeed = true; - Log_log("Using fixed RNG seed: %d\n", args.seed); + logInfo("Using fixed RNG seed: %d\n", args.seed); } if (args.printRooms) { @@ -1126,7 +1126,7 @@ int main(int argc, char* argv[]) { // reflects what each room contains without keeping all of them resident simultaneously. forEachIndexed(Room, room, idx, dataWin->room.rooms, dataWin->room.count) { if (!room->present) { - Log_log("[%d] \n", (int)idx); + logInfo("[%d] \n", (int)idx); continue; } bool loadedHere = false; @@ -1135,15 +1135,15 @@ int main(int argc, char* argv[]) { loadedHere = true; } - Log_log("[%d] %s ()\n", (int)idx, room->name); + logInfo("[%d] %s ()\n", (int)idx, room->name); forEachIndexed(RoomGameObject, roomGameObject, idx2, room->gameObjects, room->gameObjectCount) { if (roomGameObject->objectDefinition < 0 || (uint32_t) roomGameObject->objectDefinition >= dataWin->objt.count) { - Log_log(" [%d] (x=%d,y=%d)\n", (int)idx2, roomGameObject->x, roomGameObject->y); + logInfo(" [%d] (x=%d,y=%d)\n", (int)idx2, roomGameObject->x, roomGameObject->y); continue; } GameObject* gameObject = &dataWin->objt.objects[roomGameObject->objectDefinition]; - Log_log( + logInfo( " [%d] %s (x=%d,y=%d,persistent=%d,solid=%d,spriteId=%d,preCreateCode=%d,creationCode=%d)\n", (int)idx2, gameObject->name, @@ -1172,22 +1172,22 @@ int main(int argc, char* argv[]) { repeat(OBJT_EVENT_TYPE_COUNT, e) { totalEvents += obj->eventLists[e].eventCount; } - Log_log("[%u] %s:\n", (unsigned int)idx, obj->name); + logInfo("[%u] %s:\n", (unsigned int)idx, obj->name); if (obj->parentId >= 0 && (uint32_t) obj->parentId < dataWin->objt.count) { - Log_log(" Parent: %s (%d)\n", dataWin->objt.objects[obj->parentId].name, obj->parentId); + logInfo(" Parent: %s (%d)\n", dataWin->objt.objects[obj->parentId].name, obj->parentId); } else { - Log_log(" Parent: none\n"); + logInfo(" Parent: none\n"); } if (obj->spriteId >= 0 && (uint32_t) obj->spriteId < dataWin->sprt.count) { - Log_log(" Sprite: %s (%d)\n", dataWin->sprt.sprites[obj->spriteId].name, obj->spriteId); + logInfo(" Sprite: %s (%d)\n", dataWin->sprt.sprites[obj->spriteId].name, obj->spriteId); } else { - Log_log(" Sprite: none\n"); + logInfo(" Sprite: none\n"); } - Log_log(" Solid: %d\n", obj->solid); - Log_log(" Persistent: %d\n", obj->persistent); - Log_log(" Visible: %d\n", obj->visible); - Log_log(" Depth: %d\n", obj->depth); - Log_log(" Events (%u):\n", totalEvents); + logInfo(" Solid: %d\n", obj->solid); + logInfo(" Persistent: %d\n", obj->persistent); + logInfo(" Visible: %d\n", obj->visible); + logInfo(" Depth: %d\n", obj->depth); + logInfo(" Events (%u):\n", totalEvents); repeat(OBJT_EVENT_TYPE_COUNT, e) { ObjectEventList* list = &obj->eventLists[e]; repeat(list->eventCount, eIdx) { @@ -1195,10 +1195,10 @@ int main(int argc, char* argv[]) { const char* eventName = Runner_getEventName((int32_t) e, (int32_t) event->eventSubtype); int32_t codeId = -1; if (event->actionCount > 0) codeId = event->actions[0].codeId; - Log_log(" %s:\n", eventName); - Log_log(" Sub Type: %u\n", event->eventSubtype); - Log_log(" Code ID: %d\n", codeId); - Log_log(" Actions: %u\n", event->actionCount); + logInfo(" %s:\n", eventName); + logInfo(" Sub Type: %u\n", event->eventSubtype); + logInfo(" Code ID: %d\n", codeId); + logInfo(" Actions: %u\n", event->actionCount); } } } @@ -1209,25 +1209,25 @@ int main(int argc, char* argv[]) { if (args.printShaders) { forEachIndexed(Shader, shader, idx, dataWin->shdr.shaders, dataWin->shdr.count) { - Log_log("[%u] %s:\n", (unsigned int)idx, shader->name); - Log_log("GLSL Vertex Shader:\n"); + logInfo("[%u] %s:\n", (unsigned int)idx, shader->name); + logInfo("GLSL Vertex Shader:\n"); char* glslVertex = collapseNewlines(shader->glsl_Vertex); - Log_log("%s\n", glslVertex); + logInfo("%s\n", glslVertex); free(glslVertex); - Log_log("GLSL Fragment Shader:\n"); + logInfo("GLSL Fragment Shader:\n"); char* glslFragment = collapseNewlines(shader->glsl_Fragment); - Log_log("%s\n", glslFragment); + logInfo("%s\n", glslFragment); free(glslFragment); - Log_log("GLSL ES Vertex Shader:\n"); + logInfo("GLSL ES Vertex Shader:\n"); char* glslESVertex = collapseNewlines(shader->glslES_Vertex); - Log_log("%s\n", glslESVertex); + logInfo("%s\n", glslESVertex); free(glslESVertex); - Log_log("GLSL ES Fragment Shader:\n"); + logInfo("GLSL ES Fragment Shader:\n"); char* glslESFragment = collapseNewlines(shader->glslES_Fragment); - Log_log("%s\n", glslESFragment); + logInfo("%s\n", glslESFragment); free(glslESFragment); } VM_free(vm); @@ -1237,7 +1237,7 @@ int main(int argc, char* argv[]) { if (args.printDeclaredFunctions) { repeat(hmlen(vm->codeIndexByName), i) { - Log_log("[%d] %s\n", vm->codeIndexByName[i].value, vm->codeIndexByName[i].key); + logInfo("[%d] %s\n", vm->codeIndexByName[i].value, vm->codeIndexByName[i].key); } VM_free(vm); DataWin_free(dataWin); @@ -1246,7 +1246,7 @@ int main(int argc, char* argv[]) { if (args.printUnknownFunctions) { uint32_t unimplementedCount = 0; - Log_log("Unknown Functions:\n"); + logInfo("Unknown Functions:\n"); repeat(dataWin->func.functionCount, i) { const char* name = dataWin->func.functions[i].name; if (name == nullptr) @@ -1260,14 +1260,14 @@ int main(int argc, char* argv[]) { if (VM_findBuiltin(vm, name) != nullptr) continue; - Log_log("- %s\n", name); + logInfo("- %s\n", name); unimplementedCount++; } if (unimplementedCount == 0) { - Log_log("All %u referenced functions are implemented! :3\n", dataWin->func.functionCount); + logInfo("All %u referenced functions are implemented! :3\n", dataWin->func.functionCount); } else { - Log_log("%u unknown function(s) out of %u referenced\n", unimplementedCount, dataWin->func.functionCount); + logInfo("%u unknown function(s) out of %u referenced\n", unimplementedCount, dataWin->func.functionCount); } VM_free(vm); DataWin_free(dataWin); @@ -1287,7 +1287,7 @@ int main(int argc, char* argv[]) { if (idx >= 0) { VM_disassemble(vm, vm->codeIndexByName[idx].value); } else { - Log_logWarning("Warning: Script '%s' not found in funcMap\n", name); + logWarn("Warning: Script '%s' not found in funcMap\n", name); } } } @@ -1324,31 +1324,31 @@ int main(int argc, char* argv[]) { else if (strcmp(args.renderer, "software") == 0) gfx = SOFTWARE; else { - Log_logError("Unknown renderer: %s!\n", args.renderer); + logError("Unknown renderer: %s!\n", args.renderer); return 1; } #ifndef ENABLE_LEGACY_GL if (gfx == LEGACY_GL) { - Log_logError("The legacy gl renderer is not available in this build!\n"); + logError("The legacy gl renderer is not available in this build!\n"); return 0; } #endif #ifndef ENABLE_MODERN_GL if (gfx == MODERN_GL) { - Log_logError("The modern gl renderer is not available in this build!\n"); + logError("The modern gl renderer is not available in this build!\n"); return 0; } #endif #ifndef ENABLE_SW_RENDERER if (gfx == SOFTWARE) { - Log_logError("The software renderer is not available in this build!\n"); + logError("The software renderer is not available in this build!\n"); return 0; } #endif if (gfx != MODERN_GL && hmlen(args.screenshotSurfacesFrames)) { - Log_logError("You can only use --screenshot-surfaces with the modern gl renderer!\n"); + logError("You can only use --screenshot-surfaces with the modern gl renderer!\n"); return 0; } @@ -1370,7 +1370,7 @@ int main(int argc, char* argv[]) { if (gfx == LEGACY_GL || gfx == MODERN_GL) { #endif if (!platformInitGlad()) { - Log_logError("Failed to initialize GLAD\n"); + logError("Failed to initialize GLAD\n"); platformExit(); DataWin_free(dataWin); freeCommandLineArgs(&args); @@ -1412,7 +1412,7 @@ int main(int argc, char* argv[]) { } #endif if (!renderer) { - Log_logError("Failed to initialize a renderer\n"); + logError("Failed to initialize a renderer\n"); platformExit(); DataWin_free(dataWin); freeCommandLineArgs(&args); @@ -1539,7 +1539,7 @@ int main(int argc, char* argv[]) { // Pause if (RunnerKeyboard_checkPressed(runner->keyboard, 'P')) { debugPaused = !debugPaused; - Log_logDebug("%s\n", debugPaused ? "Paused" : "Resumed"); + logDebug("%s\n", debugPaused ? "Paused" : "Resumed"); } } @@ -1547,7 +1547,7 @@ int main(int argc, char* argv[]) { bool shouldStep = true; if (runner->debugMode && debugPaused) { shouldStep = RunnerKeyboard_checkPressed(runner->keyboard, 'O'); - if (shouldStep) Log_logDebug("Frame advance (frame %d)\n", runner->frameCount); + if (shouldStep) logDebug("Frame advance (frame %d)\n", runner->frameCount); } uint64_t frameStartTime = 0; @@ -1555,7 +1555,7 @@ int main(int argc, char* argv[]) { if (shouldStep) { if (args.traceFrames) { frameStartTime = nowNanos(); - Log_log("Frame %d (Start)\n", runner->frameCount); + logInfo("Frame %d (Start)\n", runner->frameCount); } // Process input recording/playback (must happen after platformHandleEvents, before Runner_step) @@ -1568,7 +1568,7 @@ int main(int argc, char* argv[]) { int32_t nextIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition + 1]; runner->pendingRoom = nextIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_logDebug("Going to next room -> %s\n", dw->room.rooms[nextIdx].name); + logDebug("Going to next room -> %s\n", dw->room.rooms[nextIdx].name); } } @@ -1579,18 +1579,18 @@ int main(int argc, char* argv[]) { int32_t prevIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition - 1]; runner->pendingRoom = prevIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_logDebug("Going to previous room -> %s\n", dw->room.rooms[prevIdx].name); + logDebug("Going to previous room -> %s\n", dw->room.rooms[prevIdx].name); } } // Dump runner state to console if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F12)) { - Log_logDebug("Dumping runner state at frame %d\n", runner->frameCount); + logDebug("Dumping runner state at frame %d\n", runner->frameCount); Runner_dumpState(runner); } if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F11)) { - Log_logDebug("Dumping runner state at frame %d\n", runner->frameCount); + logDebug("Dumping runner state at frame %d\n", runner->frameCount); char* json = Runner_dumpStateJson(runner); if (args.dumpJsonFilePattern != nullptr) { @@ -1601,12 +1601,12 @@ int main(int argc, char* argv[]) { fwrite(json, 1, strlen(json), f); fputc('\n', f); fclose(f); - Log_log("JSON dump saved: %s\n", filename); + logInfo("JSON dump saved: %s\n", filename); } else { - Log_logWarning("Warning: Could not write JSON dump to '%s'\n", filename); + logWarn("Warning: Could not write JSON dump to '%s'\n", filename); } } else { - Log_log("%s\n", json); + logInfo("%s\n", json); } free(json); @@ -1615,7 +1615,7 @@ int main(int argc, char* argv[]) { // Toggle the collision mask debug overlay if (RunnerKeyboard_checkPressed(runner->keyboard, VK_F2)) { debugShowCollisionMasks = !debugShowCollisionMasks; - Log_logDebug("Collision mask overlay %s!\n", debugShowCollisionMasks ? "enabled" : "disabled"); + logDebug("Collision mask overlay %s!\n", debugShowCollisionMasks ? "enabled" : "disabled"); } // Enable free cam @@ -1625,7 +1625,7 @@ int main(int argc, char* argv[]) { runner->freeCamZoom = 1.0f; freeCamActive = !freeCamActive; - Log_logDebug("Free cam %s!\n", freeCamActive ? "enabled" : "disabled"); + logDebug("Free cam %s!\n", freeCamActive ? "enabled" : "disabled"); } if (freeCamActive) { @@ -1651,7 +1651,7 @@ int main(int argc, char* argv[]) { int32_t interactVarId = shget(runner->vmContext->varNameMap, "interact"); Instance_setSelfVar(runner->vmContext->globalScopeInstance, interactVarId, RValue_makeInt32(0)); - Log_log("Changed global.interact [%d] value!\n", interactVarId); + logInfo("Changed global.interact [%d] value!\n", interactVarId); } bool currentKeyDown[GML_KEY_COUNT]; @@ -1681,7 +1681,7 @@ int main(int argc, char* argv[]) { if (args.profilerFramesBetween > 0 && runner->frameCount > 0 && runner->frameCount % args.profilerFramesBetween == 0) { char* profilerReport = Profiler_createReport(vm->profiler, 20, args.profilerFramesBetween); if (profilerReport != nullptr) { - Log_log("%s\n", profilerReport); + logInfo("%s\n", profilerReport); free(profilerReport); } Profiler_reset(vm->profiler); @@ -1709,12 +1709,12 @@ int main(int argc, char* argv[]) { fwrite(json, 1, strlen(json), f); fputc('\n', f); fclose(f); - Log_log("JSON dump saved: %s\n", filename); + logInfo("JSON dump saved: %s\n", filename); } else { - Log_logWarning("Warning: Could not write JSON dump to '%s'\n", filename); + logWarn("Warning: Could not write JSON dump to '%s'\n", filename); } } else { - Log_log("%s\n", json); + logInfo("%s\n", json); } free(json); } @@ -1812,13 +1812,13 @@ int main(int argc, char* argv[]) { #endif if (args.exitAtFrame >= 0 && runner->frameCount >= args.exitAtFrame) { - Log_log("Exiting at frame %d (--exit-at-frame)\n", runner->frameCount); + logInfo("Exiting at frame %d (--exit-at-frame)\n", runner->frameCount); shouldWindowClose = true; } if (shouldStep && args.traceFrames) { double frameElapsedMs = (nowNanos() - frameStartTime) / 1000000.0; - Log_log("Frame %d (End, %.2f ms)\n", runner->frameCount, frameElapsedMs); + logInfo("Frame %d (End, %.2f ms)\n", runner->frameCount, frameElapsedMs); } // Only swap when there isn't a room change to match the original runner. @@ -1830,9 +1830,9 @@ int main(int argc, char* argv[]) { if (RunnerKeyboard_checkPressed(runner->keyboard, VK_BACKSPACE)) { size_t bytes_used = get_used_memory(); if (bytes_used == 0) - Log_logWarning("Unable to get memory usage\n"); + logWarn("Unable to get memory usage\n"); else - Log_log("Memory use right now: %zu bytes (%.1f MB)\n", bytes_used, bytes_used / 1024.0f / 1024.0f); + logInfo("Memory use right now: %zu bytes (%.1f MB)\n", bytes_used, bytes_used / 1024.0f / 1024.0f); } // Limit frame rate to room speed (skip in headless mode for max speed!!) @@ -1887,7 +1887,7 @@ int main(int argc, char* argv[]) { free(currentGameArgs[i]); } arrfree(currentGameArgs); - Log_log("Bye! :3\n"); + logInfo("Bye! :3\n"); #ifdef _WIN32 timeEndPeriod(1); #endif @@ -1917,7 +1917,7 @@ int main(int argc, char* argv[]) { } if (dataWinFilename == nullptr) { - Log_logError("Runner: Launch parameters '%s' did not contain a '-game ' entry! Shutting down...\n", nextLaunchParameters); + logError("Runner: Launch parameters '%s' did not contain a '-game ' entry! Shutting down...\n", nextLaunchParameters); free(nextWorkingDirectory); free(nextLaunchParameters); freeCommandLineArgs(&args); diff --git a/src/event_table.c b/src/event_table.c index c83e90723..4bcf34d42 100644 --- a/src/event_table.c +++ b/src/event_table.c @@ -115,7 +115,7 @@ void ResolvedEventTable_build(ResolvedEventTable* outTable, DataWin* dw, const E int32_t slotCount = slotMap->slotCount; if (objectCount > MAX_EVENT_TABLE_OBJECT_COUNT) { - Log_logError("ResolvedEventTable: objectCount=%d exceeds max %d!\n", objectCount, MAX_EVENT_TABLE_OBJECT_COUNT); + logError("ResolvedEventTable: objectCount=%d exceeds max %d!\n", objectCount, MAX_EVENT_TABLE_OBJECT_COUNT); abort(); } diff --git a/src/gl/gl_renderer.c b/src/gl/gl_renderer.c index e739fde93..eaa1c0b08 100644 --- a/src/gl/gl_renderer.c +++ b/src/gl/gl_renderer.c @@ -86,7 +86,7 @@ static GLuint compileShader(GLenum type, const char* source, bool* ok) { if (!success) { char infoLog[512]; glGetShaderInfoLog(shader, sizeof(infoLog), nullptr, infoLog); - Log_logError("GL: Shader compilation failed: %s\n", infoLog); + logError("GL: Shader compilation failed: %s\n", infoLog); *ok = false; return 0; } @@ -110,11 +110,11 @@ static GLuint linkProgram(const char* name, uint32_t vertexAttributeCount, const if (!success) { char infoLog[512]; glGetProgramInfoLog(program, sizeof(infoLog), nullptr, infoLog); - Log_logError("GL: Shader %s linking failed: %s\n", name, infoLog); + logError("GL: Shader %s linking failed: %s\n", name, infoLog); *success2 = false; } else { *success2 = true; - Log_log("GL: Shader %s succesfully linked!\n", name); + logInfo("GL: Shader %s succesfully linked!\n", name); } return program; } @@ -201,18 +201,18 @@ static void flushIfNeededAndSetActiveState(GLRenderer* gl, BatchType batchType, // ===[ Vtable Implementations ]=== static bool compileProgram(GMLShader* gmlShader, const char* name, const char* vertexShaderSource, const char* fragmentShaderSource, uint32_t vertexAttributeCount, const char** vertexAttributes) { - Log_log("GL: Compiling %s vertex shader\n", name); + logInfo("GL: Compiling %s vertex shader\n", name); bool vertexShaderOK = false; bool fragmentShaderOK = false; GLuint vertShaderT = compileShader(GL_VERTEX_SHADER, vertexShaderSource, &vertexShaderOK); if (!vertexShaderOK) { - Log_logError("GL: Failed to compile %s vertex shader!\n", name); + logError("GL: Failed to compile %s vertex shader!\n", name); return false; } - Log_log("GL: Compiling %s fragment shader\n", name); + logInfo("GL: Compiling %s fragment shader\n", name); GLuint fragShaderT = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource, &fragmentShaderOK); if (!fragmentShaderOK) { - Log_logError("GL: Failed to compile %s fragment shader!\n", name); + logError("GL: Failed to compile %s fragment shader!\n", name); return false; } @@ -269,14 +269,14 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { GMLShader* defaultShader = (GMLShader*)safeCalloc(1, sizeof(GMLShader)); GLVer ver = GLCommon_getGLVersion(); if (ver.major < 2) { - Log_logError("GL: The modern-gl renderer requires OpenGL 2.0 or newer\n"); + logError("GL: The modern-gl renderer requires OpenGL 2.0 or newer\n"); abort(); } gl->isGL3 = (ver.major >= 3); gl->isGLES = ver.isGLES; if (!hasFBO()) { - Log_logError("GL: The modern-gl renderer requires FBO support\n"); + logError("GL: The modern-gl renderer requires FBO support\n"); abort(); } @@ -336,14 +336,14 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { const char* defaultAttributes[] = { "aPos", "aColor", "aTexCoord" }; bool success = compileProgram(defaultShader, "default", vertSrc, fragSrc, 3, defaultAttributes); if (!success) { - Log_logError("GL: Failed to compile default shaders! Bailing...\n"); + logError("GL: Failed to compile default shaders! Bailing...\n"); abort(); } gl->defaultShaderProgram = defaultShader; gl->gmlShaders = (GMLShader *)safeCalloc(dataWin->shdr.count, sizeof(GMLShader)); - Log_log("GL: %u Shaders Found\n", dataWin->shdr.count); + logInfo("GL: %u Shaders Found\n", dataWin->shdr.count); repeat(dataWin->shdr.count, i) { Shader* shdr = &dataWin->shdr.shaders[i]; @@ -351,11 +351,11 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { if (!shdr->present) { gl->gmlShaderCount++; - Log_logWarning("GL: Skipping shader %d because it isn't present!\n", (int)i); + logWarn("GL: Skipping shader %d because it isn't present!\n", (int)i); continue; } - Log_log("GL: Compiling %s\n", shdr->name); + logInfo("GL: Compiling %s\n", shdr->name); const char* vertexShaderSource = gl->isGLES ? shdr->glslES_Vertex : shdr->glsl_Vertex; const char* fragmentShaderSource = gl->isGLES ? shdr->glslES_Fragment : shdr->glsl_Fragment; @@ -481,7 +481,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { gl->originalTpagCount = dataWin->tpag.count; gl->originalSpriteCount = dataWin->sprt.count; - Log_log("GL: Renderer initialized (%u texture pages)\n", gl->textureCount); + logInfo("GL: Renderer initialized (%u texture pages)\n", gl->textureCount); } static void glGpuSetShader(Renderer* renderer, int32_t shaderIndex) { @@ -866,7 +866,7 @@ bool GLRenderer_ensureTextureLoaded(GLRenderer* gl, uint32_t pageId) { bool gm2022_5 = DataWin_isVersionAtLeast(dw, 2022, 5, 0, 0); uint8_t* pixels = ImageDecoder_decodeToRgba(txtr->blobData, (size_t) txtr->blobSize, gm2022_5, &w, &h); if (pixels == nullptr) { - Log_logWarning("GL: Failed to decode TXTR page %u\n", pageId); + logWarn("GL: Failed to decode TXTR page %u\n", pageId); return false; } if (!txtr->mapped) { @@ -890,7 +890,7 @@ bool GLRenderer_ensureTextureLoaded(GLRenderer* gl, uint32_t pageId) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode); - Log_log("GL: Loaded TXTR page %u (%dx%d)\n", pageId, w, h); + logInfo("GL: Loaded TXTR page %u (%dx%d)\n", pageId, w, h); return true; } @@ -1940,7 +1940,7 @@ static int32_t glCreateSurface(Renderer* renderer, int32_t width, int32_t height gl->surfaceWidth[surfaceIndex] = width; gl->surfaceHeight[surfaceIndex] = height; - Log_log("GL: Created surface %u with size (%dx%d)\n", surfaceIndex, width, height); + logInfo("GL: Created surface %u with size (%dx%d)\n", surfaceIndex, width, height); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint) prevBinding); return (int32_t) surfaceIndex; @@ -1979,7 +1979,7 @@ static void glSurfaceFree(Renderer* renderer, int32_t surfaceID) { gl->surfaceTexture[surfaceID] = 0; gl->surfaceWidth[surfaceID] = 0; gl->surfaceHeight[surfaceID] = 0; - Log_log("GL: Freed Surface %u\n", surfaceID); + logInfo("GL: Freed Surface %u\n", surfaceID); } static void glSurfaceResize(Renderer* renderer, int32_t surfaceID, int32_t width, int32_t height) { @@ -2009,7 +2009,7 @@ static void glSurfaceResize(Renderer* renderer, int32_t surfaceID, int32_t width gl->surfaceWidth[surfaceID] = width; gl->surfaceHeight[surfaceID] = height; - Log_log("GL: Resized Surface %u Size (%dx%d)\n", surfaceID, width, height); + logInfo("GL: Resized Surface %u Size (%dx%d)\n", surfaceID, width, height); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint) prevBinding); } @@ -2287,7 +2287,7 @@ static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID, sprite->maskCount = 0; sprite->masks = nullptr; - Log_log("GL: Created dynamic sprite %u (%dx%d) from surface %d at (%d,%d)\n", spriteIndex, w, h, surfaceID, x, y); + logInfo("GL: Created dynamic sprite %u (%dx%d) from surface %d at (%d,%d)\n", spriteIndex, w, h, surfaceID, x, y); return (int32_t) spriteIndex; } @@ -2299,7 +2299,7 @@ static void glDeleteSprite(Renderer* renderer, int32_t spriteIndex) { // Refuse to delete original data.win sprites if (gl->originalSpriteCount > (uint32_t) spriteIndex) { - Log_logWarning("GL: Cannot delete data.win sprite %d\n", spriteIndex); + logWarn("GL: Cannot delete data.win sprite %d\n", spriteIndex); return; } @@ -2328,7 +2328,7 @@ static void glDeleteSprite(Renderer* renderer, int32_t spriteIndex) { memset(sprite, 0, sizeof(Sprite)); sprite->name = keepName; - Log_log("GL: Deleted sprite %d\n", spriteIndex); + logInfo("GL: Deleted sprite %d\n", spriteIndex); } static BlendFactors glGpuGetBlendFactors(Renderer* renderer) { @@ -2451,7 +2451,7 @@ static int32_t glShaderGetSamplerIndex(Renderer* renderer, int32_t shaderIndex, } } - Log_logWarning("GL: Sampler Index %s not found for shader %d!\n", uniform, shaderIndex); + logWarn("GL: Sampler Index %s not found for shader %d!\n", uniform, shaderIndex); return -1; } @@ -2546,7 +2546,7 @@ static void glTextureSetStage(Renderer* renderer, int32_t slot, uint32_t texHand GLRenderer* gl = (GLRenderer*) renderer; flushBatch(gl); if (slot < 0) { - Log_logWarning("GL: Invalid Texture Stage\n"); + logWarn("GL: Invalid Texture Stage\n"); return; } TexturePageItem* tpag; @@ -2557,7 +2557,7 @@ static void glTextureSetStage(Renderer* renderer, int32_t slot, uint32_t texHand gl->currentTextureId = texID; } if (slot > MAX_TEXTURE_STAGES) { - Log_logWarning("GL: Texture Stage Higher Than Max\n"); + logWarn("GL: Texture Stage Higher Than Max\n"); return; } glActiveTexture(GL_TEXTURE0 + slot); diff --git a/src/gl_legacy/gl_legacy_renderer.c b/src/gl_legacy/gl_legacy_renderer.c index 284c0c8dc..f516ef031 100644 --- a/src/gl_legacy/gl_legacy_renderer.c +++ b/src/gl_legacy/gl_legacy_renderer.c @@ -140,7 +140,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { renderer->gmlMatrices[MATRIX_WORLD] = world; if (!hasFBO()) { - Log_logError("GL: The legacy-gl renderer requires FBO support!\n"); + logError("GL: The legacy-gl renderer requires FBO support!\n"); abort(); } @@ -206,7 +206,7 @@ static void glInit(Renderer* renderer, DataWin* dataWin) { gl->surfaceHeight = nullptr; gl->surfaceCount = 0; - Log_log("GL: Renderer initialized (%u texture pages)\n", gl->textureCount); + logInfo("GL: Renderer initialized (%u texture pages)\n", gl->textureCount); } static void glDestroy(Renderer* renderer) { @@ -408,7 +408,7 @@ bool GLLegacyRenderer_ensureTextureLoaded(GLLegacyRenderer* gl, uint32_t pageId) // We'll load the textures on demand. uint8_t* pixels; if (!PS3Textures_loadPage(pageId, &w, &h, &pixels)) { - Log_logWarning("GL: PS3 page %u has no pixels\n", pageId); + logWarn("GL: PS3 page %u has no pixels\n", pageId); return false; } gl->textureWidths[pageId] = w; @@ -433,7 +433,7 @@ bool GLLegacyRenderer_ensureTextureLoaded(GLLegacyRenderer* gl, uint32_t pageId) bool gm2022_5 = DataWin_isVersionAtLeast(dw, 2022, 5, 0, 0); uint8_t* pixels = ImageDecoder_decodeToRgba(txtr->blobData, (size_t) txtr->blobSize, gm2022_5, &w, &h); if (pixels == nullptr) { - Log_logWarning("GL: Failed to decode TXTR page %u\n", pageId); + logWarn("GL: Failed to decode TXTR page %u\n", pageId); return false; } if (!txtr->mapped) { @@ -454,7 +454,7 @@ bool GLLegacyRenderer_ensureTextureLoaded(GLLegacyRenderer* gl, uint32_t pageId) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); #endif - Log_log("GL: Loaded TXTR page %u (%dx%d)\n", pageId, w, h); + logInfo("GL: Loaded TXTR page %u (%dx%d)\n", pageId, w, h); return true; } @@ -1419,7 +1419,7 @@ static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID, sprite->maskCount = 0; sprite->masks = nullptr; - Log_log("GL: Created dynamic sprite %u (%dx%d) from surface at (%d,%d)\n", spriteIndex, w, h, x, y); + logInfo("GL: Created dynamic sprite %u (%dx%d) from surface at (%d,%d)\n", spriteIndex, w, h, x, y); return (int32_t) spriteIndex; } @@ -1431,7 +1431,7 @@ static void glDeleteSprite(Renderer* renderer, int32_t spriteIndex) { // Refuse to delete original data.win sprites if (gl->originalSpriteCount > (uint32_t) spriteIndex) { - Log_logWarning("GL: Cannot delete data.win sprite %d\n", spriteIndex); + logWarn("GL: Cannot delete data.win sprite %d\n", spriteIndex); return; } @@ -1460,7 +1460,7 @@ static void glDeleteSprite(Renderer* renderer, int32_t spriteIndex) { memset(sprite, 0, sizeof(Sprite)); sprite->name = keepName; - Log_log("GL: Deleted sprite %d\n", spriteIndex); + logInfo("GL: Deleted sprite %d\n", spriteIndex); } static BlendFactors glGpuGetBlendFactors(Renderer* renderer) { @@ -1570,13 +1570,13 @@ static int32_t glLegacyCreateSurface(Renderer* renderer, int32_t width, int32_t GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { - Log_logWarning("GL: Surface FBO incomplete (status=0x%X)\n", status); + logWarn("GL: Surface FBO incomplete (status=0x%X)\n", status); } gl->surfaceWidth[surfaceIndex] = width; gl->surfaceHeight[surfaceIndex] = height; - Log_log("GL: Created surface %u with size (%dx%d)\n", surfaceIndex, width, height); + logInfo("GL: Created surface %u with size (%dx%d)\n", surfaceIndex, width, height); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint) prevBinding); return (int32_t) surfaceIndex; } @@ -1647,7 +1647,7 @@ static void glLegacySurfaceResize(Renderer* renderer, int32_t surfaceId, int32_t gl->surfaceWidth[surfaceId] = width; gl->surfaceHeight[surfaceId] = height; - Log_log("GL: Resized Surface %u to (%dx%d)\n", surfaceId, width, height); + logInfo("GL: Resized Surface %u to (%dx%d)\n", surfaceId, width, height); } static void glLegacySurfaceFree(Renderer* renderer, int32_t surfaceId) { @@ -1661,7 +1661,7 @@ static void glLegacySurfaceFree(Renderer* renderer, int32_t surfaceId) { gl->surfaceTexture[surfaceId] = 0; gl->surfaceWidth[surfaceId] = 0; gl->surfaceHeight[surfaceId] = 0; - Log_log("GL: Freed Surface %d\n", surfaceId); + logInfo("GL: Freed Surface %d\n", surfaceId); } static bool glLegacySetRenderTarget(Renderer* renderer, int32_t surfaceId, bool implicitApplicationSurface) { diff --git a/src/image/image_decoder.c b/src/image/image_decoder.c index b1d29ba3b..937ce4a86 100644 --- a/src/image/image_decoder.c +++ b/src/image/image_decoder.c @@ -136,7 +136,7 @@ static uint8_t* decodeBz2Qoi(const uint8_t* blob, size_t blobSize, bool gm2022_5 unsigned int destLen = (unsigned int) uncompressedCapacity; int rc = BZ2_bzBuffToBuffDecompress((char*) uncompressed, &destLen, (char*)(blob + headerSize), (unsigned int)(blobSize - headerSize), 0, 0); if (rc != BZ_OK) { - Log_logWarning("ImageDecoder: BZ2 decompress failed (rc=%d)\n", rc); + logWarn("ImageDecoder: BZ2 decompress failed (rc=%d)\n", rc); free(uncompressed); return nullptr; } diff --git a/src/ini.c b/src/ini.c index 6b8acbbd8..8cdb8d4d9 100644 --- a/src/ini.c +++ b/src/ini.c @@ -114,7 +114,7 @@ IniFile* Ini_parse(const char* text) { currentSection = addSection(ini, nameStart); } } else { - Log_logWarning("Ini: malformed section header: %s\n", trimmed); + logWarn("Ini: malformed section header: %s\n", trimmed); } } else { // Key=value pair diff --git a/src/input_recording.c b/src/input_recording.c index 35a5c2148..1feacb484 100644 --- a/src/input_recording.c +++ b/src/input_recording.c @@ -21,7 +21,7 @@ InputRecording* InputRecording_createPlayer(const char* playbackFilePath, const // Read the file contents FILE* f = fopen(playbackFilePath, "rb"); if (f == nullptr) { - Log_logError("Error: Could not open input recording file '%s'\n", playbackFilePath); + logError("Error: Could not open input recording file '%s'\n", playbackFilePath); exit(1); } @@ -39,7 +39,7 @@ InputRecording* InputRecording_createPlayer(const char* playbackFilePath, const free(contents); if (root == nullptr || !JsonReader_isObject(root)) { - Log_logError("Error: Invalid JSON in input recording file '%s'\n", playbackFilePath); + logError("Error: Invalid JSON in input recording file '%s'\n", playbackFilePath); exit(1); } @@ -94,7 +94,7 @@ InputRecording* InputRecording_createPlayer(const char* playbackFilePath, const } JsonReader_free(root); - Log_log("InputRecording: Loaded %d frames from '%s'\n", rec->playbackFrameCount, playbackFilePath); + logInfo("InputRecording: Loaded %d frames from '%s'\n", rec->playbackFrameCount, playbackFilePath); return rec; } @@ -143,7 +143,7 @@ void InputRecording_processFrame(InputRecording* recording, RunnerKeyboardState* } } else { if (!recording->playbackEnded) { - Log_log("InputRecording: Playback ended at frame %d (recorded %d frames)\n", frameNumber, recording->playbackFrameCount); + logInfo("InputRecording: Playback ended at frame %d (recorded %d frames)\n", frameNumber, recording->playbackFrameCount); recording->playbackEnded = true; } } @@ -214,7 +214,7 @@ bool InputRecording_save(InputRecording* recording) { FILE* f = fopen(recording->recordFilePath, "wb"); if (f == nullptr) { - Log_logWarning("Warning: Could not write input recording to '%s'\n", recording->recordFilePath); + logWarn("Warning: Could not write input recording to '%s'\n", recording->recordFilePath); JsonWriter_free(&w); return false; } @@ -224,7 +224,7 @@ bool InputRecording_save(InputRecording* recording) { fputc('\n', f); fclose(f); - Log_log("InputRecording: Saved %d frames to '%s'\n", frameCount, recording->recordFilePath); + logInfo("InputRecording: Saved %d frames to '%s'\n", frameCount, recording->recordFilePath); JsonWriter_free(&w); return true; } diff --git a/src/json_reader.c b/src/json_reader.c index 5bc06abc8..6d2e21782 100644 --- a/src/json_reader.c +++ b/src/json_reader.c @@ -107,7 +107,7 @@ static JsonValue* parseString(JsonParser* parser) { break; } default: - Log_logWarning("JsonReader: unknown escape sequence '\\%c'\n", escaped); + logWarn("JsonReader: unknown escape sequence '\\%c'\n", escaped); free(buffer); return nullptr; } @@ -122,7 +122,7 @@ static JsonValue* parseString(JsonParser* parser) { } // Unterminated string - Log_logWarning("JsonReader: unterminated string\n"); + logWarn("JsonReader: unterminated string\n"); free(buffer); return nullptr; } @@ -132,7 +132,7 @@ static JsonValue* parseNumber(JsonParser* parser) { char* end = nullptr; double number = strtod(start, &end); if (end == start) { - Log_logWarning("JsonReader: invalid number\n"); + logWarn("JsonReader: invalid number\n"); return nullptr; } parser->position += (size_t) (end - start); @@ -183,7 +183,7 @@ static JsonValue* parseArray(JsonParser* parser) { advance(parser); return value; } else { - Log_logWarning("JsonReader: expected ',' or ']' in array\n"); + logWarn("JsonReader: expected ',' or ']' in array\n"); JsonReader_free(value); return nullptr; } @@ -209,7 +209,7 @@ static JsonValue* parseObject(JsonParser* parser) { while (true) { skipWhitespace(parser); if (peek(parser) != '"') { - Log_logWarning("JsonReader: expected string key in object\n"); + logWarn("JsonReader: expected string key in object\n"); JsonReader_free(value); return nullptr; } @@ -225,7 +225,7 @@ static JsonValue* parseObject(JsonParser* parser) { skipWhitespace(parser); if (peek(parser) != ':') { - Log_logWarning("JsonReader: expected ':' after object key\n"); + logWarn("JsonReader: expected ':' after object key\n"); free(key); JsonReader_free(value); return nullptr; @@ -260,7 +260,7 @@ static JsonValue* parseObject(JsonParser* parser) { advance(parser); return value; } else { - Log_logWarning("JsonReader: expected ',' or '}' in object\n"); + logWarn("JsonReader: expected ',' or '}' in object\n"); JsonReader_free(value); return nullptr; } @@ -292,7 +292,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 't': { JsonValue* value = parseLiteral(parser, "true", 4); if (value == nullptr) { - Log_logWarning("JsonReader: invalid literal\n"); + logWarn("JsonReader: invalid literal\n"); return nullptr; } value->type = JSON_BOOL; @@ -302,7 +302,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 'f': { JsonValue* value = parseLiteral(parser, "false", 5); if (value == nullptr) { - Log_logWarning("JsonReader: invalid literal\n"); + logWarn("JsonReader: invalid literal\n"); return nullptr; } value->type = JSON_BOOL; @@ -312,7 +312,7 @@ static JsonValue* parseValue(JsonParser* parser) { case 'n': { JsonValue* value = parseLiteral(parser, "null", 4); if (value == nullptr) { - Log_logWarning("JsonReader: invalid literal\n"); + logWarn("JsonReader: invalid literal\n"); return nullptr; } return value; @@ -321,7 +321,7 @@ static JsonValue* parseValue(JsonParser* parser) { if (c == '-' || (c >= '0' && c <= '9')) { return parseNumber(parser); } - Log_logWarning("JsonReader: unexpected character '%c' at position %zu\n", c, parser->position); + logWarn("JsonReader: unexpected character '%c' at position %zu\n", c, parser->position); return nullptr; } } @@ -348,7 +348,7 @@ JsonValue* JsonReader_parse(const char* json) { if (result != nullptr) { skipWhitespace(&parser); if (parser.position < parser.length) { - Log_logWarning("JsonReader: trailing content after JSON value at position %zu\n", parser.position); + logWarn("JsonReader: trailing content after JSON value at position %zu\n", parser.position); JsonReader_free(result); return nullptr; } diff --git a/src/log.c b/src/log.c index 8219b8b63..bab65c1d2 100644 --- a/src/log.c +++ b/src/log.c @@ -139,7 +139,7 @@ bool Log_removeFile(FILE* file) { return false; } -void Log_logToTerminal(const char* fmt, ...) { +void logInfoToTerminal(const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -147,7 +147,7 @@ void Log_logToTerminal(const char* fmt, ...) { va_end(va); } -void Log_logToFile(const char* fmt, ...) { +void logInfoToFile(const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -155,7 +155,7 @@ void Log_logToFile(const char* fmt, ...) { va_end(va); } -void Log_log(const char* fmt, ...) { +void logInfo(const char* fmt, ...) { va_list va, va2; va_start(va, fmt); @@ -172,15 +172,15 @@ void Log_log(const char* fmt, ...) { va_end(va2); } -void Log_vLogToTerminal(const char* fmt, va_list va) { +void vLogInfoToTerminal(const char* fmt, va_list va) { vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); } -void Log_vLogToFile(const char* fmt, va_list va) { +void vLogInfoToFile(const char* fmt, va_list va) { vLogToFile(LOG_TYPE_NORMAL, fmt, va); } -void Log_vLog(const char* fmt, va_list va) { +void vLogInfo(const char* fmt, va_list va) { va_list va2; va_copy(va2, va); @@ -194,7 +194,7 @@ void Log_vLog(const char* fmt, va_list va) { va_end(va2); } -void Log_logWarningToTerminal(const char* fmt, ...) { +void logWarnToTerminal(const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -202,7 +202,7 @@ void Log_logWarningToTerminal(const char* fmt, ...) { va_end(va); } -void Log_logWarningToFile(const char* fmt, ...) { +void logWarnToFile(const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -210,7 +210,7 @@ void Log_logWarningToFile(const char* fmt, ...) { va_end(va); } -void Log_logWarning(const char* fmt, ...) { +void logWarn(const char* fmt, ...) { va_list va, va2; va_start(va, fmt); @@ -227,15 +227,15 @@ void Log_logWarning(const char* fmt, ...) { va_end(va2); } -void Log_vLogWarningToTerminal(const char* fmt, va_list va) { +void vLogWarnToTerminal(const char* fmt, va_list va) { vLogToTerminal(LOG_TYPE_WARNING, fmt, va); } -void Log_vLogWarningToFile(const char* fmt, va_list va) { +void vLogWarnToFile(const char* fmt, va_list va) { vLogToFile(LOG_TYPE_WARNING, fmt, va); } -void Log_vLogWarning(const char* fmt, va_list va) { +void vLogWarn(const char* fmt, va_list va) { va_list va2; va_copy(va2, va); @@ -249,7 +249,7 @@ void Log_vLogWarning(const char* fmt, va_list va) { va_end(va2); } -void Log_logErrorToTerminal(const char* fmt, ...) { +void logErrorToTerminal(const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -257,7 +257,7 @@ void Log_logErrorToTerminal(const char* fmt, ...) { va_end(va); } -void Log_logErrorToFile(const char* fmt, ...) { +void logErrorToFile(const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -265,7 +265,7 @@ void Log_logErrorToFile(const char* fmt, ...) { va_end(va); } -void Log_logError(const char* fmt, ...) { +void logError(const char* fmt, ...) { va_list va, va2; va_start(va, fmt); @@ -282,15 +282,15 @@ void Log_logError(const char* fmt, ...) { va_end(va2); } -void Log_vLogErrorToTerminal(const char* fmt, va_list va) { +void vLogErrorToTerminal(const char* fmt, va_list va) { vLogToTerminal(LOG_TYPE_ERROR, fmt, va); } -void Log_vLogErrorToFile(const char* fmt, va_list va) { +void vLogErrorToFile(const char* fmt, va_list va) { vLogToFile(LOG_TYPE_ERROR, fmt, va); } -void Log_vLogError(const char* fmt, va_list va) { +void vLogError(const char* fmt, va_list va) { va_list va2; va_copy(va2, va); @@ -304,7 +304,7 @@ void Log_vLogError(const char* fmt, va_list va) { va_end(va2); } -void Log_logDebugToTerminal(const char* fmt, ...) { +void logDebugToTerminal(const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -312,7 +312,7 @@ void Log_logDebugToTerminal(const char* fmt, ...) { va_end(va); } -void Log_logDebugToFile(const char* fmt, ...) { +void logDebugToFile(const char* fmt, ...) { va_list va; va_start(va, fmt); @@ -320,7 +320,7 @@ void Log_logDebugToFile(const char* fmt, ...) { va_end(va); } -void Log_logDebug(const char* fmt, ...) { +void logDebug(const char* fmt, ...) { va_list va, va2; va_start(va, fmt); @@ -337,15 +337,15 @@ void Log_logDebug(const char* fmt, ...) { va_end(va2); } -void Log_vLogDebugToTerminal(const char* fmt, va_list va) { +void vLogDebugToTerminal(const char* fmt, va_list va) { vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); } -void Log_vLogDebugToFile(const char* fmt, va_list va) { +void vLogDebugToFile(const char* fmt, va_list va) { vLogToFile(LOG_TYPE_DEBUG, fmt, va); } -void Log_vLogDebug(const char* fmt, va_list va) { +void vLogDebug(const char* fmt, va_list va) { va_list va2; va_copy(va2, va); diff --git a/src/log.h b/src/log.h index 8569716d9..b8dfaabcd 100644 --- a/src/log.h +++ b/src/log.h @@ -16,36 +16,36 @@ void Log_resetFile(); bool Log_addFile(FILE* file); bool Log_removeFile(FILE* file); -void Log_logToTerminal(const char* fmt, ...); -void Log_logToFile(const char* fmt, ...); -void Log_log(const char* fmt, ...); +void logInfoToTerminal(const char* fmt, ...); +void logInfoToFile(const char* fmt, ...); +void logInfo(const char* fmt, ...); -void Log_vLogToTerminal(const char* fmt, va_list va); -void Log_vLogToFile(const char* fmt, va_list va); -void Log_vLog(const char* fmt, va_list va); +void vLogInfoToTerminal(const char* fmt, va_list va); +void vLogInfoToFile(const char* fmt, va_list va); +void vLogInfo(const char* fmt, va_list va); -void Log_logWarningToTerminal(const char* fmt, ...); -void Log_logWarningToFile(const char* fmt, ...); -void Log_logWarning(const char* fmt, ...); +void logWarnToTerminal(const char* fmt, ...); +void logWarnToFile(const char* fmt, ...); +void logWarn(const char* fmt, ...); -void Log_vLogWarningToTerminal(const char* fmt, va_list va); -void Log_vLogWarningToFile(const char* fmt, va_list va); -void Log_vLogWarning(const char* fmt, va_list va); +void vLogWarnToTerminal(const char* fmt, va_list va); +void vLogWarnToFile(const char* fmt, va_list va); +void vLogWarn(const char* fmt, va_list va); -void Log_logErrorToTerminal(const char* fmt, ...); -void Log_logErrorToFile(const char* fmt, ...); -void Log_logError(const char* fmt, ...); +void logErrorToTerminal(const char* fmt, ...); +void logErrorToFile(const char* fmt, ...); +void logError(const char* fmt, ...); -void Log_vLogErrorToTerminal(const char* fmt, va_list va); -void Log_vLogErrorToFile(const char* fmt, va_list va); -void Log_vLogError(const char* fmt, va_list va); +void vLogErrorToTerminal(const char* fmt, va_list va); +void vLogErrorToFile(const char* fmt, va_list va); +void vLogError(const char* fmt, va_list va); -void Log_logDebugToTerminal(const char* fmt, ...); -void Log_logDebugToFile(const char* fmt, ...); -void Log_logDebug(const char* fmt, ...); +void logDebugToTerminal(const char* fmt, ...); +void logDebugToFile(const char* fmt, ...); +void logDebug(const char* fmt, ...); -void Log_vLogDebugToTerminal(const char* fmt, va_list va); -void Log_vLogDebugToFile(const char* fmt, va_list va); -void Log_vLogDebug(const char* fmt, va_list va); +void vLogDebugToTerminal(const char* fmt, va_list va); +void vLogDebugToFile(const char* fmt, va_list va); +void vLogDebug(const char* fmt, va_list va); #endif /* _BS_LOG_H */ diff --git a/src/ps2/debug_font_renderer.c b/src/ps2/debug_font_renderer.c index 0ba85df12..bf1f9d0a4 100644 --- a/src/ps2/debug_font_renderer.c +++ b/src/ps2/debug_font_renderer.c @@ -20,7 +20,7 @@ static uint32_t uploadTable(GSGLOBAL* gsGlobal, const void* srcData, size_t srcB uint32_t vramSize = gsKit_texture_size(width, height, psm); uint32_t vramAddr = gsKit_vram_alloc(gsGlobal, vramSize, GSKIT_ALLOC_USERBUFFER); if (vramAddr == GSKIT_ALLOC_ERROR) { - Log_logError("DebugFontRenderer: Failed to allocate VRAM for %s\n", what); + logError("DebugFontRenderer: Failed to allocate VRAM for %s\n", what); abort(); } @@ -58,7 +58,7 @@ DebugFontRenderer* DebugFontRenderer_create(GSGLOBAL* gsGlobal) { tex->Filter = GS_FILTER_LINEAR; tex->ClutStorageMode = GS_CLUT_STORAGE_CSM1; - Log_log("DebugFontRenderer: uploaded - CLUT 0x%08lX, atlas 0x%08lX\n", (unsigned long) clutVram, (unsigned long) atlasVram); + logInfo("DebugFontRenderer: uploaded - CLUT 0x%08lX, atlas 0x%08lX\n", (unsigned long) clutVram, (unsigned long) atlasVram); return r; } diff --git a/src/ps2/gs_renderer.c b/src/ps2/gs_renderer.c index bab8f7563..a40e2132e 100644 --- a/src/ps2/gs_renderer.c +++ b/src/ps2/gs_renderer.c @@ -22,7 +22,7 @@ static void rendererPrintf(const char* fmt, ...) { va_list args; va_start(args, fmt); - Log_vLog(fmt, args); + vLogInfo(fmt, args); va_end(args); } #else @@ -47,7 +47,7 @@ static uint8_t* loadFileRaw(const char* path, uint32_t* outSize) { FILE* f = fopen(textureBinPath, "rb"); if (f == nullptr) { - Log_logError("GsRenderer: Failed to open %s\n", path); + logError("GsRenderer: Failed to open %s\n", path); abort(); } @@ -62,7 +62,7 @@ static uint8_t* loadFileRaw(const char* path, uint32_t* outSize) { fclose(f); if (read != (size_t) size) { - Log_logError("GsRenderer: Short read on %s (expected %ld, got %zu)\n", path, size, read); + logError("GsRenderer: Short read on %s (expected %ld, got %zu)\n", path, size, read); abort(); } @@ -76,7 +76,7 @@ static void loadAtlas(GsRenderer* gs) { char* atlasBinPath = PS2Utils_createDevicePath("ATLAS.BIN"); FILE* f = fopen(atlasBinPath, "rb"); if (f == nullptr) { - Log_logError("GsRenderer: Failed to open %s\n", atlasBinPath); + logError("GsRenderer: Failed to open %s\n", atlasBinPath); abort(); } @@ -88,7 +88,7 @@ static void loadAtlas(GsRenderer* gs) { uint8_t version = BinaryReader_readUint8(&reader); if (version != 0) { - Log_logError("GsRenderer: Unsupported ATLAS.BIN version %u\n", version); + logError("GsRenderer: Unsupported ATLAS.BIN version %u\n", version); abort(); } @@ -111,7 +111,7 @@ static void loadAtlas(GsRenderer* gs) { gs->atlasDataSizes[i] = BinaryReader_readUint32(&reader); gs->atlasCompressionType[i] = BinaryReader_readUint8(&reader); if (gs->atlasBpp[i] != 4 && gs->atlasBpp[i] != 8) { - Log_logError("GsRenderer: Atlas %u has unsupported bpp %u\n", i, gs->atlasBpp[i]); + logError("GsRenderer: Atlas %u has unsupported bpp %u\n", i, gs->atlasBpp[i]); abort(); } } @@ -175,7 +175,7 @@ static void loadAtlas(GsRenderer* gs) { gs->atlasToChunk[i] = -1; } - Log_log("GsRenderer: ATLAS.BIN loaded - %u TPAG entries, %u tile entries, %u atlases\n", gs->atlasTPAGCount, gs->atlasTileCount, gs->atlasCount); + logInfo("GsRenderer: ATLAS.BIN loaded - %u TPAG entries, %u tile entries, %u atlases\n", gs->atlasTPAGCount, gs->atlasTileCount, gs->atlasCount); free(atlasBinPath); } @@ -197,7 +197,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { uint32_t clut4FileSize; uint8_t* clut4Data = loadFileRaw("CLUT4.BIN", &clut4FileSize); gs->clut4Count = clut4FileSize / CLUT4_ENTRY_SIZE; - Log_log("GsRenderer: CLUT4.BIN loaded - %u CLUTs (%u bytes)\n", gs->clut4Count, clut4FileSize); + logInfo("GsRenderer: CLUT4.BIN loaded - %u CLUTs (%u bytes)\n", gs->clut4Count, clut4FileSize); gs->clut4VramAddrs = (uint32_t *)safeMalloc(gs->clut4Count * sizeof(uint32_t)); @@ -206,7 +206,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { uint32_t vramSize = gsKit_texture_size(8, 2, GS_PSM_CT32); uint32_t vramAddr = gsKit_vram_alloc(gsGlobal, vramSize, GSKIT_ALLOC_USERBUFFER); if (vramAddr == GSKIT_ALLOC_ERROR) { - Log_logError("GsRenderer: Failed to allocate VRAM for CLUT4 index %u\n", i); + logError("GsRenderer: Failed to allocate VRAM for CLUT4 index %u\n", i); abort(); } @@ -216,7 +216,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { gs->clut4VramAddrs[i] = vramAddr; } - Log_log("GsRenderer: CLUT4 uploaded (%u CLUTs)\n", gs->clut4Count); + logInfo("GsRenderer: CLUT4 uploaded (%u CLUTs)\n", gs->clut4Count); free(clut4Data); } @@ -225,7 +225,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { uint32_t clut8FileSize; uint8_t* clut8Data = loadFileRaw("CLUT8.BIN", &clut8FileSize); gs->clut8Count = clut8FileSize / CLUT8_ENTRY_SIZE; - Log_log("GsRenderer: CLUT8.BIN loaded - %u CLUTs (%u bytes)\n", gs->clut8Count, clut8FileSize); + logInfo("GsRenderer: CLUT8.BIN loaded - %u CLUTs (%u bytes)\n", gs->clut8Count, clut8FileSize); gs->clut8VramAddrs = (uint32_t *)safeMalloc(gs->clut8Count * sizeof(uint32_t)); @@ -234,7 +234,7 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { uint32_t vramSize = gsKit_texture_size(16, 16, GS_PSM_CT32); uint32_t vramAddr = gsKit_vram_alloc(gsGlobal, vramSize, GSKIT_ALLOC_USERBUFFER); if (vramAddr == GSKIT_ALLOC_ERROR) { - Log_logError("GsRenderer: Failed to allocate VRAM for CLUT8 index %u\n", i); + logError("GsRenderer: Failed to allocate VRAM for CLUT8 index %u\n", i); abort(); } @@ -243,13 +243,13 @@ static void loadAndUploadCLUTs(GsRenderer* gs) { gs->clut8VramAddrs[i] = vramAddr; } - Log_log("GsRenderer: CLUT8 uploaded (%u CLUTs)\n", gs->clut8Count); + logInfo("GsRenderer: CLUT8 uploaded (%u CLUTs)\n", gs->clut8Count); free(clut8Data); } free(tempBuf); - Log_log("GsRenderer: VRAM after CLUTs: 0x%08X / 0x%08X\n", gsGlobal->CurrentPointer, GS_VRAM_SIZE); + logInfo("GsRenderer: VRAM after CLUTs: 0x%08X / 0x%08X\n", gsGlobal->CurrentPointer, GS_VRAM_SIZE); } // ===[ VRAM Texture Cache (Buddy System with LRU Eviction) ]=== @@ -283,7 +283,7 @@ static void initTextureCache(GsRenderer* gs) { // Advance CurrentPointer past our chunk pool so any future gsKit allocations fail loudly. gs->gsGlobal->CurrentPointer = gs->textureVramBase + gs->chunkCount * VRAM_CHUNK_SIZE; - Log_log("GsRenderer: Texture cache initialized - %u chunks (%u KB each), base 0x%08X, %u KB for textures\n", gs->chunkCount, VRAM_CHUNK_SIZE / 1024, gs->textureVramBase, gs->chunkCount * (VRAM_CHUNK_SIZE / 1024)); + logInfo("GsRenderer: Texture cache initialized - %u chunks (%u KB each), base 0x%08X, %u KB for textures\n", gs->chunkCount, VRAM_CHUNK_SIZE / 1024, gs->textureVramBase, gs->chunkCount * (VRAM_CHUNK_SIZE / 1024)); } // A chunk is free if no atlas, snapshot, or surface occupies it. Snapshots and surfaces both pin the chunk against LRU eviction. @@ -470,7 +470,7 @@ static void computeAtlasReservation(GsRenderer* gs) { } if (worst > gs->chunkCount) worst = gs->chunkCount; gs->reservedAtlasChunks = worst; - Log_log("GsRenderer: Reserving first %u chunk(s) (%u KB) as atlas-only fail-safe (largest atlas @ 8bpp)\n", worst, worst * (VRAM_CHUNK_SIZE / 1024)); + logInfo("GsRenderer: Reserving first %u chunk(s) (%u KB) as atlas-only fail-safe (largest atlas @ 8bpp)\n", worst, worst * (VRAM_CHUNK_SIZE / 1024)); } // Initialize the EE RAM cache. Called from gsInit after opening TEXTURES.BIN. @@ -607,7 +607,7 @@ static void uploadAtlasToChunk(GsRenderer* gs, uint16_t atlasId, int32_t firstCh fseek(gs->texturesFile, (long) gs->atlasOffsets[atlasId], SEEK_SET); size_t bytesRead = fread(compressedBuf, 1, dataSize, gs->texturesFile); if (bytesRead != dataSize) { - Log_logError("GsRenderer: Short read for atlas %u (expected %u, got %zu)\n", atlasId, dataSize, bytesRead); + logError("GsRenderer: Short read for atlas %u (expected %u, got %zu)\n", atlasId, dataSize, bytesRead); abort(); } @@ -668,7 +668,7 @@ static void uploadAtlasToChunk(GsRenderer* gs, uint16_t atlasId, int32_t firstCh // Returns true on success, false on failure. static bool ensureAtlasLoaded(GsRenderer* gs, uint16_t atlasId) { if (atlasId >= gs->atlasCount) { - Log_logWarning("GsRenderer: Atlas ID %u out of range (max %u)\n", atlasId, gs->atlasCount - 1); + logWarn("GsRenderer: Atlas ID %u out of range (max %u)\n", atlasId, gs->atlasCount - 1); return false; } @@ -693,7 +693,7 @@ static bool ensureAtlasLoaded(GsRenderer* gs, uint16_t atlasId) { // Determine how many chunks we need uint8_t bpp = gs->atlasBpp[atlasId]; if (bpp != 4 && bpp != 8) { - Log_logWarning("GsRenderer: Atlas %u has unknown bpp %u\n", atlasId, bpp); + logWarn("GsRenderer: Atlas %u has unknown bpp %u\n", atlasId, bpp); return false; } int chunksNeeded = atlasChunkCount(gs->atlasWidth[atlasId], gs->atlasHeight[atlasId], bpp); @@ -705,7 +705,7 @@ static bool ensureAtlasLoaded(GsRenderer* gs, uint16_t atlasId) { // Allocate chunks (may evict or defrag) int32_t chunkIdx = allocateChunks(gs, chunksNeeded, 0); if (0 > chunkIdx) { - Log_logError("GsRenderer: VRAM exhausted! Cannot allocate %d chunk(s) for atlas %u (%ubpp)\n", chunksNeeded, atlasId, bpp); + logError("GsRenderer: VRAM exhausted! Cannot allocate %d chunk(s) for atlas %u (%ubpp)\n", chunksNeeded, atlasId, bpp); abort(); } @@ -903,7 +903,7 @@ static bool setupTextureForTPAG(GsRenderer* gs, GSTEXTURE* tex, int32_t tpagInde tex->ClutPSM = GS_PSM_CT32; if (entry->clutIndex >= gs->clut4Count) { - Log_logError("GsRenderer: CLUT4 index %u out of range (max %u) for TPAG %d\n", entry->clutIndex, gs->clut4Count - 1, tpagIndex); + logError("GsRenderer: CLUT4 index %u out of range (max %u) for TPAG %d\n", entry->clutIndex, gs->clut4Count - 1, tpagIndex); abort(); } @@ -913,7 +913,7 @@ static bool setupTextureForTPAG(GsRenderer* gs, GSTEXTURE* tex, int32_t tpagInde tex->ClutPSM = GS_PSM_CT32; if (entry->clutIndex >= gs->clut8Count) { - Log_logError("GsRenderer: CLUT8 index %u out of range (max %u) for TPAG %d\n", entry->clutIndex, gs->clut8Count - 1, tpagIndex); + logError("GsRenderer: CLUT8 index %u out of range (max %u) for TPAG %d\n", entry->clutIndex, gs->clut8Count - 1, tpagIndex); abort(); } @@ -965,7 +965,7 @@ static bool setupTextureForTile(GsRenderer* gs, GSTEXTURE* tex, AtlasTileEntry* tex->ClutPSM = GS_PSM_CT32; if (entry->clutIndex >= gs->clut4Count) { - Log_logError("GsRenderer: CLUT4 index %u out of range (max %u) for tile (bg=%d)\n", entry->clutIndex, gs->clut4Count - 1, entry->bgDef); + logError("GsRenderer: CLUT4 index %u out of range (max %u) for tile (bg=%d)\n", entry->clutIndex, gs->clut4Count - 1, entry->bgDef); abort(); } @@ -975,7 +975,7 @@ static bool setupTextureForTile(GsRenderer* gs, GSTEXTURE* tex, AtlasTileEntry* tex->ClutPSM = GS_PSM_CT32; if (entry->clutIndex >= gs->clut8Count) { - Log_logError("GsRenderer: CLUT8 index %u out of range (max %u) for tile (bg=%d)\n", entry->clutIndex, gs->clut8Count - 1, entry->bgDef); + logError("GsRenderer: CLUT8 index %u out of range (max %u) for tile (bg=%d)\n", entry->clutIndex, gs->clut8Count - 1, entry->bgDef); abort(); } @@ -1060,7 +1060,7 @@ static void gsInit(Renderer* renderer, DataWin* dataWin) { char* texturesBinPath = PS2Utils_createDevicePath("TEXTURES.BIN"); gs->texturesFile = fopen(texturesBinPath, "rb"); if (gs->texturesFile == nullptr) { - Log_logError("GsRenderer: Failed to open %s\n", texturesBinPath); + logError("GsRenderer: Failed to open %s\n", texturesBinPath); abort(); } setvbuf(gs->texturesFile, nullptr, _IOFBF, 128 * 1024); @@ -1081,7 +1081,7 @@ static void gsInit(Renderer* renderer, DataWin* dataWin) { // Initialize EE RAM cache for compressed atlas data initEeCache(gs); - Log_log("GsRenderer: Initialized (textured mode)\n"); + logInfo("GsRenderer: Initialized (textured mode)\n"); } static void gsDestroy(Renderer* renderer) { @@ -2295,7 +2295,7 @@ static void gsDeleteSprite(Renderer* renderer, int32_t spriteIndex) { if (0 > spriteIndex || (uint32_t) spriteIndex >= dw->sprt.count) return; // Refuse to delete original data.win sprites - their tpagIndices point into the static atlas, not snapshot pool. if (gs->originalSpriteCount > (uint32_t) spriteIndex) { - Log_logWarning("GsRenderer: Cannot delete data.win sprite %d\n", spriteIndex); + logWarn("GsRenderer: Cannot delete data.win sprite %d\n", spriteIndex); return; } @@ -2405,7 +2405,7 @@ static void gsGpuSetBlendModeExt(Renderer* renderer, int32_t sfactor, int32_t df gs->currentDFactorAlpha = dfactor_alpha; u64 alpha; if (!gmsFactorPairToGSAlpha(sfactor, dfactor, &alpha) && !gs->blendModeWarned) { - Log_logWarning("GsRenderer: blend mode (sf=%d, df=%d) not exactly representable on PS2; approximating\n", sfactor, dfactor); + logWarn("GsRenderer: blend mode (sf=%d, df=%d) not exactly representable on PS2; approximating\n", sfactor, dfactor); gs->blendModeWarned = true; } gs->currentBlendAlpha = alpha; @@ -2668,7 +2668,7 @@ static int32_t gsCreateSurface(Renderer* renderer, int32_t width, int32_t height } if (phantomReason != nullptr) { - Log_logWarning("GsRenderer: surface_create(%d, %d) phantom (%s); needed %d chunks (%u bytes)\n", width, height, phantomReason, chunksNeeded, bytes); + logWarn("GsRenderer: surface_create(%d, %d) phantom (%s); needed %d chunks (%u bytes)\n", width, height, phantomReason, chunksNeeded, bytes); Surface* s = &gs->surfaces[row]; s->firstChunk = 0; s->chunkCount = 0; diff --git a/src/ps2/main.c b/src/ps2/main.c index effb8b4fd..994d627a2 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -98,7 +98,7 @@ static void parsePadMappings(JsonValue* configRoot, const char* key, PadMapping* JsonValue* gmlKeyVal = JsonReader_getJsonValueByIndex(mappingsObj, i); mappings[i].padButton = (uint16_t) atoi(padButtonStr); mappings[i].gmlKey = (int32_t) JsonReader_getInt(gmlKeyVal); - Log_log("CONFIG.JSN: %s mapping pad=%d -> gmlKey=%d\n", logLabel, mappings[i].padButton, mappings[i].gmlKey); + logInfo("CONFIG.JSN: %s mapping pad=%d -> gmlKey=%d\n", logLabel, mappings[i].padButton, mappings[i].gmlKey); } *outMappings = mappings; *outCount = count; @@ -255,15 +255,15 @@ int main(int argc, char* argv[]) { PS2Utils_extractDeviceKey(argv[0]); - Log_log("argv0 is %s, device key is %s\n", argv[0], deviceKey.key); + logInfo("argv0 is %s, device key is %s\n", argv[0], deviceKey.key); PS2Utils_loadFSDrivers(); - Log_log("Loaded FS drivers!\n"); + logInfo("Loaded FS drivers!\n"); char* dataWinPath = PS2Utils_createDevicePath("DATA.WIN"); - Log_log("Butterscotch PS2 - Loading %s\n", dataWinPath); + logInfo("Butterscotch PS2 - Loading %s\n", dataWinPath); // ===[ Initialize gsKit ]=== // This must happen first so we can show the loading screen during other init steps @@ -296,51 +296,51 @@ int main(int argc, char* argv[]) { int ret; ret = SifExecModuleBuffer(freesio2_irx, size_freesio2_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load freesio2: %d\n", ret); + logError("Failed to load freesio2: %d\n", ret); return 1; } ret = SifExecModuleBuffer(mcman_irx, size_mcman_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load mcman: %d\n", ret); + logError("Failed to load mcman: %d\n", ret); return 1; } ret = SifExecModuleBuffer(mcserv_irx, size_mcserv_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load mcserv: %d\n", ret); + logError("Failed to load mcserv: %d\n", ret); return 1; } ret = mcInit(MC_TYPE_MC); if (0 > ret) { - Log_logError("Failed to init libmc: %d\n", ret); + logError("Failed to init libmc: %d\n", ret); return 1; } ret = SifExecModuleBuffer(freepad_irx, size_freepad_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logError("Failed to load freepad: %d\n", ret); + logError("Failed to load freepad: %d\n", ret); return 1; } padInit(0); padOpened[0] = (padPortOpen(0, 0, padBuf[0]) != 0); padOpened[1] = (padPortOpen(1, 0, padBuf[1]) != 0); - if (!padOpened[0]) Log_logWarning("Warning: failed to open pad port 0\n"); - if (!padOpened[1]) Log_logWarning("Warning: failed to open pad port 1\n"); + if (!padOpened[0]) logWarn("Warning: failed to open pad port 0\n"); + if (!padOpened[1]) logWarn("Warning: failed to open pad port 1\n"); // ===[ Load USB Keyboard IOP Modules ]=== int usbdRet = SifExecModuleBuffer(usbd_irx, size_usbd_irx, 0, nullptr, nullptr); if (0 > usbdRet) { - Log_logWarning("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); + logWarn("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); } else { int kbdRet = SifExecModuleBuffer(ps2kbd_irx, size_ps2kbd_irx, 0, nullptr, nullptr); if (0 > kbdRet) { - Log_logWarning("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); + logWarn("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); } else if (PS2KbdInit() == 0) { - Log_logWarning("Warning: PS2KbdInit failed (keyboard disabled)\n"); + logWarn("Warning: PS2KbdInit failed (keyboard disabled)\n"); } else { PS2KbdSetReadmode(PS2KBD_READMODE_RAW); PS2KbdSetBlockingMode(PS2KBD_NONBLOCKING); kbdAvailable = true; - Log_log("USB keyboard initialized\n"); + logInfo("USB keyboard initialized\n"); } } @@ -348,11 +348,11 @@ int main(int argc, char* argv[]) { // ===[ Load Audio IOP Modules ]=== ret = SifExecModuleBuffer(freesd_irx, size_freesd_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logWarning("Failed to load freesd: %d\n", ret); + logWarn("Failed to load freesd: %d\n", ret); } ret = SifExecModuleBuffer(audsrv_irx, size_audsrv_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logWarning("Failed to load audsrv: %d\n", ret); + logWarn("Failed to load audsrv: %d\n", ret); } #endif @@ -363,7 +363,7 @@ int main(int argc, char* argv[]) { padState = padGetState(0, 0); } while (PAD_STATE_STABLE != padState && PAD_STATE_FINDCTP1 != padState); - Log_log("Controller initialized\n"); + logInfo("Controller initialized\n"); // ===[ Load CONFIG.JSN ]=== PS2Overlay_drawStatusScreen(nullptr, "Loading CONFIG.JSN...", false); @@ -460,7 +460,7 @@ int main(int argc, char* argv[]) { void* heapTop = sbrk(0); int32_t usedBytes = (int32_t) (uintptr_t) heapTop; int32_t freeBytes = MAX_MEMORY_BYTES - usedBytes; - Log_log("Memory after data.win parsing: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); + logInfo("Memory after data.win parsing: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); } FileSystem* fileSystem = Ps2FileSystem_create(configRoot, dataWin->gen8.displayName); @@ -501,7 +501,7 @@ int main(int argc, char* argv[]) { if (elem != nullptr && JsonReader_isString(elem)) { const char* objName = JsonReader_getString(elem); shput(runner->disabledObjects, objName, 1); - Log_log("Disabled object: %s\n", objName); + logInfo("Disabled object: %s\n", objName); } } } @@ -515,14 +515,14 @@ int main(int argc, char* argv[]) { gamepadApiEnabled = JsonReader_getBool(JsonReader_getJsonValueByKey(gamepadObj, "enabled")); } if (gamepadApiEnabled) { - Log_log("CONFIG.JSN: GameMaker gamepad API enabled\n"); + logInfo("CONFIG.JSN: GameMaker gamepad API enabled\n"); } { void* heapTop = sbrk(0); int32_t usedBytes = (int32_t) (uintptr_t) heapTop; int32_t freeBytes = MAX_MEMORY_BYTES - usedBytes; - Log_log("Memory after VM and runner creation: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); + logInfo("Memory after VM and runner creation: used=%d bytes (%.1f KB), total=%d bytes (%.1f KB), free=%d bytes (%.1f KB)\n", usedBytes, (double) (usedBytes / 1024.0f), MAX_MEMORY_BYTES, (double) (MAX_MEMORY_BYTES / 1024.0f), freeBytes, (double) (freeBytes / 1024.0f)); } PS2Overlay_drawStatusScreen(dataWin->gen8.displayName, "Initializing first room...", true); @@ -540,7 +540,7 @@ int main(int argc, char* argv[]) { PS2Utils_loadMassStorageDrivers(); gprof_start(); - Log_log("gprof: Profiling started!\n"); + logInfo("gprof: Profiling started!\n"); #endif Gen8* gen8 = &dataWin->gen8; @@ -609,7 +609,7 @@ int main(int argc, char* argv[]) { int32_t nextIdx = dw->gen8.roomOrder[runner->currentRoomOrderPosition + 1]; runner->pendingRoom = nextIdx; runner->audioSystem->vtable->stopAll(runner->audioSystem); - Log_logDebug("Going to next room -> %s\n", dw->room.rooms[nextIdx].name); + logDebug("Going to next room -> %s\n", dw->room.rooms[nextIdx].name); } } @@ -634,7 +634,7 @@ int main(int argc, char* argv[]) { int32_t interactVarId = shget(runner->vmContext->varNameMap, "interact"); Instance_setSelfVar(runner->vmContext->globalScopeInstance, interactVarId, RValue_makeInt32(0)); - Log_log("Changed global.interact [%d] value!\n", interactVarId); + logInfo("Changed global.interact [%d] value!\n", interactVarId); } // ===[ Game Logic ]=== @@ -710,9 +710,9 @@ int main(int argc, char* argv[]) { } else { gprofPath = "mass:gmon.out"; } - Log_log("gprof: Writing profiling data to %s\n", gprofPath); + logInfo("gprof: Writing profiling data to %s\n", gprofPath); gprof_stop(gprofPath, 1); - Log_log("gprof: Done\n"); + logInfo("gprof: Done\n"); } #endif diff --git a/src/ps2/ps2_file_system.c b/src/ps2/ps2_file_system.c index 6b39da8d1..7a73a4179 100644 --- a/src/ps2/ps2_file_system.c +++ b/src/ps2/ps2_file_system.c @@ -184,9 +184,9 @@ static void copyIconIcoIfMissing(const char* dirPath) { // Copy from boot device char* srcPath = PS2Utils_createDevicePath("ICON.ICO"); if (copyFile(srcPath, dstPath)) { - Log_log("Ps2FileSystem: Copied ICON.ICO to %s\n", dirPath); + logInfo("Ps2FileSystem: Copied ICON.ICO to %s\n", dirPath); } else { - Log_logWarning("Ps2FileSystem: Failed to copy ICON.ICO from %s to %s\n", srcPath, dstPath); + logWarn("Ps2FileSystem: Failed to copy ICON.ICO from %s to %s\n", srcPath, dstPath); } free(srcPath); @@ -217,9 +217,9 @@ static void writeIconSysIfMissing(const char* dirPath, const char* gameTitle, co if (f != nullptr) { fwrite(buffer, 1, ICON_SYS_SIZE, f); fclose(f); - Log_log("Ps2FileSystem: Created icon.sys in %s\n", dirPath); + logInfo("Ps2FileSystem: Created icon.sys in %s\n", dirPath); } else { - Log_logWarning("Ps2FileSystem: Failed to create icon.sys in %s\n", dirPath); + logWarn("Ps2FileSystem: Failed to create icon.sys in %s\n", dirPath); } free(iconSysPath); @@ -612,13 +612,13 @@ FileSystem* Ps2FileSystem_create(JsonValue* configRoot, const char* gameTitle) { const char* rawPath = JsonReader_getString(pathElement); char* resolved = expandBootPrefix(rawPath); arrput(resolvedPaths, resolved); - Log_log("Ps2FileSystem: '%s' -> '%s'\n", gameFileName, resolved); + logInfo("Ps2FileSystem: '%s' -> '%s'\n", gameFileName, resolved); } shput(pfs->mappings, gameFileName, resolvedPaths); } - Log_log("Ps2FileSystem: Loaded %d file mappings\n", (int) shlen(pfs->mappings)); + logInfo("Ps2FileSystem: Loaded %d file mappings\n", (int) shlen(pfs->mappings)); return (FileSystem*) pfs; } diff --git a/src/ps2/ps2_gamepad.c b/src/ps2/ps2_gamepad.c index 67d21386b..36f332bc8 100644 --- a/src/ps2/ps2_gamepad.c +++ b/src/ps2/ps2_gamepad.c @@ -35,21 +35,21 @@ static void setupAnalogMode(int port) { } } if (!supportsDualshock) { - Log_logWarning("Ps2Gamepad: port %d does not support DualShock mode\n", port); + logWarn("Ps2Gamepad: port %d does not support DualShock mode\n", port); analogModeReady[port] = true; return; } if (padSetMainMode(port, 0, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK) == 0) { - Log_logWarning("Ps2Gamepad: padSetMainMode failed on port %d\n", port); + logWarn("Ps2Gamepad: padSetMainMode failed on port %d\n", port); return; } if (!waitForRequest(port)) { - Log_logWarning("Ps2Gamepad: DualShock mode request did not complete on port %d\n", port); + logWarn("Ps2Gamepad: DualShock mode request did not complete on port %d\n", port); return; } analogModeReady[port] = true; - Log_log("Ps2Gamepad: port %d set to DualShock analog mode\n", port); + logInfo("Ps2Gamepad: port %d set to DualShock analog mode\n", port); } void Ps2Gamepad_poll(RunnerGamepadState* gp, int port) { diff --git a/src/ps2/ps2_utils.c b/src/ps2/ps2_utils.c index 0a6f883ca..71f2a5c0e 100644 --- a/src/ps2/ps2_utils.c +++ b/src/ps2/ps2_utils.c @@ -33,23 +33,23 @@ void PS2Utils_loadFSDrivers() { require(deviceKeyLoaded); if (deviceKey.usesISO9660) { - Log_log("PS2Utils: Loading CDVD drivers for device key '%s'\n", deviceKey.key); + logInfo("PS2Utils: Loading CDVD drivers for device key '%s'\n", deviceKey.key); int ret; ret = SifLoadModule("rom0:CDVDMAN", 0, nullptr); if (0 > ret) { - Log_logError("PS2Utils: Failed to load CDVDMAN: %d\n", ret); + logError("PS2Utils: Failed to load CDVDMAN: %d\n", ret); abort(); } ret = SifLoadModule("rom0:CDVDFSV", 0, nullptr); if (0 > ret) { - Log_logError("PS2Utils: Failed to load CDVDFSV: %d\n", ret); + logError("PS2Utils: Failed to load CDVDFSV: %d\n", ret); abort(); } sceCdInit(SCECdINIT); - Log_log("PS2Utils: CDVD initialized\n"); + logInfo("PS2Utils: CDVD initialized\n"); } } @@ -67,33 +67,33 @@ extern unsigned int size_usbmass_bd_irx; void PS2Utils_loadMassStorageDrivers() { require(deviceKeyLoaded); - Log_log("PS2Utils: Loading USB mass storage drivers for gprof output...\n"); + logInfo("PS2Utils: Loading USB mass storage drivers for gprof output...\n"); int ret; ret = SifExecModuleBuffer(usbd_irx, size_usbd_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logWarning("PS2Utils: Failed to load usbd: %d\n", ret); + logWarn("PS2Utils: Failed to load usbd: %d\n", ret); } ret = SifExecModuleBuffer(bdm_irx, size_bdm_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logWarning("PS2Utils: Failed to load bdm: %d\n", ret); + logWarn("PS2Utils: Failed to load bdm: %d\n", ret); } ret = SifExecModuleBuffer(bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logWarning("PS2Utils: Failed to load bdmfs_fatfs: %d\n", ret); + logWarn("PS2Utils: Failed to load bdmfs_fatfs: %d\n", ret); } ret = SifExecModuleBuffer(usbmass_bd_irx, size_usbmass_bd_irx, 0, nullptr, nullptr); if (0 > ret) { - Log_logWarning("PS2Utils: Failed to load usbmass_bd: %d\n", ret); + logWarn("PS2Utils: Failed to load usbmass_bd: %d\n", ret); } // Wait for USB device detection sleep(3); - Log_log("PS2Utils: USB mass storage drivers loaded\n"); + logInfo("PS2Utils: USB mass storage drivers loaded\n"); } #endif diff --git a/src/ps3/main.c b/src/ps3/main.c index 66d6356a2..283139d63 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -158,7 +158,7 @@ char *str_replace(char *orig, char *rep, char *with) { static char buffer[9999]; int main(int argc, char* argv[]) { Log_init(); - Log_log("%s\n", argv[0]); + logInfo("%s\n", argv[0]); if (argc > 0) strcpy(buffer, argv[0]); char* tmp = str_replace(buffer, "butterscotch.elf", ""); @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) { sysUtilRegisterCallback(SYSUTIL_EVENT_SLOT0, sys_callback, NULL); freq = sysGetTimebaseFrequency(); - Log_log("Loading %s...\n", dataWinPath); + logInfo("Loading %s...\n", dataWinPath); DataWinParserOptions options = {0}; options.parseGen8 = true; @@ -211,7 +211,7 @@ int main(int argc, char* argv[]) { DataWin* dataWin = DataWin_parse(dataWinPath, options); Gen8* gen8 = &dataWin->gen8; - Log_log("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); + logInfo("Loaded \"%s\" (%d) successfully! [WAD Version %u / GameMaker version %u.%u.%u.%u]\n", gen8->name, gen8->gameID, gen8->wadVersion, dataWin->detectedFormat.major, dataWin->detectedFormat.minor, dataWin->detectedFormat.release, dataWin->detectedFormat.build); // Initialize VM VMContext* vm = VM_create(dataWin); @@ -255,7 +255,7 @@ int main(int argc, char* argv[]) { memcpy(texturesBinPath, dataWinDir, dirLen); strcpy(texturesBinPath + dirLen, "textures.bin"); if (!PS3Textures_init(texturesBinPath)) { - Log_logError("Fatal: failed to load %s\n", texturesBinPath); + logError("Fatal: failed to load %s\n", texturesBinPath); return 1; } free(texturesBinPath); @@ -286,7 +286,7 @@ int main(int argc, char* argv[]) { glUseProgram(gPalettedProgram); glUniform1i(uPaletteLoc, 1); glUseProgram(0); - Log_log("Paletted shader: program=%u uPaletteV=%d uPalette=%d\n", gPalettedProgram, gPalettedUPaletteVLoc, uPaletteLoc); + logInfo("Paletted shader: program=%u uPaletteV=%d uPalette=%d\n", gPalettedProgram, gPalettedUPaletteVLoc, uPaletteLoc); } // Initialize the runner @@ -311,7 +311,7 @@ int main(int argc, char* argv[]) { bool shouldStep = true; if (runner->debugMode && debugPaused) { shouldStep = RunnerKeyboard_checkPressed(runner->keyboard, 'O'); - if (shouldStep) Log_logDebug("Frame advance (frame %d)\n", runner->frameCount); + if (shouldStep) logDebug("Frame advance (frame %d)\n", runner->frameCount); } @@ -451,6 +451,6 @@ int main(int argc, char* argv[]) { sysUtilUnregisterCallback(SYSUTIL_EVENT_SLOT0); gcmSetWaitFlip(context); rsxFinish(context,1); - Log_log("Bye! :3\n"); + logInfo("Bye! :3\n"); return 0; } diff --git a/src/ps3/ps3_overlay.c b/src/ps3/ps3_overlay.c index 6fd125968..9c154b110 100644 --- a/src/ps3/ps3_overlay.c +++ b/src/ps3/ps3_overlay.c @@ -31,7 +31,7 @@ void PS3Overlay_init(void) { // Convert the 8bpp atlas into RGBA uint8_t* rgba = (uint8_t*) malloc((size_t) (DEBUGFONT_ATLAS_W * DEBUGFONT_ATLAS_H * 4)); if (rgba == nullptr) { - Log_logWarning("PS3Overlay: failed to allocate %d bytes for the font atlas\n", DEBUGFONT_ATLAS_W * DEBUGFONT_ATLAS_H * 4); + logWarn("PS3Overlay: failed to allocate %d bytes for the font atlas\n", DEBUGFONT_ATLAS_W * DEBUGFONT_ATLAS_H * 4); return; } diff --git a/src/ps3/ps3_textures.c b/src/ps3/ps3_textures.c index 83f38473b..a946caa74 100644 --- a/src/ps3/ps3_textures.c +++ b/src/ps3/ps3_textures.c @@ -46,7 +46,7 @@ bool PS3Textures_init(const char* texturesBinPath) { gFp = fopen(texturesBinPath, "rb"); if (gFp == NULL) { - Log_logWarning("PS3Textures: cannot open %s\n", texturesBinPath); + logWarn("PS3Textures: cannot open %s\n", texturesBinPath); return false; } @@ -54,7 +54,7 @@ bool PS3Textures_init(const char* texturesBinPath) { uint8_t headerBuf[7]; if (fread(headerBuf, 1, 7, gFp) != 7) goto fail; if (headerBuf[0] != 0) { - Log_logWarning("PS3Textures: unsupported version %u\n", headerBuf[0]); + logWarn("PS3Textures: unsupported version %u\n", headerBuf[0]); goto fail; } gClutCount = readU16BE(headerBuf + 1); @@ -65,7 +65,7 @@ bool PS3Textures_init(const char* texturesBinPath) { size_t clutBytes = (size_t) gClutCount * 256 * 4; uint8_t* clutBuf = (uint8_t*) malloc(clutBytes); if (clutBuf == NULL) { - Log_logWarning("PS3Textures: malloc(%zu) for CLUT failed\n", clutBytes); + logWarn("PS3Textures: malloc(%zu) for CLUT failed\n", clutBytes); goto fail; } if (fread(clutBuf, 1, clutBytes, gFp) != clutBytes) { @@ -114,7 +114,7 @@ bool PS3Textures_init(const char* texturesBinPath) { // Pixel block starts here. Pages are streamed from disk on demand. gPixelBlockBase = ftell(gFp); - Log_log("PS3Textures: opened %s (clutCount=%u pages=%u tpags=%u, streaming pixels)\n", texturesBinPath, gClutCount, gPageCount, gTpagCount); + logInfo("PS3Textures: opened %s (clutCount=%u pages=%u tpags=%u, streaming pixels)\n", texturesBinPath, gClutCount, gPageCount, gTpagCount); gInitialized = true; return true; @@ -154,7 +154,7 @@ bool PS3Textures_loadPage(uint32_t pageId, int* outW, int* outH, uint8_t** outPi uint8_t* buf = (uint8_t*) malloc(h->pixelDataSize); if (buf == NULL) { - Log_logWarning("PS3Textures: malloc(%u) for page %u failed\n", h->pixelDataSize, pageId); + logWarn("PS3Textures: malloc(%u) for page %u failed\n", h->pixelDataSize, pageId); return false; } diff --git a/src/runner.c b/src/runner.c index bcda96e66..ca88116c0 100644 --- a/src/runner.c +++ b/src/runner.c @@ -394,9 +394,9 @@ static void Runner_executeResolvedEvent(Runner* runner, Instance* instance, int3 if (shouldTrace) { if (eventType == EVENT_ALARM) { - Log_log("Runner: [%s] %s %d (instanceId=%d)\n", objectName, eventName, eventSubtype, instance->instanceId); + logInfo("Runner: [%s] %s %d (instanceId=%d)\n", objectName, eventName, eventSubtype, instance->instanceId); } else { - Log_log("Runner: [%s] %s (instanceId=%d)\n", objectName, eventName, instance->instanceId); + logInfo("Runner: [%s] %s (instanceId=%d)\n", objectName, eventName, instance->instanceId); } } } @@ -687,7 +687,7 @@ void Runner_drawTileLayer(Runner* runner, RoomLayerTilesData* data, float layerO bool rotate = (cell & GMS2_TILE_ROTATE_MASK) != 0; if (rotate && !rotateWarned) { - Log_logWarning("Runner: WARNING: GMS2 tile layer has rotated tiles; rotation not yet implemented, drawing unrotated\n"); + logWarn("Runner: WARNING: GMS2 tile layer has rotated tiles; rotation not yet implemented, drawing unrotated\n"); rotateWarned = true; } @@ -881,14 +881,14 @@ void Runner_draw(Runner* runner) { int32_t tpagIndex = Renderer_resolveObjectTPAGIndex(dataWin, tile); if (tpagIndex >= 0) { TexturePageItem* tpag = &dataWin->tpag.items[tpagIndex]; - Log_log("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag(srcX=%d srcY=%d srcW=%d srcH=%d tgtX=%d tgtY=%d bndW=%d bndH=%d page=%d) tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tpag->sourceX, tpag->sourceY, tpag->sourceWidth, tpag->sourceHeight, tpag->targetX, tpag->targetY, tpag->boundingWidth, tpag->boundingHeight, tpag->texturePageId, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); + logInfo("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag(srcX=%d srcY=%d srcW=%d srcH=%d tgtX=%d tgtY=%d bndW=%d bndH=%d page=%d) tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tpag->sourceX, tpag->sourceY, tpag->sourceWidth, tpag->sourceHeight, tpag->targetX, tpag->targetY, tpag->boundingWidth, tpag->boundingHeight, tpag->texturePageId, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); // Warn if tile source rect exceeds TPAG content bounds if ((uint32_t) (tile->sourceX + tile->width) > (uint32_t) tpag->sourceWidth || (uint32_t) (tile->sourceY + tile->height) > (uint32_t) tpag->sourceHeight) { - Log_logWarning("Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); + logWarn("Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); } } else { - Log_log("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); + logInfo("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); } } } @@ -983,14 +983,14 @@ void Runner_draw(Runner* runner) { int32_t tpagIndex = Renderer_resolveObjectTPAGIndex(dataWin, tile); if (tpagIndex >= 0) { TexturePageItem* tpag = &dataWin->tpag.items[tpagIndex]; - Log_log("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag(srcX=%d srcY=%d srcW=%d srcH=%d tgtX=%d tgtY=%d bndW=%d bndH=%d page=%d) tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tpag->sourceX, tpag->sourceY, tpag->sourceWidth, tpag->sourceHeight, tpag->targetX, tpag->targetY, tpag->boundingWidth, tpag->boundingHeight, tpag->texturePageId, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); + logInfo("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag(srcX=%d srcY=%d srcW=%d srcH=%d tgtX=%d tgtY=%d bndW=%d bndH=%d page=%d) tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tpag->sourceX, tpag->sourceY, tpag->sourceWidth, tpag->sourceHeight, tpag->targetX, tpag->targetY, tpag->boundingWidth, tpag->boundingHeight, tpag->texturePageId, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); // Warn if tile source rect exceeds TPAG content bounds if ((uint32_t) (tile->sourceX + tile->width) > (uint32_t) tpag->sourceWidth || (uint32_t) (tile->sourceY + tile->height) > (uint32_t) tpag->sourceHeight) { - Log_logWarning("Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); + logWarn("Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); } } else { - Log_log("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); + logInfo("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); } } } @@ -1288,7 +1288,7 @@ static Instance* createAndInitInstance(Runner* runner, int32_t instanceId, int32 #ifdef ENABLE_VM_TRACING if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, objDef->name) != -1) { - Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) created at (%f, %f)\n", objDef->name, instanceId, inst->objectIndex, x, y); + logInfo("VM: Instance %s (instanceId=%d,objectIndex=%d) created at (%f, %f)\n", objDef->name, instanceId, inst->objectIndex, x, y); } #endif @@ -1308,7 +1308,7 @@ static Instance** takePersistentInstances(Runner* runner) { #ifdef ENABLE_VM_TRACING GameObject* gameObject = &runner->dataWin->objt.objects[inst->objectIndex]; if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, gameObject->name) != -1) { - Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) has been persisted at (%f, %f) due to room change\n", gameObject->name, inst->instanceId, inst->objectIndex, inst->x, inst->y); + logInfo("VM: Instance %s (instanceId=%d,objectIndex=%d) has been persisted at (%f, %f) due to room change\n", gameObject->name, inst->instanceId, inst->objectIndex, inst->x, inst->y); } #endif @@ -1321,7 +1321,7 @@ static Instance** takePersistentInstances(Runner* runner) { #ifdef ENABLE_VM_TRACING GameObject* gameObject = &runner->dataWin->objt.objects[inst->objectIndex]; if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, gameObject->name) != -1) { - Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) destroyed at (%f, %f) due to room change\n", gameObject->name, inst->instanceId, inst->objectIndex, inst->x, inst->y); + logInfo("VM: Instance %s (instanceId=%d,objectIndex=%d) destroyed at (%f, %f) due to room change\n", gameObject->name, inst->instanceId, inst->objectIndex, inst->x, inst->y); } #endif @@ -1467,7 +1467,7 @@ static void initRoom(Runner* runner, int32_t roomIndex) { returnPersistentInstances(runner, carriedPersistent); // No Create events, no preCreateCode, no creationCode, no room creation code - Log_log("Runner: Room restored (persistent): %s (room %d) with %d instances\n", room->name, roomIndex, (int) arrlen(runner->instances)); + logInfo("Runner: Room restored (persistent): %s (room %d) with %d instances\n", room->name, roomIndex, (int) arrlen(runner->instances)); return; } @@ -1674,7 +1674,7 @@ static void initRoom(Runner* runner, int32_t roomIndex) { RoomGameObject* roomObj = &room->gameObjects[i]; if (roomObj->objectDefinition == -1) { - Log_logWarning("Runner: Object %d in room %s does not have a valid object definition reference! Was it deleted in the editor?\n", roomObj->instanceID, room->name); + logWarn("Runner: Object %d in room %s does not have a valid object definition reference! Was it deleted in the editor?\n", roomObj->instanceID, room->name); continue; } @@ -1752,7 +1752,7 @@ static void initRoom(Runner* runner, int32_t roomIndex) { // Mark this room as initialized for persistent room support savedState->initialized = true; - Log_log("Runner: Room loaded: %s (room %d) with %d instances\n", room->name, roomIndex, (int) arrlen(runner->instances)); + logInfo("Runner: Room loaded: %s (room %d) with %d instances\n", room->name, roomIndex, (int) arrlen(runner->instances)); } // Cleans up the runner state, used when freeing the Runner or when restarting the Runner @@ -2256,7 +2256,7 @@ Runner* Runner_create(DataWin* dataWin, VMContext* vm, Renderer* renderer, FileS repeat(shlen(vm->builtinMap), i) { bool isRegistered = shgeti(vm->codeIndexByName, vm->builtinMap[i].key) != -1; if (isRegistered) { - Log_logWarning("Runner: Builtin function %s has the same name as a GML script! The script may be a compatibility script provided by GM:S 2+, and the game may have issues due to the builtin overriding it!\n", vm->builtinMap[i].key); + logWarn("Runner: Builtin function %s has the same name as a GML script! The script may be a compatibility script provided by GM:S 2+, and the game may have issues due to the builtin overriding it!\n", vm->builtinMap[i].key); } } @@ -2308,7 +2308,7 @@ Instance* Runner_createInstanceWithLayer(Runner* runner, GMLReal x, GMLReal y, i if (isObjectDisabled(runner, objectIndex)) return nullptr; RuntimeLayer* rl = Runner_findRuntimeLayerById(runner, layerId); if (rl == nullptr) { - Log_logWarning("Runner: instance_create_layer: Layer ID %d not found!\n", layerId); + logWarn("Runner: instance_create_layer: Layer ID %d not found!\n", layerId); return nullptr; } Instance* inst = createAndInitInstance(runner, runner->nextInstanceId++, objectIndex, x, y); @@ -2355,7 +2355,7 @@ void Runner_destroyInstance(MAYBE_UNUSED Runner* runner, Instance* inst, bool ru #ifdef ENABLE_VM_TRACING GameObject* gameObject = &runner->dataWin->objt.objects[inst->objectIndex]; if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, gameObject->name) != -1) { - Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) destroyed\n", gameObject->name, inst->instanceId, inst->objectIndex); + logInfo("VM: Instance %s (instanceId=%d,objectIndex=%d) destroyed\n", gameObject->name, inst->instanceId, inst->objectIndex); } #endif } @@ -2503,7 +2503,7 @@ void Runner_initFirstRoom(Runner* runner) { repeat(dataWin->glob.count, i) { int32_t codeId = dataWin->glob.codeIds[i]; if (codeId >= 0 && dataWin->code.count > (uint32_t) codeId) { - Log_log("Runner: Executing global init script: %s\n", dataWin->code.entries[codeId].name); + logInfo("Runner: Executing global init script: %s\n", dataWin->code.entries[codeId].name); RValue result = VM_executeCode(runner->vmContext, codeId); RValue_free(&result); } @@ -2518,12 +2518,12 @@ void Runner_initFirstRoom(Runner* runner) { if (initScript == nullptr || initScript[0] == '\0') continue; int32_t scriptIndex = shget(runner->assetsByName, initScript); if (0 > scriptIndex || (uint32_t) scriptIndex >= dataWin->scpt.count) { - Log_logWarning("Runner: Extension init script '%s' not found, skipping\n", initScript); + logWarn("Runner: Extension init script '%s' not found, skipping\n", initScript); continue; } int32_t codeId = dataWin->scpt.scripts[scriptIndex].codeId; if (codeId >= 0 && dataWin->code.count > (uint32_t) codeId) { - Log_log("Runner: Executing extension init script: %s\n", initScript); + logInfo("Runner: Executing extension init script: %s\n", initScript); RValue result = VM_executeCode(runner->vmContext, codeId); RValue_free(&result); } @@ -2608,7 +2608,7 @@ static void executeCollisionEvent(Runner* runner, Instance* self, Instance* othe const char* targetName = runner->dataWin->objt.objects[targetObjectIndex].name; bool shouldTrace = shgeti(vm->eventsToBeTraced, "*") != -1 || shgeti(vm->eventsToBeTraced, "Collision") != -1 || shgeti(vm->eventsToBeTraced, selfName) != -1; if (shouldTrace) { - Log_log("Runner: [%s] Collision with %s (instanceId=%d, otherId=%d)\n", selfName, targetName, self->instanceId, other->instanceId); + logInfo("Runner: [%s] Collision with %s (instanceId=%d, otherId=%d)\n", selfName, targetName, self->instanceId, other->instanceId); } } #endif @@ -3076,7 +3076,7 @@ static void dispatchCollisionEvents(Runner* runner) { #ifdef ENABLE_VM_TRACING bool traceThisPair = shouldTraceCollisionPair(runner->vmContext, dataWin, self, other); if (traceThisPair && (!bboxSelf.valid || !bboxOther.valid)) { - Log_log("Collision: [%s id=%d] vs [%s id=%d] bbox-invalid (selfValid=%d otherValid=%d)\n", + logInfo("Collision: [%s id=%d] vs [%s id=%d] bbox-invalid (selfValid=%d otherValid=%d)\n", dataWin->objt.objects[self->objectIndex].name, self->instanceId, dataWin->objt.objects[other->objectIndex].name, other->instanceId, bboxSelf.valid, bboxOther.valid); @@ -3088,7 +3088,7 @@ static void dispatchCollisionEvents(Runner* runner) { bool aabbMiss = bboxSelf.left >= bboxOther.right || bboxOther.left >= bboxSelf.right || bboxSelf.top >= bboxOther.bottom || bboxOther.top >= bboxSelf.bottom; #ifdef ENABLE_VM_TRACING if (traceThisPair) { - Log_log("Collision: [%s id=%d pos=(%g,%g)] vs [%s id=%d pos=(%g,%g)] selfBB=(%g,%g,%g,%g %gx%g) otherBB=(%g,%g,%g,%g %gx%g) selfSolid=%d otherSolid=%d AABB=%s\n", + logInfo("Collision: [%s id=%d pos=(%g,%g)] vs [%s id=%d pos=(%g,%g)] selfBB=(%g,%g,%g,%g %gx%g) otherBB=(%g,%g,%g,%g %gx%g) selfSolid=%d otherSolid=%d AABB=%s\n", dataWin->objt.objects[self->objectIndex].name, self->instanceId, self->x, self->y, dataWin->objt.objects[other->objectIndex].name, other->instanceId, other->x, other->y, bboxSelf.left, bboxSelf.top, bboxSelf.right, bboxSelf.bottom, bboxSelf.right - bboxSelf.left, bboxSelf.bottom - bboxSelf.top, @@ -3105,7 +3105,7 @@ static void dispatchCollisionEvents(Runner* runner) { if (needsPrecise) { bool preciseHit = Collision_instancesOverlapPrecise(runner, self, other, bboxSelf, bboxOther); #ifdef ENABLE_VM_TRACING - if (traceThisPair) Log_log(" precise=%s (selfSepMasks=%d otherSepMasks=%d)\n", preciseHit ? "hit" : "miss", sprSelf ? (int32_t)sprSelf->sepMasks : -1, sprOther ? (int32_t)sprOther->sepMasks : -1); + if (traceThisPair) logInfo(" precise=%s (selfSepMasks=%d otherSepMasks=%d)\n", preciseHit ? "hit" : "miss", sprSelf ? (int32_t)sprSelf->sepMasks : -1, sprOther ? (int32_t)sprOther->sepMasks : -1); #endif if (!preciseHit) continue; } @@ -3114,7 +3114,7 @@ static void dispatchCollisionEvents(Runner* runner) { bool hadSolid = self->solid || other->solid; if (hadSolid) { #ifdef ENABLE_VM_TRACING - if (traceThisPair) Log_log(" solid-restore: self.solid=%d other.solid=%d self=(%g,%g)->(%g,%g) other=(%g,%g)->(%g,%g)\n", self->solid, other->solid, self->x, self->y, self->xprevious, self->yprevious, other->x, other->y, other->xprevious, other->yprevious); + if (traceThisPair) logInfo(" solid-restore: self.solid=%d other.solid=%d self=(%g,%g)->(%g,%g) other=(%g,%g)->(%g,%g)\n", self->solid, other->solid, self->x, self->y, self->xprevious, self->yprevious, other->x, other->y, other->xprevious, other->yprevious); #endif self->x = self->xprevious; self->y = self->yprevious; @@ -3130,7 +3130,7 @@ static void dispatchCollisionEvents(Runner* runner) { // And if it DOES move via GML, the variable write handlers will set it to dirty #ifdef ENABLE_VM_TRACING - if (traceThisPair) Log_log(" fire self->other: subtype=%d (%s) owner=%d (%s) codeId=%d codeName=%s\n", targetObjIndex, dataWin->objt.objects[targetObjIndex].name, evt->ownerObjectIndex, dataWin->objt.objects[evt->ownerObjectIndex].name, evt->codeId, dataWin->code.entries[evt->codeId].name); + if (traceThisPair) logInfo(" fire self->other: subtype=%d (%s) owner=%d (%s) codeId=%d codeName=%s\n", targetObjIndex, dataWin->objt.objects[targetObjIndex].name, evt->ownerObjectIndex, dataWin->objt.objects[evt->ownerObjectIndex].name, evt->codeId, dataWin->code.entries[evt->codeId].name); #endif executeCollisionEvent(runner, self, other, targetObjIndex, evt->codeId, evt->ownerObjectIndex); @@ -3143,8 +3143,8 @@ static void dispatchCollisionEvents(Runner* runner) { FlattenedCollisionEvent* reverseEvt = findSymmetricCollisionEvent(runner, other, self); #ifdef ENABLE_VM_TRACING if (traceThisPair) { - if (reverseEvt != nullptr) Log_log(" fire other->self: subtype=%u (%s) owner=%d (%s) codeId=%d codeName=%s [symmetric]\n", reverseEvt->targetObjectIndex, dataWin->objt.objects[reverseEvt->targetObjectIndex].name, reverseEvt->ownerObjectIndex, dataWin->objt.objects[reverseEvt->ownerObjectIndex].name, reverseEvt->codeId, dataWin->code.entries[evt->codeId].name); - else Log_log(" fire other->self: none (no matching handler) [symmetric]\n"); + if (reverseEvt != nullptr) logInfo(" fire other->self: subtype=%u (%s) owner=%d (%s) codeId=%d codeName=%s [symmetric]\n", reverseEvt->targetObjectIndex, dataWin->objt.objects[reverseEvt->targetObjectIndex].name, reverseEvt->ownerObjectIndex, dataWin->objt.objects[reverseEvt->ownerObjectIndex].name, reverseEvt->codeId, dataWin->code.entries[evt->codeId].name); + else logInfo(" fire other->self: none (no matching handler) [symmetric]\n"); } #endif if (reverseEvt != nullptr) @@ -3187,7 +3187,7 @@ static void dispatchCollisionEvents(Runner* runner) { } if (stillColliding) { #ifdef ENABLE_VM_TRACING - if (traceThisPair) Log_log(" post-event re-revert: still colliding, restoring self=(%g,%g)->(%g,%g) other=(%g,%g)->(%g,%g)\n", self->x, self->y, self->xprevious, self->yprevious, other->x, other->y, other->xprevious, other->yprevious); + if (traceThisPair) logInfo(" post-event re-revert: still colliding, restoring self=(%g,%g)->(%g,%g) other=(%g,%g)->(%g,%g)\n", self->x, self->y, self->xprevious, self->yprevious, other->x, other->y, other->xprevious, other->yprevious); #endif self->x = self->xprevious; self->y = self->yprevious; @@ -3483,7 +3483,7 @@ void Runner_handlePendingRoomChange(Runner* runner) { require(runner->dataWin->room.count > (uint32_t) newRoomIndex); const char* newRoomName = runner->dataWin->room.rooms[newRoomIndex].name; - Log_log("Room changed: %s (room %d) -> %s (room %d)\n", oldRoomName, oldRoomIndex, newRoomName, newRoomIndex); + logInfo("Room changed: %s (room %d) -> %s (room %d)\n", oldRoomName, oldRoomIndex, newRoomName, newRoomIndex); // If the old room is persistent, save its instance and visual state if (oldRoom->persistent) { @@ -3713,7 +3713,7 @@ void Runner_step(Runner* runner) { #ifdef ENABLE_VM_TRACING GameObject* object = &runner->dataWin->objt.objects[inst->objectIndex]; if (shgeti(runner->vmContext->alarmsToBeTraced, "*") != -1 || shgeti(runner->vmContext->alarmsToBeTraced, object->name) != -1) { - Log_log("VM: [%s] Ticking down Alarm[%d] (instanceId=%d), current tick is %d\n", object->name, (int)alarmIdx, inst->instanceId, inst->alarm[alarmIdx]); + logInfo("VM: [%s] Ticking down Alarm[%d] (instanceId=%d), current tick is %d\n", object->name, (int)alarmIdx, inst->instanceId, inst->alarm[alarmIdx]); } #endif @@ -3724,7 +3724,7 @@ void Runner_step(Runner* runner) { #ifdef ENABLE_VM_TRACING if (shgeti(runner->vmContext->alarmsToBeTraced, "*") != -1 || shgeti(runner->vmContext->alarmsToBeTraced, object->name) != -1) { - Log_log("VM: [%s] Firing Alarm[%d] (instanceId=%d)\n", object->name, (int)alarmIdx, inst->instanceId); + logInfo("VM: [%s] Firing Alarm[%d] (instanceId=%d)\n", object->name, (int)alarmIdx, inst->instanceId); } #endif @@ -4032,9 +4032,9 @@ void Runner_dumpState(Runner* runner) { DataWin* dataWin = runner->dataWin; int32_t instanceCount = (int32_t) arrlen(runner->instances); - Log_log("=== Frame %d State Dump ===\n", runner->frameCount); - Log_log("Room: %s (index %d)\n", runner->currentRoom->name, runner->currentRoomIndex); - Log_log("Instance count: %d\n", instanceCount); + logInfo("=== Frame %d State Dump ===\n", runner->frameCount); + logInfo("Room: %s (index %d)\n", runner->currentRoom->name, runner->currentRoomIndex); + logInfo("Instance count: %d\n", instanceCount); repeat(instanceCount, i) { Instance* inst = runner->instances[i]; @@ -4057,23 +4057,23 @@ void Runner_dumpState(Runner* runner) { parentName = dataWin->objt.objects[gameObject->parentId].name; } - Log_log("\n--- Instance #%d (%s, objectIndex=%d) ---\n", inst->instanceId, objName, inst->objectIndex); - Log_log(" Position: (%g, %g)\n", (double) inst->x, (double) inst->y); - Log_log(" Depth: %d\n", inst->depth); - Log_log(" Sprite: %s (index %d), imageIndex=%g, imageSpeed=%g\n", spriteName, inst->spriteIndex, (double) inst->imageIndex, (double) inst->imageSpeed); - Log_log(" Scale: (%g, %g), Angle: %g, Alpha: %g, Blend: 0x%06X\n", (double) inst->imageXscale, (double) inst->imageYscale, (double) inst->imageAngle, (double) inst->imageAlpha, inst->imageBlend); - Log_log(" Visible: %s, Active: %s, Solid: %s, Persistent: %s\n", inst->visible ? "true" : "false", inst->active ? "true" : "false", inst->solid ? "true" : "false", inst->persistent ? "true" : "false"); - Log_log(" Parent: %s (parentId=%d)\n", parentName, gameObject != nullptr ? gameObject->parentId : -1); + logInfo("\n--- Instance #%d (%s, objectIndex=%d) ---\n", inst->instanceId, objName, inst->objectIndex); + logInfo(" Position: (%g, %g)\n", (double) inst->x, (double) inst->y); + logInfo(" Depth: %d\n", inst->depth); + logInfo(" Sprite: %s (index %d), imageIndex=%g, imageSpeed=%g\n", spriteName, inst->spriteIndex, (double) inst->imageIndex, (double) inst->imageSpeed); + logInfo(" Scale: (%g, %g), Angle: %g, Alpha: %g, Blend: 0x%06X\n", (double) inst->imageXscale, (double) inst->imageYscale, (double) inst->imageAngle, (double) inst->imageAlpha, inst->imageBlend); + logInfo(" Visible: %s, Active: %s, Solid: %s, Persistent: %s\n", inst->visible ? "true" : "false", inst->active ? "true" : "false", inst->solid ? "true" : "false", inst->persistent ? "true" : "false"); + logInfo(" Parent: %s (parentId=%d)\n", parentName, gameObject != nullptr ? gameObject->parentId : -1); // Active alarms bool hasAlarm = false; repeat(GML_ALARM_COUNT, alarmIdx) { if (inst->alarm[alarmIdx] >= 0) { - if (!hasAlarm) { Log_log(" Alarms:"); hasAlarm = true; } - Log_log(" [%d]=%d", (int)alarmIdx, inst->alarm[alarmIdx]); + if (!hasAlarm) { logInfo(" Alarms:"); hasAlarm = true; } + logInfo(" [%d]=%d", (int)alarmIdx, inst->alarm[alarmIdx]); } } - if (hasAlarm) Log_log("\n"); + if (hasAlarm) logInfo("\n"); // Self variables bool hasSelfVars = false; @@ -4095,25 +4095,25 @@ void Runner_dumpState(Runner* runner) { } if (val.type == RVALUE_ARRAY && val.array != nullptr) { - if (!hasSelfArrays) { Log_log(" Self Arrays:\n"); hasSelfArrays = true; } + if (!hasSelfArrays) { logInfo(" Self Arrays:\n"); hasSelfArrays = true; } repeat(GMLArray_length1D(val.array), ai) { RValue* cell = GMLArray_slot(val.array, ai); if (cell == nullptr || cell->type == RVALUE_UNDEFINED) continue; char* innerStr = RValue_toStringFancy(*cell); - Log_log(" %s[%d] = %s\n", varName, (int) ai, innerStr); + logInfo(" %s[%d] = %s\n", varName, (int) ai, innerStr); free(innerStr); } } else { - if (!hasSelfVars) { Log_log(" Self Variables:\n"); hasSelfVars = true; } + if (!hasSelfVars) { logInfo(" Self Variables:\n"); hasSelfVars = true; } char* valStr = RValue_toStringFancy(val); - Log_log(" %s = %s\n", varName, valStr); + logInfo(" %s = %s\n", varName, valStr); free(valStr); } } } // Global variables (non-array) - Log_log("\n=== Global Variables ===\n"); + logInfo("\n=== Global Variables ===\n"); repeat(runner->vmContext->globalScopeInstance->selfVars.capacity, i) { IntRValueEntry entryOnTheVarStruct = runner->vmContext->globalScopeInstance->selfVars.entries[i]; @@ -4127,18 +4127,18 @@ void Runner_dumpState(Runner* runner) { RValue* cell = GMLArray_slot(target.array, ai); if (cell == nullptr || cell->type == RVALUE_UNDEFINED) continue; char* innerStr = RValue_toStringFancy(*cell); - Log_log(" %s[%d] = %s\n", name, (int) ai, innerStr); + logInfo(" %s[%d] = %s\n", name, (int) ai, innerStr); free(innerStr); } } char* valStr = RValue_toStringTyped(target); - Log_log(" %s = %s\n", name, valStr); + logInfo(" %s = %s\n", name, valStr); free(valStr); } } - Log_log("\n=== End Frame %d State Dump ===\n", runner->frameCount); + logInfo("\n=== End Frame %d State Dump ===\n", runner->frameCount); } // ===[ JSON State Dump ]=== diff --git a/src/runner.h b/src/runner.h index b545dd18e..8178ecc13 100644 --- a/src/runner.h +++ b/src/runner.h @@ -722,7 +722,7 @@ static inline void Runner_setActiveState(Runner* runner, Instance* instance, boo GameObject* objDef = &runner->dataWin->objt.objects[instance->objectIndex]; if (shgeti(runner->vmContext->instanceLifecyclesToBeTraced, "*") != -1 || shgeti(runner->vmContext->instanceLifecyclesToBeTraced, objDef->name) != -1) { - Log_log("VM: Instance %s (instanceId=%d,objectIndex=%d) marked as %s at (%f, %f)\n", objDef->name, instance->instanceId, instance->objectIndex, active ? "active" : "inactive", instance->x, instance->y); + logInfo("VM: Instance %s (instanceId=%d,objectIndex=%d) marked as %s at (%f, %f)\n", objDef->name, instance->instanceId, instance->objectIndex, active ? "active" : "inactive", instance->x, instance->y); } } #else diff --git a/src/spatial_grid.c b/src/spatial_grid.c index cc9584ebe..1f91a8e37 100644 --- a/src/spatial_grid.c +++ b/src/spatial_grid.c @@ -13,7 +13,7 @@ SpatialGrid* SpatialGrid_create(uint32_t roomWidth, uint32_t roomHeight) { uint32_t gridHeight = (roomHeight / SPATIAL_GRID_CELL_SIZE) + 1; #ifdef ENABLE_SPATIAL_GRID_LOGS - Log_log("SpatialGrid: Grid size: %dx%d\n", gridWidth, gridHeight); + logInfo("SpatialGrid: Grid size: %dx%d\n", gridWidth, gridHeight); #endif grid->gridWidth = gridWidth; grid->gridHeight = gridHeight; @@ -53,7 +53,7 @@ void SpatialGrid_syncGrid(Runner* runner, SpatialGrid* grid) { if (!requiresResync) return; #ifdef ENABLE_SPATIAL_GRID_LOGS - Log_log("SpatialGrid: Syncing grid with %d dirty instances\n", arrlen(grid->dirtyInstances)); + logInfo("SpatialGrid: Syncing grid with %d dirty instances\n", arrlen(grid->dirtyInstances)); #endif repeat(arrlen(grid->dirtyInstances), i) { diff --git a/src/utils.h b/src/utils.h index 322aea474..bdf43631a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -47,7 +47,7 @@ #define require(condition) \ do { \ if (!(condition)) { \ - Log_logError("Requirement failed at %s:%d\n", __FILE__, __LINE__); \ + logError("Requirement failed at %s:%d\n", __FILE__, __LINE__); \ abort(); \ } \ } while (0) @@ -55,7 +55,7 @@ #define requireMessage(condition, message) \ do { \ if (!(condition)) { \ - Log_logError("Requirement failed at %s:%d: %s\n", __FILE__, __LINE__, message); \ + logError("Requirement failed at %s:%d: %s\n", __FILE__, __LINE__, message); \ abort(); \ } \ } while (0) @@ -64,17 +64,17 @@ static inline void requireMessageFormatted(const char *file, int line, bool cond if (condition) return; va_list args; - Log_logError("Requirement failed at %s:%d: ", file, line); + logError("Requirement failed at %s:%d: ", file, line); va_start(args, fmt); - Log_vLogError(fmt, args); + vLogError(fmt, args); va_end(args); - Log_logError("\n"); + logError("\n"); abort(); } static inline void* requireNotNullFunction(void* ptr, const char* file, int line, const char* name) { if (!ptr) { - Log_logError("%s:%d: requireNotNull failed: '%s'\n", file, line, name); + logError("%s:%d: requireNotNull failed: '%s'\n", file, line, name); abort(); } return ptr; @@ -86,7 +86,7 @@ static inline void* requireNotNullFunction(void* ptr, const char* file, int line static inline void *safeMallocFunction(size_t size, const char *file, int line) { void *ret = malloc(size); if (!ret) { - Log_logError("FATAL: malloc(%zu) failed at %s:%d\n", size, file, line); + logError("FATAL: malloc(%zu) failed at %s:%d\n", size, file, line); abort(); } return ret; @@ -96,7 +96,7 @@ static inline void *safeMallocFunction(size_t size, const char *file, int line) static inline void *safeCallocFunction(size_t count, size_t size, const char *file, int line) { void *ret = calloc(count, size); if (!ret) { - Log_logError("FATAL: calloc(%zu, %zu) failed at %s:%d\n", count, size, file, line); + logError("FATAL: calloc(%zu, %zu) failed at %s:%d\n", count, size, file, line); abort(); } return ret; @@ -106,7 +106,7 @@ static inline void *safeCallocFunction(size_t count, size_t size, const char *fi static inline void *safeReallocFunction(void *ptr, size_t size, const char *file, int line) { void *ret = realloc(ptr, size); if (!ret) { - Log_logError("FATAL: realloc(%zu) failed at %s:%d\n", size, file, line); + logError("FATAL: realloc(%zu) failed at %s:%d\n", size, file, line); abort(); } return ret; @@ -118,7 +118,7 @@ static inline void *safeReallocFunction(void *ptr, size_t size, const char *file static inline void *safeMemalignFunction(size_t alignment, size_t size, const char *file, int line) { void *ret = memalign(alignment, size); if (!ret) { - Log_logError("FATAL: memalign(%zu, %zu) failed at %s:%d\n", alignment, size, file, line); + logError("FATAL: memalign(%zu, %zu) failed at %s:%d\n", alignment, size, file, line); abort(); } return ret; @@ -130,7 +130,7 @@ static inline void *safeMemalignFunction(size_t alignment, size_t size, const ch // Reads exactly n bytes or aborts with the "pathForError" that caused the error. static inline void safeFreadFunction(void *dst, size_t n, FILE *read_file, const char *pathForError, const char *file, int line) { if (fread(dst, 1, n, read_file) != n) { - Log_logError("FATAL: failed to read %zu bytes from %s at %s:%d\n", n, pathForError, file, line); + logError("FATAL: failed to read %zu bytes from %s at %s:%d\n", n, pathForError, file, line); abort(); } } @@ -139,7 +139,7 @@ static inline void safeFreadFunction(void *dst, size_t n, FILE *read_file, const static inline char *safeStrdupFunction(const char *str, const char *file, int line) { char *ret = strdup(str); if (!ret) { - Log_logError("FATAL: strdup() failed at %s:%d\n", file, line); + logError("FATAL: strdup() failed at %s:%d\n", file, line); abort(); } return ret; diff --git a/src/vm.c b/src/vm.c index e90deb2ec..feec4c74a 100644 --- a/src/vm.c +++ b/src/vm.c @@ -64,7 +64,7 @@ static void stackPush(VMContext* ctx, RValue val) { char* valStr = RValue_toStringTyped(val); ctx->stack.slots[ctx->stack.top++] = val; char* stackBuf = formatStackContents(ctx); - Log_log("VM: [%s] PUSH %s [stack=%d -> %d] %s\n", ctx->currentCodeName, valStr, ctx->stack.top - 1, ctx->stack.top, stackBuf); + logInfo("VM: [%s] PUSH %s [stack=%d -> %d] %s\n", ctx->currentCodeName, valStr, ctx->stack.top - 1, ctx->stack.top, stackBuf); free(stackBuf); free(valStr); return; @@ -85,7 +85,7 @@ static RValue stackPop(VMContext* ctx) { if (shouldTraceStack(ctx)) { char* valStr = RValue_toStringTyped(val); char* stackBuf = formatStackContents(ctx); - Log_log("VM: [%s] POP %s [stack=%d -> %d] %s\n", ctx->currentCodeName, valStr, ctx->stack.top + 1, ctx->stack.top, stackBuf); + logInfo("VM: [%s] POP %s [stack=%d -> %d] %s\n", ctx->currentCodeName, valStr, ctx->stack.top + 1, ctx->stack.top, stackBuf); free(stackBuf); free(valStr); } @@ -680,9 +680,9 @@ static RValue resolveVariableRead(VMContext* ctx, int32_t instanceType, uint32_t const char* varTypeName = varTypeToString((varRef >> 24) & 0xF8); if (instanceType < INSTANCE_ID_BASE && (uint32_t) instanceType < ctx->dataWin->objt.count) { GameObject* gameObject = &ctx->dataWin->objt.objects[instanceType]; - Log_logWarning("VM: [%s] READ var '%s' on object index %d (%s) but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, gameObject->name, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); + logWarn("VM: [%s] READ var '%s' on object index %d (%s) but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, gameObject->name, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); } else { - Log_logWarning("VM: [%s] READ var '%s' on instance %d but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); + logWarn("VM: [%s] READ var '%s' on instance %d but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); } return RValue_makeReal(0.0); } @@ -730,7 +730,7 @@ static RValue resolveVariableRead(VMContext* ctx, int32_t instanceType, uint32_t result = RValue_makeUndefined(); } } else { - Log_logWarning("VM: [%s] INSTANCE_ARG read on unknown variable '%s' (builtinVarId=%d)\n", ctx->currentCodeName, varDef->name, builtinVarId); + logWarn("VM: [%s] INSTANCE_ARG read on unknown variable '%s' (builtinVarId=%d)\n", ctx->currentCodeName, varDef->name, builtinVarId); result = RValue_makeUndefined(); } return result; @@ -779,7 +779,7 @@ static RValue resolveVariableRead(VMContext* ctx, int32_t instanceType, uint32_t Instance* inst = targetInstance; if (inst == nullptr) { const char* varTypeName = varTypeToString((varRef >> 24) & 0xF8); - Log_logWarning("VM: [%s] Read on self var '%s' but no current instance (instanceType=%d, varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); + logWarn("VM: [%s] Read on self var '%s' but no current instance (instanceType=%d, varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID); return RValue_makeReal(0.0); } slot = IntRValueHashMap_findSlot(&inst->selfVars, varDef->varID); @@ -954,7 +954,7 @@ static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t if (ctx->dataWin->objt.count > (uint32_t) instanceType) { GameObject* gameObject = &ctx->dataWin->objt.objects[instanceType]; char* valAsString = RValue_toString(val); - Log_logWarning("VM: [%s] WRITE var '%s' on object %d (%s) but no instances found (value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, gameObject->name, valAsString); + logWarn("VM: [%s] WRITE var '%s' on object %d (%s) but no instances found (value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, gameObject->name, valAsString); free(valAsString); } } @@ -969,7 +969,7 @@ static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t if (targetInstance == nullptr) { const char* varTypeName = varTypeToString((varRef >> 24) & 0xF8); char* valAsString = RValue_toString(val); - Log_logWarning("VM: [%s] WRITE var '%s' on instance %d but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID, valAsString); + logWarn("VM: [%s] WRITE var '%s' on instance %d but no instance found (varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID, valAsString); free(valAsString); return; } @@ -986,7 +986,7 @@ static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t } else if (bid == BUILTIN_VAR_ARGUMENT) { writeIndex = access.arrayIndex; } else { - Log_logWarning("VM: [%s] INSTANCE_ARG write on unknown variable '%s' (builtinVarId=%d)\n", ctx->currentCodeName, varDef->name, bid); + logWarn("VM: [%s] INSTANCE_ARG write on unknown variable '%s' (builtinVarId=%d)\n", ctx->currentCodeName, varDef->name, bid); } if (writeIndex >= 0) { VM_writeToScriptArgs(ctx, writeIndex, val); @@ -1031,7 +1031,7 @@ static void resolveVariableWrite(VMContext* ctx, int32_t instanceType, uint32_t if (inst == nullptr) { const char* varTypeName = varTypeToString((varRef >> 24) & 0xF8); char* valAsString = RValue_toString(val); - Log_logWarning("VM: [%s] Write on self var '%s' but no current instance (instanceType=%d, varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID, valAsString); + logWarn("VM: [%s] Write on self var '%s' but no current instance (instanceType=%d, varType=%s, isArray=%s, originalInstanceType=%d, hasInstanceType=%s, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, instanceType, varTypeName, access.isArray ? "true" : "false", originalInstanceType, access.hasInstanceType ? "true" : "false", varDef->varID, valAsString); free(valAsString); RValue_free(&val); return; @@ -1106,7 +1106,7 @@ static RValue convertValue(RValue val, uint8_t targetType) { // Variable type on stack is just an RValue passthrough return val; default: - Log_logWarning("VM: Unknown target type 0x%X for conversion\n", targetType); + logWarn("VM: Unknown target type 0x%X for conversion\n", targetType); return val; } } @@ -1175,7 +1175,7 @@ static void handlePush(VMContext* ctx, uint32_t instr, const uint8_t* extraData, // Positive scopes are real instance IDs resolved by lookup. Instance* inst = (0 > scope) ? (Instance*) ctx->currentInstance : VM_findInstanceByTarget(ctx, scope); if (inst == nullptr) { - Log_logError("VM: ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); + logError("VM: ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); abort(); } slot = IntRValueHashMap_getOrInsertUndefined(&inst->selfVars, varDef->varID); @@ -1229,7 +1229,7 @@ static void handlePush(VMContext* ctx, uint32_t instr, const uint8_t* extraData, break; } default: - Log_logError("VM: Push with unknown type 0x%X\n", type1); + logError("VM: Push with unknown type 0x%X\n", type1); abort(); } } @@ -1270,7 +1270,7 @@ static void handlePushBltn(VMContext* ctx, uint32_t instr, const uint8_t* extraD inst = (Instance*) ctx->currentInstance; } if (inst == nullptr) { - Log_logError("VM: PushBltn ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); + logError("VM: PushBltn ARRAYPUSHAF: no instance for scope %d varID=%d\n", scope, varDef->varID); abort(); } RValue* slot = IntRValueHashMap_getOrInsertUndefined(&inst->selfVars, varDef->varID); @@ -1427,9 +1427,9 @@ static void handlePop(VMContext* ctx, uint8_t type1, uint8_t type2, uint32_t var const char* varTypeName = varTypeToString(varType); char* valAsString = RValue_toString(val); if (instanceType < INSTANCE_ID_BASE && (uint32_t) instanceType < ctx->dataWin->objt.count) { - Log_logWarning("VM: [%s] WRITE array var '%s[%d]' on object index %d (%s) but no instance found (varType=%s, originalInstanceType=%d, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, arrayIndex, instanceType, ctx->dataWin->objt.objects[instanceType].name, varTypeName, originalInstanceType, varDef->varID, valAsString); + logWarn("VM: [%s] WRITE array var '%s[%d]' on object index %d (%s) but no instance found (varType=%s, originalInstanceType=%d, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, arrayIndex, instanceType, ctx->dataWin->objt.objects[instanceType].name, varTypeName, originalInstanceType, varDef->varID, valAsString); } else { - Log_logWarning("VM: [%s] WRITE array var '%s[%d]' on instance %d but no instance found (varType=%s, originalInstanceType=%d, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, arrayIndex, instanceType, varTypeName, originalInstanceType, varDef->varID, valAsString); + logWarn("VM: [%s] WRITE array var '%s[%d]' on instance %d but no instance found (varType=%s, originalInstanceType=%d, varID=%d, value=%s)\n", ctx->currentCodeName, varDef->name, arrayIndex, instanceType, varTypeName, originalInstanceType, varDef->varID, valAsString); } free(valAsString); RValue_free(&val); @@ -1700,7 +1700,7 @@ static void handleConv(VMContext* ctx, uint8_t srcType, uint8_t dstType, uint8_t case 0x5F: result = val; break; default: - Log_logWarning("VM: [%s] Conv unhandled conversion 0x%02X (src=0x%X dst=0x%X)\n", ctx->currentCodeName, convKey, srcType, dstType); + logWarn("VM: [%s] Conv unhandled conversion 0x%02X (src=0x%X dst=0x%X)\n", ctx->currentCodeName, convKey, srcType, dstType); result = val; break; } @@ -1960,7 +1960,7 @@ static void handleCall(VMContext* ctx, uint32_t instr, const uint8_t* extraData) free(display); } - Log_log("VM: [%s] Calling function \"%s(%s)\"\n", ctx->currentCodeName, funcName, functionArgumentList); + logInfo("VM: [%s] Calling function \"%s(%s)\"\n", ctx->currentCodeName, funcName, functionArgumentList); } #endif @@ -1982,7 +1982,7 @@ static void handleCall(VMContext* ctx, uint32_t instr, const uint8_t* extraData) #ifdef ENABLE_VM_TRACING if (functionIsBeingTraced) { char* returnValueAsString = RValue_toStringFancy(result); - Log_log("VM: [%s] Built-in function \"%s(%s)\" returned %s\n", ctx->currentCodeName, funcName, functionArgumentList, returnValueAsString); + logInfo("VM: [%s] Built-in function \"%s(%s)\" returned %s\n", ctx->currentCodeName, funcName, functionArgumentList, returnValueAsString); free(returnValueAsString); free(functionArgumentList); } @@ -1999,7 +1999,7 @@ static void handleCall(VMContext* ctx, uint32_t instr, const uint8_t* extraData) #ifdef ENABLE_VM_TRACING if (functionIsBeingTraced) { char* returnValueAsString = RValue_toStringFancy(result); - Log_log("VM: [%s] Script function \"%s(%s)\" returned %s\n", ctx->currentCodeName, funcName, functionArgumentList, returnValueAsString); + logInfo("VM: [%s] Script function \"%s(%s)\" returned %s\n", ctx->currentCodeName, funcName, functionArgumentList, returnValueAsString); free(returnValueAsString); free(functionArgumentList); } @@ -2027,7 +2027,7 @@ static void handleCall(VMContext* ctx, uint32_t instr, const uint8_t* extraData) if (ctx->alwaysLogUnknownFunctions || 0 > shgeti(ctx->loggedUnknownFuncs, dedupKey)) { shput(ctx->loggedUnknownFuncs, dedupKey, true); - Log_logWarning("VM: [%s] Unknown function \"%s\"!\n", callerName, unknownFuncName); + logWarn("VM: [%s] Unknown function \"%s\"!\n", callerName, unknownFuncName); } else { free(dedupKey); } @@ -2114,14 +2114,14 @@ static void handleCallV(VMContext* ctx, uint32_t instr) { char* dedupKey = VM_createDedupKey(callerName, unresolvedName); if (ctx->alwaysLogUnknownFunctions || 0 > shgeti(ctx->loggedUnknownFuncs, dedupKey)) { shput(ctx->loggedUnknownFuncs, dedupKey, true); - Log_logWarning("VM: [%s] Unknown function \"%s\"! (via CallV)\n", callerName, unresolvedName); + logWarn("VM: [%s] Unknown function \"%s\"! (via CallV)\n", callerName, unresolvedName); } else { free(dedupKey); } #endif result = RValue_makeUndefined(); } else { - Log_logWarning("VM: [%s] CALLV with unresolvable function reference (type=%d, codeIndex=%d)\n", ctx->currentCodeName, function.type, codeIndex); + logWarn("VM: [%s] CALLV with unresolvable function reference (type=%d, codeIndex=%d)\n", ctx->currentCodeName, function.type, codeIndex); #ifdef ENABLE_WAD17 VMException* exception = (VMException *)safeCalloc(1, sizeof(VMException)); exception->message = safeStrdup("CALLV with unresolvable function reference"); @@ -2312,9 +2312,9 @@ static void handlePushEnv(VMContext* ctx, uint32_t instr, uint32_t instrAddr) { } if (0 > target) { - Log_logWarning("VM: [%s] PushEnv with negative target %d, this could be a Int64 number that is getting truncated to Int32!\n", ctx->currentCodeName, target); + logWarn("VM: [%s] PushEnv with negative target %d, this could be a Int64 number that is getting truncated to Int32!\n", ctx->currentCodeName, target); } else { - Log_logWarning("VM: [%s] PushEnv with unhandled target %d\n", ctx->currentCodeName, target); + logWarn("VM: [%s] PushEnv with unhandled target %d\n", ctx->currentCodeName, target); } ctx->ip = instrAddr + jumpOffset; } @@ -2463,17 +2463,17 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { entries[j] = tmp; } - Log_log("=== Opcode Profiler Report ===\n"); - Log_log("Total instructions executed: %llu\n", (unsigned long long) total); - Log_log("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); + logInfo("=== Opcode Profiler Report ===\n"); + logInfo("Total instructions executed: %llu\n", (unsigned long long) total); + logInfo("%-12s %-6s %16s %8s\n", "Opcode", "Hex", "Count", "Pct"); forEachIndexed(CountEntry, entry, i, entries, entryCount) { (void) i; double pct = total > 0 ? (100.0 * (double) entry->count / (double) total) : 0.0; - Log_log("%-12s 0x%02X %16llu %7.2f%%\n", opcodeName((uint8_t) entry->key), (uint8_t) entry->key, (unsigned long long) entry->count, pct); + logInfo("%-12s 0x%02X %16llu %7.2f%%\n", opcodeName((uint8_t) entry->key), (uint8_t) entry->key, (unsigned long long) entry->count, pct); } // Per-opcode breakdown by type variant. Sorted within each opcode by count desc. - Log_log("\n--- Type variant breakdown (per opcode) ---\n"); + logInfo("\n--- Type variant breakdown (per opcode) ---\n"); forEachIndexed(CountEntry, entry, idx, entries, entryCount) { (void) idx; uint8_t opcode = (uint8_t) entry->key; @@ -2498,13 +2498,13 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { variantEntries[j] = tmp; } - Log_log("%s (0x%02X): %llu total\n", opcodeName(opcode), opcode, (unsigned long long) entry->count); + logInfo("%s (0x%02X): %llu total\n", opcodeName(opcode), opcode, (unsigned long long) entry->count); forEachIndexed(CountEntry, ve, vi, variantEntries, variantCount) { (void) vi; uint8_t type1 = (uint8_t) ((ve->key >> 4) & 0xF); uint8_t type2 = (uint8_t) (ve->key & 0xF); double vpct = entry->count > 0 ? (100.0 * (double) ve->count / (double) entry->count) : 0.0; - Log_log(" .%c.%c %16llu %7.2f%%\n", gmlTypeChar(type1), gmlTypeChar(type2), (unsigned long long) ve->count, vpct); + logInfo(" .%c.%c %16llu %7.2f%%\n", gmlTypeChar(type1), gmlTypeChar(type2), (unsigned long long) ve->count, vpct); } // Runtime RValue type breakdown (a, b types observed at execution time) @@ -2531,13 +2531,13 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { } rvEntries[j] = tmp; } - Log_log(" -- runtime types (a, b):\n"); + logInfo(" -- runtime types (a, b):\n"); forEachIndexed(CountEntry, re, ri, rvEntries, rvCount) { (void) ri; uint8_t typeA = (uint8_t) ((re->key >> 4) & 0xF); uint8_t typeB = (uint8_t) (re->key & 0xF); double rpct = rvTotal > 0 ? (100.0 * (double) re->count / (double) rvTotal) : 0.0; - Log_log(" (%-6s, %-6s) %16llu %7.2f%%\n", rvalueTypeName(typeA), rvalueTypeName(typeB), (unsigned long long) re->count, rpct); + logInfo(" (%-6s, %-6s) %16llu %7.2f%%\n", rvalueTypeName(typeA), rvalueTypeName(typeB), (unsigned long long) re->count, rpct); } } } @@ -2562,16 +2562,16 @@ void VM_printOpcodeProfilerReport(const VMContext* ctx) { } breakEntries[j] = tmp; } - Log_log(" -- sub-opcodes:\n"); + logInfo(" -- sub-opcodes:\n"); forEachIndexed(CountEntry, be, bi, breakEntries, breakCount) { (void) bi; int16_t breakType = (int16_t) -((int) be->key); double bpct = entry->count > 0 ? (100.0 * (double) be->count / (double) entry->count) : 0.0; - Log_log(" %-12s (%4d) %16llu %7.2f%%\n", breakSubOpName(breakType), (int) breakType, (unsigned long long) be->count, bpct); + logInfo(" %-12s (%4d) %16llu %7.2f%%\n", breakSubOpName(breakType), (int) breakType, (unsigned long long) be->count, bpct); } } } - Log_log("==============================\n"); + logInfo("==============================\n"); } #endif // ENABLE_VM_OPCODE_PROFILER @@ -2586,7 +2586,7 @@ static void handleBreakChkIndex(VMContext* ctx, uint32_t instrAddr) { RValue* top = stackPeek(ctx); int32_t idx = RValue_toInt32(*top); if (0 > idx || 32000 <= idx) { - Log_logError("VM: chkindex out of bounds: %d at offset %u in %s\n", idx, instrAddr, ctx->currentCodeName); + logError("VM: chkindex out of bounds: %d at offset %u in %s\n", idx, instrAddr, ctx->currentCodeName); abort(); } } @@ -2629,7 +2629,7 @@ static void handleBreakPushAC(VMContext* ctx, uint32_t instrAddr) { int32_t idx = stackPopInt32(ctx); RValue arrayRef = stackPop(ctx); if (arrayRef.type != RVALUE_ARRAY || arrayRef.array == nullptr) { - Log_logError("VM: pushac on non-array (type=%d) at offset %u in %s\n", arrayRef.type, instrAddr, ctx->currentCodeName); + logError("VM: pushac on non-array (type=%d) at offset %u in %s\n", arrayRef.type, instrAddr, ctx->currentCodeName); abort(); } GMLArray* parent = arrayRef.array; @@ -2740,7 +2740,7 @@ static void handleBreak(VMContext* ctx, uint32_t instr, uint32_t instrAddr, cons case BREAK_ISNULLISH: handleBreakIsNullish(ctx); break; case BREAK_PUSHREF: handleBreakPushRef(ctx, extraData); break; default: - Log_logError("VM: Unknown BREAK sub-opcode %d at offset %u in %s\n", breakType, instrAddr, ctx->currentCodeName); + logError("VM: Unknown BREAK sub-opcode %d at offset %u in %s\n", breakType, instrAddr, ctx->currentCodeName); abort(); } } @@ -2780,11 +2780,11 @@ static RValue executeLoop(VMContext* ctx) { #ifdef ENABLE_WAD17 if (ctx->exception != nullptr) { #ifdef ENABLE_VM_EXCEPTIONS_LOGS - Log_logError("VM: Exception thrown! Stack Top is %d\n", ctx->exceptionHandlerStackTop); + logError("VM: Exception thrown! Stack Top is %d\n", ctx->exceptionHandlerStackTop); #endif if (ctx->exceptionHandlerStackTop == 0) { // TODO: When Butterscotch is better, we could have a strict mode that DOES throw a error - Log_logError("VM: The exception handler frame stack is 0, but we have a pending exception to be dispatched! This would've technically crashed the game in the original runner... or we aren't handling exceptions correctly. We'll swallow the exception and hope for the best... (Exception: %s)\n", ctx->exception->message); + logError("VM: The exception handler frame stack is 0, but we have a pending exception to be dispatched! This would've technically crashed the game in the original runner... or we aren't handling exceptions correctly. We'll swallow the exception and hope for the best... (Exception: %s)\n", ctx->exception->message); free(ctx->exception->message); free(ctx->exception); ctx->exception = nullptr; @@ -2797,7 +2797,7 @@ static RValue executeLoop(VMContext* ctx) { // Not for us, propagate the exception! if (exceptionHandlerFrame->boundToCallDepth != ctx->callDepth) { #ifdef ENABLE_VM_EXCEPTIONS_LOGS - Log_logWarning("VM: We wanted %d but we are %d - Propagating...\n", exceptionHandlerFrame->boundToCallDepth, ctx->callDepth); + logWarn("VM: We wanted %d but we are %d - Propagating...\n", exceptionHandlerFrame->boundToCallDepth, ctx->callDepth); #endif return RValue_makeUndefined(); } @@ -2810,7 +2810,7 @@ static RValue executeLoop(VMContext* ctx) { VM_SYNC_IP(); #ifdef ENABLE_VM_EXCEPTIONS_LOGS - Log_logWarning("VM: Jumped to %d due to exception handler, is this a exception? %d\n", ip, isException); + logWarn("VM: Jumped to %d due to exception handler, is this a exception? %d\n", ip, isException); #endif if (isException) { @@ -2892,9 +2892,9 @@ static RValue executeLoop(VMContext* ctx) { char* stackBuf = formatStackContents(ctx); if (operandStr[0] != '\0') { - Log_log("VM: [%s] @%04X (%d) [0x%08X] %s %s [stack=%d] %s\n", ctx->currentCodeName, instrAddr, instrAddr, instr, opcodeStr, operandStr, ctx->stack.top, stackBuf); + logInfo("VM: [%s] @%04X (%d) [0x%08X] %s %s [stack=%d] %s\n", ctx->currentCodeName, instrAddr, instrAddr, instr, opcodeStr, operandStr, ctx->stack.top, stackBuf); } else { - Log_log("VM: [%s] @%04X (%d) [0x%08X] %s [stack=%d] %s\n", ctx->currentCodeName, instrAddr, instrAddr, instr, opcodeStr, ctx->stack.top, stackBuf); + logInfo("VM: [%s] @%04X (%d) [0x%08X] %s [stack=%d] %s\n", ctx->currentCodeName, instrAddr, instrAddr, instr, opcodeStr, ctx->stack.top, stackBuf); } free(stackBuf); } @@ -3294,7 +3294,7 @@ static RValue executeLoop(VMContext* ctx) { break; default: - Log_logError("VM: Unknown opcode 0x%02X at offset %u\n", opcode, instrAddr); + logError("VM: Unknown opcode 0x%02X at offset %u\n", opcode, instrAddr); abort(); } } @@ -3576,7 +3576,7 @@ VMContext* VM_create(DataWin* dataWin) { } } - Log_log("VM: Initialized with %u functions mapped\n", (uint32_t) shlen(ctx->codeIndexByName)); + logInfo("VM: Initialized with %u functions mapped\n", (uint32_t) shlen(ctx->codeIndexByName)); return ctx; } @@ -3643,7 +3643,7 @@ void VM_reset(VMContext* ctx) { } #endif - Log_log("VM: Reset complete\n"); + logInfo("VM: Reset complete\n"); } static CodeLocals* resolveCodeLocals(VMContext* ctx, const char* codeName) { @@ -4290,17 +4290,17 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { CodeEntry* code = &dw->code.entries[codeIndex]; // Header - Log_log("=== %s (length=%u, locals=%u, args=%u) ===\n", code->name, code->length, code->localsCount, code->argumentsCount); + logInfo("=== %s (length=%u, locals=%u, args=%u) ===\n", code->name, code->length, code->localsCount, code->argumentsCount); // CodeLocals CodeLocals* locals = resolveCodeLocals(ctx, code->name); if (locals != nullptr && locals->localVarCount > 0) { - Log_log("Locals:"); + logInfo("Locals:"); repeat(locals->localVarCount, i) { - if (i > 0) Log_log(","); - Log_log(" [%u] %s", locals->locals[i].varID, locals->locals[i].name); + if (i > 0) logInfo(","); + logInfo(" [%u] %s", locals->locals[i].varID, locals->locals[i].name); } - Log_log("\n"); + logInfo("\n"); } // Cross-references @@ -4308,16 +4308,16 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { ptrdiff_t mapIdx = hmgeti(ctx->crossRefMap, codeIndex); if (mapIdx >= 0) { int32_t* callers = ctx->crossRefMap[mapIdx].value; - Log_log("Called by:"); + logInfo("Called by:"); for (ptrdiff_t i = 0; arrlen(callers) > i; i++) { - if (i > 0) Log_log(","); - Log_log(" %s", dw->code.entries[callers[i]].name); + if (i > 0) logInfo(","); + logInfo(" %s", dw->code.entries[callers[i]].name); } - Log_log("\n"); + logInfo("\n"); } } - Log_log("\n"); + logInfo("\n"); const uint8_t* bytecodeBase = dw->bytecodeBuffer + (code->bytecodeAbsoluteOffset - dw->bytecodeBufferBase); uint32_t codeLength = code->length; @@ -4369,7 +4369,7 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { // Print label if this address is a branch target if (hmgeti(branchTargets, instrAddr) >= 0) { - Log_log(" %04X: L_%04X:\n", instrAddr, instrAddr); + logInfo(" %04X: L_%04X:\n", instrAddr, instrAddr); } int32_t indent = 2 + envDepth * 4; @@ -4381,9 +4381,9 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { // Print the formatted line if (commentStr[0] != '\0') { - Log_log("%*s%04X (%6d): [0x%08X] %-16s %-45s %s\n", indent, "", instrAddr, instrAddr, instr, opcodeStr, operandStr, commentStr); + logInfo("%*s%04X (%6d): [0x%08X] %-16s %-45s %s\n", indent, "", instrAddr, instrAddr, instr, opcodeStr, operandStr, commentStr); } else { - Log_log("%*s%04X (%6d): [0x%08X] %-16s %s\n", indent, "", instrAddr, instrAddr, instr, opcodeStr, operandStr); + logInfo("%*s%04X (%6d): [0x%08X] %-16s %s\n", indent, "", instrAddr, instrAddr, instr, opcodeStr, operandStr); } // PushEnv increases depth after printing @@ -4391,7 +4391,7 @@ void VM_disassemble(VMContext* ctx, int32_t codeIndex) { } hmfree(branchTargets); - Log_log("\n"); + logInfo("\n"); } void VM_registerBuiltin(VMContext* ctx, const char* name, BuiltinFunc func) { diff --git a/src/vm.h b/src/vm.h index 41fdfc0e1..3ea72a8da 100644 --- a/src/vm.h +++ b/src/vm.h @@ -402,7 +402,7 @@ static inline void VM_checkIfVariableShouldBeTracedAndLog(VMContext* ctx, const if (arrayIndex >= 0) snprintf(indexBuf, sizeof(indexBuf), "[%d]", arrayIndex); char instanceIdBuf[28] = ""; if (instanceId >= 0) snprintf(instanceIdBuf, sizeof(instanceIdBuf), " (instanceId=%d)", instanceId); - Log_log("VM: [%s] %s %s.%s%s %s %s%s%s\n", ctx->currentCodeName, verb, scopeName, name, indexBuf, arrow, rvalueAsString, instanceIdBuf, additional); + logInfo("VM: [%s] %s %s.%s%s %s %s%s%s\n", ctx->currentCodeName, verb, scopeName, name, indexBuf, arrow, rvalueAsString, instanceIdBuf, additional); free(rvalueAsString); } #endif diff --git a/src/vm_builtins.c b/src/vm_builtins.c index e2e1c2d91..678413c51 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -107,7 +107,7 @@ static void logStubbedFunction(VMContext* ctx, const char* funcName) { if (ctx->alwaysLogStubbedFunctions || 0 > shgeti(ctx->loggedStubbedFuncs, dedupKey)) { // shput stores the key pointer, so don't free it when inserting shput(ctx->loggedStubbedFuncs, dedupKey, true); - Log_logWarning("VM: [%s] Stubbed function \"%s\"!\n", callerName, funcName); + logWarn("VM: [%s] Stubbed function \"%s\"!\n", callerName, funcName); } else { free(dedupKey); } @@ -120,7 +120,7 @@ static void logSemiStubbedFunction(VMContext* ctx, const char* funcName) { if (ctx->alwaysLogStubbedFunctions || 0 > shgeti(ctx->loggedStubbedFuncs, dedupKey)) { // shput stores the key pointer, so don't free it when inserting shput(ctx->loggedStubbedFuncs, dedupKey, true); - Log_logWarning("VM: [%s] Semi-Stubbed function \"%s\"!\n", callerName, funcName); + logWarn("VM: [%s] Semi-Stubbed function \"%s\"!\n", callerName, funcName); } else { free(dedupKey); } @@ -1259,7 +1259,7 @@ RValue VMBuiltins_getVariable(VMContext* ctx, Instance* inst, int16_t builtinVar break; } - Log_logWarning("VM: [%s] Unhandled built-in variable read '%s' (arrayIndex=%d)\n", ctx->currentCodeName, name, arrayIndex); + logWarn("VM: [%s] Unhandled built-in variable read '%s' (arrayIndex=%d)\n", ctx->currentCodeName, name, arrayIndex); return RValue_makeReal(0.0); } @@ -1476,7 +1476,7 @@ void VMBuiltins_setVariable(VMContext* ctx, Instance* inst, int16_t builtinVarId #ifdef ENABLE_VM_TRACING if (inst->objectIndex >= 0 && (shgeti(ctx->alarmsToBeTraced, "*") != -1 || shgeti(ctx->alarmsToBeTraced, runner->dataWin->objt.objects[inst->objectIndex].name) != -1)) { - Log_log("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, arrayIndex, newValue, inst->instanceId); + logInfo("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, arrayIndex, newValue, inst->instanceId); } #endif @@ -1770,23 +1770,23 @@ void VMBuiltins_setVariable(VMContext* ctx, Instance* inst, int16_t builtinVarId case BUILTIN_VAR_DEBUG_MODE: case BUILTIN_VAR_ROOM_FIRST: case BUILTIN_VAR_ROOM_LAST: - Log_logWarning("VM: [%s] Attempted write to read-only built-in '%s'\n", ctx->currentCodeName, name); + logWarn("VM: [%s] Attempted write to read-only built-in '%s'\n", ctx->currentCodeName, name); return; } - Log_logWarning("VM: [%s] Unhandled built-in variable write '%s' (arrayIndex=%d)\n", ctx->currentCodeName, name, arrayIndex); + logWarn("VM: [%s] Unhandled built-in variable write '%s' (arrayIndex=%d)\n", ctx->currentCodeName, name, arrayIndex); } // ===[ BUILTIN FUNCTION IMPLEMENTATIONS ]=== static RValue builtin_show_debug_message(MAYBE_UNUSED VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - Log_logWarning("[show_debug_message] Expected at least 1 argument\n"); + logWarn("[show_debug_message] Expected at least 1 argument\n"); return RValue_makeUndefined(); } char* val = RValue_toString(args[0]); - Log_log("Game: %s\n", val); + logInfo("Game: %s\n", val); free(val); return RValue_makeUndefined(); @@ -3289,7 +3289,7 @@ static RValue builtin_room_goto_next(VMContext* ctx, MAYBE_UNUSED RValue* args, if ((int32_t) runner->dataWin->gen8.roomOrderCount > nextPos) { runner->pendingRoom = runner->dataWin->gen8.roomOrder[nextPos]; } else { - Log_logWarning("VM: room_goto_next - already at last room!\n"); + logWarn("VM: room_goto_next - already at last room!\n"); } return RValue_makeUndefined(); } @@ -3301,7 +3301,7 @@ static RValue builtin_room_goto_previous(VMContext* ctx, MAYBE_UNUSED RValue* ar if (previousPos >= 0) { runner->pendingRoom = runner->dataWin->gen8.roomOrder[previousPos]; } else { - Log_logWarning("VM: room_goto_previous - already at first room!\n"); + logWarn("VM: room_goto_previous - already at first room!\n"); } return RValue_makeUndefined(); } @@ -4076,7 +4076,7 @@ static RValue builtin_script_execute(VMContext* ctx, RValue* args, int32_t argCo // Fallback: treat as SCPT index (BC16 and earlier, or when FUNC lookup failed) if (0 > codeId) { if (0 > rawArg || (uint32_t) rawArg >= ctx->dataWin->scpt.count) { - Log_logWarning("VM: script_execute - invalid script index %d\n", rawArg); + logWarn("VM: script_execute - invalid script index %d\n", rawArg); return RValue_makeUndefined(); } codeId = ctx->dataWin->scpt.scripts[rawArg].codeId; @@ -4084,7 +4084,7 @@ static RValue builtin_script_execute(VMContext* ctx, RValue* args, int32_t argCo } if (0 > codeId || ctx->dataWin->code.count <= (uint32_t) codeId) { - Log_logWarning("VM: script_execute - invalid codeId %d\n", codeId); + logWarn("VM: script_execute - invalid codeId %d\n", codeId); return RValue_makeUndefined(); } @@ -6577,7 +6577,7 @@ static RValue builtin_audio_group_is_loaded(VMContext* ctx, RValue* args, MAYBE_ static RValue builtin_audio_play_music(VMContext* ctx, RValue* args, MAYBE_UNUSED int32_t argCount) { if (ctx->dataWin->gen8.wadVersion >= 14) { - Log_logWarning("VM: [%s] audio_play_music is no-op in WAD version 14+!\n", ctx->currentCodeName); + logWarn("VM: [%s] audio_play_music is no-op in WAD version 14+!\n", ctx->currentCodeName); return RValue_makeUndefined(); } @@ -6593,7 +6593,7 @@ static RValue builtin_audio_play_music(VMContext* ctx, RValue* args, MAYBE_UNUSE static RValue builtin_audio_stop_music(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { if (ctx->dataWin->gen8.wadVersion >= 14) { - Log_logWarning("VM: [%s] audio_stop_music is no-op in WAD version 14+!\n", ctx->currentCodeName); + logWarn("VM: [%s] audio_stop_music is no-op in WAD version 14+!\n", ctx->currentCodeName); return RValue_makeUndefined(); } @@ -7105,7 +7105,7 @@ static RValue builtin_file_text_open_read(VMContext* ctx, RValue* args, int32_t int32_t slot = findFreeTextFileSlot(runner); if (0 > slot) { - Log_logError("Error: Too many open text files!\n"); + logError("Error: Too many open text files!\n"); abort(); } @@ -7135,7 +7135,7 @@ static RValue builtin_file_text_open_write(VMContext* ctx, RValue* args, int32_t int32_t slot = findFreeTextFileSlot(runner); if (0 > slot) { - Log_logError("Error: Too many open text files!\n"); + logError("Error: Too many open text files!\n"); abort(); } @@ -7444,7 +7444,7 @@ static RValue builtin_file_bin_open(VMContext* ctx, RValue* args, int32_t argCou int32_t slot = findFreeBinaryFileSlot(runner); if (0 > slot) { - Log_logWarning("Warning: Too many open binary files!\n"); + logWarn("Warning: Too many open binary files!\n"); return RValue_makeReal(-1.0); } @@ -7826,7 +7826,7 @@ static RValue builtin_window_set_caption(VMContext* ctx, MAYBE_UNUSED RValue* ar runner->windowTitle = safeStrdup(val); if (runner->setWindowTitle) { runner->setWindowTitle(val); - Log_log("Runner: Window title set to: %s\n", val); + logInfo("Runner: Window title set to: %s\n", val); } } @@ -7994,7 +7994,7 @@ static RValue builtin_instance_create(VMContext* ctx, RValue* args, int32_t argC GMLReal y = RValue_toReal(args[1]); int32_t objectIndex = RValue_toInt32(args[2]); if (0 > objectIndex || runner->dataWin->objt.count <= (uint32_t) objectIndex) { - Log_logWarning("VM: instance_create: objectIndex %d out of range\n", objectIndex); + logWarn("VM: instance_create: objectIndex %d out of range\n", objectIndex); return RValue_makeReal(0.0); } Instance* callerInst = ctx->currentInstance; @@ -8010,7 +8010,7 @@ static RValue builtin_instance_copy(VMContext* ctx, RValue* args, int32_t argCou Runner* runner = ctx->runner; Instance* source = ctx->currentInstance; if (source == nullptr) { - Log_logWarning("VM: instance_copy: no current instance\n"); + logWarn("VM: instance_copy: no current instance\n"); return RValue_makeReal(INSTANCE_NOONE); } bool performEvent = argCount > 0 ? RValue_toBool(args[0]) : false; @@ -8068,7 +8068,7 @@ static RValue builtin_instance_create_depth(VMContext* ctx, RValue* args, int32_ int32_t depth = RValue_toInt32(args[2]); int32_t objectIndex = RValue_toInt32(args[3]); if (0 > objectIndex || runner->dataWin->objt.count <= (uint32_t) objectIndex) { - Log_logWarning("VM: instance_create: objectIndex %d out of range\n", objectIndex); + logWarn("VM: instance_create: objectIndex %d out of range\n", objectIndex); return RValue_makeReal(0.0); } Instance* callerInst = ctx->currentInstance; @@ -8091,7 +8091,7 @@ static RValue builtin_instance_change(VMContext* ctx, RValue* args, int32_t argC bool performEvents = RValue_toBool(args[1]); if (0 > objectIndex || (uint32_t) objectIndex >= runner->dataWin->objt.count) { - Log_logWarning("VM: instance_change: objectIndex %d out of range\n", objectIndex); + logWarn("VM: instance_change: objectIndex %d out of range\n", objectIndex); return RValue_makeUndefined(); } @@ -8270,20 +8270,20 @@ static RValue builtin_event_inherited(VMContext* ctx, MAYBE_UNUSED RValue* args, Runner* runner = ctx->runner; Instance* inst = ctx->currentInstance; if (inst == nullptr || 0 > ctx->currentEventObjectIndex || 0 > ctx->currentEventType) { - Log_logWarning("VM: event_inherited called with no event context (inst=%p, eventObjIdx=%d, eventType=%d)\n", (void*) inst, ctx->currentEventObjectIndex, ctx->currentEventType); + logWarn("VM: event_inherited called with no event context (inst=%p, eventObjIdx=%d, eventType=%d)\n", (void*) inst, ctx->currentEventObjectIndex, ctx->currentEventType); return RValue_makeReal(0.0); } DataWin* dataWin = ctx->dataWin; int32_t ownerObjectIndex = ctx->currentEventObjectIndex; if ((uint32_t) ownerObjectIndex >= dataWin->objt.count) { - Log_logWarning("VM: event_inherited ownerObjectIndex %d out of range\n", ownerObjectIndex); + logWarn("VM: event_inherited ownerObjectIndex %d out of range\n", ownerObjectIndex); return RValue_makeReal(0.0); } int32_t parentObjectIndex = dataWin->objt.objects[ownerObjectIndex].parentId; if (ctx->traceEventInherited) { - Log_log("VM: [%s] event_inherited owner=%s(%d) parent=%s(%d) event=%s (instanceId=%d)\n", dataWin->objt.objects[inst->objectIndex].name, dataWin->objt.objects[ownerObjectIndex].name, ownerObjectIndex, (0 > parentObjectIndex) ? "none" : dataWin->objt.objects[parentObjectIndex].name, parentObjectIndex, Runner_getEventName(ctx->currentEventType, ctx->currentEventSubtype), inst->instanceId); + logInfo("VM: [%s] event_inherited owner=%s(%d) parent=%s(%d) event=%s (instanceId=%d)\n", dataWin->objt.objects[inst->objectIndex].name, dataWin->objt.objects[ownerObjectIndex].name, ownerObjectIndex, (0 > parentObjectIndex) ? "none" : dataWin->objt.objects[parentObjectIndex].name, parentObjectIndex, Runner_getEventName(ctx->currentEventType, ctx->currentEventSubtype), inst->instanceId); } if (0 > parentObjectIndex) return RValue_makeReal(0.0); @@ -8332,7 +8332,7 @@ static RValue builtin_action_create_object(VMContext* ctx, RValue* args, int32_t GMLReal x = RValue_toReal(args[1]); GMLReal y = RValue_toReal(args[2]); if (0 > objectIndex || runner->dataWin->objt.count <= (uint32_t) objectIndex) { - Log_logWarning("VM: action_create_object: objectIndex %d out of range\n", objectIndex); + logWarn("VM: action_create_object: objectIndex %d out of range\n", objectIndex); return RValue_makeUndefined(); } Instance* callerInst = ctx->currentInstance; @@ -8855,7 +8855,7 @@ static RValue builtin_buffer_write(MAYBE_UNUSED VMContext* ctx, RValue* args, MA break; } default: - Log_logWarning("buffer_write: unsupported data type %d\n", dataType); + logWarn("buffer_write: unsupported data type %d\n", dataType); break; } @@ -8966,7 +8966,7 @@ static RValue builtin_buffer_read(MAYBE_UNUSED VMContext* ctx, RValue* args, MAY break; } default: - Log_logWarning("buffer_read: unsupported data type %d\n", dataType); + logWarn("buffer_read: unsupported data type %d\n", dataType); break; } @@ -9186,7 +9186,7 @@ static RValue builtin_buffer_save_async(MAYBE_UNUSED VMContext* ctx, RValue* arg static RValue builtin_buffer_async_group_begin(MAYBE_UNUSED VMContext* ctx, RValue* args, MAYBE_UNUSED int32_t argCount) { Runner* runner = ctx->runner; if (runner->asyncBufferGroupActive) { - Log_logWarning("buffer_async_group_begin: a buffer group is already open\n"); + logWarn("buffer_async_group_begin: a buffer group is already open\n"); return RValue_makeUndefined(); } free(runner->asyncBufferGroupName); @@ -9198,7 +9198,7 @@ static RValue builtin_buffer_async_group_begin(MAYBE_UNUSED VMContext* ctx, RVal static RValue builtin_buffer_async_group_end(MAYBE_UNUSED VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { Runner* runner = ctx->runner; if (!runner->asyncBufferGroupActive) { - Log_logWarning("buffer_async_group_end: no matching buffer_async_group_begin\n"); + logWarn("buffer_async_group_end: no matching buffer_async_group_begin\n"); return RValue_makeReal(-1.0); } @@ -10543,7 +10543,7 @@ static RValue builtin_surface_copy_part(VMContext* ctx, RValue* args, MAYBE_UNUS float ys = (float) RValue_toReal(args[5]); float ws = (float) RValue_toReal(args[6]); float hs = (float) RValue_toReal(args[7]); - // Log_log("Set Surface Target Yes\n"); + // logInfo("Set Surface Target Yes\n"); Runner* runner = ctx->runner; if (runner->renderer != nullptr) { runner->renderer->vtable->surfaceCopy(runner->renderer, sourceID, x, y, destinationID, xs, ys, ws, hs, true); @@ -10556,7 +10556,7 @@ static RValue builtin_surface_copy(VMContext* ctx, RValue* args, MAYBE_UNUSED in float x = (float) RValue_toReal(args[1]); float y = (float) RValue_toReal(args[2]); int32_t destinationID = (int32_t) RValue_toReal(args[3]); - // Log_log("Set Surface Target Yes\n"); + // logInfo("Set Surface Target Yes\n"); Runner* runner = ctx->runner; if (runner->renderer != nullptr) { runner->renderer->vtable->surfaceCopy(runner->renderer, sourceID, x, y, destinationID, 0.0, 0.0, 0.0, 0.0, false); @@ -12134,7 +12134,7 @@ static RValue builtin_action_set_alarm(VMContext* ctx, MAYBE_UNUSED RValue* args #ifdef ENABLE_VM_TRACING Runner* runner = ctx->runner; if (shgeti(ctx->alarmsToBeTraced, "*") != -1 || shgeti(ctx->alarmsToBeTraced, runner->dataWin->objt.objects[inst->objectIndex].name) != -1) { - Log_log("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, steps, inst->instanceId); + logInfo("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, steps, inst->instanceId); } #endif @@ -12160,7 +12160,7 @@ static RValue builtin_alarm_set(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE #ifdef ENABLE_VM_TRACING Runner* runner = ctx->runner; if (shgeti(ctx->alarmsToBeTraced, "*") != -1 || shgeti(ctx->alarmsToBeTraced, runner->dataWin->objt.objects[inst->objectIndex].name) != -1) { - Log_log("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, value, inst->instanceId); + logInfo("VM: [%s] Setting Alarm[%d] = %d (instanceId=%d)\n", runner->dataWin->objt.objects[inst->objectIndex].name, alarmIndex, value, inst->instanceId); } #endif @@ -12545,7 +12545,7 @@ static RValue builtin_action_sprite_color(VMContext* ctx, RValue* args, MAYBE_UN // action_message(text) - shows a dialog. static RValue builtin_action_message(MAYBE_UNUSED VMContext* ctx, RValue* args, MAYBE_UNUSED int32_t argCount) { char* text = RValue_toString(args[0]); - Log_log("VM: action_message: %s\n", text); + logInfo("VM: action_message: %s\n", text); free(text); return RValue_makeUndefined(); } @@ -12571,7 +12571,7 @@ static RValue builtin_action_next_room(VMContext* ctx, MAYBE_UNUSED RValue* args if ((int32_t) runner->dataWin->gen8.roomOrderCount > nextPos) { runner->pendingRoom = runner->dataWin->gen8.roomOrder[nextPos]; } else { - Log_logWarning("VM: action_next_room - already at last room!\n"); + logWarn("VM: action_next_room - already at last room!\n"); } return RValue_makeUndefined(); } @@ -12716,7 +12716,7 @@ static RValue builtin_tile_add(VMContext* ctx, RValue* args, MAYBE_UNUSED int32_ int32_t backgroundIndex = RValue_toInt32(args[0]); if (0 > backgroundIndex || backgroundIndex >= (int32_t) ctx->dataWin->bgnd.count) { - Log_logWarning("VM: tile_add: background does not exist (%d)\n", backgroundIndex); + logWarn("VM: tile_add: background does not exist (%d)\n", backgroundIndex); return RValue_makeReal(-1.0); } @@ -12809,7 +12809,7 @@ static RValue builtin_tile_delete(VMContext* ctx, RValue* args, MAYBE_UNUSED int runner->drawableListStructureDirty = true; return RValue_makeUndefined(); } - Log_logWarning("VM: tile_delete: tile does not exist (%u)\n", id); + logWarn("VM: tile_delete: tile does not exist (%u)\n", id); return RValue_makeUndefined(); } @@ -12825,7 +12825,7 @@ static RValue builtin_tile_set_alpha(VMContext* ctx, RValue* args, MAYBE_UNUSED room->tiles[i].alpha = alpha; return RValue_makeUndefined(); } - Log_logWarning("VM: tile_set_alpha: tile does not exist (%u)\n", id); + logWarn("VM: tile_set_alpha: tile does not exist (%u)\n", id); return RValue_makeUndefined(); } @@ -13961,7 +13961,7 @@ static RValue builtin_tilemap_set(VMContext* ctx, RValue* args, MAYBE_UNUSED int uint32_t cell = (uint32_t) RValue_toInt32(args[1]); uint32_t tileIndex = (cell >> 0) & TILEINDEX_SHIFTEDMASK; if (tileset != nullptr && tileset->gms2TileCount != 0 && tileIndex >= tileset->gms2TileCount) { - Log_logWarning("VM: [%s] tilemap_set() - tile index outside tile set count\n", ctx->currentCodeName); + logWarn("VM: [%s] tilemap_set() - tile index outside tile set count\n", ctx->currentCodeName); return RValue_makeBool(false); } @@ -13985,7 +13985,7 @@ static RValue builtin_tilemap_set_at_pixel(VMContext* ctx, RValue* args, MAYBE_U uint32_t cell = (uint32_t) RValue_toInt32(args[1]); uint32_t tileIndex = cell & TILEINDEX_SHIFTEDMASK; if (tileset->gms2TileCount != 0 && tileIndex >= tileset->gms2TileCount) { - Log_logWarning("VM: [%s] tilemap_set_at_pixel() - tile index outside tile set count\n", ctx->currentCodeName); + logWarn("VM: [%s] tilemap_set_at_pixel() - tile index outside tile set count\n", ctx->currentCodeName); return RValue_makeBool(false); } @@ -14138,7 +14138,7 @@ static RValue builtin_SetStatic(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE // We reuse Instance (with objectIndex = STRUCT_OBJECT_INDEX) the same way globalScopeInstance is used for GLOB scripts, instead of introducing a separate struct type. static RValue builtin_NewGMLObject(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - Log_logWarning("VM: @@NewGMLObject@@ called with no arguments\n"); + logWarn("VM: @@NewGMLObject@@ called with no arguments\n"); return RValue_makeUndefined(); } @@ -14160,7 +14160,7 @@ static RValue builtin_NewGMLObject(VMContext* ctx, RValue* args, int32_t argCoun } } if (0 > codeIndex || (uint32_t) codeIndex > ctx->dataWin->code.count) { - Log_logWarning("VM: @@NewGMLObject@@ method has invalid codeIndex %d\n", codeIndex); + logWarn("VM: @@NewGMLObject@@ method has invalid codeIndex %d\n", codeIndex); return RValue_makeUndefined(); } @@ -14220,7 +14220,7 @@ static RValue builtin_try_hook(VMContext* ctx, RValue* args, int32_t argCount) { exceptionStackHandler->stackTop = ctx->stack.top; #ifdef ENABLE_VM_EXCEPTIONS_LOGS - Log_log("VM: Configured exception handler for jump on exception: %d, jump on success: %d\n", jumpToOnException, jumpToOnSuccess); + logInfo("VM: Configured exception handler for jump on exception: %d, jump on success: %d\n", jumpToOnException, jumpToOnSuccess); #endif return RValue_makeUndefined(); @@ -15271,7 +15271,7 @@ static RValue jsonDecodeValue(VMContext* ctx, JsonValue* json) { static RValue builtin_json_decode(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - Log_logWarning("[json_decode] Expected at least 1 argument\n"); + logWarn("[json_decode] Expected at least 1 argument\n"); return RValue_makeUndefined(); } @@ -15336,7 +15336,7 @@ static RValue builtin_object_get_solid(VMContext* ctx, RValue* args, int32_t arg static RValue builtin_object_get_sprite(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - Log_logWarning("[object_get_sprite] Expected at least 1 argument\n"); + logWarn("[object_get_sprite] Expected at least 1 argument\n"); return RValue_makeUndefined(); } @@ -15476,7 +15476,7 @@ static RValue fontAddSpriteImpl(VMContext* ctx, int32_t spriteIndex, uint16_t* c DataWin* dw = ctx->dataWin; if (0 > spriteIndex || (uint32_t) spriteIndex >= dw->sprt.count) { - Log_logWarning("[font_add_sprite] Invalid sprite index %d\n", spriteIndex); + logWarn("[font_add_sprite] Invalid sprite index %d\n", spriteIndex); return RValue_makeReal(-1.0); } @@ -15596,7 +15596,7 @@ static RValue fontAddSpriteImpl(VMContext* ctx, int32_t spriteIndex, uint16_t* c static RValue builtin_font_get_name(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - Log_logWarning("[font_get_name] Expected 1 argument, got 0"); + logWarn("[font_get_name] Expected 1 argument, got 0"); return RValue_makeUndefined(); } @@ -15647,7 +15647,7 @@ static RValue builtin_font_get_info(VMContext* ctx, RValue* args, int32_t argCou // font_add_sprite_ext(sprite, string_map, prop, sep) static RValue builtin_font_add_sprite_ext(VMContext* ctx, RValue* args, int32_t argCount) { if (4 > argCount) { - Log_logWarning("[font_add_sprite_ext] Expected 4 arguments, got %d\n", argCount); + logWarn("[font_add_sprite_ext] Expected 4 arguments, got %d\n", argCount); return RValue_makeReal(-1.0); } @@ -15672,7 +15672,7 @@ static RValue builtin_font_add_sprite_ext(VMContext* ctx, RValue* args, int32_t // font_add_sprite(sprite, first, prop, sep) static RValue builtin_font_add_sprite(VMContext* ctx, RValue* args, int32_t argCount) { if (4 > argCount) { - Log_logWarning("[font_add_sprite] Expected 4 arguments, got %d\n", argCount); + logWarn("[font_add_sprite] Expected 4 arguments, got %d\n", argCount); return RValue_makeReal(-1.0); } @@ -15699,7 +15699,7 @@ static RValue builtin_font_add_sprite(VMContext* ctx, RValue* args, int32_t argC static RValue builtin_asset_get_index(VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) { - Log_logWarning("[asset_get_index] Expected at least 1 argument\n"); + logWarn("[asset_get_index] Expected at least 1 argument\n"); return RValue_makeUndefined(); } @@ -15863,7 +15863,7 @@ static RValue builtin_parameter_string(VMContext* ctx, RValue* args, int32_t arg static RValue builtin_shader_set(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { int32_t ShaderID = (int32_t) RValue_toReal(args[0]); - // Log_log("Set Shader ID %u\n", ShaderID); + // logInfo("Set Shader ID %u\n", ShaderID); // gpuSetShader ctx->runner->renderer->vtable->gpuSetShader(ctx->runner->renderer, ShaderID); return RValue_makeUndefined(); @@ -15920,7 +15920,7 @@ static RValue builtin_texture_set_stage(VMContext* ctx, MAYBE_UNUSED RValue* arg static RValue builtin_shader_set_uniformF(VMContext* ctx, MAYBE_UNUSED RValue* args, MAYBE_UNUSED int32_t argCount) { int32_t handle = (int32_t) RValue_toReal(args[0]); float value1, value2, value3, value4; - // Log_log("Set ARG Count %u\n", argCount); + // logInfo("Set ARG Count %u\n", argCount); if (argCount == 2) { value1 = (float) RValue_toReal(args[1]); ctx->runner->renderer->vtable->shaderSetUniformF(ctx->runner->renderer, handle, 1, value1, 0.0, 0.0, 0.0); @@ -15938,7 +15938,7 @@ static RValue builtin_shader_set_uniformF(VMContext* ctx, MAYBE_UNUSED RValue* a value2 = (float) RValue_toReal(args[2]); value3 = (float) RValue_toReal(args[3]); value4 = (float) RValue_toReal(args[4]); - // Log_log("Value4 %.8f\n", value4); + // logInfo("Value4 %.8f\n", value4); ctx->runner->renderer->vtable->shaderSetUniformF(ctx->runner->renderer, handle, 4, value1, value2, value3, value4); } return RValue_makeUndefined(); diff --git a/src/web/main.c b/src/web/main.c index 9882f0f7d..befd957e8 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -55,7 +55,7 @@ int getKeyCount() { int main() { Log_setOptions(true, false, true, false, nullptr); Log_init(); - Log_log("Howdy! Loritta is so cute! lol\n"); + logInfo("Howdy! Loritta is so cute! lol\n"); emscripten_exit_with_live_runtime(); return 0; } @@ -64,12 +64,12 @@ int main() { int mountOpfs(void) { backend_t opfs = wasmfs_create_opfs_backend(); if (!opfs) { - Log_logWarning("Failed to create OPFS backend\n"); + logWarn("Failed to create OPFS backend\n"); return -1; } int rc = wasmfs_create_directory("/butterscotch", 0777, opfs); if (rc != 0) { - Log_logWarning("Failed to mount OPFS at /butterscotch: %s\n", strerror(errno)); + logWarn("Failed to mount OPFS at /butterscotch: %s\n", strerror(errno)); return -1; } return 0; @@ -165,7 +165,7 @@ void* loop() { } // Cleanup - Log_log("Cleaning up runner!\n"); + logInfo("Cleaning up runner!\n"); gRunner->audioSystem->vtable->destroy(gRunner->audioSystem); gRunner->audioSystem = nullptr; @@ -191,7 +191,7 @@ void setWindowTitle(const char* title) { // gamePath: WASMFS path to the data.win to load (example: "/butterscotch/games/undertale/data.win"). // savesPath: WASMFS directory where saves should live (example: "/butterscotch/saves/undertale" - Created if it does not exist). void startRunner(const char* gamePath, const char* savesPath) { - Log_log("Starting runner! gamePath=%s savesPath=%s\n", gamePath, savesPath); + logInfo("Starting runner! gamePath=%s savesPath=%s\n", gamePath, savesPath); EmscriptenWebGLContextAttributes attrs; emscripten_webgl_init_context_attributes(&attrs); @@ -208,7 +208,7 @@ void startRunner(const char* gamePath, const char* savesPath) { // But that's how Emscripten works for SOME REASON ctx = emscripten_webgl_create_context("#canvas", &attrs); if (0 >= ctx) { - Log_logError("Failed to create WebGL context: %d\n", (int)ctx); + logError("Failed to create WebGL context: %d\n", (int)ctx); abort(); } @@ -220,7 +220,7 @@ void startRunner(const char* gamePath, const char* savesPath) { // Make sure the saves directory exists. The FileSystem impl will write into it. if (savesPath != nullptr && savesPath[0] != '\0') { if (mkdirP(savesPath) != 0) { - Log_logWarning("Warning: failed to ensure saves dir exists at %s: %s\n", savesPath, strerror(errno)); + logWarn("Warning: failed to ensure saves dir exists at %s: %s\n", savesPath, strerror(errno)); } } @@ -297,6 +297,6 @@ void startRunner(const char* gamePath, const char* savesPath) { } void stopRunner() { - Log_log("Marked runner to exit!\n"); + logInfo("Marked runner to exit!\n"); gRunner->shouldExit = true; } From 6aeda60bfe10ec3f51191e743d514b57dc287553 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 14:06:23 +0800 Subject: [PATCH 37/57] Add warning and error prefixes as well --- src/desktop/backends/sdl1.c | 2 +- src/desktop/backends/sdl2.c | 2 +- src/desktop/backends/sdl3.c | 2 +- src/desktop/main.c | 42 ++++++++++++++++++------------------- src/input_recording.c | 6 +++--- src/log.c | 4 ++-- src/ps2/main.c | 10 ++++----- src/runner.c | 6 +++--- src/vm_builtins.c | 6 +++--- src/web/main.c | 2 +- 10 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/desktop/backends/sdl1.c b/src/desktop/backends/sdl1.c index 0eccb4ba4..fd57c8851 100644 --- a/src/desktop/backends/sdl1.c +++ b/src/desktop/backends/sdl1.c @@ -271,7 +271,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) if (!scr && gfx == SOFTWARE) { SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN); if (modes && modes != (SDL_Rect**) -1 && modes[0]) { - logWarn("Warning: %dx%d unavailable, falling back to %dx%d: %s\n", + logWarn("%dx%d unavailable, falling back to %dx%d: %s\n", reqW, reqH, modes[0]->w, modes[0]->h, SDL_GetError()); scr = SDL_SetVideoMode(modes[0]->w, modes[0]->h, 0, 0); fbWidth = modes[0]->w; diff --git a/src/desktop/backends/sdl2.c b/src/desktop/backends/sdl2.c index 3d3b1511c..baacf199e 100644 --- a/src/desktop/backends/sdl2.c +++ b/src/desktop/backends/sdl2.c @@ -194,7 +194,7 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { if (!window && gfx == SOFTWARE) { SDL_DisplayMode mode; if (SDL_GetDisplayMode(0, 0, &mode) == 0) { - logWarn("Warning: %dx%d unavailable, falling back to %dx%d: %s\n", + logWarn("%dx%d unavailable, falling back to %dx%d: %s\n", reqW, reqH, mode.w, mode.h, SDL_GetError()); reqW = mode.w; reqH = mode.h; diff --git a/src/desktop/backends/sdl3.c b/src/desktop/backends/sdl3.c index 217e7c802..19a99914e 100644 --- a/src/desktop/backends/sdl3.c +++ b/src/desktop/backends/sdl3.c @@ -172,7 +172,7 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) { const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay()); if (mode != NULL) { SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "Warning: %dx%d unavailable, falling back to %dx%d: %s", + "%dx%d unavailable, falling back to %dx%d: %s", fbWidth, fbHeight, mode->w, mode->h, SDL_GetError()); fbWidth = mode->w; diff --git a/src/desktop/main.c b/src/desktop/main.c index ed86aae92..c903ff842 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -548,7 +548,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - logError("Error: Invalid frame number '%s'\n", optarg); + logError("Invalid frame number '%s'\n", optarg); exit(1); } @@ -562,7 +562,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - logError("Error: Invalid frame number '%s' for --screenshot-surfaces-at-frame\n", optarg); + logError("Invalid frame number '%s' for --screenshot-surfaces-at-frame\n", optarg); exit(1); } hmput(args->screenshotSurfacesFrames, frame, true); @@ -630,7 +630,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - logError("Error: Invalid frame number '%s' for --exit-at-frame\n", optarg); + logError("Invalid frame number '%s' for --exit-at-frame\n", optarg); exit(1); } args->exitAtFrame = frame; @@ -640,7 +640,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - logError("Error: Invalid frame number '%s' for --trace-bytecode-after-frame\n", optarg); + logError("Invalid frame number '%s' for --trace-bytecode-after-frame\n", optarg); exit(1); } args->traceBytecodeAfterFrame = frame; @@ -650,7 +650,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - logError("Error: Invalid frame number '%s' for --dump-frame\n", optarg); + logError("Invalid frame number '%s' for --dump-frame\n", optarg); exit(1); } hmput(args->dumpFrames, frame, true); @@ -660,7 +660,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int frame = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || 0 > frame) { - logError("Error: Invalid frame number '%s' for --dump-frame-json\n", optarg); + logError("Invalid frame number '%s' for --dump-frame-json\n", optarg); exit(1); } hmput(args->dumpJsonFrames, frame, true); @@ -673,7 +673,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; double speed = strtod(optarg, &endPtr); if (*endPtr != '\0' || speed <= 0.0) { - logError("Error: Invalid speed multiplier '%s' for --speed (must be > 0)\n", optarg); + logError("Invalid speed multiplier '%s' for --speed (must be > 0)\n", optarg); exit(1); } args->speedMultiplier = speed; @@ -683,7 +683,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; double speed = strtod(optarg, &endPtr); if (*endPtr != '\0' || speed <= 0.0) { - logError("Error: Invalid speed '%s' for --fast-forward-speed (must be > 0)\n", optarg); + logError("Invalid speed '%s' for --fast-forward-speed (must be > 0)\n", optarg); exit(1); } args->fastForwardSpeed = speed; @@ -714,7 +714,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int seedVal = strtol(optarg, &endPtr, 10); if (*endPtr != '\0') { - logError("Error: Invalid seed value '%s' for --seed\n", optarg); + logError("Invalid seed value '%s' for --seed\n", optarg); exit(1); } args->seed = seedVal; @@ -731,7 +731,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) char* endPtr; int framesBetween = strtol(optarg, &endPtr, 10); if (*endPtr != '\0' || framesBetween <= 0) { - logError("Error: Invalid frame count '%s' for --profile-gml-scripts (must be > 0)\n", optarg); + logError("Invalid frame count '%s' for --profile-gml-scripts (must be > 0)\n", optarg); exit(1); } args->profilerFramesBetween = framesBetween; @@ -755,7 +755,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) #endif case 'O': if (!parseOsTypeArg(optarg, &args->osType)) { - logError("Error: Invalid --os-type value '%s' (expected: ", optarg); + logError("Invalid --os-type value '%s' (expected: ", optarg); printOsTypeNames(stderr); logError(")\n"); exit(1); @@ -764,7 +764,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) case 'w': { int32_t w = 0, h = 0; if (sscanf(optarg, "%dx%d", &w, &h) != 2 || 0 >= w || 0 >= h) { - logError("Error: Invalid --window-size value '%s' (expected WxH, e.g. 960x544)\n", optarg); + logError("Invalid --window-size value '%s' (expected WxH, e.g. 960x544)\n", optarg); exit(1); } args->windowWidth = w; @@ -779,7 +779,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } else if (strcmp(optarg, "load-per-chunk") == 0) { args->loadType = DATAWINLOADTYPE_LOAD_PER_CHUNK; } else { - logError("Error: Unknown load type '%s'\n", optarg); + logError("Unknown load type '%s'\n", optarg); exit(1); } break; @@ -797,7 +797,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } else if ((ratio = strtod(optarg, &endPtr)), *endPtr == '\0' && ratio > 0.0) { args->widescreenAspect = (float) ratio; } else { - logError("Error: Invalid --widescreen-hack value '%s' (expected W:H like 16:9, or a decimal like 1.7778)\n", optarg); + logError("Invalid --widescreen-hack value '%s' (expected W:H like 16:9, or a decimal like 1.7778)\n", optarg); exit(1); } break; @@ -824,19 +824,19 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) } if (optind >= argc) { - logError("Usage: %s \n", argv[0]); + printUsage(argv[0]); exit(1); } args->dataWinPath = argv[optind]; if (hmlen(args->screenshotFrames) > 0 && args->screenshotPattern == nullptr) { - logError("Error: --screenshot-at-frame requires --screenshot to be set\n"); + logError("--screenshot-at-frame requires --screenshot to be set\n"); exit(1); } if (hmlen(args->screenshotSurfacesFrames) > 0 && args->screenshotSurfacesPattern == nullptr) { - logError("Error: --screenshot-surfaces-at-frame requires --screenshot-surfaces to be set\n"); + logError("--screenshot-surfaces-at-frame requires --screenshot-surfaces to be set\n"); exit(1); } @@ -877,7 +877,7 @@ static void writeFramebufferAsPng(GLuint fbo, int width, int height, const char* int stride = width * 4; unsigned char* pixels = (unsigned char *)safeMalloc(stride * height); if (pixels == nullptr) { - logWarn("Warning: Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height); + logWarn("Failed to allocate memory for %s (%dx%d)\n", logPrefix, width, height); return; } @@ -1287,7 +1287,7 @@ int main(int argc, char* argv[]) { if (idx >= 0) { VM_disassemble(vm, vm->codeIndexByName[idx].value); } else { - logWarn("Warning: Script '%s' not found in funcMap\n", name); + logWarn("Script '%s' not found in funcMap\n", name); } } } @@ -1603,7 +1603,7 @@ int main(int argc, char* argv[]) { fclose(f); logInfo("JSON dump saved: %s\n", filename); } else { - logWarn("Warning: Could not write JSON dump to '%s'\n", filename); + logWarn("Could not write JSON dump to '%s'\n", filename); } } else { logInfo("%s\n", json); @@ -1711,7 +1711,7 @@ int main(int argc, char* argv[]) { fclose(f); logInfo("JSON dump saved: %s\n", filename); } else { - logWarn("Warning: Could not write JSON dump to '%s'\n", filename); + logWarn("Could not write JSON dump to '%s'\n", filename); } } else { logInfo("%s\n", json); diff --git a/src/input_recording.c b/src/input_recording.c index 1feacb484..32bbdf2d7 100644 --- a/src/input_recording.c +++ b/src/input_recording.c @@ -21,7 +21,7 @@ InputRecording* InputRecording_createPlayer(const char* playbackFilePath, const // Read the file contents FILE* f = fopen(playbackFilePath, "rb"); if (f == nullptr) { - logError("Error: Could not open input recording file '%s'\n", playbackFilePath); + logError("Could not open input recording file '%s'\n", playbackFilePath); exit(1); } @@ -39,7 +39,7 @@ InputRecording* InputRecording_createPlayer(const char* playbackFilePath, const free(contents); if (root == nullptr || !JsonReader_isObject(root)) { - logError("Error: Invalid JSON in input recording file '%s'\n", playbackFilePath); + logError("Invalid JSON in input recording file '%s'\n", playbackFilePath); exit(1); } @@ -214,7 +214,7 @@ bool InputRecording_save(InputRecording* recording) { FILE* f = fopen(recording->recordFilePath, "wb"); if (f == nullptr) { - logWarn("Warning: Could not write input recording to '%s'\n", recording->recordFilePath); + logWarn("Could not write input recording to '%s'\n", recording->recordFilePath); JsonWriter_free(&w); return false; } diff --git a/src/log.c b/src/log.c index bab65c1d2..ad33c426b 100644 --- a/src/log.c +++ b/src/log.c @@ -42,8 +42,8 @@ static void vLogInternal(FILE* file, bool logColour, const int type, const char* fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : (type == LOG_TYPE_ERROR ? ANSI_COLOUR_CODE_BOLD_RED : ANSI_COLOUR_CODE_BOLD_PURPLE)))); } - if (type == LOG_TYPE_DEBUG) { - fprintf(file, "Debug: "); + if (type != LOG_TYPE_NORMAL) { + fprintf(file, (type == LOG_TYPE_WARNING ? "Warning: " : (type == LOG_TYPE_ERROR ? "Error: " : "Debug: "))); } vfprintf(file, fmt, va); diff --git a/src/ps2/main.c b/src/ps2/main.c index 994d627a2..6d24f753d 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -323,19 +323,19 @@ int main(int argc, char* argv[]) { padInit(0); padOpened[0] = (padPortOpen(0, 0, padBuf[0]) != 0); padOpened[1] = (padPortOpen(1, 0, padBuf[1]) != 0); - if (!padOpened[0]) logWarn("Warning: failed to open pad port 0\n"); - if (!padOpened[1]) logWarn("Warning: failed to open pad port 1\n"); + if (!padOpened[0]) logWarn("failed to open pad port 0\n"); + if (!padOpened[1]) logWarn("failed to open pad port 1\n"); // ===[ Load USB Keyboard IOP Modules ]=== int usbdRet = SifExecModuleBuffer(usbd_irx, size_usbd_irx, 0, nullptr, nullptr); if (0 > usbdRet) { - logWarn("Warning: failed to load usbd: %d (keyboard disabled)\n", usbdRet); + logWarn("failed to load usbd: %d (keyboard disabled)\n", usbdRet); } else { int kbdRet = SifExecModuleBuffer(ps2kbd_irx, size_ps2kbd_irx, 0, nullptr, nullptr); if (0 > kbdRet) { - logWarn("Warning: failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); + logWarn("failed to load ps2kbd: %d (keyboard disabled)\n", kbdRet); } else if (PS2KbdInit() == 0) { - logWarn("Warning: PS2KbdInit failed (keyboard disabled)\n"); + logWarn("PS2KbdInit failed (keyboard disabled)\n"); } else { PS2KbdSetReadmode(PS2KBD_READMODE_RAW); PS2KbdSetBlockingMode(PS2KBD_NONBLOCKING); diff --git a/src/runner.c b/src/runner.c index ca88116c0..4cd0d2170 100644 --- a/src/runner.c +++ b/src/runner.c @@ -687,7 +687,7 @@ void Runner_drawTileLayer(Runner* runner, RoomLayerTilesData* data, float layerO bool rotate = (cell & GMS2_TILE_ROTATE_MASK) != 0; if (rotate && !rotateWarned) { - logWarn("Runner: WARNING: GMS2 tile layer has rotated tiles; rotation not yet implemented, drawing unrotated\n"); + logWarn("Runner: GMS2 tile layer has rotated tiles; rotation not yet implemented, drawing unrotated\n"); rotateWarned = true; } @@ -885,7 +885,7 @@ void Runner_draw(Runner* runner) { // Warn if tile source rect exceeds TPAG content bounds if ((uint32_t) (tile->sourceX + tile->width) > (uint32_t) tpag->sourceWidth || (uint32_t) (tile->sourceY + tile->height) > (uint32_t) tpag->sourceHeight) { - logWarn("Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); + logWarn("Runner: [%s] Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); } } else { logInfo("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); @@ -987,7 +987,7 @@ void Runner_draw(Runner* runner) { // Warn if tile source rect exceeds TPAG content bounds if ((uint32_t) (tile->sourceX + tile->width) > (uint32_t) tpag->sourceWidth || (uint32_t) (tile->sourceY + tile->height) > (uint32_t) tpag->sourceHeight) { - logWarn("Runner: [%s] WARNING: Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); + logWarn("Runner: [%s] Tile #%d source rect (%d,%d %ux%u) exceeds TPAG content bounds (%dx%d)\n", roomName, d->tileIndex, tile->sourceX, tile->sourceY, tile->width, tile->height, tpag->sourceWidth, tpag->sourceHeight); } } else { logInfo("Runner: [%s] Drawing tile #%d bg=%s(%d) tpag=UNRESOLVED tile(srcX=%d srcY=%d w=%u h=%u) at pos=(%d,%d) depth=%d\n", roomName, d->tileIndex, bgName, tile->backgroundDefinition, tile->sourceX, tile->sourceY, tile->width, tile->height, tile->x, tile->y, tile->tileDepth); diff --git a/src/vm_builtins.c b/src/vm_builtins.c index 678413c51..9e936e436 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -7105,7 +7105,7 @@ static RValue builtin_file_text_open_read(VMContext* ctx, RValue* args, int32_t int32_t slot = findFreeTextFileSlot(runner); if (0 > slot) { - logError("Error: Too many open text files!\n"); + logError("Too many open text files!\n"); abort(); } @@ -7135,7 +7135,7 @@ static RValue builtin_file_text_open_write(VMContext* ctx, RValue* args, int32_t int32_t slot = findFreeTextFileSlot(runner); if (0 > slot) { - logError("Error: Too many open text files!\n"); + logError("Too many open text files!\n"); abort(); } @@ -7444,7 +7444,7 @@ static RValue builtin_file_bin_open(VMContext* ctx, RValue* args, int32_t argCou int32_t slot = findFreeBinaryFileSlot(runner); if (0 > slot) { - logWarn("Warning: Too many open binary files!\n"); + logWarn("Too many open binary files!\n"); return RValue_makeReal(-1.0); } diff --git a/src/web/main.c b/src/web/main.c index befd957e8..ec1684c2b 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -220,7 +220,7 @@ void startRunner(const char* gamePath, const char* savesPath) { // Make sure the saves directory exists. The FileSystem impl will write into it. if (savesPath != nullptr && savesPath[0] != '\0') { if (mkdirP(savesPath) != 0) { - logWarn("Warning: failed to ensure saves dir exists at %s: %s\n", savesPath, strerror(errno)); + logWarn("failed to ensure saves dir exists at %s: %s\n", savesPath, strerror(errno)); } } From a0a667fe1cc6f521a41febf585bbd8c64cec817c Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 14:39:02 +0800 Subject: [PATCH 38/57] Use isatty --- src/log.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/log.c b/src/log.c index ad33c426b..62b964bc7 100644 --- a/src/log.c +++ b/src/log.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "common.h" @@ -37,7 +38,9 @@ enum { #define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" #define ANSI_COLOUR_CODE_BOLD_PURPLE "\x1b[1;35m" -static void vLogInternal(FILE* file, bool logColour, const int type, const char* fmt, va_list va) { +static void vLogInternal(FILE* file, const int type, const char* fmt, va_list va) { + const bool logColour = isatty(fileno(file)) ? logColourTerminal : logColourFile; + if (logColour) { fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : (type == LOG_TYPE_ERROR ? ANSI_COLOUR_CODE_BOLD_RED : ANSI_COLOUR_CODE_BOLD_PURPLE)))); } From a7eb85bd03e6e983fe1e1ad0a86a2bfe890e7679 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 15:35:47 +0800 Subject: [PATCH 39/57] Do what uniq said i think --- src/android/main.c | 8 ++ src/desktop/main.c | 24 ++++- src/log.c | 255 +++++++++++++++------------------------------ src/log.h | 21 ++-- src/ps2/main.c | 6 ++ src/ps3/main.c | 6 ++ src/web/main.c | 6 ++ 7 files changed, 143 insertions(+), 183 deletions(-) diff --git a/src/android/main.c b/src/android/main.c index 11de88812..6bb6f6cbf 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -16,6 +16,8 @@ #include "gl/gl_renderer.h" #include "stb_ds.h" +#include "log.h" + #define LOG_TAG "Butterscotch" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) @@ -40,6 +42,12 @@ static float gNormalizedCursorY = 0.0f; // We don't need to worry about game changes because the profiler will be automatically disabled then static int32_t gProfilerStartedAtFrame = 0; +void platformLog(const logType type, const logOutType out, const char *format, va_list va) { + if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { + __android_log_print(type == LOG_TYPE_NORMAL ? ANDROID_LOG_INFO : (type == LOG_TYPE_WARNING ? ANDROID_LOG_WARN : ANDROID_LOG_ERROR), LOG_TAG, format, va); + } +} + // Android has no platformGetWindowSize like the desktop, so we cache the EGL surface size the host // passes into stepAndDraw and expose it through the getWindowSize hook below. static int32_t gWindowW = 0; diff --git a/src/desktop/main.c b/src/desktop/main.c index c903ff842..0764b2437 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -55,6 +55,8 @@ #include "profiler.h" #include "gettime.h" +FILE* logFileHandle = nullptr; + /* For SDL_main */ #if defined(USE_SDL1) #include @@ -302,11 +304,25 @@ static bool parseOsTypeArg(const char* s, YoYoOperatingSystem* out) { } static void printOsTypeNames(FILE* out) { - bool addFileSucceeded = Log_addFile(out); forEachIndexed(const OsTypeNameEntry, entry, i, OS_TYPE_NAMES, OS_TYPE_NAMES_COUNT) { - logInfoToFile("%s%s", i > 0 ? ", " : "", entry->name); + fprintf(out, "%s%s", i > 0 ? ", " : "", entry->name); } - if (addFileSucceeded) Log_removeFile(out); +} + +void platformLog(const logType type, const logOutType out, const char *format, va_list va) { + if (out == LOG_OUT_ALL) { + va_list va2; + va_copy(va2, va); + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + vfprintf(logFileHandle, format, va2); + va_end(va2); + } + else if (out == LOG_OUT_TERMINAL) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + } + else { // LOG_OUT_FILE + vfprintf(logFileHandle, format, va); + } } // Resolves the window size for the specified operating system. @@ -1039,7 +1055,7 @@ int main(int argc, char* argv[]) { Log_setOptions(!args.disableTerminalLog, !args.disableFileLog, !args.disableTerminalLogColours, args.enableFileLogColours, args.logFile ? args.logFile : "./butterscotch.log"); - Log_init(); + logFileHandle = Log_init(); char* currentDataWinPath = safeStrdup(args.dataWinPath); char** currentGameArgs = args.gameArgs; diff --git a/src/log.c b/src/log.c index 62b964bc7..e3deda221 100644 --- a/src/log.c +++ b/src/log.c @@ -6,7 +6,7 @@ #include #include -#include "common.h" +#include "utils.h" static bool logToTerminal = true; static bool logToFile = true; @@ -15,19 +15,6 @@ static bool logColourTerminal = true; static bool logColourFile = false; static const char* logFile = "./butterscotch.log"; -static const char* logFileBackup = "./butterscotch.log"; - -static FILE* logFileHandleBackup = nullptr; -static FILE* logFileHandle = nullptr; - -static FILE* logFiles[LOG_MAX_FILES]; - -enum { - LOG_TYPE_NORMAL=0, - LOG_TYPE_WARNING=1, - LOG_TYPE_ERROR=2, - LOG_TYPE_DEBUG=3 -}; #ifndef va_copy #define va_copy(d, s) ((d) = (s)) @@ -38,56 +25,98 @@ enum { #define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" #define ANSI_COLOUR_CODE_BOLD_PURPLE "\x1b[1;35m" -static void vLogInternal(FILE* file, const int type, const char* fmt, va_list va) { - const bool logColour = isatty(fileno(file)) ? logColourTerminal : logColourFile; - - if (logColour) { - fprintf(file, (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : (type == LOG_TYPE_ERROR ? ANSI_COLOUR_CODE_BOLD_RED : ANSI_COLOUR_CODE_BOLD_PURPLE)))); +// In the platform main.c +void platformLog(const logType type, const logOutType out, const char *format, va_list va); +// Example impl: +// void platformLog(const logType type, const logOutType out, const char *format, va_list va) { +// if (out == LOG_OUT_ALL) { +// va_list va2; +// va_copy(va2, va); +// vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); +// vfprintf(logFileHandle, format, va2); +// va_end(va2); +// } +// else if (out == LOG_OUT_TERMINAL) { +// vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); +// } +// else { // LOG_OUT_FILE +// vfprintf(logFileHandle, format, va); +// } +// } + +static void vLogInternal(const logType type, const logOutType out, const char* fmt, va_list va) { + // TODO: Seperate logColour less hackily + if (out == LOG_OUT_ALL) { + va_list va2; + va_copy(va2, va); + vLogInternal(type, LOG_OUT_TERMINAL, fmt, va); + vLogInternal(type, LOG_OUT_FILE, fmt, va2); + va_end(va2); + return; } - if (type != LOG_TYPE_NORMAL) { - fprintf(file, (type == LOG_TYPE_WARNING ? "Warning: " : (type == LOG_TYPE_ERROR ? "Error: " : "Debug: "))); + const bool logColour = out == LOG_OUT_TERMINAL ? logColourTerminal : logColourFile; + + const char* prefix = ""; + if (type == LOG_TYPE_WARNING) { + prefix = "Warning: "; + } + else if (type == LOG_TYPE_ERROR) { + prefix = "Error: "; + } + else if (type == LOG_TYPE_DEBUG) { + prefix = "Debug: "; } - vfprintf(file, fmt, va); + const char* colourPrefix = ""; + const char* colourPostfix = ""; - if (logColour) { - fprintf(file, ANSI_COLOUR_CODE_WHITE); + if(logColour) { + colourPrefix = (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : (type == LOG_TYPE_ERROR ? ANSI_COLOUR_CODE_BOLD_RED : ANSI_COLOUR_CODE_BOLD_PURPLE))); + colourPostfix = ANSI_COLOUR_CODE_WHITE; } + + size_t newFmtSize = strlen(colourPrefix) + strlen(prefix) + strlen(fmt) + strlen(colourPostfix) + 1; + + char* newFmt = safeMalloc(newFmtSize); + + snprintf(newFmt, newFmtSize, "%s%s%s%s", colourPrefix, prefix, fmt, colourPostfix); + + newFmt[newFmtSize-1] = '\0'; + + platformLog(type, out, newFmt, va); + + free(newFmt); } static void vLogToTerminal(const int type, const char* fmt, va_list va) { if (!logToTerminal) return; - vLogInternal(type == LOG_TYPE_NORMAL ? stdout : stderr, logColourTerminal, type, fmt, va); + vLogInternal(type, LOG_OUT_TERMINAL, fmt, va); } static void vLogToFile(const int type, const char* fmt, va_list va) { - if (!logToFile || !logFileHandle) return; + if (!logToFile) return; - vLogInternal(logFileHandle, logColourFile, type, fmt, va); + vLogInternal(type, LOG_OUT_FILE, fmt, va); +} - for (int i=0; i < LOG_MAX_FILES; i++) { - if (!logFiles[i]) continue; - vLogInternal(logFiles[i], logColourFile, type, fmt, va); - } +static void vLog(const int type, const char* fmt, va_list va) { + if (!logToTerminal && !logToFile) return; + + vLogInternal(type, LOG_OUT_ALL, fmt, va); } -void Log_init() { - memset(logFiles, 0, sizeof(logFiles)); +FILE* Log_init() { + if (logFile == nullptr) return nullptr; + FILE* logFileHandle = fopen(logFile, "w"); if (logFileHandle != nullptr) { - fclose(logFileHandle); + setvbuf(logFileHandle, nullptr, _IONBF, 0); + return logFileHandle; } - if (logFile != nullptr) { - logFileHandle = fopen(logFile, "w"); - if (logFileHandle != nullptr) { - setvbuf(logFileHandle, nullptr, _IONBF, 0); - logFileHandleBackup = logFileHandle; - logFileBackup = logFile; - } - } + return nullptr; } void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, const char* pLogFile) { @@ -100,48 +129,6 @@ void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTermina } } -void Log_setFile(FILE* file, const char* path) { - logFileHandle = file; - logFile = path; -} - -void Log_resetFile() { - logFileHandle = logFileHandleBackup; - logFile = logFileBackup; -} - -bool Log_addFile(FILE* file) { - if (file == nullptr) return false; - - int availableSlot = -1; - for (int i=0; i < LOG_MAX_FILES; i++) { - if (logFiles[i] == file) { - return true; - } - if (logFiles[i] == nullptr) { - availableSlot = i; - } - } - - if (availableSlot == -1) return false; - - logFiles[availableSlot] = file; - return true; -} - -bool Log_removeFile(FILE* file) { - if (file == nullptr) return false; - - for (int i=0; i < LOG_MAX_FILES; i++) { - if (logFiles[i] == file) { - logFiles[i] = nullptr; - return true; - } - } - - return false; -} - void logInfoToTerminal(const char* fmt, ...) { va_list va; @@ -159,20 +146,11 @@ void logInfoToFile(const char* fmt, ...) { } void logInfo(const char* fmt, ...) { - va_list va, va2; + va_list va; va_start(va, fmt); - va_copy(va2, va); - - if (logToTerminal) { - vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); - } - if (logToFile) { - vLogToFile(LOG_TYPE_NORMAL, fmt, va2); - } - + vLog(LOG_TYPE_NORMAL, fmt, va); va_end(va); - va_end(va2); } void vLogInfoToTerminal(const char* fmt, va_list va) { @@ -184,17 +162,7 @@ void vLogInfoToFile(const char* fmt, va_list va) { } void vLogInfo(const char* fmt, va_list va) { - va_list va2; - va_copy(va2, va); - - if (logToTerminal) { - vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); - } - if (logToFile) { - vLogToFile(LOG_TYPE_NORMAL, fmt, va2); - } - - va_end(va2); + vLog(LOG_TYPE_NORMAL, fmt, va); } void logWarnToTerminal(const char* fmt, ...) { @@ -214,20 +182,11 @@ void logWarnToFile(const char* fmt, ...) { } void logWarn(const char* fmt, ...) { - va_list va, va2; + va_list va; va_start(va, fmt); - va_copy(va2, va); - - if (logToTerminal) { - vLogToTerminal(LOG_TYPE_WARNING, fmt, va); - } - if (logToFile) { - vLogToFile(LOG_TYPE_WARNING, fmt, va2); - } - + vLog(LOG_TYPE_WARNING, fmt, va); va_end(va); - va_end(va2); } void vLogWarnToTerminal(const char* fmt, va_list va) { @@ -239,17 +198,7 @@ void vLogWarnToFile(const char* fmt, va_list va) { } void vLogWarn(const char* fmt, va_list va) { - va_list va2; - va_copy(va2, va); - - if (logToTerminal) { - vLogToTerminal(LOG_TYPE_WARNING, fmt, va); - } - if (logToFile) { - vLogToFile(LOG_TYPE_WARNING, fmt, va2); - } - - va_end(va2); + vLog(LOG_TYPE_WARNING, fmt, va); } void logErrorToTerminal(const char* fmt, ...) { @@ -269,20 +218,11 @@ void logErrorToFile(const char* fmt, ...) { } void logError(const char* fmt, ...) { - va_list va, va2; + va_list va; va_start(va, fmt); - va_copy(va2, va); - - if (logToTerminal) { - vLogToTerminal(LOG_TYPE_ERROR, fmt, va); - } - if (logToFile) { - vLogToFile(LOG_TYPE_ERROR, fmt, va2); - } - + vLog(LOG_TYPE_ERROR, fmt, va); va_end(va); - va_end(va2); } void vLogErrorToTerminal(const char* fmt, va_list va) { @@ -294,17 +234,7 @@ void vLogErrorToFile(const char* fmt, va_list va) { } void vLogError(const char* fmt, va_list va) { - va_list va2; - va_copy(va2, va); - - if (logToTerminal) { - vLogToTerminal(LOG_TYPE_ERROR, fmt, va); - } - if (logToFile) { - vLogToFile(LOG_TYPE_ERROR, fmt, va2); - } - - va_end(va2); + vLog(LOG_TYPE_ERROR, fmt, va); } void logDebugToTerminal(const char* fmt, ...) { @@ -324,20 +254,11 @@ void logDebugToFile(const char* fmt, ...) { } void logDebug(const char* fmt, ...) { - va_list va, va2; + va_list va; va_start(va, fmt); - va_copy(va2, va); - - if (logToTerminal) { - vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); - } - if (logToFile) { - vLogToFile(LOG_TYPE_DEBUG, fmt, va2); - } - + vLog(LOG_TYPE_DEBUG, fmt, va); va_end(va); - va_end(va2); } void vLogDebugToTerminal(const char* fmt, va_list va) { @@ -349,15 +270,5 @@ void vLogDebugToFile(const char* fmt, va_list va) { } void vLogDebug(const char* fmt, va_list va) { - va_list va2; - va_copy(va2, va); - - if (logToTerminal) { - vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); - } - if (logToFile) { - vLogToFile(LOG_TYPE_DEBUG, fmt, va2); - } - - va_end(va2); + vLog(LOG_TYPE_DEBUG, fmt, va); } diff --git a/src/log.h b/src/log.h index b8dfaabcd..982d27803 100644 --- a/src/log.h +++ b/src/log.h @@ -7,15 +7,22 @@ #define LOG_MAX_FILES 16 -void Log_init(); +typedef enum { + LOG_TYPE_NORMAL=0, + LOG_TYPE_WARNING=1, + LOG_TYPE_ERROR=2, + LOG_TYPE_DEBUG=3 +} logType; + +typedef enum { + LOG_OUT_ALL=0, + LOG_OUT_TERMINAL=1, + LOG_OUT_FILE=2 +} logOutType; + +FILE* Log_init(); void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, const char* pLogFile); -void Log_setFile(FILE* file, const char* path); -void Log_resetFile(); - -bool Log_addFile(FILE* file); -bool Log_removeFile(FILE* file); - void logInfoToTerminal(const char* fmt, ...); void logInfoToFile(const char* fmt, ...); void logInfo(const char* fmt, ...); diff --git a/src/ps2/main.c b/src/ps2/main.c index 6d24f753d..e7af7c887 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -88,6 +88,12 @@ static bool padWasStable[2] = {false, false}; // Whether the controllers should be exposed via the GameMaker gamepad API static bool gamepadApiEnabled = false; +void platformLog(const logType type, const logOutType out, const char *format, va_list va) { + if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + } +} + static void parsePadMappings(JsonValue* configRoot, const char* key, PadMapping** outMappings, int* outCount, const char* logLabel) { JsonValue* mappingsObj = JsonReader_getJsonValueByKey(configRoot, key); if (mappingsObj == nullptr || !JsonReader_isObject(mappingsObj)) return; diff --git a/src/ps3/main.c b/src/ps3/main.c index 283139d63..98ba7f702 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -155,6 +155,12 @@ char *str_replace(char *orig, char *rep, char *with) { return result; } +void platformLog(const logType type, const logOutType out, const char *format, va_list va) { + if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + } +} + static char buffer[9999]; int main(int argc, char* argv[]) { Log_init(); diff --git a/src/web/main.c b/src/web/main.c index ec1684c2b..a844eef9f 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -22,6 +22,12 @@ static int32_t gAudioSampleRate = 48000; uint8_t keyDown[GML_KEY_COUNT] = {0}; uint8_t keyUp[GML_KEY_COUNT] = {0}; +void platformLog(const logType type, const logOutType out, const char *format, va_list va) { + if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + } +} + // Configures the sample rate that miniaudio will mix at. Must match the AudioContext's sampleRate // on the JS side, and must be called BEFORE startRunner. void setAudioSampleRate(int32_t rate) { From b12119831de29a1f7ffba4c44d83e02c4b86c878 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 15:38:56 +0800 Subject: [PATCH 40/57] Explicit cast --- src/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/log.c b/src/log.c index e3deda221..a03457656 100644 --- a/src/log.c +++ b/src/log.c @@ -78,7 +78,7 @@ static void vLogInternal(const logType type, const logOutType out, const char* f size_t newFmtSize = strlen(colourPrefix) + strlen(prefix) + strlen(fmt) + strlen(colourPostfix) + 1; - char* newFmt = safeMalloc(newFmtSize); + char* newFmt = (char*)safeMalloc(newFmtSize); snprintf(newFmt, newFmtSize, "%s%s%s%s", colourPrefix, prefix, fmt, colourPostfix); From 8427e68172ec8a70a541d5e32ba43c1c31075921 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 15:41:44 +0800 Subject: [PATCH 41/57] Hopefully fix web meta --- CMakeLists.txt | 2 ++ src/log.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48746cc78..05f8d05dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -367,6 +367,8 @@ elseif(PLATFORM STREQUAL "web-meta") OUTPUT_NAME "butterscotch-meta" ) + target_compile_definitions(butterscotch PRIVATE PLATFORM_WEB_META) + target_link_libraries(butterscotch PRIVATE stb_ds) target_link_options( diff --git a/src/log.c b/src/log.c index a03457656..1ecb5103d 100644 --- a/src/log.c +++ b/src/log.c @@ -44,6 +44,14 @@ void platformLog(const logType type, const logOutType out, const char *format, v // } // } +#ifdef PLATFORM_WEB_META +void platformLog(const logType type, const logOutType out, const char *format, va_list va) { + if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + } +} +#endif + static void vLogInternal(const logType type, const logOutType out, const char* fmt, va_list va) { // TODO: Seperate logColour less hackily if (out == LOG_OUT_ALL) { From 3a74c1a18ad5d3bb30e20c241f279294afbefbba Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 15:44:00 +0800 Subject: [PATCH 42/57] Hopefully fix --- src/log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/log.c b/src/log.c index 1ecb5103d..2c9a5b6fe 100644 --- a/src/log.c +++ b/src/log.c @@ -97,19 +97,19 @@ static void vLogInternal(const logType type, const logOutType out, const char* f free(newFmt); } -static void vLogToTerminal(const int type, const char* fmt, va_list va) { +static void vLogToTerminal(const logType type, const char* fmt, va_list va) { if (!logToTerminal) return; vLogInternal(type, LOG_OUT_TERMINAL, fmt, va); } -static void vLogToFile(const int type, const char* fmt, va_list va) { +static void vLogToFile(const logType type, const char* fmt, va_list va) { if (!logToFile) return; vLogInternal(type, LOG_OUT_FILE, fmt, va); } -static void vLog(const int type, const char* fmt, va_list va) { +static void vLog(const logType type, const char* fmt, va_list va) { if (!logToTerminal && !logToFile) return; vLogInternal(type, LOG_OUT_ALL, fmt, va); From db6ea5f0b252b839eeda125c3e8fa76c230f21fd Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 15:47:05 +0800 Subject: [PATCH 43/57] Add compatability va_copy define in main.c --- src/desktop/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/desktop/main.c b/src/desktop/main.c index 0764b2437..433548a02 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -309,6 +309,10 @@ static void printOsTypeNames(FILE* out) { } } +#ifndef va_copy +#define va_copy(d, s) ((d) = (s)) +#endif + void platformLog(const logType type, const logOutType out, const char *format, va_list va) { if (out == LOG_OUT_ALL) { va_list va2; From e41d955bbbb33e1b7c4dd3b3dadc35354a163829 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 21:55:18 +0800 Subject: [PATCH 44/57] Do what uniq said (at least for desktop) i think --- README.md | 4 +- src/desktop/main.c | 50 +++--------- src/log.c | 188 +++------------------------------------------ src/log.h | 29 +------ 4 files changed, 21 insertions(+), 250 deletions(-) diff --git a/README.md b/README.md index 7984f95d8..f746bc723 100644 --- a/README.md +++ b/README.md @@ -152,11 +152,9 @@ The desktop target has a lot of nifty CLI parameters that you can use to trace a --profile-opcodes - Rank which GML opcodes were executed the most --lazy-textures - Load textures into VRAM on first use, improving startup times --load-type - Specify how data.win is loaded, per-chunk or all at once ---disable-terminal-log - Disables logging to the terminal --disable-file-log - Disable logging to a file --log-file - File to log to ---disable-terminal-log-colours - Disable colours for warning and error logs in terminal ---enable-file-log-colours - Enables colours for warning and error logs in file +--disable-terminal-log-colours - Disable colours for warning, error, and debug logs ``` ## Debug Features diff --git a/src/desktop/main.c b/src/desktop/main.c index 433548a02..f449d77d3 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -55,8 +55,6 @@ #include "profiler.h" #include "gettime.h" -FILE* logFileHandle = nullptr; - /* For SDL_main */ #if defined(USE_SDL1) #include @@ -256,11 +254,9 @@ typedef struct { #ifdef ENABLE_VM_OPCODE_PROFILER bool opcodeProfiler; #endif - bool disableTerminalLog; bool disableFileLog; const char* logFile; - bool disableTerminalLogColours; - bool enableFileLogColours; + bool disableLogColours; } CommandLineArgs; typedef struct { const char* name; YoYoOperatingSystem value; } OsTypeNameEntry; @@ -309,24 +305,8 @@ static void printOsTypeNames(FILE* out) { } } -#ifndef va_copy -#define va_copy(d, s) ((d) = (s)) -#endif - -void platformLog(const logType type, const logOutType out, const char *format, va_list va) { - if (out == LOG_OUT_ALL) { - va_list va2; - va_copy(va2, va); - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); - vfprintf(logFileHandle, format, va2); - va_end(va2); - } - else if (out == LOG_OUT_TERMINAL) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); - } - else { // LOG_OUT_FILE - vfprintf(logFileHandle, format, va); - } +void platformLog(const logType type, const char *format, va_list va) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); } // Resolves the window size for the specified operating system. @@ -526,11 +506,9 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) {"game-args", required_argument, nullptr, 'N'}, {"lazy-textures", no_argument, nullptr, 'L'}, {"load-type", required_argument, nullptr, 999}, - {"disable-terminal-log", no_argument, nullptr, 1001}, - {"disable-file-log", no_argument, nullptr, 1002}, - {"log-file", required_argument, nullptr, 1003}, - {"disable-terminal-log-colours", no_argument, nullptr, 1004}, - {"enable-file-log-colours", no_argument, nullptr, 1005}, + {"disable-file-log", no_argument, nullptr, 1001}, + {"log-file", required_argument, nullptr, 1002}, + {"disable-log-colours", no_argument, nullptr, 1003}, #ifdef ENABLE_VM_OPCODE_PROFILER {"profile-opcodes", no_argument, nullptr, 'Q'}, #endif @@ -823,19 +801,13 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) break; } case 1001: - args->disableTerminalLog = true; - break; - case 1002: args->disableFileLog = true; break; - case 1003: + case 1002: args->logFile = optarg; break; - case 1004: - args->disableTerminalLogColours = true; - break; - case 1005: - args->enableFileLogColours = true; + case 1003: + args->disableLogColours = true; break; default: printUsage(argv[0]); @@ -1057,9 +1029,7 @@ int main(int argc, char* argv[]) { CommandLineArgs args; parseCommandLineArgs(&args, argc, argv); - Log_setOptions(!args.disableTerminalLog, !args.disableFileLog, !args.disableTerminalLogColours, args.enableFileLogColours, args.logFile ? args.logFile : "./butterscotch.log"); - - logFileHandle = Log_init(); + Log_setColour(!args.disableLogColours); char* currentDataWinPath = safeStrdup(args.dataWinPath); char** currentGameArgs = args.gameArgs; diff --git a/src/log.c b/src/log.c index 2c9a5b6fe..0fbb2a09d 100644 --- a/src/log.c +++ b/src/log.c @@ -8,17 +8,7 @@ #include "utils.h" -static bool logToTerminal = true; -static bool logToFile = true; - -static bool logColourTerminal = true; -static bool logColourFile = false; - -static const char* logFile = "./butterscotch.log"; - -#ifndef va_copy -#define va_copy(d, s) ((d) = (s)) -#endif +static bool logColour = true; #define ANSI_COLOUR_CODE_WHITE "\x1b[0;37m" #define ANSI_COLOUR_CODE_BOLD_YELLOW "\x1b[1;33m" @@ -26,45 +16,16 @@ static const char* logFile = "./butterscotch.log"; #define ANSI_COLOUR_CODE_BOLD_PURPLE "\x1b[1;35m" // In the platform main.c -void platformLog(const logType type, const logOutType out, const char *format, va_list va); -// Example impl: -// void platformLog(const logType type, const logOutType out, const char *format, va_list va) { -// if (out == LOG_OUT_ALL) { -// va_list va2; -// va_copy(va2, va); -// vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); -// vfprintf(logFileHandle, format, va2); -// va_end(va2); -// } -// else if (out == LOG_OUT_TERMINAL) { -// vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); -// } -// else { // LOG_OUT_FILE -// vfprintf(logFileHandle, format, va); -// } -// } +void platformLog(const logType type, const char *format, va_list va); +// Example impl: #ifdef PLATFORM_WEB_META -void platformLog(const logType type, const logOutType out, const char *format, va_list va) { - if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); - } +void platformLog(const logType type, const char *format, va_list va) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); } #endif -static void vLogInternal(const logType type, const logOutType out, const char* fmt, va_list va) { - // TODO: Seperate logColour less hackily - if (out == LOG_OUT_ALL) { - va_list va2; - va_copy(va2, va); - vLogInternal(type, LOG_OUT_TERMINAL, fmt, va); - vLogInternal(type, LOG_OUT_FILE, fmt, va2); - va_end(va2); - return; - } - - const bool logColour = out == LOG_OUT_TERMINAL ? logColourTerminal : logColourFile; - +static void vLog(const logType type, const char* fmt, va_list va) { const char* prefix = ""; if (type == LOG_TYPE_WARNING) { prefix = "Warning: "; @@ -92,65 +53,13 @@ static void vLogInternal(const logType type, const logOutType out, const char* f newFmt[newFmtSize-1] = '\0'; - platformLog(type, out, newFmt, va); + platformLog(type, newFmt, va); free(newFmt); } -static void vLogToTerminal(const logType type, const char* fmt, va_list va) { - if (!logToTerminal) return; - - vLogInternal(type, LOG_OUT_TERMINAL, fmt, va); -} - -static void vLogToFile(const logType type, const char* fmt, va_list va) { - if (!logToFile) return; - - vLogInternal(type, LOG_OUT_FILE, fmt, va); -} - -static void vLog(const logType type, const char* fmt, va_list va) { - if (!logToTerminal && !logToFile) return; - - vLogInternal(type, LOG_OUT_ALL, fmt, va); -} - -FILE* Log_init() { - if (logFile == nullptr) return nullptr; - - FILE* logFileHandle = fopen(logFile, "w"); - if (logFileHandle != nullptr) { - setvbuf(logFileHandle, nullptr, _IONBF, 0); - return logFileHandle; - } - - return nullptr; -} - -void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, const char* pLogFile) { - logToTerminal = bLogToTerminal; - logToFile = bLogToFile; - logColourTerminal = bLogColourTerminal; - logColourFile = bLogColourFile; - if (pLogFile != nullptr) { - logFile = pLogFile; - } -} - -void logInfoToTerminal(const char* fmt, ...) { - va_list va; - - va_start(va, fmt); - vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); - va_end(va); -} - -void logInfoToFile(const char* fmt, ...) { - va_list va; - - va_start(va, fmt); - vLogToFile(LOG_TYPE_NORMAL, fmt, va); - va_end(va); +void Log_setColour(bool bLogColour) { + logColour = bLogColour; } void logInfo(const char* fmt, ...) { @@ -161,34 +70,10 @@ void logInfo(const char* fmt, ...) { va_end(va); } -void vLogInfoToTerminal(const char* fmt, va_list va) { - vLogToTerminal(LOG_TYPE_NORMAL, fmt, va); -} - -void vLogInfoToFile(const char* fmt, va_list va) { - vLogToFile(LOG_TYPE_NORMAL, fmt, va); -} - void vLogInfo(const char* fmt, va_list va) { vLog(LOG_TYPE_NORMAL, fmt, va); } -void logWarnToTerminal(const char* fmt, ...) { - va_list va; - - va_start(va, fmt); - vLogToTerminal(LOG_TYPE_WARNING, fmt, va); - va_end(va); -} - -void logWarnToFile(const char* fmt, ...) { - va_list va; - - va_start(va, fmt); - vLogToFile(LOG_TYPE_WARNING, fmt, va); - va_end(va); -} - void logWarn(const char* fmt, ...) { va_list va; @@ -197,33 +82,10 @@ void logWarn(const char* fmt, ...) { va_end(va); } -void vLogWarnToTerminal(const char* fmt, va_list va) { - vLogToTerminal(LOG_TYPE_WARNING, fmt, va); -} - -void vLogWarnToFile(const char* fmt, va_list va) { - vLogToFile(LOG_TYPE_WARNING, fmt, va); -} - void vLogWarn(const char* fmt, va_list va) { vLog(LOG_TYPE_WARNING, fmt, va); } -void logErrorToTerminal(const char* fmt, ...) { - va_list va; - - va_start(va, fmt); - vLogToTerminal(LOG_TYPE_ERROR, fmt, va); - va_end(va); -} - -void logErrorToFile(const char* fmt, ...) { - va_list va; - - va_start(va, fmt); - vLogToFile(LOG_TYPE_ERROR, fmt, va); - va_end(va); -} void logError(const char* fmt, ...) { va_list va; @@ -233,34 +95,10 @@ void logError(const char* fmt, ...) { va_end(va); } -void vLogErrorToTerminal(const char* fmt, va_list va) { - vLogToTerminal(LOG_TYPE_ERROR, fmt, va); -} - -void vLogErrorToFile(const char* fmt, va_list va) { - vLogToFile(LOG_TYPE_ERROR, fmt, va); -} - void vLogError(const char* fmt, va_list va) { vLog(LOG_TYPE_ERROR, fmt, va); } -void logDebugToTerminal(const char* fmt, ...) { - va_list va; - - va_start(va, fmt); - vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); - va_end(va); -} - -void logDebugToFile(const char* fmt, ...) { - va_list va; - - va_start(va, fmt); - vLogToFile(LOG_TYPE_DEBUG, fmt, va); - va_end(va); -} - void logDebug(const char* fmt, ...) { va_list va; @@ -269,14 +107,6 @@ void logDebug(const char* fmt, ...) { va_end(va); } -void vLogDebugToTerminal(const char* fmt, va_list va) { - vLogToTerminal(LOG_TYPE_DEBUG, fmt, va); -} - -void vLogDebugToFile(const char* fmt, va_list va) { - vLogToFile(LOG_TYPE_DEBUG, fmt, va); -} - void vLogDebug(const char* fmt, va_list va) { vLog(LOG_TYPE_DEBUG, fmt, va); } diff --git a/src/log.h b/src/log.h index 982d27803..24cdebd39 100644 --- a/src/log.h +++ b/src/log.h @@ -14,45 +14,18 @@ typedef enum { LOG_TYPE_DEBUG=3 } logType; -typedef enum { - LOG_OUT_ALL=0, - LOG_OUT_TERMINAL=1, - LOG_OUT_FILE=2 -} logOutType; - -FILE* Log_init(); -void Log_setOptions(bool bLogToTerminal, bool bLogToFile, bool bLogColourTerminal, bool bLogColourFile, const char* pLogFile); +void Log_setColour(bool bColour); -void logInfoToTerminal(const char* fmt, ...); -void logInfoToFile(const char* fmt, ...); void logInfo(const char* fmt, ...); - -void vLogInfoToTerminal(const char* fmt, va_list va); -void vLogInfoToFile(const char* fmt, va_list va); void vLogInfo(const char* fmt, va_list va); -void logWarnToTerminal(const char* fmt, ...); -void logWarnToFile(const char* fmt, ...); void logWarn(const char* fmt, ...); - -void vLogWarnToTerminal(const char* fmt, va_list va); -void vLogWarnToFile(const char* fmt, va_list va); void vLogWarn(const char* fmt, va_list va); -void logErrorToTerminal(const char* fmt, ...); -void logErrorToFile(const char* fmt, ...); void logError(const char* fmt, ...); - -void vLogErrorToTerminal(const char* fmt, va_list va); -void vLogErrorToFile(const char* fmt, va_list va); void vLogError(const char* fmt, va_list va); -void logDebugToTerminal(const char* fmt, ...); -void logDebugToFile(const char* fmt, ...); void logDebug(const char* fmt, ...); - -void vLogDebugToTerminal(const char* fmt, va_list va); -void vLogDebugToFile(const char* fmt, va_list va); void vLogDebug(const char* fmt, va_list va); #endif /* _BS_LOG_H */ From a2caa32643f89b8419dc88ac0f71e0fa77eec9ca Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 22:19:36 +0800 Subject: [PATCH 45/57] Implement file logging in desktop --- README.md | 4 ++-- src/desktop/main.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f746bc723..987b51e79 100644 --- a/README.md +++ b/README.md @@ -154,8 +154,8 @@ The desktop target has a lot of nifty CLI parameters that you can use to trace a --load-type - Specify how data.win is loaded, per-chunk or all at once --disable-file-log - Disable logging to a file --log-file - File to log to ---disable-terminal-log-colours - Disable colours for warning, error, and debug logs -``` +--disable-log-colours - Disable colours for warning, error, and debug logs +--disable-log-colors - Same as --disable-log-colours, but different spelling ## Debug Features diff --git a/src/desktop/main.c b/src/desktop/main.c index f449d77d3..8937c7205 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -5,6 +5,7 @@ #include "platformdefs.h" #include +#include #include #include #include @@ -305,8 +306,23 @@ static void printOsTypeNames(FILE* out) { } } +static bool logToFile = false; +static FILE* logFileHandle = nullptr; + +#ifndef va_copy +#define va_copy ((d) = (s)) +#endif + void platformLog(const logType type, const char *format, va_list va) { + va_list va2; + if (logToFile) { + va_copy(va2, va); + } vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + if (logToFile) { + vfprintf(logFileHandle, format, va2); + va_end(va2); + } } // Resolves the window size for the specified operating system. @@ -442,11 +458,10 @@ static void printUsage(const char *argv0) { " --game-args - Arguments to pass to the game\n" " --lazy-textures - Load textures into VRAM on first use, improving startup times\n" " --load-type - Specify how data.win is loaded, per-chunk or all at once\n" - " --disable-terminal-log - Disables logging to the terminal\n" " --disable-file-log - Disable logging to a file\n" " --log-file - File to log to\n" - " --disable-terminal-log-colours - Disable colours for warning and error logs in terminal\n" - " --enable-file-log-colours - Enables colours for warning and error logs in file\n" + " --disable-log-colours - Disable colours for warning, error, and debug logs\n" + " --disable-log-colors - Same as --disable-log-colours, but different spelling\n" #ifdef EABLE_VM_OPCODE_PROFILER " --profile-opcodes - Rank which GML opcodes were executed the most\n" #endif @@ -509,6 +524,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[]) {"disable-file-log", no_argument, nullptr, 1001}, {"log-file", required_argument, nullptr, 1002}, {"disable-log-colours", no_argument, nullptr, 1003}, + {"disable-log-colors", no_argument, nullptr, 1003}, #ifdef ENABLE_VM_OPCODE_PROFILER {"profile-opcodes", no_argument, nullptr, 'Q'}, #endif @@ -1029,6 +1045,12 @@ int main(int argc, char* argv[]) { CommandLineArgs args; parseCommandLineArgs(&args, argc, argv); + logToFile = !args.disableFileLog; + if (logToFile) { + logFileHandle = fopen(args.logFile ? args.logFile : "./butterscotch.log", "w"); + setbuf(logFileHandle, NULL); + } + Log_setColour(!args.disableLogColours); char* currentDataWinPath = safeStrdup(args.dataWinPath); @@ -1965,4 +1987,8 @@ int main(int argc, char* argv[]) { arrfree(newArguments); } } + + if (logToFile) { + fclose(logFileHandle); + } } From cdbde3421932b85b7a8d5569c0b8723db32cb56a Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 22:22:49 +0800 Subject: [PATCH 46/57] Fix other platforms --- CMakeLists.txt | 2 -- src/android/main.c | 6 ++---- src/log.c | 8 +++----- src/ps2/main.c | 7 ++----- src/ps3/main.c | 6 ++---- src/web-meta/main.c | 4 ++++ src/web/main.c | 6 ++---- 7 files changed, 15 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05f8d05dc..48746cc78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -367,8 +367,6 @@ elseif(PLATFORM STREQUAL "web-meta") OUTPUT_NAME "butterscotch-meta" ) - target_compile_definitions(butterscotch PRIVATE PLATFORM_WEB_META) - target_link_libraries(butterscotch PRIVATE stb_ds) target_link_options( diff --git a/src/android/main.c b/src/android/main.c index 6bb6f6cbf..734f902af 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -42,10 +42,8 @@ static float gNormalizedCursorY = 0.0f; // We don't need to worry about game changes because the profiler will be automatically disabled then static int32_t gProfilerStartedAtFrame = 0; -void platformLog(const logType type, const logOutType out, const char *format, va_list va) { - if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { - __android_log_print(type == LOG_TYPE_NORMAL ? ANDROID_LOG_INFO : (type == LOG_TYPE_WARNING ? ANDROID_LOG_WARN : ANDROID_LOG_ERROR), LOG_TAG, format, va); - } +void platformLog(const logType type, const char *format, va_list va) { + __android_log_print(type == LOG_TYPE_NORMAL ? ANDROID_LOG_INFO : (type == LOG_TYPE_WARNING ? ANDROID_LOG_WARN : ANDROID_LOG_ERROR), LOG_TAG, format, va); } // Android has no platformGetWindowSize like the desktop, so we cache the EGL surface size the host diff --git a/src/log.c b/src/log.c index 0fbb2a09d..f78a647b4 100644 --- a/src/log.c +++ b/src/log.c @@ -19,11 +19,9 @@ static bool logColour = true; void platformLog(const logType type, const char *format, va_list va); // Example impl: -#ifdef PLATFORM_WEB_META -void platformLog(const logType type, const char *format, va_list va) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); -} -#endif +// void platformLog(const logType type, const char *format, va_list va) { +// vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); +// } static void vLog(const logType type, const char* fmt, va_list va) { const char* prefix = ""; diff --git a/src/ps2/main.c b/src/ps2/main.c index e7af7c887..f32c16505 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -88,12 +88,9 @@ static bool padWasStable[2] = {false, false}; // Whether the controllers should be exposed via the GameMaker gamepad API static bool gamepadApiEnabled = false; -void platformLog(const logType type, const logOutType out, const char *format, va_list va) { - if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); - } +void platformLog(const logType type, const char *format, va_list va) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); } - static void parsePadMappings(JsonValue* configRoot, const char* key, PadMapping** outMappings, int* outCount, const char* logLabel) { JsonValue* mappingsObj = JsonReader_getJsonValueByKey(configRoot, key); if (mappingsObj == nullptr || !JsonReader_isObject(mappingsObj)) return; diff --git a/src/ps3/main.c b/src/ps3/main.c index 98ba7f702..384b05de5 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -155,10 +155,8 @@ char *str_replace(char *orig, char *rep, char *with) { return result; } -void platformLog(const logType type, const logOutType out, const char *format, va_list va) { - if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); - } +void platformLog(const logType type, const char *format, va_list va) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); } static char buffer[9999]; diff --git a/src/web-meta/main.c b/src/web-meta/main.c index 8bf23e105..c521d664b 100644 --- a/src/web-meta/main.c +++ b/src/web-meta/main.c @@ -4,6 +4,10 @@ #include #include "data_win.h" +void platformLog(const logType type, const char *format, va_list va) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); +} + DataWin* parseDataWin(const char* path) { DataWinParserOptions opts = {0}; opts.parseGen8 = true; diff --git a/src/web/main.c b/src/web/main.c index a844eef9f..24fbc53cd 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -22,10 +22,8 @@ static int32_t gAudioSampleRate = 48000; uint8_t keyDown[GML_KEY_COUNT] = {0}; uint8_t keyUp[GML_KEY_COUNT] = {0}; -void platformLog(const logType type, const logOutType out, const char *format, va_list va) { - if (out == LOG_OUT_ALL || out == LOG_OUT_TERMINAL) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); - } +void platformLog(const logType type, const char *format, va_list va) { + vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); } // Configures the sample rate that miniaudio will mix at. Must match the AudioContext's sampleRate From a3ef0664210173e2b4efb66e8b9307ed3139181b Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 22:25:06 +0800 Subject: [PATCH 47/57] I forgot to give args to the va_copy compat macro --- src/desktop/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index 8937c7205..3a1161a6b 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -310,7 +310,7 @@ static bool logToFile = false; static FILE* logFileHandle = nullptr; #ifndef va_copy -#define va_copy ((d) = (s)) +#define va_copy(d, s) ((d) = (s)) #endif void platformLog(const logType type, const char *format, va_list va) { From 6d3d69cbab7b8237550c24c35632d7f2d9e1c525 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 22:28:32 +0800 Subject: [PATCH 48/57] Fix other platforms hopefully --- src/android/main.c | 3 +-- src/ps2/main.c | 2 +- src/ps3/main.c | 2 +- src/web-meta/main.c | 1 + src/web/main.c | 3 +-- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/android/main.c b/src/android/main.c index 734f902af..432bc71a4 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -74,8 +74,7 @@ static JNIEnv* getEnvNoAttach(void) { } JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, MAYBE_UNUSED void* reserved) { - Log_setOptions(true, false, false, false, nullptr); - Log_init(); + Log_setColour(false); gJvm = vm; JNIEnv* env = nullptr; if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) return JNI_ERR; diff --git a/src/ps2/main.c b/src/ps2/main.c index f32c16505..1a1eed44d 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -245,7 +245,7 @@ int main(int argc, char* argv[]) { SifInitRpc(0); sbv_patch_enable_lmb(); - Log_init(); + Log_setColour(false); // Ask the kernel how much main RAM we actually have. MAX_MEMORY_BYTES = (int) GetMemorySize(); diff --git a/src/ps3/main.c b/src/ps3/main.c index 384b05de5..67bfff900 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -161,7 +161,7 @@ void platformLog(const logType type, const char *format, va_list va) { static char buffer[9999]; int main(int argc, char* argv[]) { - Log_init(); + Log_setColour(false); logInfo("%s\n", argv[0]); if (argc > 0) strcpy(buffer, argv[0]); diff --git a/src/web-meta/main.c b/src/web-meta/main.c index c521d664b..b41de3b96 100644 --- a/src/web-meta/main.c +++ b/src/web-meta/main.c @@ -52,5 +52,6 @@ uint32_t getDefaultWindowHeight(DataWin* dw) { } int main(void) { + Log_setColour(false); return 0; } diff --git a/src/web/main.c b/src/web/main.c index 24fbc53cd..3386addc1 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -57,8 +57,7 @@ int getKeyCount() { } int main() { - Log_setOptions(true, false, true, false, nullptr); - Log_init(); + Log_setColour(false); logInfo("Howdy! Loritta is so cute! lol\n"); emscripten_exit_with_live_runtime(); return 0; From ec9bb6b1a9524420d9dee7a733dd18d1596db958 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Thu, 16 Jul 2026 22:28:56 +0800 Subject: [PATCH 49/57] Unconditionally va_copy --- src/desktop/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index 3a1161a6b..c1c720ac4 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -315,9 +315,7 @@ static FILE* logFileHandle = nullptr; void platformLog(const logType type, const char *format, va_list va) { va_list va2; - if (logToFile) { - va_copy(va2, va); - } + va_copy(va2, va); vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); if (logToFile) { vfprintf(logFileHandle, format, va2); From d3d323cea2d84c608dbd74474616ce8e7969b2da Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Fri, 17 Jul 2026 07:29:30 +0800 Subject: [PATCH 50/57] Move va_end out of conditional --- src/desktop/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index c1c720ac4..a4232cfd2 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -319,8 +319,8 @@ void platformLog(const logType type, const char *format, va_list va) { vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); if (logToFile) { vfprintf(logFileHandle, format, va2); - va_end(va2); } + va_end(va2); } // Resolves the window size for the specified operating system. From 3cc82f2e405d16ae18aba4b0237712681a64ff5b Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Fri, 17 Jul 2026 08:28:04 +0800 Subject: [PATCH 51/57] Maybe fix tests --- tests/tests.conf | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/tests.conf b/tests/tests.conf index b4a06ccb5..1d5db981a 100644 --- a/tests/tests.conf +++ b/tests/tests.conf @@ -1,7 +1,7 @@ tests = [ { name = "Test if collisions are executed sorted in object index order NOT in instance creation order" - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "object-index-iteration-test/data.win", "--headless", "--exit-at-frame", "1"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "object-index-iteration-test/data.win", "--headless", "--exit-at-frame", "1"] expectedStdoutOutput = [ [ "Game: start frame", @@ -13,7 +13,7 @@ tests = [ }, { name = "Test Loritta and the Stars" - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "loritta-and-the-stars/data.win", "--playback-inputs", "loritta-and-the-stars/gameplay.json", "--exit-at-frame", "9000", "--screenshot-surfaces-at-frame", "9000", "--screenshot-surfaces", "loritta-and-the-stars/actual.%d.%d.png", "--headless"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "loritta-and-the-stars/data.win", "--playback-inputs", "loritta-and-the-stars/gameplay.json", "--exit-at-frame", "9000", "--screenshot-surfaces-at-frame", "9000", "--screenshot-surfaces", "loritta-and-the-stars/actual.%d.%d.png", "--headless"] expectedScreenshots = [ { expected = "loritta-and-the-stars/expected.9000.0.png" @@ -24,10 +24,10 @@ tests = [ { name = "Test Undertale PT-BR (WinPack/TranslaTale WAD)" commercialGame = true - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "undertale-ptbr-winpack/data.win", "--playback-inputs", "undertale-ptbr-winpack/gameplay.json", "--exit-at-frame", "730", "--screenshot-surfaces-at-frame", "730", "--screenshot-surfaces", "undertale-ptbr-winpack/actual.%d.%d.png", "--headless", "--lazy-textures"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "undertale-ptbr-winpack/data.win", "--playback-inputs", "undertale-ptbr-winpack/gameplay.json", "--exit-at-frame", "730", "--screenshot-surfaces-at-frame", "730", "--screenshot-surfaces", "undertale-ptbr-winpack/actual.%d.%d.png", "--headless", "--lazy-textures"] expectedStderrOutput = [ [ - "DataWin: Allocated new TPAG! Was the WAD built with WinPack? (TranslaTale)" + "Warning: DataWin: Allocated new TPAG! Was the WAD built with WinPack? (TranslaTale)" ] ] expectedScreenshots = [ @@ -40,7 +40,7 @@ tests = [ { name = "Test Underfavela (Bogus Sprite Types and Bogus AGPR padding checks)" commercialGame = true - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "underfavela/data.win", "--seed", "0", "--playback-inputs", "underfavela/gameplay.json", "--screenshot-surfaces", "underfavela/actual.%d.%d.png", "--screenshot-surfaces-at-frame", "2000", "--exit-at-frame", "2000", "--headless", "--lazy-textures"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "underfavela/data.win", "--seed", "0", "--playback-inputs", "underfavela/gameplay.json", "--screenshot-surfaces", "underfavela/actual.%d.%d.png", "--screenshot-surfaces-at-frame", "2000", "--exit-at-frame", "2000", "--headless", "--lazy-textures"] expectedScreenshots = [ { expected = "underfavela/expected.2000.0.png" @@ -51,7 +51,7 @@ tests = [ { name = "Test Simple Structs, Methods and Dynamic Methods" commercialGame = false - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "simple-structs-methods-and-dynamic-methods/data.win", "--exit-at-frame", "1"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "simple-structs-methods-and-dynamic-methods/data.win", "--exit-at-frame", "1"] expectedStdoutOutput = [ [ "Game: My name is Loritta Morenitta!", @@ -71,7 +71,7 @@ tests = [ { name = "Test Out of Lives Event Ordering" commercialGame = false - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "lives-and-health-events-check/data.win", "--exit-at-frame", "20", "--headless"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "lives-and-health-events-check/data.win", "--exit-at-frame", "20", "--headless"] expectedStdoutOutput = [ [ "Game: Current lives is 10, decreasing one...", @@ -97,7 +97,7 @@ tests = [ { name = "Test if path_add is creating paths closed by default (DELTARUNE Chapter 4 - Jackenstein)" commercialGame = true - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "deltarune-chapter4-105-beta/data.win", "--playback-inputs", "deltarune-chapter4-105-beta/jackenstein-path-test.json", "--lazy-textures", "--seed", "0", "--screenshot-surfaces", "deltarune-chapter4-105-beta/actual.jackenstein-path-test.%d.%d.png", "--screenshot-surfaces-at-frame", "9473", "--screenshot-surfaces-at-frame", "9474", "--headless", "--exit-at-frame", "9474", "--save-folder", "deltarune-chapter4-105-beta/jackenstein/"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "deltarune-chapter4-105-beta/data.win", "--playback-inputs", "deltarune-chapter4-105-beta/jackenstein-path-test.json", "--lazy-textures", "--seed", "0", "--screenshot-surfaces", "deltarune-chapter4-105-beta/actual.jackenstein-path-test.%d.%d.png", "--screenshot-surfaces-at-frame", "9473", "--screenshot-surfaces-at-frame", "9474", "--headless", "--exit-at-frame", "9474", "--save-folder", "deltarune-chapter4-105-beta/jackenstein/"] expectedScreenshots = [ { expected = "deltarune-chapter4-105-beta/expected.jackenstein-path-test.9473.0.png" @@ -112,7 +112,7 @@ tests = [ { name = "Test struct_get_names and variable_instance_get_names" commercialGame = false - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "struct-get-names-test/data.win", "--exit-at-frame", "1", "--headless"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "struct-get-names-test/data.win", "--exit-at-frame", "1", "--headless"] # The order is not guaranteed by GameMaker, so we also won't check for the exact order expectedStdoutOutput = [ [ "Game: [struct(struct_get_names)] Name is gabrielaName" ], @@ -150,7 +150,7 @@ tests = [ { name = "Test Stack Unwinding" commercialGame = false - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "stack-unwinding/data.win", "--exit-at-frame", "1", "--headless"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "stack-unwinding/data.win", "--exit-at-frame", "1", "--headless"] expectedStdoutOutput = [ [ "Game: Exited loop! Current count is 2047" ], ] @@ -158,10 +158,10 @@ tests = [ { name = "Test try ... catch ... finally" commercialGame = false - butterscotchArgs = ["--disable-terminal-log-colours", "--disable-file-log", "try-catch-finally-test/data.win", "--exit-at-frame", "1", "--headless"] + butterscotchArgs = ["--disable-log-colours", "--disable-file-log", "try-catch-finally-test/data.win", "--exit-at-frame", "1", "--headless"] expectedStderrOutput = [ - [ "VM: The exception handler frame stack is 0, but we have a pending exception to be dispatched! This would've technically crashed the game in the original runner... or we aren't handling exceptions correctly. We'll swallow the exception and hope for the best... (Exception: b)" ] + [ "Error: VM: The exception handler frame stack is 0, but we have a pending exception to be dispatched! This would've technically crashed the game in the original runner... or we aren't handling exceptions correctly. We'll swallow the exception and hope for the best... (Exception: b)" ] ] expectedStdoutOutput = [ From b2cbbd8b27f864d6d507dce2c8de6e45660b27b6 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Fri, 17 Jul 2026 08:34:18 +0800 Subject: [PATCH 52/57] Maybe fix them --- tests/tests.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tests.conf b/tests/tests.conf index 1d5db981a..ee83bf4a0 100644 --- a/tests/tests.conf +++ b/tests/tests.conf @@ -63,6 +63,8 @@ tests = [ "Game: Howdy! This was invoked via a dynamic method, but now bound to a asset reference woo - x: 640, y: 224", "Game: Name: Loritta Morenitta", "Game: Stars: 1437", + ], + [ "Game: Hiii, my name is Pantufa!", "Game: This is another function!!" ] @@ -75,6 +77,8 @@ tests = [ expectedStdoutOutput = [ [ "Game: Current lives is 10, decreasing one...", + ], + [ "Game: Current lives is 9, decreasing one...", "Game: Current lives is 8, decreasing one...", "Game: Current lives is 7, decreasing one...", From 1ba1991aeada9c5356fa970968f3fe5a3c78aba3 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Fri, 17 Jul 2026 15:09:24 +0800 Subject: [PATCH 53/57] Remove unused macro --- src/log.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/log.h b/src/log.h index 24cdebd39..bfb08f27b 100644 --- a/src/log.h +++ b/src/log.h @@ -5,8 +5,6 @@ #include #include -#define LOG_MAX_FILES 16 - typedef enum { LOG_TYPE_NORMAL=0, LOG_TYPE_WARNING=1, From cd4108e07e33d69d56b86022edf8a3289c7a1a28 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Fri, 17 Jul 2026 15:52:57 +0800 Subject: [PATCH 54/57] Do what uniq said for desktop i think --- src/desktop/main.c | 41 ++++++++++++++++++++---- src/log.c | 79 +++++++++++++++------------------------------- src/log.h | 5 ++- 3 files changed, 65 insertions(+), 60 deletions(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index a4232cfd2..95a1dca20 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -309,17 +309,44 @@ static void printOsTypeNames(FILE* out) { static bool logToFile = false; static FILE* logFileHandle = nullptr; +static bool logColour; + #ifndef va_copy #define va_copy(d, s) ((d) = (s)) #endif void platformLog(const logType type, const char *format, va_list va) { + FILE *out = stderr; + const char* prefix = ANSI_COLOUR_CODE_RESET; + switch (type) { + case LOG_TYPE_NORMAL: + out = stdout; + break; + case LOG_TYPE_WARNING: + prefix = ANSI_COLOUR_CODE_BOLD_YELLOW"Warning: "; + break; + case LOG_TYPE_ERROR: + prefix = ANSI_COLOUR_CODE_BOLD_RED"Error: "; + break; + case LOG_TYPE_DEBUG: + prefix = ANSI_COLOUR_CODE_BOLD_PURPLE"Debug: "; + break; + } + va_list va2; va_copy(va2, va); - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); - if (logToFile) { - vfprintf(logFileHandle, format, va2); + + print: + if (logColour) fputs(prefix, out); + vfprintf(out, format, va2); + if (logColour) fputs(ANSI_COLOUR_CODE_RESET, out); + + if (logToFile && out != logFileHandle && logFileHandle) { + out = logFileHandle; + va_copy(va2, va); + goto print; } + va_end(va2); } @@ -1046,10 +1073,12 @@ int main(int argc, char* argv[]) { logToFile = !args.disableFileLog; if (logToFile) { logFileHandle = fopen(args.logFile ? args.logFile : "./butterscotch.log", "w"); - setbuf(logFileHandle, NULL); + if (logFileHandle) { + setbuf(logFileHandle, NULL); + } } - Log_setColour(!args.disableLogColours); + logColour = !args.disableLogColours; char* currentDataWinPath = safeStrdup(args.dataWinPath); char** currentGameArgs = args.gameArgs; @@ -1986,7 +2015,7 @@ int main(int argc, char* argv[]) { } } - if (logToFile) { + if (logFileHandle) { fclose(logFileHandle); } } diff --git a/src/log.c b/src/log.c index f78a647b4..c1a45a673 100644 --- a/src/log.c +++ b/src/log.c @@ -8,80 +8,53 @@ #include "utils.h" -static bool logColour = true; - -#define ANSI_COLOUR_CODE_WHITE "\x1b[0;37m" -#define ANSI_COLOUR_CODE_BOLD_YELLOW "\x1b[1;33m" -#define ANSI_COLOUR_CODE_BOLD_RED "\x1b[1;31m" -#define ANSI_COLOUR_CODE_BOLD_PURPLE "\x1b[1;35m" - // In the platform main.c void platformLog(const logType type, const char *format, va_list va); // Example impl: // void platformLog(const logType type, const char *format, va_list va) { -// vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); +// FILE *out = stderr; +// switch (type) { +// case LOG_TYPE_NORMAL: +// out = stdout; +// fputs(ANSI_COLOUR_CODE_RESET, out); +// break; +// case LOG_TYPE_WARNING: +// fputs(ANSI_COLOUR_CODE_BOLD_YELLOW"Warning: ", out); +// break; +// case LOG_TYPE_ERROR: +// fputs(ANSI_COLOUR_CODE_BOLD_RED"Error: ", out); +// break; +// case LOG_TYPE_DEBUG: +// fputs(ANSI_COLOUR_CODE_BOLD_PURPLE"Debug: ", out); +// break; +// } +// vfprintf(out, format, va); +// fputs(ANSI_COLOUR_CODE_RESET, out); // } -static void vLog(const logType type, const char* fmt, va_list va) { - const char* prefix = ""; - if (type == LOG_TYPE_WARNING) { - prefix = "Warning: "; - } - else if (type == LOG_TYPE_ERROR) { - prefix = "Error: "; - } - else if (type == LOG_TYPE_DEBUG) { - prefix = "Debug: "; - } - - const char* colourPrefix = ""; - const char* colourPostfix = ""; - - if(logColour) { - colourPrefix = (type == LOG_TYPE_NORMAL ? ANSI_COLOUR_CODE_WHITE : (type == LOG_TYPE_WARNING ? ANSI_COLOUR_CODE_BOLD_YELLOW : (type == LOG_TYPE_ERROR ? ANSI_COLOUR_CODE_BOLD_RED : ANSI_COLOUR_CODE_BOLD_PURPLE))); - colourPostfix = ANSI_COLOUR_CODE_WHITE; - } - - size_t newFmtSize = strlen(colourPrefix) + strlen(prefix) + strlen(fmt) + strlen(colourPostfix) + 1; - - char* newFmt = (char*)safeMalloc(newFmtSize); - - snprintf(newFmt, newFmtSize, "%s%s%s%s", colourPrefix, prefix, fmt, colourPostfix); - - newFmt[newFmtSize-1] = '\0'; - - platformLog(type, newFmt, va); - - free(newFmt); -} - -void Log_setColour(bool bLogColour) { - logColour = bLogColour; -} - void logInfo(const char* fmt, ...) { va_list va; va_start(va, fmt); - vLog(LOG_TYPE_NORMAL, fmt, va); + platformLog(LOG_TYPE_NORMAL, fmt, va); va_end(va); } void vLogInfo(const char* fmt, va_list va) { - vLog(LOG_TYPE_NORMAL, fmt, va); + platformLog(LOG_TYPE_NORMAL, fmt, va); } void logWarn(const char* fmt, ...) { va_list va; va_start(va, fmt); - vLog(LOG_TYPE_WARNING, fmt, va); + platformLog(LOG_TYPE_WARNING, fmt, va); va_end(va); } void vLogWarn(const char* fmt, va_list va) { - vLog(LOG_TYPE_WARNING, fmt, va); + platformLog(LOG_TYPE_WARNING, fmt, va); } @@ -89,22 +62,22 @@ void logError(const char* fmt, ...) { va_list va; va_start(va, fmt); - vLog(LOG_TYPE_ERROR, fmt, va); + platformLog(LOG_TYPE_ERROR, fmt, va); va_end(va); } void vLogError(const char* fmt, va_list va) { - vLog(LOG_TYPE_ERROR, fmt, va); + platformLog(LOG_TYPE_ERROR, fmt, va); } void logDebug(const char* fmt, ...) { va_list va; va_start(va, fmt); - vLog(LOG_TYPE_DEBUG, fmt, va); + platformLog(LOG_TYPE_DEBUG, fmt, va); va_end(va); } void vLogDebug(const char* fmt, va_list va) { - vLog(LOG_TYPE_DEBUG, fmt, va); + platformLog(LOG_TYPE_DEBUG, fmt, va); } diff --git a/src/log.h b/src/log.h index bfb08f27b..2f8ee3f29 100644 --- a/src/log.h +++ b/src/log.h @@ -12,7 +12,10 @@ typedef enum { LOG_TYPE_DEBUG=3 } logType; -void Log_setColour(bool bColour); +#define ANSI_COLOUR_CODE_RESET "\033[0m" +#define ANSI_COLOUR_CODE_BOLD_YELLOW "\033[1;33m" +#define ANSI_COLOUR_CODE_BOLD_RED "\033[1;31m" +#define ANSI_COLOUR_CODE_BOLD_PURPLE "\033[1;35m" void logInfo(const char* fmt, ...); void vLogInfo(const char* fmt, va_list va); From 85d724cc8ae7b37c2473116cbfd8541c4b22c3f4 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Fri, 17 Jul 2026 16:03:34 +0800 Subject: [PATCH 55/57] Fix other backends hopefully --- src/android/main.c | 23 ++++++++++++++++++++++- src/ps2/main.c | 20 +++++++++++++++++--- src/ps3/main.c | 18 ++++++++++++++++-- src/web-meta/main.c | 17 ++++++++++++++++- src/web/main.c | 17 ++++++++++++++++- 5 files changed, 87 insertions(+), 8 deletions(-) diff --git a/src/android/main.c b/src/android/main.c index 432bc71a4..94ed62a3a 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -43,7 +43,28 @@ static float gNormalizedCursorY = 0.0f; static int32_t gProfilerStartedAtFrame = 0; void platformLog(const logType type, const char *format, va_list va) { - __android_log_print(type == LOG_TYPE_NORMAL ? ANDROID_LOG_INFO : (type == LOG_TYPE_WARNING ? ANDROID_LOG_WARN : ANDROID_LOG_ERROR), LOG_TAG, format, va); + const char* prefix = ""; + switch (type) { + case LOG_TYPE_NORMAL: + break; + case LOG_TYPE_WARNING: + prefix = "Warning: "; + break; + case LOG_TYPE_ERROR: + prefix = "Error: "; + break; + case LOG_TYPE_DEBUG: + prefix = "Debug: "; + break; + } + + const int newFormatSize = strlen(format) + strlen(prefix) + 1; + const char* newFormat = (char*)safeMalloc(newFormatSize); + snprintf(newFormat, newFormatSize, "%s%s", prefix, format); + + __android_log_vprint(type == LOG_TYPE_NORMAL ? ANDROID_LOG_INFO : (type == LOG_TYPE_WARNING ? ANDROID_LOG_WARN : ANDROID_LOG_ERROR), LOG_TAG, newFormat, va); + + free(newFormat); } // Android has no platformGetWindowSize like the desktop, so we cache the EGL surface size the host diff --git a/src/ps2/main.c b/src/ps2/main.c index 1a1eed44d..26d230219 100644 --- a/src/ps2/main.c +++ b/src/ps2/main.c @@ -89,8 +89,24 @@ static bool padWasStable[2] = {false, false}; static bool gamepadApiEnabled = false; void platformLog(const logType type, const char *format, va_list va) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + FILE *out = stderr; + switch (type) { + case LOG_TYPE_NORMAL: + out = stdout; + break; + case LOG_TYPE_WARNING: + fputs("Warning: ", out); + break; + case LOG_TYPE_ERROR: + fputs("Error: ", out); + break; + case LOG_TYPE_DEBUG: + fputs("Debug: ", out); + break; + } + vfprintf(out, format, va); } + static void parsePadMappings(JsonValue* configRoot, const char* key, PadMapping** outMappings, int* outCount, const char* logLabel) { JsonValue* mappingsObj = JsonReader_getJsonValueByKey(configRoot, key); if (mappingsObj == nullptr || !JsonReader_isObject(mappingsObj)) return; @@ -245,8 +261,6 @@ int main(int argc, char* argv[]) { SifInitRpc(0); sbv_patch_enable_lmb(); - Log_setColour(false); - // Ask the kernel how much main RAM we actually have. MAX_MEMORY_BYTES = (int) GetMemorySize(); diff --git a/src/ps3/main.c b/src/ps3/main.c index 67bfff900..065394c21 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -156,9 +156,23 @@ char *str_replace(char *orig, char *rep, char *with) { } void platformLog(const logType type, const char *format, va_list va) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + FILE *out = stderr; + switch (type) { + case LOG_TYPE_NORMAL: + out = stdout; + break; + case LOG_TYPE_WARNING: + fputs("Warning: ", out); + break; + case LOG_TYPE_ERROR: + fputs("Error: ", out); + break; + case LOG_TYPE_DEBUG: + fputs("Debug: ", out); + break; + } + vfprintf(out, format, va); } - static char buffer[9999]; int main(int argc, char* argv[]) { Log_setColour(false); diff --git a/src/web-meta/main.c b/src/web-meta/main.c index b41de3b96..7d9b1d448 100644 --- a/src/web-meta/main.c +++ b/src/web-meta/main.c @@ -5,7 +5,22 @@ #include "data_win.h" void platformLog(const logType type, const char *format, va_list va) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + FILE *out = stderr; + switch (type) { + case LOG_TYPE_NORMAL: + out = stdout; + break; + case LOG_TYPE_WARNING: + fputs("Warning: ", out); + break; + case LOG_TYPE_ERROR: + fputs("Error: ", out); + break; + case LOG_TYPE_DEBUG: + fputs("Debug: ", out); + break; + } + vfprintf(out, format, va); } DataWin* parseDataWin(const char* path) { diff --git a/src/web/main.c b/src/web/main.c index 3386addc1..786c90d81 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -23,7 +23,22 @@ uint8_t keyDown[GML_KEY_COUNT] = {0}; uint8_t keyUp[GML_KEY_COUNT] = {0}; void platformLog(const logType type, const char *format, va_list va) { - vfprintf(type == LOG_TYPE_NORMAL ? stdout : stderr, format, va); + FILE *out = stderr; + switch (type) { + case LOG_TYPE_NORMAL: + out = stdout; + break; + case LOG_TYPE_WARNING: + fputs("Warning: ", out); + break; + case LOG_TYPE_ERROR: + fputs("Error: ", out); + break; + case LOG_TYPE_DEBUG: + fputs("Debug: ", out); + break; + } + vfprintf(out, format, va); } // Configures the sample rate that miniaudio will mix at. Must match the AudioContext's sampleRate From b5e819558c2bbd8742db57c22c686b8ccbbe3bb1 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Fri, 17 Jul 2026 16:09:18 +0800 Subject: [PATCH 56/57] Hopefully fix compile errs --- src/android/main.c | 1 - src/ps3/main.c | 1 - src/web-meta/main.c | 1 - src/web/main.c | 1 - 4 files changed, 4 deletions(-) diff --git a/src/android/main.c b/src/android/main.c index 94ed62a3a..0bca9a4ad 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -95,7 +95,6 @@ static JNIEnv* getEnvNoAttach(void) { } JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, MAYBE_UNUSED void* reserved) { - Log_setColour(false); gJvm = vm; JNIEnv* env = nullptr; if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) return JNI_ERR; diff --git a/src/ps3/main.c b/src/ps3/main.c index 065394c21..0bd03bd43 100644 --- a/src/ps3/main.c +++ b/src/ps3/main.c @@ -175,7 +175,6 @@ void platformLog(const logType type, const char *format, va_list va) { } static char buffer[9999]; int main(int argc, char* argv[]) { - Log_setColour(false); logInfo("%s\n", argv[0]); if (argc > 0) strcpy(buffer, argv[0]); diff --git a/src/web-meta/main.c b/src/web-meta/main.c index 7d9b1d448..99ba8549a 100644 --- a/src/web-meta/main.c +++ b/src/web-meta/main.c @@ -67,6 +67,5 @@ uint32_t getDefaultWindowHeight(DataWin* dw) { } int main(void) { - Log_setColour(false); return 0; } diff --git a/src/web/main.c b/src/web/main.c index 786c90d81..57400044a 100644 --- a/src/web/main.c +++ b/src/web/main.c @@ -72,7 +72,6 @@ int getKeyCount() { } int main() { - Log_setColour(false); logInfo("Howdy! Loritta is so cute! lol\n"); emscripten_exit_with_live_runtime(); return 0; From d3a7fe4ef18ce12fcd584d31700af74ccb71c2f7 Mon Sep 17 00:00:00 2001 From: Purplesmaug96 Date: Fri, 17 Jul 2026 17:57:56 +0800 Subject: [PATCH 57/57] Fix tests hopefully --- src/desktop/main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/desktop/main.c b/src/desktop/main.c index 95a1dca20..91b25b005 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -317,19 +317,23 @@ static bool logColour; void platformLog(const logType type, const char *format, va_list va) { FILE *out = stderr; - const char* prefix = ANSI_COLOUR_CODE_RESET; + const char* colourPrefix = ANSI_COLOUR_CODE_RESET; + const char* textPrefix = ""; switch (type) { case LOG_TYPE_NORMAL: out = stdout; break; case LOG_TYPE_WARNING: - prefix = ANSI_COLOUR_CODE_BOLD_YELLOW"Warning: "; + colourPrefix = ANSI_COLOUR_CODE_BOLD_YELLOW; + textPrefix = "Warning: "; break; case LOG_TYPE_ERROR: - prefix = ANSI_COLOUR_CODE_BOLD_RED"Error: "; + colourPrefix = ANSI_COLOUR_CODE_BOLD_RED; + textPrefix = "Error: "; break; case LOG_TYPE_DEBUG: - prefix = ANSI_COLOUR_CODE_BOLD_PURPLE"Debug: "; + colourPrefix = ANSI_COLOUR_CODE_BOLD_PURPLE; + textPrefix = "Debug: "; break; } @@ -337,7 +341,8 @@ void platformLog(const logType type, const char *format, va_list va) { va_copy(va2, va); print: - if (logColour) fputs(prefix, out); + if (logColour) fputs(colourPrefix, out); + fputs(textPrefix, out); vfprintf(out, format, va2); if (logColour) fputs(ANSI_COLOUR_CODE_RESET, out);