Permalink
Browse files

cache.manifest for chess, send_delay for slow network testing

  • Loading branch information...
1 parent ef087a1 commit e5dcde8dad1e481e6168e170c2d9245277f41d11 brucero committed Apr 21, 2011
Showing with 128 additions and 7 deletions.
  1. +11 −6 bin/jsgamebench
  2. +35 −0 chess/chess.js
  3. +62 −0 chess/chess.manifest
  4. +1 −1 chess/index.shtml
  5. BIN favicon.ico
  6. +19 −0 lib/comm.js
View
@@ -51,12 +51,17 @@ for(var i=0;i<process.argv.length;i++) {
production_mode = true;
listenPort = 80;
sslPort = 443;
- } else if (process.argv[i] === '--port' && i+1 < process.argv.length) {
- i++;
- listenPort = process.argv[i];
- } else if (process.argv[i] === '--sslport' && i+1 < process.argv.length) {
- i++;
- sslPort = process.argv[i];
+ } else if (i+1 < process.argv.length) {
+ if (process.argv[i] === '--port') {
+ i++;
+ listenPort = process.argv[i];
+ } else if (process.argv[i] === '--sslport') {
+ i++;
+ sslPort = process.argv[i];
+ } else if (process.argv[i] === '--delay') {
+ i++;
+ Comm.setDelay(parseInt(process.argv[i]));
+ }
}
}
View
@@ -154,7 +154,42 @@ var Chess = (function() {
newGameState('playing');
}
+ function loading(e) {
+ console.log('loaded: '+e.loaded+' / '+e.total);
+ var size = [150,60];
+ pos = UI.uiPos([Middle,Middle],size);
+ var box = UI.makeBox(0,'loading',pos,size,'button_class');
+ box.innerHTML = 'Loading: ' + e.loaded+' / '+e.total;
+ }
+
+ function updateReady(e) {
+ UI.removeTree('loading');
+ window.applicationCache.swapCache();
+ }
+
+ function noUpdate(e) {
+ }
+
+ function checking(e) {
+ }
+
+ function sup(e,count) {
+ console.log(count+ ' sup: ' + JSON.stringify(e));
+ console.log('');
+ }
+
function init() {
+
+ cache = window.applicationCache;
+ cache.addEventListener('checking', checking, false);
+ cache.addEventListener('error', function(e) { sup(e,2); }, false);
+ cache.addEventListener('update', function(e) { sup(e,3); }, false);
+ cache.addEventListener('noupdate', noUpdate, false);
+ cache.addEventListener('downloading', function(e) { sup(e,4); }, false);
+ cache.addEventListener('progress', loading, false);
+ cache.addEventListener('updateready', updateReady, false);
+ cache.addEventListener('cached', function(e) { sup(e,7); }, false);
+
GameFrame.updateSettings({
render_mode: GameFrame.HTML_ONLY,
update_existing: true,
View
@@ -0,0 +1,62 @@
+CACHE MANIFEST
+# version 1.3
+
+images/Ninja_Bishop.png
+images/Ninja_King.png
+images/Ninja_Knight.png
+images/Ninja_Pawn.png
+images/Ninja_Queen.png
+images/Ninja_Rook.png
+images/Pirate_128_0000.png
+images/Pirate_Bishop.png
+images/Pirate_Bishop_Gray.png
+images/Pirate_King.png
+images/Pirate_King_Gray.png
+images/Pirate_Knight.png
+images/Pirate_Knight_Gray.png
+images/Pirate_Pawn.png
+images/Pirate_Pawn_Gray.png
+images/Pirate_Queen.png
+images/Pirate_Queen_Gray.png
+images/Pirate_Rook.png
+images/Pirate_Rook_Gray.png
+images/chess_icon.png
+images/small_explo.png
+
+/engine/css/style.css
+/engine/core/min_ui.js
+/engine/core/browser.js
+/engine/core/utils.js
+/engine/core/tick.js
+/engine/core/gameframe.js
+/engine/core/gob.js
+/engine/core/world.js
+/engine/core/sprites.js
+/engine/core/render.js
+/engine/core/dom_render.js
+/engine/core/canvas_render.js
+/engine/core/input.js
+/engine/core/init.js
+
+/chess/style.css
+/chess/constants.js
+/chess/publish.js
+/chess/pieces.js
+/chess/board.js
+#/chess/chess.js
+
+NETWORK:
+# All URLs that start with the following lines
+# are whitelisted.
+*
+
+#http://example.com/examplepath/
+#http://www.example.org/otherexamplepath/
+
+#CACHE:
+# Additional items to cache.
+#demoimages/stonessmall.jpg
+
+#FALLBACK:
+#demoimages/ images/
+
View
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html manifest="chess/chess.manifest">
<head>
<link rel="stylesheet" type="text/css" href="/chess/style.css" />
#include '/engine/include/fb_jssdk.include'
View
Binary file not shown.
View
@@ -106,7 +106,22 @@ function expandSHTML(req, file, filename, options) { //FIXMEBRUCE - should make
return result;
}
+var send_delay = 0;
+function setDelay(msecs) {
+ send_delay = msecs;
+ console.log('delay: ' + send_delay);
+}
+
function sendFile(req, res, filename, options) {
+ if (send_delay) {
+ setTimeout(sendFileNow,send_delay,req, res, filename, options);
+ } else {
+ sendFileNow(req, res, filename, options);
+ }
+}
+
+function sendFileNow(req, res, filename, options) {
+ console.log('sending: '+filename);
options = options || {};
var fullname = fullFileName(filename);
fs.readFile(fullname, 'binary', function(err, file) {
@@ -126,6 +141,9 @@ function sendFile(req, res, filename, options) {
case '.css':
header['Content-Type'] = 'text/css';
break;
+ case '.manifest':
+ header['Content-Type'] = 'text/cache-manifest';
+ break;
case '.shtml':
file = expandSHTML(req, file, filename, options);
break;
@@ -155,3 +173,4 @@ exports.sendFileNotFound = sendFileNotFound;
exports.sendFile = sendFile;
exports.toClient = toClient;
exports.expandSHTML = expandSHTML;
+exports.setDelay = setDelay;

0 comments on commit e5dcde8

Please sign in to comment.