diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2014-06-12 19:58:49 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2014-06-16 15:26:38 (GMT) |
commit | dba0488ae9ab21c87bc840eab6bb3b79223c3cd7 (patch) | |
tree | 14a2e0b7d73669c5fb95422dd97266733bbf0272 | |
parent | 7de726b052795cef0076e8d010492f7e502c3f7f (diff) |
Removed all the code used to calculate dirty regions
Tested the activity on XO-1 and the performance is good enough,
then removed alll the code used to calculate the dirty areas.
In fact the code was disabled from the port to cairo.
-rw-r--r-- | game.py | 61 |
1 files changed, 3 insertions, 58 deletions
@@ -173,14 +173,9 @@ class MazeGame(Gtk.DrawingArea): self.finish_time = None for player in self.allplayers: player.reset() - self.dirtyRect = self.maze.bounds - self.dirtyPoints = [] self.maze.map[self.maze.width - 2][self.maze.height - 2] = \ self.maze.GOAL - # clear and mark the whole screen as dirty - # TODO - # self.screen.fill((0, 0, 0)) self.queue_draw() self.mouse_in_use = 0 if self._ebook_mode_detector.get_ebook_mode(): @@ -190,12 +185,6 @@ class MazeGame(Gtk.DrawingArea): self._finish_window = None def __draw_cb(self, widget, ctx): - """Draw the current state of the game. - This makes use of the dirty rectangle to reduce CPU load.""" - # TODO - # if self.dirtyRect is None and len(self.dirtyPoints) == 0: - # return - # compute the size of the tiles given the screen size, etc. allocation = self.get_allocation() @@ -241,35 +230,15 @@ class MazeGame(Gtk.DrawingArea): ctx.fill() ctx.restore() - # re-draw the dirty rectangle - if self.dirtyRect is not None: - # compute the area that needs to be redrawn - left = max(0, self.dirtyRect.x) - right = min(self.maze.width, - self.dirtyRect.x + self.dirtyRect.width) - top = max(0, self.dirtyRect.y) - bottom = min(self.maze.height, - self.dirtyRect.y + self.dirtyRect.height) - - # loop over the dirty rect and draw - for x in range(left, right): - for y in range(top, bottom): - drawPoint(x, y) - - # re-draw the dirty points - # for x, y in self.dirtyPoints: - # drawPoint(x, y) + for x in range(0, self.maze.width): + for y in range(0, self.maze.height): + drawPoint(x, y) # draw all players for player in self.allplayers: if not player.hidden: player.draw(ctx, self.bounds, self.tileSize) - # clear the dirty rect so nothing will be drawn until there is a change - # TODO - # self.dirtyRect = None - # self.dirtyPoints = [] - def set_show_trail(self, show_trail): if self._show_trail != show_trail: self._show_trail = show_trail @@ -278,19 +247,6 @@ class MazeGame(Gtk.DrawingArea): else: return False - def markRectDirty(self, rect): - """Mark an area that needs to be redrawn. This lets us - play really big mazes without needing to re-draw the whole - thing each frame.""" - if self.dirtyRect is None: - self.dirtyRect = rect - else: - self.dirtyRect.union_ip(rect) - - def markPointDirty(self, pt): - """Mark a single point that needs to be redrawn.""" - self.dirtyPoints.append(pt) - def _ebook_mode_changed_cb(self, detector, ebook_mode): if ebook_mode: self._activity.show_accelerator_alert() @@ -430,8 +386,6 @@ class MazeGame(Gtk.DrawingArea): oldposition = player.position newposition = player.animate(self.maze, change_direction) if oldposition != newposition: - self.markPointDirty(oldposition) - self.markPointDirty(newposition) if player in self.localplayers: self.maze.map[player.previous[0]][player.previous[1]] = \ self.maze.SEEN @@ -459,7 +413,6 @@ class MazeGame(Gtk.DrawingArea): self.remoteplayers[buddy.get_key()] = player self.allplayers.append(player) self.allplayers.extend(player.bonusPlayers()) - self.markPointDirty(player.position) def _send_maze(self, player): # tell them which maze we are playing, so they can sync up @@ -479,10 +432,8 @@ class MazeGame(Gtk.DrawingArea): if buddy.get_key() in self.remoteplayers: player = self.remoteplayers[buddy.get_key()] logging.debug("Leave: %s", player.nick) - self.markPointDirty(player.position) self.allplayers.remove(player) for bonusplayer in player.bonusPlayers(): - self.markPointDirty(bonusplayer.position) self.allplayers.remove(bonusplayer) del self.remoteplayers[buddy.get_key()] @@ -542,20 +493,14 @@ class MazeGame(Gtk.DrawingArea): elif message.startswith("move:"): # a player has moved x, y, dx, dy = message[5:].split(",")[:5] - - self.markPointDirty(player.position) player.position = (int(x), int(y)) player.direction = (int(dx), int(dy)) - self.markPointDirty(player.position) self.player_walk(player) elif message.startswith("step:"): # a player has moved using the accelerometer x, y, dx, dy = message[5:].split(",")[:5] - - self.markPointDirty(player.position) player.position = (int(x), int(y)) player.direction = (int(dx), int(dy)) - self.markPointDirty(player.position) self.player_walk(player, False) elif message.startswith("maze:"): # someone has a different maze than us |