MouseHit() does not work sometimes
BlitzMax Forums/BlitzMax Programming/MouseHit() does not work sometimes
| ||
Any clues why MouseHit() isn't reliable on my pc? It's a dual core machine and very fast, however MouseHit often 'misses' or fails to pick up my clicks. I find I need to call it a LOT in order to get some kind of response from it, as in more than once per loop! I don't have this problem with keyboard input nor do I have a problem with any other games or applications. |
| ||
What if you use mh1=mousehit(1) once each loop? |
| ||
I do this. I have also tried directly calling MouseHit(1) several times. Both require being called several times to get a response on this PC. |
| ||
hmm. In BlitzPlus I got unreliability but this was due me calling it more than once and each call cleans out the buffer (of one hit at least). So in the end I used TonyG's method of only calling once per loop. Also have you used flushmouse anywhere in your loop? If so you might not be giving enough time between the flush and the mousehit for a new hit to be registered. I did this by accident too and it resulted in unreliable mouse performance. |
| ||
One Eyed Jack - how are you synching to the vblank? Maybe the mouse is only polled once a vblank - if you are going two or three flips before a vblank occurs maybe the mouse can miss a call? for example the mouse code in the BMax docs is as follows: ' mousehit.bmx Graphics 640,480 While Not KeyHit(KEY_ESCAPE) Cls If MouseHit(1) DrawRect 0,0,200,200 If MouseHit(2) DrawRect 200,0,200,200 If MouseHit(3) DrawRect 400,0,200,200 Flip Wend if you put a 1 or a 0 after the flip, the mousehit doesnot seem to register all the time and so only occasionally draws the rectangle. Using a -1 seems to get a result though. Just a thought. IPete2. |
| ||
Hi Grey, no flushmouse. IPete2, I am just using Flip without parameters. The game is graphically heavy but there is only one place I call the mouse input gathering routine. I find calling it more often picks up the MouseHit() more frequently. Could it be an issue with dual core cpus? |
| ||
Could be. Did you install the AMD drivers for powersaving (or something like that) from their page? If this is not installed, there are known issues that can cause quite a lot as the time calculation in running apps is incorrect as the stepping / energy saving stuff does not work as the apps assume it does. There is as well a WinXP hotfix that might be needed additionally (although its normally only needed for Intel dualcores). |
| ||
I have installed the hotfix and power saving. |
| ||
Maybe you can post a demo for others to test? |
| ||
I can't post my whole game. |
| ||
What about an .exe (unless it's secret) or a sub section that still shows the symptoms? |
| ||
It's secret (you know how it is)... I have isolated absolutely EVERYTHING! I even removed all the timing code till I had basically Ipete2's code (only it's drawing a lot more) and I'm having this problem with flip 1, 0 or -1... I'm getting sparodic inputs from MouseHit (mousedown seems fine, but then it would be hard to tell with mousedown). |
| ||
If your game has a decent framerate, why not jsut use MouseDown once per frame and set a global variable based on the state? |
| ||
I may just have to do this. It's crazy though? I'm pulling my hair out here man! |
| ||
I hate that kinda crazy technical crap. It drives me mad and wastes soo much time. That's why most peoples plans go to pot, because they don't put in contingency for sh*t like this. |
| ||
Ok after a lot of fiddling about, and also trying events, I've come to the conclusion that mousehit() seems to clear the backlog every time it's called. Thats the problem, I think. |
| ||
OK The more I render, the less responsive the mouse gets, despite the framerate being in the high 500's. MouseX() and MouseY() respond constantly and fine. It's just a problem with mouse buttons. F@@@@:):):)! thing. I'm guessing we'll see more bugs like this as more people make mouse-controlled games. Most people do not make mouse controlled games in Blitzmax presently. |
| ||
oh dear, my next game is mouse controlled. I'll let you know if it cocks up on mine. If not, I'll post a beta for testing. |
| ||
Does it work if your do a PeekEvent? |
| ||
OEJ: Is this perhaps somehow connected to the fake try to get around mouselag? (reinserting a different mouse lag issue) Otherwise, you might try one thing: Let the user decide the FPS. then do the drawing timed (ie if tdiff > 1000/wished_fps renderscene() ) This way you get around 20'000 - 100'000 main loop runs which is even higher than the timer precision and thus should be able to get all mouseevents without any problem. |
| ||
OEJ: Is this perhaps somehow connected to the fake try to get around mouselag? (reinserting a different mouse lag issue) God I hope not! |
| ||
OK The more I render, the less responsive the mouse gets, despite the framerate being in the high 500's. when you say 'render' are you just using basic DrawImage/Text commands? There shouldn't be a reason why it doesn't come out 'sometimes'. I'm currently working on a blitzmax project and I call mousehit() and mousedown() once per loop and it has not been unresponsive, and my render functions have become a bit more complex than the standard blitzmax draws. Try that example that IPete2 posted from the blitzDocs. If that works for you then there's something in your mainloop that is calling mouseHit(). If you happen to be using IGlass btw and call IGL_RefreshGUI() that would cause even ur single mouseHit() call to not work sometimes, because it calls it inside that function. |
| ||
This is why i prefer custom input routines. One "Updateinput" command whenever you need to update it. If mousehit is broken, you can use mousedown in a custom routine to detect it. On a side note, I'm not having any mousedown problems and i'm rendering pretty intensive 3D. [edit] Quckly realised I dont even use the mousehit commands :) |
| ||
Rob, I haven't been able to reproduce your problem here and have double checked module source without any luck. I would try adding a PollSystem at the same point you are flushing the graphics pipe with GrabPixmap. If that fails, you might want to consider sending me a build to see if I can reproduce your problem here. |
| ||
This topic solved mine issue... I use FlushMouse() to make sure after each loop MouseZ() = 0 But I forgot that it had a great effect on all other buttons as well By putting MouseHit() direct above the FlushMouse my game I'm working on works smoothly again |
| ||
Glad you've solved the issue. For future reference, and I think that this was pointed out above somewhere, MouseHit() returns the number of times a mouse button has been pressed since the last time that MouseHit() was called. This count is then reset to 0 (which is why you should only call it once per loop) or when you use FlushMouse. |
| ||
One time I made a game where you slide the numbers around and put them in order. I called Keyhit by saying for example: If (board(0) = 4) And (KeyHit(203)) board(0) = board(1) board(1) = 4 ... EndIf It didn't work. Then I tried saying: If KeyHit(203) Then leftkey = 1 My new code: If (board(0) = 4) And (leftkey = 1) board(0) = board(1) board(1) = 4 ... EndIf It worked. (By the way incase you were wondering, if a tile = 4 it is blank in this program.) So instead of calling MouseHit directly, do what I did with KeyHit. It might work. |
| ||
? |
| ||
? I second that.. |
| ||
This one time.... at band camp.... |
| ||
Ok after a lot of fiddling about, and also trying events, I've come to the conclusion that mousehit() seems to clear the backlog every time it's called. Yes it does. This is the proper behavior. If you call MouseHit() then click the button 10 times, then call Mousehit() again, it is reset to 0, not 9. If for some reason, there is going to be significant time between Mousehit() calls and its possible for the button to be clicked more than once between calls, then you need to check the value returned to determine the number of times it is hit. Something like this. Local NumMouseHits1:Int = 0 ... Local MouseHit1:Int = False If NumMouseHits 'Check to see if Mousehits still need to be processed MouseHit1 = True NumMouseHits :- 1 Else NumMouseHits = MouseHit(1) 'Store number of times Mouse has been pressed since last call If NumMouseHits 'Was the button pressed at least once? MouseHit1 = True NumMouseHits :- 1 End If End If If MouseHit1 'Process Mouse Hits here End If |
| ||
One time I made a game where you slide the numbers around and put them in order. I called Keyhit by saying for example: If (board(0) = 4) And (KeyHit(203)) board(0) = board(1) board(1) = 4 ... EndIf It didn't work. Then I tried saying: If KeyHit(203) Then leftkey = 1 My new code: If (board(0) = 4) And (leftkey = 1) board(0) = board(1) board(1) = 4 ... EndIf It worked. Actually it would have worked if you had typed If KeyHit(203) And (board(0) = 4) You see, if one part of the And is false, then the other part will never get processed, |