defold / defold

Defold is a completely free to use game engine for development of desktop, mobile and web games.
https://www.defold.com
Other
4.36k stars 307 forks source link

Add source device field to input action #9320

Open nanaktaev opened 2 months ago

nanaktaev commented 2 months ago

Hi! It's impossible to detect if button_left input trigger was emitted by touchscreen tap or by mouse click. It makes life really tought if you want to support mouse and multitouch screen at the same time (hybrid devices).

What happens:

  1. User touches the screen.
  2. touch_multi action is executed.
  3. AND button_left action is executed also.

I want to ignore button_left action if it's a touchscreen tap since I already process it as a part of touch_multi, but I want to process it independently if it's a mouse click. But there is no way to tell them apart!

Please add a new field to input action so it will be possible to tell the source of it. Something roughly like this:

{ --[[000002394C63C160]]
  -- NEW FIELD HERE
  device = "touchscreen",
  dx = 0,
  dy = 0,
  screen_x = 591,
  screen_y = 395,
  screen_dx = 0,
  screen_dy = 0,
  value = 0,
  pressed = false,
  x = 473.20001220703,
  y = 316.40002441406,
  repeated = false,
  released = true
}

This will allow developer to choose how to process/ignore an action based on the source device.

Alternative solution would be to split button_left trigger into two separate triggers - one for mouse, one for screen touch, but that would be breaking change I guess + it will require to change some manuals.

All the best!

britzl commented 2 months ago

I agree that it might be useful to tag which device generated the action, but I don't really see how it matters much in your case? Don't you want to treat a mouse button or single touch in exactly the same way? And you can keep track of if you've handled it or not by setting a flag in on_input and clearing it in update.

nanaktaev commented 2 months ago

Hi!

Don't you want to treat a mouse button or single touch in exactly the same way?

Actually no. Imagine a situation: You have a world map. You can pinch with two fingers to zoom and click/touch to select something on the map. You make a pinch gesture and two input triggers are fired at this moment: touch-multi leads to zooming logic and touch leads to selection logic, so result is the mix of zoom + selecting something. I would like to ignore touch from the screen during touch-multi gestures, but process touch from mouse at all times.

And you can keep track of if you've handled it or not by setting a flag in on_input and clearing it in update.

But I don't know if incoming touch is a part of touch-multi which is happening at the same time or not. Also probably it's not guaranteed which trigger will come first.

May be it will be enough to just ignore touch if touch-multi is happening the same frame. Is the order of incoming input events guaranteed somehow?