[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Speed of mouse position capture



[snip]
[embarrassed] I don't know how to multi thread. Will try using DirectX,
failing that will investigate multi threading (can you point me to a
good reference?)
I don't know how to use threads very well either.
I made a real hack-and-slash example, calling pygame.mouse.get_pos() as fast as possible while updating a tiny part of the screen and
flushing the event queue.
Guess what happened?
Yep, you guessed it.
From the generated file the program created:
>Number of mousepos calls executed: 1253492
Hmm, it called the function 1,000,000 times and the program only ran < 10 seconds.
I moved my mouse around crazily and slowly both.
It must have gotten all those mouse motion events perfectly! you exclaim as you exhale, breathless with excited anticipation.
sadly, no! I reply.
there are only about 100 captured *different* mouse positions in the file.
I didn't bother filling the file with events that were the same as a previous position because this isn't really movement, now is it?


So the conclusion I've come to is that the other guy is right, and you'll need to DirectInput it or something.
file attached, code inexplicably raises errors.
It was, how do you say, my first endeavor into threading, and unsuccessful I contend.


Aside:
I couldn't figure out how to do this threading stuff without dummy arguments to the grabmousepos function.
does anyone know why this is?
Advice such as "use threading instead of thread" welcome but I'd like
an explanation of the reason they expect my function to want a tuple.


Brian
"The information contained in this transmission is confidential. It is intended for the named address only. If you are not the named address you may not copy, distribute or take any action in reliance upon this transmission"

ooh a disclaimer.
Even better, you could use KSchnee's program to stenographize that message into your "Brian" sig, and no one would ever know!
except since the text is solid black and the background's solid white, there might be some noticeable artifacts. Not too sure if you could
discern the slight color differences or not.
Anyway, cheers.
-Luke


P.S. I am happy and so I'm saying so.
Thanks for reading about my happiness.
import pygame
from pygame.locals import *
import thread
pygame.display.init()

screen = pygame.display.set_mode((640,480))


mousepositionsinpast = []
global calls
calls = 0
def grabmousepos(a,b):
    global calls
    previnput = pygame.mouse.get_pos()
    while 1:
        calls += 1
        val = pygame.mouse.get_pos()
        if val != previnput:
            mousepositionsinpast.append("(%s,%s)\n" % val)
            previnput = val

thread1 = thread.start_new_thread(grabmousepos,(1,1))
while 1:
    pygame.display.update((0,0,5,5))
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                f = file("mousemovements.txt","w")
                mousepositionsinpast.append("Number of mousepos calls executed: %s\n" % calls)
                f.writelines(mousepositionsinpast)
                f.close()
                raise SystemExit