Nathan Lamont

Notes to Self

PlayKode Research

Swift asm

macOS Catalina, "gyp: No Xcode or CLT version" message? $ [sudo] xcode-select — reset via https://medium.com/p/f76739eef9ad/responses/show

More on Emscripten

After running it states:

Next steps:
- To conveniently access emsdk tools from the command line,
  consider adding the following directories to your PATH:
    /Users/nathan/Downloads/emscripten/emsdk
    /Users/nathan/Downloads/emscripten/emsdk/node/14.18.2_64bit/bin
    /Users/nathan/Downloads/emscripten/emsdk/upstream/emscripten
- This can be done for the current shell by running:
    source "/Users/nathan/Downloads/emscripten/emsdk/emsdk_env.sh"
- Configure emsdk in your shell startup scripts by running:
    echo 'source "/Users/nathan/Downloads/emscripten/emsdk/emsdk_env.sh"' >> $HOME/.zprofile

You are hesitant because you think it slowed down the launching of your shell before.

On calling JS from C:

Seems to be two ways: one is a macro from C:

EM_ASM( ShipPosition($0, $1), ship_x, ship_y );

This probably executes in a global context, so the JavaScript function would have to be attached to the window.

The other method is more work but "cleaner" using
a callback.

Given a JS Function CallJS, declare it as extern in C:

extern void CallJS(int iVal);

You define the instantianWasm thusly:

  Module.instantiateWasm = function(imports, successCallback) {
    // javascript you want to be able to call from C
    // for each, in c, you need
    // extern void <function name>(…);
    window.asmLibraryArg.CallJS = () => {
      console.log('hello from CallJs')
    }

    const info = {
      env: window.asmLibraryArg,
      wasi_snapshot_preview1: window.asmLibraryArg
    }
    let thisInstance = null
    function receiveInstance(instance, module) {
      thisInstance = instance
      // exports = instance.exports
      // Module.asm = exports
      // removeRunDependency('wasm-instantiate')
    }
    // addRunDependency('wasm-instantiate')
    function receiveInstantiatedSource(output) {
      receiveInstance(output.instance)
    }
    function instantiateArrayBuffer(receiver) {
      return window
        .getBinaryPromise()
        .then(function(binary) {
          return WebAssembly.instantiate(binary, info)
        })
        .then(receiver, function(reason) {
          window.err('failed to asynchronously prepare wasm: ' + reason)
          window.abort(reason)
        })
    }
    function instantiateAsync() {
      if (
        !window.wasmBinary &&
        typeof WebAssembly.instantiateStreaming === 'function' &&
        !window.isDataURI(window.wasmBinaryFile) &&
        !window.isFileURI(window.wasmBinaryFile) &&
        typeof window.fetch === 'function'
      ) {
        window
          .fetch(window.wasmBinaryFile, { credentials: 'same-origin' })
          .then(function(response) {
            const result = WebAssembly.instantiateStreaming(response, info)
            return result.then(receiveInstantiatedSource, function(reason) {
              window.err('wasm streaming compile failed: ' + reason)
              window.err('falling back to ArrayBuffer instantiation')
              instantiateArrayBuffer(receiveInstantiatedSource)
            })
          })
      } else {
        return instantiateArrayBuffer(receiveInstantiatedSource)
      }
    }
    instantiateAsync().then(() => {
      successCallback(thisInstance)
    })

    // return exports
    return {}
  }

Unknown: passing argument to the JS function, receiving results, available to Web Worker?

On Using Swift

Storage Options

We want the user to be able to add their own media (sounds and images). Ultimately, we will need to be able to store them in a shared place like s3, but for now we will focus on the local experience. For the local experience, we will use not localStorage (with, evidently, a max of 5mb and only capable of storing strings) but indexedDB. IndexedDB is more complex.

Some information on storage limits, mostly relating to Firefox - 50% of available space.

Chrome storage limits, as linked to above Minimum of 1% of available or 1GB. Worth noting that on mobile devices these are pretty small (8gb capacity = as little as 80MB available).

Both of these browsers will aggressively delete databases if quotas are exceeded, which can happen outside of the browser (suddenly there's less disk space, so the database gets killed).

Someone's old code for syncing dexie to dropbox: https://gist.github.com/cfilipov/48338f23ce92047807585f750af04bc0

Via: https://github.com/dfahlander/Dexie.js/issues/545

Related item: a JavaScript library for storing user data locally in the browser, as well as connecting to remoteStorage servers and syncing data across devices and applications. It is also capable of connecting and syncing data with a person’s Dropbox or Google Drive account

IndexedDB wrappers:

As suggested by https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API

Note: what about migrating these databases on code changes? Do any of these libraries support that?

  • localForage - works like localStorage, but with promises. Maybe not modern? Although recently updated, 339K weekly
  • dexie.js. 56K weekly but more DB like, fancier site and more complete readme; appears to have built-in migration-like behavior with versioning; see https://dexie.org/docs/Tutorial/Design#database-versioning
  • zangodb aims to be like mongo and you don't want that
  • pouchdb syncs with certain servers (CouchDB, e.g. https://www.ibm.com/cloud/cloudant)
  • idb lightweight convenience wrapper around IndexedDB; maybe too low level; cannot find reference to versioning/migration but there does appear to be some support for it built into IndexedDB ("IDBVersionChangeEvent")
  • idb-keyval like localForage but less old browser support
  • jsstore "think in sql" up to date but little used according to NPM and janky English in docs
  • lovefield by google and "provides SQL-like syntax and works cross-browser" but npm says last release was 3 years ago (although repo shows some activity)

Pretty sure dexie is best choice.

Font for brand: M PLUS Rounded 1c

Couldn't get c to work with C++ until: https://developers.google.com/web/updates/2018/08/embind at the bottom, using the --bind option/syntax at the bottom of that page.

Tons of Useful Info

https://marcoselvatici.github.io/WASM_tutorial/ - not sure how old, but stuff about heap v stack, ptrs, reading files

Drawing Component?

https://codepen.io/Lewitje/pen/MVommB

free json store

On Resizing Canvas

https://groups.google.com/g/emscripten-discuss/c/NONijDAFuTE?pli=1https://stackoverflow.com/questions/60920177/emscripten-sdl2-origin-of-canvas-appears-to-move-when-canvas-is-resized

On Making a Bitmap Font with SDL

https://github.com/i8degrees/nomlib/blob/dev/src/graphics/fonts/TrueTypeFont.cpp

http://lazyfoo.net/SDL_tutorials/lesson30/index.php

Educational Resources

https://www.apple.com/education/k12/learning-from-home/

On dealing with binary data and passing same around

https://stackoverflow.com/questions/59465413/convert-blob-url-to-file-object-with-axios

Shared Memory? https://lucasfcosta.com/2017/04/30/JavaScript-From-Workers-to-Shared-Memory.html

https://groups.google.com/g/emscripten-discuss/c/CMfYljLWMvY

https://stackoverflow.com/questions/17883799/how-to-handle-passing-returning-array-pointers-to-emscripten-compiled-code

Get an Image and convert to blob with axios?

Similar products

tiny games you can play on phone

Fonts

The Oldschool PC Font Pack v2.0

Typed Lua?

Luau https://roblox.github.io/luau/

https://news.ycombinator.com/item?id=24059432

JHelmsAt 6 hours ago

In case anyone is interested: Roblox (who is making Luau) is hiring. We've been growing fast, and are looking for strong C++, systems, and application engineers. As a highly vertically integrate gaming platform, we've got a lot of hard problems to solve - from programming language design (see OP!) to debugger tooling.

You can email me at my username plus roblox.com.

https://www.planimeter.org/grid-sdk/https://github.com/Planimeter/grid-sdk/blob/master/class.luahttps://github.com/Planimeter/grid-sdk

Song Maker: https://musiclab.chromeexperiments.com/Song-Maker/song/5787245861666816

Game maker on top of pixi.js? https://ctjs.rocks

Js mod Player https://keithclark.github.io/ZzFXM/