Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Armpack macro compatibility #136

Merged
merged 2 commits into from Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions Sources/iron/data/SceneFormat.hx
@@ -1,9 +1,18 @@
package iron.data;

#if !macro
import kha.FastFloat;
import kha.arrays.Float32Array;
import kha.arrays.Uint32Array;
import kha.arrays.Int16Array;
#end

#if macro
typedef Float32Array = haxe.io.Float32Array;
typedef Uint32Array = haxe.io.UInt32Array;
typedef Int16Array = haxe.io.UInt16Array;
typedef FastFloat = Float;
#end

#if js
typedef TSceneFormat = {
Expand Down
16 changes: 11 additions & 5 deletions Sources/iron/system/ArmPack.hx
Expand Up @@ -24,20 +24,22 @@ import haxe.io.Bytes;
import haxe.io.BytesInput;
import haxe.io.BytesOutput;
import haxe.io.Eof;
import iron.data.SceneFormat;
#if !macro
import kha.arrays.Float32Array;
import kha.arrays.Uint32Array;
import kha.arrays.Int16Array;
import iron.data.SceneFormat;
#end

class ArmPack {

public static inline function decode(b: Bytes): Dynamic {
public static inline function decode<T>(b: Bytes): T {
var i = new BytesInput(b);
i.bigEndian = false;
return read(i);
}

static function read(i: BytesInput, key = "", parentKey = ""): Dynamic {
static function read(i: BytesInput, key = "", parentKey = "") : Any {
try {
var b = i.readByte();
switch (b) {
Expand Down Expand Up @@ -76,7 +78,7 @@ class ArmPack {
return null;
}

static function readArray(i: BytesInput, length: Int, key = "", parentKey = ""): Dynamic {
static function readArray(i: BytesInput, length: Int, key = "", parentKey = ""): Any {
var b = i.readByte();
i.position--;

Expand Down Expand Up @@ -105,7 +107,7 @@ class ArmPack {
}
}

static function readMap(i: BytesInput, length: Int, key = "", parentKey = ""): Dynamic {
static function readMap(i: BytesInput, length: Int, key = "", parentKey = ""): Any {
#if js
var out = {};
#else
Expand Down Expand Up @@ -162,6 +164,8 @@ class ArmPack {
}
#end

#if !macro

public static inline function encode(d: Dynamic): Bytes {
var o = new BytesOutput();
o.bigEndian = false;
Expand Down Expand Up @@ -227,4 +231,6 @@ class ArmPack {
default: {}
}
}

#end
}
7 changes: 6 additions & 1 deletion Sources/iron/system/Lz4.hx
Expand Up @@ -22,8 +22,13 @@
package iron.system;

import haxe.io.Bytes;
import kha.arrays.Uint8Array;
#if macro
import haxe.io.Int32Array;
typedef Uint8Array = haxe.io.UInt8Array;
#else
import kha.arrays.Int32Array;
import kha.arrays.Uint8Array;
#end

class Lz4 {

Expand Down