diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 04:11:44 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 04:11:44 +0000 |
commit | 8505831392922851d8b42869bc0ee82b66f982ad (patch) | |
tree | e2dfa5f4b509b9e00d145d48cdf4f334d74f0050 /native_client_sdk/src/examples | |
parent | d0d9c3eed9085779098868f5ab8a3d90e6899dcc (diff) | |
download | chromium_src-8505831392922851d8b42869bc0ee82b66f982ad.zip chromium_src-8505831392922851d8b42869bc0ee82b66f982ad.tar.gz chromium_src-8505831392922851d8b42869bc0ee82b66f982ad.tar.bz2 |
[NaCl SDK] Fix some examples
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10583008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142908 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src/examples')
-rw-r--r-- | native_client_sdk/src/examples/file_histogram/index.html | 2 | ||||
-rw-r--r-- | native_client_sdk/src/examples/file_io/index.html | 12 | ||||
-rw-r--r-- | native_client_sdk/src/examples/gamepad/index.html | 2 | ||||
-rw-r--r-- | native_client_sdk/src/examples/index.html | 4 | ||||
-rw-r--r-- | native_client_sdk/src/examples/pong/index.html | 23 | ||||
-rw-r--r-- | native_client_sdk/src/examples/pong/pong.cc | 23 | ||||
-rw-r--r-- | native_client_sdk/src/examples/sine_synth/index.html | 2 |
7 files changed, 44 insertions, 24 deletions
diff --git a/native_client_sdk/src/examples/file_histogram/index.html b/native_client_sdk/src/examples/file_histogram/index.html index 91fc346..7642f30 100644 --- a/native_client_sdk/src/examples/file_histogram/index.html +++ b/native_client_sdk/src/examples/file_histogram/index.html @@ -62,7 +62,7 @@ --> <div id="listener"> <script type="text/javascript"> - var listener = document.getElementById('listener') + var listener = document.getElementById('listener'); listener.addEventListener('load', moduleDidLoad, true); listener.addEventListener('message', handleMessage, true); listener.addEventListener('drop', handleFileDrop, true); diff --git a/native_client_sdk/src/examples/file_io/index.html b/native_client_sdk/src/examples/file_io/index.html index 6455157..a71a3d1 100644 --- a/native_client_sdk/src/examples/file_io/index.html +++ b/native_client_sdk/src/examples/file_io/index.html @@ -50,7 +50,7 @@ if (messageParts[0] == "ERR") { updateStatus(messageParts[1]); - document.getElementById('status_field').style.color = "red"; + document.getElementById('statusField').style.color = "red"; } else if(messageParts[0] == "STAT") { updateStatus(messageParts[1]); @@ -60,13 +60,13 @@ document.getElementById('file_editor').value = messageParts[1]; } else if (messageParts[0] == "READY") { - var statusField = document.getElementById('status_field'); + var statusField = document.getElementById('statusField'); updateStatus(statusField.innerHTML + ' Ready!'); } } </script> </head> -<body onload="pageDidLoad('<NAME>', '<tc>')"> +<body> <h1><TITLE></h1> <h2>Status: <code id="statusField">NO-STATUS</code></h2> @@ -86,6 +86,12 @@ --> <div id="listener"> <script type="text/javascript"> + window.webkitStorageInfo.requestQuota(window.PERSISTENT, 1024*1024, + function(bytes) { + updateStatus('Allocated '+bytes+' bytes of persistant storage.'); + createNaClModule('<NAME>', '<tc>', 200, 200); + }, + function(e) { alert('Failed to allocate space') }); var listener = document.getElementById('listener') listener.addEventListener('load', moduleDidLoad, true); listener.addEventListener('message', handleMessage, true); diff --git a/native_client_sdk/src/examples/gamepad/index.html b/native_client_sdk/src/examples/gamepad/index.html index 7271198..92c06e0 100644 --- a/native_client_sdk/src/examples/gamepad/index.html +++ b/native_client_sdk/src/examples/gamepad/index.html @@ -29,6 +29,8 @@ We use a non-zero sized embed to give Chrome space to place the bad plug-in graphic, if there is a problem. --> + <p> Attached gamepad values should appear, left to right, once they've been + interacted with. Buttons, esp triggers are analog. </p> <div id="listener"> <script type="text/javascript"> var listener = document.getElementById('listener') diff --git a/native_client_sdk/src/examples/index.html b/native_client_sdk/src/examples/index.html index 06ead20..3e65940 100644 --- a/native_client_sdk/src/examples/index.html +++ b/native_client_sdk/src/examples/index.html @@ -127,7 +127,7 @@ mulithreading...</p></dd> displayed in the page under the text entry box. <p>Teaching focus: Using shared objects.</p> </dd> -<dt><a href="load_progress/load_progress.html">Load Progress</a></dt> +<dt><a href="load_progress/index.html">Load Progress</a></dt> <dd> The Load Progress example demonstrates how to listen for and handle events that occur while a NaCl module loads. This example listens for different load event types and dispatches different events to their @@ -143,7 +143,7 @@ mulithreading...</p></dd> <p>Teaching focus: File I/O, 2D graphics, input events.</p> </dd> - <dt><a href="multithreaded_input_events/index.html">Multi-threaded + <dt><a href="mt_input_events/index.html">Multi-threaded Input Events</a></dt> <dd>The Multithreaded Input Events example combines HTML, Javascript, and C++ (the C++ is compiled to create a .nexe file). diff --git a/native_client_sdk/src/examples/pong/index.html b/native_client_sdk/src/examples/pong/index.html index 37fa878..4b02899 100644 --- a/native_client_sdk/src/examples/pong/index.html +++ b/native_client_sdk/src/examples/pong/index.html @@ -18,9 +18,23 @@ function resetScore() { naclModule.postMessage("resetScore"); } + + // Handle a message coming from the NaCl module. The message payload is + // assumed to contain the current game score. Update the score text + // display with this value. + // Note that errors are also sent to this handler. A message starting + // with 'ERROR' is considered an error, all other strings are assumed + // to be scores. + function handleMessage(message_event) { + if (message_event.data.indexOf('ERROR') == 0) { + document.getElementById('error_log').innerHTML = message_event.data; + } else { + document.getElementById('score').innerHTML = message_event.data; + } + } </script> </head> -<body onunload="pageDidUnload()" onload="pageDidLoad('<NAME>', '<tc>', 800, 600)"> +<body onunload="pageDidUnload()"> <h1><TITLE></h1> <h2>Status: <code id="statusField">NO-STATUS</code></h2> <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' @@ -39,7 +53,12 @@ --> <div id="listener"> <script type="text/javascript"> - window.webkitStorageInfo.requestQuota(PERSISTENT, 1024); + window.webkitStorageInfo.requestQuota(window.PERSISTENT, 1024, + function(bytes) { + updateStatus('Allocated '+bytes+' bytes of persistent storage.'); + createNaClModule('<NAME>', '<tc>', 800, 600); + }, + function(e) { alert('Failed to allocate space'); }); var listener = document.getElementById('listener') listener.addEventListener('load', moduleDidLoad, true); listener.addEventListener('message', handleMessage, true); diff --git a/native_client_sdk/src/examples/pong/pong.cc b/native_client_sdk/src/examples/pong/pong.cc index 8adf3fe..54ba17f3 100644 --- a/native_client_sdk/src/examples/pong/pong.cc +++ b/native_client_sdk/src/examples/pong/pong.cc @@ -93,7 +93,7 @@ void QueryCallback(void* data, int32_t result) { pong->bytes_buffer_.resize(pong->bytes_to_read_); // Check if there is anything to read. - if (pong->bytes_to_read_ == 0) { + if (pong->bytes_to_read_ != 0) { pong->file_io_->Read(pong->offset_, &pong->bytes_buffer_[0], pong->bytes_to_read_, @@ -340,11 +340,9 @@ void Pong::WriteScoreToFile() { if (file_io_ == NULL) return; // Write the score in <player score>:<computer score> format. - size_t score_string_length = 1 + (player_score_ ? log(player_score_) : 1) + 1 - + (computer_score_ ? log(computer_score_) : 1) + 1; - bytes_buffer_.resize(score_string_length); - snprintf(&bytes_buffer_[0], bytes_buffer_.length(), "%i:%i", player_score_, - computer_score_); + char buffer[100]; + snprintf(&buffer[0], sizeof(buffer), "%d:%d", player_score_, computer_score_); + bytes_buffer_ = std::string(&buffer[0]); offset_ = 0; // overwrite score in file. file_io_->Write(offset_, bytes_buffer_.c_str(), @@ -404,15 +402,10 @@ Pong::BallDirection Pong::RightPaddleNextMove() const { } void Pong::UpdateScoreDisplay() { - if (file_io_ == NULL) - PostMessage(pp::Var("Could not save score (incognito?).")); - return; // Since we cant't save the score to file, do nothing and return. - size_t message_length = 18 + (player_score_ ? log(player_score_) : 1) + 1 - + (computer_score_ ? log(computer_score_) : 1) + 1; - std::string score_message(message_length, '\0'); - snprintf(&score_message[0], score_message.length(), - "You: %i Computer: %i", player_score_, computer_score_); - PostMessage(pp::Var(score_message)); + char buffer[100]; + snprintf(&buffer[0], sizeof(buffer), "You %d: Computer %d", player_score_, + computer_score_); + PostMessage(pp::Var(buffer)); } } // namespace pong diff --git a/native_client_sdk/src/examples/sine_synth/index.html b/native_client_sdk/src/examples/sine_synth/index.html index 9fba6dc..8cbac21 100644 --- a/native_client_sdk/src/examples/sine_synth/index.html +++ b/native_client_sdk/src/examples/sine_synth/index.html @@ -35,7 +35,7 @@ <button onclick="toggleSound(false)">Stop</button> <p>Enter the frequency of the sine wave:</p> <input type="text" size="15" id="frequency_field" - value="#undef" onchange="changeFrequency(this.value)" /> + value="440" onchange="changeFrequency(this.value)" /> <!-- The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' and a 'message' event listener attached. This wrapping method is used |