[pypy-svn] r64593 - pypy/trunk/pypy/lang/gameboy

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Apr 23 14:41:19 CEST 2009


Author: cfbolz
Date: Thu Apr 23 14:41:18 2009
New Revision: 64593

Modified:
   pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py
   pypy/trunk/pypy/lang/gameboy/video.py
Log:
(tverwaes, cfbolz): only draw pixels that changed since the last frame


Modified: pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py	Thu Apr 23 14:41:18 2009
@@ -73,14 +73,12 @@
         self.emulate(constants.GAMEBOY_CLOCK / FPS)
         spent = time.time() - self.sync_time
         left = 1.0/FPS + self.penalty - spent
-        print "left", left
         if left > 0:
             delay(left)
             self.penalty = 0.0
         else:
             # Fade out penalties over time.
             self.penalty = left - self.penalty / 2
-            print self.penalty
         self.sync_time = time.time()
         
     
@@ -189,7 +187,9 @@
     def draw_pixels(self):
         for y in range(constants.GAMEBOY_SCREEN_HEIGHT):
             for x in range(constants.GAMEBOY_SCREEN_WIDTH):
-                self.draw_pixel(x, y, self.pixels[y][x])
+                if self.changed[y][x]:
+                    self.draw_pixel(x, y, self.pixels[y][x])
+                    self.changed[y][x] = False
 
     def draw_ascii_pixels(self):
             str = []

Modified: pypy/trunk/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video.py	Thu Apr 23 14:41:18 2009
@@ -552,7 +552,9 @@
                 self.draw_gb_pixel(x, y, 0)
 
     def draw_gb_pixel(self, x, y, color):
+        old = self.pixels[y][x]
         self.pixels[y][x] = color
+        self.changed[y][x] = old != color
 
     def update_gb_display(self):
         self.update_display()
@@ -562,5 +564,9 @@
         pass
 
     def create_pixels(self):
-        self.pixels = [[0] * self.width
+        # any non-valid color is fine
+        self.pixels = [[255] * self.width
                         for i in range(self.height)]
+        self.changed = [[True] * self.width
+                         for i in range(self.height)]
+                        



More information about the Pypy-commit mailing list