Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse updates are only provided if the mouse vector is set #14

Open
hikari-no-yume opened this issue Jul 2, 2023 · 17 comments
Open

Mouse updates are only provided if the mouse vector is set #14

hikari-no-yume opened this issue Jul 2, 2023 · 17 comments

Comments

@hikari-no-yume
Copy link

hikari-no-yume commented Jul 2, 2023

Or at least, I think that's what's going on? oneko-uxn's first release doesn't work for this reason: I only check the mouse inputs in the screen vector, and never set the mouse vector. Should I not be doing that? I guess it'd be easy to change my code to be compatible with uxn32, but I'm kinda worried about this being a potential compatibility issue in general.

@hikari-no-yume
Copy link
Author

/cc @neauoire: the varvara docs don't seem to say anything about whether this is correct or not.

@neauoire
Copy link
Contributor

neauoire commented Jul 2, 2023

The keyboard and mouse should still be accessible even if vectors are not set. Inversely, you should still be able to get a valid screen size from within the mouse event, even if there are no screen vector set.

I'll add a note on the docs to make this explicit.

@randrew
Copy link
Owner

randrew commented Jul 2, 2023

The keyboard and mouse should still be accessible even if vectors are not set. Inversely, you should still be able to get a valid screen size from within the mouse event, even if there are no screen vector set.

When I implemented the mouse handling in Uxn32, I'm pretty sure I talked to you on IRC and we agreed that the behavior of Uxn32 is fine. The emulator doesn't need to provide mouse position if the mouse vector isn't set. Uxn32 is designed around this, and if the mouse vector isn't set, the mouse cursor operates in an alternate mouse mode where the host cursor isn't hidden and doesn't invoke input events to the emulator and executing ROM code.

If your game needs to use the mouse, you need to at least set a dummy routine to the mouse vector to instruct the emulator to track and capture or hide the host mouse cursor. If you set a routine that just returns, you will be able to get the mouse cursor position in the screen update routine from the mouse device, even if you don't handle the mouse input in the mouse routine/vector.

I can't easily change this code in Uxn32.

@hikari-no-yume
Copy link
Author

Hmm… I mean, I doubt I'm the first or the last person to write code that works this way. Wouldn't it be possible to detect use of DEI on the mouse values and enable mouse input anyway?

@randrew
Copy link
Owner

randrew commented Jul 2, 2023

That seems even weirder, doesn't it?

@randrew
Copy link
Owner

randrew commented Jul 2, 2023

You probably are the first person to run into this problem, though. You need to at least set a routine to the mouse vector, even if all it does is BRK. Otherwise, Uxn32 doesn't know to hide the standard Windows mouse cursor and do the work for dealing with the mouse.

@neauoire
Copy link
Contributor

neauoire commented Jul 2, 2023 via email

@randrew
Copy link
Owner

randrew commented Jul 3, 2023

I think those two things are compatible. It might even be the best way to do it. Set mouse vector to try to use it -> get a an error flag set somewhere, now the ROM knows it can't use the mouse and uses some other input method.

@hikari-no-yume
Copy link
Author

A few thoughts.

Speaking about programming in general, rather than just uxn, I think it is common, or at least not rare, that people write programs that poll for events during drawing, rather than actually using event handlers. I have a few reasons to think this:

  • I've done this in several of my own games for systems other than uxn.
  • The way it lets you put everything in one function (drawing, input handling and game logic) is very convenient and natural in my opinion.
  • It is the straightforward way to do things when implementing an immediate-mode GUI system, which is a popular approach in game development.

Considering all that, suppose you're writing an uxn app and you feel like using polling. You write a screen vector that draws something, and now you want to add input handling. Since varvara lets you directly read the mouse and controller values outside their vectors with DEI/DEI2, you just add those to your screen vector, and it works fine in uxnemu, the original and most popular emulator. Since you don't have a need for the other vectors, and there is no specific guidance in the documentation, you don't even think about setting them. That's exactly the trap I fell into, and I can only assume many other people could stumble into it also.

At the very least, I think this kind of requirement should be documented. But considering people will often miss that something is de jure wrong if it de facto works when they try it, it would be better if the emulator behaviour would prevent you from making a program that accidentally works in some emulators. Some options:

  • If we want to allow this pattern, then Uxn32 can accommodate it by detecting use of DEI to read the mouse/controller device.
  • If we want to disallow this pattern, then either:
    • emulators should be required to return 0 for use of DEI on the mouse/controller state unless their respective vectors are set
    • emulators should be required to return 0 for the use of DEI on the mouse/controller state when this happens outside the respective vector

A more radical solution would be to not use DEI at all for inputs that require vectors: what if the mouse X and Y (etc) were pushed onto the stack before calling the mouse vector? But that would break all the existing software…


Re: being able to check if setting the mouse vector worked, I can see that being useful. I think a reasonable way to allow that would be to return 0000 if the vector is read back.

@neauoire
Copy link
Contributor

neauoire commented Jul 3, 2023 via email

@hikari-no-yume
Copy link
Author

For oneko-uxn I'll probably implement an actual mouse vector anyway, because it's more efficient (no unnecessary “has the mouse moved” check every frame), it can give more responsive movement in emulators like Uxn32 that support >60Hz mouse updates, and it will be easier to support a gamepad this way. That it fixes Uxn32 in the process is a nice bonus.

@randrew
Copy link
Owner

randrew commented Jul 3, 2023

Uxn32 will have to be modified to support this

It will have to be redesigned to support this. And there will need to be some way to recognize if the Uxn ROM program is drawing a mouse cursor or not, somehow. Because losing the mouse cursor when the user mouses over the window isn't a desirable behavior for a desktop program. At least not in Windows.

@randrew
Copy link
Owner

randrew commented Jul 3, 2023

Well, maybe it's OK to just lose the mouse cursor? I don't know. Maybe it's fine.

@neauoire
Copy link
Contributor

neauoire commented Jul 4, 2023 via email

@randrew
Copy link
Owner

randrew commented Jul 4, 2023 via email

@hikari-no-yume
Copy link
Author

hikari-no-yume commented Jul 4, 2023

Is there any reason detecting DEI/DEI2 use on the mouse ports wouldn't work? I suppose you could make a ROM that does read the mouse co-ords but doesn't draw its own cursor, but considering uxnemu's behaviour I don't think that needs to be worried about.

@randrew
Copy link
Owner

randrew commented Jul 5, 2023

It would work, but it's a bit weird. I wouldn't expect reading from an apparently read-only location to have such large external effects as hiding the mouse cursor for the end user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants