Owen Nelson avatar Owen Nelson committed 45da562

only generate new quads for changed cells

Comments (0)

Files changed (2)

                 yield (x, y, 0)  # kill the cell if it doesn't have 2 or 3 friendlies
             elif val == 0 and count == 3:
                 yield (x, y, 1)
-
             it.iternext()
 
-    for x, y, v in list(_updates()):
+    changes = list(_updates())
+    for x, y, v in changes:
         state[(x, y)] = v
 
+    return changes
+
 
 class Game(object):
 
 
     def __iter__(self):
         while 1:
-            tick(self._state)
-            yield self._state
+            yield tick(self._state)
+            # yield self._state
 
     def next(self):
         if self._iter is None:
             self._iter = iter(self)
+            return self.initial_state
         return self._iter.next()
 
     def coords(self):
         """
         x, y = self.state.shape
         return ((x_, y_) for x_ in xrange(x) for y_ in xrange(y))
+
+    @property
+    def initial_state(self):
+        it = np.nditer(self._state, flags=['multi_index'])
+        while not it.finished:
+            (x, y) = it.multi_index
+            v = it[0]
+            yield (x, y, v)
+            it.iternext()
 import sys
-import numpy as np
 import pyglet
 import cgol
 
 def update(dt):
     global game
     global batch
-    frame = game.next()
 
-    for x, y in game.coords():
-        v = frame[(x, y)]
+    frame = game.next()
 
+    for x, y, v in frame:
         top_left = (grid_w * x, grid_h * y)
         top_right = (grid_w * (x + 1), grid_h * y)
         bottom_left = (grid_w * x, grid_h * (y + 1))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.