Quellcode durchsuchen

cleanup old stuff (see #362)

Nicolas Cannasse vor 7 Jahren
Ursprung
Commit
684b6c44b9
8 geänderte Dateien mit 61 neuen und 841 gelöschten Zeilen
  1. 24 32
      hxd/Pixels.hx
  2. 0 130
      hxd/impl/FastIO.hx
  3. 0 99
      hxd/impl/Memory.hx
  4. 0 262
      hxd/impl/Partition.hx
  5. 0 292
      hxd/impl/PathFind.hx
  6. 30 0
      hxd/impl/UncheckedBytes.hx
  7. 7 8
      hxd/res/FontBuilder.hx
  8. 0 18
      hxd/snd/OggData.hx

+ 24 - 32
hxd/Pixels.hx

@@ -271,62 +271,54 @@ class Pixels {
 		if( format == target )
 			return;
 		willChange();
+		var bytes : hxd.impl.UncheckedBytes = bytes;
 		switch( [format, target] ) {
 		case [BGRA, ARGB], [ARGB, BGRA]:
 			// reverse bytes
-			var mem = hxd.impl.Memory.select(bytes);
 			for( i in 0...width*height ) {
 				var p = (i << 2) + offset;
-				var a = mem.b(p);
-				var r = mem.b(p+1);
-				var g = mem.b(p+2);
-				var b = mem.b(p+3);
-				mem.wb(p, b);
-				mem.wb(p+1, g);
-				mem.wb(p+2, r);
-				mem.wb(p+3, a);
+				var a = bytes[p];
+				var r = bytes[p+1];
+				var g = bytes[p+2];
+				var b = bytes[p+3];
+				bytes[p++] = b;
+				bytes[p++] = g;
+				bytes[p++] = r;
+				bytes[p] = a;
 			}
-			mem.end();
 		case [BGRA, RGBA], [RGBA,BGRA]:
-			var mem = hxd.impl.Memory.select(bytes);
 			for( i in 0...width*height ) {
 				var p = (i << 2) + offset;
-				var b = mem.b(p);
-				var r = mem.b(p+2);
-				mem.wb(p, r);
-				mem.wb(p+2, b);
+				var b = bytes[p];
+				var r = bytes[p+2];
+				bytes[p] = r;
+				bytes[p+2] = b;
 			}
-			mem.end();
 
 		case [ARGB, RGBA]:
-			var mem = hxd.impl.Memory.select(bytes);
 			for ( i in 0...width * height ) {
 				var p = (i << 2) + offset;
-				var a = (mem.b(p));
-
-				mem.wb(p, mem.b(p + 1));
-				mem.wb(p + 1, mem.b(p + 2));
-				mem.wb(p + 2, mem.b(p + 3));
-				mem.wb(p + 3, a);
+				var a = bytes[p];
+				bytes[p] = bytes[p+1];
+				bytes[p+1] = bytes[p+2];
+				bytes[p+2] = bytes[p+3];
+				bytes[p+3] = a;
 			}
-			mem.end();
 
 		case [RGBA, ARGB]:
-			var mem = hxd.impl.Memory.select(bytes);
 			for ( i in 0...width * height ) {
 				var p = (i << 2) + offset;
-				var a = (mem.b(p + 3));
-
-				mem.wb(p + 3, mem.b(p + 2));
-				mem.wb(p + 2, mem.b(p + 1));
-				mem.wb(p + 1, mem.b(p));
-				mem.wb(p, a);
+				var a = bytes[p+3];
+				bytes[p+3] = bytes[p+2];
+				bytes[p+2] = bytes[p+1];
+				bytes[p+1] = bytes[p];
+				bytes[p] = a;
 			}
-			mem.end();
 
 		default:
 			throw "Cannot convert from " + format + " to " + target;
 		}
+
 		innerFormat = target;
 	}
 

+ 0 - 130
hxd/impl/FastIO.hx

@@ -1,130 +0,0 @@
-package hxd.impl;
-
-@:generic
-class FastIO<T> {
-
-	var read : Int;
-	var write : Int;
-	var max : Int;
-	var table : #if flash flash.Vector<T> #else Array<T> #end;
-
-	public function new() {
-		reset();
-		table = #if flash new flash.Vector() #else [] #end;
-	}
-
-	public inline function reset() {
-		read = 0;
-		write = 0;
-		max = 0;
-	}
-
-	public inline function hasNext() {
-		return read < max;
-	}
-
-	public inline function next() : T {
-		return table[read++];
-	}
-
-	public inline function add( v : T ) {
-		table[write++] = v;
-	}
-
-	public inline function flush( count = 1000 ) {
-		if( read == write ) {
-			read = write = max = 0;
-		} else {
-			max = write;
-			if( write < read ) read = 0 else if( read > count ) write = 0;
-		}
-	}
-
-	public inline function flushMax( writesPerRead ) {
-		flush((write < read ? write : (write - read)) * writesPerRead);
-	}
-
-}
-
-class FastIntIO extends FastIO<Int> {
-
-	public inline function add2d( x, y, bits ) {
-		add(x | (y << bits));
-	}
-
-	public inline function add2di( x, y, d, bits ) {
-		add(x | ((y | (d << bits)) << bits));
-	}
-
-	public inline function loop(callb) {
-		while( true ) {
-			flushMax(4);
-			if( !hasNext() )
-				break;
-			for( id in this )
-				callb(id);
-		}
-	}
-
-	public inline function rec2d( x, y, bits, callb ) {
-		add2d(x, y, bits);
-		while( true ) {
-			flushMax(4);
-			if( !hasNext() )
-				break;
-			for( id in this ) {
-				var x = id & ((1 << bits) - 1);
-				var y = id >>> bits;
-				if( !callb(x,y) )
-					continue;
-				add2d(x + 1, y, bits);
-				add2d(x - 1, y, bits);
-				add2d(x, y + 1, bits);
-				add2d(x, y - 1, bits);
-			}
-		}
-	}
-
-	public inline function rec2di( x, y, d, bits, callb ) {
-		add2di(x, y, d, bits);
-		while( true ) {
-			flushMax(4);
-			if( !hasNext() )
-				break;
-			for( id in this ) {
-				var x = id & ((1 << bits) - 1);
-				var y = (id >>> bits) & ((1 << bits) - 1);
-				var d = id >>> (bits << 1);
-				d = callb(x, y, d);
-				if( d < 0 )
-					continue;
-				add2di(x + 1, y, d, bits);
-				add2di(x - 1, y, d, bits);
-				add2di(x, y + 1, d, bits);
-				add2di(x, y - 1, d, bits);
-			}
-		}
-	}
-
-	public inline function rec2dk( x, y, bits, callb ) {
-		var k = 0;
-		add2d(x, y, bits);
-		while( true ) {
-			flushMax(4);
-			if( !hasNext() )
-				break;
-			for( id in this ) {
-				var x = id & ((1 << bits) - 1);
-				var y = id >>> bits;
-				if( !callb(x,y,k) )
-					continue;
-				add2d(x + 1, y, bits);
-				add2d(x - 1, y, bits);
-				add2d(x, y + 1, bits);
-				add2d(x, y - 1, bits);
-			}
-			k++;
-		}
-	}
-
-}

+ 0 - 99
hxd/impl/Memory.hx

@@ -1,99 +0,0 @@
-package hxd.impl;
-
-@:access(hxd.impl.Memory)
-class MemoryReader {
-
-	public function new() {
-	}
-
-	public inline function b( addr : Int ) {
-		#if flash
-		return flash.Memory.getByte(addr);
-		#else
-		return Memory.current.get(addr);
-		#end
-	}
-
-	public inline function wb( addr : Int, v : Int ) {
-		#if flash
-		flash.Memory.setByte(addr, v);
-		#else
-		Memory.current.set(addr, v);
-		#end
-	}
-
-	public inline function double( addr : Int ) : Float {
-		#if flash
-		return flash.Memory.getDouble(addr);
-		#else
-		throw "TODO";
-		return 0.;
-		#end
-	}
-
-	public inline function float( addr : Int ) : Float {
-		#if flash
-		return flash.Memory.getFloat(addr);
-		#else
-		throw "TODO";
-		return 0.;
-		#end
-	}
-
-	public inline function wfloat( addr : Int, v : Float ) : Void {
-		#if flash
-		flash.Memory.setFloat(addr, v);
-		#else
-		throw "TODO";
-		#end
-	}
-
-	public inline function wdouble( addr : Int, v : Float ) : Void {
-		#if flash
-		flash.Memory.setDouble(addr, v);
-		#else
-		throw "TODO";
-		#end
-	}
-
-	public inline function i32( addr : Int ) : Int {
-		#if flash
-		return flash.Memory.getI32(addr);
-		#else
-		throw "TODO";
-		return 0;
-		#end
-	}
-
-	public inline function end() {
-		@:privateAccess Memory.end();
-	}
-
-}
-
-class Memory {
-
-	static var stack = new Array<haxe.io.Bytes>();
-	static var current : haxe.io.Bytes = null;
-	static var inst = new MemoryReader();
-
-	public static function select( b : haxe.io.Bytes ) {
-		#if flash
-		var data = b.getData();
-		if( data.length < 1024 ) data.length = 1024;
-		flash.Memory.select(data);
-		#end
-		if( current != null ) stack.push(current);
-		current = b;
-		return inst;
-	}
-
-	static function end() {
-		current = stack.pop();
-		#if flash
-		if( current != null )
-			flash.Memory.select(current.getData());
-		#end
-	}
-
-}

+ 0 - 262
hxd/impl/Partition.hx

@@ -1,262 +0,0 @@
-package hxd.impl;
-
-@:generic class PartitionChunk<T> {
-	public var x : Int;
-	public var y : Int;
-	public var px : Int;
-	public var py : Int;
-	public var elements : T;
-	public function new(x, y, px, py) {
-		this.x = x;
-		this.y = y;
-		this.px = px;
-		this.py = py;
-		elements = null;
-	}
-}
-
-@:generic class PartitionIterator < T: { partQueryNext:T } > {
-	var cur : T;
-	public inline function new(e) {
-		this.cur = e;
-	}
-	public inline function hasNext() {
-		return cur != null;
-	}
-	public inline function next() {
-		var e = cur;
-		cur = e.partQueryNext;
-		return e;
-	}
-}
-
-/**
-	Partition will segment a 2D space into chunks of 2^N size and keep track of each entity position.
-	It allows to perform efficient queries without checking all the entities.
-**/
-@:generic
-@:allow(hxd.impl.PartitionChunk)
-class Partition<T : { x : Float, y : Float, partChunk : Int, partNext : T, partQueryNext : T }> {
-
-	var chunks : haxe.ds.Vector<PartitionChunk<T>>;
-	var pbits : Int;
-	var psize : Int;
-	var pwidth : Int;
-	var pheight : Int;
-
-	/**
-		Creates a new partition for the given world size.
-		PBits tells the number of bits for the chunk size.
-		Using too large chunks will not perform well if there's too many entities into them.
-		Using too small chunks will require more often to move entities between chunks for each sync()
-	**/
-	public function new(width:Int, height:Int, pbits:Int) {
-		this.pbits = pbits;
-		this.psize = 1 << pbits;
-		this.pwidth = Math.ceil(width / psize);
-		this.pheight = Math.ceil(height / psize);
-		chunks = new haxe.ds.Vector(pwidth * pheight);
-		for( y in 0...pheight ) {
-			for( x in 0...pwidth ) {
-				var c = new PartitionChunk<T>(x, y, x * psize, y * psize);
-				chunks[x + y * pwidth] = c;
-			}
-		}
-	}
-
-	/**
-		Query a list of entities found within the given disc.
-		Important : query results are optimized to perform zero allocation, so making a query will overwrite the results from a previous one.
-		Make sure not to make a second query before the first one is fully processed.
-	**/
-	public inline function query( x : Float, y : Float, ray : Float ) : PartitionIterator<T> {
-		var q = runQueryDist(x, y, ray);
-		return new PartitionIterator(q);
-	}
-
-	public inline function count( x : Float, y : Float, ray : Float, cond : T -> Bool ) {
-		var k = 0;
-		iterElements(x, y, ray, function(e) {
-			if( cond(e) ) k++;
-		});
-		return k;
-	}
-
-	function runQueryDist(x, y, r) {
-		return runQueryInline(x, y, r, function(e) { var dx = e.x - x; var dy = e.y - y; return dx * dx + dy * dy; } );
-	}
-
-	inline function runQueryInline(x:Float, y:Float, r:Float, calcDistSq : T -> Float ) : T {
-		var rr = r * r;
-		var head : T = null, last : T = null;
-		iterElements(x, y, r, function(e) {
-			var d = calcDistSq(e);
-			if( d <= rr && d >= 0. ) {
-				if( head == null ) {
-					head = last = e;
-				} else {
-					last.partQueryNext = e;
-					last = e;
-				}
-			}
-		});
-		if( last != null )
-			last.partQueryNext = null;
-		return head;
-	}
-
-	public inline function queryNearest( x : Float, y : Float, ray : Float, calcDistSq : T -> Float ) : T {
-		var best : T = null, bestD = ray * ray;
-		iterElements(x,y,ray,function(e) {
-			var d = calcDistSq(e);
-			if( d <= bestD && d >= 0. ) {
-				best = e;
-				bestD = d;
-			}
-		});
-		return best;
-	}
-
-	inline function iterElements(x:Float, y:Float, r:Float, iterFun) {
-		var xMin = Math.floor(x - r) >> pbits;
-		var yMin = Math.floor(y - r) >> pbits;
-		var xMax = (Math.ceil(x + r) + (psize-1)) >> pbits;
-		var yMax = (Math.ceil(y + r) + (psize-1)) >> pbits;
-		xMin -= 1;
-		yMin -= 1;
-		xMax += 2;
-		yMax += 2;
-		if( xMin < 0 ) xMin = 0;
-		if( yMin < 0 ) yMin = 0;
-		if( xMax > pwidth ) xMax = pwidth;
-		if( yMax > pheight ) yMax = pheight;
-		for( cy in yMin...yMax ) {
-			var cid = cy * pwidth + xMin;
-			for( cx in xMin...xMax ) {
-				var c = chunks[cid++];
-				var e = c.elements;
-				if( e == null ) continue;
-				while( e != null ) {
-					iterFun(e);
-					e = e.partNext;
-				}
-			}
-		}
-	}
-
-
-	/**
-		Adds an entity to our partition system.
-		If the entity is already present, it will sync() it, but in a less efficient manner.
-		If an entity is outside of world bounds, an error is throw in debug, otherwise the result is unspecified.
-	**/
-	public function add( e : T ) {
-		var cx = Std.int(e.x) >> pbits;
-		var cy = Std.int(e.y) >> pbits;
-		#if debug
-		if( cx < 0 || cy < 0 || cx >= pwidth || cy >= pheight ) throw "Position outside partition " + Std.int(e.x) + "," + Std.int(e.y);
-		#end
-		var cid = cx + cy * pwidth;
-		if( e.partChunk == cid && e.partChunk != 0 )
-			return;
-		remove(e);
-		var c = chunks[cid];
-		e.partChunk = cid;
-		e.partNext = c.elements;
-		c.elements = e;
-	}
-
-	inline function removeFromChunk( c : PartitionChunk<T>, e : T ) {
-		var prev : T = null;
-		var cur = c.elements;
-		while( cur != null ) {
-			if( cur == e ) {
-				if( prev == null )
-					c.elements = e.partNext;
-				else
-					prev.partNext = e.partNext;
-				break;
-			}
-			prev = cur;
-			cur = cur.partNext;
-		}
-	}
-
-
-	/**
-		Removes an entity to our partition system.
-		Multiple removes of the same entity does not have any side effect.
-	**/
-	public function remove( e : T ) {
-		if( e.partChunk < 0 ) return;
-		var c = chunks[e.partChunk];
-		removeFromChunk(c, e);
-		e.partChunk = -1;
-	}
-
-	/**
-		After your entity position have changed, you can either call syncAll() or sync() for the entities that have moved.
-		Please note that you don't have to call sync() for each change, but at least when the entity has moved a distance of the chunk size.
-	**/
-	public inline function sync( e : T ) {
-		var cx = Std.int(e.x) >> pbits;
-		var cy = Std.int(e.y) >> pbits;
-		var cid = cx + cy * pwidth;
-		if( e.partChunk != cid ) moveTo(e, cx, cy);
-	}
-
-	/**
-		Force a complete refresh of entities partition. If only a few entities are moving, using sync() will be more efficient.
-		If most of the entities are moving each frame, it is more efficient to call syncAll()
-	**/
-	public function syncAll() {
-		for( c in chunks ) {
-			var e = c.elements;
-			var prev = null;
-			var ox = c.x;
-			var oy = c.y;
-			while( e != null ) {
-				var cx = Std.int(e.x) >> pbits;
-				var cy = Std.int(e.y) >> pbits;
-				if( cx == ox && cy == oy ) {
-					prev = e;
-					e = e.partNext;
-					continue;
-				}
-				#if debug
-				if( cx < 0 || cy < 0 || cx >= pwidth || cy >= pheight ) throw "Position outside partition " + Std.int(e.x) + "," + Std.int(e.y);
-				#end
-
-				// faster remove
-				var next = e.partNext;
-				if( prev == null )
-					c.elements = next;
-				else
-					prev.partNext = next;
-
-				var cid = cx + cy * pwidth;
-				var cnew = chunks[cid];
-				e.partChunk = cid;
-				e.partNext = cnew.elements;
-				cnew.elements = e;
-				e = next;
-			}
-		}
-	}
-
-	function moveTo(e:T, cx, cy) {
-		#if debug
-		if( cx < 0 || cy < 0 || cx >= pwidth || cy >= pheight ) throw "Position outside partition " + Std.int(e.x) + "," + Std.int(e.y);
-		var dx = (e.partChunk % pwidth) - cx;
-		var dy = Std.int(e.partChunk / pwidth) - cy;
-		if( dx < -1 || dx > 1 || dy < -1 || dy > 1 ) trace(e+" moved move than one chunk since last sync : might skip collide checks");
-		#end
-		removeFromChunk(chunks[e.partChunk], e);
-		var cid = cx + cy * pwidth;
-		var c = chunks[cid];
-		e.partChunk = cid;
-		e.partNext = c.elements;
-		c.elements = e;
-	}
-
-}

+ 0 - 292
hxd/impl/PathFind.hx

@@ -1,292 +0,0 @@
-package hxd.impl;
-
-class PathFind {
-
-	// 0 - unreachable
-	// positive - dist+1 to reach
-	// negative - -(dist+1) : collides but reachable
-
-	var t : haxe.ds.Vector<Int>;
-	var bits : Int;
-	var init : Bool;
-	var width : Int;
-	var height : Int;
-
-	public function new(width, height) {
-		this.width = width;
-		this.height = height;
-		t = new haxe.ds.Vector<Int>(width * height);
-		bits = 0;
-		while( width >= 1 << bits )
-			bits++;
-		#if js
-		clear();
-		#end
-	}
-
-	public function clear() {
-		for( i in 0...width * height )
-			t[i] = 0;
-	}
-
-	public inline function build( x : Int, y : Int, collide : Int -> Int -> Bool ) {
-		var tmp = new FastIO.FastIntIO();
-		tmp.rec2dk(x, y, bits, function(x, y, k) {
-			if( x < 0 || y < 0 || x >= width || y >= height ) return false;
-			k++;
-			var a = x + y * width;
-			var p = t[a];
-			if( p != 0 ) return false;
-			if( collide(x, y) ) {
-				t[a] = -k;
-				return k == 1;
-			}
-			t[a] = k;
-			return true;
-		});
-	}
-
-	public inline function buildMap( isStart : Int -> Int -> Bool, collide : Int -> Int -> Bool ) {
-		var tmp = new FastIO.FastIntIO();
-		var k = 0;
-		for( y in 0...height )
-			for( x in 0...width )
-				if( isStart(x, y) )
-					tmp.add2d(x, y, bits);
-		var k = 1;
-		while( true ) {
-			tmp.flushMax(4);
-			if( !tmp.hasNext() )
-				break;
-			for( id in tmp ) {
-				var x = id & ((1 << bits) - 1);
-				var y = id >>> bits;
-
-				var a = x + y * width;
-				var p = t[a];
-				if( p != 0 ) continue;
-
-				if( collide(x, y) ) {
-					t[a] = -k;
-					if( k == 1 ) continue;
-				}
-				t[a] = k;
-				if( x < width-1 ) tmp.add2d(x + 1, y, bits);
-				if( x > 0 ) tmp.add2d(x - 1, y, bits);
-				if( y < height - 1 ) tmp.add2d(x, y + 1, bits);
-				if( y > 0 ) tmp.add2d(x, y - 1, bits);
-			}
-			k++;
-		}
-	}
-
-
-	/**
-		The collide function will return the allowed movements for a given position as a set of bits 1|2|4|8 for Up|Down|Left|Right
-	**/
-	public inline function build4Dirs( x : Int, y : Int, collide : Int -> Int -> Int ) {
-		var tmp = new FastIO.FastIntIO();
-		var k = 0;
-		tmp.add2d(x, y, bits);
-		while( true ) {
-			tmp.flushMax(4);
-			if( !tmp.hasNext() )
-				break;
-			for( id in tmp ) {
-				var x = id & ((1 << bits) - 1);
-				var y = id >>> bits;
-				var col = collide(x, y);
-
-				var a = x + y * width;
-				var p = t[a];
-				if( p != 0 ) continue;
-
-				var k = k + 1;
-				var col = collide(x, y);
-
-				if( y > 0 ) {
-					if( col & 1 != 0 )
-						tmp.add2d(x, y - 1, bits);
-					else if( t[a - width] == 0 )
-						t[a - width] = -k;
-				}
-
-				if( y < height - 1 ) {
-					if( col & 2 != 0 )
-						tmp.add2d(x, y + 1, bits);
-					else if( t[a + width] == 0 )
-						t[a + width] = -k;
-				}
-
-				if( x > 0 ) {
-					if( col & 4 != 0 )
-						tmp.add2d(x - 1, y, bits);
-					else if( t[a - 1] == 0 )
-						t[a - 1] = -k;
-				}
-
-				if( x < width - 1 ) {
-					if( col & 8 != 0 )
-						tmp.add2d(x + 1, y, bits);
-					else if( t[a + 1] == 0 )
-						t[a + 1] = -k;
-				}
-
-				t[a] = k;
-			}
-			k++;
-		}
-	}
-
-	public function nearestReachable( x : Int, y : Int, fromX : Int = -1, fromY : Int = -1 ) {
-		if( t[x + y * width] > 0 )
-			return { x : x, y : y };
-		var sz = 1;
-		var bestX = -1, bestY = -1, bestD = 0x7FFFFFFF, bestSZ = 0;
-		while( true ) {
-			var xMin = x - sz;
-			var xMax = x + sz;
-			var yMin = y - sz;
-			var yMax = y + sz;
-			var out = true;
-			var xs = xMin < 0 ? 0 : xMin;
-			var xe = xMax >= width ? width - 1 : xMax;
-			var ys = yMin < 0 ? 0 : yMin;
-			var ye = yMax >= height ? height - 1 : yMax;
-
-			inline function check(cx, cy) {
-				if( t[cx + cy * height] > 0 ) {
-					var dx = cx - x;
-					var dy = cy - y;
-					var d = dx * dx + dy * dy;
-					if( d == bestD && fromX >= 0 ) {
-						var bx = bestX - fromX;
-						var by = bestY - fromY;
-						var bd = bx * bx + by * by;
-						var nx = cx - fromX;
-						var ny = cy - fromY;
-						var nd = nx * nx + ny * ny;
-						if( nd < bd ) bestD++;
-					}
-					if( d < bestD ) {
-						bestX = cx;
-						bestY = cy;
-						bestD = d;
-						bestSZ = sz;
-					}
-				}
-			}
-
-			if( ys == yMin ) {
-				for( cx in xs...xe+1 )
-					check(cx, yMin);
-				out = false;
-			}
-
-			if( ye == yMax ) {
-				for( cx in xs...xe+1 )
-					check(cx, yMax);
-				out = false;
-			}
-
-			if( xs == xMin ) {
-				for( cy in ys...ye+1 )
-					check(xMin, cy);
-				out = false;
-			}
-
-			if( xe == xMax ) {
-				for( cy in ys...ye+1 )
-					check(xMax, cy);
-				out = false;
-			}
-
-			sz++;
-
-			if( out || (bestSZ > 0 && sz * sz > bestD) ) break;
-		}
-		if( bestX < 0 )
-			return null;
-		return { x : bestX, y : bestY };
-	}
-
-	public function getPath( x : Int, y : Int, ?prefDir : hxd.Direction ) {
-		var a = x + y * width;
-		var k = Math.iabs(t[a]);
-		if( k == 0 ) return null;
-		var path = [];
-		var dir : hxd.Direction = prefDir == null ? Direction.Down : prefDir;
-		while( k > 1 ) {
-			k--;
-
-			// check with previous dir
-			var tx = x + dir.x, ty = y + dir.y, ta = a + dir.x + dir.y * width;
-			if( tx > 0 && tx < width && ty > 0 && ty < height && t[ta] == k ) {
-				x += dir.x;
-				y += dir.y;
-				a = ta;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-
-			if( x > 0 && t[a - 1] == k ) {
-				x--;
-				a--;
-				dir = Left;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-			if( y > 0 && t[a - width] == k ) {
-				y--;
-				a -= width;
-				dir = Up;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-			if( x < width-1 && t[a + 1] == k ) {
-				x++;
-				a++;
-				dir = Right;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-			if( y < height - 1 && t[a + width] == k ) {
-				y++;
-				a += width;
-				dir = Down;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-			// target collides
-			if( k != 1 ) throw "assert "+k;
-			k = -1;
-			if( x > 0 && t[a - 1] == k ) {
-				x--;
-				a--;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-			if( y > 0 && t[a - width] == k ) {
-				y--;
-				a-=width;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-			if( x < width-1 && t[a + 1] == k ) {
-				x++;
-				a++;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-			if( y < height - 1 && t[a + width] == k ) {
-				y++;
-				a += width;
-				path.push( { x:x, y:y } );
-				continue;
-			}
-			throw "assert";
-		}
-		return path;
-	}
-
-}

+ 30 - 0
hxd/impl/UncheckedBytes.hx

@@ -0,0 +1,30 @@
+package hxd.impl;
+
+private typedef InnerData = #if hl hl.Bytes #elseif js js.html.Uint8Array #else haxe.io.BytesData #end
+
+abstract UncheckedBytes(InnerData) {
+
+	inline function new(v) {
+		this = v;
+	}
+
+	@:arrayAccess inline function get( i : Int ) : Int {
+		return this[i];
+	}
+
+	@:arrayAccess inline function set( i : Int, v : Int ) : Int {
+		this[i] = v;
+		return v;
+	}
+
+	@:from public static inline function fromBytes( b : haxe.io.Bytes ) : UncheckedBytes {
+		#if hl
+		return new UncheckedBytes(b);
+		#elseif js
+		return new UncheckedBytes(@:privateAccess b.b);
+		#else
+		return new UncheckedBytes(b.getData());
+		#end
+	}
+
+}

+ 7 - 8
hxd/res/FontBuilder.hx

@@ -107,18 +107,17 @@ class FontBuilder {
 
 		// let's remove alpha premult (all pixels should be white with alpha)
 		pixels.convert(BGRA);
-		var r = hxd.impl.Memory.select(pixels.bytes);
+		flash.Memory.select(pixels.bytes.getData());
 		for( i in 0...pixels.width * pixels.height ) {
 			var p = i << 2;
-			var b = r.b(p+3);
+			var b = flash.Memory.getByte(p+3);
 			if( b > 0 ) {
-				r.wb(p, 0xFF);
-				r.wb(p + 1, 0xFF);
-				r.wb(p + 2, 0xFF);
-				r.wb(p + 3, b);
+				flash.Memory.setByte(p, 0xFF);
+				flash.Memory.setByte(p + 1, 0xFF);
+				flash.Memory.setByte(p + 2, 0xFF);
+				flash.Memory.setByte(p + 3, b);
 			}
 		}
-		r.end();
 
 		if( innerTex == null ) {
 			innerTex = h3d.mat.Texture.fromPixels(pixels);
@@ -164,7 +163,7 @@ class FontBuilder {
 		var height = width;
 		while( width * height >> 1 > surf )
 			height >>= 1;
-			
+
 		if( innerTex != null ) {
 			width = innerTex.width;
 			height = innerTex.height;

+ 0 - 18
hxd/snd/OggData.hx

@@ -87,44 +87,26 @@ private class BytesOutput extends haxe.io.Output {
 
 	var bytes : haxe.io.Bytes;
 	var position : Int;
-	#if flash
-	var m : hxd.impl.Memory.MemoryReader;
-	#end
 
 	public function new() {
 	}
 
 	public function done() {
-		#if flash
-		m.end();
-		#end
 	}
 
 	public function init( bytes : haxe.io.Bytes, position : Int ) {
 		this.bytes = bytes;
 		this.position = position;
-		#if flash
-		m = hxd.impl.Memory.select(bytes);
-		#end
 	}
 
 	override function writeFloat(f) {
-		#if flash
-		m.wfloat(position, f);
-		#else
 		bytes.setFloat(position, f);
-		#end
 		position += 4;
 	}
 
 	override function writeInt16(i) {
-		#if flash
-		m.wb(position++, i >> 8);
-		m.wb(position++, i);
-		#else
 		bytes.setUInt16(position, i);
 		position += 2;
-		#end
 	}
 
 }