Skip to content

Commit

Permalink
libretro: Use memset() to set the initial TIC-80 state (#2591)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach authored May 21, 2024
1 parent b255c61 commit ed1de62
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/system/libretro/tic80_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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--;
}

Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit ed1de62

Please sign in to comment.