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

ericvrp at codespeak.net ericvrp at codespeak.net
Wed Jun 14 23:07:45 CEST 2006


Author: ericvrp
Date: Wed Jun 14 23:07:42 2006
New Revision: 28792

Modified:
   pypy/dist/pypy/translator/js/proxy/dev.cfg
   pypy/dist/pypy/translator/js/proxy/testme/controllers.py
   pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
   pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
Log:
Animations sort of working with some sprite management issues.
But there is a problem with inline_frame uncompression that I
need to look into tomorrow.


Modified: pypy/dist/pypy/translator/js/proxy/dev.cfg
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/dev.cfg	(original)
+++ pypy/dist/pypy/translator/js/proxy/dev.cfg	Wed Jun 14 23:07:42 2006
@@ -33,7 +33,8 @@
 server.logFile="server.log"
 server.logToScreen=False
 
-server.environment="production"
+#server.environment="production"
+server.environment="development"
 autoreload.package="testme"
 autoreload.on = False
 

Modified: pypy/dist/pypy/translator/js/proxy/testme/controllers.py
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/controllers.py	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/controllers.py	Wed Jun 14 23:07:42 2006
@@ -30,7 +30,10 @@
         if sm.socket is None:
             sm.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             sm.socket.connect((self.host, self.port))
-            sm.socket.send(message(CMSG_PROTO_VERSION, 2))
+            sm.socket.send(message(CMSG_PROTO_VERSION, 2))  #, version
+            sm.socket.send(message(CMSG_ENABLE_SOUND, 0))   #, has_sound
+            sm.socket.send(message(CMSG_ENABLE_MUSIC, 0))   #, has_music
+            sm.socket.send(message(CMSG_UDP_PORT, "\\"))    #, port
             #XXX todo: session.socket.close() after a timeout
         return sm.socket
 
@@ -71,6 +74,8 @@
         sm.data = data
         #log('RECEIVED DATA REMAINING CONTAINS %d BYTES' % len(data))
 
+        #XXX: TODO: remove all but the last message where type == 'inline_frame'(PMSG_INLINE_FRAME)
+
         #if messages:
         #    log('MESSAGES:%s' % messages)
         return dict(messages=messages)

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	Wed Jun 14 23:07:42 2006
@@ -2,11 +2,12 @@
 from cherrypy import session
 from msgstruct import *
 import PIL.Image
-from zlib import decompress
+from zlib import decompressobj
 from urllib import quote
 from os import mkdir
 from os.path import exists
 from md5 import md5
+from struct import unpack
 
 
 debug = True
@@ -23,6 +24,7 @@
 PMSG_PLAYER_ICON   = "player_icon"
 PMSG_PLAYER_JOIN   = "player_join"
 PMSG_DEF_KEY       = "def_key"
+PMSG_INLINE_FRAME  = "inline_frame"
 
 
 # convert server messages to proxy messages in json format
@@ -39,6 +41,8 @@
         self.n_header_lines = 2
         self.gfx_dir = self.base_gfx_dir    #gets overwritten depending on playfield FnDesc
         self.gfx_url = self.base_gfx_url
+        self.decompressobj = decompressobj().decompress
+
 
     def dispatch(self, *values):
         #log('RECEIVED:%s(%d)' % (values[0], len(values[1:])))
@@ -84,12 +88,20 @@
         else:
             bitmap_filename = '%sbitmap%d.ppm' % (self.gfx_dir, bitmap_code)
             f = open(bitmap_filename, 'wb')
-            f.write(decompress(data))
+            f.write(self.decompressobj(data))
             f.close()
             #TODO: use in memory (don't save ppm first)
-            bitmap = PIL.Image.open(bitmap_filename)
-            bitmap.save(gif_bitmap_filename)
-            log('SAVED:%s' % gif_bitmap_filename)
+            try:
+                bitmap = PIL.Image.open(bitmap_filename)
+            except IOError:
+                log('ERROR LOADING:%s' % bitmap_filename)
+                return 'error'
+            try:
+                bitmap.save(gif_bitmap_filename)
+                log('SAVED:%s' % gif_bitmap_filename)
+            except IOError:
+                log('ERROR SAVING:%s' % gif_bitmap_filename)
+                return 'error'
 
     def def_bitmap2(self, bitmap_code, fileid, *rest):
         #log('def_bitmap2: bitmap_code=%d, fileid=%d, colorkey=%s' % (bitmap_code, fileid, rest))
@@ -136,7 +148,9 @@
         #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']
-        self.def_bitmap(bitmap_code, data, *colorkey)
+        t = self.def_bitmap(bitmap_code, data, *colorkey)
+        if t == 'error':
+            return
         messages = []
         if bitmap_code in self._def_icon_queue:
             #log('%d icons queued for bitmap %d' % (
@@ -169,6 +183,33 @@
             'checksum'      : checksum,
             }
 
+    def inline_frame(self, data):
+        decompressed_data = d = self.decompressobj(data)
+        log('inline_frame len(data)=%d, len(decompressed_data)=%d' % (
+            len(data), len(d)))
+
+        return_raw_data = False
+        if return_raw_data:
+            return dict(type=PMSG_INLINE_FRAME, data=decompressed_data)
+
+        #note: we are not returning the raw data here but we could let the Javascript
+        #      handle it. If this is working we can convert this to RPython and move it
+        #      to the client instead. (based on BnB update_sprites in display/pclient.py)
+        sounds, sprites = [], []
+
+        base = 0
+        while d[base+4:base+6] == '\xFF\xFF':
+            key, lvol, rvol = struct.unpack("!hBB", udpdata[base:base+4])
+            sounds.append((key, lvol, rvol))
+            base += 6
+
+        for j in range(base, len(d)-5, 6):
+            info = d[j:j+6]
+            x, y, icon_code = unpack("!hhh", info[:6])
+            sprites.append((icon_code, x, y))
+
+        return dict(type=PMSG_INLINE_FRAME, sounds=sounds, sprites=sprites)
+
     MESSAGES = {
         MSG_BROADCAST_PORT : ignore,
         MSG_PING           : ignore,
@@ -181,4 +222,5 @@
         MSG_PLAYER_JOIN    : player_join,
         MSG_DEF_KEY        : def_key,
         MSG_MD5_FILE       : md5_file,
+        MSG_INLINE_FRAME   : inline_frame,
         }

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	Wed Jun 14 23:07:42 2006
@@ -24,13 +24,25 @@
                 {'bgcolor':bgcolor, 'width':msg.width, 'height':msg.height});
             replaceChildNodes(body, playfield);
             body.setAttribute('bgcolor', bgcolor); //XXX hack!
+
         } else if (msg.type == 'def_icon') {
-            if (!(msg.icon_code in icon)) {
-                icon[msg.icon_code] = new Image();
-                //icon[msg.icon_code].src = msg.filename;
-                var img = IMG({'src':msg.filename, 'title':msg.filename,
-                    'width':msg.width, 'height':msg.height});
-                appendChildNodes(playfield, img);
+            icon[msg.icon_code] = new Image();
+            icon[msg.icon_code].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;'});
+            appendChildNodes(playfield, img);
+
+        } else if (msg.type == 'inline_frame') { //msg.sounds, msg.sprites
+            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';
             }
         }
         else {



More information about the Pypy-commit mailing list