OSDN Git Service

move layer: fix to prevent tiledict overgrowth
authorRichard Jones <optigon17@gmail.com>
Tue, 20 Dec 2011 01:18:41 +0000 (20:18 -0500)
committerAndrew Chadwick <andrewc-git@piffle.org>
Tue, 20 Dec 2011 11:55:09 +0000 (11:55 +0000)
Fixes to prevent Layer Move from always increasing TileDict size.

lib/tiledsurface.py

index cb2db48..d55fba7 100644 (file)
@@ -414,8 +414,11 @@ class _InteractiveMove:
 
     def __init__(self, surface, x, y):
         self.surface = surface
+        # Remove empty tiles prior to Layer Move
+        self.surface.remove_empty_tiles()
         self.snapshot = surface.save_snapshot()
         self.chunks = self.snapshot.tiledict.keys()
+        # print "Number of Tiledict_keys", len(self.chunks)
         tx = x // N
         ty = y // N
         chebyshev = lambda p: max(abs(tx - p[0]), abs(ty - p[1]))
@@ -476,6 +479,8 @@ class _InteractiveMove:
         bbox = get_tiles_bbox(written) # hopefully relatively contiguous
         self.surface.notify_observers(*bbox)
         self.chunks_i += n
+        # Remove empty tile created by Layer Move
+        self.surface.remove_empty_tiles()
         return self.chunks_i < len(self.chunks)