| client/library/humble_api.h | ●●●●● patch | view | raw | blame | history | |
| client/library/library_humble.js | ●●●●● patch | view | raw | blame | history | |
| client/test/main.cpp | ●●●●● patch | view | raw | blame | history |
client/library/humble_api.h
@@ -22,6 +22,30 @@ */ void humble_fetch_asset_data(const char* url, void *arg, em_async_wget_onload_func onload, em_arg_callback_func onerror); typedef enum { /** * This callback is passed a float volume (between 0.0 and 1.0) as well as the data parameter when registered. * * callback prototype: void (*)(float volume, void* data); */ HUMBLE_API_CALLBACK_SET_PLAYER_VOLUME = 1, /** * This callback is passed an int value which is either 1 for fullscreen or 0 for windowed as well as the data parameter when registered. * when going windowed, the application should use and respect the humble_get_player_size values * * callback prototype: void (*)(int fullscreen, void* data); */ HUMBLE_API_CALLBACK_SET_PLAYER_FULLSCREEN = 2, } HUMBLE_API_CALLBACK; /** * Register a callback for the specified callback type * If a callback is already registered, it will be replaced with the new callback * passing a NUL for callback will unregister the callback for that type * data will be passed along to the callback function as the last parameter */ int humble_set_callback(HUMBLE_API_CALLBACK type, void *callback, void* data); /** * 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 client/library/library_humble.js
@@ -24,6 +24,43 @@ */ demoEndedCallback: null }, callbacks: { /** * a callback in the game code to set the expected player volume. * The callback takes a float parameter with a value between 0.0 and 1.0 */ setPlayerVolume: null, /** * a callback to set the fullscreen */ setPlayerFullscreen: null }, /** * Attempts to call into the app to inform it that the volume should be adjusted * @param volume the float volume (between 0.0 and 1.0) * @return bool.. true if the callback was successful.. false if no callback registered */ setPlayerVolume: function(volume) { if (HUMBLE_API.callbacks.setPlayerVolume == null) return false; var cb = HUMBLE_API.callbacks.setPlayerVolume[0], data = HUMBLE_API.callbacks.setPlayerVolume[1]; if (volume > 1.0) volume = 1.0; if (volume < 0.0) volume = 0.0; Runtime.dynCall('vdi', cb, [volume, data]); return true; }, /** * Attempts to call into the app to inform it that it should change to or from fullscreen mode * @param fullscreen A bool of either true or false * @return bool.. true if the callback was successful.. false if no callback registered */ setPlayerFullscreen: function(fullscreen) { if (HUMBLE_API.callbacks.setPlayerFullscreen == null) return false; var cb = HUMBLE_API.callbacks.setPlayerFullscreen[0], data = HUMBLE_API.callbacks.setPlayerFullscreen[1]; Runtime.dynCall('vii', cb, [fullscreen ? 1 : 0, data]); return true; }, /** * allows configuring the HUMBLE_API simply call this method in a preRun to initialize.. * any option is accepted and will be added to the configuration hash. @@ -231,7 +268,24 @@ if (HUMBLE_API.options.demoEndedCallback) { return HUMBLE_API.options.demoEndedCallback.call(HUMBLE_API); } }, humble_set_callback__deps: ['$HUMBLE_API'], humble_set_callback: function(type, cb, data) { var key = null; switch(type) { case 1: key = 'setPlayerVolume'; break; case 2: key = 'setPlayerFullscreen'; break; } if (key == null) { return 0; } if (cb == 0) { HUMBLE_API.callbacks[key] = null; } else { HUMBLE_API.callbacks[key] = [cb, data]; } return 1; }, }; mergeInto(LibraryManager.library, LibraryHUMBLE); client/test/main.cpp
@@ -74,11 +74,23 @@ humble_demo_ended(); } void setPlayerVolume(float volume, void* data) { std::cout << "Adjusting volume to " << volume << "\n"; } void setPlayerFullscreen(int fullscreen, void* data) { std::cout << "Adjusting display to " << (fullscreen ? "fullscreen" : "windowed") << "\n"; } int main(int argc, char * argv[]) { std::cout << "Welcome Main\n"; // call dummy function to init cloud humble_init(); humble_set_callback(HUMBLE_API_CALLBACK_SET_PLAYER_VOLUME, (void*)&setPlayerVolume, NULL); humble_set_callback(HUMBLE_API_CALLBACK_SET_PLAYER_FULLSCREEN, (void*)&setPlayerFullscreen, NULL); int w, h; int ret = humble_get_player_size(&w, &h);