Overhaul console logging

This commit is contained in:
Agent X 2023-11-26 16:49:32 -05:00
parent cbcee61255
commit 5cb9e25090
18 changed files with 121 additions and 91 deletions

View file

@ -43,12 +43,14 @@ in_files = [
"src/audio/external.h",
"src/game/envfx_snow.h",
"src/pc/mods/mod_storage.h",
"src/game/first_person_cam.h"
"src/game/first_person_cam.h",
"src/pc/djui/djui_console.h"
]
exclude_constants = {
"*": [ "^MAXCONTROLLERS$", "^AREA_[^T].*", "^AREA_T[HTO]", "^CONT_ERR.*", "^READ_MASK$", "^SIGN_RANGE$", ],
"src/game/obj_behaviors.c": [ "^o$" ]
"src/game/obj_behaviors.c": [ "^o$" ],
"src/pc/djui/djui_console.h": [ "CONSOLE_MAX_TMP_BUFFER" ]
}
include_constants = {

View file

@ -307,7 +307,7 @@ manual_index_documentation = """
- [texture_override_reset](#texture_override_reset)
- [smlua_anim_util_register_animation](#smlua_anim_util_register_animation)
- [level_script_parse](#level_script_parse)
- [set_exclamation_box_contents](#set_exclamation_box_contents)
- [log_to_console](#log_to_console)
<br />
@ -641,23 +641,24 @@ Parses a level script and passes area index, behavior data, macro behavior IDs a
<br />
## [set_exclamation_box_new_contents](#set_exclamation_box_new_contents)
## [log_to_console](#log_to_console)
Sets the contents of an exclamation box.
Logs a message to the in-game console.
### Lua Example
`set_exclamation_box_new_contents(contents)`
`log_to_console("sm64coopdx FTW", CONSOLE_MESSAGE_INFO)`
### Parameters
| Field | Type |
| ----- | ---- |
| contents | [ExclamationBoxContents](structs.md#ExclamationBoxContents) |
| message | `string` |
| level | `ConsoleMessageLevel` |
### Returns
- None
### C Prototype
`void set_exclamation_box_new_contents(struct Struct802C0DF0 contents[], u8 size);`
`void log_to_console(const char* message, enum ConsoleMessageLevel level);`
[:arrow_up_small:](#)

View file

@ -3299,6 +3299,17 @@ DIALOG_169 = 169
--- @type DialogId
DIALOG_COUNT = 170
--- @class ConsoleMessageLevel
--- @type ConsoleMessageLevel
CONSOLE_MESSAGE_INFO = 0
--- @type ConsoleMessageLevel
CONSOLE_MESSAGE_WARNING = 1
--- @type ConsoleMessageLevel
CONSOLE_MESSAGE_ERROR = 2
--- @class DjuiFontType
--- @type DjuiFontType

View file

@ -8873,12 +8873,6 @@ function is_transition_playing()
-- ...
end
--- @param message string
--- @return nil
function log_to_console(message)
-- ...
end
--- @param name string
--- @param level integer
--- @param area integer

View file

@ -133,13 +133,13 @@ end
-- functions --
---------------
--- @param t number
--- @param t number Angle
--- @return number
function sins(t)
-- ...
end
--- @param t number
--- @param t number Angle
--- @return number
function coss(t)
-- ...
@ -276,6 +276,21 @@ function texture_override_reset(textureName)
-- ...
end
--- @class bhvData
--- @field behavior BehaviorId
--- @field behaviorArg integer
--- @param levelNum LevelNum | integer
--- @param func fun(areaIndex:number, bhvData:bhvData, macroBhvIds:BehaviorId[], macroBhvArgs:integer[])
--- @return nil
--- When `func` is called, arguments are filled depending on the level command:
--- - `AREA` command: only `areaIndex` is filled. It's a number.
--- - `OBJECT` command: only `bhvData` is filled. `bhvData` is a table with two fields: `behavior` and `behaviorArg`.
--- - `MACRO` command: only `macroBhvIds` and `macroBhvArgs` are filled. `macrobhvIds` is a list of behavior ids. `macroBhvArgs` is a list of behavior params. Both lists have the same size and start at index 0.
function level_script_parse(levelNum, func)
-- ...
end
--- @param name string
--- @param flags integer
--- @param animYTransDivisor integer
@ -290,18 +305,11 @@ function smlua_anim_util_register_animation(name, flags, animYTransDivisor, star
-- ...
end
--- @class bhvData
--- @field behavior BehaviorId
--- @field behaviorArg integer
--- @param levelNum LevelNum | integer
--- @param func fun(areaIndex:number, bhvData:bhvData, macroBhvIds:BehaviorId[], macroBhvArgs:integer[])
--- @param message string The message to log
--- @param level? ConsoleMessageLevel Optional; Determines whether the message should appear as info, a warning or an error.
--- @return nil
--- When `func` is called, arguments are filled depending on the level command:
--- - `AREA` command: only `areaIndex` is filled. It's a number.
--- - `OBJECT` command: only `bhvData` is filled. `bhvData` is a table with two fields: `behavior` and `behaviorArg`.
--- - `MACRO` command: only `macroBhvIds` and `macroBhvArgs` are filled. `macrobhvIds` is a list of behavior ids. `macroBhvArgs` is a list of behavior params. Both lists have the same size and start at index 0.
function level_script_parse(levelNum, func)
--- Logs a message to the in-game console
function log_to_console(message, level)
-- ...
end

View file

@ -737,7 +737,7 @@ template <typename... Args>
void PrintConsole(const char *aFmt, Args... aArgs) {
snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, aFmt, aArgs...);
sys_swap_backslashes(gDjuiConsoleTmpBuffer);
djui_console_message_create(gDjuiConsoleTmpBuffer);
djui_console_message_create(gDjuiConsoleTmpBuffer, CONSOLE_MESSAGE_INFO);
}
template <typename... Args>
@ -745,7 +745,7 @@ void PrintError(const char *aFmt, Args... aArgs) {
printf(aFmt, aArgs...);
printf("\r\n");
fflush(stdout);
PrintConsole(aFmt, aArgs...);
PrintConsole(aFmt, CONSOLE_MESSAGE_ERROR, aArgs...);
}
#define PrintDataError(...) { \
if (aGfxData->mErrorCount == 0) Print(" ERROR!"); \

View file

@ -12,6 +12,8 @@
- [enum PlayerParts](#enum-PlayerParts)
- [dialog_ids.h](#dialog_idsh)
- [enum DialogId](#enum-DialogId)
- [djui_console.h](#djui_consoleh)
- [enum ConsoleMessageLevel](#enum-ConsoleMessageLevel)
- [djui_hud_utils.h](#djui_hud_utilsh)
- [enum DjuiFontType](#enum-DjuiFontType)
- [enum HudUtilsFilter](#enum-HudUtilsFilter)
@ -1095,6 +1097,19 @@
<br />
## [djui_console.h](#djui_console.h)
### [enum ConsoleMessageLevel](#ConsoleMessageLevel)
| Identifier | Value |
| :--------- | :---- |
| CONSOLE_MESSAGE_INFO | 0 |
| CONSOLE_MESSAGE_WARNING | 1 |
| CONSOLE_MESSAGE_ERROR | 2 |
[:arrow_up_small:](#)
<br />
## [djui_hud_utils.h](#djui_hud_utils.h)
### [enum DjuiFontType](#DjuiFontType)

View file

@ -1357,26 +1357,6 @@
<br />
## [log_to_console](#log_to_console)
### Lua Example
`log_to_console(message)`
### Parameters
| Field | Type |
| ----- | ---- |
| message | `string` |
### Returns
- None
### C Prototype
`void log_to_console(const char* message);`
[:arrow_up_small:](#)
<br />
## [movtexqc_register](#movtexqc_register)
### Lua Example

View file

@ -23,7 +23,7 @@
- [texture_override_reset](#texture_override_reset)
- [smlua_anim_util_register_animation](#smlua_anim_util_register_animation)
- [level_script_parse](#level_script_parse)
- [set_exclamation_box_contents](#set_exclamation_box_contents)
- [log_to_console](#log_to_console)
<br />
@ -1663,7 +1663,6 @@
- [hud_show](functions-5.md#hud_show)
- [is_game_paused](functions-5.md#is_game_paused)
- [is_transition_playing](functions-5.md#is_transition_playing)
- [log_to_console](functions-5.md#log_to_console)
- [movtexqc_register](functions-5.md#movtexqc_register)
- [play_transition](functions-5.md#play_transition)
- [save_file_get_using_backup_slot](functions-5.md#save_file_get_using_backup_slot)
@ -2125,23 +2124,24 @@ Parses a level script and passes area index, behavior data, macro behavior IDs a
<br />
## [set_exclamation_box_new_contents](#set_exclamation_box_new_contents)
## [log_to_console](#log_to_console)
Sets the contents of an exclamation box.
Logs a message to the in-game console.
### Lua Example
`set_exclamation_box_new_contents(contents)`
`log_to_console("sm64coopdx FTW", CONSOLE_MESSAGE_INFO)`
### Parameters
| Field | Type |
| ----- | ---- |
| contents | [ExclamationBoxContents](structs.md#ExclamationBoxContents) |
| message | `string` |
| level | `ConsoleMessageLevel` |
### Returns
- None
### C Prototype
`void set_exclamation_box_new_contents(struct Struct802C0DF0 contents[], u8 size);`
`void log_to_console(const char* message, enum ConsoleMessageLevel level);`
[:arrow_up_small:](#)

View file

@ -52,6 +52,6 @@ static void _debuglog_print_log(const char* logType, char* filename) {
#define LOG_INFO(...) (configDebugInfo ? ( _debuglog_print_log("INFO", __FILE__), printf(__VA_ARGS__), printf("\n") ) : 0)
#define LOG_ERROR(...) (configDebugError ? ( _debuglog_print_log("ERROR", __FILE__), printf(__VA_ARGS__), printf("\n") ) : 0)
#endif
#define LOG_CONSOLE(...) { snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, __VA_ARGS__), djui_console_message_create(gDjuiConsoleTmpBuffer); }
#define LOG_CONSOLE(...) { snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, __VA_ARGS__), djui_console_message_create(gDjuiConsoleTmpBuffer, CONSOLE_MESSAGE_INFO); }
#endif

View file

@ -14,14 +14,16 @@ bool sDjuiConsoleQueueMessages = true;
struct ConsoleQueuedMessage {
char* message;
enum ConsoleMessageLevel level;
struct ConsoleQueuedMessage* next;
};
struct ConsoleQueuedMessage* sConsoleQueuedMessages = NULL;
static void djui_console_message_queue(const char* message) {
static void djui_console_message_queue(const char* message, enum ConsoleMessageLevel level) {
struct ConsoleQueuedMessage* queued = malloc(sizeof(struct ConsoleQueuedMessage));
queued->message = strdup(message);
queued->level = level;
queued->next = NULL;
if (sConsoleQueuedMessages == NULL) {
sConsoleQueuedMessages = queued;
@ -39,7 +41,7 @@ void djui_console_message_dequeue(void) {
struct ConsoleQueuedMessage* entry = sConsoleQueuedMessages;
while (entry) {
struct ConsoleQueuedMessage* next = entry->next;
djui_console_message_create(entry->message);
djui_console_message_create(entry->message, entry->level);
free(entry->message);
free(entry);
entry = next;
@ -101,9 +103,9 @@ static bool djui_console_on_key_down(UNUSED struct DjuiBase* base, int scancode)
return true;
}
void djui_console_message_create(const char* message) {
void djui_console_message_create(const char* message, enum ConsoleMessageLevel level) {
if (sDjuiConsoleQueueMessages || !gDjuiConsole) {
djui_console_message_queue(message);
djui_console_message_queue(message, level);
return;
}
djui_base_compute_tree(&gDjuiConsole->base);
@ -117,7 +119,17 @@ void djui_console_message_create(const char* message) {
djui_base_set_alignment(tBase, DJUI_HALIGN_LEFT, DJUI_VALIGN_BOTTOM);
djui_base_set_size_type(tBase, DJUI_SVT_ABSOLUTE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(tBase, maxTextWidth, 32);
djui_base_set_color(tBase, 220, 220, 220, 255);
switch (level) {
case CONSOLE_MESSAGE_INFO:
djui_base_set_color(tBase, 220, 220, 220, 255);
break;
case CONSOLE_MESSAGE_WARNING:
djui_base_set_color(tBase, 255, 255, 160, 255);
break;
case CONSOLE_MESSAGE_ERROR:
djui_base_set_color(tBase, 255, 160, 160, 255);
break;
}
// figure out chat message height
text->base.comp.width = maxTextWidth;

View file

@ -1,6 +1,12 @@
#pragma once
#include "djui.h"
enum ConsoleMessageLevel {
CONSOLE_MESSAGE_INFO,
CONSOLE_MESSAGE_WARNING,
CONSOLE_MESSAGE_ERROR
};
struct DjuiConsole {
struct DjuiBase base;
struct DjuiFlowLayout* flow;
@ -13,6 +19,6 @@ extern bool gDjuiConsoleFocus;
extern char gDjuiConsoleTmpBuffer[];
void djui_console_message_dequeue(void);
void djui_console_message_create(const char* message);
void djui_console_message_create(const char* message, enum ConsoleMessageLevel level);
void djui_console_toggle(void);
struct DjuiConsole* djui_console_create(void);

View file

@ -20,8 +20,8 @@
#include "pc/debuglog.h"
#include "pc/djui/djui_console.h"
#define LOG_LUA(...) { if (!gSmLuaSuppressErrors) { _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n"), smlua_mod_error(), snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, __VA_ARGS__), djui_console_message_create(gDjuiConsoleTmpBuffer); } }
#define LOG_LUA_LINE(...) { if (!gSmLuaSuppressErrors) { _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n"), smlua_mod_error(); snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, __VA_ARGS__), djui_console_message_create(gDjuiConsoleTmpBuffer), smlua_logline(); } }
#define LOG_LUA(...) { if (!gSmLuaSuppressErrors) { _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n"), smlua_mod_error(), snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, __VA_ARGS__), sys_swap_backslashes(gDjuiConsoleTmpBuffer), djui_console_message_create(gDjuiConsoleTmpBuffer, CONSOLE_MESSAGE_ERROR); } }
#define LOG_LUA_LINE(...) { if (!gSmLuaSuppressErrors) { _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n"), smlua_mod_error(); snprintf(gDjuiConsoleTmpBuffer, CONSOLE_MAX_TMP_BUFFER, __VA_ARGS__), sys_swap_backslashes(gDjuiConsoleTmpBuffer), djui_console_message_create(gDjuiConsoleTmpBuffer, CONSOLE_MESSAGE_ERROR), smlua_logline(); } }
#ifdef DEVELOPMENT
#define LUA_STACK_CHECK_BEGIN() int __LUA_STACK_TOP = lua_gettop(gLuaState)

View file

@ -1313,6 +1313,9 @@ char gSmluaConstants[] = ""
"DIALOG_168 = 168\n"
"DIALOG_169 = 169\n"
"DIALOG_COUNT = 170\n"
"CONSOLE_MESSAGE_INFO = 0\n"
"CONSOLE_MESSAGE_WARNING = 1\n"
"CONSOLE_MESSAGE_ERROR = 2\n"
"RESOLUTION_DJUI = 0\n"
"RESOLUTION_N64 = 1\n"
"RESOLUTION_COUNT = 2\n"

View file

@ -790,6 +790,29 @@ int smlua_func_smlua_anim_util_register_animation(lua_State* L) {
return 1;
}
/////////////
// console //
/////////////
int smlua_func_log_to_console(lua_State* L) {
if (!smlua_functions_valid_param_range(L, 1, 2)) { return 0; }
int paramCount = lua_gettop(L);
const char* message = smlua_to_string(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1"); return 0; }
enum ConsoleMessageLevel level = CONSOLE_MESSAGE_INFO;
if (paramCount >= 2) {
level = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2"); return 0; }
}
djui_console_message_create(message, level);
return 1;
}
//////////
// bind //
//////////
@ -817,4 +840,5 @@ void smlua_bind_functions(void) {
smlua_bind_function(L, "texture_override_reset", smlua_func_texture_override_reset);
smlua_bind_function(L, "level_script_parse", smlua_func_level_script_parse);
smlua_bind_function(L, "smlua_anim_util_register_animation", smlua_func_smlua_anim_util_register_animation);
smlua_bind_function(L, "log_to_console", smlua_func_log_to_console);
}

View file

@ -29253,23 +29253,6 @@ int smlua_func_is_transition_playing(UNUSED lua_State* L) {
return 1;
}
int smlua_func_log_to_console(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 1) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "log_to_console", 1, top);
return 0;
}
const char* message = smlua_to_string(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "log_to_console"); return 0; }
log_to_console(message);
return 1;
}
int smlua_func_movtexqc_register(lua_State* L) {
if (L == NULL) { return 0; }
@ -32868,7 +32851,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "hud_show", smlua_func_hud_show);
smlua_bind_function(L, "is_game_paused", smlua_func_is_game_paused);
smlua_bind_function(L, "is_transition_playing", smlua_func_is_transition_playing);
smlua_bind_function(L, "log_to_console", smlua_func_log_to_console);
smlua_bind_function(L, "movtexqc_register", smlua_func_movtexqc_register);
smlua_bind_function(L, "play_transition", smlua_func_play_transition);
smlua_bind_function(L, "save_file_get_using_backup_slot", smlua_func_save_file_get_using_backup_slot);

View file

@ -81,12 +81,6 @@ void djui_reset_popup_disabled_override(void) {
///
void log_to_console(const char* message) {
djui_console_message_create(message);
}
///
extern s8 gDialogBoxState;
s8 get_dialog_box_state(void) {
return gDialogBoxState;

View file

@ -47,8 +47,6 @@ bool djui_is_popup_disabled(void);
void djui_set_popup_disabled_override(bool value);
void djui_reset_popup_disabled_override(void);
void log_to_console(const char* message);
s8 get_dialog_box_state(void);
s16 get_dialog_id(void);