Ooops
September 29, 2020, 04:06:34 PM

Author Topic: Blitzmax NG SDL mouse events not registering on MacOS  (Read 209 times)

Offline Ashmoor

  • Jr. Member
  • **
  • Posts: 82
Blitzmax NG SDL mouse events not registering on MacOS
« on: August 24, 2020, 03:04:49 PM »
If MouseHit() is used before changing graphics, the following MouseHit() is ignored. It is as if the window loses focus and a click must be made to regain mouse input. If a key triggers graphics change, mouse works fine.

BRL graphics works fine so it's not a general MacOS issue, just a SDL issue. It happens on Windows as well but not as often as on Mac. On Mac every other click is registered, on windows about 7 out of 10 are registered.

Check code below. Am I doing something wrong or is it a problem with the module?

Code: BlitzMax
  1.  
  2. Framework SDL.gl2sdlmax2d
  3. Import brl.jpgloader
  4. Import BRL.PNGLoader
  5. Import brl.Random
  6.  
  7.  
  8. Global fullscreen%=0
  9. Global width:Int=1110
  10. Global height:Int=619
  11.  
  12.  
  13. Graphics width,height,fullscreen
  14. Global mouse_hit_nbr
  15. Repeat
  16.  
  17.         Cls
  18.         SetColor (150,50,20)
  19.         DrawRect (0,0,width,height)
  20.         SetColor(255,255,255)
  21.         DrawMouseCoords()
  22.         Flip
  23.        
  24.         If KeyHit (KEY_ESCAPE) Or AppTerminate() Then End
  25.         If KeyHit (KEY_3) Then
  26.                 fullscreen=Not(fullscreen)
  27.                 EndGraphics()
  28.                 ReInitGraphics()
  29.         EndIf
  30.  
  31.         If MouseHit(1) Then
  32.                 fullscreen=Not(fullscreen)
  33.                 EndGraphics()
  34.                 Local w= 500+Rnd(500)
  35.                 Local h= 300+Rnd(300)
  36.                 Graphics (h,w)
  37.                 mouse_hit_nbr:+1
  38.                 Print "mouse hits : "+mouse_hit_nbr
  39.         EndIf  
  40.                
  41. Forever
  42.  
  43. Function ReInitGraphics()
  44.         If fullscreen=1 Then
  45.                 Graphics 1920,1080,32
  46.         Else
  47.                 Graphics width,height,0
  48.         EndIf
  49.  
  50. EndFunction
  51.  
  52.  
  53. Function DrawMouseCoords()
  54.         Local x%, y%, vx%, vy%
  55.         Local yOffset:Int=200
  56.        
  57.         x=MouseX()
  58.         y=MouseY()
  59.         vx=VirtualMouseX()
  60.         vy=VirtualMouseY()
  61.        
  62.         SetScale(2.0,2.0)
  63.         DrawText("rm:"+x+","+y,10,10+yOffset)
  64.         DrawText("vm:"+vx+","+vy,10,40+yOffset)
  65.         SetScale(1,1)
  66.  
  67. EndFunction
  68.  

Offline Derron

  • Hero Member
  • *****
  • Posts: 3185
Re: Blitzmax NG SDL mouse events not registering on MacOS
« Reply #1 on: August 24, 2020, 04:15:50 PM »
Happens on Linux too... will raise an issue with your example (added brl.randomdefault as import).


bye
Ron

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1911
Re: Blitzmax NG SDL mouse events not registering on MacOS
« Reply #2 on: August 25, 2020, 06:51:48 AM »
well... (my spidy senses are tingling)
mouse and keyboard are events, so... you need to respond to the event system

hit(anything) is not responding to the event system but is tracking a 'moment' in time

so any system that isn't using an event loop as it's main loop will not function correctly (as you thought it might)

hit(anything)is meant for testing is a key or mouse or button is being pressed at the time it is executed. also be aware that keyboards are very strange creatures - some can only register a certain amount of keys pressed at any single time. these are stored and fired through events.

simples :)

Offline Derron

  • Hero Member
  • *****
  • Posts: 3185
Re: Blitzmax NG SDL mouse events not registering on MacOS
« Reply #3 on: August 25, 2020, 09:30:55 AM »
No Adam,

the apps are "polling" for new events ... and then react to it. Eg an SDL event for mouse button is relayed to the "brl system" listener (so that it works for brl and sdl driven apps).
But the SDL event system does NOT see the first mouse button event after the graphics change.

So dunno ... maybe the sdl module does something special during graphics changes ...


bye
Ron

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1911
Re: Blitzmax NG SDL mouse events not registering on MacOS
« Reply #4 on: August 25, 2020, 10:39:43 AM »
Actually Derron you are wrong!

I've been into the code and looked at pollinput to see exactly what is going on:

1. MouseHit and Keyhit are just simple arrays
2. when (behind the scenes) an event occurs, the responding array position is filled true or false
3. at some stage (which ive not bothered to track down) both arrays will be cleared

so at NO stage is the user actually responding to an event. just to the cumulative (internal) events that are filling in the arrays.

Ashmoors program code proves this: the main loop has no event system, just hitkey and hitmouse

how and when the actual events are cleared and stored is being handled by some form of event thread behind the scenes somewhere.

The original question also was mentioning that mouse click (and potentially key presses) were being missed on ALL platforms. this suggests that the (hidden) event framework system is doing what it was programmed to do - it just wasn't programmed well.

To answer Ashmoors correctly (as stated)
you NEED (<-read MUST) be basing your main loop on an event loop. or YOU WILL LOOSE clicks and other events!

OR...

your (hidden) framework loop correctly handles the events and allows the end user to correctly use them.
Such a system would look something like:

setup graphics
programloop()
end

onmousehit() - respond to mouse

onkeyhit() - respond to key

onrender() - draw to screen

I am very fast coming to the conclusion that NG as a language works, but that is all. To make it work proper almost all the mods should be dumped, stripped and rewritten with a clear concept.

Offline Derron

  • Hero Member
  • *****
  • Posts: 3185
Re: Blitzmax NG SDL mouse events not registering on MacOS
« Reply #5 on: August 25, 2020, 11:42:44 AM »
As you correctly stated:
MouseHit reads from an array
An array which is filled by events
Events which are processed "in the background"
Events which SDL "hands in"...

Events which SDL _should_ hand in ...!

it __SHOULD__ do so ... but doesn't do (currently) for the first mouse hit after a graphics change.


It is not a "hidden framework system" which is flawed, but somehow SDL does not receive the event, maybe the sdl window context whatever thing is not set correctly or whatever it is ... it is not a flawed event system "BlitzMax" which uses.


Just use "brl.glmax2d" instead of "sdl.gl2sdlmax2d" (so brl, not sdl) ... and it works:

Code: BlitzMax
  1. SuperStrict
  2.  
  3. 'Framework SDL.gl2sdlmax2d
  4. Framework brl.glmax2d
  5. Import Brl.StandardIO
  6. Import brl.jpgloader
  7. Import BRL.PNGLoader
  8. Import brl.Random
  9. Import Brl.RandomDefault
  10.  
  11. Global fullscreen%=0
  12. Global width:Int=1110
  13. Global height:Int=619
  14.  
  15.  
  16. Graphics width,height,fullscreen
  17. Global mouse_hit_nbr:Int
  18. Repeat
  19.  
  20.         Cls
  21.         SetColor (150,50,20)
  22.         DrawRect (0,0,width,height)
  23.         SetColor(255,255,255)
  24.         DrawMouseCoords()
  25.         Flip
  26.        
  27.         If KeyHit (KEY_ESCAPE) Or AppTerminate() Then End
  28.         If KeyHit (KEY_3) Then
  29.                 fullscreen=Not(fullscreen)
  30.                 EndGraphics()
  31.                 ReInitGraphics()
  32.         EndIf
  33.  
  34.         If MouseHit(1) Then
  35.                 fullscreen=Not(fullscreen)
  36.                 EndGraphics()
  37.                 Local w:Int= 500+Rnd(500)
  38.                 Local h:Int= 300+Rnd(300)
  39.                 Graphics (h,w)
  40.                 mouse_hit_nbr:+1
  41.                 Print "mouse hits : "+mouse_hit_nbr
  42.         EndIf  
  43.                
  44. Forever
  45.  
  46. Function ReInitGraphics()
  47.         If fullscreen=1 Then
  48.                 Graphics 1920,1080,32
  49.         Else
  50.                 Graphics width,height,0
  51.         EndIf
  52.  
  53. EndFunction
  54.  
  55.  
  56. Function DrawMouseCoords()
  57.         Local x%, y%, vx%, vy%
  58.         Local yOffset:Int=200
  59.        
  60.         x=MouseX()
  61.         y=MouseY()
  62.         vx=VirtualMouseX()
  63.         vy=VirtualMouseY()
  64.        
  65.         SetScale(2.0,2.0)
  66.         DrawText("rm:"+x+","+y,10,10+yOffset)
  67.         DrawText("vm:"+vx+","+vy,10,40+yOffset)
  68.         SetScale(1,1)
  69.  
  70. EndFunction
  71.  


There is no need to have event driven system  - you can, but it is not an requirement.



PS: @Ashmoor

Graphics() returns TGraphics ... which has an Resize() method (see below - ResizeGraphics).
Graphics() also calls "EndGraphics()" for you already (no need to do twice)

ResizeGraphics() can be used to resize the current graphics window (for now only working with render backend supporting it).

So not much of use for you now (except for the "EndGraphics" hint).


bye
Ron

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1911
Re: Blitzmax NG SDL mouse events not registering on MacOS
« Reply #6 on: August 25, 2020, 12:23:38 PM »
to quote you Derron:
Quote
The issue with the brl modules on mac is ... that opengl is more or less deprecated and so ... we need to handle that soon anyways. Dunno if there is much benefit in fixing stuff in "brl" if SDL works.

Quote
Just use "brl.glmax2d" instead of "sdl.gl2sdlmax2d" (so brl, not sdl) ... and it works:

So you are saying. "brl doesn't work so use sdl" but "use brl because sdl doesn't work"???

And you then say:
Quote
It is not a "hidden framework system" which is flawed, but somehow SDL does not receive the event, maybe the sdl window context whatever thing is not set correctly or whatever it is ... it is not a flawed event system "BlitzMax" which uses.

and
Quote
it __SHOULD__ do so ... but doesn't do (currently) for the first mouse hit after a graphics change.


so.... to recap....
Which to use as they are both fully working and both completely not working?

Can you see how end users are starting to complain or can't work out why something that should work... doesn't?

Offline Derron

  • Hero Member
  • *****
  • Posts: 3185
Re: Blitzmax NG SDL mouse events not registering on MacOS
« Reply #7 on: August 25, 2020, 12:39:52 PM »
I just said, that - if you used brl.glmax2d, the issue is gone. So it is not the "blitzmax event system" ("the thing in the background") which has a bug ... it is somewhere in sdl.mod
So I used the brl max2d driver to find out if it was a generic issue (eg in max2d) or an sdl one ... seems it only affects sdl ...


I did not say "use brl.glmax2d instead of sdl.glsdlmax2d for your applications".


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal