emscripten Humble Cloud interface
Edward Rudd
2014-09-15 dcc25b2f92fc75e01fc2c85e8df63a6786112395

implement humble_get_player_size

4 files modified
35 ■■■■■ changed files
client/library/humble_api.h 6 ●●●●● patch | view | raw | blame | history
client/library/library_humble.js 13 ●●●●● patch | view | raw | blame | history
client/test/main.cpp 5 ●●●●● patch | view | raw | blame | history
client/test/shell.html 11 ●●●●● patch | view | raw | blame | history
client/library/humble_api.h
@@ -22,6 +22,12 @@
     */
    void humble_fetch_asset_data(const char* url, void *arg, em_async_wget_onload_func onload, em_arg_callback_func onerror);
    /**
     * Gets the allowable player size of the humble player.  Use this to restrict the size of the game in windowed mode.
     * returns 1 if the restriction should be enforced.. 0 otherwise
     */
    int humble_get_player_size(int& width, int& height);
#ifdef __cplusplus
};
#endif
client/library/library_humble.js
@@ -6,6 +6,9 @@
            locateAsset: null, // function(path) { return path; }
            // takes a string key and returns a modified key. return null to NOT cache the specific resource
            buildCacheKey: null, // function(path) { return path; }
            // function returning a hash like {width: 800, height: 600, locked: true}
            // locked specifies whether the game should ONLY use that width/height
            playerSize: null // function() { return { width: 800, height: 600, locked: true } }
        },
        configure: function(options) {
@@ -78,6 +81,16 @@
                if (onerror) Runtime.dynCall('vi', onerror, [arg]);
            }, true /* NO run dependency */);
        });
    },
    humble_get_player_size__deps: ['$HUMBLE_API'],
    humble_get_player_size: function(w, h) {
        var ret = {width: 0, height: 0, locked: false};
        if (HUMBLE_API.options.playerSize) {
            ret = HUMBLE_API.options.playerSize();
        }
        if (w) {{{ makeSetValue('w', '0', 'ret.width', 'i32') }}};
        if (h) {{{ makeSetValue('h', '0', 'ret.height', 'i32') }}};
        return ret.locked ? 1 : 0;
    }
};
client/test/main.cpp
@@ -69,5 +69,10 @@
    // call dummy function to init cloud
    humble_init();
    int w, h;
    int ret = humble_get_player_size(w, h);
    std::cout << "HumblePlayerSize Enabled: " << ret << " @ ( " << w << ", " << h << " )\n";
    return 0;
}
client/test/shell.html
@@ -1301,6 +1301,17 @@
        };
      };
      Module['preRun'].push(function() {
          // configure HUMBLE_API
          HUMBLE_API.configure({
              applicationtoken: 'deadbeef',
              playerSize: function() {
                  return {
                      width: 800, height: 600, locked: true
                  }
              }
          });
      });
      Module['preRun'].push(function() {
          var provider_name = '@TEST_CLOUD_PROVIDER@';
          addRunDependency('CLOUDFS_setup');