Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 09, 2012
@leafo wrote some text b4b59f0
Commits on Apr 11, 2012
@leafo point at new 32 bit nexe name 8e11a5e
Commits on Apr 12, 2012
@leafo file cache and fixed file loader a06e51e
View
3  nacl/Makefile
@@ -5,6 +5,9 @@ strip:
deploy:
rsync -rvuzLR *.html *.nexe *.nmf js/ game/ examples/ leaf@leafo.net:www/aroma/demo
+volcanox::
+ rsync -rvuzLR --exclude volcanox/.git volcanox/ leaf@leafo.net:www/aroma/
+
32:
echo "CONFIG_NACL_ARCH=i686" >> ../tup.config
echo "CONFIG_NACL_BIN_NAME=aroma_tmp" >> ../tup.config
View
2  nacl/aroma.nmf
@@ -1,6 +1,6 @@
{
"program": {
"x86-64": {"url": "aroma_x86_64.nexe"},
- "x86-32": {"url": "aroma_x86_32.nexe"}
+ "x86-32": {"url": "aroma_i686.nexe"}
}
}
View
69 nacl/js/aroma.coffee
@@ -20,10 +20,6 @@ get = (url, on_finish, on_fail, send=yes) ->
else
req
-module_to_url = (module_name) ->
- module_name = module_name.replace /\./g, '/'
- "#{module_name}.lua"
-
# bytes can be array like
encode_byte_array = (bytes, size=null) ->
@@ -48,7 +44,7 @@ get_image_data = (url, callback) ->
img.onload = ->
canvas = document.createElement "canvas"
- console.log "loaded image #{url} [#{img.width}, #{img.height}]"
+ log "loaded image #{url} [#{img.width}, #{img.height}]"
canvas.width = img.width
canvas.height = img.height
@@ -70,10 +66,11 @@ class Aroma
async_handlers: {
require: (msg, callback) ->
[_, module] = msg
- url = module_to_url(module)
- pass = (req) -> callback ["success", req.responseText]
- fail = (req) -> callback ["error", "Failed to find module: tried #{url}"]
- get url, pass, fail
+ @file_loader.get_module module, (code) ->
+ if code?
+ callback ["success", code]
+ else
+ callback ["error", "Failed to find module: tried #{url}"]
image: (msg, callback) ->
[_, path] = msg
@@ -113,6 +110,7 @@ class Aroma
constructor: (@container, @events) ->
@module = null
+ @file_loader = new Aroma.FileLoader
@audio = new Aroma.Audio
listen @container, "load", =>
@@ -151,7 +149,6 @@ class Aroma
if o
@dispatch @message_handlers, o[0], o
-
class StreamingSource
@from_url: (url, callback) ->
elm = document.createElement "audio"
@@ -269,6 +266,58 @@ class Aroma.Font
bytestring = encode_byte_array @ctx.getImageData(0, 0, real_width, @height).data
[str, bytestring, real_width, @height]
+
+class Aroma.FileLoader
+ loaders: {
+ # TODO
+ audio: {
+ match: (path) -> false
+ load: (path, callback) -> false
+ }
+ }
+
+ default_loader: (path, callback) ->
+ @_get path, (req) ->
+ log ">> got result for #{path}"
+ callback req.responseText
+
+ _get: (url, callback) ->
+ log ">> getting: #{url}"
+ get url, callback, @fail_fn || ->
+
+ real_path: (path) ->
+ if @root?
+ "#{@root}/#{path}"
+ else
+ path
+
+ constructor: (@root) ->
+ @file_cache = {}
+
+ get_module: (module_name, callback) ->
+ path = module_name.replace /\./g, '/'
+ path = "#{path}.lua"
+ @get_file path, callback
+
+ get_file: (path, callback) ->
+ path = @real_path path
+
+ return callback @file_cache[path] if @file_cache[path]?
+ # find loader
+ loader = null
+ for name, tuple of @loaders
+ {match: match, load: load} = tuple
+ if match.call this, path
+ loader = load
+ break
+
+ loader = @default_loader unless loader?
+ @on_fail = -> callback null
+
+ loader.call this, path, (result) =>
+ @file_cache[path] = result
+ callback result
+
window.Aroma = Aroma
# font test
View
39 site/index.md
@@ -11,6 +11,45 @@ easy to port.
[2]: https://lua.org
[3]: https://love2d.org
+<div>$index</div>
+
+## How It Works
+
+Native client files are distributed as `.nexe` binaries where are compiled for
+both 64-bit and 32-bit computers. Aroma comes as a compiled `.nexe` file that's
+ready to use after uploading to your server.
+
+### Reusing Your Browser
+
+Aroma comes with some support JavaScript that must be uploaded alongside your
+game. The JavaScript facilitiates things like loading code, loading images, and
+rendering fonts.
+
+In order to keep the `.nexe` binary small, things that can already be
+accomplished by your browser are handled there. Thing like rendering fonts and
+decoding images are handled by the `canvas` tag, which functions as an
+invisible buffer.
+
+### Asynchronous Loading
+
+Aroma loads all of your game code from the web. You typically will upload your
+code alongside the `.nexe` files. This enables you to quickly deploy changes
+without having to recompile anything.
+
+If you've ever done web programming you're probably familiar with making
+asynchronous requests to a server to fetch resources by providing some sort of
+a callback function. On the other hand, when loading code in Lua typically
+write something synchronous like:
+
+ ```lua
+ require "mygame.enemy"
+ ```
+
+Aroma translates this call into an asynchronous request to the browser,
+blocking the execution of the game until the resource has been fetched.
+Combined with the caching provided by the browser, this makes loading code from
+the web pleasant.
+
## Download
## Getting Started
View
2  site/style.less
@@ -85,7 +85,7 @@ a {
background: #E7FFF6;
padding: 12px;
- h2 {
+ h2, h3, h4 {
color: #48817D;
text-shadow: 0px 1px 0px white;
}
View
4 src/lib/nacl.moon
@@ -59,6 +59,7 @@ async_require = (module_name) ->
setfenv loader, getfenv 2
mod = loader module_name
+ mod = true if mod == nil
package.loaded[module_name] = mod
mod
@@ -74,6 +75,9 @@ game_thread = nil -- to prevent it from being garbage collected
nacl.show_error = async_err
+nacl.prefetch = (files) ->
+ request_response { "prefetch", files }
+
nacl.handle_message = (msg) ->
error "unknown msg: " .. tostring(msg) if type(msg) != "string"
print ">>", msg\sub 1, 120

No commit comments for this range

Something went wrong with that request. Please try again.