Explorar el Código

allowed more classes compilation from within macros + added test to prevent regressions

ncannasse hace 7 años
padre
commit
f158249374
Se han modificado 9 ficheros con 69 adiciones y 12 borrados
  1. 3 1
      h3d/Engine.hx
  2. 7 1
      h3d/impl/Driver.hx
  3. 2 0
      h3d/mat/Pass.hx
  4. 2 0
      h3d/mat/Stencil.hx
  5. 6 2
      h3d/mat/Texture.hx
  6. 15 1
      h3d/pass/Copy.hx
  7. 8 6
      hxd/Cursor.hx
  8. 1 1
      hxsl/Eval.hx
  9. 25 0
      samples/ExtraTests.hx

+ 3 - 1
h3d/Engine.hx

@@ -62,7 +62,9 @@ class Engine {
 		realFps = hxd.System.getDefaultFrameRate();
 		realFps = hxd.System.getDefaultFrameRate();
 		lastTime = haxe.Timer.stamp();
 		lastTime = haxe.Timer.stamp();
 		window.addResizeEvent(onWindowResize);
 		window.addResizeEvent(onWindowResize);
-		#if (js || cpp || hlsdl || usegl)
+		#if macro
+		driver = new h3d.impl.NullDriver();
+		#elseif (js || cpp || hlsdl || usegl)
 		driver = new h3d.impl.GlDriver(antiAlias);
 		driver = new h3d.impl.GlDriver(antiAlias);
 		#elseif flash
 		#elseif flash
 		driver = new h3d.impl.Stage3dDriver(antiAlias);
 		driver = new h3d.impl.Stage3dDriver(antiAlias);

+ 7 - 1
h3d/impl/Driver.hx

@@ -1,6 +1,12 @@
 package h3d.impl;
 package h3d.impl;
 
 
-#if flash
+#if macro
+typedef IndexBuffer = {};
+typedef VertexBuffer = {};
+typedef Texture = {};
+typedef DepthBuffer = {};
+typedef Query = {};
+#elseif flash
 typedef IndexBuffer = flash.display3D.IndexBuffer3D;
 typedef IndexBuffer = flash.display3D.IndexBuffer3D;
 typedef VertexBuffer = Stage3dDriver.VertexWrapper;
 typedef VertexBuffer = Stage3dDriver.VertexWrapper;
 typedef Texture = flash.display3D.textures.TextureBase;
 typedef Texture = flash.display3D.textures.TextureBase;

+ 2 - 0
h3d/mat/Pass.hx

@@ -272,6 +272,7 @@ class Pass implements hxd.impl.Serializable {
 		return p;
 		return p;
 	}
 	}
 
 
+	#if !macro
 	public function getDebugShaderCode( scene : h3d.scene.Scene, toHxsl = true ) {
 	public function getDebugShaderCode( scene : h3d.scene.Scene, toHxsl = true ) {
 		var shader = scene.renderer.debugCompileShader(this);
 		var shader = scene.renderer.debugCompileShader(this);
 		if( toHxsl ) {
 		if( toHxsl ) {
@@ -281,6 +282,7 @@ class Pass implements hxd.impl.Serializable {
 			return h3d.Engine.getCurrent().driver.getNativeShaderCode(shader);
 			return h3d.Engine.getCurrent().driver.getNativeShaderCode(shader);
 		}
 		}
 	}
 	}
+	#end
 
 
 	#if hxbit
 	#if hxbit
 
 

+ 2 - 0
h3d/mat/Stencil.hx

@@ -2,7 +2,9 @@ package h3d.mat;
 import h3d.mat.Data;
 import h3d.mat.Data;
 
 
 @:allow(h3d.mat.Material)
 @:allow(h3d.mat.Material)
+#if !macro
 @:build(hxd.impl.BitsBuilder.build())
 @:build(hxd.impl.BitsBuilder.build())
+#end
 class Stencil implements hxd.impl.Serializable {
 class Stencil implements hxd.impl.Serializable {
 
 
 	@:s var maskBits  : Int = 0;
 	@:s var maskBits  : Int = 0;

+ 6 - 2
h3d/mat/Texture.hx

@@ -116,8 +116,12 @@ class Texture {
 				flags.push(f);
 				flags.push(f);
 		var t = new Texture(width, height, flags, format, allocPos);
 		var t = new Texture(width, height, flags, format, allocPos);
 		t.name = this.name;
 		t.name = this.name;
-		if(this.flags.has(Cube)) h3d.pass.CubeCopy.run(this, t);
-		else h3d.pass.Copy.run(this, t);
+		#if !macro
+		if(this.flags.has(Cube))
+			h3d.pass.CubeCopy.run(this, t);
+		else
+		#end
+			h3d.pass.Copy.run(this, t);
 		lastFrame = old;
 		lastFrame = old;
 		return t;
 		return t;
 	}
 	}

+ 15 - 1
h3d/pass/Copy.hx

@@ -1,5 +1,17 @@
 package h3d.pass;
 package h3d.pass;
 
 
+#if macro
+
+class Copy {
+
+	public static function run( from : h3d.mat.Texture, to : h3d.mat.Texture, ?blend : h3d.mat.BlendMode, ?pass : h3d.mat.Pass ) {
+		throw "assert";
+	}
+
+}
+
+#else
+
 private class CopyShader extends h3d.shader.ScreenShader {
 private class CopyShader extends h3d.shader.ScreenShader {
 
 
 	static var SRC = {
 	static var SRC = {
@@ -52,4 +64,6 @@ class Copy extends ScreenFx<CopyShader> {
 		return inst.apply(from, to, blend, pass);
 		return inst.apply(from, to, blend, pass);
 	}
 	}
 
 
-}
+}
+
+#end

+ 8 - 6
hxd/Cursor.hx

@@ -16,7 +16,9 @@ class CustomCursor {
 	var speed : Float;
 	var speed : Float;
 	var offsetX : Int;
 	var offsetX : Int;
 	var offsetY : Int;
 	var offsetY : Int;
-	#if hlsdl
+	#if macro
+	var alloc : Array<Dynamic>;
+	#elseif hlsdl
 	var alloc : Array<sdl.Cursor>;
 	var alloc : Array<sdl.Cursor>;
 	#elseif hldx
 	#elseif hldx
 	var alloc : Array<dx.Cursor>;
 	var alloc : Array<dx.Cursor>;
@@ -29,14 +31,14 @@ class CustomCursor {
 	#else
 	#else
 	var alloc : Dynamic;
 	var alloc : Dynamic;
 	#end
 	#end
-	
+
 	// Heaps-side cursor animation for target that do not support native animated cursors.
 	// Heaps-side cursor animation for target that do not support native animated cursors.
 	#if (hlsdl || hldx || js)
 	#if (hlsdl || hldx || js)
 	var frameDelay : Float;
 	var frameDelay : Float;
 	var frameTime : Float;
 	var frameTime : Float;
 	var frameIndex : Int;
 	var frameIndex : Int;
 	#end
 	#end
-	
+
 	public function new( frames, speed, offsetX, offsetY ) {
 	public function new( frames, speed, offsetX, offsetY ) {
 		this.frames = frames;
 		this.frames = frames;
 		this.speed = speed;
 		this.speed = speed;
@@ -51,13 +53,13 @@ class CustomCursor {
 		frameIndex = 0;
 		frameIndex = 0;
 		#end
 		#end
 	}
 	}
-	
+
 	#if (hlsdl || hldx || js)
 	#if (hlsdl || hldx || js)
 	public function reset() : Void {
 	public function reset() : Void {
 		frameTime = 0;
 		frameTime = 0;
 		frameIndex = 0;
 		frameIndex = 0;
 	}
 	}
-	
+
 	public function update( dt : Float ) : Int {
 	public function update( dt : Float ) : Int {
 		var newTime : Float = frameTime + dt;
 		var newTime : Float = frameTime + dt;
 		var delay : Float = frameDelay;
 		var delay : Float = frameDelay;
@@ -67,7 +69,7 @@ class CustomCursor {
 			index++;
 			index++;
 		}
 		}
 		frameTime = newTime;
 		frameTime = newTime;
-		
+
 		if ( index >= frames.length ) index %= frames.length;
 		if ( index >= frames.length ) index %= frames.length;
 		if ( index != frameIndex ) {
 		if ( index != frameIndex ) {
 			frameIndex = index;
 			frameIndex = index;

+ 1 - 1
hxsl/Eval.hx

@@ -161,7 +161,7 @@ class Eval {
 		case [ToFloat, [ { e : TConst(CInt(i)) } ]]: TConst(CFloat(i));
 		case [ToFloat, [ { e : TConst(CInt(i)) } ]]: TConst(CFloat(i));
 		case [Trace, args]:
 		case [Trace, args]:
 			for( a in args )
 			for( a in args )
-				haxe.Log.trace(Printer.toString(a), { fileName : a.p.file, lineNumber : 0, className : null, methodName : null });
+				haxe.Log.trace(Printer.toString(a), { fileName : #if macro haxe.macro.Context.getPosInfos(a.p).file #else a.p.file #end, lineNumber : 0, className : null, methodName : null });
 			TBlock([]);
 			TBlock([]);
 		case [ChannelRead|ChannelReadLod, _]:
 		case [ChannelRead|ChannelReadLod, _]:
 			var i = switch( args[0].e ) { case TConst(CInt(i)): i; default: Error.t("Cannot eval complex channel " + Printer.toString(args[0],true)+" "+constantsToString(), pos); throw "assert"; };
 			var i = switch( args[0].e ) { case TConst(CInt(i)): i; default: Error.t("Cannot eval complex channel " + Printer.toString(args[0],true)+" "+constantsToString(), pos); throw "assert"; };

+ 25 - 0
samples/ExtraTests.hx

@@ -0,0 +1,25 @@
+
+class CheckMacroCompilation {
+
+	// check correct compilation of these files in macro mode
+	//var t : h2d.Tile;
+	//var tex : h3d.mat.Texture;
+
+	public static function check() {
+		return macro null;
+	}
+}
+
+#if !macro
+class ExtraTests extends hxd.App {
+
+	override function init() {
+		CheckMacroCompilation.check();
+	}
+
+	static function main() {
+		new ExtraTests();
+	}
+
+}
+ #end