From bddce4f9879c6f23d87e0d76c13ff6e5e12b8751 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 6 Jul 2015 17:45:49 -0700 Subject: [PATCH] Sync changes with hxtypedarray repository --- lime/utils/ArrayBufferView.hx | 21 +++++++ lime/utils/DataView.hx | 99 ++++++++++++++++++++++++++++++++- lime/utils/Float32Array.hx | 15 +++-- lime/utils/Float64Array.hx | 15 +++-- lime/utils/Int16Array.hx | 13 ++++- lime/utils/Int32Array.hx | 14 +++-- lime/utils/Int8Array.hx | 15 +++-- lime/utils/UInt16Array.hx | 15 +++-- lime/utils/UInt32Array.hx | 13 ++++- lime/utils/UInt8Array.hx | 16 ++++-- lime/utils/UInt8ClampedArray.hx | 13 +++-- 11 files changed, 212 insertions(+), 37 deletions(-) diff --git a/lime/utils/ArrayBufferView.hx b/lime/utils/ArrayBufferView.hx index 9a84ae3a0..8979b9d8d 100644 --- a/lime/utils/ArrayBufferView.hx +++ b/lime/utils/ArrayBufferView.hx @@ -239,6 +239,27 @@ class ArrayBufferView { } + #if !no_typedarray_inline inline #end + function toString() { + + var name = + switch(type) { + case Int8: 'Int8Array'; + case Uint8: 'UInt8Array'; + case Uint8Clamped: 'UInt8ClampedArray'; + case Int16: 'Int16Array'; + case Uint16: 'UInt16Array'; + case Int32: 'Int32Array'; + case Uint32: 'UInt32Array'; + case Float32: 'Float32Array'; + case Float64: 'Float64Array'; + case _: 'ArrayBufferView'; + } + + return name + ' [byteLength:${this.byteLength}, length:${this.length}]'; + + } //toString + #if !no_typedarray_inline inline #end function toByteLength( elemCount:Int ) : Int { diff --git a/lime/utils/DataView.hx b/lime/utils/DataView.hx index 52fddee96..967d3a83c 100644 --- a/lime/utils/DataView.hx +++ b/lime/utils/DataView.hx @@ -2,7 +2,102 @@ package lime.utils; #if (js && !display) - typedef DataView = js.html.DataView; + @:forward + abstract DataView(js.html.DataView) + from js.html.DataView + to js.html.DataView { + + public inline function new( buffer:ArrayBuffer, byteOffset:Null = null, byteLength:Null = null ) { + if(byteOffset != null && byteLength == null) this = new js.html.DataView( buffer, byteOffset ); + else if(byteOffset != null && byteLength != null) this = new js.html.DataView( buffer, byteOffset, byteLength); + else this = new js.html.DataView( buffer ); + } + + #if !no_typedarray_inline inline #end + public function getInt8( byteOffset:Int ) : Int { + return this.getInt8( byteOffset); + } + + #if !no_typedarray_inline inline #end + public function getInt16( byteOffset:Int, ?littleEndian:Bool = true ) : Int { + return this.getInt16( byteOffset, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function getInt32( byteOffset:Int, ?littleEndian:Bool = true ) : Int { + return this.getInt32( byteOffset, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function getUint8( byteOffset:Int ) : UInt { + return this.getUint8( byteOffset); + } + + #if !no_typedarray_inline inline #end + public function getUint16( byteOffset:Int, ?littleEndian:Bool = true ) : UInt { + return this.getUint16( byteOffset, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function getUint32( byteOffset:Int, ?littleEndian:Bool = true ) : UInt { + return this.getUint32( byteOffset, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function getFloat32( byteOffset:Int, ?littleEndian:Bool = true ) : Float { + return this.getFloat32( byteOffset, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function getFloat64( byteOffset:Int, ?littleEndian:Bool = true ) : Float { + return this.getFloat64( byteOffset, littleEndian); + } + + + + + #if !no_typedarray_inline inline #end + public function setInt8( byteOffset:Int, value:Int ) { + this.setInt8( byteOffset, value); + } + + #if !no_typedarray_inline inline #end + public function setInt16( byteOffset:Int, value:Int, ?littleEndian:Bool = true) { + this.setInt16( byteOffset, value, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function setInt32( byteOffset:Int, value:Int, ?littleEndian:Bool = true) { + this.setInt32( byteOffset, value, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function setUint8( byteOffset:Int, value:UInt ) { + this.setUint8( byteOffset, value); + } + + #if !no_typedarray_inline inline #end + public function setUint16( byteOffset:Int, value:UInt, ?littleEndian:Bool = true) { + this.setUint16( byteOffset, value, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function setUint32( byteOffset:Int, value:UInt, ?littleEndian:Bool = true) { + this.setUint32( byteOffset, value, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function setFloat32( byteOffset:Int, value:Float, ?littleEndian:Bool = true) { + this.setFloat32( byteOffset, value, littleEndian); + } + + #if !no_typedarray_inline inline #end + public function setFloat64( byteOffset:Int, value:Float, ?littleEndian:Bool = true) { + this.setFloat64( byteOffset, value, littleEndian); + } + + } + #else @@ -127,4 +222,4 @@ class DataView { } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/Float32Array.hx b/lime/utils/Float32Array.hx index 0f04c8709..258a9e539 100644 --- a/lime/utils/Float32Array.hx +++ b/lime/utils/Float32Array.hx @@ -23,11 +23,12 @@ package lime.utils; this = new js.html.Float32Array( untyped array ); } else if(view != null) { this = new js.html.Float32Array( untyped view ); - } else if (buffer != null) { - if (len == null) + } else if(buffer != null) { + if(len == null) { this = new js.html.Float32Array( buffer, byteoffset ); - else + } else { this = new js.html.Float32Array( buffer, byteoffset, len ); + } } else { this = null; } @@ -39,6 +40,8 @@ package lime.utils; //non spec haxe conversions public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Float32Array { + if(byteOffset == null) return new js.html.Float32Array(cast bytes.getData()); + if(len == null) return new js.html.Float32Array(cast bytes.getData(), byteOffset); return new js.html.Float32Array(cast bytes.getData(), byteOffset, len); } @@ -50,6 +53,8 @@ package lime.utils; #end } + function toString() return 'Float32Array [byteLength:${this.byteLength}, length:${this.length}]'; + } #else @@ -102,6 +107,8 @@ abstract Float32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { //Internal + function toString() return 'Float32Array [byteLength:${this.byteLength}, length:${this.length}]'; + inline function get_length() return this.length; @@ -119,4 +126,4 @@ abstract Float32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/Float64Array.hx b/lime/utils/Float64Array.hx index 813879dfb..7046cfa77 100644 --- a/lime/utils/Float64Array.hx +++ b/lime/utils/Float64Array.hx @@ -23,11 +23,12 @@ package lime.utils; this = new js.html.Float64Array( untyped array ); } else if(view != null) { this = new js.html.Float64Array( untyped view ); - } else if (buffer != null) { - if (len == null) + } else if(buffer != null) { + if(len == null) { this = new js.html.Float64Array( buffer, byteoffset ); - else + } else { this = new js.html.Float64Array( buffer, byteoffset, len ); + } } else { this = null; } @@ -39,6 +40,8 @@ package lime.utils; //non spec haxe conversions public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Float64Array { + if(byteOffset == null) return new js.html.Float64Array(cast bytes.getData()); + if(len == null) return new js.html.Float64Array(cast bytes.getData(), byteOffset); return new js.html.Float64Array(cast bytes.getData(), byteOffset, len); } @@ -50,6 +53,8 @@ package lime.utils; #end } + function toString() return 'Float64Array [byteLength:${this.byteLength}, length:${this.length}]'; + } #else @@ -116,6 +121,8 @@ abstract Float64Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { return ArrayBufferIO.setFloat64(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val); } + function toString() return 'Float64Array [byteLength:${this.byteLength}, length:${this.length}]'; + } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/Int16Array.hx b/lime/utils/Int16Array.hx index 161f76185..432ed36a6 100644 --- a/lime/utils/Int16Array.hx +++ b/lime/utils/Int16Array.hx @@ -24,10 +24,11 @@ package lime.utils; } else if(view != null) { this = new js.html.Int16Array( untyped view ); } else if(buffer != null) { - if (len == null) + if(len == null) { this = new js.html.Int16Array( buffer, byteoffset ); - else + } else { this = new js.html.Int16Array( buffer, byteoffset, len ); + } } else { this = null; } @@ -39,6 +40,8 @@ package lime.utils; //non spec haxe conversions public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Int16Array { + if(byteOffset == null) return new js.html.Int16Array(cast bytes.getData()); + if(len == null) return new js.html.Int16Array(cast bytes.getData(), byteOffset); return new js.html.Int16Array(cast bytes.getData(), byteOffset, len); } @@ -50,6 +53,8 @@ package lime.utils; #end } + function toString() return 'Int16Array [byteLength:${this.byteLength}, length:${this.length}]'; + } #else @@ -116,6 +121,8 @@ abstract Int16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { return ArrayBufferIO.setInt16(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val); } + function toString() return 'Int16Array [byteLength:${this.byteLength}, length:${this.length}]'; + } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/Int32Array.hx b/lime/utils/Int32Array.hx index 389024dfb..7baaeba09 100644 --- a/lime/utils/Int32Array.hx +++ b/lime/utils/Int32Array.hx @@ -24,10 +24,11 @@ package lime.utils; } else if(view != null) { this = new js.html.Int32Array( untyped view ); } else if(buffer != null) { - if (len == null) + if(len == null) { this = new js.html.Int32Array( buffer, byteoffset ); - else + } else { this = new js.html.Int32Array( buffer, byteoffset, len ); + } } else { this = null; } @@ -39,6 +40,8 @@ package lime.utils; //non spec haxe conversions public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Int32Array { + if(byteOffset == null) return new js.html.Int32Array(cast bytes.getData()); + if(len == null) return new js.html.Int32Array(cast bytes.getData(), byteOffset); return new js.html.Int32Array(cast bytes.getData(), byteOffset, len); } @@ -50,13 +53,14 @@ package lime.utils; #end } + function toString() return 'Int32Array [byteLength:${this.byteLength}, length:${this.length}]'; + } #else import lime.utils.ArrayBufferView; - @:forward() @:arrayAccess abstract Int32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { @@ -117,6 +121,8 @@ abstract Int32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { return ArrayBufferIO.setInt32(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val); } + function toString() return 'Int32Array [byteLength:${this.byteLength}, length:${this.length}]'; + } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/Int8Array.hx b/lime/utils/Int8Array.hx index 01f90edde..a56682848 100644 --- a/lime/utils/Int8Array.hx +++ b/lime/utils/Int8Array.hx @@ -24,10 +24,11 @@ package lime.utils; } else if(view != null) { this = new js.html.Int8Array( untyped view ); } else if(buffer != null) { - if (len == null) + if(len == null) { this = new js.html.Int8Array( buffer, byteoffset ); - else + } else { this = new js.html.Int8Array( buffer, byteoffset, len ); + } } else { this = null; } @@ -50,6 +51,8 @@ package lime.utils; #end } + function toString() return 'Int8Array [byteLength:${this.byteLength}, length:${this.length}]'; + } #else @@ -92,7 +95,9 @@ abstract Int8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { //non spec haxe conversions public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Int8Array { - return new Int8Array(bytes, byteOffset, len); + if(byteOffset == null) return new Int8Array(cast bytes.getData()); + if(len == null) return new Int8Array(cast bytes.getData(), byteOffset); + return new Int8Array(cast bytes.getData(), byteOffset, len); } public function toBytes() : haxe.io.Bytes { @@ -116,6 +121,8 @@ abstract Int8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { return ArrayBufferIO.setInt8(this.buffer, this.byteOffset+idx, val); } + function toString() return 'Int8Array [byteLength:${this.byteLength}, length:${this.length}]'; + } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/UInt16Array.hx b/lime/utils/UInt16Array.hx index aa0de3b0a..81b99b2ed 100644 --- a/lime/utils/UInt16Array.hx +++ b/lime/utils/UInt16Array.hx @@ -24,10 +24,11 @@ package lime.utils; } else if(view != null) { this = new js.html.Uint16Array( untyped view ); } else if(buffer != null) { - if (len == null) + if(len == null) { this = new js.html.Uint16Array( buffer, byteoffset ); - else + } else { this = new js.html.Uint16Array( buffer, byteoffset, len ); + } } else { this = null; } @@ -39,6 +40,8 @@ package lime.utils; //non spec haxe conversions public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt16Array { + if(byteOffset == null) return new js.html.Uint16Array(cast bytes.getData()); + if(len == null) return new js.html.Uint16Array(cast bytes.getData(), byteOffset); return new js.html.Uint16Array(cast bytes.getData(), byteOffset, len); } @@ -50,6 +53,8 @@ package lime.utils; #end } + function toString() return 'UInt16Array [byteLength:${this.byteLength}, length:${this.length}]'; + } #else @@ -91,7 +96,7 @@ abstract UInt16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { //non spec haxe conversions - public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt16Array { + public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Uint16Array { return new UInt16Array(bytes, byteOffset, len); } @@ -116,6 +121,8 @@ abstract UInt16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { return ArrayBufferIO.setUint16(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val); } + function toString() return 'UInt16Array [byteLength:${this.byteLength}, length:${this.length}]'; + } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/UInt32Array.hx b/lime/utils/UInt32Array.hx index 49e45fa04..1dcb82f71 100644 --- a/lime/utils/UInt32Array.hx +++ b/lime/utils/UInt32Array.hx @@ -24,10 +24,11 @@ package lime.utils; } else if(view != null) { this = new js.html.Uint32Array( untyped view ); } else if(buffer != null) { - if (len == null) + if(len == null) { this = new js.html.Uint32Array( buffer, byteoffset ); - else + } else { this = new js.html.Uint32Array( buffer, byteoffset, len ); + } } else { this = null; } @@ -39,6 +40,8 @@ package lime.utils; //non spec haxe conversions public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt32Array { + if(byteOffset == null) return new js.html.Uint32Array(cast bytes.getData()); + if(len == null) return new js.html.Uint32Array(cast bytes.getData(), byteOffset); return new js.html.Uint32Array(cast bytes.getData(), byteOffset, len); } @@ -50,6 +53,8 @@ package lime.utils; #end } + function toString() return 'UInt32Array [byteLength:${this.byteLength}, length:${this.length}]'; + } #else @@ -116,6 +121,8 @@ abstract UInt32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { return ArrayBufferIO.setUint32(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val); } + function toString() return 'UInt32Array [byteLength:${this.byteLength}, length:${this.length}]'; + } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/UInt8Array.hx b/lime/utils/UInt8Array.hx index 2dfe2442c..f586bd7e5 100644 --- a/lime/utils/UInt8Array.hx +++ b/lime/utils/UInt8Array.hx @@ -24,10 +24,11 @@ package lime.utils; } else if(view != null) { this = new js.html.Uint8Array( untyped view ); } else if(buffer != null) { - if (len == null) + if(len == null) { this = new js.html.Uint8Array( buffer, byteoffset ); - else + } else { this = new js.html.Uint8Array( buffer, byteoffset, len ); + } } else { this = null; } @@ -38,7 +39,9 @@ package lime.utils; //non spec haxe conversions - public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt8Array { + public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int, ?len:Int ) : UInt8Array { + if(byteOffset == null) return new js.html.Uint8Array(cast bytes.getData()); + if(len == null) return new js.html.Uint8Array(cast bytes.getData(), byteOffset); return new js.html.Uint8Array(cast bytes.getData(), byteOffset, len); } @@ -50,13 +53,14 @@ package lime.utils; #end } + function toString() return 'UInt8Array [byteLength:${this.byteLength}, length:${this.length}]'; + } #else import lime.utils.ArrayBufferView; - @:forward() @:arrayAccess abstract UInt8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { @@ -102,6 +106,8 @@ abstract UInt8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { //Internal + function toString() return 'UInt8Array [byteLength:${this.byteLength}, length:${this.length}]'; + inline function get_length() return this.length; @@ -119,4 +125,4 @@ abstract UInt8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView { } -#end //!js +#end //!js \ No newline at end of file diff --git a/lime/utils/UInt8ClampedArray.hx b/lime/utils/UInt8ClampedArray.hx index 3aa2f681b..8d2cd8e4f 100644 --- a/lime/utils/UInt8ClampedArray.hx +++ b/lime/utils/UInt8ClampedArray.hx @@ -24,10 +24,11 @@ package lime.utils; } else if(view != null) { this = new js.html.Uint8ClampedArray( untyped view ); } else if(buffer != null) { - if (len == null) + if (len == null) { this = new js.html.Uint8ClampedArray( buffer, byteoffset ); - else + } else { this = new js.html.Uint8ClampedArray( buffer, byteoffset, len ); + } } else { this = null; } @@ -39,6 +40,8 @@ package lime.utils; //non spec haxe conversions public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt8ClampedArray { + if(byteOffset == null) return new js.html.Uint8ClampedArray(cast bytes.getData()); + if(len == null) return new js.html.Uint8ClampedArray(cast bytes.getData(), byteOffset); return new js.html.Uint8ClampedArray(cast bytes.getData(), byteOffset, len); } @@ -50,6 +53,8 @@ package lime.utils; #end } + function toString() return 'UInt8ClampedArray [byteLength:${this.byteLength}, length:${this.length}]'; + //internal //clamp a Int to a 0-255 Uint8 static function _clamp(_in:Float) : Int { @@ -64,7 +69,6 @@ package lime.utils; import lime.utils.ArrayBufferView; - @:forward() @:arrayAccess abstract UInt8ClampedArray(ArrayBufferView) from ArrayBufferView to ArrayBufferView { @@ -125,7 +129,8 @@ abstract UInt8ClampedArray(ArrayBufferView) from ArrayBufferView to ArrayBufferV return ArrayBufferIO.setUint8Clamped(this.buffer, this.byteOffset+idx, val); } + function toString() return 'UInt8ClampedArray [byteLength:${this.byteLength}, length:${this.length}]'; } -#end //!js +#end //!js \ No newline at end of file