Mercurial > rinkhals
comparison gamelib/engine.py @ 369:25f7d4824250
Disable timers during move_foxes loop to stop events piling up too much
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 10 Sep 2009 15:18:39 +0000 |
parents | a36ab7dd0eb9 |
children | 463802281182 |
comparison
equal
deleted
inserted
replaced
368:14d49a7d8ffc | 369:25f7d4824250 |
---|---|
214 elif e.type is KEYDOWN and e.key == K_ESCAPE: | 214 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
215 self.dialog = check_exit() | 215 self.dialog = check_exit() |
216 elif e.type is ANIM_ID: | 216 elif e.type is ANIM_ID: |
217 self.game.gameboard.run_animations() | 217 self.game.gameboard.run_animations() |
218 elif e.type is MOVE_FOX_ID: | 218 elif e.type is MOVE_FOX_ID: |
219 # Timer aren't nessecairly ordered, so we make sure | 219 # ensure no timers trigger while we're running |
220 # we don't get a ANIM event until at least cycle after this | 220 pygame.time.set_timer(ANIM_ID, 0) |
221 pygame.time.set_timer(ANIM_ID, self.cycle_time) | 221 pygame.time.set_timer(MOVE_FOX_ID, 0) |
222 # Clear any queued timer events, so we don't full the queue | |
223 pygame.event.clear(ANIM_ID) | |
224 pygame.event.clear(MOVE_FOX_ID) | |
222 # Ensure any outstanding animitions get cleaned up | 225 # Ensure any outstanding animitions get cleaned up |
223 self.game.gameboard.run_animations() | 226 self.game.gameboard.run_animations() |
224 self.cycle_count += 1 | 227 self.cycle_count += 1 |
225 if self.cycle_count > constants.NIGHT_LENGTH: | 228 if self.cycle_count > constants.NIGHT_LENGTH: |
226 return pygame.event.post(START_DAY) | 229 return pygame.event.post(START_DAY) |
227 if self.game.gameboard.move_foxes(): | 230 if self.game.gameboard.move_foxes(): |
228 # All foxes are gone/safe, so dawn happens | 231 # All foxes are gone/safe, so dawn happens |
229 return pygame.event.post(START_DAY) | 232 return pygame.event.post(START_DAY) |
233 # Re-enable timers | |
234 pygame.time.set_timer(ANIM_ID, self.cycle_time) | |
235 pygame.time.set_timer(MOVE_FOX_ID, 4*self.cycle_time) | |
230 elif e.type is not QUIT: | 236 elif e.type is not QUIT: |
231 self.game.main_app.event(e) | 237 self.game.main_app.event(e) |
232 | 238 |
233 def loop(self): | 239 def loop(self): |
234 self.game.gameboard.loop() | 240 self.game.gameboard.loop() |