Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjlew <jlew.blackout@gmail.com>2010-06-28 21:52:40 (GMT)
committer jlew <jlew.blackout@gmail.com>2010-06-28 21:52:40 (GMT)
commit721d43756cf45596a2968ae9e01c3c0357b73a07 (patch)
tree07d80032238964f17104aff83cba8d0089bce06f
parentbf007b892cd8e2aaf6f9a565ae3f166e53716501 (diff)
Added a lock over the draw and event loops (ticket #29)
There is an issue that changing values from the event loop while in mid draw can cause some crazy frames until the next static frame is drawn. So this commit adds a lock over the even loops and the draw loops that prevents python from stealing the thread while drawing or modifying internal variables that are used by the drawing methods. Question: Should I instead implement a game engine locking system so that the event can lock only on its drawing portion or leave it over the entire draw/update process.
-rw-r--r--MAFH2/fortuneengine/GameEngine.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/MAFH2/fortuneengine/GameEngine.py b/MAFH2/fortuneengine/GameEngine.py
index 864761f..477bd07 100644
--- a/MAFH2/fortuneengine/GameEngine.py
+++ b/MAFH2/fortuneengine/GameEngine.py
@@ -15,7 +15,7 @@
import pygame
import inspect
-from threading import Thread
+from threading import Thread, Lock
from GameEngineConsole import GameEngineConsole
@@ -55,6 +55,8 @@ class GameEngine(object):
# TODO Allow mouse motion on request
pygame.event.set_blocked(pygame.MOUSEMOTION)
+ self.event_lock = Lock()
+
def start_event_timer(self, id, time):
"""
Starts a timer that fires a user event into the queue every "time"
@@ -125,10 +127,11 @@ class GameEngine(object):
pygame.display.flip()
else:
+ self.event_lock.acquire()
for fnc in self.__draw_lst:
fnc(self.screen)
- self.console.draw()
+ self.event_lock.release()
pygame.display.flip()
def _event_loop(self):
@@ -154,10 +157,12 @@ class GameEngine(object):
# Reverse list so that newest stuff is on top
list_cp.reverse()
+ self.event_lock.acquire()
for cb in list_cp:
# Fire the event for all in cb and stop if return True
if cb(event) == True:
break
+ self.event_lock.release()
def stop_event_loop(self):
"""