From ed1de6264066d59311769e507ec6ea9cdac0740e Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Tue, 21 May 2024 08:42:52 -0400 Subject: [PATCH] libretro: Use memset() to set the initial TIC-80 state (#2591) --- src/system/libretro/tic80_libretro.c | 31 +++++++++++----------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/system/libretro/tic80_libretro.c b/src/system/libretro/tic80_libretro.c index 9d6512032..0239d5608 100644 --- a/src/system/libretro/tic80_libretro.c +++ b/src/system/libretro/tic80_libretro.c @@ -125,7 +125,7 @@ void tic80_libretro_error(const char* info) if (environ_cb) { struct retro_message msg = { info, - 400 + 6 * TIC80_FRAMERATE }; environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); } @@ -176,23 +176,12 @@ RETRO_API void retro_init(void) return; } - // Initialize the base state. + // Initialize the base state with some default values. state = (struct tic80_state*) malloc(sizeof(struct tic80_state)); - state->quit = false; - state->cropBorder = false; - state->pointerDevice = POINTER_DEVICE_MOUSE; + memset(state, 0, sizeof(struct tic80_state)); state->pointerSpeed = 1.0f; - state->slowGamepadMouse = false; - state->mouseCursor = MOUSE_CURSOR_NONE; state->mouseCursorColor = 15; state->analogDeadzone = (int)(0.15f * (float)RETRO_ANALOG_RANGE); - state->mouseX = 0; - state->mouseY = 0; - state->mousePreviousX = 0; - state->mousePreviousY = 0; - state->mouseXAccumulator = 0.0f; - state->mouseYAccumulator = 0.0f; - state->mouseHideTimer = state->mouseHideTimerStart; // Initialize the keyboard mappings. state->keymap[RETROK_UNKNOWN] = tic_key_unknown; @@ -766,7 +755,7 @@ void tic80_libretro_update_mouse(tic80_mouse* mouse) state->mousePreviousX = state->mouseX; state->mousePreviousY = state->mouseY; } - if (state->mouseHideTimer > 0) { + else if (state->mouseHideTimer > 0) { state->mouseHideTimer--; } @@ -782,14 +771,16 @@ void tic80_libretro_update_mouse(tic80_mouse* mouse) void tic80_libretro_mousecursor(tic80* game, tic80_mouse* mouse, enum mouse_cursor_type cursortype) { TIC_UNUSED(mouse); + // Only draw the mouse cursor if it's active. - if (state->mouseHideTimer == 0) { + if (state->mouseHideTimerStart > 0 && state->mouseHideTimer == 0) { return; } tic_mem* tic = (tic_mem*)state->tic; - // Determine which cursor to draw. + // Draw the cursor. + // TODO: Fix the cursor not being drawn on the screen by possibly modifing game->screen directly. switch (cursortype) { case MOUSE_CURSOR_NONE: // Nothing. @@ -974,16 +965,18 @@ void tic80_libretro_variables(bool startup) } // Mouse Hide Delay - state->mouseHideTimerStart = -1; + state->mouseHideTimerStart = 0; var.key = "tic80_mouse_hide_delay"; var.value = NULL; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { state->mouseHideTimerStart = atoi(var.value); if (state->mouseHideTimerStart > 0) { state->mouseHideTimerStart = state->mouseHideTimerStart * TIC80_FRAMERATE; + state->mouseHideTimer = state->mouseHideTimerStart; } else { - state->mouseHideTimerStart = -1; + state->mouseHideTimerStart = 0; + state->mouseHideTimer = 0; } }