nesbox / TIC-80

TIC-80 is a fantasy computer for making, playing and sharing tiny games.
https://tic80.com
MIT License
4.95k stars 479 forks source link

Libretro: no cursor despite `mouse_cursor = "arrow"` #2147

Open Des-Nerger opened 1 year ago

Des-Nerger commented 1 year ago

I've done some tests and now suspect it's the whole drawing mechanism inside void tic80_libretro_mousecursor(...) of tic80_libretro.c that isn't working:

tic_mem* tic = (tic_mem*)state->tic;
...
switch (cursortype) {
...
    case MOUSE_CURSOR_ARROW:
            // Seems to draw into where nothing is seen.
            // Even though mouseX, mouseY and mouseCursorColor looked correct.
            // Perhaps it's the var "tic" that is to blame here.
        tic_api_tri(tic, state->mouseX, state->mouseY, state->mouseX + 3, state->mouseY, state->mouseX, state->mouseY + 3, state->mouseCursorColor);
        tic_api_line(tic, state->mouseX + 3, state->mouseY, state->mouseX, state->mouseY + 3, tic_color_black);
Des-Nerger commented 1 year ago

Ok, I found a fix, even though it's not very efficient:

diff --git a/src/system/libretro/tic80_libretro.c b/src/system/libretro/tic80_libretro.c
index c830d60..fdeb195 100644
--- a/src/system/libretro/tic80_libretro.c
+++ b/src/system/libretro/tic80_libretro.c
@@ -737,8 +737,7 @@ void tic80_libretro_mousecursor(tic80* game, tic80_mouse* mouse, enum mouse_curs
        // Determine which cursor to draw.
        switch (cursortype) {
                case MOUSE_CURSOR_NONE:
-                       // Nothing.
-               break;
+                       return;
                case MOUSE_CURSOR_DOT:
                        tic_api_pix(tic, state->mouseX, state->mouseY, state->mouseCursorColor, false);
                break;
@@ -753,6 +752,7 @@ void tic80_libretro_mousecursor(tic80* game, tic80_mouse* mouse, enum mouse_curs
                        tic_api_line(tic, state->mouseX + 3, state->mouseY, state->mouseX, state->mouseY + 3, tic_color_black);
                break;
        }
+       tic_core_blit(tic);
 }

 /**
nesbox commented 1 year ago

I'm not sure about using tic_core_blit() here, I think you should draw your cursor directly in the screen buffer game->screen

Des-Nerger commented 1 year ago

Yes, that's why I said "it's not very efficient". But then one had to reimplement the functionality of tic_api_tri, tic_api_line and tic_api_pix, basically reduplicating the code for the case of drawing directly to game->screen, which imo isn't a very neat solution either. I think the best way for the libretro core would be to register some kind of event "onBlit", so everytime a .tic game finishes its frame, the cursor is automatically drawn and we would have only one blit call overall. But I don't know if such event system exists in TIC-80. I'm just a user. Anyway, who's maintaining / responsible-for tic80_libretro.c now? Is it still @RobLoach ? Have you guys even tested the cursor functionality before publishing it? What's the point of having those tic80_mouse_cursor* libretro options if a cursor doesn't show up anyway?

RobLoach commented 1 year ago

what's the point....

If the cursor doesn't show up, then a bug appeared somewhere. It did work before.

The code is owned by nesbox. I'm happy to test out any updates though, and push up changes when I'm looking at this thing.