Prechádzať zdrojové kódy

added hxsl.Tools.evalConst

ncannasse 7 rokov pred
rodič
commit
46569b6749
2 zmenil súbory, kde vykonal 23 pridanie a 21 odobranie
  1. 22 0
      hxsl/Ast.hx
  2. 1 21
      tools/hxsl/Main.hx

+ 22 - 0
hxsl/Ast.hx

@@ -496,6 +496,28 @@ class Tools {
 		}
 	}
 
+	#if !macro
+	public static function evalConst( e : TExpr ) : Dynamic {
+		return switch( e.e ) {
+		case TConst(c):
+			switch( c ) {
+			case CNull: null;
+			case CBool(b): b;
+			case CInt(i): i;
+			case CFloat(f): f;
+			case CString(s): s;
+			}
+		case TCall({ e : TGlobal(Vec2 | Vec3 | Vec4) }, args):
+			var vals = [for( a in args ) evalConst(a)];
+			if( vals.length == 1 )
+				return new Types.Vec(vals[0], vals[0], vals[0], vals[0]);
+			return new Types.Vec(vals[0], vals[1], vals[2], vals[3]);
+		default:
+			throw "Unhandled constant init " + Printer.toString(e);
+		}
+	}
+	#end
+
 }
 
 class Tools2 {

+ 1 - 21
tools/hxsl/Main.hx

@@ -94,26 +94,6 @@ class Main {
 		}
 	}
 
-	function evalConst( e : hxsl.Ast.TExpr ) : Dynamic {
-		return switch( e.e ) {
-		case TConst(c):
-			switch( c ) {
-			case CNull: null;
-			case CBool(b): b;
-			case CInt(i): i;
-			case CFloat(f): f;
-			case CString(s): s;
-			}
-		case TCall({ e : TGlobal(Vec2 | Vec3 | Vec4) }, args):
-			var vals = [for( a in args ) evalConst(a)];
-			if( vals.length == 1 )
-				return new h3d.Vector(vals[0], vals[0], vals[0], vals[0]);
-			return new h3d.Vector(vals[0], vals[1], vals[2], vals[3]);
-		default:
-			throw "Unhandled constant init " + hxsl.Printer.toString(e);
-		}
-	}
-
 	function rebuild() {
 		var code = text.value;
 		var output = out.value;
@@ -151,7 +131,7 @@ class Main {
 			@:privateAccess shared.initialize();
 			var shader = new hxsl.DynamicShader(shared);
 			for( i in checker.inits )
-				shader.hscriptSet(i.v.name, evalConst(i.e));
+				shader.hscriptSet(i.v.name, hxsl.Ast.Tools.evalConst(i.e));
 			for( v in Reflect.fields(vars) )
 				shader.hscriptSet(v, Reflect.field(vars, v));