TIC-80 icon indicating copy to clipboard operation
TIC-80 copied to clipboard

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

Open Des-Nerger opened this issue 2 years ago • 4 comments

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 avatar Feb 28 '23 12:02 Des-Nerger

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);
 }
 
 /**

Des-Nerger avatar Feb 28 '23 13:02 Des-Nerger

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

nesbox avatar Mar 01 '23 08:03 nesbox

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?

Des-Nerger avatar Mar 11 '23 03:03 Des-Nerger

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.

RobLoach avatar Mar 11 '23 04:03 RobLoach