[pypy-svn] r28770 - in pypy/dist/pypy/translator/js/proxy: . testme testme/static/javascript
ericvrp at codespeak.net
ericvrp at codespeak.net
Wed Jun 14 16:14:15 CEST 2006
Author: ericvrp
Date: Wed Jun 14 16:14:13 2006
New Revision: 28770
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:
supporting the much faster protocol version 2
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 16:14:13 2006
@@ -29,9 +29,11 @@
server.socketHost="127.0.0.1"
# Disable the debug output at the end on pages.
-# logDebugInfoFilter.on = False
+logDebugInfoFilter.on = False
+server.logFile="server.log"
+server.logToScreen=False
-server.environment="production" #"development"
+server.environment="production"
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 16:14:13 2006
@@ -30,7 +30,7 @@
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, 1)) #XXX we would like version 2
+ sm.socket.send(message(CMSG_PROTO_VERSION, 2))
#XXX todo: session.socket.close() after a timeout
return sm.socket
@@ -54,7 +54,7 @@
while sm.n_header_lines > 0 and '\n' in data:
sm.n_header_lines -= 1
header_line, data = data.split('\n',1)
- log('RECEIVED HEADER LINE: %s' % header_line)
+ #log('RECEIVED HEADER LINE: %s' % header_line)
#log('RECEIVED DATA CONTAINS %d BYTES' % len(data))
messages = []
@@ -64,12 +64,15 @@
break # incomplete message
messageOutput = sm.dispatch(*values)
if messageOutput:
- messages.append(messageOutput)
+ if type(messageOutput) is type([]):
+ messages += messageOutput
+ else:
+ messages.append(messageOutput)
sm.data = data
#log('RECEIVED DATA REMAINING CONTAINS %d BYTES' % len(data))
- if messages:
- log('MESSAGES:%s' % messages)
+ #if messages:
+ # log('MESSAGES:%s' % messages)
return dict(messages=messages)
def _close(self):
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 16:14:13 2006
@@ -16,8 +16,8 @@
#proxy messages
-PMSG_PING = "ping" #server wants to hear from client
-PMSG_PONG = "pong" #server responds to client's ping
+#PMSG_PING = "ping" #server wants to hear from client
+#PMSG_PONG = "pong" #server responds to client's ping
PMSG_DEF_PLAYFIELD = "def_playfield"
PMSG_DEF_ICON = "def_icon"
PMSG_PLAYER_ICON = "player_icon"
@@ -28,6 +28,8 @@
# convert server messages to proxy messages in json format
class ServerMessage:
+ _md5_file = {}
+ _def_icon_queue = {}
base_gfx_dir = 'testme/static/images/'
base_gfx_url = 'static/images/'
@@ -39,29 +41,22 @@
self.gfx_url = self.base_gfx_url
def dispatch(self, *values):
- #log('RECEIVED MESSAGE:%s(%d)' % (values[0], len(values[1:])))
+ #log('RECEIVED:%s(%d)' % (values[0], len(values[1:])))
fn = self.MESSAGES.get(values[0])
if fn:
return fn(self, *values[1:])
else:
- log("UNKNOWN MESSAGE:%s" % str(values))
+ log("UNKNOWN:%s" % str(values))
return dict(type='unknown', values=values)
#server message handlers...
- def broadcast_port(self, *values):
- log('MESSAGE (IGNORE):broadcast_port %s' % str(values))
-
- def ping(self, *rest):
- log('MESSAGE:ping udpsockcounter=%s' % str(rest))
- return dict(type=PMSG_PING)
-
- def pong(self):
- log('MESSAGE:pong')
- return dict(type=PMSG_PONG)
+ def ignore(self, *values):
+ #log('ignore %s' % str(values))
+ return
def def_playfield(self, width, height, backcolor, FnDesc):
- log('MESSAGE:def_playfield width=%s, height=%s, backcolor=%s, FnDesc=%s' %\
- (width, height, backcolor, FnDesc))
+ #log('def_playfield width=%s, height=%s, backcolor=%s, FnDesc=%s' % (\
+ # width, height, backcolor, FnDesc))
hexdigest = md5(FnDesc).hexdigest()
self.gfx_dir = self.base_gfx_dir + hexdigest + '/'
self.gfx_url = self.base_gfx_url + hexdigest + '/'
@@ -72,64 +67,118 @@
return dict(type=PMSG_DEF_PLAYFIELD, width=width, height=height,
backcolor=backcolor, FnDesc=FnDesc)
- def def_bitmap(self, code, data, *rest):
- log('MESSAGE:def_bitmap code=%s, data=%d bytes, colorkey=%s' %\
- (code, len(data), rest))
- gif_bitmap_filename = '%sbitmap%d.gif' % (self.gfx_dir, code)
- if exists(gif_bitmap_filename):
- return
- bitmap_filename = '%sbitmap%d.ppm' % (self.gfx_dir, code)
- f = open(bitmap_filename, 'wb')
- f.write(decompress(data))
- f.close()
-
- #TODO: use in memory (don't save ppm first)
- bitmap = PIL.Image.open(bitmap_filename)
- bitmap.save(gif_bitmap_filename)
-
- def def_icon(self, bitmap_code, code, x,y,w,h, *rest):
- log('MESSAGE:def_icon bitmap_code=%s, code=%s, x=%s, y=%s, w=%s, h=%s, alpha=%s' %\
- (bitmap_code, code, x,y,w,h, rest))
+ def def_bitmap(self, bitmap_code, data_or_fileid, *rest):
+ if type(data_or_fileid) is type(0):
+ fn = self.def_bitmap2
+ else:
+ fn = self.def_bitmap1
+ return fn(bitmap_code, data_or_fileid, *rest)
- icon_filename = '%sicon%d.gif' % (self.gfx_dir, code)
- if not exists(icon_filename):
+ def def_bitmap1(self, bitmap_code, data, *rest):
+ #log('def_bitmap1 bitmap_code=%d, data=%d bytes, colorkey=%s' % (
+ # bitmap_code, len(data), rest))
+ gif_bitmap_filename = '%sbitmap%d.gif' % (self.gfx_dir, bitmap_code)
+ if exists(gif_bitmap_filename):
+ #log('CACHED:%s' % gif_bitmap_filename)
+ pass
+ else:
+ bitmap_filename = '%sbitmap%d.ppm' % (self.gfx_dir, bitmap_code)
+ f = open(bitmap_filename, 'wb')
+ f.write(decompress(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)
+
+ def def_bitmap2(self, bitmap_code, fileid, *rest):
+ #log('def_bitmap2: bitmap_code=%d, fileid=%d, colorkey=%s' % (bitmap_code, fileid, rest))
+ gif_bitmap_filename = '%sbitmap%d.gif' % (self.gfx_dir, bitmap_code)
+ if exists(gif_bitmap_filename):
+ #log('SKIP DATA_REQUEST:%s' % gif_bitmap_filename)
+ pass
+ else:
+ self._md5_file[fileid]['bitmap_code'] = bitmap_code
+ self._md5_file[fileid]['colorkey'] = rest
+ position = self._md5_file[fileid]['offset']
+ size = self._md5_file[fileid]['len_data']
+ msg = message(CMSG_DATA_REQUEST, fileid, position, size)
+ self.socket.send(msg)
+ log('DATA_REQUEST:%s' % gif_bitmap_filename)
+
+ def def_icon(self, bitmap_code, icon_code, x,y,w,h, *rest):
+ #log('def_icon bitmap_code=%s, icon_code=%s, x=%s, y=%s, w=%s, h=%s, alpha=%s' %\
+ # (bitmap_code, icon_code, x,y,w,h, rest))
+
+ bitmap_filename = '%sbitmap%d.gif' % (self.gfx_dir, bitmap_code)
+ icon_filename = '%sicon%d.gif' % (self.gfx_dir, icon_code)
+ if exists(icon_filename):
+ #log('CACHED:%s' % icon_filename)
+ pass
+ elif exists(bitmap_filename):
#TODO: use in memory (don't save ppm first)
- bitmap_filename = '%sbitmap%d.gif' % (self.gfx_dir, bitmap_code)
icon = PIL.Image.open(bitmap_filename)
box = (x, y, x+w, y+h)
region = icon.crop(box)
region.save(icon_filename)
log('SAVED:%s' % icon_filename)
+ else: #bitmap is not available yet (protocol 2)
+ #log('%s NOT AVAILABLE FOR %s' % (bitmap_filename, icon_filename))
+ if bitmap_code not in self._def_icon_queue:
+ self._def_icon_queue[bitmap_code] = []
+ self._def_icon_queue[bitmap_code].append((icon_code, x, y, w, h, rest))
+ return
- filename = '%sicon%d.gif' % (self.gfx_url, code)
- return dict(type=PMSG_DEF_ICON, code=code, filename=filename, width=w, height=h)
+ filename = '%sicon%d.gif' % (self.gfx_url, icon_code)
+ return dict(type=PMSG_DEF_ICON, icon_code=icon_code, filename=filename, width=w, height=h)
- def player_icon(self, player_id, code):
- log('MESSAGE:player_icon player_id=%d, code=%d' % (player_id, code))
- return dict(type=PMSG_PLAYER_ICON, player_id=player_id, code=code)
+ def zpatch_file(self, fileid, position, data): #response to CMSG_DATA_REQUEST
+ #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)
+ messages = []
+ if bitmap_code in self._def_icon_queue:
+ #log('%d icons queued for bitmap %d' % (
+ # len(self._def_icon_queue[bitmap_code]), bitmap_code))
+ for t in self._def_icon_queue[bitmap_code]:
+ icon_code, x, y, w, h, rest = t
+ messages.append(self.def_icon(bitmap_code, icon_code, x, y, w, h, *rest))
+ del self._def_icon_queue[bitmap_code]
+ return messages
+
+ def player_icon(self, player_id, icon_code):
+ log('player_icon player_id=%d, icon_code=%d' % (player_id, icon_code))
+ return dict(type=PMSG_PLAYER_ICON, player_id=player_id, icon_code=icon_code)
def player_join(self, player_id, client_is_self):
- log('MESSAGE:player_join player_id=%d, client_is_self=%d' % (player_id, client_is_self))
+ log('player_join player_id=%d, client_is_self=%d' % (player_id, client_is_self))
return dict(type=PMSG_PLAYER_JOIN, player_id=player_id, client_is_self=client_is_self)
- def def_key(self, keyname, num, *ico_codes):
- log('MESSAGE:def_key keyname=%s, num=%d, ico_codes=%s' % (keyname, num, str(ico_codes)))
- return dict(type=PMSG_DEF_KEY, keyname=keyname, num=num, ico_codes=ico_codes)
+ def def_key(self, keyname, num, *icon_codes):
+ log('def_key keyname=%s, num=%d, icon_codes=%s' % (keyname, num, str(icon_codes)))
+ return dict(type=PMSG_DEF_KEY, keyname=keyname, num=num, icon_codes=icon_codes)
def md5_file(self, fileid, protofilepath, offset, len_data, checksum):
- log('MESSAGE:md5_file fileid=%d, protofilepath=%s, offset=%d, len_data=%d, checksum=...' % (
- fileid, protofilepath, offset, len_data))
- #skip for now...
+ #log('md5_file fileid=%d, protofilepath=%s, offset=%d, len_data=%d, checksum=...' % (
+ # fileid, protofilepath, offset, len_data))
+ self._md5_file[fileid] = {
+ 'protofilepath' : protofilepath,
+ 'offset' : offset,
+ 'len_data' : len_data,
+ 'checksum' : checksum,
+ }
MESSAGES = {
- MSG_BROADCAST_PORT : broadcast_port,
- MSG_PING : ping,
+ MSG_BROADCAST_PORT : ignore,
+ MSG_PING : ignore,
+ MSG_PONG : ignore,
MSG_DEF_PLAYFIELD : def_playfield,
MSG_DEF_BITMAP : def_bitmap,
+ MSG_ZPATCH_FILE : zpatch_file,
MSG_DEF_ICON : def_icon,
MSG_PLAYER_ICON : player_icon,
MSG_PLAYER_JOIN : player_join,
- MSG_PONG : pong,
MSG_DEF_KEY : def_key,
MSG_MD5_FILE : md5_file,
}
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 16:14:13 2006
@@ -25,16 +25,16 @@
replaceChildNodes(body, playfield);
body.setAttribute('bgcolor', bgcolor); //XXX hack!
} else if (msg.type == 'def_icon') {
- if (!(msg.code in icon)) {
- icon[msg.code] = new Image();
- //icon[msg.code].src = msg.filename;
+ 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);
}
}
else {
- logWarning('unknown msg.type: ' + msg.type + ', msg: ' + msg);
+ logWarning('unknown msg.type: ' + msg.type + ', msg: ' + items(msg));
}
}
sendPing();
More information about the Pypy-commit
mailing list