Make update code on playing a stone much more efficient

This commit is contained in:
2012-04-18 11:33:20 -04:00
parent e9032003f7
commit becf13e4ab
3 changed files with 57 additions and 17 deletions

View File

@ -108,11 +108,14 @@ class GoGame(gtk.HBox):
row = int(y / inc)
col = int(x / inc)
self.goban.play_move((row,col))
self.update()
changed = self.goban.play_move((row,col))
print changed
self.update(changed)
def do_board_configure(self, widget, event):
print 'configure'
gc = widget.get_style().fg_gc[gtk.STATE_NORMAL]
x,y,width,height = widget.get_allocation()
self.board_backbuf = gtk.gdk.Pixmap(widget.window, width, height, depth=-1)
@ -121,6 +124,8 @@ class GoGame(gtk.HBox):
def do_board_expose(self, widget, event):
print 'expose'
x , y, width, height = event.area
widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL],
self.board_backbuf, x, y, x, y, width, height)
@ -130,7 +135,11 @@ class GoGame(gtk.HBox):
# fixme: rendering/updating the whole board is pretty slow. Eliminate the need to
# render the whole board when a stone is played (we need a list of modified
# locations from somewhere)
# fixme: the board doesn't get drawn initially, even though the backbuffer *should*
# have the board in it before our first expose event
def update_board(self, to_update=None):
print 'update'
if to_update == None:
to_update = range(len(self.goban.board))
@ -169,13 +178,13 @@ class GoGame(gtk.HBox):
def on_pass(self, widget):
self.goban.pass_move()
self.update()
changed = self.goban.pass_move()
self.update(changed)
def on_resign(self, widget):
self.goban.resign()
self.update()
changed = self.goban.resign()
self.update(changed)
# fixme: Add a widget to show the outcome
@ -191,9 +200,9 @@ class GoGame(gtk.HBox):
self.white_cap_value.set_text(str(self.goban.white_captures))
def update(self):
def update(self, changed):
self.update_info()
self.update_board()
self.update_board(changed)