Skip to content

Commit

Permalink
Replace EM_BOOL with normal C/C++ bool type. NFC
Browse files Browse the repository at this point in the history
There is no need that I can think of to use a custom type/macro here.

This also reduces the size of several structs due to the fact that
the C/C++ bool type is smaller than int.

Keep EM_BOOL/EM_TRUE/EM_FALSE around for backwards compat but
don't use them internally anymore.
  • Loading branch information
sbc100 committed Jun 27, 2024
1 parent a864dde commit dc0f6e5
Show file tree
Hide file tree
Showing 77 changed files with 606 additions and 618 deletions.
282 changes: 133 additions & 149 deletions site/source/docs/api_reference/html5.h.rst

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions site/source/docs/api_reference/wasm_audio_worklets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ own noise generator AudioWorkletProcessor node type:

.. code-block:: cpp
void AudioThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData)
void AudioThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, bool success, void *userData)
{
if (!success) return; // Check browser console in a debug build for detailed errors
WebAudioWorkletProcessorCreateOptions opts = {
Expand All @@ -110,7 +110,7 @@ which resumes the audio context when the user clicks on the DOM Canvas element t

.. code-block:: cpp
void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData)
void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, bool success, void *userData)
{
if (!success) return; // Check browser console in a debug build for detailed errors
Expand All @@ -137,13 +137,13 @@ which resumes the audio context when the user clicks on the DOM Canvas element t

.. code-block:: cpp
EM_BOOL OnCanvasClick(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
bool OnCanvasClick(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
{
EMSCRIPTEN_WEBAUDIO_T audioContext = (EMSCRIPTEN_WEBAUDIO_T)userData;
if (emscripten_audio_context_state(audioContext) != AUDIO_CONTEXT_STATE_RUNNING) {
emscripten_resume_audio_context_sync(audioContext);
}
return EM_FALSE;
return false;
}
5. Finally we can implement the audio callback that is to generate the noise:
Expand All @@ -152,7 +152,7 @@ which resumes the audio context when the user clicks on the DOM Canvas element t
#include <emscripten/em_math.h>
EM_BOOL GenerateNoise(int numInputs, const AudioSampleFrame *inputs,
bool GenerateNoise(int numInputs, const AudioSampleFrame *inputs,
int numOutputs, AudioSampleFrame *outputs,
int numParams, const AudioParamFrame *params,
void *userData)
Expand All @@ -161,7 +161,7 @@ which resumes the audio context when the user clicks on the DOM Canvas element t
for(int j = 0; j < 128*outputs[i].numberOfChannels; ++j)
outputs[i].data[j] = emscripten_random() * 0.2 - 0.1; // Warning: scale down audio volume by factor of 0.2, raw noise can be really loud otherwise
return EM_TRUE; // Keep the graph output going
return true; // Keep the graph output going
}
And that's it! Compile the code with the linker flags ``-sAUDIO_WORKLET=1 -sWASM_WORKERS=1`` to enable targeting AudioWorklets.
Expand Down
4 changes: 2 additions & 2 deletions site/source/docs/porting/emscripten-runtime-environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ Typically you will have a small section with ``#ifdef __EMSCRIPTEN__`` for the t
// Our "main loop" function. This callback receives the current time as
// reported by the browser, and the user data we provide in the call to
// emscripten_request_animation_frame_loop().
EM_BOOL one_iter(double time, void* userData) {
bool one_iter(double time, void* userData) {
// Can render to the screen here, etc.
puts("one iteration");
// Return true to keep the loop running.
return EM_TRUE;
return true;
}
int main() {
Expand Down
146 changes: 73 additions & 73 deletions src/generated_struct_info32.json
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,15 @@
"nodeName": 0
},
"EmscriptenFullscreenChangeEvent": {
"__size__": 280,
"elementHeight": 268,
"elementWidth": 264,
"fullscreenEnabled": 4,
"id": 136,
"__size__": 276,
"elementHeight": 264,
"elementWidth": 260,
"fullscreenEnabled": 1,
"id": 130,
"isFullscreen": 0,
"nodeName": 8,
"screenHeight": 276,
"screenWidth": 272
"nodeName": 2,
"screenHeight": 272,
"screenWidth": 268
},
"EmscriptenFullscreenStrategy": {
"__size__": 24,
Expand All @@ -513,53 +513,53 @@
"scaleMode": 0
},
"EmscriptenGamepadEvent": {
"__size__": 1432,
"__size__": 1240,
"analogButton": 528,
"axis": 16,
"connected": 1296,
"connected": 1104,
"digitalButton": 1040,
"id": 1304,
"index": 1300,
"mapping": 1368,
"id": 1112,
"index": 1108,
"mapping": 1176,
"numAxes": 8,
"numButtons": 12,
"timestamp": 0
},
"EmscriptenKeyboardEvent": {
"__size__": 176,
"altKey": 20,
"charCode": 32,
"charValue": 108,
"code": 76,
"__size__": 160,
"altKey": 14,
"charCode": 20,
"charValue": 96,
"code": 64,
"ctrlKey": 12,
"key": 44,
"keyCode": 36,
"locale": 140,
"key": 32,
"keyCode": 24,
"locale": 128,
"location": 8,
"metaKey": 24,
"repeat": 28,
"shiftKey": 16,
"metaKey": 15,
"repeat": 16,
"shiftKey": 13,
"timestamp": 0,
"which": 40
"which": 28
},
"EmscriptenMouseEvent": {
"__size__": 72,
"altKey": 32,
"button": 40,
"buttons": 42,
"canvasX": 60,
"canvasY": 64,
"__size__": 64,
"altKey": 26,
"button": 28,
"buttons": 30,
"canvasX": 48,
"canvasY": 52,
"clientX": 16,
"clientY": 20,
"ctrlKey": 24,
"metaKey": 36,
"movementX": 44,
"movementY": 48,
"metaKey": 27,
"movementX": 32,
"movementY": 36,
"screenX": 8,
"screenY": 12,
"shiftKey": 28,
"targetX": 52,
"targetY": 56,
"shiftKey": 25,
"targetX": 40,
"targetY": 44,
"timestamp": 0
},
"EmscriptenOrientationChangeEvent": {
Expand All @@ -568,36 +568,36 @@
"orientationIndex": 0
},
"EmscriptenPointerlockChangeEvent": {
"__size__": 260,
"id": 132,
"__size__": 257,
"id": 129,
"isActive": 0,
"nodeName": 4
"nodeName": 1
},
"EmscriptenTouchEvent": {
"__size__": 1696,
"altKey": 20,
"__size__": 1552,
"altKey": 14,
"ctrlKey": 12,
"metaKey": 24,
"metaKey": 15,
"numTouches": 8,
"shiftKey": 16,
"shiftKey": 13,
"timestamp": 0,
"touches": 28
"touches": 16
},
"EmscriptenTouchPoint": {
"__size__": 52,
"canvasX": 44,
"canvasY": 48,
"__size__": 48,
"canvasX": 40,
"canvasY": 44,
"clientX": 12,
"clientY": 16,
"identifier": 0,
"isChanged": 28,
"onTarget": 32,
"onTarget": 29,
"pageX": 20,
"pageY": 24,
"screenX": 4,
"screenY": 8,
"targetX": 36,
"targetY": 40
"targetX": 32,
"targetY": 36
},
"EmscriptenUiEvent": {
"__size__": 36,
Expand All @@ -617,26 +617,26 @@
"visibilityState": 4
},
"EmscriptenWebGLContextAttributes": {
"__size__": 56,
"__size__": 36,
"alpha": 0,
"antialias": 12,
"depth": 4,
"enableExtensionsByDefault": 40,
"explicitSwapControl": 44,
"failIfMajorPerformanceCaveat": 28,
"majorVersion": 32,
"minorVersion": 36,
"powerPreference": 24,
"premultipliedAlpha": 16,
"preserveDrawingBuffer": 20,
"proxyContextToMainThread": 48,
"renderViaOffscreenBackBuffer": 52,
"stencil": 8
"antialias": 3,
"depth": 1,
"enableExtensionsByDefault": 24,
"explicitSwapControl": 25,
"failIfMajorPerformanceCaveat": 12,
"majorVersion": 16,
"minorVersion": 20,
"powerPreference": 8,
"premultipliedAlpha": 4,
"preserveDrawingBuffer": 5,
"proxyContextToMainThread": 28,
"renderViaOffscreenBackBuffer": 32,
"stencil": 2
},
"EmscriptenWebSocketCloseEvent": {
"__size__": 524,
"code": 8,
"reason": 10,
"__size__": 520,
"code": 6,
"reason": 8,
"wasClean": 4
},
"EmscriptenWebSocketCreateAttributes": {
Expand All @@ -650,11 +650,11 @@
"numBytes": 8
},
"EmscriptenWheelEvent": {
"__size__": 104,
"deltaMode": 96,
"deltaX": 72,
"deltaY": 80,
"deltaZ": 88,
"__size__": 96,
"deltaMode": 88,
"deltaX": 64,
"deltaY": 72,
"deltaZ": 80,
"mouse": 0
},
"SDL_AudioSpec": {
Expand Down
Loading

0 comments on commit dc0f6e5

Please sign in to comment.