diff --git a/lime/utils/Int16Array.hx b/lime/utils/Int16Array.hx index 9876d239d..cc8971c25 100644 --- a/lime/utils/Int16Array.hx +++ b/lime/utils/Int16Array.hx @@ -14,6 +14,34 @@ typedef Int16Array = js.html.Int16Array; public function new #if !java #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null = null) { + #if (openfl && neko && !lime_legacy) + if (Std.is (bufferOrArray, openfl.Vector.VectorData)) { + + var vector:openfl.Vector = cast bufferOrArray; + var ints:Array = vector; + this.length = (length != null) ? length : ints.length - start; + + super (this.length << 1); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i16 (bytes, (i << 1), ints[i + start]); + #else + buffer.writeShort (ints[i + start]); + #end + + } + + return; + + } + #end + if (Std.is (bufferOrArray, Int)) { super (Std.int (cast bufferOrArray) << 1); diff --git a/lime/utils/Int32Array.hx b/lime/utils/Int32Array.hx index 180ad8763..e3cfcf0c0 100644 --- a/lime/utils/Int32Array.hx +++ b/lime/utils/Int32Array.hx @@ -14,6 +14,34 @@ typedef Int32Array = js.html.Int32Array; public function new #if !java #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null = null) { + #if (openfl && neko && !lime_legacy) + if (Std.is (bufferOrArray, openfl.Vector.VectorData)) { + + var vector:openfl.Vector = cast bufferOrArray; + var ints:Array = vector; + this.length = (length != null) ? length : ints.length - start; + + super (this.length << 2); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i32 (bytes, (i << 2), ints[i + start]); + #else + buffer.writeInt (ints[i + start]); + #end + + } + + return; + + } + #end + if (Std.is (bufferOrArray, Int)) { super (Std.int (cast bufferOrArray) << 2); diff --git a/lime/utils/Int8Array.hx b/lime/utils/Int8Array.hx index 6d6e5da83..937727874 100644 --- a/lime/utils/Int8Array.hx +++ b/lime/utils/Int8Array.hx @@ -14,6 +14,34 @@ typedef Int8Array = js.html.Int8Array; public function new #if !java #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null = null) { + #if (openfl && neko && !lime_legacy) + if (Std.is (bufferOrArray, openfl.Vector.VectorData)) { + + var vector:openfl.Vector = cast bufferOrArray; + var ints:Array = vector; + this.length = (length != null) ? length : ints.length - start; + + super (this.length); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_byte (bytes, i, ints[i + start]); + #else + buffer.writeByte (ints[i + start]); + #end + + } + + return; + + } + #end + if (Std.is (bufferOrArray, Int)) { super (Std.int (cast bufferOrArray)); diff --git a/lime/utils/UInt16Array.hx b/lime/utils/UInt16Array.hx index eeab11bcd..bda0836c2 100644 --- a/lime/utils/UInt16Array.hx +++ b/lime/utils/UInt16Array.hx @@ -14,6 +14,34 @@ typedef UInt16Array = js.html.Uint16Array; public function new #if !java #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null = null) { + #if (openfl && neko && !lime_legacy) + if (Std.is (bufferOrArray, openfl.Vector.VectorData)) { + + var vector:openfl.Vector = cast bufferOrArray; + var ints:Array = vector; + this.length = (length != null) ? length : ints.length - start; + + super (this.length << 1); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_ui16 (bytes, (i << 1), ints[i + start]); + #else + buffer.writeShort (ints[i + start]); + #end + + } + + return; + + } + #end + if (Std.is (bufferOrArray, Int)) { super (Std.int (cast bufferOrArray) << 1); diff --git a/lime/utils/UInt32Array.hx b/lime/utils/UInt32Array.hx index 87d4a620e..fe51efdb3 100644 --- a/lime/utils/UInt32Array.hx +++ b/lime/utils/UInt32Array.hx @@ -14,6 +14,34 @@ typedef UInt32Array = js.html.Uint32Array; public function new #if !java #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null = null) { + #if (openfl && neko && !lime_legacy) + if (Std.is (bufferOrArray, openfl.Vector.VectorData)) { + + var vector:openfl.Vector = cast bufferOrArray; + var ints:Array = vector; + this.length = (length != null) ? length : ints.length - start; + + super (this.length << 2); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_ui32 (bytes, (i << 2), ints[i + start]); + #else + buffer.writeInt (ints[i + start]); + #end + + } + + return; + + } + #end + if (Std.is (bufferOrArray, Int)) { super (Std.int (cast bufferOrArray) << 2); diff --git a/lime/utils/UInt8Array.hx b/lime/utils/UInt8Array.hx index 09718429e..6e64ecb13 100644 --- a/lime/utils/UInt8Array.hx +++ b/lime/utils/UInt8Array.hx @@ -14,6 +14,34 @@ typedef UInt8Array = js.html.Uint8Array; public function new #if !java #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null = null) { + #if (openfl && neko && !lime_legacy) + if (Std.is (bufferOrArray, openfl.Vector.VectorData)) { + + var vector:openfl.Vector = cast bufferOrArray; + var ints:Array = vector; + this.length = (length != null) ? length : ints.length - start; + + super (this.length); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_byte (bytes, i, ints[i + start]); + #else + buffer.writeByte (ints[i + start]); + #end + + } + + return; + + } + #end + if (Std.is (bufferOrArray, Int)) { super (Std.int (cast bufferOrArray));