Fix ArrayBuffer from openfl.Vector on Neko

This commit is contained in:
Joshua Granick
2015-01-16 09:47:40 -08:00
parent 9c3e022fca
commit d2a2ed5cd2
6 changed files with 168 additions and 0 deletions

View File

@@ -14,6 +14,34 @@ typedef Int16Array = js.html.Int16Array;
public function new #if !java <T> #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null<Int> = null) {
#if (openfl && neko && !lime_legacy)
if (Std.is (bufferOrArray, openfl.Vector.VectorData)) {
var vector:openfl.Vector<Int> = cast bufferOrArray;
var ints:Array<Int> = 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);

View File

@@ -14,6 +14,34 @@ typedef Int32Array = js.html.Int32Array;
public function new #if !java <T> #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null<Int> = null) {
#if (openfl && neko && !lime_legacy)
if (Std.is (bufferOrArray, openfl.Vector.VectorData)) {
var vector:openfl.Vector<Int> = cast bufferOrArray;
var ints:Array<Int> = 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);

View File

@@ -14,6 +14,34 @@ typedef Int8Array = js.html.Int8Array;
public function new #if !java <T> #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null<Int> = null) {
#if (openfl && neko && !lime_legacy)
if (Std.is (bufferOrArray, openfl.Vector.VectorData)) {
var vector:openfl.Vector<Int> = cast bufferOrArray;
var ints:Array<Int> = 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));

View File

@@ -14,6 +14,34 @@ typedef UInt16Array = js.html.Uint16Array;
public function new #if !java <T> #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null<Int> = null) {
#if (openfl && neko && !lime_legacy)
if (Std.is (bufferOrArray, openfl.Vector.VectorData)) {
var vector:openfl.Vector<Int> = cast bufferOrArray;
var ints:Array<Int> = 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);

View File

@@ -14,6 +14,34 @@ typedef UInt32Array = js.html.Uint32Array;
public function new #if !java <T> #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null<Int> = null) {
#if (openfl && neko && !lime_legacy)
if (Std.is (bufferOrArray, openfl.Vector.VectorData)) {
var vector:openfl.Vector<Int> = cast bufferOrArray;
var ints:Array<Int> = 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);

View File

@@ -14,6 +14,34 @@ typedef UInt8Array = js.html.Uint8Array;
public function new #if !java <T> #end (bufferOrArray:#if !java T #else Dynamic #end, start:Int = 0, length:Null<Int> = null) {
#if (openfl && neko && !lime_legacy)
if (Std.is (bufferOrArray, openfl.Vector.VectorData)) {
var vector:openfl.Vector<Int> = cast bufferOrArray;
var ints:Array<Int> = 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));