Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
cache.manifest for chess, send_delay for slow network testing
Browse files Browse the repository at this point in the history
  • Loading branch information
brucero committed Apr 21, 2011
1 parent ef087a1 commit e5dcde8
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 7 deletions.
17 changes: 11 additions & 6 deletions bin/jsgamebench
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ for(var i=0;i<process.argv.length;i++) {
production_mode = true; production_mode = true;
listenPort = 80; listenPort = 80;
sslPort = 443; sslPort = 443;
} else if (process.argv[i] === '--port' && i+1 < process.argv.length) { } else if (i+1 < process.argv.length) {
i++; if (process.argv[i] === '--port') {
listenPort = process.argv[i]; i++;
} else if (process.argv[i] === '--sslport' && i+1 < process.argv.length) { listenPort = process.argv[i];
i++; } else if (process.argv[i] === '--sslport') {
sslPort = process.argv[i]; i++;
sslPort = process.argv[i];
} else if (process.argv[i] === '--delay') {
i++;
Comm.setDelay(parseInt(process.argv[i]));
}
} }
} }


Expand Down
35 changes: 35 additions & 0 deletions chess/chess.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -154,7 +154,42 @@ var Chess = (function() {
newGameState('playing'); 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() { 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({ GameFrame.updateSettings({
render_mode: GameFrame.HTML_ONLY, render_mode: GameFrame.HTML_ONLY,
update_existing: true, update_existing: true,
Expand Down
62 changes: 62 additions & 0 deletions chess/chess.manifest
Original file line number Original file line Diff line number Diff line change
@@ -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/

2 changes: 1 addition & 1 deletion chess/index.shtml
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html manifest="chess/chess.manifest">
<head> <head>
<link rel="stylesheet" type="text/css" href="/chess/style.css" /> <link rel="stylesheet" type="text/css" href="/chess/style.css" />
#include '/engine/include/fb_jssdk.include' #include '/engine/include/fb_jssdk.include'
Expand Down
Binary file added favicon.ico
Binary file not shown.
19 changes: 19 additions & 0 deletions lib/comm.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -106,7 +106,22 @@ function expandSHTML(req, file, filename, options) { //FIXMEBRUCE - should make
return result; return result;
} }


var send_delay = 0;
function setDelay(msecs) {
send_delay = msecs;
console.log('delay: ' + send_delay);
}

function sendFile(req, res, filename, options) { 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 || {}; options = options || {};
var fullname = fullFileName(filename); var fullname = fullFileName(filename);
fs.readFile(fullname, 'binary', function(err, file) { fs.readFile(fullname, 'binary', function(err, file) {
Expand All @@ -126,6 +141,9 @@ function sendFile(req, res, filename, options) {
case '.css': case '.css':
header['Content-Type'] = 'text/css'; header['Content-Type'] = 'text/css';
break; break;
case '.manifest':
header['Content-Type'] = 'text/cache-manifest';
break;
case '.shtml': case '.shtml':
file = expandSHTML(req, file, filename, options); file = expandSHTML(req, file, filename, options);
break; break;
Expand Down Expand Up @@ -155,3 +173,4 @@ exports.sendFileNotFound = sendFileNotFound;
exports.sendFile = sendFile; exports.sendFile = sendFile;
exports.toClient = toClient; exports.toClient = toClient;
exports.expandSHTML = expandSHTML; exports.expandSHTML = expandSHTML;
exports.setDelay = setDelay;

0 comments on commit e5dcde8

Please sign in to comment.