2

I had been working on a python and tkinter solution to the code golf here: https://codegolf.stackexchange.com/questions/26824/frogger-ish-game/

My response is the Python 2.7 one. The thing is, when I run this code on my 2008 mac pro, everything works fine. When I run it on Win7 (I have tried this on several different machines, with the same result), the main update loop runs way too slowly. You will notice that I designed my implementation with a 1-ms internal clock:

if(self.gameover == False):
 self.root.after(1, self.process_world)

Empirical testing reveals that this runs much, much slower than every 1ms. Is this a well-known Windows 7-specific behavior? I have not been able to find much information about calls to after() lagging behind by this much. I understand that the call is supposed to be executed "at least" after the given amount of time, and not "at most", but I am seeing 1000 update ticks every 20 seconds instead of every 1 second, and a factor of 20 seems excessive. The timer loop that displays the game clock works perfectly well. I thought that maybe the culprit was my thread lock arrangement, but commenting that out makes no difference. This is my first time using tkinter, so I would appreciate any help and/or advice!

Community
  • 1
  • 1
R.T.
  • 121
  • 2
  • It seems more likely that `process_world` simply runs more slowly on your Windows machine. Why not measure the run time for `process_world` on the Mac and on the Windows machine, and compare? – Brionius Jun 02 '14 at 16:55
  • The default Windows timer resolution is ~15ms. Trying to fire a timer every 1ms is not likely to work the way you want, and for a game is probably quite unnecessary (a display running a 60FPS updates only every ~16ms). See http://stackoverflow.com/questions/3744032/why-are-net-timers-limited-to-15-ms-resolution – nobody Jun 02 '14 at 17:08
  • Thanks! I switched it to a 20-ms timer and that solved this perfectly. It revealed some new bugs too, heh, but those were easy to handle :) – R.T. Jun 02 '14 at 18:45

0 Answers0