Kaynağa Gözat

cleanup deprecated flash platform

Nicolas Cannasse 1 yıl önce
ebeveyn
işleme
cee7517b28
54 değiştirilmiş dosya ile 86 ekleme ve 4885 silme
  1. 1 1
      all.hxml
  2. 0 8
      h2d/Bitmap.hx
  3. 1 2
      h2d/RenderContext.hx
  4. 0 10
      h2d/Tile.hx
  5. 0 941
      h3d/impl/Stage3dDriver.hx
  6. 1 10
      h3d/mat/BigTexture.hx
  7. 1 60
      h3d/mat/Texture.hx
  8. 0 4
      h3d/pass/HardwarePick.hx
  9. 0 3
      h3d/pass/ShaderManager.hx
  10. 0 2
      h3d/scene/fwd/Renderer.hx
  11. 22 175
      hxd/BitmapData.hx
  12. 4 13
      hxd/ByteConversions.hx
  13. 1 20
      hxd/BytesBuffer.hx
  14. 0 9
      hxd/Cursor.hx
  15. 9 192
      hxd/File.hx
  16. 4 10
      hxd/FloatBuffer.hx
  17. 2 10
      hxd/IndexBuffer.hx
  18. 0 12
      hxd/Key.hx
  19. 3 113
      hxd/Pad.hx
  20. 0 55
      hxd/Perlin.hx
  21. 1 38
      hxd/Save.hx
  22. 0 183
      hxd/System.flash.hx
  23. 0 333
      hxd/Window.flash.hx
  24. 0 139
      hxd/Worker.hx
  25. 1 1
      hxd/fmt/hmd/Writer.hx
  26. 2 31
      hxd/fmt/pak/FileSystem.hx
  27. 1 12
      hxd/fs/BytesFileSystem.hx
  28. 1 3
      hxd/fs/Convert.hx
  29. 3 62
      hxd/fs/EmbedFileSystem.hx
  30. 2 6
      hxd/fs/LoadedBitmap.hx
  31. 0 4
      hxd/fs/LocalFileSystem.hx
  32. 0 95
      hxd/impl/Air3File.hx
  33. 1 13
      hxd/net/BinaryLoader.hx
  34. 5 142
      hxd/net/Socket.hx
  35. 0 42
      hxd/poly2tri/VisiblePolygon.hx
  36. 2 4
      hxd/res/Config.hx
  37. 2 21
      hxd/res/Embed.hx
  38. 1 17
      hxd/res/FileTree.hx
  39. 1 6
      hxd/res/Font.hx
  40. 1 106
      hxd/res/FontBuilder.hx
  41. 0 18
      hxd/res/NanoJpeg.hx
  42. 0 6
      hxd/res/Sound.hx
  43. 3 34
      hxd/snd/Mp3Data.hx
  44. 3 25
      hxd/snd/NativeChannel.hx
  45. 1 4
      hxd/snd/openal/Emulator.hx
  46. 0 961
      hxsl/AgalOptim.hx
  47. 0 871
      hxsl/AgalOut.hx
  48. 1 3
      hxsl/Cache.hx
  49. 1 31
      hxsl/Flatten.hx
  50. 1 5
      hxsl/Globals.hx
  51. 1 4
      hxsl/SharedShader.hx
  52. 1 1
      samples/Cursor.hx
  53. 1 9
      samples/Network.hx
  54. 0 5
      samples/Pbr.hx

+ 1 - 1
all.hxml

@@ -4,7 +4,7 @@
 --macro include('h3d')
 --macro include('h2d',true,['h2d.domkit'])
 --macro include('hxsl',true,['hxsl.Macros','hxsl.CacheFile','hxsl.CacheFileBuilder','hxsl.Checker'])
---macro include('hxd',true,['hxd.res.FileTree','hxd.Res','hxd.impl.BitsBuilder','hxd.impl.Air3File','hxd.fmt.pak.Build','hxd.net.SteamHost','hxd.snd.efx','hxd.snd.openal','hxd.res.Config'])
+--macro include('hxd',true,['hxd.res.FileTree','hxd.Res','hxd.impl.BitsBuilder','hxd.fmt.pak.Build','hxd.snd.openal','hxd.res.Config'])
 --no-output
 -D apicheck
 --each

+ 0 - 8
h2d/Bitmap.hx

@@ -40,14 +40,6 @@ class Bitmap extends Drawable {
 		this.tile = tile;
 	}
 
-	#if flash
-	override function set_tileWrap(b) {
-		if( b && tile != null && tile.getTexture().flags.has(IsNPOT) )
-			throw "Cannot set tileWrap on a non power-of-two texture";
-		return tileWrap = b;
-	}
-	#end
-
 	override function getBoundsRec( relativeTo : Object, out : h2d.col.Bounds, forSize : Bool ) {
 		super.getBoundsRec(relativeTo, out, forSize);
 		if( tile != null ) {

+ 1 - 2
h2d/RenderContext.hx

@@ -179,8 +179,7 @@ class RenderContext extends h3d.impl.RenderContext {
 		inFilter = null;
 		manager.globals.set("time", time);
 		manager.globals.set("global.time", time);
-		// todo : we might prefer to auto-detect this by running a test and capturing its output
-		baseShader.pixelAlign = #if flash true #else false #end;
+		baseShader.pixelAlign = false;
 		baseShader.halfPixelInverse.set(0.5 / engine.width, 0.5 / engine.height);
 		baseShader.viewportA.set(scene.viewportA, 0, scene.viewportX);
 		baseShader.viewportB.set(0, scene.viewportD * -baseFlipY, scene.viewportY * -baseFlipY);

+ 0 - 10
h2d/Tile.hx

@@ -333,16 +333,6 @@ class Tile {
 	function upload( bmp:hxd.BitmapData ) : Void {
 		var w = innerTex.width;
 		var h = innerTex.height;
-		#if flash
-		if( w != bmp.width || h != bmp.height ) {
-			var bmp2 = new flash.display.BitmapData(w, h, true, 0);
-			var p0 = new flash.geom.Point(0, 0);
-			var bmp = bmp.toNative();
-			bmp2.copyPixels(bmp, bmp.rect, p0, bmp, p0, true);
-			innerTex.uploadBitmap(hxd.BitmapData.fromNative(bmp2));
-			bmp2.dispose();
-		} else
-		#end
 		innerTex.uploadBitmap(bmp);
 	}
 

+ 0 - 941
h3d/impl/Stage3dDriver.hx

@@ -1,941 +0,0 @@
-package h3d.impl;
-import h3d.impl.Driver;
-import h3d.mat.Pass;
-import h3d.mat.Stencil;
-import h3d.mat.Data;
-
-#if flash
-
-@:allow(h3d.impl.Stage3dDriver)
-class VertexWrapper {
-	var vbuf : flash.display3D.VertexBuffer3D;
-	var written : Bool;
-	var b : ManagedBuffer;
-
-	function new(vbuf, b) {
-		this.vbuf = vbuf;
-		this.b = b;
-	}
-
-	function finalize( driver : Stage3dDriver ) {
-		if( written ) return;
-		written = true;
-		// fill all the free positions that were unwritten with zeroes (necessary for flash)
-		var f = @:privateAccess b.freeList;
-		while( f != null ) {
-			if( f.count > 0 ) {
-				var mem : UInt = f.count * b.stride * 4;
-				if( driver.empty.length < mem ) driver.empty.length = mem;
-				driver.uploadVertexBytes(@:privateAccess b.vbuf, f.pos, f.count, haxe.io.Bytes.ofData(driver.empty), 0);
-			}
-			f = f.next;
-		}
-	}
-
-}
-
-private class CompiledShader {
-	public var p : flash.display3D.Program3D;
-	public var s : hxsl.RuntimeShader;
-	public var stride : Int;
-	public var bufferFormat : Int;
-	public var inputs : InputNames;
-	public var usedTextures : Array<Bool>;
-	public function new(s) {
-		this.s = s;
-		stride = 0;
-		bufferFormat = 0;
-		usedTextures = [];
-	}
-}
-
-class Stage3dDriver extends Driver {
-
-	// standard profile was introduced with Flash14 but it causes problems with filters, only enable it for flash15+
-	public static var PROFILE = #if flash15 cast "standard" #else flash.display3D.Context3DProfile.BASELINE #end;
-	public static var SHADER_CACHE_PATH = null;
-
-	var s3d : flash.display.Stage3D;
-	var ctx : flash.display3D.Context3D;
-	var onCreateCallback : Bool -> Void;
-
-	var curMatBits : Int;
-	var curStOpBits : Int;
-	var curStMaskBits : Int;
-	var defStencil : Stencil;
-	var curShader : CompiledShader;
-	var curBuffer : Buffer;
-	var curManagedBuffer : ManagedBuffer;
-	var curMultiBuffer : Array<Int>;
-	var curAttributes : Int;
-	var curTextures : Array<h3d.mat.Texture>;
-	var curSamplerBits : Array<Int>;
-	var renderTargets : Int;
-	var antiAlias : Int;
-	var width : Int;
-	var height : Int;
-	var enableDraw : Bool;
-	var frame : Int;
-	var programs : Map<Int, CompiledShader>;
-	var isStandardMode : Bool;
-	var flashVersion : Float;
-	var tdisposed : Texture;
-	var defaultDepth : h3d.mat.Texture;
-	var curColorMask = -1;
-
-	@:allow(h3d.impl.VertexWrapper)
-	var empty : flash.utils.ByteArray;
-
-	public function new(antiAlias=0) {
-		var v = flash.system.Capabilities.version.split(" ")[1].split(",");
-		flashVersion = Std.parseFloat(v[0] + "." + v[1]);
-		empty = new flash.utils.ByteArray();
-		s3d = flash.Lib.current.stage.stage3Ds[0];
-		programs = new Map();
-		this.antiAlias = antiAlias;
-		curTextures = [];
-		curSamplerBits = [];
-		curMultiBuffer = [];
-		defStencil = new Stencil();
-		defaultDepth = new h3d.mat.Texture( -1, -1, Depth24Stencil8);
-	}
-
-	override function logImpl( str : String ) {
-		flash.Lib.trace(str);
-	}
-
-	override function getDriverName(details:Bool) {
-		return ctx == null ? "None" : (details ? ctx.driverInfo : ctx.driverInfo.split(" ")[0]);
-	}
-
-	override function begin( frame : Int ) {
-		reset();
-		this.frame = frame;
-	}
-
-	function reset() {
-		enableDraw = true;
-		curMatBits = -1;
-		curStOpBits = -1;
-		curStMaskBits = -1;
-		curShader = null;
-		curBuffer = null;
-		curMultiBuffer[0] = -1;
-		for( i in 0...curAttributes )
-			ctx.setVertexBufferAt(i, null);
-		curAttributes = 0;
-		for( i in 0...curTextures.length ) {
-			ctx.setTextureAt(i, null);
-			curTextures[i] = null;
-		}
-		for( i in 0...curSamplerBits.length )
-			curSamplerBits[i] = -1;
-	}
-
-	override function init( onCreate, forceSoftware = false ) {
-		isStandardMode = Std.string(PROFILE) == "standard";
-		if( isStandardMode && flashVersion < 14 ) {
-			isStandardMode = false;
-			PROFILE = flash.display3D.Context3DProfile.BASELINE;
-		}
-		this.onCreateCallback = onCreate;
-		s3d.addEventListener(flash.events.Event.CONTEXT3D_CREATE, this.onCreate);
-		s3d.requestContext3D( cast (forceSoftware ? "software" : "auto"), PROFILE );
-	}
-
-	function onCreate(_) {
-		var old = ctx;
-		for( p in programs )
-			p.p.dispose();
-		programs = new Map();
-		if( old != null ) {
-			//if( old.driverInfo != "Disposed" ) throw "Duplicate onCreate()";
-			old.dispose();
-			ctx = s3d.context3D;
-			onCreateCallback(true);
-		} else {
-			ctx = s3d.context3D;
-			if( tdisposed == null ) {
-				tdisposed = ctx.createTexture(1, 1, flash.display3D.Context3DTextureFormat.BGRA, false);
-				tdisposed.dispose();
-			}
-			onCreateCallback(false);
-		}
-	}
-
-	override function hasFeature( f : Feature ) : Bool {
-		return switch( f ) {
-		case HardwareAccelerated: ctx != null && ctx.driverInfo.toLowerCase().indexOf("software") == -1;
-		case StandardDerivatives, FloatTextures: isStandardMode;
-		case MultipleRenderTargets: (PROFILE == cast "standard") || (PROFILE == cast "standardExtended");
-		default: false;
-		}
-	}
-
-	override function resize(width, height) {
-		try {
-			ctx.configureBackBuffer(width, height, antiAlias);
-			this.width = width;
-			this.height = height;
-			@:privateAccess {
-				defaultDepth.width = width;
-				defaultDepth.height = height;
-			}
-		} catch( e : flash.errors.Error ) {
-			// large screen but bad video card ?
-			if( width > 2048 || height > 2048 ) {
-				if( width > 2048 ) width = 2048;
-				if( height > 2048 ) height = 2048;
-				resize(width, height);
-			} else
-				throw new flash.errors.Error("" + e+" (" + width + "x" + height + ")");
-		}
-	}
-
-	override function clear( ?color : h3d.Vector, ?depth : Float, ?stencil : Int ) {
-		var mask = 0;
-		if( color != null ) mask |= flash.display3D.Context3DClearMask.COLOR;
-		if( depth != null ) mask |= flash.display3D.Context3DClearMask.DEPTH;
-		if( stencil != null ) mask |= flash.display3D.Context3DClearMask.STENCIL;
-		ctx.clear( color == null ? 0 : color.r, color == null ? 0 : color.g, color == null ? 0 : color.b, color == null ? 1 : color.a, depth == null ? 1 : depth, stencil == null ? 0 : stencil, mask);
-	}
-
-	override function captureRenderBuffer( pixels : hxd.Pixels ) {
-		if( renderTargets != 0 )
-			throw "Can't capture render target in flash";
-		var bmp = new flash.display.BitmapData(pixels.width, pixels.height, true, 0);
-		ctx.drawToBitmapData(bmp);
-
-		var pix = bmp.getPixels(bmp.rect);
-		bmp.dispose();
-		var b = pixels.bytes.getData();
-		b.position = 0;
-		b.writeBytes(pix, 0, pixels.width * pixels.height * 4);
-		@:privateAccess pixels.innerFormat = ARGB;
-		pixels.flags.set(AlphaPremultiplied);
-	}
-
-	override function dispose() {
-		s3d.removeEventListener(flash.events.Event.CONTEXT3D_CREATE, onCreate);
-		if( ctx != null ) ctx.dispose();
-		ctx = null;
-	}
-
-	override function isDisposed() {
-		return ctx == null || ctx.driverInfo == "Disposed";
-	}
-
-	override function present() {
-		ctx.present();
-	}
-
-	override function disposeTexture( t : h3d.mat.Texture ) {
-		if( t.t != null ) {
-			t.t.dispose();
-			t.t = null;
-		}
-	}
-
-	override function allocVertexes( buf : ManagedBuffer ) : VertexBuffer {
-		var v;
-		try {
-			v = ctx.createVertexBuffer(buf.size, buf.stride);
-		} catch( e : flash.errors.Error ) {
-			// too many resources / out of memory
-			if( e.errorID == 3691 )
-				return null;
-			throw e;
-		}
-		return new VertexWrapper(v, buf);
-	}
-
-	override function allocIndexes( count : Int, is32 : Bool ) : IndexBuffer {
-		if( is32 )
-			throw "32 bit indexes are not supported";
-		try {
-			return ctx.createIndexBuffer(count);
-		} catch( e : flash.errors.Error ) {
-			// too many resources / out of memory
-			if( e.errorID == 3691 )
-				return null;
-			throw e;
-		}
-	}
-
-	function getMipLevels( t : h3d.mat.Texture ) {
-		if( !t.flags.has(MipMapped) )
-			return 0;
-		var levels = 0;
-		while( t.width > (1 << levels) || t.height > (1 << levels) )
-			levels++;
-		return levels;
-	}
-
-	override function isSupportedFormat( fmt : h3d.mat.Data.TextureFormat ) {
-		return switch( fmt ) {
-		case BGRA: true;
-		case RGBA16F: true;
-		default: false;
-		}
-	}
-
-	override function allocTexture( t : h3d.mat.Texture ) : Texture {
-		var fmt = switch( t.format ) {
-		case BGRA: flash.display3D.Context3DTextureFormat.BGRA;
-		case RGBA16F: flash.display3D.Context3DTextureFormat.RGBA_HALF_FLOAT;
-		default: throw "Unsupported texture format " + t.format;
-		}
-		t.lastFrame = frame;
-		t.flags.unset(WasCleared);
-		try {
-			if( t.flags.has(IsNPOT) ) {
-				if( t.flags.has(Cube) || t.flags.has(MipMapped) )
-					throw "Not power of two texture is not supported with these flags";
-				#if !flash11_8
-				throw "Support for rectangle texture requires Flash 11.8+ compilation";
-				#else
-				return ctx.createRectangleTexture(t.width, t.height, fmt, t.flags.has(Target));
-				#end
-			}
-			if( t.flags.has(Cube) )
-				return ctx.createCubeTexture(t.width, fmt, t.flags.has(Target), getMipLevels(t));
-			return ctx.createTexture(t.width, t.height, fmt, t.flags.has(Target), getMipLevels(t));
-		} catch( e : flash.errors.Error ) {
-			if( e.errorID == 3691 )
-				return null;
-			if( e.errorID == 3694 )
-				return tdisposed; // our context was disposed, let's return a disposed texture
-			throw e;
-		}
-	}
-
-	override function uploadTextureBitmap( t : h3d.mat.Texture, bmp : hxd.BitmapData, mipLevel : Int, side : Int ) {
-		if( t.t == tdisposed ) return;
-		if( t.flags.has(Cube) ) {
-			var t = flash.Lib.as(t.t, flash.display3D.textures.CubeTexture);
-			t.uploadFromBitmapData(bmp.toNative(), side, mipLevel);
-		} else if( t.flags.has(IsNPOT) ) {
-			#if flash11_8
-			var t = flash.Lib.as(t.t, flash.display3D.textures.RectangleTexture);
-			t.uploadFromBitmapData(bmp.toNative());
-			#end
-		} else {
-			var t = flash.Lib.as(t.t, flash.display3D.textures.Texture);
-			t.uploadFromBitmapData(bmp.toNative(), mipLevel);
-		}
-	}
-
-	override function uploadTexturePixels( t : h3d.mat.Texture, pixels : hxd.Pixels, mipLevel : Int, side : Int ) {
-		if( t.t == tdisposed ) return;
-		pixels.convert(BGRA);
-		var data = pixels.bytes.getData();
-		if( t.flags.has(Cube) ) {
-			var t = flash.Lib.as(t.t, flash.display3D.textures.CubeTexture);
-			t.uploadFromByteArray(data, pixels.offset, side, mipLevel);
-		} else if( t.flags.has(IsNPOT) ) {
-			#if flash11_8
-			var t = flash.Lib.as(t.t, flash.display3D.textures.RectangleTexture);
-			t.uploadFromByteArray(data, pixels.offset);
-			#end
-		} else {
-			var t = flash.Lib.as(t.t,  flash.display3D.textures.Texture);
-			t.uploadFromByteArray(data, pixels.offset, mipLevel);
-		}
-	}
-
-	override function disposeVertexes( v : VertexBuffer ) {
-		v.vbuf.dispose();
-		v.b = null;
-	}
-
-	override function disposeIndexes( i : IndexBuffer ) {
-		i.dispose();
-	}
-
-	override function setDebug( d : Bool ) {
-		if( ctx != null ) ctx.enableErrorChecking = d && hasFeature(HardwareAccelerated);
-	}
-
-	override function uploadVertexBuffer( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : hxd.FloatBuffer, bufPos : Int ) {
-		var data = buf.getNative();
-		v.vbuf.uploadFromVector( bufPos == 0 ? data : data.slice(bufPos, vertexCount * v.b.stride + bufPos), startVertex, vertexCount );
-	}
-
-	override function uploadVertexBytes( v : VertexBuffer, startVertex : Int, vertexCount : Int, bytes : haxe.io.Bytes, bufPos : Int ) {
-		v.vbuf.uploadFromByteArray( bytes.getData(), bufPos, startVertex, vertexCount );
-	}
-
-	override function uploadIndexBuffer( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : hxd.IndexBuffer, bufPos : Int ) {
-		var data = buf.getNative();
-		i.uploadFromVector( bufPos == 0 ? data : data.slice(bufPos, indiceCount + bufPos), startIndice, indiceCount );
-	}
-
-	override function uploadIndexBytes( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
-		i.uploadFromByteArray(buf.getData(), bufPos, startIndice, indiceCount );
-	}
-
-	override function selectMaterial( pass : Pass ) {
-		selectMaterialBits(@:privateAccess pass.bits);
-
-		if( pass.colorMask != curColorMask ) {
-			var m = pass.colorMask;
-			ctx.setColorMask(m & 1 != 0, m & 2 != 0, m & 4 != 0, m & 8 != 0);
-			curColorMask = m;
-		}
-
-		var s = pass.stencil != null ? pass.stencil : defStencil;
-		@:privateAccess selectStencilBits(s.opBits, s.maskBits);
-	}
-
-	function selectMaterialBits( bits : Int ) {
-		var diff = bits ^ curMatBits;
-		if( curMatBits < 0 ) diff = -1;
-		if( diff == 0 )
-			return;
-		if( diff & Pass.culling_mask != 0 )
-			ctx.setCulling(FACE[Pass.getCulling(bits)]);
-		if( diff & (Pass.blendSrc_mask | Pass.blendDst_mask | Pass.blendAlphaSrc_mask | Pass.blendAlphaDst_mask) != 0 ) {
-			var csrc = Pass.getBlendSrc(bits);
-			var cdst = Pass.getBlendDst(bits);
-			var asrc = Pass.getBlendAlphaSrc(bits);
-			var adst = Pass.getBlendAlphaDst(bits);
-			if( csrc == asrc && cdst == adst ) {
-				if( (csrc | cdst) > BLEND.length ) throw "Blend operation not supported on flash";
-				ctx.setBlendFactors(BLEND[csrc], BLEND[cdst]);
-			} else {
-				throw "Alpha blend functions not supported on flash";
-			}
-		}
-		if( diff & (Pass.blendOp_mask | Pass.blendAlphaOp_mask) != 0 ) {
-			var cop = Pass.getBlendOp(bits);
-			var aop = Pass.getBlendAlphaOp(bits);
-			if( cop != 0 || aop != 0 )
-				throw "Custom blend operation not supported on flash";
-		}
-		if( diff & (Pass.depthWrite_mask | Pass.depthTest_mask) != 0 ) {
-			var write = Pass.getDepthWrite(bits) != 0;
-			var cmp = Pass.getDepthTest(bits);
-			ctx.setDepthTest(write, COMPARE[cmp]);
-		}
-		curMatBits = bits;
-	}
-
-	function selectStencilBits( opBits : Int, maskBits : Int ) {
-		var diffOp  = opBits ^ curStOpBits;
-		var diffMask = maskBits ^ curStMaskBits;
-
-		if( (diffOp | diffMask) == 0 ) return;
-
-		if( diffOp & (Stencil.frontTest_mask | Stencil.frontSTfail_mask | Stencil.frontDPfail_mask | Stencil.frontPass_mask) != 0 ) {
-			ctx.setStencilActions(
-				FACE[Type.enumIndex(Front)],
-				COMPARE[Stencil.getFrontTest(opBits)],
-				STENCIL_OP[Stencil.getFrontPass(opBits)],
-				STENCIL_OP[Stencil.getFrontDPfail(opBits)],
-				STENCIL_OP[Stencil.getFrontSTfail(opBits)]);
-		}
-
-		if( diffOp & (Stencil.backTest_mask | Stencil.backSTfail_mask | Stencil.backDPfail_mask | Stencil.backPass_mask) != 0 ) {
-			ctx.setStencilActions(
-				FACE[Type.enumIndex(Back)],
-				COMPARE[Stencil.getBackTest(opBits)],
-				STENCIL_OP[Stencil.getBackPass(opBits)],
-				STENCIL_OP[Stencil.getBackDPfail(opBits)],
-				STENCIL_OP[Stencil.getBackSTfail(opBits)]);
-		}
-
-		if( diffMask != 0 ) {
-			ctx.setStencilReferenceValue(
-				Stencil.getReference(maskBits),
-				Stencil.getReadMask(maskBits),
-				Stencil.getWriteMask(maskBits));
-		}
-
-		curStOpBits = opBits;
-		curStMaskBits = maskBits;
-	}
-
-	function compileShader( s : hxsl.RuntimeShader.RuntimeShaderData, usedTextures : Array<Bool> ) {
-		//trace(hxsl.Printer.shaderToString(s.data));
-		var agalVersion = isStandardMode ? 2 : 1;
-		var agal = hxsl.AgalOut.toAgal(s, agalVersion);
-		//var old = format.agal.Tools.toString(agal);
-		var optim = new hxsl.AgalOptim();
-		agal = optim.optimize(agal);
-		#if debug
-		var maxVarying = format.agal.Tools.getProps(RVar, !s.vertex, agalVersion).count;
-		var maxTextures = format.agal.Tools.getProps(RTexture, !s.vertex, agalVersion).count;
-		for( op in agal.code )
-			optim.iter(op, function(r, _) {
-				switch( r.t ) {
-				case RVar:
-					if( r.index >= maxVarying ) {
-						var vars = [];
-						for( v in s.data.vars )
-							switch( v.kind ) {
-							case Var: vars.push(v.name);
-							default:
-							}
-						throw "Too many varying for this shader ("+vars.join(",")+")";
-					}
-				case RTexture:
-					if( r.index >= maxTextures ) {
-						var vars = [];
-						for( v in s.data.vars )
-							switch( v.type ) {
-							case TSampler2D, TSamplerCube: vars.push(v.name);
-							default:
-							}
-						throw "Too many textures for this shader ("+vars.join(",")+")";
-					}
-				default:
-				}
-			});
-		#end
-		//var opt = format.agal.Tools.toString(agal);
-		for( op in agal.code )
-			switch( op ) {
-			case OTex(_, _, t): usedTextures[t.index] = true;
-			default:
-			}
-		var size = s.globalsSize+s.paramsSize;
-		var max = format.agal.Tools.getProps(RConst, !s.vertex, agalVersion).count;
-		if( size > max )
-			throw (s.vertex?"Vertex ":"Fragment ") + " shader uses " + size+" constant registers while " + max + " is allowed";
-		var o = new haxe.io.BytesOutput();
-		new format.agal.Writer(o).write(agal);
-		return { agal : agal, bytes : o.getBytes() };
-	}
-
-	override function getNativeShaderCode( shader : hxsl.RuntimeShader ) {
-		var vertex = compileShader(shader.vertex, []).agal;
-		var fragment = compileShader(shader.fragment, []).agal;
-		function fmt( agal, data : hxsl.RuntimeShader.RuntimeShaderData ) {
-			var str = format.agal.Tools.toString(agal);
-			return ~/c([0-9]+)(.[xyz]+)?/g.map(str, function(r) {
-				var cid = Std.parseInt(r.matched(1)) << 2;
-				var swiz = r.matched(2);
-				if( swiz != null ) {
-					var d = swiz.charCodeAt(1) - 'x'.code;
-					cid += d;
-					swiz = "." + [for( i in 1...swiz.length ) String.fromCharCode(swiz.charCodeAt(i) - d)].join("");
-				}
-				var name = "C" + cid;
-				var g = data.globals;
-				while( g != null ) {
-					if( g.path == "__consts__" && cid >= g.pos && cid < g.pos + (switch(g.type) { case TArray(TFloat, SConst(n)): n; default: 0; } ) && swiz == ".x" ) {
-						swiz = null;
-						name = "" + data.consts[cid - g.pos];
-						break;
-					}
-					if( g.pos == cid ) {
-						name = g.path;
-						break;
-					}
-					g = g.next;
-				}
-				var p = data.params;
-				while( p != null ) {
-					if( p.pos + (data.globalsSize << 2) == cid ) {
-						name = p.name;
-						break;
-					}
-					p = p.next;
-				}
-				return swiz == null ? name : name+swiz;
-			});
-		}
-		return fmt(vertex, shader.vertex) + "\n" + fmt(fragment, shader.fragment);
-	}
-
-	function initShader( shader : hxsl.RuntimeShader ) {
-		var p = new CompiledShader(shader);
-		p.p = ctx.createProgram();
-
-		var cachedShader = null;
-		var file = SHADER_CACHE_PATH;
-		if( SHADER_CACHE_PATH != null ) {
-			file += shader.signature;
-			if( !isStandardMode ) file += "1";
-			file += ".shader";
-			try cachedShader = haxe.Unserializer.run(hxd.File.getBytes(file).toString()) catch( e : Dynamic ) { };
-		}
-		if( cachedShader == null ) {
-			cachedShader = {
-				vertex : compileShader(shader.vertex,[]).bytes,
-				fragment : compileShader(shader.fragment, p.usedTextures).bytes,
-				tex : p.usedTextures,
-			};
-			if( file != null )
-				hxd.File.saveBytes(file, haxe.io.Bytes.ofString(haxe.Serializer.run(cachedShader)));
-		} else {
-			p.usedTextures = cachedShader.tex;
-		}
-
-		var vdata = cachedShader.vertex.getData();
-		var fdata = cachedShader.fragment.getData();
-		vdata.endian = flash.utils.Endian.LITTLE_ENDIAN;
-		fdata.endian = flash.utils.Endian.LITTLE_ENDIAN;
-
-		var pos = 0;
-		var inputNames = [];
-		for( v in shader.vertex.data.vars )
-			if( v.kind == Input ) {
-				var size;
-				var fmt = switch( v.type ) {
-				case TBytes(4): size = 1; flash.display3D.Context3DVertexBufferFormat.BYTES_4;
-				case TFloat: size = 1; flash.display3D.Context3DVertexBufferFormat.FLOAT_1;
-				case TVec(2, VFloat): size = 2; flash.display3D.Context3DVertexBufferFormat.FLOAT_2;
-				case TVec(3, VFloat): size = 3; flash.display3D.Context3DVertexBufferFormat.FLOAT_3;
-				case TVec(4, VFloat): size = 4; flash.display3D.Context3DVertexBufferFormat.FLOAT_4;
-				default: throw "unsupported input " + v.type;
-				}
-				var idx = FORMAT.indexOf(fmt);
-				if( idx < 0 ) throw "assert " + fmt;
-				p.bufferFormat |= idx << (pos * 3);
-				inputNames.push(v.name);
-				p.stride += size;
-				pos++;
-			}
-		p.inputs = InputNames.get(inputNames);
-		p.p.upload(vdata, fdata);
-		return p;
-	}
-
-	override function selectShader( shader : hxsl.RuntimeShader ) {
-		var shaderChanged = false;
-		var p = programs.get(shader.id);
-		if( p == null ) {
-			p = initShader(shader);
-			programs.set(shader.id, p);
-			curShader = null;
-		}
-		if( p != curShader ) {
-			ctx.setProgram(p.p);
-			shaderChanged = true;
-			curShader = p;
-			// unbind extra textures
-			var tcount : Int = shader.fragment.texturesCount + shader.vertex.texturesCount;
-			while( curTextures.length > tcount ) {
-				curTextures.pop();
-				ctx.setTextureAt(curTextures.length, null);
-			}
-			// force remapping for sampler bits
-			for( i in 0...curSamplerBits.length )
-				curSamplerBits[i] = -1;
-			// force remapping of vertex buffer
-			curBuffer = null;
-			curMultiBuffer[0] = -1;
-		}
-		return shaderChanged;
-	}
-
-	override function uploadShaderBuffers( buffers : h3d.shader.Buffers, which : h3d.shader.Buffers.BufferKind ) {
-		switch( which ) {
-		case Textures:
-			for( i in 0...curShader.s.fragment.texturesCount ) {
-				var t = buffers.fragment.tex[i];
-				if( t == null || t.isDisposed() ) {
-					var color = h3d.mat.Defaults.loadingTextureColor;
-					t = h3d.mat.Texture.fromColor(color,(color>>>24)/255);
-				}
-				if( t != null && t.t == null && t.realloc != null ) {
-					t.alloc();
-					t.realloc();
-				}
-				t.lastFrame = frame;
-				if( !curShader.usedTextures[i] ) {
-					if( curTextures[i] != null ) {
-						ctx.setTextureAt(i, null);
-						curTextures[i] = null;
-						curSamplerBits[i] = -1;
-					}
-					continue;
-				}
-				var cur = curTextures[i];
-				if( t != cur ) {
-					ctx.setTextureAt(i, t.t);
-					curTextures[i] = t;
-				}
-				// if we have set one of the texture flag manually or if the shader does not configure the texture flags
-				if( true /*!t.hasDefaultFlags() || !s.texHasConfig[s.textureMap[i]]*/ ) {
-					if( cur == null || t.bits != curSamplerBits[i] ) {
-						ctx.setSamplerStateAt(i, WRAP[t.wrap.getIndex()], FILTER[t.filter.getIndex()], MIP[t.mipMap.getIndex()]);
-						curSamplerBits[i] = t.bits;
-					}
-				} else {
-					// the texture flags has been set by the shader, so we are in an unkown state
-					curSamplerBits[i] = -1;
-				}
-			}
-		case Buffers:
-			if( curShader.s.fragment.bufferCount + curShader.s.vertex.bufferCount > 0 )
-				throw "Uniform Buffers are not supported";
-		case Params:
-			if( curShader.s.vertex.paramsSize > 0 ) ctx.setProgramConstantsFromVector(flash.display3D.Context3DProgramType.VERTEX, curShader.s.vertex.globalsSize, buffers.vertex.params.toData(), curShader.s.vertex.paramsSize);
-			if( curShader.s.fragment.paramsSize > 0 ) ctx.setProgramConstantsFromVector(flash.display3D.Context3DProgramType.FRAGMENT, curShader.s.fragment.globalsSize, buffers.fragment.params.toData(), curShader.s.fragment.paramsSize);
-		case Globals:
-			if( curShader.s.vertex.globalsSize > 0 ) ctx.setProgramConstantsFromVector(flash.display3D.Context3DProgramType.VERTEX, 0, buffers.vertex.globals.toData(), curShader.s.vertex.globalsSize);
-			if( curShader.s.fragment.globalsSize > 0 ) ctx.setProgramConstantsFromVector(flash.display3D.Context3DProgramType.FRAGMENT, 0, buffers.fragment.globals.toData(), curShader.s.fragment.globalsSize);
-		}
-	}
-
-	@:access(h3d.impl.ManagedBuffer)
-	override function selectBuffer( v : Buffer ) {
-		if( v == curBuffer )
-			return;
-		if( curBuffer != null && v.buffer == curManagedBuffer && v.flags.has(RawFormat) == curBuffer.flags.has(RawFormat) ) {
-			curBuffer = v;
-			return;
-		}
-		if( curShader == null )
-			throw "No shader selected";
-
-		curBuffer = v;
-		curManagedBuffer = v.buffer; // store if curBuffer is disposed()
-		curMultiBuffer[0] = -1;
-
-		var m = v.buffer.vbuf;
-		if( m.b.stride < curShader.stride )
-			throw "Buffer stride (" + m.b.stride + ") and shader stride (" + curShader.stride + ") mismatch";
-		if( !m.written )
-			m.finalize(this);
-		var pos = 0, offset = 0;
-		var bits = curShader.bufferFormat;
-		if( v.flags.has(RawFormat) ) {
-			while( offset < curShader.stride ) {
-				var size = bits & 7;
-				ctx.setVertexBufferAt(pos++, m.vbuf, offset, FORMAT[size]);
-				offset += size == 0 ? 1 : size;
-				bits >>= 3;
-			}
-		} else {
-			offset = 8; // custom data starts after [position, normal, uv]
-			for( s in curShader.inputs.names ) {
-				switch( s ) {
-				case "position":
-					ctx.setVertexBufferAt(pos++, m.vbuf, 0, FORMAT[3]);
-				case "normal":
-					if( m.b.stride < 6 ) throw "Buffer is missing NORMAL data, set it to RAW format ?" #if track_alloc + @:privateAccess v.allocPos #end;
-					ctx.setVertexBufferAt(pos++, m.vbuf, 3, FORMAT[3]);
-				case "uv":
-					if( m.b.stride < 8 ) throw "Buffer is missing UV data, set it to RAW format ?" #if track_alloc + @:privateAccess v.allocPos #end;
-					ctx.setVertexBufferAt(pos++, m.vbuf, 6, FORMAT[2]);
-				default:
-					var size = bits & 7;
-					ctx.setVertexBufferAt(pos++, m.vbuf, offset, FORMAT[size]);
-					offset += size == 0 ? 1 : size;
-					if( offset > m.b.stride ) throw "Buffer is missing '"+s+"' data, set it to RAW format ?" #if track_alloc + @:privateAccess v.allocPos #end;
-				}
-				bits >>= 3;
-			}
-		}
-		for( i in pos...curAttributes )
-			ctx.setVertexBufferAt(i, null);
-		curAttributes = pos;
-	}
-
-	override function getShaderInputNames() {
-		return curShader.inputs;
-	}
-
-	override function selectMultiBuffers( buffers : Buffer.BufferOffset ) {
-		// select the multiple buffers elements
-		var changed = false;
-		var b = buffers;
-		var i = 0;
-		while( b != null || i < curAttributes ) {
-			if( b == null || b.id != curMultiBuffer[i] ) {
-				changed = true;
-				break;
-			}
-			b = b.next;
-			i++;
-		}
-		if( changed ) {
-			var pos = 0, offset = 0;
-			var bits = curShader.bufferFormat;
-			var b = buffers;
-			while( offset < curShader.stride ) {
-				var size = bits & 7;
-				if( b.buffer.next != null )
-					throw "Buffer is split";
-				var vbuf = @:privateAccess b.buffer.buffer.vbuf;
-				if( !vbuf.written ) vbuf.finalize(this);
-				ctx.setVertexBufferAt(pos, vbuf.vbuf, b.offset, FORMAT[size]);
-				curMultiBuffer[pos] = b.id;
-				offset += size == 0 ? 1 : size;
-				bits >>= 3;
-				pos++;
-				b = b.next;
-			}
-			for( i in pos...curAttributes )
-				ctx.setVertexBufferAt(i, null);
-			curAttributes = pos;
-			curBuffer = null;
-		}
-	}
-
-	function debugDraw( ibuf : IndexBuffer, startIndex : Int, ntriangles : Int ) {
-		try {
-			ctx.drawTriangles(ibuf, startIndex, ntriangles);
-		} catch( e : flash.errors.Error ) {
-			// this error should not happen, but sometime does in debug mode (?)
-			if( e.errorID != 3605 )
-				throw e;
-		}
-	}
-
-	override function allocDepthBuffer(b:h3d.mat.Texture):DepthBuffer {
-		throw "You can't allocate custom depth buffer on this platform.";
-	}
-
-	override function getDefaultDepthBuffer() {
-		return defaultDepth;
-	}
-
-	override function draw( ibuf : IndexBuffer, startIndex : Int, ntriangles : Int ) {
-		if( enableDraw ) {
-			if( ctx.enableErrorChecking )
-				debugDraw(ibuf, startIndex, ntriangles);
-			else
-				ctx.drawTriangles(ibuf, startIndex, ntriangles);
-		}
-	}
-
-	override function setRenderZone( x : Int, y : Int, width : Int, height : Int ) {
-		if( x == 0 && y == 0 && width < 0 && height < 0 ) {
-			enableDraw = true;
-			ctx.setScissorRectangle(null);
-		} else {
-			if( x < 0 ) {
-				width += x;
-				x = 0;
-			}
-			if( y < 0 ) {
-				height += y;
-				y = 0;
-			}
-			var tw = renderTargets == 0 ? this.width : 9999;
-			var th = renderTargets == 0 ? this.height : 9999;
-			if( x + width > tw ) width = tw - x;
-			if( y + height > th ) height = th - y;
-			enableDraw = width > 0 && height > 0;
-			if( enableDraw )
-				ctx.setScissorRectangle(new flash.geom.Rectangle(x, y, width, height));
-		}
-	}
-
-	override function setRenderTarget( t : Null<h3d.mat.Texture>, face = 0, mipLevel = 0 ) {
-		if( mipLevel != 0 )
-			throw "Cannot render to mipmap in flash, use upload()";
-		if( renderTargets > 1 ) {
-			for( i in 1...renderTargets )
-				ctx.setRenderToTexture(null, false, 0, 0, i);
-			renderTargets = 1;
-		}
-		if( t == null ) {
-			ctx.setRenderToBackBuffer();
-			renderTargets = 0;
-		} else {
-			if( t.t == null )
-				t.alloc();
-			ctx.setRenderToTexture(t.t, t.depthBuffer != null, 0, face);
-			renderTargets = 1;
-			t.lastFrame = frame;
-			// make sure we at least clear the color the first time
-			if( flashVersion >= 15 && !t.flags.has(WasCleared) ) {
-				t.flags.set(WasCleared);
-				ctx.clear(0, 0, 0, 0, 1, 0, flash.display3D.Context3DClearMask.COLOR);
-			}
-		}
-		reset();
-	}
-
-	override function setRenderTargets( textures : Array<h3d.mat.Texture>) {
-		if( textures.length == 0 ) {
-			setRenderTarget(null);
-			return;
-		}
-		var hasDepth = textures[0].depthBuffer != null;
-		for( i in 0...textures.length ) {
-			var t = textures[i];
-			if( t.t == null )
-				t.alloc();
-			ctx.setRenderToTexture(t.t, hasDepth, 0, 0, i);
-			t.lastFrame = frame;
-		}
-		for( i in textures.length...renderTargets )
-			ctx.setRenderToTexture(null, false, 0, 0, i);
-		renderTargets = textures.length;
-		reset();
-	}
-
-	static var BLEND = [
-		flash.display3D.Context3DBlendFactor.ONE,
-		flash.display3D.Context3DBlendFactor.ZERO,
-		flash.display3D.Context3DBlendFactor.SOURCE_ALPHA,
-		flash.display3D.Context3DBlendFactor.SOURCE_COLOR,
-		flash.display3D.Context3DBlendFactor.DESTINATION_ALPHA,
-		flash.display3D.Context3DBlendFactor.DESTINATION_COLOR,
-		flash.display3D.Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA,
-		flash.display3D.Context3DBlendFactor.ONE_MINUS_SOURCE_COLOR,
-		flash.display3D.Context3DBlendFactor.ONE_MINUS_DESTINATION_ALPHA,
-		flash.display3D.Context3DBlendFactor.ONE_MINUS_DESTINATION_COLOR
-	];
-
-	static var FACE = [
-		flash.display3D.Context3DTriangleFace.NONE,
-		flash.display3D.Context3DTriangleFace.BACK,
-		flash.display3D.Context3DTriangleFace.FRONT,
-		flash.display3D.Context3DTriangleFace.FRONT_AND_BACK,
-	];
-
-	static var COMPARE = [
-		flash.display3D.Context3DCompareMode.ALWAYS,
-		flash.display3D.Context3DCompareMode.NEVER,
-		flash.display3D.Context3DCompareMode.EQUAL,
-		flash.display3D.Context3DCompareMode.NOT_EQUAL,
-		flash.display3D.Context3DCompareMode.GREATER,
-		flash.display3D.Context3DCompareMode.GREATER_EQUAL,
-		flash.display3D.Context3DCompareMode.LESS,
-		flash.display3D.Context3DCompareMode.LESS_EQUAL,
-	];
-
-	static var STENCIL_OP = [
-		flash.display3D.Context3DStencilAction.KEEP,
-		flash.display3D.Context3DStencilAction.ZERO,
-		flash.display3D.Context3DStencilAction.SET,
-		flash.display3D.Context3DStencilAction.INCREMENT_SATURATE,
-		flash.display3D.Context3DStencilAction.INCREMENT_WRAP,
-		flash.display3D.Context3DStencilAction.DECREMENT_SATURATE,
-		flash.display3D.Context3DStencilAction.DECREMENT_WRAP,
-		flash.display3D.Context3DStencilAction.INVERT,
-	];
-
-	static var FORMAT = [
-		flash.display3D.Context3DVertexBufferFormat.BYTES_4,
-		flash.display3D.Context3DVertexBufferFormat.FLOAT_1,
-		flash.display3D.Context3DVertexBufferFormat.FLOAT_2,
-		flash.display3D.Context3DVertexBufferFormat.FLOAT_3,
-		flash.display3D.Context3DVertexBufferFormat.FLOAT_4,
-	];
-
-	static var WRAP = [
-		flash.display3D.Context3DWrapMode.CLAMP,
-		flash.display3D.Context3DWrapMode.REPEAT,
-	];
-
-	static var FILTER = [
-		flash.display3D.Context3DTextureFilter.NEAREST,
-		flash.display3D.Context3DTextureFilter.LINEAR,
-	];
-
-	static var MIP = [
-		flash.display3D.Context3DMipFilter.MIPNONE,
-		flash.display3D.Context3DMipFilter.MIPNEAREST,
-		flash.display3D.Context3DMipFilter.MIPLINEAR,
-	];
-
-}
-#end

+ 1 - 10
h3d/mat/BigTexture.hx

@@ -304,17 +304,8 @@ class BigTexture {
 			loadRec(q.br);
 		}
 		loadRec(space);
-		if( loadCount > 0 ) {
-			#if flash
-			// flash seems to sometime fail to load texture
-			if( waitTimer == null ) {
-				lastEvent = haxe.Timer.stamp();
-				waitTimer = new haxe.Timer(1000);
-				waitTimer.run = retry.bind(allPixels);
-			}
-			#end
+		if( loadCount > 0 )
 			return;
-		}
 		flush();
 	}
 

+ 1 - 60
h3d/mat/Texture.hx

@@ -12,9 +12,7 @@ class Texture {
 		The default texture color format
 	**/
 	public static var nativeFormat(default,never) : TextureFormat =
-		#if flash
-			BGRA
-		#elseif (usesys && !hldx && !hlsdl && !usegl && !macro)
+		#if (usesys && !hldx && !hlsdl && !usegl && !macro)
 			haxe.GraphicsDriver.nativeFormat
 		#else
 			RGBA
@@ -350,70 +348,13 @@ class Texture {
 		Beware, this is a very slow operation that shouldn't be done during rendering.
 	**/
 	public function capturePixels( face = 0, mipLevel = 0, ?region:h2d.col.IBounds ) : hxd.Pixels {
-		#if flash
-		if( flags.has(Cube) ) throw "Can't capture cube texture on this platform";
-		if( region != null ) throw "Can't capture texture region on this platform";
-		if( face != 0 || mipLevel != 0 ) throw "Can't capture face/mipLevel on this platform";
-		return capturePixelsFlash();
-		#else
 		var old = lastFrame;
 		preventAutoDispose();
 		var pix = mem.driver.capturePixels(this, face, mipLevel, region);
 		lastFrame = old;
 		return pix;
-		#end
 	}
 
-	#if flash
-	function capturePixelsFlash() {
-		var e = h3d.Engine.getCurrent();
-		var oldW = e.width, oldH = e.height;
-		var oldF = filter, oldM = mipMap, oldWrap = wrap;
-		if( e.width < width || e.height < height )
-			e.resize(width, height);
-		e.driver.clear(new h3d.Vector(0, 0, 0, 0),1,0);
-		var s2d = new h2d.Scene();
-		var b = new h2d.Bitmap(h2d.Tile.fromTexture(this), s2d);
-		var shader = new h3d.shader.AlphaChannel();
-		b.addShader(shader); // erase alpha
-		b.blendMode = None;
-
-		mipMap = None;
-
-		s2d.render(e);
-
-		var pixels = hxd.Pixels.alloc(width, height, ARGB);
-		e.driver.captureRenderBuffer(pixels);
-
-		shader.showAlpha = true;
-		s2d.render(e); // render only alpha channel
-		var alpha = hxd.Pixels.alloc(width, height, ARGB);
-		e.driver.captureRenderBuffer(alpha);
-		var alphaPos = hxd.Pixels.getChannelOffset(alpha.format, A);
-		var redPos = hxd.Pixels.getChannelOffset(alpha.format, R);
-		var bpp = @:privateAccess alpha.bytesPerPixel;
-		for( y in 0...height ) {
-			var p = y * width * bpp;
-			for( x in 0...width ) {
-				pixels.bytes.set(p + alphaPos, alpha.bytes.get(p + redPos)); // copy alpha value only
-				p += bpp;
-			}
-		}
-		alpha.dispose();
-		pixels.flags.unset(AlphaPremultiplied);
-
-		if( e.width != oldW || e.height != oldH )
-			e.resize(oldW, oldH);
-		e.driver.clear(new h3d.Vector(0, 0, 0, 0));
-		s2d.dispose();
-
-		filter = oldF;
-		mipMap = oldM;
-		wrap = oldWrap;
-		return pixels;
-	}
-	#end
-
 	public static function fromBitmap( bmp : hxd.BitmapData ) {
 		var t = new Texture(bmp.width, bmp.height);
 		t.uploadBitmap(bmp);

+ 0 - 4
h3d/pass/HardwarePick.hx

@@ -35,11 +35,7 @@ class HardwarePick extends Default {
 		material = new h3d.mat.Pass("");
 		material.blend(One, Zero);
 		texOut = new h3d.mat.Texture(3, 3, [Target]);
-		#if !flash
 		texOut.depthBuffer = new h3d.mat.Texture(3, 3, Depth24Stencil8);
-		#else
-		texOut.depthBuffer = h3d.mat.Texture.getDefaultDepth();
-		#end
 	}
 
 	override function dispose() {

+ 0 - 3
h3d/pass/ShaderManager.hx

@@ -10,9 +10,6 @@ class ShaderManager {
 
 	public function new(?output:Array<hxsl.Output>) {
 		shaderCache = hxsl.Cache.get();
-		#if flash
-		shaderCache.constsToGlobal = true;
-		#end
 		globals = new hxsl.Globals();
 		currentOutput = new hxsl.ShaderList(null);
 		setOutput(output);

+ 0 - 2
h3d/scene/fwd/Renderer.hx

@@ -1,7 +1,5 @@
 package h3d.scene.fwd;
 
-private typedef SMap<T> = #if flash haxe.ds.UnsafeStringMap<T> #else Map<String,T> #end
-
 class DepthPass extends h3d.pass.Default {
 
 	var depthMapId : Int;

+ 22 - 175
hxd/BitmapData.hx

@@ -1,13 +1,9 @@
 package hxd;
 
-typedef BitmapInnerData =
-#if flash
-	flash.display.BitmapData;
-#elseif js
-	js.html.CanvasRenderingContext2D;
+#if js 
+typedef BitmapInnerData = js.html.CanvasRenderingContext2D;
 #else
-	BitmapInnerDataImpl;
-
+typedef BitmapInnerData = BitmapInnerDataImpl;
 class BitmapInnerDataImpl {
 	#if hl
 	public var pixels : hl.BytesAccess<Int>;
@@ -23,15 +19,7 @@ class BitmapInnerDataImpl {
 
 class BitmapData {
 
-	#if flash
-	static var tmpRect = new flash.geom.Rectangle();
-	static var tmpPoint = new flash.geom.Point();
-	static var tmpMatrix = new flash.geom.Matrix();
-	#end
-
-#if flash
-	var bmp : flash.display.BitmapData;
-#elseif js
+#if js
 	var ctx : js.html.CanvasRenderingContext2D;
 	var lockImage : js.html.ImageData;
 	var pixel : js.html.ImageData;
@@ -46,9 +34,7 @@ class BitmapData {
 		if( width == -101 && height == -102 ) {
 			// no alloc
 		} else {
-			#if flash
-			bmp = new flash.display.BitmapData(width, height, true, 0);
-			#elseif js
+			#if js
 			var canvas = js.Browser.document.createCanvasElement();
 			canvas.width = width;
 			canvas.height = height;
@@ -68,11 +54,7 @@ class BitmapData {
 	}
 
 	public function clear( color : Int ) {
-		#if flash
-		bmp.fillRect(bmp.rect, color);
-		#else
 		fill(0, 0, width, height, color);
-		#end
 	}
 
 	static inline function notImplemented() {
@@ -80,14 +62,7 @@ class BitmapData {
 	}
 
 	public function fill( x : Int, y : Int, width : Int, height : Int, color : Int ) {
-		#if flash
-		var r = tmpRect;
-		r.x = x;
-		r.y = y;
-		r.width = width;
-		r.height = height;
-		bmp.fillRect(r, color);
-		#elseif js
+		#if js
 		ctx.fillStyle = 'rgba(${(color>>16)&0xFF}, ${(color>>8)&0xFF}, ${color&0xFF}, ${(color>>>24)/255})';
 		ctx.fillRect(x, y, width, height);
 		#else
@@ -112,100 +87,12 @@ class BitmapData {
 	}
 
 	public function draw( x : Int, y : Int, src : BitmapData, srcX : Int, srcY : Int, width : Int, height : Int, ?blendMode : h2d.BlendMode ) {
-		#if flash
-		if( blendMode == null ) blendMode = Alpha;
-		var r = tmpRect;
-		r.x = srcX;
-		r.y = srcY;
-		r.width = width;
-		r.height = height;
-		switch( blendMode ) {
-		case None:
-			var p = tmpPoint;
-			p.x = x;
-			p.y = y;
-			bmp.copyPixels(src.bmp, r, p);
-		case Alpha:
-			var p = tmpPoint;
-			p.x = x;
-			p.y = y;
-			bmp.copyPixels(src.bmp, r, p, src.bmp, null, true);
-		case Add:
-			var m = tmpMatrix;
-			m.tx = x - srcX;
-			m.ty = y - srcY;
-			r.x = x;
-			r.y = y;
-			bmp.draw(src.bmp, m, null, flash.display.BlendMode.ADD, r, false);
-		case Erase:
-			var m = tmpMatrix;
-			m.tx = x - srcX;
-			m.ty = y - srcY;
-			r.x = x;
-			r.y = y;
-			bmp.draw(src.bmp, m, null, flash.display.BlendMode.ERASE, r, false);
-		case Multiply:
-			var m = tmpMatrix;
-			m.tx = x - srcX;
-			m.ty = y - srcY;
-			r.x = x;
-			r.y = y;
-			bmp.draw(src.bmp, m, null, flash.display.BlendMode.MULTIPLY, r, false);
-		case Screen:
-			var m = tmpMatrix;
-			m.tx = x - srcX;
-			m.ty = y - srcY;
-			r.x = x;
-			r.y = y;
-			bmp.draw(src.bmp, m, null, flash.display.BlendMode.SCREEN, r, false);
-		case SoftAdd, AlphaAdd, AlphaMultiply, Sub, Max, Min:
-			throw "BlendMode not supported";
-		}
-		#else
-		notImplemented();
-		#end
+		drawScaled(x,y,width,height,src,srcX,srcY,width,height,blendMode);
 	}
 
 	public function drawScaled( x : Int, y : Int, width : Int, height : Int, src : BitmapData, srcX : Int, srcY : Int, srcWidth : Int, srcHeight : Int, ?blendMode : h2d.BlendMode, smooth = true ) {
 		if( blendMode == null ) blendMode = Alpha;
-		#if flash
-
-		var b = switch( blendMode ) {
-		case None:
-			// todo : clear before ?
-			flash.display.BlendMode.NORMAL;
-		case Alpha:
-			flash.display.BlendMode.NORMAL;
-		case Add:
-			flash.display.BlendMode.ADD;
-		case Erase:
-			flash.display.BlendMode.ERASE;
-		case Multiply:
-			flash.display.BlendMode.MULTIPLY;
-		case Screen:
-			flash.display.BlendMode.SCREEN;
-		case SoftAdd, AlphaAdd, AlphaMultiply, Sub, Max, Min:
-			throw "BlendMode not supported";
-		}
-
-		var m = tmpMatrix;
-		m.a = width / srcWidth;
-		m.d = height / srcHeight;
-		m.tx = x - srcX * m.a;
-		m.ty = y - srcY * m.d;
-
-		var r = tmpRect;
-		r.x = x;
-		r.y = y;
-		r.width = width;
-		r.height = height;
-
-		bmp.draw(src.bmp, m, null, b, r, smooth);
-		m.a = 1;
-		m.d = 1;
-
-		#elseif hl
-
+		#if hl
 		if( blendMode != None ) throw "BitmapData.drawScaled blendMode no supported : " + blendMode;
 		if( x < 0 || y < 0 || width < 0 || height < 0 || srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 ||
 			x + width > this.width || y + height > this.height || srcX + srcWidth > src.width || srcY + srcHeight > src.height )
@@ -215,7 +102,6 @@ class BitmapData {
 			src.data.pixels, (srcX + srcY * src.width)<<2, src.width<<2, srcWidth, srcHeight,
 			smooth?1:0
 		);
-
 		#else
 		notImplemented();
 		#end
@@ -459,9 +345,7 @@ class BitmapData {
 	}
 
 	public inline function dispose() {
-		#if flash
-		bmp.dispose();
-		#elseif js
+		#if js
 		ctx = null;
 		pixel = null;
 		#else
@@ -474,11 +358,7 @@ class BitmapData {
 	}
 
 	public function sub( x, y, w, h ) : BitmapData {
-		#if flash
-		var b = new flash.display.BitmapData(w, h);
-		b.copyPixels(bmp, new flash.geom.Rectangle(x, y, w, h), new flash.geom.Point(0, 0));
-		return fromNative(b);
-		#elseif js
+		#if js
 		var canvas = js.Browser.document.createCanvasElement();
 		canvas.width = w;
 		canvas.height = h;
@@ -507,9 +387,7 @@ class BitmapData {
 		Inform that we will perform several pixel operations on the BitmapData.
 	**/
 	public function lock() {
-		#if flash
-		bmp.lock();
-		#elseif js
+		#if js
 		if( lockImage == null )
 			lockImage = ctx.getImageData(0, 0, width, height);
 		#end
@@ -519,9 +397,7 @@ class BitmapData {
 		Inform that we have finished performing pixel operations on the BitmapData.
 	**/
 	public function unlock() {
-		#if flash
-		bmp.unlock();
-		#elseif js
+		#if js
 		if( lockImage != null ) {
 			ctx.putImageData(lockImage, 0, 0);
 			lockImage = null;
@@ -532,10 +408,8 @@ class BitmapData {
 	/**
 		Access the pixel color value at the given position. Note : this function can be very slow if done many times and the BitmapData has not been locked.
 	**/
-	public #if flash inline #end function getPixel( x : Int, y : Int ) : Int {
-		#if flash
-		return bmp.getPixel32(x, y);
-		#elseif js
+	public function getPixel( x : Int, y : Int ) : Int {
+		#if js
 		var i = lockImage;
 		var a;
 		if( i != null )
@@ -553,10 +427,8 @@ class BitmapData {
 	/**
 		Modify the pixel color value at the given position. Note : this function can be very slow if done many times and the BitmapData has not been locked.
 	**/
-	public #if flash inline #end function setPixel( x : Int, y : Int, c : Int ) {
-		#if flash
-		bmp.setPixel32(x, y, c);
-		#elseif js
+	public function setPixel( x : Int, y : Int, c : Int ) {
+		#if js
 		var i : js.html.ImageData = lockImage;
 		if( i != null ) {
 			var a = (x + y * i.width) << 2;
@@ -582,9 +454,7 @@ class BitmapData {
 	}
 
 	inline function get_width() : Int {
-		#if flash
-		return bmp.width;
-		#elseif js
+		#if js
 		return ctx.canvas.width;
 		#else
 		return data.width;
@@ -592,9 +462,7 @@ class BitmapData {
 	}
 
 	inline function get_height() {
-		#if flash
-		return bmp.height;
-		#elseif js
+		#if js
 		return ctx.canvas.height;
 		#else
 		return data.height;
@@ -602,11 +470,7 @@ class BitmapData {
 	}
 
 	public function getPixels() : Pixels {
-		#if flash
-		var p = new Pixels(width, height, haxe.io.Bytes.ofData(bmp.getPixels(bmp.rect)), ARGB);
-		p.flags.set(AlphaPremultiplied);
-		return p;
-		#elseif js
+		#if js
 		var w = width;
 		var h = height;
 		var data = ctx.getImageData(0, 0, w, h).data;
@@ -623,20 +487,7 @@ class BitmapData {
 	public function setPixels( pixels : Pixels ) {
 		if( pixels.width != width || pixels.height != height )
 			throw "Invalid pixels size";
-		#if flash
-		var bytes = pixels.bytes.getData();
-		bytes.position = 0;
-		switch( pixels.format ) {
-		case BGRA:
-			bytes.endian = flash.utils.Endian.LITTLE_ENDIAN;
-		case ARGB:
-			bytes.endian = flash.utils.Endian.BIG_ENDIAN;
-		default:
-			pixels.convert(BGRA);
-			bytes.endian = flash.utils.Endian.LITTLE_ENDIAN;
-		}
-		bmp.setPixels(bmp.rect, bytes);
-		#elseif js
+		#if js
 		var img = ctx.createImageData(pixels.width, pixels.height);
 		pixels.convert(RGBA);
 		for( i in 0...pixels.width*pixels.height*4 ) img.data[i] = pixels.bytes.get(i);
@@ -650,9 +501,7 @@ class BitmapData {
 	}
 
 	public inline function toNative() : BitmapInnerData {
-		#if flash
-		return bmp;
-		#elseif js
+		#if js
 		return ctx;
 		#else
 		return data;
@@ -661,9 +510,7 @@ class BitmapData {
 
 	public static function fromNative( data : BitmapInnerData ) : BitmapData {
 		var b = new BitmapData( -101, -102 );
-		#if flash
-		b.bmp = data;
-		#elseif js
+		#if js
 		b.ctx = data;
 		#else
 		b.data = data;

+ 4 - 13
hxd/ByteConversions.hx

@@ -7,20 +7,11 @@ import haxe.io.Bytes;
  */
 class ByteConversions{
 
-#if flash
+#if js
 
-	public static inline function byteArrayToBytes( v: flash.utils.ByteArray ) : haxe.io.Bytes {
-		return Bytes.ofData( v );
-	}
-
-	public static inline function bytesToByteArray( v: haxe.io.Bytes ) :  flash.utils.ByteArray {
-		return v.getData();
-	}
-#elseif js
-
-	public static inline function arrayBufferToBytes( v : hxd.impl.TypedArray.ArrayBuffer ) : haxe.io.Bytes{
-		return haxe.io.Bytes.ofData(v);
-	}
+	//public static inline function arrayBufferToBytes( v : hxd.impl.TypedArray.ArrayBuffer ) : haxe.io.Bytes{
+	//	return haxe.io.Bytes.ofData(v);
+	//}
 
 #end
 

+ 1 - 20
hxd/BytesBuffer.hx

@@ -1,18 +1,11 @@
 package hxd;
 
-private typedef InnerData = #if flash flash.utils.ByteArray #else haxe.io.BytesOutput #end
-
-abstract BytesBuffer(InnerData) {
+abstract BytesBuffer(haxe.io.BytesOutput) {
 
 	public var length(get, never) : Int;
 
 	public inline function new() {
-		#if flash
-		this = new flash.utils.ByteArray();
-		this.endian = flash.utils.Endian.LITTLE_ENDIAN;
-		#else
 		this = new haxe.io.BytesOutput();
-		#end
 	}
 
 	public static inline function fromU8Array(arr:Array<Int>) {
@@ -38,27 +31,15 @@ abstract BytesBuffer(InnerData) {
 	}
 
 	public inline function writeInt32( v : Int ) {
-		#if flash
-		this.writeUnsignedInt(v);
-		#else
 		this.writeInt32(v);
-		#end
 	}
 
 	public inline function getBytes() : haxe.io.Bytes {
-		#if flash
-		return haxe.io.Bytes.ofData(this);
-		#else
 		return this.getBytes();
-		#end
 	}
 
 	inline function get_length() {
-		#if flash
-		return this.length;
-		#else
 		return this.length;
-		#end
 	}
 
 }

+ 0 - 9
hxd/Cursor.hx

@@ -26,10 +26,6 @@ class CustomCursor {
 	var alloc : Array<sdl.Cursor>;
 	#elseif hldx
 	var alloc : Array<dx.Cursor>;
-	#elseif flash
-	static var UID = 0;
-	var name : String;
-	var alloc : flash.ui.MouseCursorData;
 	#elseif js
 	var alloc : Array<String>;
 	#else
@@ -48,9 +44,6 @@ class CustomCursor {
 		this.speed = speed;
 		this.offsetX = offsetX;
 		this.offsetY = offsetY;
-		#if flash
-		name = "custom_" + UID++;
-		#end
 		#if (hlsdl || hldx || js)
 		frameDelay = 1 / speed;
 		frameTime = 0;
@@ -92,8 +85,6 @@ class CustomCursor {
 			for (cur in alloc) {
 				cur.free();
 			}
-			#elseif flash
-			flash.ui.Mouse.unregisterCursor(name);
 			#elseif hldx
 			for (cur in alloc) {
 				cur.destroy();

+ 9 - 192
hxd/File.hx

@@ -22,81 +22,9 @@ typedef BrowseSelect = {
 
 class File {
 
-	#if flash
-	static function isAir() {
-		return flash.system.Capabilities.playerType == "Desktop";
-	}
-	#end
-
-	#if (flash && air3)
-
-	static function getRelPath( path : String ) {
-		return try new flash.filesystem.File(path) catch( e : Dynamic ) new flash.filesystem.File(flash.filesystem.File.applicationDirectory.nativePath + "/" + path);
-	}
-
-	static var lastBrowseDir : Dynamic;
-	static function browseAir( onSelect : BrowseSelect -> Void, options : BrowseOptions, filters ) {
-		var f : flash.filesystem.File = lastBrowseDir;
-		if( f == null )
-			f = flash.filesystem.File.applicationDirectory;
-		if( options.defaultPath != null )
-			try f = flash.filesystem.File.applicationDirectory.resolvePath(options.defaultPath) catch( e : Dynamic ) {}
-		lastBrowseDir = f;
-		var basePath = f.clone();
-		function onSelectCallb(_) {
-			f.removeEventListener(flash.events.Event.SELECT, onSelectCallb);
-			var path = f.nativePath;
-			if( options.relativePath ) {
-				if( !basePath.isDirectory ) basePath = basePath.parent;
-				var relPath = basePath.getRelativePath(f, true);
-				if( relPath != null )
-					path = relPath;
-			}
-			var sel : BrowseSelect = {
-				fileName : path,
-				load : function(onReady) {
-					haxe.Timer.delay(function() {
-						var fs = new flash.filesystem.FileStream();
-						fs.open(f, flash.filesystem.FileMode.READ);
-						var bytes = haxe.io.Bytes.alloc(fs.bytesAvailable);
-						fs.readBytes(bytes.getData());
-						fs.close();
-						onReady(bytes);
-					},1);
-				},
-			};
-			onSelect(sel);
-		}
-		f.addEventListener(flash.events.Event.SELECT, onSelectCallb);
-		f.browseForOpen(options.title == null ? "" : options.title, filters);
-	}
-	#end
-
 	public static function browse( onSelect : BrowseSelect -> Void, ?options : BrowseOptions ) {
 		if( options == null ) options = {};
-		#if flash
-			var filters = options.fileTypes == null ? null : [for( o in options.fileTypes ) new flash.net.FileFilter(o.name,[for( e in o.extensions ) "*."+e].join(";"))];
-			#if air3
-			if( isAir() ) {
-				browseAir(onSelect, options,filters);
-				return;
-			}
-			#end
-			var f = new flash.net.FileReference();
-			f.addEventListener(flash.events.Event.SELECT, function(_) {
-				var sel : BrowseSelect = {
-					fileName : f.name,
-					load : function(onReady) {
-						f.addEventListener(flash.events.Event.COMPLETE, function(_) {
-							onReady(haxe.io.Bytes.ofData(f.data));
-						});
-						f.load();
-					},
-				};
-				onSelect(sel);
-			});
-			f.browse(filters);
-		#elseif (hl && (haxe_ver >= 4))
+		#if (hl && (haxe_ver >= 4))
 			var old = hxd.System.allowTimeout;
 			hxd.System.allowTimeout = false;
 			var path = hl.UI.loadFile({
@@ -173,50 +101,9 @@ class File {
 		#end
 	}
 
-	#if (flash && air3)
-	static function saveAsAir( dataContent : haxe.io.Bytes, options : BrowseOptions ) {
-		var f = flash.filesystem.File.applicationDirectory;
-		if( options.defaultPath != null )
-			try f = f.resolvePath(options.defaultPath) catch( e : Dynamic ) {}
-		var basePath = f.clone();
-		function onSelect(_) {
-			f.removeEventListener(flash.events.Event.SELECT, onSelect);
-			// save data
-			var o = new flash.filesystem.FileStream();
-			o.open(f, flash.filesystem.FileMode.WRITE);
-			o.writeBytes(dataContent.getData());
-			o.close();
-			if( options.saveFileName != null ) {
-				var path = f.nativePath;
-				if( options.relativePath ) {
-					if( !basePath.isDirectory ) basePath = basePath.parent;
-					var relPath = basePath.getRelativePath(f, true);
-					if( relPath != null )
-						path = relPath;
-				}
-				options.saveFileName(path);
-			}
-		};
-		f.addEventListener(flash.events.Event.SELECT, onSelect);
-		f.browseForSave(options.title == null ? "" : options.title);
-	}
-	#end
-
 	public static function saveAs( dataContent : haxe.io.Bytes, ?options : BrowseOptions ) {
 		if( options == null ) options = { };
-		#if flash
-			#if air3
-			if( isAir() ) {
-				saveAsAir(dataContent, options);
-				return;
-			}
-			#end
-			var f = new flash.net.FileReference();
-			f.addEventListener(flash.events.Event.SELECT, function(_) {
-			});
-			var defaultFile = options.defaultPath;
-			f.save(dataContent.getData(), defaultFile);
-		#elseif (hl && (haxe_ver >= 4))
+		#if (hl && (haxe_ver >= 4))
 			var old = hxd.System.allowTimeout;
 			hxd.System.allowTimeout = false;
 			var path = hl.UI.saveFile({
@@ -241,9 +128,7 @@ class File {
 	}
 
 	public static function exists( path : String ) : Bool {
-		#if (flash && air3)
-		return getRelPath(path).exists;
-		#elseif (sys || nodejs)
+		#if (sys || nodejs)
 		return sys.FileSystem.exists(path);
 		#else
 		throw "Not supported";
@@ -252,12 +137,7 @@ class File {
 	}
 
 	public static function delete( path : String ) {
-		#if (flash && air3)
-		try {
-			getRelPath(path).deleteFile();
-		} catch( e : Dynamic ) {
-		}
-		#elseif (sys || nodejs)
+		#if (sys || nodejs)
 		try sys.FileSystem.deleteFile(path) catch( e : Dynamic ) { };
 		#else
 		throw "Not supported";
@@ -265,13 +145,7 @@ class File {
 	}
 
 	public static function listDirectory( path : String ) {
-		#if (flash && air3)
-		try {
-			return [for( f in getRelPath(path).getDirectoryListing() ) f.name];
-		} catch( e : Dynamic ) {
-			return [];
-		}
-		#elseif (sys || nodejs)
+		#if (sys || nodejs)
 		return sys.FileSystem.readDirectory(path);
 		#else
 		throw "Not supported";
@@ -279,16 +153,7 @@ class File {
 	}
 
 	public static function getBytes( path : String ) : haxe.io.Bytes {
-		#if (flash && air3)
-		var file = getRelPath(path);
-		if( !file.exists ) throw "File not found " + path;
-		var fs = new flash.filesystem.FileStream();
-		fs.open(file, flash.filesystem.FileMode.READ);
-		var bytes = haxe.io.Bytes.alloc(fs.bytesAvailable);
-		fs.readBytes(bytes.getData());
-		fs.close();
-		return bytes;
-		#elseif (sys || nodejs)
+		#if (sys || nodejs)
 		return sys.io.File.getBytes(path);
 		#else
 		throw "Not supported";
@@ -296,27 +161,8 @@ class File {
 		#end
 	}
 
-	#if (flash && air3)
-	static function saveBytesAir( path : String, data : haxe.io.Bytes ) {
-		if( path == null ) throw "NULL path";
-		var f = getRelPath(path);
-		var o = new flash.filesystem.FileStream();
-		o.open(f, flash.filesystem.FileMode.WRITE);
-		o.writeBytes(data.getData());
-		o.close();
-	}
-	#end
-
 	public static function saveBytes( path : String, data : haxe.io.Bytes ) {
-		#if flash
-			#if air3
-			if( isAir() ) {
-				saveBytesAir(path, data);
-				return;
-			}
-			#end
-			saveAs(data, { defaultPath:path } );
-		#elseif (sys || nodejs)
+		#if (sys || nodejs)
 		sys.io.File.saveBytes(path, data);
 		#else
 		throw "Not supported";
@@ -325,20 +171,7 @@ class File {
 
 	public static function load( path : String, onLoad : haxe.io.Bytes -> Void, ?onError : String -> Void ) {
 		if( onError == null ) onError = function(_) { };
-		#if flash
-		var f = new flash.net.URLLoader();
-		f.dataFormat = flash.net.URLLoaderDataFormat.BINARY;
-		f.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) {
-			onError(Std.string(e));
-		});
-		f.addEventListener(flash.events.SecurityErrorEvent.SECURITY_ERROR, function(e:flash.events.SecurityErrorEvent) {
-			onError(Std.string(e));
-		});
-		f.addEventListener(flash.events.Event.COMPLETE, function(_) {
-			onLoad(haxe.io.Bytes.ofData(f.data));
-		});
-		f.load(new flash.net.URLRequest(path));
-		#elseif sys
+		#if sys
 		var content = try sys.io.File.getBytes(path) catch( e : Dynamic ) { if( onError != null ) onError("" + e); return; };
 		onLoad(content);
 		#else
@@ -347,27 +180,11 @@ class File {
 	}
 
 	public static function createDirectory( path : String ) {
-		#if (flash && air3)
-		getRelPath(path).createDirectory();
-		#elseif (sys || nodejs)
+		#if (sys || nodejs)
 		sys.FileSystem.createDirectory(path);
 		#else
 		throw "Not supported";
 		#end
 	}
 
-	public static function applicationPath() : String {
-		#if flash
-		var path = flash.Lib.current.loaderInfo.loaderURL.substr(7); // file://
-		if( path.charCodeAt(2) == "|".code ) // driver letter on windows
-			path = path.charAt(1) + ":" + path.substr(3);
-		var path = path.split("/");
-		path[path.length - 1] = "";
-		return path.join("/");
-		#else
-		throw "Not supported";
-		return null;
-		#end
-	}
-
 }

+ 4 - 10
hxd/FloatBuffer.hx

@@ -1,7 +1,7 @@
 package hxd;
 import hxd.impl.TypedArray;
 
-private typedef InnerData = #if flash flash.Vector<Float> #elseif js Float32Expand #else Array<hxd.impl.Float32> #end
+private typedef InnerData = #if js Float32Expand #else Array<hxd.impl.Float32> #end
 
 #if js
 private abstract Float32Expand({ pos : Int, array : hxd.impl.TypedArray.Float32Array }) {
@@ -65,7 +65,7 @@ abstract FloatBuffer(InnerData) {
 	public var length(get, never) : Int;
 
 	public inline function new(length = 0) {
-		#if (flash || js)
+		#if js
 		this = new InnerData(length);
 		#else
 		this = new InnerData();
@@ -74,17 +74,11 @@ abstract FloatBuffer(InnerData) {
 	}
 
 	public inline function push( v : hxd.impl.Float32 ) {
-		#if flash
-		this[this.length] = v;
-		#else
 		this.push(v);
-		#end
 	}
 
 	public inline function grow( v : Int ) {
-		#if flash
-		if( v > this.length ) this.length = v;
-		#elseif js
+		#if js
 		for( i in this.length...v )
 			this.push(0.);
 		#else
@@ -93,7 +87,7 @@ abstract FloatBuffer(InnerData) {
 	}
 
 	public inline function resize( v : Int ) {
-		#if (flash||js)
+		#if js
 		this.length = v;
 		#else
 		if( this.length > v ) this.splice(v, this.length - v) else grow(v);

+ 2 - 10
hxd/IndexBuffer.hx

@@ -1,6 +1,6 @@
 package hxd;
 
-private typedef InnerData = #if flash flash.Vector<UInt> #else Array<hxd.impl.UInt16> #end
+private typedef InnerData = Array<hxd.impl.UInt16>;
 
 private class InnerIterator {
 	var b : InnerData;
@@ -26,8 +26,6 @@ abstract IndexBuffer(InnerData) {
 	public inline function new(length = 0) {
 		#if js
 		this = #if (haxe_ver >= 4) js.Syntax.construct #else untyped __new__ #end(Array, length);
-		#elseif flash
-		this = new InnerData(length);
 		#else
 		this = new InnerData();
 		if( length > 0 ) grow(length);
@@ -35,17 +33,11 @@ abstract IndexBuffer(InnerData) {
 	}
 
 	public inline function push( v : Int ) {
-		#if flash
-		this[this.length] = v;
-		#else
 		this.push(v);
-		#end
 	}
 
 	public inline function grow( v : Int ) {
-		#if flash
-		if( v > this.length ) this.length = v;
-		#elseif js
+		#if js
 		while( this.length < v ) this.push(0);
 		#else
 		if( v > this.length ) this[v - 1] = 0;

+ 0 - 12
hxd/Key.hx

@@ -194,28 +194,16 @@ class Key {
 		initDone = true;
 		keyPressed = [];
 		Window.getInstance().addEventTarget(onEvent);
-		#if flash
-		flash.Lib.current.stage.addEventListener(flash.events.Event.DEACTIVATE, onDeactivate);
-		#end
 	}
 
 	public static function dispose() {
 		if( initDone ) {
 			Window.getInstance().removeEventTarget(onEvent);
-			#if flash
-			flash.Lib.current.stage.removeEventListener(flash.events.Event.DEACTIVATE, onDeactivate);
-			#end
 			initDone = false;
 			keyPressed = [];
 		}
 	}
 
-	#if flash
-	static function onDeactivate(_) {
-		keyPressed = [];
-	}
-	#end
-
 	static function onEvent( e : Event ) {
 		switch( e.kind ) {
 		case EKeyDown:

+ 3 - 113
hxd/Pad.hx

@@ -53,32 +53,6 @@ typedef PadConfig = {
 
 class Pad {
 
-	#if flash
-	public static var CONFIG_XBOX = {
-		analogX : 0,
-		analogY : 1,
-		ranalogX : 2,
-		ranalogY : 3,
-		A : 4,
-		B : 5,
-		X : 6,
-		Y : 7,
-		LB : 8,
-		RB : 9,
-		LT : 10,
-		RT : 11,
-		back : 12,
-		start : 13,
-		analogClick : 14,
-		ranalogClick : 15,
-		dpadUp : 16,
-		dpadDown : 17,
-		dpadLeft : 18,
-		dpadRight : 19,
-		names : ["LX","LY","RX","RY","A","B","X","Y","LB","RB","LT","RT","Back","Start","LCLK","RCLK","DUp","DDown","DLeft","DRight"],
-	};
-	#end
-
 	#if hlsdl
 	/**
 		Works with both DualShock and XBox controllers
@@ -212,7 +186,6 @@ class Pad {
 
 	public static var DEFAULT_CONFIG : PadConfig =
 		#if hlsdl CONFIG_SDL
-		#elseif flash CONFIG_XBOX
 		#elseif (hldx || usesys) GameController.CONFIG
 		#elseif js  CONFIG_JS_STD
 		#else ({}:Dynamic) #end;
@@ -310,7 +283,7 @@ class Pad {
 
 	function get_name() {
 		if( index < 0 ) return "Dummy GamePad";
-		#if (flash || hldx || hlsdl || usesys)
+		#if (hldx || hlsdl || usesys)
 		return d.name;
 		#elseif js
 		return d.id;
@@ -331,11 +304,7 @@ class Pad {
 	static var waitPad : Pad -> Void;
 	static var initDone = false;
 
-	#if flash
-	var d : flash.ui.GameInputDevice;
-	static var inst : flash.ui.GameInput;
-	static var pads : Array<hxd.Pad> = [];
-	#elseif js
+	#if js
 	var d : js.html.Gamepad;
 	static var pads : Map<Int, hxd.Pad> = new Map();
 	#elseif (hldx || hlsdl || usesys)
@@ -352,86 +321,7 @@ class Pad {
 			return;
 		#end
 		waitPad = onPad;
-		#if flash
-		if( !initDone ) {
-			initDone = true;
-			inst = new flash.ui.GameInput();
-			inst.addEventListener(flash.events.GameInputEvent.DEVICE_ADDED, function(e:flash.events.GameInputEvent) {
-				var p = new Pad();
-				pads.push( p );
-				p.d = e.device;
-				//trace(p.d.name, p.d.id);
-				for( i in 0...flash.ui.GameInput.numDevices )
-					if( p.d == flash.ui.GameInput.getDeviceAt(i) )
-						p.index = i;
-				p.d.enabled = true;
-				var axisCount = 0;
-				var axisX = 0, axisY = 1;
-				var raxisX = 2, raxisY = 3;
-				for( i in 0...p.d.numControls ) {
-					var c = p.d.getControlAt(i);
-					var cid = c.id;
-					var valID = p.values.length;
-					var min = c.minValue, max = c.maxValue;
-					p.values.push(0.);
-					if( StringTools.startsWith(c.id, "AXIS_") ) {
-						var axisID = axisCount++;
-						c.addEventListener(flash.events.Event.CHANGE, function(_) {
-							var v = (c.value - min) * 2 / (max - min) - 1;
-							//if( Math.abs(p.values[valID] - v) > 0.1 ) trace(valID, v);
-							p.values[valID] = v;
-							if( axisID == axisX )
-								p.rawXAxis = v;
-							else if( axisID == axisY )
-								p.rawYAxis = -v;
-							else if( axisID == raxisX)
-								p.rawRXAxis = v;
-							else if( axisID == raxisY)
-								p.rawRYAxis = -v;
-						});
-					} else if( StringTools.startsWith(c.id, "BUTTON_") ) {
-						c.addEventListener(flash.events.Event.CHANGE, function(_) {
-							var v = (c.value - min) / (max - min);
-							//if( Math.abs(p.values[valID] - v) > 0.1 ) trace(valID, v);
-							p.values[valID] = v;
-							p.buttons[valID] = v > 0.5;
-						});
-					}
-				}
-
-				if( waitPad != null ) waitPad(p);
-			});
-			inst.addEventListener(flash.events.GameInputEvent.DEVICE_REMOVED, function(e:flash.events.GameInputEvent) {
-				for( p in pads )
-					if( p.d.id == e.device.id ){
-						pads.remove( p );
-						p.d.enabled = false;
-						p.connected = false;
-						p.onDisconnect();
-						break;
-					}
-			});
-			inst.addEventListener(flash.events.GameInputEvent.DEVICE_UNUSABLE, function(e:flash.events.GameInputEvent) {
-				for( p in pads )
-					if( p.d.id == e.device.id ){
-						pads.remove( p );
-						p.d.enabled = false;
-						p.connected = false;
-						p.onDisconnect();
-						break;
-					}
-			});
-			flash.Lib.current.addEventListener(flash.events.Event.EXIT_FRAME, function(_){
-				for( p in pads ) {
-					for( i in 0...p.buttons.length )
-						p.prevButtons[i] = p.buttons[i];
-					for( i in 0...p.values.length )
-						p.prevValues[i] = p.values[i];
-				}
-			});
-			var count = flash.ui.GameInput.numDevices; // necessary to trigger added
-		}
-		#elseif hlsdl
+		#if hlsdl
 		if( !initDone ) {
 			initDone = true;
 			var c = @:privateAccess GameController.gctrlCount();

+ 0 - 55
hxd/Perlin.hx

@@ -7,28 +7,10 @@ class Perlin {
 	/** Keep result in the [-1, 1] range **/
 	public var normalize : Bool;
 
-	#if flash
-	var buf : flash.utils.ByteArray;
-	#else
 	var gradients : Array<Float>;
-	#end
 
 	public function new() {
 		repeat = 0x7FFFFFFF;
-		#if flash
-		// space for gradients
-		buf = new flash.utils.ByteArray();
-		buf.length += NGRADS * 4 * 8;
-		// init gradients and alpha channel
-		flash.Memory.select(buf);
-		for( i in 0...NGRADS ) {
-			var p = i << 5;
-			setDouble(p, GRADIENTS[i * 3] * 2.12);
-			setDouble(p + 8, GRADIENTS[i * 3 + 1] * 2.12);
-			setDouble(p + 16, GRADIENTS[i * 3 + 2] * 2.12);
-			setDouble(p + 24, 0); // padding
-		}
-		#else
 		gradients = [];
 		for( i in 0...NGRADS ) {
 			gradients.push(GRADIENTS[i * 3] * 2.12);
@@ -36,26 +18,7 @@ class Perlin {
 			gradients.push(GRADIENTS[i * 3 + 2] * 2.12);
 			gradients.push(0); // padding
 		}
-		#end
-		select();
-	}
-
-	public inline function select() {
-		#if flash
-		flash.Memory.select(buf);
-		#end
-	}
-
-	#if flash
-	inline function setDouble( index : Int, v : Float )  {
-		flash.Memory.setDouble(index, v);
-	}
-
-	inline function double( index : Int ) : Float {
-		return flash.Memory.getDouble(index);
-
 	}
-	#end
 
 	inline function scurve( a : Float ) {
 		var a2 = a * a;
@@ -69,43 +32,25 @@ class Perlin {
 	inline function gradient3DAt( x : Float, y : Float, z : Float, ix : Int, iy : Int, iz : Int, seed : Int ) {
 		var index = seed * 1013 + (ix % repeat) * 1619 + (iy % repeat) * 31337 + iz * 6971;
 		index = ((index ^ (index >>> 8)) & 0xFF);
-		#if flash
-		index <<= 5;
-		var gx = double(index);
-		var gy = double(index + 8);
-		var gz = double(index + 16);
-		#else
 		index <<= 2;
 		var gx = gradients[index];
 		var gy = gradients[index + 1];
 		var gz = gradients[index + 2];
-		#end
 		return gx * (x - ix) + gy * (y - iy) + gz * (z - iz);
 	}
 
 	inline function gradient1DAt( x : Float, ix : Int, seed : Int ) {
 		var index = seed * 1013 + (ix%repeat) * 1619;
 		index = ((index ^ (index >>> 8)) & 0xFF);
-		#if flash
-		index <<= 5;
-		var gx = double(index);
-		#else
 		var gx = gradients[index << 2];
-		#end
 		return gx * (x - ix);
 	}
 
 	inline function gradientAt( x : Float, y : Float, ix : Int, iy : Int, seed : Int ) {
 		var index = seed * 1013 + (ix%repeat) * 1619 + (iy%repeat) * 31337;
 		index = ((index ^ (index >>> 8)) & 0xFF);
-		#if flash
-		index <<= 5;
-		var gx = double(index);
-		var gy = double(index + 8);
-		#else
 		var gx = gradients[index << 2];
 		var gy = gradients[(index << 2) + 1];
-		#end
 		return gx * (x - ix) + gy * (y - iy);
 	}
 

+ 1 - 38
hxd/Save.hx

@@ -7,18 +7,6 @@ package hxd;
 class Save {
 
 	static var cur = new Map<String,String>();
-	#if flash
-	static var saveObj : flash.net.SharedObject;
-	static var curObj : String;
-	static function getObj( name : String ) {
-		if( curObj != name ) {
-			curObj = name;
-			saveObj = flash.net.SharedObject.getLocal(name);
-		}
-		return saveObj;
-	}
-	#end
-
 	static var SALT = "s*al!t";
 
 	static function makeCRC( data : String ) {
@@ -58,23 +46,12 @@ class Save {
 		@param checkSum Set to true if data expected to have crc checksum prepending the data. Should be set for entries saved with `checkSum = true`.
 	**/
 	public static function load<T>( ?defValue : T, ?name = "save", checkSum = false ) : T {
-		#if flash
-		try {
-			var data = Reflect.field(getObj(name).data, "data");
-			cur.set(name, data);
-			return loadData(data,checkSum,defValue);
-		} catch( e : Dynamic ) {
-			return defValue;
-		}
-		#else
 		return try loadData(readSaveData(name), checkSum, defValue) catch( e : Dynamic ) defValue;
-		#end
 	}
 
 	/**
 		Override this method to provide custom save lookup.
 		By default it uses `name + ".sav"` for system targets and `localStorage.getItem(name)` on JS.
-		Have no effect on flash (shared object is used).
 		**Note:** This method is an utility method, to load data use `hxd.Save.load`
 	**/
 	@:noCompletion public static dynamic function readSaveData( name : String ) : String {
@@ -91,7 +68,6 @@ class Save {
 	/**
 		Override this method to provide custom save storage.
 		By default it stores saves in `name + ".sav"` file in current working directory on system targets and `localStorage.setItem(name)` on JS.
-		Have no effect on flash (shared object is used)
 		**Note:** This method is an utility method, to save data use `hxd.Save.save`
 	**/
 	@:noCompletion public static dynamic function writeSaveData( name : String, data : String ) {
@@ -107,12 +83,9 @@ class Save {
 	/**
 		Deletes save with specified name.
 		Override this method when using custom save lookup.
-		Does not work on flash.
 	**/
 	public dynamic static function delete( name = "save" ) {
-		#if flash
-		throw "TODO";
-		#elseif sys
+		#if sys
 		try sys.FileSystem.deleteFile(name+".sav") catch( e : Dynamic ) {}
 		#elseif js
 		try js.Browser.window.localStorage.removeItem(name) catch( e : Dynamic ) {}
@@ -124,20 +97,10 @@ class Save {
 		@param checkSum When set, save data is prepended by salted crc checksum for data validation. When save is loaded, `checkSum` flag should be set accordingly.
 	**/
 	public static function save( val : Dynamic, ?name = "save", checkSum = false ) {
-		#if flash
-		var data = saveData(val, checkSum);
-		if( data == cur.get(name) )
-			return false;
-		cur.set(name, data);
-		getObj(name).setProperty("data", data);
-		try saveObj.flush() catch( e : Dynamic ) throw "Can't write save (disk full ?)";
-		return true;
-		#else
 		var data = saveData(val,checkSum);
 		try if( readSaveData(name) == data ) return false catch( e : Dynamic ) {};
 		writeSaveData(name, data);
 		return true;
-		#end
 	}
 
 }

+ 0 - 183
hxd/System.flash.hx

@@ -1,183 +0,0 @@
-package hxd;
-
-enum Platform {
-	IOS;
-	Android;
-	WebGL;
-	PC;
-	Console;
-	FlashPlayer;
-}
-
-enum SystemValue {
-	IsTouch;
-	IsWindowed;
-	IsMobile;
-}
-
-class System {
-
-	public static var width(get,never) : Int;
-	public static var height(get, never) : Int;
-	public static var lang(get, never) : String;
-	public static var platform(get, never) : Platform;
-	public static var screenDPI(get,never) : Float;
-	public static var setCursor = setNativeCursor;
-	public static var allowTimeout(get, set) : Bool;
-
-	public static function timeoutTick() : Void {
-	}
-
-	static var loopFunc : Void -> Void;
-
-	// FLASH
-	static var hasLoop : Bool;
-
-	public static function getCurrentLoop() : Void -> Void {
-		return loopFunc;
-	}
-
-	public static function setLoop( f : Void -> Void ) : Void {
-		loopFunc = f;
-		if( hasLoop ) {
-			hasLoop = false;
-			flash.Lib.current.removeEventListener(flash.events.Event.ENTER_FRAME, onLoop);
-		}
-		if( f != null ) {
-			hasLoop = true;
-			flash.Lib.current.addEventListener(flash.events.Event.ENTER_FRAME, onLoop);
-		}
-	}
-
-	static function onLoop(_) {
-		loopFunc();
-		var e = h3d.Engine.getCurrent();
-		if( e != null ) e.driver.present();
-	}
-
-	public static function start( callb : Void -> Void ) : Void {
-		callb();
-	}
-
-	public static function setNativeCursor( c : Cursor ) : Void {
-		flash.ui.Mouse.cursor = switch( c ) {
-		case Default: "auto";
-		case Button: "button";
-		case Move: "hand";
-		case TextInput: "ibeam";
-		case Hide: "auto";
-		case Custom(cursor):
-			if( cursor.alloc == null ) {
-				var c = new flash.ui.MouseCursorData();
-				var v = new flash.Vector();
-				for( f in cursor.frames ) v.push(f.toNative());
-				c.data = v;
-				c.frameRate = cursor.speed;
-				c.hotSpot = new flash.geom.Point(cursor.offsetX, cursor.offsetY);
-				cursor.alloc = c;
-				flash.ui.Mouse.registerCursor(cursor.name, cursor.alloc);
-			}
-			cursor.name;
-		case Callback(_): throw "assert";
-		}
-		if( c == Hide ) flash.ui.Mouse.hide() else flash.ui.Mouse.show();
-	}
-
-	static var CACHED_NAME = null;
-	public static function getDeviceName() : String {
-		if( CACHED_NAME != null )
-			return CACHED_NAME;
-		var name;
-		switch( platform ) {
-		case Android if( isAir() ):
-			try {
-				var f : Dynamic = Type.createInstance(flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.filesystem.File"), ["/system/build.prop"]);
-				var fs : flash.utils.IDataInput = Type.createInstance(flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.filesystem.FileStream"), []);
-				Reflect.callMethod(fs, Reflect.field(fs, "open"), [f, "read"]);
-				var content = fs.readUTFBytes(fs.bytesAvailable);
-				name = StringTools.trim(content.split("ro.product.model=")[1].split("\n")[0]);
-			} catch( e : Dynamic ) {
-				name = "Android";
-			}
-		case IOS:
-			name = switch( [width, height, screenDPI] ) {
-			case [960, 640, 326]: "iPhone4";
-			case [1136, 640, 326]: "iPhone5";
-			case [1334, 750, 326]: "iPhone6";
-			case [1920, 1080, 401]: "iPhone6+";
-			case [2048, 1536, 264]: "iPad"; // 3/4/Air
-			case [2048, 1536, 326]: "iPadMini2";
-			case [1024, 768, 163]: "iPadMini";
-			case [w, h, dpi]: "IOS Unknown " + w + "x" + h + "@" + dpi;
-			}
-		default:
-			name = "PC";
-		}
-		return name;
-	}
-
-	public static function getDefaultFrameRate() : Float {
-		return flash.Lib.current.stage.frameRate;
-	}
-
-	public static function getValue( s : SystemValue ) : Bool {
-		switch( s ) {
-		case IsWindowed:
-			var p = flash.system.Capabilities.playerType;
-			return p == "ActiveX" || p == "PlugIn" || p == "StandAlone" || p == "Desktop";
-		case IsMobile:
-			return platform == IOS || platform == Android;
-		case IsTouch:
-			return flash.system.Capabilities.touchscreenType == flash.system.TouchscreenType.FINGER;
-		}
-	}
-
-	public static function exit() : Void {
-		if( isAir() ) {
-			var d : Dynamic = flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.desktop.NativeApplication");
-			Reflect.field(Reflect.field(d,"nativeApplication"),"exit")();
-		} else
-			flash.system.System.exit(0);
-	}
-
-	public static function openURL( url : String ) : Void {
-		throw 'Not implemented';
-	}
-
-	// getters
-
-	static function get_width() {
-		var Cap = flash.system.Capabilities;
-		return getValue(IsWindowed) ? flash.Lib.current.stage.stageWidth : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionX : Cap.screenResolutionY);
-	}
-
-	static function get_height() {
-		var Cap = flash.system.Capabilities;
-		return getValue(IsWindowed) ? flash.Lib.current.stage.stageHeight : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionY : Cap.screenResolutionX);
-	}
-
-	static function get_lang() : String {
-		return flash.system.Capabilities.language;
-	}
-
-	static function get_platform() : Platform {
-		if( flash.system.Capabilities.manufacturer.indexOf('Android') != -1 )
-			return Android;
-		if( flash.system.Capabilities.manufacturer.indexOf('iOS') != -1 )
-			return IOS;
-		return FlashPlayer;
-	}
-
-	static function isAir() : Bool {
-		return flash.system.Capabilities.playerType == "Desktop";
-	}
-
-	static function get_screenDPI() : Int {
-		return Std.int(flash.system.Capabilities.screenDPI);
-	}
-
-	static function get_allowTimeout() return true;
-	static function set_allowTimeout(b) return true; // can't be disabled
-
-}
-

+ 0 - 333
hxd/Window.flash.hx

@@ -1,333 +0,0 @@
-package hxd;
-
-enum DisplayMode {
-	Windowed;
-	Borderless;
-	Fullscreen;
-	FullscreenResize;
-}
-
-class Window {
-
-	var resizeEvents : List<Void -> Void>;
-	var eventTargets : List<Event -> Void>;
-
-	public var width(get, never) : Int;
-	public var height(get, never) : Int;
-	public var mouseX(get, never) : Int;
-	public var mouseY(get, never) : Int;
-	public var mouseLock(get, set) : Bool;
-	public var vsync(get, set) : Bool;
-	public var isFocused(get, never) : Bool;
-
-	public var title(get, set) : String;
-	@:isVar
-	public var displayMode(get, set) : DisplayMode;
-
-	// FLASH
-	var stage : flash.display.Stage;
-	var fsDelayed : Bool;
-
-	function new() : Void {
-		eventTargets = new List();
-		resizeEvents = new List();
-
-		stage = flash.Lib.current.stage;
-		stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
-		stage.addEventListener(flash.events.Event.RESIZE, onResize);
-		initGesture(false);
-		if( isAir() )
-			setupOnCloseEvent();
-	}
-
-	inline function isAir() {
-		return @:privateAccess hxd.System.isAir();
-	}
-
-	function initGesture(b) {
-		if( hxd.System.getValue(IsMobile) ) {
-			if( b )  {
-				flash.ui.Multitouch.inputMode = flash.ui.MultitouchInputMode.GESTURE;
-				stage.removeEventListener(flash.events.TouchEvent.TOUCH_BEGIN, onTouchDown);
-				stage.removeEventListener(flash.events.TouchEvent.TOUCH_MOVE, onTouchMove);
-				stage.removeEventListener(flash.events.TouchEvent.TOUCH_END, onTouchUp);
-				stage.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, onMouseDown);
-				stage.addEventListener(flash.events.MouseEvent.MOUSE_MOVE, onMouseMove);
-				stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, onMouseUp);
-			} else {
-				flash.ui.Multitouch.inputMode = flash.ui.MultitouchInputMode.TOUCH_POINT;
-				stage.addEventListener(flash.events.TouchEvent.TOUCH_BEGIN, onTouchDown);
-				stage.addEventListener(flash.events.TouchEvent.TOUCH_MOVE, onTouchMove);
-				stage.addEventListener(flash.events.TouchEvent.TOUCH_END, onTouchUp);
-				stage.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, onMouseDown);
-				stage.removeEventListener(flash.events.MouseEvent.MOUSE_MOVE, onMouseMove);
-				stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, onMouseUp);
-			}
-		} else {
-			stage.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, onMouseDown);
-			stage.addEventListener(flash.events.MouseEvent.MOUSE_MOVE, onMouseMove);
-			stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, onMouseUp);
-			stage.addEventListener(flash.events.MouseEvent.MOUSE_WHEEL, onMouseWheel);
-			stage.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, onKeyDown);
-			stage.addEventListener(flash.events.KeyboardEvent.KEY_UP, onKeyUp);
-			stage.addEventListener(flash.events.MouseEvent.RIGHT_MOUSE_DOWN, onRMouseDown);
-			stage.addEventListener(flash.events.MouseEvent.RIGHT_MOUSE_UP, onRMouseUp);
-		}
-	}
-
-	public dynamic function onClose() : Bool {
-		return true;
-	}
-
-	public function event( e : hxd.Event ) : Void {
-		for( et in eventTargets )
-			et(e);
-	}
-
-	public function addEventTarget( et : Event->Void ) : Void {
-		eventTargets.add(et);
-	}
-
-	public function removeEventTarget( et : Event->Void ) : Void {
-		for( e in eventTargets )
-			if( Reflect.compareMethods(e,et) ) {
-				eventTargets.remove(e);
-				break;
-			}
-	}
-
-	public function addResizeEvent( f : Void -> Void ) : Void {
-		resizeEvents.push(f);
-	}
-
-	public function removeResizeEvent( f : Void -> Void ) : Void {
-		for( e in resizeEvents )
-			if( Reflect.compareMethods(e,f) ) {
-				resizeEvents.remove(f);
-				break;
-			}
-	}
-
-	function onResize(e:Dynamic) : Void {
-		for( r in resizeEvents )
-			r();
-	}
-
-	public function resize( width : Int, height : Int ) : Void {
-	}
-
-
-	@:deprecated("Use the displayMode property instead")
-	public function setFullScreen( v : Bool ) : Void {
-		this.displayMode = v ? Borderless : Windowed;
-	}
-
-	static var inst : Window = null;
-	public static function getInstance() : Window {
-		if( inst == null ) inst = new Window();
-		return inst;
-	}
-
-	function setupOnCloseEvent() {
-		var nw : flash.events.EventDispatcher = Reflect.field(stage, "nativeWindow");
-		if( nw == null ) return;
-		nw.addEventListener("closing", function(e:flash.events.Event) {
-			if( !onClose() )
-				e.preventDefault();
-		});
-	}
-
-	#if !air3 static inline #end
-	var multipleWindowsSupport = false;
-	var lastX : Float = -1.;
-	var lastY : Float = -1.;
-
-	inline function get_mouseX() {
-		return Std.int( multipleWindowsSupport ? lastX : stage.mouseX );
-	}
-
-	inline function get_mouseY() {
-		return Std.int( multipleWindowsSupport ? lastY : stage.mouseY );
-	}
-
-	inline function get_width() {
-		return stage.stageWidth;
-	}
-
-	inline function get_height() {
-		return stage.stageHeight;
-	}
-
-	inline function get_mouseLock() {
-		return stage.mouseLock;
-	}
-
-	inline function set_mouseLock(v) {
-		return stage.mouseLock = v;
-	}
-
-	function get_vsync() : Bool return true;
-
-	function set_vsync( b : Bool ) : Bool {
-		if( !b ) throw "Can't disable vsync on this platform";
-		return true;
-	}
-
-	function onMouseDown(e:Dynamic) {
-		event(new Event(EPush, mouseX, mouseY));
-	}
-
-	function onRMouseDown(e:Dynamic) {
-		var e = new Event(EPush, mouseX, mouseY);
-		e.button = 1;
-		event(e);
-	}
-
-	function onMouseUp(e:Dynamic) {
-		event(new Event(ERelease, mouseX, mouseY));
-	}
-
-	function onRMouseUp(e:Dynamic) {
-		var e = new Event(ERelease, mouseX, mouseY);
-		e.button = 1;
-		event(e);
-	}
-
-	function onMouseMove(e:flash.events.MouseEvent) {
-		if( multipleWindowsSupport ) {
-			lastX = e.stageX;
-			lastY = e.stageY;
-		}
-		event(new Event(EMove, mouseX, mouseY));
-	}
-
-	function onMouseWheel(e:flash.events.MouseEvent) {
-		var ev = new Event(EWheel, mouseX, mouseY);
-		ev.wheelDelta = -e.delta / 3.0;
-		event(ev);
-	}
-
-	function onKeyUp(e:flash.events.KeyboardEvent) {
-		var ev = new Event(EKeyUp, mouseX, mouseY);
-		ev.keyCode = e.keyCode;
-		event(ev);
-	}
-
-	function onKeyDown(e:flash.events.KeyboardEvent) {
-		var ev = new Event(EKeyDown, mouseX, mouseY);
-		ev.keyCode = e.keyCode;
-		event(ev);
-
-		var charCode = getCharCode(e);
-		if( charCode != 0 ) {
-			var ev = new Event(ETextInput, mouseX, mouseY);
-			ev.charCode = charCode;
-			event(ev);
-		}
-
-		// prevent escaping fullscreen in air
-		if( e.keyCode == flash.ui.Keyboard.ESCAPE ) e.preventDefault();
-		if( e.keyCode == "S".code && e.ctrlKey ) e.preventDefault();
-		// prevent ALT menu (sadly DONT WORK)
-		if( e.keyCode == 18 ) {
-			e.preventDefault();
-			e.stopImmediatePropagation();
-			e.stopPropagation();
-		}
-		// prevent back exiting app in mobile
-		if( e.keyCode == flash.ui.Keyboard.BACK ) {
-			e.preventDefault();
-			e.stopImmediatePropagation();
-		}
-	}
-
-	function getCharCode( e : flash.events.KeyboardEvent ) {
-		// disable some invalid charcodes
-		if( e.keyCode == 27 ) e.charCode = 0;
-		// Flash charCode are not valid, they assume an english keyboard. Let's do some manual translation here (to complete with command keyboards)
-		switch( flash.system.Capabilities.language ) {
-		case "fr":
-			return switch( e.keyCode ) {
-			case 49: if( e.altKey ) 0 else if( e.shiftKey ) '1'.code else e.charCode;
-			case 50: if( e.altKey ) '~'.code else if( e.shiftKey ) '2'.code else e.charCode;
-			case 51: if( e.altKey ) '#'.code else if( e.shiftKey ) '3'.code else e.charCode;
-			case 52: if( e.altKey ) '{'.code else if( e.shiftKey ) '4'.code else e.charCode;
-			case 53: if( e.altKey ) '['.code else if( e.shiftKey ) '5'.code else e.charCode;
-			case 54: if( e.altKey ) '|'.code else if( e.shiftKey ) '6'.code else e.charCode;
-			case 55: if( e.altKey ) '`'.code else if( e.shiftKey ) '7'.code else e.charCode;
-			case 56: if( e.altKey ) '\\'.code else if( e.shiftKey ) '8'.code else e.charCode;
-			case 57: if( e.altKey ) '^'.code else if( e.shiftKey ) '9'.code else e.charCode;
-			case 48: if( e.altKey ) '@'.code else if( e.shiftKey ) '0'.code else e.charCode;
-			case 219: if( e.altKey ) ']'.code else if( e.shiftKey ) '°'.code else e.charCode;
-			case 187: if( e.altKey ) '}'.code else if( e.shiftKey ) '+'.code else e.charCode;
-			case 188: if( e.altKey ) 0 else if( e.shiftKey ) '?'.code else e.charCode;
-			case 190: if( e.altKey ) 0 else if( e.shiftKey ) '.'.code else e.charCode;
-			case 191: if( e.altKey ) 0 else if( e.shiftKey ) '/'.code else e.charCode;
-			case 223: if( e.altKey ) 0 else if( e.shiftKey ) '§'.code else e.charCode;
-			case 192: if( e.altKey ) 0 else if( e.shiftKey ) '%'.code else e.charCode;
-			case 220: if( e.altKey ) 0 else if( e.shiftKey ) 'µ'.code else e.charCode;
-			case 221: if( e.altKey ) 0 else if( e.shiftKey ) '¨'.code else '^'.code;
-			case 186: if( e.altKey ) '¤'.code else if( e.shiftKey ) '£'.code else e.charCode;
-			default:
-				e.charCode;
-			}
-		default:
-			return e.charCode;
-		}
-	}
-
-	function onTouchDown(e:flash.events.TouchEvent) {
-		var ev = new Event(EPush, e.localX, e.localY);
-		ev.touchId = e.touchPointID;
-		event(ev);
-	}
-
-	function onTouchUp(e:flash.events.TouchEvent) {
-		var ev = new Event(ERelease, e.localX, e.localY);
-		ev.touchId = e.touchPointID;
-		event(ev);
-	}
-
-	function onTouchMove(e:flash.events.TouchEvent) {
-		var ev = new Event(EMove, e.localX, e.localY);
-		ev.touchId = e.touchPointID;
-		event(ev);
-	}
-
-	function get_isFocused() : Bool return false;
-
-	function get_displayMode() : DisplayMode {
-		if (stage.displayState == flash.display.StageDisplayState.NORMAL) {
-			return Windowed;
-		}
-
-		return Borderless;
-	}
-
-	function set_displayMode( m : DisplayMode ) : DisplayMode {
-		var fullscreen = m != Windowed;
-		var isAir = isAir();
-		var state = fullscreen ? (isAir ? flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE : flash.display.StageDisplayState.FULL_SCREEN) : flash.display.StageDisplayState.NORMAL;
-		if( stage.displayState != state ) {
-			var t = flash.Lib.getTimer();
-			// delay first fullsrceen toggle on OSX/Air to prevent the command window to spawn over
-			if( fullscreen && isAir && t < 5000 && !fsDelayed && flash.system.Capabilities.os.indexOf("Mac") != -1 ) {
-				fsDelayed = true;
-				haxe.Timer.delay(function() { this.displayMode = m; }, 1000);
-				return m;
-			}
-			stage.displayState = state;
-		}
-
-		return m;
-	}
-
-	function get_title() : String {
-		return "";
-	}
-
-	function set_title( t : String ) : String {
-		return t;
-	}
-}
-

+ 0 - 139
hxd/Worker.hx

@@ -1,139 +0,0 @@
-package hxd;
-
-class Worker<T:EnumValue> {
-
-	#if flash
-	public static var ENABLE = flash.system.Worker.isSupported;
-	var sendChan : flash.system.MessageChannel;
-	var recvChan : flash.system.MessageChannel;
-	var curMessage : { code : Int, count : Int, args : Array<Dynamic> };
-	var queue : Array<Dynamic>;
-	#else
-	public static var ENABLE = false;
-	#end
-	var enumValue : Enum<T>;
-	var isWorker : Bool;
-	var debugPeer : Worker<T>;
-	var useWorker : Bool;
-
-	public function new( e : Enum<T> ) {
-		this.enumValue = e;
-		this.useWorker = ENABLE;
-	}
-
-	function clone() : Worker<T> {
-		throw "Not implemented";
-		return null;
-	}
-
-	public function send( msg : T ) {
-		if( !useWorker ) {
-			#if debug
-			// emulate delay
-			haxe.Timer.delay(debugPeer.handleMessage.bind(msg), 1);
-			#else
-			debugPeer.handleMessage(msg);
-			#end
-			return;
-		}
-		#if flash
-		inline function sendRaw( v : Dynamic ) {
-			if( queue != null )
-				queue.push(v);
-			else
-				sendChan.send(v);
-		}
-		var args = Type.enumParameters(msg);
-		sendRaw( { code : Type.enumIndex(msg), count : args.length } );
-		// send args as separate messages or else bytearrays will get copied
-		for( a in args )
-			sendRaw(a);
-		#else
-		throw "TODO";
-		#end
-	}
-
-	function readMessage() : T {
-		#if flash
-		if( curMessage == null ) {
-			curMessage = recvChan.receive();
-			curMessage.args = [];
-			if( curMessage.count > 0 )
-				return null;
-		} else {
-			curMessage.args.push(recvChan.receive());
-			if( --curMessage.count > 0 )
-				return null;
-		}
-		var m = Type.createEnumIndex(enumValue, curMessage.code, curMessage.args);
-		curMessage = null;
-		return m;
-		#else
-		throw "TODO";
-		#end
-	}
-
-	function handleMessage( msg : T ) {
-		throw "TODO";
-	}
-
-	function setupMain() {
-	}
-
-	function setupWorker() {
-	}
-
-	public function start() {
-		if( !useWorker ) {
-			isWorker = false;
-			setupMain();
-			debugPeer = clone();
-			debugPeer.isWorker = true;
-			debugPeer.setupWorker();
-			debugPeer.debugPeer = this;
-			return false;
-		}
-		#if flash
-		var cur = flash.system.Worker.current;
-		if( cur.isPrimordial ) {
-			var wait = true;
-			var bgWorker = flash.system.WorkerDomain.current.createWorker(flash.Lib.current.loaderInfo.bytes, true);
-			sendChan = cur.createMessageChannel(bgWorker);
-			recvChan = bgWorker.createMessageChannel(cur);
-			recvChan.addEventListener(flash.events.Event.CHANNEL_MESSAGE, function(_) {
-				if( queue != null ) {
-					recvChan.receive(true); // ignore
-					for( m in queue )
-						sendChan.send(m);
-					queue = null;
-					return;
-				}
-				var msg = readMessage();
-				if( msg != null ) handleMessage(msg);
-			});
-			bgWorker.setSharedProperty("send", sendChan);
-			bgWorker.setSharedProperty("recv", recvChan);
-			isWorker = false;
-			queue = [];
-			setupMain();
-			bgWorker.start();
-			return false;
-		} else {
-			// inverse
-			sendChan = cur.getSharedProperty("recv");
-			recvChan = cur.getSharedProperty("send");
-			recvChan.addEventListener(flash.events.Event.CHANNEL_MESSAGE, function(e) {
-				var msg = readMessage();
-				if( msg != null ) handleMessage(msg);
-			});
-			isWorker = true;
-			sendChan.send(0);
-			setupWorker();
-			return true;
-		}
-		#else
-		throw "Native worker not supported for this platform";
-		#end
-	}
-
-}

+ 1 - 1
hxd/fmt/hmd/Writer.hx

@@ -40,7 +40,7 @@ class Writer {
 			out.writeByte(0xFF);
 			return;
 		}
-		#if (flash || js)
+		#if js
 		out.writeByte(haxe.io.Bytes.ofString(name).length);
 		#else
 		out.writeByte(name.length);

+ 2 - 31
hxd/fmt/pak/FileSystem.hx

@@ -1,8 +1,6 @@
 package hxd.fmt.pak;
 import hxd.fs.FileEntry;
-#if air3
-import hxd.impl.Air3File;
-#elseif (sys || nodejs)
+#if (sys || nodejs)
 import sys.io.File;
 import sys.io.FileInput;
 typedef FileSeekMode = sys.io.FileSeek;
@@ -132,33 +130,6 @@ private class PakEntry extends FileEntry {
 		return new hxd.impl.ArrayIterator<FileEntry>(cast subs);
 	}
 
-	override function loadBitmap( onLoaded ) {
-		#if flash
-		if( openedBytes != null ) throw "Must close() before loadBitmap";
-		open();
-		var old = openedBytes;
-		var loader = new flash.display.Loader();
-		loader.contentLoaderInfo.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) {
-			throw Std.string(e) + " while loading " + path;
-		});
-		loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, function(_) {
-			if( openedBytes == null ) {
-				openedBytes = old;
-				close();
-			}
-			var content : flash.display.Bitmap = cast loader.content;
-			onLoaded(new hxd.fs.LoadedBitmap(content.bitmapData));
-			loader.unload();
-		});
-		var ctx = new flash.system.LoaderContext();
-		ctx.imageDecodingPolicy = ON_LOAD;
-		loader.loadBytes(openedBytes.getData(), ctx);
-		openedBytes = null;
-		#else
-		super.loadBitmap(onLoaded);
-		#end
-	}
-
 }
 
 class FileSystem implements hxd.fs.FileSystem {
@@ -248,7 +219,7 @@ class FileSystem implements hxd.fs.FileSystem {
 		var id = getThreadID();
 		var input = f.inputs[id];
 		if( input == null ) {
-			#if (air3 || sys || nodejs)
+			#if (sys || nodejs)
 			input = File.read(f.path);
 			#else
 			throw "File.read not implemented";

+ 1 - 12
hxd/fs/BytesFileSystem.hx

@@ -34,18 +34,7 @@ class BytesFileEntry extends FileEntry {
 	}
 
 	override function loadBitmap( onLoaded : LoadedBitmap -> Void ) : Void {
-		#if flash
-		var loader = new flash.display.Loader();
-		loader.contentLoaderInfo.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) {
-			throw Std.string(e) + " while loading " + fullPath;
-		});
-		loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, function(_) {
-			var content : flash.display.Bitmap = cast loader.content;
-			onLoaded(new hxd.fs.LoadedBitmap(content.bitmapData));
-			loader.unload();
-		});
-		loader.loadBytes(bytes.getData());
-		#elseif js
+		#if js
 		var mime = switch fullPath.extension().toLowerCase() {
 			case 'jpg' | 'jpeg': 'image/jpeg';
 			case 'png': 'image/png';

+ 1 - 3
hxd/fs/Convert.hx

@@ -44,9 +44,7 @@ class Convert {
 	}
 
 	function command( cmd : String, args : Array<String> ) {
-		#if flash
-		trace("TODO");
-		#elseif (sys || nodejs)
+		#if (sys || nodejs)
 		var code = Sys.command(cmd, args);
 		if( code != 0 )
 			throw "Command '" + cmd + (args.length == 0 ? "" : " " + args.join(" ")) + "' failed with exit code " + code;

+ 3 - 62
hxd/fs/EmbedFileSystem.hx

@@ -8,13 +8,8 @@ private class EmbedEntry extends FileEntry {
 
 	var fs : EmbedFileSystem;
 	var relPath : String;
-	#if flash
-	var data : Class<flash.utils.ByteArray>;
-	var bytes : flash.utils.ByteArray;
-	#else
 	var data : String;
 	var bytes : haxe.io.Bytes;
-	#end
 
 	function new(fs, name, relPath, data) {
 		this.fs = fs;
@@ -24,30 +19,16 @@ private class EmbedEntry extends FileEntry {
 	}
 
 	function init() {
-		#if flash
-		if( bytes == null )
-			bytes = Type.createInstance(data, []);
-		bytes.position = 0;
-		#else
 		if( bytes == null ) {
 			bytes = haxe.Resource.getBytes(data);
 			if( bytes == null ) throw "Missing resource " + data;
 		}
-		#end
 	}
 
 	override function getBytes() : haxe.io.Bytes {
-		#if flash
-		if( data == null )
-			return null;
-		if( bytes == null )
-			init();
-		return haxe.io.Bytes.ofData(bytes);
-		#else
 		if( bytes == null )
 			init();
 		return bytes;
-		#end
 	}
 
 	override function readBytes( out : haxe.io.Bytes, outPos : Int, pos : Int, len : Int ) : Int {
@@ -61,26 +42,13 @@ private class EmbedEntry extends FileEntry {
 	}
 
 	override function load( ?onReady : Void -> Void ) : Void {
-		#if (flash || js)
+		#if js
 		if( onReady != null ) haxe.Timer.delay(onReady, 1);
 		#end
 	}
 
 	override function loadBitmap( onLoaded : LoadedBitmap -> Void ) : Void {
-		#if flash
-		var loader = new flash.display.Loader();
-		loader.contentLoaderInfo.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) {
-			throw Std.string(e) + " while loading " + relPath;
-		});
-		loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, function(_) {
-			var content : flash.display.Bitmap = cast loader.content;
-			onLoaded(new LoadedBitmap(content.bitmapData));
-			loader.unload();
-		});
-		init();
-		loader.loadBytes(bytes);
-		close(); // flash will copy bytes content in loadBytes() !
-		#elseif js
+		#if js
 		// directly get the base64 encoded data from resources
 		var rawData = null;
 		for( res in @:privateAccess haxe.Resource.content )
@@ -120,13 +88,8 @@ private class EmbedEntry extends FileEntry {
 	}
 
 	override function get_size() {
-		#if flash
-		init();
-		return bytes.length;
-		#else
 		init();
 		return bytes.length;
-		#end
 	}
 
 	override function iterator() {
@@ -153,26 +116,9 @@ class EmbedFileSystem #if !macro implements FileSystem #end {
 
 	static var invalidChars = ~/[^A-Za-z0-9_]/g;
 	static function resolve( path : String ) {
-		#if flash
-		return "_R_" + invalidChars.replace(path, "_");
-		#else
 		return "R_" + invalidChars.replace(path, "_");
-		#end
 	}
 
-	#if flash
-	function open( path : String ) : Class<flash.utils.ByteArray> {
-		var name = resolve(path);
-		var cl = null;
-		try {
-			cl = flash.system.ApplicationDomain.currentDomain.getDefinition(name);
-		} catch( e : Dynamic ) {
-		}
-		return cl;
-	}
-
-	#end
-
 	function splitPath( path : String ) {
 		return path == "." ? [] : path.split("/");
 	}
@@ -196,23 +142,18 @@ class EmbedFileSystem #if !macro implements FileSystem #end {
 	}
 
 	public function exists( path : String ) {
-		#if flash
-		var f = open(path);
-		return f != null || isDirectory(path);
-		#else
 		var r = root;
 		for( p in splitPath(path) ) {
 			r = Reflect.field(r, p);
 			if( r == null ) return false;
 		}
 		return true;
-		#end
 	}
 
 	public function get( path : String ) {
 		if( !exists(path) )
 			throw new NotFound(path);
-		var id = #if flash open(path) #else resolve(path) #end;
+		var id = resolve(path);
 		return new EmbedEntry(this, path.split("/").pop(), path, id);
 	}
 

+ 2 - 6
hxd/fs/LoadedBitmap.hx

@@ -1,8 +1,6 @@
 package hxd.fs;
 
-#if flash
-typedef LoadedBitmapData = flash.display.BitmapData;
-#elseif js
+#if js
 typedef LoadedBitmapData = js.html.Image;
 #else
 typedef LoadedBitmapData = hxd.BitmapData;
@@ -15,9 +13,7 @@ abstract LoadedBitmap(LoadedBitmapData) {
 	}
 
 	public function toBitmap() : hxd.BitmapData {
-		#if flash
-		return hxd.BitmapData.fromNative(this);
-		#elseif js
+		#if js
 		var bmp = new hxd.BitmapData(this.width, this.height);
 		@:privateAccess bmp.ctx.drawImage(this, 0, 0);
 		return bmp;

+ 0 - 4
hxd/fs/LocalFileSystem.hx

@@ -352,10 +352,6 @@ class LocalFileSystem implements FileSystem {
 	public var baseDir(default,null) : String;
 
 	public function new( dir : String ) {
-		#if flash
-		if( flash.system.Capabilities.playerType == "Desktop" )
-			throw "Please compile with -lib air3";
-		#end
 		throw "Local file system is not supported for this platform";
 	}
 

+ 0 - 95
hxd/impl/Air3File.hx

@@ -1,95 +0,0 @@
-package hxd.impl;
-
-enum FileSeek {
-	SeekBegin;
-	SeekCur;
-	SeekEnd;
-}
-
-#if air3
-
-typedef File = Air3File;
-
-class FileInput extends haxe.io.Input {
-
-	var fs : flash.filesystem.FileStream;
-	var avail : Int;
-	var maxSize : Int;
-
-	public function new(file) {
-		fs = new flash.filesystem.FileStream();
-		fs.open(file, flash.filesystem.FileMode.READ);
-		maxSize = avail = fs.bytesAvailable;
-	}
-
-	override function close() {
-		if( fs != null ) {
-			fs.close();
-			fs = null;
-		}
-	}
-
-	public function seek( p : Int, pos : FileSeek ) {
-		switch( pos ) {
-		case SeekBegin:
-			if( p < 0 ) p = 0;
-			if( p > maxSize ) p = maxSize;
-			fs.position = p;
-			avail = maxSize;
-		case SeekCur:
-			if( p < 0 && p < -fs.position ) p = -Std.int(fs.position) else if( p > avail ) p = avail;
-			fs.position += p;
-			avail -= p;
-		case SeekEnd:
-			if( p > maxSize ) p = maxSize;
-			fs.position = maxSize - p;
-			avail = p;
-		}
-	}
-
-	public function tell() : Int {
-		return Std.int(fs.position);
-	}
-
-	public function eof() {
-		return avail <= 0;
-	}
-
-	override function readByte() {
-		if( avail <= 0 ) throw new haxe.io.Eof();
-		var b = fs.readUnsignedByte();
-		avail--;
-		return b;
-	}
-
-	override function readBytes( bytes : haxe.io.Bytes, pos : Int, len : Int ) : Int {
-		if( len > avail ) len = avail;
-		if( len > 0 ) fs.readBytes(bytes.getData(), pos, len);
-		avail -= len;
-		return len;
-	}
-}
-
-class Air3File {
-
-	static function getRelPath( path : String ) {
-		try {
-			return new flash.filesystem.File(path);
-		}  catch( e : Dynamic ) {
-			var app = flash.filesystem.File.applicationDirectory;
-			var dir = app.nativePath;
-			if( dir == "" )
-				return app.resolvePath(path);
-			return new flash.filesystem.File(dir + "/" + path);
-		}
-	}
-
-	public static function read( path : String, binary = true ) {
-		if( !binary ) throw "text mode not supported";
-		var f = getRelPath(path);
-		if( !f.exists ) throw path + " does not exists";
-		return new FileInput(f);
-	}
-
-}
-#end

+ 1 - 13
hxd/net/BinaryLoader.hx

@@ -3,9 +3,6 @@ package hxd.net;
 class BinaryLoader {
 
 	public var url(default, null) : String;
-	#if flash
-	var loader : flash.net.URLLoader;
-	#end
 
 	public function new( url : String ) {
 		this.url = url;
@@ -22,16 +19,7 @@ class BinaryLoader {
 	}
 
 	public function load() {
-		#if flash
-
-		loader = new flash.net.URLLoader();
-		loader.dataFormat = flash.net.URLLoaderDataFormat.BINARY;
-		loader.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) onError(e.text));
-		loader.addEventListener(flash.events.Event.COMPLETE, function(_) onLoaded(haxe.io.Bytes.ofData(loader.data)));
-		loader.addEventListener(flash.events.ProgressEvent.PROGRESS, function(e:flash.events.ProgressEvent) onProgress(Std.int(e.bytesLoaded), Std.int(e.bytesTotal)));
-		loader.load(new flash.net.URLRequest(url));
-
-		#elseif js
+		#if js
 
 		var xhr = new js.html.XMLHttpRequest();
 		xhr.open('GET', url, true);

+ 5 - 142
hxd/net/Socket.hx

@@ -33,16 +33,11 @@ private class SocketInput extends haxe.io.Input {
 class Socket {
 
 	static var openedSocks = [];
-	#if flash
-	var s : flash.net.Socket;
-	#elseif hl
+	#if hl
 	var s : #if (haxe_ver >= 4) hl.uv.Stream #else Dynamic #end;
 	#elseif (nodejs && hxnodejs)
 	var s : js.node.net.Socket;
 	#end
-	#if (flash && air3)
-	var serv : flash.net.ServerSocket;
-	#end
 	public var out(default, null) : SocketOutput;
 	public var input(default, null) : SocketInput;
 	public var timeout(default, set) : Null<Float>;
@@ -57,26 +52,13 @@ class Socket {
 	}
 
 	public function set_timeout(t:Null<Float>) {
-		#if flash
-		if( s != null ) s.timeout = t == null ? 0x7FFFFFFF : Math.ceil(t * 1000);
-		#end
 		return this.timeout = t;
 	}
 
 	public function connect( host : String, port : Int, onConnect : Void -> Void ) {
 		close();
 		openedSocks.push(this);
-		#if flash
-		s = new flash.net.Socket();
-		if( timeout != null ) this.timeout = timeout;
-		s.addEventListener(flash.events.Event.CONNECT, function(_) {
-			out = new FlashSocketOutput(s);
-			input = new FlashSocketInput(s);
-			onConnect();
-		});
-		bindEvents();
-		s.connect(host, port);
-		#elseif (hl && haxe_ver >= 4)
+		#if (hl && haxe_ver >= 4)
 		var tcp = new hl.uv.Tcp();
 		s = tcp;
 		tcp.connect(new sys.net.Host(host), port, function(b) {
@@ -94,45 +76,10 @@ class Socket {
 		#end
 	}
 
-	#if flash
-	function bindEvents() {
-		s.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) {
-			close();
-			onError(e.text);
-		});
-		s.addEventListener(flash.events.Event.CLOSE, function(_) {
-			close();
-			onError("Closed");
-		});
-		s.addEventListener(flash.events.ProgressEvent.SOCKET_DATA, function(e:flash.events.ProgressEvent) {
-			onData();
-		});
-	}
-	#end
-
-	public static inline var ALLOW_BIND = #if (flash && air3) true #else false #end;
-
 	public function bind( host : String, port : Int, onConnect : Socket -> Void, listenCount = 5 ) {
 		close();
 		openedSocks.push(this);
-		#if (flash && air3)
-		serv = new flash.net.ServerSocket();
-		try serv.bind(port, host) catch( e : Dynamic ) {
-			close();
-			throw e;
-		};
-		serv.listen(listenCount);
-		serv.addEventListener(flash.events.ServerSocketConnectEvent.CONNECT, function(e:flash.events.ServerSocketConnectEvent) {
-			var sock = e.socket;
-			var s = new Socket();
-			s.s = sock;
-			s.bindEvents();
-			s.out = new FlashSocketOutput(sock);
-			s.input = new FlashSocketInput(sock);
-			openedSocks.push(s);
-			onConnect(s);
-		});
-		#elseif (hl && haxe_ver >= 4)
+		#if (hl && haxe_ver >= 4)
 		var tcp = new hl.uv.Tcp();
 		s = tcp;
 		try {
@@ -169,13 +116,7 @@ class Socket {
 
 	public function close() {
 		openedSocks.remove(this);
-		#if (flash && air3)
-		if( serv != null ) {
-			try serv.close() catch( e : Dynamic ) { };
-			serv = null;
-		}
-		#end
-		#if (flash || hl)
+		#if hl
 		if( s != null ) {
 			try s.close() catch( e : Dynamic ) { };
 			out = new SocketOutput();
@@ -199,85 +140,7 @@ class Socket {
 
 }
 
-
-#if flash
-private class FlashSocketOutput extends SocketOutput {
-	var s : flash.net.Socket;
-	var autoFlush = true;
-
-	public function new(s) {
-		super();
-		this.s = s;
-		s.endian = flash.utils.Endian.LITTLE_ENDIAN;
-	}
-
-	inline function f() if( autoFlush ) s.flush();
-
-	override function wait() {
-		autoFlush = false;
-	}
-
-	override function flush() {
-		autoFlush = true;
-		s.flush();
-	}
-
-	override function writeByte( c : Int ) {
-		s.writeByte(c);
-		f();
-	}
-
-	override function writeBytes( b : haxe.io.Bytes, pos : Int, len : Int ) : Int {
-		if( len > 0 ) {
-			s.writeBytes(b.getData(), pos, len);
-			f();
-		}
-		return len;
-	}
-
-	override function writeInt32( i : Int ) {
-		s.writeInt(i);
-		f();
-	}
-
-	override function writeString( str : String #if (haxe_ver >= 4) , ?encoding :  haxe.io.Encoding #end ) {
-		s.writeUTFBytes(str);
-		f();
-	}
-
-}
-
-private class FlashSocketInput extends SocketInput {
-
-	var sock : flash.net.Socket;
-
-	public function new(s) {
-		sock = s;
-	}
-
-	override function get_available() {
-		return sock.bytesAvailable;
-	}
-
-	override function readBytes( bytes : haxe.io.Bytes, pos : Int, len : Int ) {
-		if( len > (sock.bytesAvailable : Int) ) {
-			len = sock.bytesAvailable;
-			if( len == 0 ) throw new haxe.io.Eof();
-		}
-		if( len > 0 )
-			sock.readBytes(bytes.getData(), pos, len);
-		return len;
-	}
-
-	override function readByte() {
-		if( sock.bytesAvailable == 0 )
-			throw new haxe.io.Eof();
-		return sock.readUnsignedByte();
-	}
-
-}
-
-#elseif hl
+#if hl
 
 class HLSocketOutput extends SocketOutput {
 

+ 0 - 42
hxd/poly2tri/VisiblePolygon.hx

@@ -66,46 +66,4 @@ class VisiblePolygon
 		return sweepContext.triangles.length;
 	}
 
-
-	#if flash
-	public function drawShape(g:flash.display.Graphics)
-	{
-		var t:Triangle;
-		var pl:Array<Point>;
-
-		performTriangulationOnce();
-
-		for (t in sweepContext.triangles)
-		{
-			pl = t.points;
-
-			g.beginFill( 0xefb83d, .9 );
-			g.moveTo(pl[0].x, pl[0].y);
-			g.lineTo(pl[1].x, pl[1].y);
-			g.lineTo(pl[2].x, pl[2].y);
-			g.lineTo(pl[0].x, pl[0].y);
-			g.endFill();
-		}
-
-		g.lineStyle(1, 0xd31205, 1);
-
-		for (t in sweepContext.triangles)
-		{
-			pl = t.points;
-
-			g.moveTo(pl[0].x, pl[0].y);
-			g.lineTo(pl[1].x, pl[1].y);
-			g.lineTo(pl[2].x, pl[2].y);
-			g.lineTo(pl[0].x, pl[0].y);
-		}
-
-		g.lineStyle(2, 0x945922, 2);
-
-		for (e in sweepContext.edge_list)
-		{
-			g.moveTo(e.p.x, e.p.y);
-			g.lineTo(e.q.x, e.q.y);
-		}
-	}
-	#end
 }

+ 2 - 4
hxd/res/Config.hx

@@ -1,7 +1,6 @@
 package hxd.res;
 
 enum Platform {
-	Flash;
 	HL;
 	JS;
 	Unknown;
@@ -69,9 +68,9 @@ class Config {
 	];
 
 	public static function addPairedExtension( main, shadow) {
-		if (pairedExtensions.exists(main)) 
+		if (pairedExtensions.exists(main))
 			pairedExtensions.set(main, pairedExtensions.get(main) + "," + shadow);
-		else 
+		else
 			pairedExtensions.set(main, shadow);
 	}
 
@@ -81,7 +80,6 @@ class Config {
 
 	static function init() {
 		var pf =
-			if( defined("flash") ) Flash else
 			if( defined("js") ) JS else
 			if( defined("hl") ) HL else
 			Unknown;

+ 2 - 21
hxd/res/Embed.hx

@@ -18,31 +18,12 @@ class Embed {
 		return null;
 	}
 
-	public static function doEmbedFont( name : String, file : String, chars : String ) {
+	public static function doEmbedFont( name : String, file : String, chars : String ) : haxe.macro.Expr {
 
 		var m = Context.getLocalClass().get().module;
 		Context.registerModuleDependency(m, file);
 
-		if( Context.defined("flash") ) {
-			if( chars == null ) // convert char list to char range
-				chars = Charset.DEFAULT_CHARS.split("-").join("\\-");
-			var pos = Context.currentPos();
-			haxe.macro.Context.defineType({
-				pack : ["hxd","_res"],
-				name : name,
-				meta : [
-					{ name : ":native", pos : pos, params : [macro $v { "_"+name } ] },
-					{ name : ":font", pos : pos, params : [macro $v { file }, macro $v { chars } ] },
-					{ name : ":keep", pos : pos, params : [] }
-				],
-				kind : TDClass({ pack : ["flash","text"], name : "Font", params : [] }),
-				params : [],
-				pos : pos,
-				isExtern : false,
-				fields : [],
-			});
-			return macro new hxd._res.$name().fontName;
-		} else if( Context.defined("js") ) {
+		if( Context.defined("js") ) {
 			// TODO : we might want to extract the chars from the TTF font
 			var pos = Context.currentPos();
 			var content = haxe.crypto.Base64.encode(sys.io.File.getBytes(Context.resolvePath(file)));

+ 1 - 17
hxd/res/FileTree.hx

@@ -161,26 +161,10 @@ class FileTree {
 			var fullPath = fs.getAbsolutePath(f);
 
 			switch( file.ext ) {
-			case "ttf" if( Config.platform == JS || Config.platform == Flash ):
+			case "ttf" if( Config.platform == JS ):
 				Embed.doEmbedFont(name, fullPath, options.fontsChars);
 				embedTypes.push("hxd._res." + name);
 				continue;
-			case _ if( Config.platform == Flash ):
-				Context.defineType( {
-					params : [],
-					pack : ["hxd","_res"],
-					name : name,
-					pos : pos,
-					isExtern : false,
-					fields : [],
-					meta : [
-						{ name : ":native", params : [{ expr : EConst(CString("_"+name)), pos : pos }], pos : pos },
-						{ name : ":keep", params : [], pos : pos },
-						{ name : ":file", params : [ { expr : EConst(CString(fullPath)), pos : pos } ], pos : pos },
-					],
-					kind : TDClass({ pack : ["flash","utils"], name : "ByteArray", params : [] }),
-				});
-				embedTypes.push("hxd._res." + name);
 			default:
 				Context.addResource(name, sys.io.File.getBytes(fullPath));
 			}

+ 1 - 6
hxd/res/Font.hx

@@ -8,12 +8,7 @@ package hxd.res;
 class Font extends Resource {
 
 	public function build( size : Int, ?options ) : h2d.Font {
-		#if flash
-		var fontClass : Class<flash.text.Font> = cast Type.resolveClass("_R_" + ~/[^A-Za-z0-9_]/g.replace(entry.path, "_"));
-		if( fontClass == null ) throw "Embeded font not found " + entry.path;
-		var font = Type.createInstance(fontClass, []);
-		return FontBuilder.getFont(font.fontName, size, options);
-		#elseif js
+		#if js
 		var name = "R_" + ~/[^A-Za-z0-9_]/g.replace(entry.path, "_");
 		return FontBuilder.getFont(name, size, options);
 		#else

+ 1 - 106
hxd/res/FontBuilder.hx

@@ -26,112 +26,7 @@ class FontBuilder {
 		if( options.chars == null ) options.chars = hxd.Charset.DEFAULT_CHARS;
 	}
 
-	#if flash
-
-	function build() : h2d.Font {
-		font.lineHeight = 0;
-		var tf = new flash.text.TextField();
-		var fmt = tf.defaultTextFormat;
-		fmt.font = font.name;
-		fmt.size = font.size;
-		fmt.color = 0xFFFFFF;
-		tf.defaultTextFormat = fmt;
-		for( f in flash.text.Font.enumerateFonts() )
-			if( f.fontName == font.name ) {
-				tf.embedFonts = true;
-				break;
-			}
-		if( options.antiAliasing ) {
-			tf.gridFitType = flash.text.GridFitType.PIXEL;
-			tf.antiAliasType = flash.text.AntiAliasType.ADVANCED;
-		}
-		var surf = 0;
-		var sizes = [];
-		for( i in 0...options.chars.length ) {
-			tf.text = options.chars.charAt(i);
-			var w = Math.ceil(tf.textWidth) + 1;
-			if( w == 1 ) continue;
-			var h = Math.ceil(tf.textHeight) + 1;
-			surf += (w + 1) * (h + 1);
-			if( h > font.lineHeight )
-				font.lineHeight = h;
-			sizes[i] = { w:w, h:h };
-		}
-		var side = Math.ceil( Math.sqrt(surf) );
-		var width = 1;
-		while( side > width )
-			width <<= 1;
-		var height = width;
-		while( width * height >> 1 > surf )
-			height >>= 1;
-		var all, bmp;
-		do {
-			bmp = new flash.display.BitmapData(width, height, true, 0);
-			bmp.lock();
-			font.glyphs = new Map();
-			all = [];
-			var m = new flash.geom.Matrix();
-			var x = 0, y = 0, lineH = 0;
-			for( i in 0...options.chars.length ) {
-				var size = sizes[i];
-				if( size == null ) continue;
-				var w = size.w;
-				var h = size.h;
-				if( x + w > width ) {
-					x = 0;
-					y += lineH + 1;
-				}
-				// no space, resize
-				if( y + h > height ) {
-					bmp.dispose();
-					bmp = null;
-					height <<= 1;
-					break;
-				}
-				m.tx = x - 2;
-				m.ty = y - 2;
-				tf.text = options.chars.charAt(i);
-				bmp.fillRect(new flash.geom.Rectangle(x, y, w, h), 0);
-				bmp.draw(tf, m);
-				var t = new h2d.Tile(innerTex, x, y, w - 1, h - 1);
-				all.push(t);
-				font.glyphs.set(options.chars.charCodeAt(i), new h2d.Font.FontChar(t,w-1));
-				// next element
-				if( h > lineH ) lineH = h;
-				x += w + 1;
-			}
-		} while( bmp == null );
-
-		var pixels = hxd.BitmapData.fromNative(bmp).getPixels();
-		bmp.dispose();
-
-		// let's remove alpha premult (all pixels should be white with alpha)
-		pixels.convert(BGRA);
-		flash.Memory.select(pixels.bytes.getData());
-		for( i in 0...pixels.width * pixels.height ) {
-			var p = i << 2;
-			var b = flash.Memory.getByte(p+3);
-			if( b > 0 ) {
-				flash.Memory.setByte(p, 0xFF);
-				flash.Memory.setByte(p + 1, 0xFF);
-				flash.Memory.setByte(p + 2, 0xFF);
-				flash.Memory.setByte(p + 3, b);
-			}
-		}
-
-		if( innerTex == null ) {
-			innerTex = h3d.mat.Texture.fromPixels(pixels, h3d.mat.Texture.nativeFormat);
-			font.tile = h2d.Tile.fromTexture(innerTex);
-			for( t in all )
-				t.setTexture(innerTex);
-			innerTex.realloc = build;
-		} else
-			innerTex.uploadPixels(pixels);
-		pixels.dispose();
-		return font;
-	}
-
-	#elseif js
+	#if js
 
 	function build() : h2d.Font {
 		var bmp = js.Browser.document.createCanvasElement();

+ 0 - 18
hxd/res/NanoJpeg.hx

@@ -606,19 +606,10 @@ class NanoJpeg {
 		var out = alloc(c.width * c.height);
 		var lin = new FastBytes(c.pixels);
 		var pout = 0;
-		#if flash
-		var dat = out.getData();
-		if( dat.length < 1024 ) dat.length = 1024;
-		flash.Memory.select(dat);
-		inline function write(pos, v) {
-			flash.Memory.setByte(pos, v);
-		}
-		#else
 		var lout = new FastBytes(out);
 		inline function write(pos, v) {
 			lout[pos] = v;
 		}
-		#end
 		for( y in 0...c.height ) {
 			var pin = (y >> yshift) * c.stride;
 			for( x in 0...c.width )
@@ -650,19 +641,10 @@ class NanoJpeg {
 			var py = new FastBytes(comps[0].pixels);
 			var pcb = new FastBytes(comps[1].pixels);
 			var pcr = new FastBytes(comps[2].pixels);
-			#if flash
-			var dat = pixels.getData();
-			if( dat.length < 1024 ) dat.length = 1024;
-			flash.Memory.select(dat);
-			inline function write(out, c) {
-				flash.Memory.setByte(out, c);
-			}
-			#else
 			var pix = new FastBytes(pixels);
 			inline function write(out, c) {
 				pix[out] = c;
 			}
-			#end
 			var k1 = 0, k2 = 0, k3 = 0, out = 0;
 			for( yy in 0...height ) {
 				for( x in 0...width ) {

+ 0 - 6
hxd/res/Sound.hx

@@ -31,12 +31,6 @@ class Sound extends Resource {
 		if( data != null )
 			return data;
 		var bytes = entry.getBytes();
-
-		#if flash
-		if( bytes.length == 0 )
-			return new hxd.snd.LoadingData(this);
-		#end
-
 		switch( bytes.get(0) ) {
 		case 'R'.code: // RIFF (wav)
 			data = new hxd.snd.WavData(bytes);

+ 3 - 34
hxd/snd/Mp3Data.hx

@@ -8,9 +8,7 @@ private typedef Mp3File = hl.Abstract<"fmt_mp3">;
 
 class Mp3Data extends Data {
 
-	#if flash
-	var snd : flash.media.Sound;
-	#elseif js
+	#if js
 	var buffer : haxe.io.Bytes;
 	var onEnd : Void -> Void;
 	#elseif hl
@@ -49,20 +47,7 @@ class Mp3Data extends Data {
 		samplingRate = format.mp3.Constants.MPEG.srEnum2Num(header.samplingRate);
 		channels = header.channelMode == Mono ? 1 : 2;
 
-		#if flash
-
-		// flash only allows to decode mp3 in stereo 44.1Khz
-		channels = 2;
-		if( samplingRate != 44100 ) {
-			samples = Math.ceil(samples * 44100.0 / samplingRate);
-			samplingRate = 44100;
-		}
-
-		snd = new flash.media.Sound();
-		bytes.getData().position = 0;
-		snd.loadCompressedDataFromByteArray(bytes.getData(), bytes.length);
-
-		#elseif js
+		#if js
 
 		var ctx = hxd.snd.webaudio.Context.get();
 		if( ctx == null ) return;
@@ -141,23 +126,7 @@ class Mp3Data extends Data {
 	#end
 
 	override function decodeBuffer(out:haxe.io.Bytes, outPos:Int, sampleStart:Int, sampleCount:Int) {
-		#if flash
-		var b = out.getData();
-		b.position = outPos;
-		while( sampleCount > 0 ) {
-			var r = Std.int(snd.extract(b, sampleCount, sampleStart + 2257 /* MAGIC_DELAY, silence added at mp3 start */ ));
-			if( r == 0 ) {
-				while( sampleCount > 0 ) {
-					b.writeFloat(0);
-					b.writeFloat(0);
-					sampleCount--;
-				}
-				return;
-			}
-			sampleCount -= r;
-			sampleStart += r;
-		}
-		#elseif js
+		#if js
 		if( buffer == null ) {
 			// not yet available : fill with blanks
 			out.fill(outPos, sampleCount * 4 * channels, 0);

+ 3 - 25
hxd/snd/NativeChannel.hx

@@ -104,10 +104,7 @@ private class ALChannel {
 #end
 class NativeChannel {
 
-	#if flash
-	var snd : flash.media.Sound;
-	var channel : flash.media.SoundChannel;
-	#elseif js
+	#if js
 	// Avoid excessive buffer allocation when playing many sounds.
 	// bufferSamples is constant and never change at runtime, so it's safe to use general pool.
 	static var bufferPool : Array<haxe.io.Float32Array> = new Array();
@@ -126,11 +123,7 @@ class NativeChannel {
 
 	public function new( bufferSamples : Int ) {
 		this.bufferSamples = bufferSamples;
-		#if flash
-		snd = new flash.media.Sound();
-		snd.addEventListener(flash.events.SampleDataEvent.SAMPLE_DATA, onFlashSample);
-		channel = snd.play(0, 0x7FFFFFFF);
-		#elseif js
+		#if js
 		var ctx = hxd.snd.webaudio.Context.get();
 
 		var rate = Std.int(ctx.sampleRate);
@@ -165,16 +158,6 @@ class NativeChannel {
 		#end
 	}
 
-	#if flash
-	function onFlashSample( event : flash.events.SampleDataEvent ) {
-		var buf = event.data;
-		buf.length = bufferSamples * 2 * 4;
-		buf.position = 0;
-		onSample(haxe.io.Float32Array.fromBytes(haxe.io.Bytes.ofData(buf)));
-		buf.position = bufferSamples * 2 * 4;
-	}
-	#end
-
 	#if js
 
 	function swap( event : js.html.Event ) {
@@ -215,12 +198,7 @@ class NativeChannel {
 	}
 
 	public function stop() {
-		#if flash
-		if( channel != null ) {
-			channel.stop();
-			channel = null;
-		}
-		#elseif js
+		#if js
 		if ( front != null ) {
 			current.removeEventListener("ended", swap);
 			current.stop();

+ 1 - 4
hxd/snd/openal/Emulator.hx

@@ -539,11 +539,8 @@ class Emulator {
 			}
 		case FORMAT_STEREOF32:
 			var bdata = buffer.alloc(size >> 2);
-			#if flash
-			flash.Memory.select(data.getData());
-			#end
 			for( i in 0...size>>2 )
-				buffer.data[i] = #if flash flash.Memory.getFloat #else data.getFloat #end(i<<2);
+				buffer.data[i] = data.getFloat(i<<2);
 		default:
 			throw "Format not supported 0x" + StringTools.hex(format);
 		}

+ 0 - 961
hxsl/AgalOptim.hx

@@ -1,961 +0,0 @@
-package hxsl;
-import format.agal.Data;
-
-private class RegInfos {
-	public var index : Int;
-	public var swiz : Array<C>;
-	public var values : Array<Reg>;
-	public var prevRead : haxe.ds.Vector<Int>;
-	public var prevWrite : haxe.ds.Vector<Int>;
-	public var reads : haxe.ds.Vector<Int>;
-	public var writes : haxe.ds.Vector<Int>;
-
-	public var live : Array<Int>;
-	public var invertSwiz : Array<Int>;
-
-	public function new(i) {
-		index = i;
-		prevRead = new haxe.ds.Vector(4);
-		prevWrite = new haxe.ds.Vector(4);
-		reads = new haxe.ds.Vector(4);
-		writes = new haxe.ds.Vector(4);
-		reset();
-	}
-
-	public inline function reset() {
-		live = [];
-		swiz = null;
-		invertSwiz = null;
-		values = null;
-		invertSwiz = [];
-		for( i in 0...4 ) {
-			prevRead[i] = -1;
-			prevWrite[i] = -1;
-			writes[i] = -1;
-			reads[i] = -1;
-		}
-	}
-}
-
-@:noDebug
-class AgalOptim {
-
-	static var COMPS = [X, Y, Z, W];
-
-	var code : Array<Opcode>;
-	var codePos : Int;
-	var prevRegs : Array<RegInfos>;
-	var regs : Array<RegInfos>;
-	var flag : Bool;
-	var maxRegs : Int;
-	var startReg : Int;
-	var changed : Bool;
-	var data : Data;
-	var usedRegs : Array<Array<RegInfos>>;
-	var packRegisters : Bool;
-	var debug : Bool;
-
-	public function new(debug = false) {
-		this.debug = debug;
-		regs = [];
-	}
-
-	function opStr(op) {
-		return format.agal.Tools.opStr(op);
-	}
-
-	function isWriteMask( swiz : Array<C> ) {
-		if( swiz == null || swiz.length == 1 )
-			return true;
-		for( i in 0...swiz.length )
-			if( swiz[i] != COMPS[i] )
-				return false;
-		return true;
-	}
-
-	public function optimize( d : Data ) : Data {
-		data = d;
-		code = d.code.copy();
-
-		var inputs = [];
-		for( op in code ) iter(op, function(r, _) if( r.t == RAttr ) inputs[r.index] = true);
-
-		while( true ) {
-			//if( debug ) trace("OPTIM\n"+[for( op in code ) opStr(op)].join("\n"));
-			changed = false;
-			buildLive(true);
-			splice();
-			if( changed ) continue;
-			optiMov();
-			if( changed ) continue;
-			optiDup();
-			if( changed ) continue;
-			break;
-		}
-
-		// added unread inputs
-		for( op in code ) iter(op, function(r, _) if( r.t == RAttr ) inputs[r.index] = false);
-		for( i in 0...inputs.length )
-			if( inputs[i] ) {
-				changed = true;
-				code.push(OMov(allocTemp(4), new Reg(RAttr, i, null)));
-			}
-
-		// single writes for out/varying
-		uniqueWrite(RVar);
-		uniqueWrite(ROut);
-
-		unoptim();
-		if( changed )
-			buildLive(false);
-
-		var old = code;
-		packRegisters = false;
-		if( !allocRegs() ) {
-			code = old;
-			packRegisters = true;
-			allocRegs();
-		}
-
-		optiMat();
-
-
-		// write mask are just masks, not full swizzle, we then need to change all our writes
-		//    for instance  V.zw = T.xy  actually mean  V.??zw = T.xyyy (? = ignore write)
-		for( i in 0...code.length ) {
-			var op = code[i];
-			switch( op ) {
-			case OMov(dst, v), ORcp(dst, v) if( !isWriteMask(dst.swiz) ):
-				var dst = dst.clone();
-				var v = v.clone();
-				// reinterpret swizzling accordingly to write mask
-				var last = X;
-				v.swiz = [for( i in 0...4 ) {
-					var k = dst.swiz.indexOf(COMPS[i]);
-					if( k >= 0 ) last = v.swiz[k];
-					last;
-				}];
-				code[i] = OMov(dst, v);
-			case OIfe(_), OIne(_), OIfg(_), OIfl(_), OEls, OEif, OKil(_):
-				// ignore
-			default:
-				var dst : Reg = op.getParameters()[0];
-				if( !isWriteMask(dst.swiz) )
-					throw "invalid write mask in "+format.agal.Tools.opStr(op);
-			}
-		}
-
-		return {
-			version : d.version,
-			fragmentShader : d.fragmentShader,
-			code : code,
-		};
-	}
-
-	function uniqueWrite( t ) {
-		var writes = [];
-		for( op in code ) iter(op, function(r, w) if( r.t == t ) writes[r.index] += w ? 1 : (data.fragmentShader ? 0 : 2));
-		for( i in 0...writes.length ) {
-			if( writes[i] > 1 ) {
-				var ri = allocTemp(4);
-				for( op in code ) iter(op, function(r, _) if( r.t == t && r.index == i ) { r.t = RTemp; r.index = ri.index; } );
-				code.push(OMov( new Reg(t, i, null), ri));
-				changed = true;
-			}
-		}
-	}
-
-	function allocRegs() {
-		for( r in regs )
-			if( r != null ) {
-				r.index = -1;
-				// we extend the liveness of registers on their total lifetime
-				// TODO : we should instead split the register into several different ones
-				var allRegs = 0, first = -1, last = -1;
-				for( i in 0...r.live.length ) {
-					var v = r.live[i];
-					if( v > 0 ) {
-						allRegs |= v;
-						if( first < 0 ) first = i;
-						last = i;
-					}
-				}
-				for( i in first...last + 1 )
-					r.live[i] = allRegs;
-			}
-		startReg = 0;
-		maxRegs = 0;
-		var max = format.agal.Tools.getProps(RTemp, data.fragmentShader, data.version).count;
-		usedRegs = [for( i in 0...max ) []];
-		var ocode = [];
-		for( i in 0...code.length ) {
-			var o = code[i];
-			codePos = i;
-			if( o != OUnused )
-				ocode.push(map(o, remapReg));
-		}
-		code = ocode;
-		return usedRegs.length <= max;
-	}
-
-	function remapReg( r : Reg, write : Bool ) {
-		var inf = getReg(r);
-		if( inf == null ) {
-			if( swizBits(r) == 228 )
-				r.swiz = null;
-			return r;
-		}
-		if( write && inf.index < 0 )
-			assignReg(inf);
-		var swiz = swiz(r);
-		if( r.access != null )
-			swiz = [r.access.comp];
-		var sout = [];
-		for( s in swiz ) {
-			var s2 : Null<C> = inf.swiz[s.getIndex()];
-			if( s2 == null ) {
-				// reading from unassigned component can happen if we are padding a varying
-				for( i in 0...4 ) {
-					var s : Null<C> = inf.swiz[3 - i];
-					if( s != null ) {
-						s2 = s;
-						break;
-					}
-				}
-			}
-			sout.push(s2);
-		}
-		var access = null;
-		if( r.access != null ) {
-			access = new RegAccess(r.access.t, sout[0], r.access.offset);
-			sout = null;
-		}
-		var r = new Reg(RTemp, inf.index, sout, access);
-		if( swizBits(r) == 228 ) r.swiz = null;
-		return r;
-	}
-
-	function assignReg( inf : RegInfos ) {
-		// make sure that we reserve all the components we will write
-		var mask = 0, ncomps = 0;
-		for( i in 0...4 )
-			if( inf.writes[i] >= codePos ) {
-				ncomps++;
-				mask |= 1 << i;
-			}
-		// allocate a new temp id by looking the other live variable components
-		var found : Null<Int> = null, reservedMask = 0, foundUsage = 10;
-		for( td in 0...usedRegs.length ) {
-			var rid = (startReg + td) % usedRegs.length;
-			var reg = usedRegs[rid];
-
-			// check current reserved components
-			var rmask = 0;
-			var available = 4;
-			for( i in 0...4 ) {
-				var t = reg[i];
-				if( t == null ) continue;
-				var b = t.live[codePos];
-				if( b & (1 << t.invertSwiz[i]) == 0 ) continue;
-				rmask |= 1 << i;
-				available--;
-			}
-
-			// not enough components available
-			if( available < ncomps )
-				continue;
-
-			// not first X components available
-			// this is necessary for write masks
-			if( ncomps > 1 && (rmask & ((1 << ncomps) - 1)) != 0 )
-				continue;
-
-			// if we have found a previous register that is better fit
-			if( packRegisters && found != null && foundUsage <= available - ncomps )
-				continue;
-
-			found = rid;
-			foundUsage = available - ncomps;
-			reservedMask = rmask;
-			// continue to look for best match
-			if( !packRegisters ) {
-				startReg = rid;
-				break;
-			}
-		}
-		if( found == null ) {
-			reservedMask = 0;
-			found = usedRegs.length;
-			usedRegs.push([]);
-		}
-		var reg = usedRegs[found];
-		inf.index = found;
-		// list free components
-		var all = [X, Y, Z, W];
-		var comps = [];
-		for( i in 0...4 )
-			if( reservedMask & (1 << i) == 0 )
-				comps.push(all[i]);
-		// create component map
-		inf.swiz = [];
-		for( i in 0...4 )
-			if( mask & (1 << i) != 0 ) {
-				// if one single component, allocate from the end to keep free first registers
-				var c = ncomps == 1 ? comps.pop() : comps.shift();
-				inf.swiz[i] = c;
-				inf.invertSwiz[c.getIndex()] = i;
-				reg[c.getIndex()] = inf;
-			}
-	}
-
-	function splice() {
-		for( i in 0...code.length ) {
-			codePos = i;
-			flag = false;
-			iter(code[i], checkUseful);
-			if( flag ) {
-				code[i] = OUnused;
-				changed = true;
-			}
-		}
-	}
-
-	function allocTemp( size : Int ) : Reg {
-		var r = new Reg(RTemp, regs.length, size == 4 ? null : [for( i in 0...size ) COMPS[i]]);
-		regs.push(null);
-		return r;
-	}
-
-	function unoptim() {
-		// expand invalid AGAL opcodes with additional MOV
-		var out = [];
-		for( i in 0...code.length ) {
-			var op = code[i];
-			switch( op ) {
-			case OMov(_), OTex(_):
-				out.push(op);
-				continue;
-			default:
-			}
-			var args : Array<Reg> = cast op.getParameters();
-			switch( args.length ) {
-			case 0, 1:
-				// nothing
-			case 2:
-				// unop with a const
-				if( args[1].t == RConst && args[1].access == null ) {
-					var r = allocTemp(swiz(args[1]).length);
-					out.push(OMov(r, args[1]));
-					out.push(Opcode.createByIndex(op.getIndex(), [args[0], r]));
-					changed = true;
-					continue;
-				}
-			default:
-				// binop with two consts
-				switch( [args[1].t, args[2].t] ) {
-				case [RConst, RConst]:
-					var r = allocTemp(swiz(args[1]).length);
-					out.push(OMov(r, args[1]));
-					out.push(Opcode.createByIndex(op.getIndex(), [args[0], r, args[2]]));
-					changed = true;
-					continue;
-				default:
-				}
-			}
-			out.push(op);
-		}
-		code = out;
-	}
-
-
-	function optiMov() {
-		// additional remove of operations of this kind :
-		//    mul t0.x, a, b
-		//    mul t1.x, c, d
-		//    mov t2.x, t0.x
-		//    mov t2.y, t1.x
-		//
-		//    we will optimize as:
-		//
-		//	  mul t2.x, a, b
-		//    mul t2.y, c, d
-		for( i in 0...code.length ) {
-			codePos = i;
-			switch( code[i] ) {
-
-			case OMov(r1, r2) if( r2.access != null ):
-				var i2 = getReg(r2);
-				if( i2 == null || i2.values == null ) continue;
-				// optimize
-				// 		mov a, b
-				//		mov c, X[a]
-				//  into
-				//		mov c, X[b]
-				var v = i2.values[r2.access.comp.getIndex()];
-				if( v == null || (v.index == r2.index && v.t == r2.t) ) continue;
-				code[i] = OMov(r1, new Reg(v.t, v.index, r2.swiz, new RegAccess(r2.access.t, v.swiz[0], r2.access.offset)));
-				changed = true;
-
-			case OMov(r1, r2):
-				var i1 = getReg(r1);
-				var i2 = getReg(r2);
-				if( i1 == null || i2 == null ) continue;
-				var sw1 = swiz(r1);
-				var sw2 = swiz(r2);
-				var used = [];
-				var rewrite = true;
-				for( i in 0...sw1.length ) {
-					var k2 = sw2[i].getIndex();
-
-					// we don't support mov A.xy, B.xx atm
-					if( used[k2] ) {
-						rewrite = false;
-						break;
-					}
-					used[k2] = true;
-
-					// if we have written after now, we can't tell the real write pos
-					var wt = i2.writes[k2];
-					if( wt >= codePos ) {
-						rewrite = false;
-						break;
-					}
-
-					// if we read after write, we can't opt since it's needed elsewhere
-					if( i2.reads[k2] != codePos || (i2.prevRead[k2] != -1 && i2.prevRead[k2] > wt) ) {
-						rewrite = false;
-						break;
-					}
-
-					// make sure the component we will write is not live between write and mov
-					var k1 = sw1[i].getIndex();
-					for( p in wt + 1...codePos )
-						if( i1.live[p] & (1 << k1) != 0 ) {
-							rewrite = false;
-							break;
-						}
-					if( !rewrite ) break;
-				}
-
-				if( rewrite ) {
-					// if we have written at the same time one other component that we don't use,
-					// we can't remap the mov since this will write more components than we want
-					// e.g.
-					//	mov a.xyz, E
-					//  op b, E
-					//  mov a.w, b.x
-					//
-					//  we can't do "op a.wwww, E" since that will be E.w and not E.x
-					for( i in 0...sw1.length ) {
-						var k2 = sw2[i].getIndex();
-						var wt = i2.writes[k2];
-						for( i in 0...4 )
-							if( !used[i] && i2.writes[i] == wt ) {
-								rewrite = false;
-								break;
-							}
-						if( !rewrite )
-							break;
-					}
-				}
-
-				if( !rewrite ) continue;
-
-				// perform rewrite
-				for( i in 0...sw1.length ) {
-					var k2 = sw2[i].getIndex();
-					var wt = i2.writes[k2];
-					var op = map(code[wt], function(r, w) {
-						if( !w ) return r;
-						var sout = [];
-						for( s in swiz(r) ) {
-							var idx = sw2.indexOf(s);
-							sout.push(sw1[idx]);
-						}
-						return new Reg(RTemp, r1.index, sout);
-					});
-					code[wt] = op;
-				}
-				code[codePos] = OUnused;
-				changed = true;
-			default:
-			}
-			// we can't perform several changes since this will break live bits
-			if( changed ) return;
-		}
-	}
-
-	function buildLive(check) {
-		prevRegs = regs;
-		regs = [];
-		for( i in 0...code.length ) {
-			codePos = i;
-			code[i] = switch( code[i] ) {
-			case OMov(r1, r2) if( check ):
-				checkMov(r1, r2);
-			case op:
-				map(op, checkValue);
-			}
-		}
-	}
-
-	function checkMov( r1 : Reg, r2 : Reg ) {
-
-		r2 = checkValue(r2, false);
-
-		var inf = getReg(r1);
-		if( inf == null )
-			return OMov(r1, r2);
-		if( r2.access != null ) {
-			inf.values = null;
-			write(r1);
-			return OMov(r1, r2);
-		}
-		var swiz = swiz(r1);
-		var swiz2 = this.swiz(r2);
-		if( inf.values == null ) inf.values = [];
-		for( i in 0...swiz.length ) {
-			var s = swiz[i];
-			inf.values[s.getIndex()] = new Reg(r2.t, r2.index, [swiz2[i]]);
-		}
-		write(r1);
-		return OMov(r1, r2);
-	}
-
-	inline function swiz( r : Reg ) {
-		var s = r.swiz;
-		if( s == null ) s = COMPS;
-		return s;
-	}
-
-	function checkUseful( r : Reg, write : Bool ) {
-		if( write ) {
-			var inf = getReg(r);
-			if( inf == null ) return;
-			var sw = swiz(r);
-			var mask = 0;
-			for( s in swiz(r) )
-				mask |= 1 << s.getIndex();
-			if( inf.live[codePos + 1] & mask == 0 )
-				flag = true;
-		}
-	}
-
-	function checkValue( r : Reg, write : Bool ) {
-		var inf = getReg(r);
-		if( inf == null ) return r;
-		if( write ) {
-			if( r.swiz == null )
-				inf.values = null;
-			else if( inf.values != null )
-				for( s in r.swiz )
-					inf.values[s.getIndex()] = new Reg(RTemp, r.index, [s]);
-			this.write(r);
-			return r;
-		}
-		if( inf.values == null ) {
-			read(r);
-			return r;
-		}
-		var swiz = swiz(r);
-		var reg = new Reg(null, 0, []);
-		for( s in swiz ) {
-			var v = inf.values[s.getIndex()];
-			if( v == null ) {
-				read(r);
-				return r;
-			}
-			if( reg.t == null ) {
-				reg.t = v.t;
-				reg.index = v.index;
-			} else if( reg.t != v.t || reg.index != v.index ) {
-				read(r);
-				return r;
-			}
-			reg.swiz.push(v.swiz[0]);
-		}
-		read(reg);
-		return reg;
-	}
-
-	function write( r : Reg ) {
-		var inf = getReg(r);
-		if( inf == null ) return;
-		for( s in swiz(r) ) {
-			var b = s.getIndex();
-			var r = inf.writes[b];
-			if( r < codePos ) inf.prevWrite[b] = r;
-			inf.writes[b] = codePos;
-		}
-	}
-
-	function read( r : Reg ) {
-		var inf = getReg(r);
-		if( inf == null ) return;
-		var minPos = 10000000, mask = 0;
-		for( s in swiz(r) ) {
-			var b = s.getIndex();
-			var r = inf.reads[b];
-			if( r < codePos ) inf.prevRead[b] = r;
-			inf.reads[b] = codePos;
-			var w = inf.writes[b];
-			if( w < minPos ) minPos = w;
-			mask |= 1 << b;
-		}
-		for( p in minPos+1...codePos+1 )
-			inf.live[p] |= mask;
-	}
-
-	function getReg( r : Reg ) {
-		if( r.t != RTemp ) return null;
-		var inf = regs[r.index];
-		if( inf == null ) {
-			inf = prevRegs[r.index];
-			if( inf != null )
-				inf.reset();
-			else
-				inf = new RegInfos(r.index);
-			regs[r.index] = inf;
-		}
-		return inf;
-	}
-
-	function swizBits( r : Reg ) {
-		if( r.swiz == null ) return 228;
-		var b = 0;
-		for( i in 0...r.swiz.length )
-			b |= r.swiz[i].getIndex() << (i * 2);
-		return b;
-	}
-
-	inline function same( a : Reg, b : Reg ) {
-		return dist(a, b) == 0;
-	}
-
-	inline function sameTex( ta : Tex, tb : Tex ) {
-		return ta.index == tb.index && (ta.flags == tb.flags || ta.flags.join("") == tb.flags.join(""));
-	}
-
-	inline function dist( a : Reg, b : Reg ) {
-		return a.t == b.t && a.access == null && b.access == null ? b.index - a.index : 1000;
-	}
-
-	inline function noSwiz( r : Reg ) {
-		return new Reg(r.t, r.index, null);
-	}
-
-	function regSign(r:Reg) {
-		return (r.index << 8) | swizBits(r);
-	}
-
-	function getSign( op : Opcode ) {
-		var ra = 0, rb = 0;
-		inline function regSign(r:Reg) {
-			return ((r.index << 4)&511) ^ swizBits(r);
-		}
-		inline function unop(_, a, _) {
-			ra = regSign(a);
-		}
-		inline function binop(_, a, b, _) {
-			ra = regSign(a);
-			rb = regSign(b);
-		}
-		switch( op ) {
-		case OMov(_): return -1;
-		case OAdd(d, a, b): binop(d, a, b, OAdd);
-		case OSub(d, a, b): binop(d, a, b, OSub);
-		case OMul(d, a, b): binop(d, a, b, OMul);
-		case ODiv(d, a, b): binop(d, a, b, ODiv);
-		case ORcp(d, v): unop(d, v, ORcp);
-		case OMin(d, a, b): binop(d, a, b, OMin);
-		case OMax(d, a, b): binop(d, a, b, OMax);
-		case OFrc(d, v): unop(d, v, OFrc);
-		case OSqt(d, v): unop(d, v, OSqt);
-		case ORsq(d, v): unop(d, v, ORsq);
-		case OPow(d, a, b): binop(d, a, b, OPow);
-		case OLog(d, v): unop(d, v, OLog);
-		case OExp(d, v): unop(d, v, OExp);
-		case ONrm(d, v): unop(d, v, ONrm);
-		case OSin(d, v): unop(d, v, OSin);
-		case OCos(d, v): unop(d, v, OCos);
-		case OCrs(d, a, b): binop(d, a, b, OCrs);
-		case ODp3(d, a, b): binop(d, a, b, ODp3);
-		case ODp4(d, a, b): binop(d, a, b, ODp4);
-		case OAbs(d, v): unop(d, v, OAbs);
-		case ONeg(d, v): unop(d, v, ONeg);
-		case OSat(d, v): unop(d, v, OSat);
-		case OM33(d, a, b): binop(d, a, b, OM33);
-		case OM44(d, a, b): binop(d, a, b, OM44);
-		case OM34(d, a, b): binop(d, a, b, OM34);
-		case ODdx(d, v): unop(d, v, ODdx);
-		case ODdy(d, v): unop(d, v, ODdy);
-		case OIfe(_), OIne(_), OIfg(_), OIfl(_), OEls, OEif, OUnused, OKil(_):
-			return -1;
-		case OTex(_,a,tex):
-			ra = regSign(a);
-			rb = tex.index;
-			return -1;
-		case OSge(d, a, b): binop(d, a, b, OSge);
-		case OSlt(d, a, b): binop(d, a, b, OSlt);
-		case OSgn(d, v): unop(d, v, OSgn);
-		case OSeq(d, a, b): binop(d, a, b, OSeq);
-		case OSne(d, a, b): binop(d, a, b, OSne);
-		}
-		return (op.getIndex() << 26) | (ra << 13) | rb;
-	}
-
-	function getAssignedReg( op : Opcode ) {
-		return switch( op ) {
-		case OMov(r, _), ORcp(r, _), ORsq(r, _), OFrc(r, _), OSqt(r, _), OLog(r, _), OExp(r, _), ONrm(r, _), OSin(r, _), OCos(r, _), OAbs(r, _), ONeg(r, _), OSat(r, _), ODdx(r, _), ODdy(r, _): r;
-		case OAdd(r, _, _), OSub(r, _, _), OMul(r, _, _), ODiv(r, _, _), OMin(r, _, _), OMax(r, _ , _), OPow(r, _, _), OCrs(r, _, _), ODp3(r, _, _), ODp4(r, _, _), OM33(r, _, _), OM44(r, _, _), OM34(r, _, _), OTex(r, _, _): r;
-		case OIfe(_), OIne(_), OIfg(_), OIfl(_), OEls, OEif, OUnused, OKil(_), OSge(_), OSlt(_), OSgn(_), OSeq(_), OSne(_): null;
-		}
-	}
-
-	function optiDup() {
-		// optimize duplication of code
-		var opIds = new Map();
-
-		// use prevWrite to store our last opcode signature
-		for( r in regs )
-			if( r != null ) {
-				r.prevWrite[0] = -1;
-				r.prevWrite[1] = -1;
-				r.prevWrite[2] = -1;
-				r.prevWrite[3] = -1;
-			}
-
-		for( i in 0...code.length ) {
-			var op1 = code[i];
-			var sign = getSign(op1);
-
-			inline function clearReg() {
-				// clear previous operation from cache (register has been modified)
-				var r = getAssignedReg(op1);
-				if( r != null && r.t == RTemp ) {
-					var ops = regs[r.index].prevWrite;
-					var sw = r.swiz == null ? COMPS : r.swiz;
-					for( c in sw ) {
-						var id = ops[c.getIndex()];
-						if( id != -1 ) opIds.remove(id);
-						ops[c.getIndex()] = sign;
-					}
-				}
-			}
-
-			if( sign == -1 ) {
-				clearReg();
-				continue;
-			}
-			var prev = sign;
-			while( true ) {
-				var prev = opIds.get(sign);
-				if( prev == null ) {
-					clearReg();
-					opIds.set(sign, i);
-					break;
-				}
-				var op2 = code[prev];
-				if( op1.getIndex() != op2.getIndex() ) {
-					sign = sign * 1103515245 + 12345;
-					continue;
-				}
-
-				var params1 = op1.getParameters();
-				var params2 = op2.getParameters();
-				var ok = true;
-
-				// additional check
-				if( !same(params1[1], params2[1]) )
-					ok = false;
-				else switch( op1 ) {
-				case OTex(_):
-					if( !sameTex(params1[2], params2[2]) )
-						ok = false;
-				default:
-					if( !same(params1[2], params2[2]) )
-						ok = false;
-				}
-
-				if( ok ) {
-					var pos = i;
-					code[i] = OMov(params1[0], params2[0]);
-					changed = true;
-					break;
-				}
-				sign = sign * 1103515245 + 12345;
-			}
-		}
-	}
-
-	function optiMat() {
-		var XYZ = 36;
-		var XYZW = 228;
-		// group contiguous dp into matrix macros
-		// should be purely cosmetic
-		for( i in 0...code.length - 2 ) {
-			switch( code[i] ) {
-			// disable for Temps, since we can't swiz on [b.XYZ], and since we are not sure W is written (and it's rejected by AGAL!)
-			case ODp3(dst, a, b) if( swizBits(dst) == 0 && swizBits(b) & 63 == XYZ && b.t != RTemp ):
-				var sa = swizBits(a) & 63;
-				switch( [code[i + 1], code[i + 2]] ) {
-				case [ODp3(d2, a2, b2), ODp3(d3, a3, b3)]:
-					if( same(dst, d2) && same(dst, d3) && same(a, a2) && same(a, a3) && swizBits(a2)&63 == sa && swizBits(a3)&63 == sa && dist(b, b2) == 1 && dist(b, b3) == 2 && swizBits(d2) == 1 && swizBits(d3) == 2 && swizBits(b2)&63 == XYZ && swizBits(b3)&63 == XYZ ) {
-						var dst = dst.clone();
-						dst.swiz = [X, Y, Z];
-						code[i] = OM33(dst, a, noSwiz(b));
-						code[i + 1] = OUnused;
-						code[i + 2] = OUnused;
-					}
-				default:
-				}
-			case ODp4(dst, a, b) if( swizBits(dst) == 0 && swizBits(b) == XYZW ):
-				var sa = swizBits(a);
-				switch( [code[i + 1], code[i + 2]] ) {
-				case [ODp4(d2, a2, b2), ODp4(d3, a3, b3)]:
-					if( same(dst, d2) && same(dst, d3) && same(a, a2) && same(a, a3) && swizBits(a2) == sa && swizBits(a3) == sa && dist(b, b2) == 1 && dist(b, b3) == 2 && swizBits(d2) == 1 && swizBits(d3) == 2 && swizBits(b2) == XYZW && swizBits(b3) == XYZW ) {
-						var m44 = false;
-						if( i + 3 < code.length )
-							switch( code[i + 3] ) {
-							case ODp4(d4, a4, b4):
-								if( same(dst, d4) && same(a, a4) && swizBits(a4) == sa && dist(b, b4) == 3 && swizBits(d4) == 3 && swizBits(b4) == XYZW )
-									m44 = true;
-							default:
-							}
-						var dst = dst.clone();
-						dst.swiz = m44 ? null : [X,Y,Z];
-						code[i] = (m44?OM44:OM34)(dst, sa == XYZW ? noSwiz(a) : a, noSwiz(b));
-						code[i + 1] = OUnused;
-						code[i + 2] = OUnused;
-						if( m44 ) code[i + 3] = OUnused;
-					}
-				default:
-				}
-			default:
-			}
-		}
-		while( code.remove(OUnused) )
-			continue;
-	}
-
-	public function iter( op : Opcode, reg : Reg -> Bool -> Void ) {
-		switch( op ) {
-		case OUnused:
-			// nothing
-		case OKil(r):
-			reg(r, false);
-		case OMov(d, v):
-			if( v.access != null )
-				reg( new Reg(v.t, v.index, [v.access.comp]), false );
-			else
-				reg(v, false);
-			reg(d, true);
-		case OTex(d, v, _), ORcp(d, v), OFrc(d,v),OSqt(d,v), ORsq(d,v), OLog(d,v),OExp(d,v), ONrm(d,v), OSin(d,v), OCos(d,v), OAbs(d,v), ONeg(d,v), OSat(d,v), OSgn(d,v):
-			reg(v,false);
-			reg(d,true);
-		case OAdd(d, a, b), OSub(d, a, b), OMul(d, a, b), ODiv(d, a, b), OMin(d, a, b), OMax(d, a, b),
-			OPow(d, a, b), OCrs(d, a, b), ODp3(d, a, b), OSge(d, a, b), OSlt(d, a, b), OSne(d,a,b), OSeq(d,a,b), ODp4(d,a,b):
-			reg(a,false);
-			reg(b,false);
-			reg(d,true);
-		case OM33(d, a, b),  OM34(d, a, b):
-			reg(a, false);
-			reg(b, false);
-			reg(offset(b, 1), false);
-			reg(offset(b, 2), false);
-			reg(d, true);
-		case OM44(d, a, b):
-			reg(a, false);
-			reg(b, false);
-			reg(offset(b, 1), false);
-			reg(offset(b, 2), false);
-			reg(offset(b, 3), false);
-			reg(d, true);
-		case OIne(a, b), OIfe(a, b), OIfg(a, b), OIfl(a, b):
-			reg(a, false);
-			reg(b, false);
-		case ODdx(d, v), ODdy(d,v):
-			reg(v, false);
-			reg(d, true);
-		case OEls, OEif:
-		}
-	}
-
-	inline function map( mop : Opcode, r : Reg -> Bool -> Reg ) {
-		inline function unop(d, v, op) {
-			var v2 = r(v, false);
-			var d2 = r(d, true);
-			return if( v == v2 && d == d2 ) mop else op(d2,v2);
-		}
-		inline function binop(d, a, b, op) {
-			var a2 = r(a, false);
-			var b2 = r(b, false);
-			var d2 = r(d, true);
-			return if( a == a2 && b == b2 && d == d2 ) mop else op(d2, a2, b2);
-		}
-		inline function cond(a, b, op) {
-			var a2 = r(a, false);
-			var b2 = r(b, false);
-			return if( a2 == a && b2 == b ) mop else op(a2, b2);
-		}
-		return switch( mop ) {
-		case OMov(d, v): unop(d, v, OMov);
-		case OAdd(d, a, b): binop(d, a, b, OAdd);
-		case OSub(d, a, b): binop(d, a, b, OSub);
-		case OMul(d, a, b): binop(d, a, b, OMul);
-		case ODiv(d, a, b): binop(d, a, b, ODiv);
-		case ORcp(d, v): unop(d, v, ORcp);
-		case OMin(d, a, b): binop(d, a, b, OMin);
-		case OMax(d, a, b): binop(d, a, b, OMax);
-		case OFrc(d, v): unop(d, v, OFrc);
-		case OSqt(d, v): unop(d, v, OSqt);
-		case ORsq(d, v): unop(d, v, ORsq);
-		case OPow(d, a, b): binop(d, a, b, OPow);
-		case OLog(d, v): unop(d, v, OLog);
-		case OExp(d, v): unop(d, v, OExp);
-		case ONrm(d, v): unop(d, v, ONrm);
-		case OSin(d, v): unop(d, v, OSin);
-		case OCos(d, v): unop(d, v, OCos);
-		case OCrs(d, a, b): binop(d, a, b, OCrs);
-		case ODp3(d, a, b): binop(d, a, b, ODp3);
-		case ODp4(d, a, b): binop(d, a, b, ODp4);
-		case OAbs(d, v): unop(d, v, OAbs);
-		case ONeg(d, v): unop(d, v, ONeg);
-		case OSat(d, v): unop(d, v, OSat);
-		case OM33(d, a, b): binop(d, a, b, OM33);
-		case OM44(d, a, b): binop(d, a, b, OM44);
-		case OM34(d, a, b): binop(d, a, b, OM34);
-		case ODdx(d, v): unop(d, v, ODdx);
-		case ODdy(d, v): unop(d, v, ODdy);
-		case OIfe(a, b): cond(a, b, OIfe);
-		case OIne(a, b): cond(a, b, OIne);
-		case OIfg(a, b): cond(a, b, OIfg);
-		case OIfl(a, b): cond(a, b, OIfl);
-		case OEls: OEls;
-		case OEif: OEif;
-		case OUnused: OUnused;
-		case OKil(v):
-			OKil(r(v, false));
-		case OTex(d, v, t):
-			v = r(v, false);
-			OTex(r(d, true), v, t);
-		case OSge(d, a, b): binop(d, a, b, OSge);
-		case OSlt(d, a, b): binop(d, a, b, OSlt);
-		case OSgn(d, v): unop(d, v, OSgn);
-		case OSeq(d, a, b): binop(d, a, b, OSeq);
-		case OSne(d, a, b): binop(d, a, b, OSne);
-		}
-	}
-
-	inline function rswiz( r : Reg, s : Array<C> ) : Reg {
-		if( r.access != null ) throw "assert";
-		var swiz = swiz(r);
-		return new Reg(r.t, r.index, [for( s in s ) swiz[s.getIndex()]]);
-	}
-
-	inline function offset( r : Reg, n : Int ) : Reg {
-		if( r.access != null ) throw "assert";
-		return new Reg(r.t, r.index + n, r.swiz == null ? null : r.swiz.copy());
-	}
-
-}

+ 0 - 871
hxsl/AgalOut.hx

@@ -1,871 +0,0 @@
-package hxsl;
-
-import hxsl.Ast;
-import hxsl.RuntimeShader;
-import format.agal.Data;
-
-class AgalOut {
-
-	static var COMPS = [X, Y, Z, W];
-
-	var code : Array<Opcode>;
-	var current : RuntimeShaderData;
-	var version : Int;
-	var opcodes : Array<Opcode>;
-	var varMap : Map<Int, Reg>;
-	var tmpCount : Int;
-	var nullReg : Reg;
-	var unused : Map<Int, Reg>;
-
-	public function new() {
-	}
-
-	public dynamic function error( msg : String, p : Position ) {
-		throw msg;
-	}
-
-	public function compile( s : RuntimeShaderData, version ) : Data {
-		current = s;
-		nullReg = new Reg(RTemp, -1, null);
-		this.version = version;
-		opcodes = [];
-		tmpCount = 0;
-		varMap = new Map();
-		unused = new Map();
-
-		var varying = [];
-		var paramCount = 0, inputCount = 0, outCount = 0, texCount = 0;
-		for( v in s.data.vars ) {
-			var r : Reg;
-			switch( v.kind ) {
-			case Param, Global:
-				switch( v.type ) {
-				case TArray(TSampler2D | TSamplerCube, SConst(n)):
-					r = new Reg(RTexture, texCount, null);
-					texCount += n;
-				default:
-					r = new Reg(RConst, paramCount, defSwiz(v.type));
-					paramCount += regSize(v.type);
-				}
-			case Var:
-				r = new Reg(RVar, v.id, defSwiz(v.type));
-				varying.push(r);
-			case Output:
-				r = new Reg(ROut, outCount, defSwiz(v.type));
-				outCount += regSize(v.type);
-			case Input:
-				r = new Reg(RAttr, inputCount, defSwiz(v.type));
-				inputCount += regSize(v.type);
-			case Local, Function:
-				continue;
-			}
-			varMap.set(v.id, r);
-			unused.set(v.id, r);
-		}
-		if( paramCount != s.globalsSize + s.paramsSize )
-			throw "assert";
-
-		// optimize varying
-		// make sure the order is the same in both fragment and vertex shader
-		varying.sort(function(r1, r2) return ((r2.swiz == null ? 4 : r2.swiz.length) - (r1.swiz == null ? 4 : r1.swiz.length)) * 100000 + (r1.index - r2.index));
-		var valloc : Array<Array<C>> = [];
-		for( r in varying ) {
-			var size = r.swiz == null ? 4 : r.swiz.length;
-			var found = -1;
-			for( i in 0...valloc.length ) {
-				var v = valloc[i];
-				if( v.length < size ) continue;
-				found = i;
-				break;
-			}
-			if( found < 0 ) {
-				found = valloc.length;
-				valloc.push([X, Y, Z, W]);
-			}
-			r.index = found;
-			var v = valloc[found];
-			if( size == 4 )
-				valloc[found] = [];
-			else if( size == 1 )
-				r.swiz[0] = v.pop();
-			else {
-				for( i in 0...size )
-					r.swiz[i] = v.shift();
-			}
-		}
-
-		if( s.data.funs.length != 1 ) throw "assert";
-		expr(s.data.funs[0].expr);
-
-		// force write of missing varying components
-		for( vid in 0...valloc.length ) {
-			var v = valloc[vid];
-			if( v.length == 0 ) continue;
-			for( i in 0...opcodes.length )
-				switch( opcodes[i] ) {
-				case OMov(dst, val) if( dst.index == vid && dst.t == RVar ):
-					var dst = dst.clone();
-					var val = val.clone();
-					var last = X;
-					val.swiz = [for( i in 0...4 ) { var k = dst.swiz.indexOf(COMPS[i]); if( k >= 0 ) last = val.swiz[k]; last; } ];
-					dst.swiz = null;
-					opcodes[i] = OMov(dst, val);
-					break;
-				default:
-				}
-		}
-
-		// force write of unused inputs
-		for( r in unused )
-			switch( r.t ) {
-			case RAttr:
-				var t = allocReg();
-				t.swiz = r.swiz == null ? null : [for( i in 0...r.swiz.length ) COMPS[i]];
-				op(OMov(t, r));
-			default:
-			}
-
-		return {
-			fragmentShader : !current.vertex,
-			version : version,
-			code : opcodes,
-		};
-	}
-
-	function mov(dst, src, t) {
-		var n = regSize(t);
-		op(OMov(dst, src));
-		if( n > 1 )
-			for( i in 1...n )
-				op(OMov(offset(dst, i), offset(src, i)));
-	}
-
-	inline function op(o) {
-		opcodes.push(o);
-	}
-
-	inline function swiz( r : Reg, sw : Array<C> ) : Reg {
-		if( r.access != null ) throw "assert";
-		var sw = sw;
-		if( r.swiz != null )
-			sw = [for( c in sw ) r.swiz[c.getIndex()]];
-		return new Reg(r.t, r.index, sw);
-	}
-
-	inline function offset( r : Reg, k : Int ) : Reg {
-		if( r.access != null ) throw "assert";
-		return new Reg(r.t, r.index + k, r.swiz == null ? null : r.swiz.copy());
-	}
-
-	function getConst( v : Float ) : Reg {
-		for( i in 0...current.consts.length )
-			if( current.consts[i] == v ) {
-				var g = current.globals;
-				while( g != null ) {
-					if( g.path == "__consts__" )
-						break;
-					g = g.next;
-				}
-				var p = g.pos + i;
-				return new Reg(RConst, p >> 2, [COMPS[p & 3]]);
-			}
-		throw "Missing required const "+v;
-	}
-
-	function getConsts( va : Array<Float> ) : Reg {
-		var pad = (va.length - 1) & 3;
-		for( i in 0...current.consts.length - (va.length - 1) ) {
-			if( (i >> 2) != (i + pad) >> 2 ) continue;
-			var found = true;
-			for( j in 0...va.length )
-				if( current.consts[i + j] != va[j] ) {
-					found = false;
-					break;
-				}
-			if( found ) {
-				var g = current.globals;
-				while( g != null ) {
-					if( g.path == "__consts__" )
-						break;
-					g = g.next;
-				}
-				var p = g.pos + i;
-				return new Reg(RConst, p >> 2, defSwiz(TVec(va.length,VFloat)));
-			}
-		}
-		throw "Missing required consts "+va;
-	}
-
-	function expr( e : TExpr ) : Reg {
-		switch( e.e ) {
-		case TConst(c):
-			switch( c ) {
-			case CInt(v):
-				return getConst(v);
-			case CFloat(f):
-				return getConst(f);
-			default:
-				throw "assert " + c;
-			}
-		case TParenthesis(e):
-			return expr(e);
-		case TVarDecl(v, init):
-			if( init != null )
-				mov(reg(v), expr(init), v.type);
-			return nullReg;
-		case TBlock(el):
-			var r = nullReg;
-			for( e in el )
-				r = expr(e);
-			return r;
-		case TVar(v):
-			var r = reg(v);
-			switch( v.type ) {
-			case TBytes(n):
-				// multiply by 255 on read
-				var ro = allocReg();
-				var c = getConst(255);
-				var sw = [];
-				for( i in 0...n ) {
-					sw.push(COMPS[i]);
-					if( i > 0 ) c.swiz.push(c.swiz[0]);
-				}
-				op(OMul(swiz(ro, sw), swiz(r, sw), c));
-				return ro;
-			default:
-			}
-			return r;
-		case TBinop(bop, e1, e2):
-			return binop(bop, e.t, e1, e2);
-		case TCall(c, args):
-			switch( c.e ) {
-			case TGlobal(g):
-				return global(g, args, e.t);
-			default:
-				throw "TODO CALL " + e.e;
-			}
-		case TArray(ea, index):
-			switch( index.e ) {
-			case TConst(CInt(v)):
-				var r = expr(ea);
-				var stride = switch( ea.t ) {
-				case TArray(TSampler2D | TSamplerCube, _): 4;
-				case TArray(t, _): Tools.size(t);
-				default: throw "assert " + e.t;
-				};
-				var index = v * stride;
-				var swiz = null;
-				if( stride < 4 ) {
-					swiz = [];
-					for( i in 0...stride )
-						swiz.push(COMPS[(i + index) & 3]);
-				} else if( index & 3 != 0 ) throw "assert"; // not register-aligned !
-				return new Reg(r.t, r.index + (index>>2), swiz);
-			default:
-				var r = expr(ea);
-				var delta = 0;
-				// remove ToInt and extract delta when the form is [int(offset) * stride + delta] as produced by Flatten
-				switch( index.e ) {
-				case TBinop(OpAdd, { e : TBinop(OpMult,{ e : TCall({ e : TGlobal(ToInt) },[epos]) },stride) } , { e : TConst(CInt(d)) } ):
-					delta = d;
-					index = { e : TBinop(OpMult, epos, stride), t : TFloat, p : index.p };
-				case TBinop(OpMult,{ e : TCall({ e : TGlobal(ToInt) },[epos]) },stride):
-					index = { e : TBinop(OpMult, epos, stride), t : TFloat, p : index.p };
-				case TBinop(OpAdd, { e : TCall({ e : TGlobal(ToInt) },[epos]) }, { e : TConst(CInt(d)) } ):
-					delta = d;
-					index = epos;
-				case TCall({ e : TGlobal(ToInt) },[epos]):
-					index = epos;
-				default:
-				}
-				var i = expr(index);
-				if( r.swiz != null || r.access != null ) throw "assert";
-				if( i.swiz == null || i.swiz.length != 1 || i.access != null ) throw "assert";
-				var out = allocReg();
-				op(OMov(out, new Reg(i.t, i.index, null, new RegAccess(r.t, i.swiz[0], r.index + delta))));
-				return out;
-			}
-		case TSwiz(e, regs):
-			var r = expr(e);
-			return swiz(r, [for( r in regs ) COMPS[r.getIndex()]]);
-		case TIf( cond, { e : TDiscard }, null ):
-			switch( cond.e ) {
-			case TBinop(bop = OpLt | OpGt, e1, e2) if( e1.t == TFloat ):
-				if( bop == OpGt ) {
-					var tmp = e1;
-					e1 = e2;
-					e2 = e1;
-				}
-				var r = allocReg(TFloat);
-				op(OSub(r, expr(e1), expr(e2)));
-				op(OKil(r));
-				return nullReg;
-			default:
-				throw "Discard cond not supported " + e.e+ " "+e.p;
-			}
-		case TUnop(uop, e):
-			switch( uop ) {
-			case OpNeg:
-				var r = allocReg(e.t);
-				op(ONeg(r, expr(e)));
-				return r;
-			default:
-			}
-		case TIf(econd, eif, eelse):
-			switch( econd.e ) {
-			case TBinop(bop, e1, e2) if( e1.t == TFloat ):
-				inline function cop(f) {
-					op(f(expr(e1), expr(e2)));
-					expr(eif);
-					if( eelse != null ) {
-						op(OEls);
-						expr(eelse);
-					}
-					op(OEif);
-					return nullReg;
-				}
-				switch( bop ) {
-				case OpEq:
-					return cop(OIfe);
-				case OpNotEq:
-					return cop(OIfe);
-				case OpGt:
-					return cop(OIfg);
-				case OpLt:
-					return cop(OIfl);
-				default:
-					throw "Conditional operation not supported " + bop+" " + econd.p;
-				}
-			default:
-			}
-			throw "Conditional not supported " + econd.e+" " + econd.p;
-		case TMeta(_, _, e):
-			return expr(e);
-		default:
-			throw "Expression '" + Printer.toString(e)+"' not supported in AGAL "+e.p;
-		}
-		return null;
-	}
-
-	function binop( bop, et : Type, e1 : TExpr, e2 : TExpr ) {
-		inline function std(bop) {
-			var r = allocReg(et);
-			op(bop(r, expr(e1), expr(e2)));
-			return r;
-		}
-		inline function compare(bop,e1,e2) {
-			var r = allocReg(et);
-			op(bop(r, expr(e1), expr(e2)));
-			return r;
-		}
-		switch( bop ) {
-		case OpAdd: return std(OAdd);
-		case OpSub: return std(OSub);
-		case OpDiv: return std(ODiv);
-		case OpMod:
-			var tmp = allocReg(e2.t);
-			op(OMov(tmp, expr(e2)));
-			var r = allocReg(et);
-			op(ODiv(r, expr(e1), tmp));
-			op(OFrc(r, r));
-			op(OMul(r, r, tmp));
-			return r;
-		case OpAssign:
-			var r = expr(e1);
-			mov(r, expr(e2), e1.t);
-			return r;
-		case OpAssignOp(op):
-			var r1 = expr(e1);
-			mov(r1, expr( { e : TBinop(op, e1, e2), t : e1.t, p : e1.p } ), e1.t);
-			return r1;
-		case OpMult:
-			var r = allocReg(et);
-			var r1 = expr(e1);
-			var r2 = expr(e2);
-			switch( [e1.t, e2.t] ) {
-			case [TFloat | TInt | TVec(_), TFloat | TInt | TVec(_)]:
-				op(OMul(r, r1, r2));
-			case [TVec(3, VFloat), TMat3]:
-				var r2 = swiz(r2,[X,Y,Z]);
-				op(ODp3(swiz(r,[X]), r1, r2));
-				op(ODp3(swiz(r,[Y]), r1, offset(r2,1)));
-				op(ODp3(swiz(r,[Z]), r1, offset(r2,2)));
-			case [TVec(3, VFloat), TMat3x4]:
-				if( r1.t == RTemp ) {
-					var r = allocReg();
-					op(OMov(swiz(r, [X, Y, Z]), r1));
-					op(OMov(swiz(r, [W]), getConst(1)));
-					r1 = r;
-				} else {
-					r1 = r1.clone();
-					r1.swiz = null;
-				}
-				op(ODp4(swiz(r,[X]), r1, r2));
-				op(ODp4(swiz(r,[Y]), r1, offset(r2,1)));
-				op(ODp4(swiz(r,[Z]), r1, offset(r2,2)));
-			case [TVec(4, VFloat), TMat4]:
-				op(ODp4(swiz(r,[X]), r1, r2));
-				op(ODp4(swiz(r,[Y]), r1, offset(r2,1)));
-				op(ODp4(swiz(r,[Z]), r1, offset(r2,2)));
-				op(ODp4(swiz(r, [W]), r1, offset(r2, 3)));
-			case [TMat4, TMat4]:
-				var tmp = allocReg(TMat4);
-				colsToRows(r1, tmp, TMat4);
-				for( i in 0...4 ) {
-					var b = offset(r2, i);
-					var o = offset(r, i);
-					op(ODp4(swiz(o, [X]), tmp, b));
-					op(ODp4(swiz(o, [Y]), offset(tmp, 1), b));
-					op(ODp4(swiz(o, [Z]), offset(tmp, 2), b));
-					op(ODp4(swiz(o, [W]), offset(tmp, 3), b));
-				}
-			default:
-				throw "assert " + [e1.t, e2.t];
-			}
-			return r;
-		case OpGt:
-			return compare(OSlt, e2, e1);
-		case OpLt:
-			return compare(OSlt, e1, e2);
-		case OpGte:
-			return compare(OSge, e1, e2);
-		case OpLte:
-			return compare(OSlt, e2, e1);
-		case OpEq:
-			return compare(OSeq, e1, e2);
-		case OpNotEq:
-			return compare(OSne, e1, e2);
-		default:
-			throw "TODO " + bop;
-		}
-		return null;
-	}
-
-	function colsToRows( src : Reg, dst : Reg, t : Type ) {
-		switch( t ) {
-		case TMat4:
-			for( i in 0...4 ) {
-				var ldst = offset(dst, i);
-				for( j in 0...4 )
-					op(OMov(swiz(ldst, [COMPS[j]]), swiz(offset(src, j), [COMPS[i]])));
-			}
-		default:
-			throw "Can't transpose " + t;
-		}
-	}
-
-
-	function global( g : TGlobal, args : Array<TExpr>, ret : Type ) : Reg {
-		inline function binop(bop) {
-			if( args.length != 2 ) throw "assert";
-			var r = allocReg(ret);
-			op(bop(r, expr(args[0]), expr(args[1])));
-			return r;
-		}
-		inline function unop(uop) {
-			if( args.length != 1 ) throw "assert";
-			var r = allocReg(ret);
-			op(uop(r, expr(args[0])));
-			return r;
-		}
-
-		switch( [g, args] ) {
-		case [ToFloat, [a]]:
-			return expr(a);
-		case [Max, _]:
-			return binop(OMax);
-		case [Min, _]:
-			return binop(OMin);
-		case [Pow, _]:
-			return binop(OPow);
-		case [Sqrt, _]:
-			return unop(OSqt);
-		case [Inversesqrt, _]:
-			return unop(ORsq);
-		case [Abs, _]:
-			return unop(OAbs);
-		case [Sin, _]:
-			return unop(OSin);
-		case [Cos, _]:
-			return unop(OCos);
-		case [Tan | Asin | Acos | Atan | Sign, _]:
-			throw "TODO" + g;
-		case [Log2, _]:
-			return unop(OLog);
-		case [Exp2, _]:
-			return unop(OExp);
-		case [Log, _]:
-			var r = unop(OLog);
-			op(OMul(r, r, getConst(0.6931471805599453))); // log(2)/log(e)
-			return r;
-		case [Exp, [e]]:
-			var r = allocReg(e.t);
-			op(OMul(r, expr(e), getConst(1.4426950408889634))); // log(e)/log(2)
-			op(OExp(r, r));
-			return r;
-		case [Radians, [e]]:
-			var r = allocReg(e.t);
-			op(OMul(r, expr(e), getConst(Math.PI / 180)));
-			return r;
-		case [Degrees, [e]]:
-			var r = allocReg(e.t);
-			op(OMul(r, expr(e), getConst(180 / Math.PI)));
-			return r;
-		case [Cross, [a, b]]:
-			var r = allocReg(a.t);
-			op(OCrs(r, expr(a), expr(b)));
-			return r;
-		case [Length, [e]]:
-			var r = allocReg(TFloat);
-			switch( e.t  ) {
-			case TFloat:
-				op(OAbs(r, expr(e)));
-				return r;
-			case TVec(2, VFloat):
-				var e = expr(e);
-				var tmp = allocReg(TVec(3,VFloat));
-				op(OMul(swiz(tmp, [X, Y]), e, e));
-				op(OAdd(r, swiz(tmp, [X]), swiz(tmp, [Y])));
-			case TVec(3, VFloat):
-				var e = expr(e);
-				op(ODp3(r, e, e));
-			case TVec(4, VFloat):
-				var e = expr(e);
-				op(ODp4(r, e, e));
-			default:
-				throw "TODO length(" + e.t + ")";
-			}
-			op(OSqt(r, r));
-			return r;
-
-		case [Mix, [a, b, t]]:
-			var ra = allocReg(a.t);
-			var rb = allocReg(b.t);
-			var r = allocReg(t.t);
-			op(OMov(r, expr(t)));
-			op(OMul(rb, expr(b), r));
-			op(OSub(r, getConst(1), r));
-			op(OMul(ra, expr(a), r));
-			op(OAdd(ra, ra, rb));
-			return ra;
-
-		case [Fract, _]:
-			return unop(OFrc);
-		case [Saturate, _]:
-			return unop(OSat);
-		case [Floor | ToInt, [a]]:
-			// might not be good for negative values...
-			var r = expr(a);
-			var tmp = allocReg(a.t);
-			op(OFrc(tmp, r));
-			op(OSub(r, r, tmp));
-			return r;
-		case [Clamp, [a, min, max]]:
-			var r = allocReg(ret);
-			op(OMax(r, expr(a), expr(min)));
-			var r2 = allocReg(ret);
-			op(OMin(r2, r, expr(max)));
-			return r2;
-		case [Vec4, _]:
-			var r = allocReg();
-			var pos = 0;
-			for( a in args ) {
-				var e = expr(a);
-				switch( a.t ) {
-				case TFloat:
-					if( args.length == 1 )
-						mov(r, swiz(e,[X,X,X,X]), a.t);
-					else
-						mov(swiz(r, [COMPS[pos++]]), e, a.t);
-				case TVec(2, VFloat):
-					mov(swiz(r, [COMPS[pos++], COMPS[pos++]]), e, a.t);
-				case TVec(3, VFloat):
-					mov(swiz(r, [COMPS[pos++], COMPS[pos++], COMPS[pos++]]), e, a.t);
-				case TVec(4, VFloat):
-					mov(r, e, a.t);
-				default:
-					throw "assert " + e.t;
-				}
-			}
-			return r;
-		case [Vec3, _]:
-			var r = allocReg(TVec(3,VFloat));
-			var pos = 0;
-			for( a in args ) {
-				var e = expr(a);
-				switch( a.t ) {
-				case TFloat:
-					if( args.length == 1 )
-						mov(r, swiz(e,[X,X,X]), a.t);
-					else
-						mov(swiz(r, [COMPS[pos++]]), e, a.t);
-				case TVec(2, VFloat):
-					mov(swiz(r, [COMPS[pos++], COMPS[pos++]]), e, a.t);
-				case TVec(3, VFloat):
-					mov(r, e, a.t);
-				default:
-					throw "assert " + e.t;
-				}
-			}
-			return r;
-		case [Vec2, _]:
-			var r = allocReg(TVec(2,VFloat));
-			var pos = 0;
-			for( a in args ) {
-				var e = expr(a);
-				switch( a.t ) {
-				case TFloat:
-					if( args.length == 1 )
-						mov(r, swiz(e,[X,X]), a.t);
-					else
-						mov(swiz(r, [COMPS[pos++]]), e, a.t);
-				case TVec(2, VFloat):
-					mov(r, e, a.t);
-				default:
-					throw "assert " + e.t;
-				}
-			}
-			return r;
-		case [Texture, [et,uv]]:
-			var t = expr(et);
-			var uv = expr(uv);
-			var r = allocReg();
-			if( t.t != RTexture ) throw "assert";
-			var flags = [TIgnoreSampler];
-			if( et.t == TSamplerCube )
-				flags.push(TCube);
-			op(OTex(r, uv, { index : t.index, flags : flags }));
-			return r;
-		case [Dot, [a, b]]:
-			switch( a.t ) {
-			case TFloat | TInt:
-				var r = allocReg(TFloat);
-				op(OMul(r, expr(a), expr(b)));
-				return r;
-			case TVec(2, _):
-				var r = allocReg(TFloat);
-				var tmp = allocReg(TVec(2,VFloat));
-				op(OMul(tmp, expr(a), expr(b)));
-				op(OAdd(r, swiz(tmp, [X]), swiz(tmp, [Y])));
-				return r;
-			case TVec(3, _):
-				var r = allocReg(TFloat);
-				op(ODp3(r, expr(a), expr(b)));
-				return r;
-			case TVec(4, _):
-				var r = allocReg(TFloat);
-				op(ODp4(r, expr(a), expr(b)));
-				return r;
-			default:
-			}
-		case [Mat3, _]:
-			return copyToMatrix(args, 3, 3);
-		case [Mat3x4, _]:
-			return copyToMatrix(args, 3, 4);
-		case [Mat4, _]:
-			return copyToMatrix(args, 4, 4);
-		case [Normalize, [e]]:
-			switch( e.t ) {
-			case TVec(3, VFloat):
-				var r = allocReg(e.t);
-				op(ONrm(r, expr(e)));
-				return r;
-			default:
-			}
-		case [LReflect, [a, b]]:
-			var ra = expr(a);
-			var rb = expr(b);
-			var tmp = allocReg(TFloat);
-			switch( a.t ) {
-			case TFloat | TInt:
-				op(OMul(tmp, ra, rb));
-			case TVec(2, _):
-				var r = allocReg(TVec(2,VFloat));
-				op(OMul(r, ra, rb));
-				op(OAdd(tmp, swiz(r, [X]), swiz(r, [Y])));
-			case TVec(3, _):
-				op(ODp3(tmp, ra, rb));
-			case TVec(4, _):
-				op(ODp4(tmp, ra, rb));
-			default:
-			}
-			op(OAdd(tmp, tmp, tmp));
-			var o = allocReg(a.t);
-			var sw = defSwiz(a.t);
-			op(OMul(o, swiz(tmp, sw == null ? [X, X, X, X] : [for( _ in sw ) X]), rb));
-			op(OSub(o, ra, o));
-			return o;
-		case [ScreenToUv,[e]]:
-			var r = allocReg();
-			op(OMul(r,expr(e),getConsts([0.5,-0.5])));
-			op(OAdd(r,r,getConsts([0.5,0.5])));
-			return r;
-		case [UvToScreen,[e]]:
-			var r = allocReg();
-			op(OMul(r,expr(e),getConsts([2,-2])));
-			op(OAdd(r,r,getConsts([-1,1])));
-			return r;
-		case [Pack, [e]]:
-			var c = getConsts([1, 255, 255 * 255, 255 * 255 * 255]);
-			var r = allocReg();
-			op(OMul(r, swiz(expr(e), [X, X, X, X]), c));
-			op(OFrc(r, r));
-			var r2 = allocReg();
-			op(OMul(r2, swiz(r, [Y, Z, W, W]), getConsts([1/255,1/255,1/255,0])));
-			op(OSub(r, r, r2));
-			return r;
-		case [Unpack, [e]]:
-			var c = getConsts([1, 1/255, 1/(255 * 255), 1/(255 * 255 * 255)]);
-			var r = allocReg(TFloat);
-			op(ODp4(r, expr(e), c));
-			return r;
-		case [PackNormal, [e]]:
-			var r = allocReg();
-			op(OAdd(r, expr(e), getConst(1)));
-			op(OMul(r, r, getConst(0.5)));
-			return r;
-		case [UnpackNormal, [e]]:
-			var r = allocReg(TVec(3,VFloat));
-			op(OSub(r, swiz(expr(e), [X, Y,Z]) , getConst(0.5) ));
-			op(ONrm(r, r));
-			return r;
-		case [Step, [a, b]]:
-			return this.binop(OpGt, ret, a, b);
-		case [DFdx, [v]]:
-			var v = expr(v);
-			var r = allocReg();
-			op(ODdx(r, v));
-			return r;
-		case [DFdy, [v]]:
-			var v = expr(v);
-			var r = allocReg();
-			op(ODdy(r, v));
-			return r;
-		case [Fwidth, [v]]:
-			var v = expr(v);
-			var r = allocReg();
-			op(ODdx(r, v));
-			op(OAbs(r, r));
-			var r2 = allocReg();
-			op(ODdy(r2, v));
-			op(OAbs(r2, r2));
-			op(OAdd(r, r, r2));
-			return r;
-		case [Smoothstep, [e0, e1, x]]:
-			//:x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
-			var edge0 = expr(e0);
-			var edge1 = expr(e1);
-			var r = allocReg(ret);
-			var t = allocReg(ret);
-			op(OMov(r, expr(x)));
-			op(OMov(t, edge1));
-			op(OSub(r, r, edge0));
-			op(OSub(t, t, edge0));
-			op(ORcp(t, t));
-			op(OMul(r, r, t));
-			op(OSat(r, r));
-			//:return x * x * (3 - 2 * x);
-			op(OMul(t, r, getConst(2.0)));
-			op(OMul(r, r, r));
-			op(OSub(t, getConst(3.0), t));
-			op(OMul(r, r, t));
-			return r;
-		default:
-		}
-
-		throw "TODO " + g + ":" + args.length;
-		return null;
-	}
-
-	function copyToMatrix( args : Array<TExpr>, w : Int, h : Int ) {
-		var regs = [for( a in args ) expr(a)];
-		var out = [for( i in 0...w ) allocReg()];
-		var comps = [for( o in out ) for( i in 0...h ) swiz(o, [COMPS[i]])];
-		var defSwiz = [X, Y, Z, W];
-		// copy all regs to output components
-		for( i in 0...args.length ) {
-			var regs = [regs[i]];
-			switch( args[i].t ) {
-			case TFloat, TVec(_):
-			case TMat3, TMat3x4:
-				if( args.length != 1 ) throw "assert";
-				regs.push(offset(regs[0], 1));
-				regs.push(offset(regs[0], 2));
-				if( h < 4 ) defSwiz = [X, Y, Z];
-			case TMat4:
-				if( args.length != 1 ) throw "assert";
-				regs.push(offset(regs[0], 1));
-				regs.push(offset(regs[0], 2));
-				if( w == 4 ) regs.push(offset(regs[0], 3));
-				// we allow to reduce the size of the output matrix
-				if( h < 4 ) defSwiz = [X, Y, Z];
-			default:
-				throw "assert " + args[i].t;
-			}
-			for( i in 0...regs.length ) {
-				regs[i] = regs[i].clone();
-				if( regs[i].swiz == null ) regs[i].swiz = defSwiz.copy();
-				if( regs[i].access != null ) throw "assert";
-			}
-			while( regs.length > 0 ) {
-				var w = comps[0].index;
-				var r = regs[0];
-				var sw = [], sr = [];
-				while( regs[0].swiz.length > 0 && comps[0].index == w ) {
-					sw.push(comps.shift().swiz[0]);
-					sr.push(regs[0].swiz.shift());
-				}
-				if( regs[0].swiz.length == 0 ) regs.shift();
-				var m = OMov( new Reg(RTemp, w, sw), new Reg(r.t, r.index, sr) );
-				op(m);
-			}
-		}
-		if( comps.length != 0 ) throw "assert";
-		return out[0];
-	}
-
-	function regSize( t : Type ) {
-		return switch( t ) {
-		case TInt, TFloat, TVec(_), TBytes(_), TBool: 1;
-		case TMat2: throw "Mat2 is not supported in AGAL";
-		case TMat3, TMat3x4: 3;
-		case TMat4: 4;
-		case TArray(t, SConst(size)), TBuffer(t, SConst(size)): (Tools.size(t) * size + 3) >> 2;
-		case TStruct(vl): throw "TODO";
-		case TVoid, TString, TSampler2D, TSampler2DArray, TSamplerCube, TFun(_), TArray(_), TBuffer(_), TChannel(_): throw "assert "+t;
-		}
-	}
-
-	function defSwiz( t : Type ) {
-		return switch( t ) {
-		case TInt, TFloat: [X];
-		case TVec(2, _), TBytes(2): [X, Y];
-		case TVec(3, _), TBytes(3): [X, Y, Z];
-		default: null;
-		}
-	}
-
-	function reg( v : TVar ) : Reg {
-		var r = varMap.get(v.id);
-		if( r != null ) {
-			unused.remove(v.id);
-			return r;
-		}
-		if( v.kind != Local ) throw "assert " + v;
-		r = allocReg(v.type);
-		varMap.set(v.id, r);
-		return r;
-	}
-
-	function allocReg( ?t : Type ) : Reg {
-		var r = new Reg(RTemp, tmpCount, t == null ? null : defSwiz(t));
-		tmpCount += t == null ? 1 : regSize(t);
-		return r;
-	}
-
-	public static function toAgal( shader, version ) {
-		var a = new AgalOut();
-		return a.compile(shader, version);
-	}
-
-}

+ 1 - 3
hxsl/Cache.hx

@@ -65,10 +65,8 @@ class Cache {
 	var batchShaders : Map<RuntimeShader, { shader : SharedShader, params : RuntimeShader.AllocParam, size : Int }>;
 	var byID : Map<String, RuntimeShader>;
 	var batchShadersParams : Map<String, Map<RuntimeShader, { shader : SharedShader, params : RuntimeShader.AllocParam, size : Int }>>;
-	public var constsToGlobal : Bool;
 
 	function new() {
-		constsToGlobal = false;
 		linkCache = new SearchMap();
 		linkShaders = new Map();
 		batchShaders = new Map();
@@ -426,7 +424,7 @@ class Cache {
 	function flattenShader( s : ShaderData, kind : FunctionKind, params : Map<Int,{ instance:Int, index:Int }> ) {
 		var flat = new Flatten();
 		var c = new RuntimeShaderData();
-		var data = flat.flatten(s, kind, constsToGlobal);
+		var data = flat.flatten(s, kind);
 		#if (hl && heaps_compact_mem)
 		data = hl.Api.compact(data, null, 0, null);
 		#end

+ 1 - 31
hxsl/Flatten.hx

@@ -33,40 +33,10 @@ class Flatten {
 	public function new() {
 	}
 
-	public function flatten( s : ShaderData, kind : FunctionKind, constsToGlobal : Bool ) : ShaderData {
+	public function flatten( s : ShaderData, kind : FunctionKind ) : ShaderData {
 		globals = [];
 		params = [];
 		outVars = [];
-		if( constsToGlobal ) {
-			consts = [];
-			var p = s.funs[0].expr.p;
-			var gc : TVar = {
-				id : Tools.allocVarId(),
-				name : "__consts__",
-				kind : Global,
-				type : null,
-			};
-			econsts = {
-				e : TVar(gc),
-				t : null,
-				p : p,
-			};
-			s = {
-				name : s.name,
-				vars : s.vars.copy(),
-				funs : [for( f in s.funs ) mapFun(f, mapConsts)],
-			};
-			for( v in s.vars )
-				switch( v.type ) {
-				case TBytes(_):
-					allocConst(255, p);
-				default:
-				}
-			if( consts.length > 0 ) {
-				gc.type = econsts.t = TArray(TFloat, SConst(consts.length));
-				s.vars.push(gc);
-			}
-		}
 		varMap = new Map();
 		allocData = new Map();
 		for( v in s.vars )

+ 1 - 5
hxsl/Globals.hx

@@ -58,14 +58,10 @@ class Globals {
 	}
 
 	static var ALL : Array<String>;
-	static var MAP : #if flash haxe.ds.UnsafeStringMap<Int> #else Map<String,Int> #end;
+	static var MAP : Map<String,Int>;
 	public static function allocID( path : String ) : Int {
 		if( MAP == null ) {
-			#if flash
-			MAP = new haxe.ds.UnsafeStringMap<Int>();
-			#else
 			MAP = new Map();
-			#end
 			ALL = [];
 		}
 		var id = MAP.get(path);

+ 1 - 4
hxsl/SharedShader.hx

@@ -37,7 +37,7 @@ class ShaderConst {
 
 class SharedShader {
 
-	public static var UNROLL_LOOPS = #if flash true #else false #end;
+	public static var UNROLL_LOOPS = false;
 
 	public var data : ShaderData;
 	public var globals : Array<ShaderGlobal>;
@@ -81,9 +81,6 @@ class SharedShader {
 			c = c.next;
 		}
 		eval.inlineCalls = true;
-		#if flash
-		eval.eliminateConditionals = true;
-		#end
 		eval.unrollLoops = UNROLL_LOOPS;
 		var edata = eval.eval(data);
 		edata = compactMem(edata);

+ 1 - 1
samples/Cursor.hx

@@ -13,7 +13,7 @@ class Cursor extends SampleApp {
 		bmp.line(31, 0, 31, 31, 0xFF00FF00);
 
 		var animationSupported = false;
-		#if (flash || js || hldx || hlsdl)
+		#if (js || hldx || hlsdl)
 		animationSupported = true;
 		#end
 

+ 1 - 9
samples/Network.hx

@@ -95,13 +95,8 @@ class Network extends hxd.App {
 		host = new hxd.net.SocketHost();
 		host.setLogger(function(msg) log(msg));
 
-		if( !hxd.net.Socket.ALLOW_BIND ) {
-			#if flash
-			log("Using network with flash requires compiling with -lib air3 and running through AIR");
-			#else
+		if( !hxd.net.Socket.ALLOW_BIND )
 			log("Server not allowed on this platform");
-			#end
-		}
 
 		try {
 			host.wait(HOST, PORT, function(c) {
@@ -155,9 +150,6 @@ class Network extends hxd.App {
 
 	public static var inst : Network;
 	static function main() {
-		#if air3
-		@:privateAccess hxd.Stage.getInstance().multipleWindowsSupport = true;
-		#end
 		inst = new Network();
 	}
 

+ 0 - 5
samples/Pbr.hx

@@ -20,11 +20,6 @@ class Pbr extends SampleApp {
 
 		new h3d.scene.CameraController(5.5, s3d);
 
-		#if flash
-		new h2d.Text(getFont(), s2d).text = "Not supported on this platform (requires render to mipmap target and fragment textureCubeLod support)";
-		return;
-		#end
-
 		#if js
 		if( !engine.driver.hasFeature(ShaderModel3) ) {
 			new h2d.Text(getFont(), s2d).text = "WebGL 2.0 support required and not available on this browser.";