From: <Blu...@us...> - 2010-09-01 17:41:11
|
Revision: 386 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=386&view=rev Author: BlueWolf_ Date: 2010-09-01 17:41:05 +0000 (Wed, 01 Sep 2010) Log Message: ----------- Limited the FPS to 50 and also fixed the update-function blocking too much code (which dropped the framerate dramatically) Modified Paths: -------------- trunk/client/VP.py trunk/client/functions.py trunk/client/playground.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-09-01 15:37:21 UTC (rev 385) +++ trunk/client/VP.py 2010-09-01 17:41:05 UTC (rev 386) @@ -114,30 +114,20 @@ and update the screen """ - # The following code will prevent it from going crazy on the cpu. - # aka: using unlimited FPS. This will limit the FPS to 50 and will - # remember everything that should be updated in the mean time - - self.updaterect.append(Rect(rect)) + # When something updates due to a timer-update, nothing will be updated + # as long as the frame is still being rendered. Instead, the rect will + # be saved and will be updated once the timer has finished this frame if self.updatewaiting: - # Rect is saved. Will be updated once self.clock stops blocking + self.updaterect.append(Rect(rect)) return - # When there are more updates from here one, they will be saved without - # being updated immediately. We will do that once tick stops blocking - self.updatewaiting = True - self.clock.tick(UPDATE_FPS) - # Get all the rects to update - if len(self.updaterect) == 1: - rects = self.updaterect[0] - else: - rects = self.updaterect[0].unionall(self.updaterect[1:]) + if type(rect) == list: + if len(rect) == 1: + rect = rect[0] + else: + rect = rect[0].unionall(rect[1:]) - self.updaterect = [] - self.updatewaiting = False - - # The actual updating happens here sh['screen'].blit(sh['playground'].surf, rect, rect) sh['screen'].blit(sh['layout'].surf, rect, rect) @@ -152,7 +142,7 @@ class Timer(): """ - This timer will update every 33ms (30fps) ones called + This timer will update every frame as defined in UPDATE_FPS @ functions.py """ def __init__(self): self.speed = 1/float(UPDATE_FPS) @@ -177,10 +167,22 @@ self.timer = None def update(self): + # Stop blitting to the screen + sh['main'].updaterect = [] + sh['main'].updatewaiting = True + + # Do stuff for name, info in self.callers.items(): if info[0](name, *info[1]): del self.callers[name] + # Force one big update + sh['main'].updatewaiting = False + if sh['main'].updaterect != []: + sh['main'].update(sh['main'].updaterect) + sh['main'].updaterect = [] + + # Start the next timer if self.callers != {}: self.timer = threading.Timer(self.speed, self.update) Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-09-01 15:37:21 UTC (rev 385) +++ trunk/client/functions.py 2010-09-01 17:41:05 UTC (rev 386) @@ -24,7 +24,7 @@ SERVER = ("vp.bluewolf.nl", 6653) -UPDATE_FPS = 100 +UPDATE_FPS = 50 # This will be used to [sh]are all variables, functions and classes across the # code Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-01 15:37:21 UTC (rev 385) +++ trunk/client/playground.py 2010-09-01 17:41:05 UTC (rev 386) @@ -61,25 +61,25 @@ if ev.type == KEYDOWN: if ev.key == K_UP and self.direction_pressed != 0: self.direction_pressed = 0 - sh['timer'].start("playground_move", self.playground_move, \ + sh['timer'].start("playground-move", self.playground_move, \ time.time(), self.viewport.top, 0) elif ev.key == K_DOWN and self.direction_pressed != 1: self.direction_pressed = 1 - sh['timer'].start("playground_move", self.playground_move, \ + sh['timer'].start("playground-move", self.playground_move, \ time.time(), self.viewport.top, 1) elif ev.key == K_LEFT and self.direction_pressed != 2: self.direction_pressed = 2 - sh['timer'].start("playground_move", self.playground_move, \ + sh['timer'].start("playground-move", self.playground_move, \ time.time(), self.viewport.left, 2) elif ev.key == K_RIGHT and self.direction_pressed != 3: self.direction_pressed = 3 - sh['timer'].start("playground_move", self.playground_move, \ + sh['timer'].start("playground-move", self.playground_move, \ time.time(), self.viewport.left, 3) elif ev.type == KEYUP: if ev.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]: self.direction_pressed = None - sh['timer'].stop("playground_move") + sh['timer'].stop("playground-move") def call(self, name, data): @@ -89,6 +89,7 @@ # Unload data from the playground if self.status != None: sh['timer'].stop("playground-transit") + sh['timer'].stop("playground-move") for name in self.backgrounds.keys(): sh['downloader'].remove_usage(name) self.backgrounds = {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |