You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Add JavaScriptBridge buffer methods
This commit is contained in:
@@ -127,6 +127,10 @@ const GodotJSWrapper = {
|
||||
GodotRuntime.setHeapValue(p_exchange, id, 'i64');
|
||||
return 24; // OBJECT
|
||||
},
|
||||
|
||||
isBuffer: function (obj) {
|
||||
return obj instanceof ArrayBuffer || ArrayBuffer.isView(obj);
|
||||
},
|
||||
},
|
||||
|
||||
godot_js_wrapper_interface_get__proxy: 'sync',
|
||||
@@ -303,6 +307,34 @@ const GodotJSWrapper = {
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
|
||||
godot_js_wrapper_object_is_buffer__proxy: 'sync',
|
||||
godot_js_wrapper_object_is_buffer__sig: 'ii',
|
||||
godot_js_wrapper_object_is_buffer: function (p_id) {
|
||||
const obj = GodotJSWrapper.get_proxied_value(p_id);
|
||||
return GodotJSWrapper.isBuffer(obj)
|
||||
? 1
|
||||
: 0;
|
||||
},
|
||||
|
||||
godot_js_wrapper_object_transfer_buffer__proxy: 'sync',
|
||||
godot_js_wrapper_object_transfer_buffer__sig: 'viiii',
|
||||
godot_js_wrapper_object_transfer_buffer: function (p_id, p_byte_arr, p_byte_arr_write, p_callback) {
|
||||
let obj = GodotJSWrapper.get_proxied_value(p_id);
|
||||
if (!GodotJSWrapper.isBuffer(obj)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(obj) && !(obj instanceof Uint8Array)) {
|
||||
obj = new Uint8Array(obj.buffer);
|
||||
} else if (obj instanceof ArrayBuffer) {
|
||||
obj = new Uint8Array(obj);
|
||||
}
|
||||
|
||||
const resizePackedByteArrayAndOpenWrite = GodotRuntime.get_func(p_callback);
|
||||
const bytesPtr = resizePackedByteArrayAndOpenWrite(p_byte_arr, p_byte_arr_write, obj.length);
|
||||
HEAPU8.set(obj, bytesPtr);
|
||||
},
|
||||
};
|
||||
|
||||
autoAddDeps(GodotJSWrapper, '$GodotJSWrapper');
|
||||
|
||||
Reference in New Issue
Block a user