|
@@ -1,6 +1,46 @@
|
|
package hxd;
|
|
package hxd;
|
|
|
|
|
|
-private typedef InnerData = #if flash flash.Vector<Float> #else Array<hxd.impl.Float32> #end
|
|
|
|
|
|
+private typedef InnerData = #if flash flash.Vector<Float> #elseif js Float32Expand #else Array<hxd.impl.Float32> #end
|
|
|
|
+
|
|
|
|
+#if js
|
|
|
|
+private abstract Float32Expand({ pos : Int, array : js.html.Float32Array }) {
|
|
|
|
+
|
|
|
|
+ public var length(get, set) : Int;
|
|
|
|
+
|
|
|
|
+ public function new(length) {
|
|
|
|
+ this = { pos : 0, array : new js.html.Float32Array(new js.html.ArrayBuffer(length)) };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ inline function get_length() return this.array.length;
|
|
|
|
+ inline function set_length(v:Int) {
|
|
|
|
+ if( length != v ) {
|
|
|
|
+ var newArray = new js.html.Float32Array(v);
|
|
|
|
+ newArray.set(this.array);
|
|
|
|
+ this.array = newArray;
|
|
|
|
+ }
|
|
|
|
+ this.pos = v;
|
|
|
|
+ return v;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public inline function push(v:Float) {
|
|
|
|
+ if( this.pos == this.array.length ) {
|
|
|
|
+ var newSize = this.array.length << 1;
|
|
|
|
+ if( newSize < 128 ) newSize = 128;
|
|
|
|
+ var newArray = new js.html.Float32Array(newSize);
|
|
|
|
+ newArray.set(this.array);
|
|
|
|
+ this.array = newArray;
|
|
|
|
+ }
|
|
|
|
+ this.array[this.pos++] = v;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @:arrayAccess inline function get(index) return this.array[index];
|
|
|
|
+ @:arrayAccess inline function set(index,v:Float) return this.array[index] = v;
|
|
|
|
+
|
|
|
|
+ @:to inline function toF32Array() return this.array;
|
|
|
|
+ @:to inline function toArray() return [for( i in 0...this.pos ) this.array[i]];
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+#end
|
|
|
|
|
|
private class InnerIterator {
|
|
private class InnerIterator {
|
|
var b : InnerData;
|
|
var b : InnerData;
|
|
@@ -24,9 +64,7 @@ abstract FloatBuffer(InnerData) {
|
|
public var length(get, never) : Int;
|
|
public var length(get, never) : Int;
|
|
|
|
|
|
public inline function new(length = 0) {
|
|
public inline function new(length = 0) {
|
|
- #if js
|
|
|
|
- this = untyped __new__(Array, length);
|
|
|
|
- #elseif flash
|
|
|
|
|
|
+ #if (flash || js)
|
|
this = new InnerData(length);
|
|
this = new InnerData(length);
|
|
#else
|
|
#else
|
|
this = new InnerData();
|
|
this = new InnerData();
|
|
@@ -54,7 +92,7 @@ abstract FloatBuffer(InnerData) {
|
|
}
|
|
}
|
|
|
|
|
|
public inline function resize( v : Int ) {
|
|
public inline function resize( v : Int ) {
|
|
- #if flash
|
|
|
|
|
|
+ #if (flash||js)
|
|
this.length = v;
|
|
this.length = v;
|
|
#else
|
|
#else
|
|
if( this.length > v ) this.splice(v, this.length - v) else grow(v);
|
|
if( this.length > v ) this.splice(v, this.length - v) else grow(v);
|