Fixes and quality of life changes (#213)

Add the Lua Profiler to the debug menu.
    Prevent Mario from sleeping on the main menu.
    Fix IP address string corruption when saving the config file.
    Bring back the Discord fatal message.
This commit is contained in:
Isaac0-dev 2022-10-31 10:29:59 +10:00 committed by GitHub
parent b2eb76ec32
commit e387b6b24b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 54 additions and 42 deletions

View file

@ -99,6 +99,8 @@ EXTRA_CFLAGS ?=
EXTRA_CPP_FLAGS ?=
EXTRA_CFLAGS += -Wno-format-security -Wno-trigraphs
dev:; @$(MAKE) DEBUG=1 DEVELOPMENT=1
# COMPILER - selects the C compiler to use
# gcc - uses the GNU C Compiler
COMPILER = gcc

View file

@ -534,8 +534,11 @@ void render_hud(void) {
}
#if defined(LUA_PROFILER)
extern void lua_profiler_update_counters();
lua_profiler_update_counters();
extern bool configLuaProfiler;
if (configLuaProfiler) {
extern void lua_profiler_update_counters();
lua_profiler_update_counters();
}
#endif
}
}

View file

@ -123,11 +123,17 @@ s32 act_idle(struct MarioState *m) {
return TRUE;
}
extern bool gDjuiInMainMenu;
if (m->actionState == 3) {
if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SNOW) {
return set_mario_action(m, ACT_SHIVERING, 0);
} else {
return set_mario_action(m, ACT_START_SLEEPING, 0);
if (!gDjuiInMainMenu) {
return set_mario_action(m, ACT_START_SLEEPING, 0);
} else {
m->actionState = 0;
m->actionTimer = 0;
}
}
}

View file

@ -144,6 +144,9 @@ bool configDisablePopups = 0;
#ifdef DEVELOPMENT
bool configDisableDevPause = 1;
#endif
#ifdef LUA_PROFILER
bool configLuaProfiler = 1;
#endif
bool configDisableDownloadedModels = 0;
unsigned int configInterpolationMode = 1;
unsigned int configGamepadNumber = 0;
@ -237,6 +240,9 @@ static const struct ConfigOption options[] = {
{.name = "disable_popups", .type = CONFIG_TYPE_BOOL , .boolValue = &configDisablePopups},
#ifdef DEVELOPMENT
{.name = "disable_devpause", .type = CONFIG_TYPE_BOOL , .boolValue = &configDisableDevPause},
#endif
#ifdef LUA_PROFILER
{.name = "lua_profiler", .type = CONFIG_TYPE_BOOL , .boolValue = &configLuaProfiler},
#endif
{.name = "disable_downloaded_models", .type = CONFIG_TYPE_BOOL , .boolValue = &configDisableDownloadedModels},
{.name = "interpolation_mode", .type = CONFIG_TYPE_UINT , .uintValue = &configInterpolationMode},

View file

@ -101,6 +101,9 @@ extern bool configDisablePopups;
#ifdef DEVELOPMENT
extern bool configDisableDevPause;
#endif
#ifdef LUA_PROFILER
extern bool configLuaProfiler;
#endif
extern bool configDisableDownloadedModels;
extern unsigned int configInterpolationMode;

View file

@ -5,6 +5,7 @@
#include "src/pc/controller/controller_mouse.h"
#include "src/pc/controller/controller_keyboard.h"
#include "src/pc/utils/misc.h"
#include "pc/network/network.h"
#include "sounds.h"
#include "audio/external.h"
@ -223,7 +224,7 @@ bool djui_interactable_on_key_down(int scancode) {
if (gDjuiPlayerList != NULL || gDjuiModList != NULL) {
for (int i = 0; i < MAX_BINDS; i++) {
if (scancode == (int)configKeyPlayerList[i]) {
if (scancode == (int)configKeyPlayerList[i] && !gDjuiInMainMenu && gNetworkType != NT_NONE) {
if (gDjuiPlayerList != NULL) {
djui_base_set_visible(&gDjuiPlayerList->base, true);
}

View file

@ -118,9 +118,7 @@ static void djui_panel_join_ip_text_set_new(void) {
}
}
gGetHostName = buffer;
printf("gGetHostName: %s\n", gGetHostName); /* Log the value of gGetHostName.
For some reason this fixes some formatting issues? LOG_INFO isn't working at all in this file. */
snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", buffer);
if (snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", buffer) < 0) {
LOG_INFO("truncating IP");
}

View file

@ -22,6 +22,13 @@ void djui_panel_options_debug_create(struct DjuiBase* caller) {
djui_base_set_size(&checkbox2->base, 1.0f, 32);
defaultBase = &checkbox2->base;
#ifdef LUA_PROFILER
struct DjuiCheckbox* checkbox3 = djui_checkbox_create(&body->base, "Lua Profiler", &configLuaProfiler);
djui_base_set_size_type(&checkbox3->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&checkbox3->base, 1.0f, 32);
defaultBase = &checkbox3->base;
#endif
struct DjuiButton* button2 = djui_button_create(&body->base, "Back");
djui_base_set_size_type(&button2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button2->base, 1.0f, 64);

View file

@ -39,13 +39,11 @@ static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult res
discord_network_init(lobby->id);
discord_activity_update(false);
if (gNetworkType == NT_CLIENT) {
if (gNetworkPlayerServer == NULL) {
network_player_connected(NPT_SERVER, 0, 0, &DEFAULT_MARIO_PALETTE, "Player");
}
ns_discord_save_id(gNetworkPlayerServer->localIndex, lobby->owner_id);
network_send_mod_list_request();
if (gNetworkPlayerServer == NULL) {
network_player_connected(NPT_SERVER, 0, 0, &DEFAULT_MARIO_PALETTE, "Player");
}
ns_discord_save_id(gNetworkPlayerServer->localIndex, lobby->owner_id);
network_send_mod_list_request();
gNetworkUserIds[0] = lobby->owner_id;
}

View file

@ -21,23 +21,22 @@ static int64_t applicationId = 752700005210390568;
struct DiscordApplication app = { 0 };
bool gDiscordInitialized = false;
bool gDiscordFailed = false;
static int already_run = 0;
bool alreadyRun = false;
static void discord_sdk_log_callback(UNUSED void* hook_data, enum EDiscordLogLevel level, const char* message) {
LOGFILE_INFO(LFT_DISCORD, "callback (%d): %s", level, message);
}
void discord_fatal_message(int rc) {
return; // Discord usually does this because of loss of connection to Discord
void discord_fatal_message(int rc) { // Discord usually does this because of loss of connection to Discord
char errorMessage[132] = { 0 };
snprintf(errorMessage, 132, "Discord threw an error.\nTo fix: \n1. Close the game.\n2. Restart Discord.\n3. Start the game.\nRC: %d", rc);
snprintf(errorMessage, 132, "Discord threw an error.\nTo fix, try: \n1. Close the game.\n2. Restart Discord.\n3. Start the game.\nRC: %d", rc);
djui_popup_create(errorMessage, 6);
}
void discord_fatal(int rc) {
if (already_run == 0) {
already_run = 1;
if (!alreadyRun) {
discord_fatal_message(rc);
alreadyRun = true;
}
if (rc != DiscordResult_Ok) {

View file

@ -251,7 +251,7 @@ void network_send_to(u8 localIndex, struct Packet* p) {
memcpy(&p->buffer[p->dataLength], &hash, sizeof(u32));
// redirect to server if required
if (localIndex != 0 && gNetworkType != NT_SERVER && gNetworkSystem->requireServerBroadcast) {
if (localIndex != 0 && gNetworkType != NT_SERVER && gNetworkSystem->requireServerBroadcast && gNetworkPlayerServer != NULL) {
localIndex = gNetworkPlayerServer->localIndex;
}

View file

@ -380,6 +380,14 @@ void network_receive_player(struct Packet* p) {
network_player_disconnected(np->localIndex);
}
}
#else
if (m->action == ACT_DEBUG_FREE_MOVE && oldData.action != ACT_DEBUG_FREE_MOVE) {
char *playerColorString = network_get_player_text_color_string(np->localIndex);
char message[256];
snprintf(message, 256, "%s%s\\#dcdcdc\\ entered the debug free fly state", playerColorString, np->name);
djui_popup_create(message, 1);
LOG_INFO("%s entered the debug free fly state", np->name);
}
#endif
}

View file

@ -10,7 +10,7 @@
#include <netdb.h>
#endif
char *gGetHostName = NULL;
char gGetHostName[MAX_CONFIG_STRING] = "";
void domain_resolution(void) {
struct in_addr addr;
@ -18,10 +18,6 @@ void domain_resolution(void) {
struct hostent *remoteHost;
char *domainname = "";
if (gGetHostName == NULL) {
return;
}
int i = 0;
remoteHost = gethostbyname(host_name);
if (remoteHost == NULL) {
@ -36,10 +32,3 @@ void domain_resolution(void) {
}
}
}
void save_domain(void) {
if (gGetHostName != NULL) {
snprintf(configJoinIp, 256, "%s", gGetHostName);
gGetHostName = NULL;
}
}

View file

@ -92,7 +92,7 @@ static bool ns_socket_initialize(enum NetworkType networkType) {
domain_resolution();
sAddr[0].sin_addr.s_addr = inet_addr(configJoinIp);
LOG_INFO("connecting to %s %u", configJoinIp, port);
save_domain();
snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", gGetHostName);
}
// kick off first packet

View file

@ -10,7 +10,7 @@
#include "../network.h"
extern struct NetworkSystem gNetworkSystemSocket;
extern char *gGetHostName;
extern char gGetHostName[MAX_CONFIG_STRING];
SOCKET socket_initialize(void);
void socket_shutdown(SOCKET socket);

View file

@ -1,9 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef _WIN32
#include <signal.h>
#endif
#include "sm64.h"
@ -392,11 +389,6 @@ void main_func(void) {
}
int main(int argc, char *argv[]) {
#ifndef _WIN32
#ifdef SIGINT
signal(SIGINT, inthand);
#endif
#endif
parse_cli_opts(argc, argv);
main_func();
return 0;