Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another Mouse Issue?
#15
(05-01-2024, 11:42 PM)NakedApe Wrote:
(04-25-2024, 01:40 AM)TerryRitchie Wrote:
(04-25-2024, 01:06 AM)SMcNeill Wrote: Mouse your mouse events outside the update loop:
LOL. Mouse your mouse events, cracked me up. I find myself doing these types of typos all the time.

But Steve is correct, the only thing that should be done within a mouse update loop is gathering scroll wheel events. Here's a demo of that:

Code: (Select All)
SCREEN _NEWIMAGE(800, 600, 32)

radius = 50
DO
    _LIMIT 60
    CLS
    LOCATE 2, 2: PRINT "_MOUSEHWEEL OUTSIDE THE UPDATE LOOP"
    LOCATE 4, 2: PRINT "Use mouse wheel to change size of circle"

    LOCATE 6, 2: PRINT "PRESS ANY KEY TO MOVE _MOUSEWHEEL INSIDE THE LOOP"
    WHILE _MOUSEINPUT: WEND
    radius = radius + _MOUSEWHEEL * 5
    IF radius < 5 THEN radius = 5
    CIRCLE (_MOUSEX, _MOUSEY), radius
    _DISPLAY
LOOP UNTIL INKEY$ <> ""
DO
    _LIMIT 60
    CLS
    LOCATE 2, 2: PRINT "_MOUSEHWEEL NOW INSIDE THE UPDATE LOOP"
    LOCATE 4, 2: PRINT "Use mouse wheel to change size of circle"
    LOCATE 6, 2: PRINT "PRESS ESC TO EXIT"
    WHILE _MOUSEINPUT
        radius = radius + _MOUSEWHEEL * 5
        IF radius < 5 THEN radius = 5
    WEND
    CIRCLE (_MOUSEX, _MOUSEY), radius
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SYSTEM

So I have a question then about the mouse update loop and only putting MouseWheel events inside the While:Wend. I based one of my mouse routines on this, from HELP in the IDE under _MOUSEINPUT:

Code: (Select All)

DO WHILE _MOUSEINPUT 'mouse status changes only
    x = _MOUSEX
    y = _MOUSEY
    IF x > 0 AND x < 640 AND y > 0 AND y < 480 THEN
        IF _MOUSEBUTTON(2) THEN
            PSET (x, y), 15
            LOCATE 1, 1: PRINT x, y
        END IF
    END IF
LOOP

Is this not a proper approach? Is it okay to do this in a DO WHILE: LOOP, but not a WHILE:WEND?  Huh  I mean, it works well...

It's completely unnecessary.   Let's take a few quick code snippets as an example:

DO
  WHILE _MOUSEINPUT
    x = _MOUSEX
  WEND
  _LIMIT 10
LOOP

and compare that to:
DO
  _WHILE _MOUSEINPUT
  WEND
  x = _MOUSEX
  _LIMIT 10
LOOP


Now, let's grab our mouse and drag it all across the screen from point 0,0 to point 1000,1000 in exactly 1 second.  Since we're using the Steve Virtual Mouse(tm) which updates 100 times per second, we can calculate exactly how far that mouse moves in .1 seconds.

0,0 to 10,10
to 20,20
to 30,30
to 40,40
to 50,50
to 60,60
to 70,70
to 80,80
to 90,90
to 100,100

.... and since we're running our main program with a _LIMIT 10, we know we're only going to get .1 second worth of data in each of the main loops that those WHILE... WEND are going to process.

Now, the first routine runs, and it...
WHILE _MOUSEINPUT:
assigns x the value of 10
assigns x the value of 20
assigns x the value of 30
assigns x the value of 40
assigns x the value of 50
assigns x the value of 60
assigns x the value of 70
assigns x the value of 80
assigns x the value of 90
assigns x the value of 100
WEND  (we're now out of cached data)
x is a value of 100!


And the second routine runs and it:
WHILE _MOUSEINPUT
WEND (update all those values in the background)
x = 100 (the last value which _mouseinput updated for us)


Now, which of those are going to run smoother and perform better??
Reply


Messages In This Thread
Another Mouse Issue? - by NakedApe - 04-25-2024, 12:54 AM
RE: Another Mouse Issue? - by SMcNeill - 04-25-2024, 01:06 AM
RE: Another Mouse Issue? - by TerryRitchie - 04-25-2024, 01:40 AM
RE: Another Mouse Issue? - by NakedApe - 05-01-2024, 11:42 PM
RE: Another Mouse Issue? - by SMcNeill - 05-02-2024, 12:23 AM
RE: Another Mouse Issue? - by Pete - 04-25-2024, 01:27 AM
RE: Another Mouse Issue? - by bplus - 04-25-2024, 01:42 AM
RE: Another Mouse Issue? - by TerryRitchie - 04-25-2024, 02:08 AM
RE: Another Mouse Issue? - by NakedApe - 04-25-2024, 02:16 AM
RE: Another Mouse Issue? - by TerryRitchie - 04-25-2024, 05:33 AM
RE: Another Mouse Issue? - by a740g - 04-26-2024, 02:23 AM
RE: Another Mouse Issue? - by bplus - 04-25-2024, 11:50 AM
RE: Another Mouse Issue? - by NakedApe - 04-25-2024, 04:11 PM
RE: Another Mouse Issue? - by TerryRitchie - 04-25-2024, 05:43 PM
RE: Another Mouse Issue? - by NakedApe - 04-26-2024, 06:19 AM
RE: Another Mouse Issue? - by TerryRitchie - 05-02-2024, 12:31 AM
RE: Another Mouse Issue? - by SMcNeill - 05-02-2024, 12:31 AM
RE: Another Mouse Issue? - by NakedApe - 05-02-2024, 03:16 AM



Users browsing this thread: 1 Guest(s)