Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: ports/quakespasm/quakespasm.js

Issue 337323007: Add quakespasm, and OpenGL+SDL-based port of quake1. (Closed) Base URL: https://naclports.googlecode.com/svn/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 var PAK_FILE = 'id1/pak0.pak';
8
9 function updateStatus(message) {
10 document.getElementById('status').innerHTML += message + '<br />';
11 }
12
13 /*
14 * Creates and add to the DOM the NaCl embed tag which
15 * in effect launches Quake.
16 */
17 function runQuake(pwd) {
18 var embed = document.createElement('object');
binji 2014/07/18 23:48:04 s/object/embed/
Sam Clegg 2014/07/19 00:59:49 We use object in naclterm.js .. and it seems that
binji 2014/07/21 17:45:48 yeah object w/ a data element is the old way and e
Sam Clegg 2014/07/21 18:05:27 Done. I figured out how to use the 'embed' elemen
19 embed.width = 800;
20 embed.height = 600;
21 embed.data = 'quakespasm.nmf';
22 embed.type = 'application/x-nacl';
23 if (pwd) {
24 var param = document.createElement('param');
binji 2014/07/18 23:48:04 Use embed.setAttribute('PWD', pwd); instead?
Sam Clegg 2014/07/19 00:59:49 Done.
25 param.name = 'PWD';
binji 2014/07/18 23:48:03 seems a bit weird that PWD changes the directory i
Sam Clegg 2014/07/19 00:59:49 PWD is what bash uses in its environment and its w
26 param.value = pwd;
27 embed.appendChild(param);
28 }
29 document.getElementById('quake').appendChild(embed);
30 }
31
32 function extractZipFile(file, filesystem) {
binji 2014/07/18 23:48:04 Yikes! I'd break this up into smaller functions pe
Sam Clegg 2014/07/19 00:59:49 Done.
33 updateStatus('Extracting file: ' + file.name);
34 zip.createReader(new zip.BlobReader(file),
35 function(zipReader) {
36 zipReader.getEntries(function(entries) {
37 entries_written = 0;
38 for (var i in entries) {
39 var entry = entries[i];
40 if (entry.directory) {
41 filesystem.root.getDirectory(entry.filename, { create : true },
42 function() {
43 entries_written += 1;
44 }
45 );
46 continue;
47 } else {
48 filesystem.root.getFile(entry.filename,
49 { create : true },
50 function(fileEntry) {
51 var writer = new zip.FileWriter(fileEntry);
52 entry.getData(writer,
53 function() {
54 entries_written += 1;
55 if (entries_written === entries.length) {
56 // Once we have extracted all the files then
57 // launch the game.
58 runQuake('/tmp');
binji 2014/07/18 23:48:04 probably a little more javascript-y to have a call
Sam Clegg 2014/07/19 00:59:49 Done.
59 }
60 });
61 },
62 function(error) {
63 updateStatus('error creating temp file: ' + error);
64 }
65 );
66 }
67 }
68 });
69 },
70 function() {
71 updateStatus('Error reading zip file');
72 }
73 )
74 }
75
76 function uploadDidChange(event) {
77 navigator.webkitTemporaryStorage.requestQuota(3 * 1024 * 1024,
78 function(bytes) {
binji 2014/07/18 23:48:04 what if the quota isn't granted? I guess the user
Sam Clegg 2014/07/19 00:59:49 Done.
79 window.webkitRequestFileSystem(window.TEMPORARAY, bytes, function(fs) {
binji 2014/07/18 23:48:04 sp: TEMPORARY
Sam Clegg 2014/07/19 00:59:49 Done.
80 var file = event.target.files[0];
81 extractZipFile(file, fs);
82 });
83 }
84 );
85 }
86
87 function loadFromLocalStorage() {
88 function loadFailure() {
89 updateStatus('Quake data not found in local html5 filesystem.');
90 updateStatus('Please locate a quake level set (for example the '
91 + '<a href="http://www.libsdl.org/projects/quake/data/quakesw-1.0.6.zip">'
92 + 'shareware levels</a>) and either extract them alongside the nmf file,'
93 + ' or use the upload button below to unzip them in the local html5'
94 + ' filesystem.');
95 // Create an html5 file input elemnt in so the user can upload the game
96 // data as a zip file.
97 document.getElementById('quake').innerHTML =
98 '<input type="file" accept="application/zip" id="infile">';
99 document.getElementById('infile').addEventListener('change',
100 uploadDidChange,
101 false);
102 }
103
104 function loadSuccess() {
105 updateStatus('Found pak file in local storage. Launching quake.');
106 runQuake('/tmp');
107 }
108
109 window.webkitRequestFileSystem(
110 window.TEMPORARAY, 3 * 1024 * 1024,
binji 2014/07/18 23:48:04 TEMPORARY
Sam Clegg 2014/07/19 00:59:49 Done.
111 function(fs) {
112 fs.root.getFile(PAK_FILE, {}, loadSuccess, loadFailure);
113 }
114 );
115 }
116
117 function onLoad() {
118 updateStatus('Searching for Quake data (' + PAK_FILE + ')');
119 var req = new XMLHttpRequest();
120 req.onreadystatechange = function() {
binji 2014/07/18 23:48:04 I prefer using onload/onerror. onreadystatechange
Sam Clegg 2014/07/19 00:59:49 Done.
121 if (req.readyState === 4) {
122 if (req.status === 200) {
123 updateStatus('Found ' + PAK_FILE + '. Launching quake.');
124 runQuake();
125 } else {
126 // Failed to find PAK_FILE on webserver, try local storage
127 updateStatus('Quake data not found alongside executable.');
128 loadFromLocalStorage();
129 }
130 }
131 };
132 req.open('GET', PAK_FILE);
133 req.send(null);
134 }
135
136 window.onload = function() {
137 onLoad();
138 };
OLDNEW
« no previous file with comments | « ports/quakespasm/pkg_info ('k') | ports/sdl/nacl.patch » ('j') | ports/sdl/nacl.patch » ('J')

Powered by Google App Engine
This is Rietveld 408576698