[pypy-svn] r28798 - in pypy/dist/pypy/translator/js/proxy/testme: . static/javascript

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Jun 15 09:48:57 CEST 2006


Author: ericvrp
Date: Thu Jun 15 09:48:56 2006
New Revision: 28798

Modified:
   pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
   pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
Log:
Basic animations now working. Uncompression error still irritating because
this causes animations to stop after about two seconds.


Modified: pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/servermessage.py	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/servermessage.py	Thu Jun 15 09:48:56 2006
@@ -16,6 +16,10 @@
         print msg
 
 
+class BitmapCreationException(Exception):
+    pass
+
+
 #proxy messages
 #PMSG_PING          = "ping"	#server wants to hear from client
 #PMSG_PONG          = "pong"	#server responds to client's ping
@@ -87,21 +91,26 @@
             pass
         else:
             bitmap_filename = '%sbitmap%d.ppm' % (self.gfx_dir, bitmap_code)
+            try:
+                decompressed_data = self.decompressobj(data)
+            except Exception, e:
+                raise BitmapCreationException('ERROR UNCOMPRESSING DATA FOR %s (%s)' % (
+                    bitmap_filename, str(e)))
             f = open(bitmap_filename, 'wb')
-            f.write(self.decompressobj(data))
+            f.write(decompressed_data)
             f.close()
             #TODO: use in memory (don't save ppm first)
             try:
                 bitmap = PIL.Image.open(bitmap_filename)
-            except IOError:
-                log('ERROR LOADING:%s' % bitmap_filename)
-                return 'error'
+            except IOError, e:
+                raise BitmapCreationException('ERROR LOADING %s (%s)' % (
+                    bitmap_flename, str(e)))
             try:
                 bitmap.save(gif_bitmap_filename)
                 log('SAVED:%s' % gif_bitmap_filename)
             except IOError:
-                log('ERROR SAVING:%s' % gif_bitmap_filename)
-                return 'error'
+                raise BitmapCreationException('ERROR SAVING %s (%s)' % (
+                    gif_bitmap_filename, str(e)))
 
     def def_bitmap2(self, bitmap_code, fileid, *rest):
         #log('def_bitmap2: bitmap_code=%d, fileid=%d, colorkey=%s' % (bitmap_code, fileid, rest))
@@ -148,9 +157,11 @@
         #log('zpatch_file fileid=%d, position=%d, len(data)=%d' % (fileid, position, len(data)))
         bitmap_code = self._md5_file[fileid]['bitmap_code']
         colorkey    = self._md5_file[fileid]['colorkey']
-        t = self.def_bitmap(bitmap_code, data, *colorkey)
-        if t == 'error':
-            return
+        try:
+            t = self.def_bitmap(bitmap_code, data, *colorkey)
+        except BitmapCreationException, e:
+            log(str(e))
+            return #i.e. not attempting to create icons 
         messages = []
         if bitmap_code in self._def_icon_queue:
             #log('%d icons queued for bitmap %d' % (

Modified: pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js	Thu Jun 15 09:48:56 2006
@@ -26,24 +26,41 @@
             body.setAttribute('bgcolor', bgcolor); //XXX hack!
 
         } else if (msg.type == 'def_icon') {
-            icon[msg.icon_code] = new Image();
-            icon[msg.icon_code].src = msg.filename;
-            var img = IMG({'src':msg.filename, 'title':msg.filename,
+            icon[msg.icon_code] = msg;
+            //icon[msg.icon_code].image = new Image();
+            //icon[msg.icon_code].image.src = msg.filename;
+            /*
+            var img = IMG({//'src':msg.filename,
+                //'title':msg.filename,
                 'width':msg.width, 'height':msg.height,
                 'id':'icon_code'+msg.icon_code,
-                'style':'position:absolute; top:200px; left:50px;'});
+                'style':'position:absolute; top:0px; left:0px;'});
             appendChildNodes(playfield, img);
+            */
 
         } else if (msg.type == 'inline_frame') { //msg.sounds, msg.sprites
+            var images = [];
             for (var n in msg.sprites) {
                 var sprite_data = msg.sprites[n];
                 var icon_code = sprite_data[0];
                 var x         = sprite_data[1];
                 var y         = sprite_data[2];
-                var obj       = $('icon_code'+icon_code);
-                obj.style.left = x + 'px';
-                obj.style.top  = y + 'px';
+                //var obj       = $('icon_code'+icon_code);
+                //obj.style.left = x + 'px';
+                //obj.style.top  = y + 'px';
+                //obj.src = icon[icon_code].filename;
+
+                //XXX need to test performance here. Maybe we should cash images and
+                //    reuse what's already attached to the playfield.
+                //    On the other hand this might not be bad and communication overhead
+                //    seems to be the killer anyway.
+                var img = IMG({'src':icon[icon_code].filename,
+                'width':icon[icon_code].width, 'height':icon[icon_code].height,
+                'style':'position:absolute; top:' + y + 'px; left:' + x + 'px;'});
+
+                images.push(img);
             }
+            replaceChildNodes(playfield, images);
         }
         else {
             logWarning('unknown msg.type: ' + msg.type + ', msg: ' + items(msg));



More information about the Pypy-commit mailing list