Skip to content

Commit

Permalink
Extract JSEvents.memcpy helper. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Nov 4, 2024
1 parent 8bbe1f8 commit 5c344e1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ var LibraryHTML5 = {
currentEventHandler: null,
#endif
*/
memcpy(target, src, size) {
HEAP32.set(HEAP32.subarray(src, src + size), target);
},

removeAllEventListeners() {
while (JSEvents.eventHandlers.length) {
Expand Down Expand Up @@ -594,7 +597,7 @@ var LibraryHTML5 = {
// HTML5 does not really have a polling API for mouse events, so implement one manually by
// returning the data from the most recently received event. This requires that user has registered
// at least some no-op function as an event handler to any of the mouse function.
HEAP8.set(HEAP8.subarray(JSEvents.mouseEvent, JSEvents.mouseEvent + {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}}), mouseState);
JSEvents.memcpy(mouseState, JSEvents.mouseEvent, {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}});
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},

Expand Down Expand Up @@ -852,7 +855,7 @@ var LibraryHTML5 = {
// HTML5 does not really have a polling API for device orientation events, so implement one manually by
// returning the data from the most recently received event. This requires that user has registered
// at least some no-op function as an event handler.
HEAP32.set(HEAP32.subarray(JSEvents.deviceOrientationEvent, {{{ C_STRUCTS.EmscriptenDeviceOrientationEvent.__size__ }}}), orientationState);
JSEvents.memcpy(orientationState, JSEvents.deviceOrientationEvent, {{{ C_STRUCTS.EmscriptenDeviceOrientationEvent.__size__ }}});
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},

Expand Down Expand Up @@ -922,7 +925,7 @@ var LibraryHTML5 = {
// HTML5 does not really have a polling API for device motion events, so implement one manually by
// returning the data from the most recently received event. This requires that user has registered
// at least some no-op function as an event handler.
HEAP32.set(HEAP32.subarray(JSEvents.deviceMotionEvent, {{{ C_STRUCTS.EmscriptenDeviceMotionEvent.__size__ }}}), motionState);
JSEvents.memcpy(motionState, JSEvents.deviceMotionEvent, {{{ C_STRUCTS.EmscriptenDeviceMotionEvent.__size__ }}});
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},

Expand Down

0 comments on commit 5c344e1

Please sign in to comment.