Explorar o código

Std.downcast for haxe4

Nicolas Cannasse %!s(int64=6) %!d(string=hai) anos
pai
achega
0a381a60d1

+ 1 - 1
h2d/Drawable.hx

@@ -149,7 +149,7 @@ class Drawable extends Object {
 	**/
 	**/
 	public function getShader< T:hxsl.Shader >( stype : Class<T> ) : T {
 	public function getShader< T:hxsl.Shader >( stype : Class<T> ) : T {
 		if (shaders != null) for( s in shaders ) {
 		if (shaders != null) for( s in shaders ) {
-			var s = Std.instance(s, stype);
+			var s = hxd.impl.Api.downcast(s, stype);
 			if( s != null )
 			if( s != null )
 				return s;
 				return s;
 		}
 		}

+ 1 - 1
h2d/Interactive.hx

@@ -87,7 +87,7 @@ class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
 		parentMask = null;
 		parentMask = null;
 		var p = parent;
 		var p = parent;
 		while( p != null ) {
 		while( p != null ) {
-			var m = Std.instance(p, Mask);
+			var m = hxd.impl.Api.downcast(p, Mask);
 			if( m != null ) {
 			if( m != null ) {
 				parentMask = m;
 				parentMask = m;
 				break;
 				break;

+ 2 - 2
h2d/KeyFrames.hx

@@ -97,7 +97,7 @@ class KeyFrames extends Mask {
 
 
 	public function set_smooth( v : Bool ) : Bool {
 	public function set_smooth( v : Bool ) : Bool {
 		for( l in layers ){
 		for( l in layers ){
-			var bmp = Std.instance(l.spr, h2d.Bitmap);
+			var bmp = hxd.impl.Api.downcast(l.spr, h2d.Bitmap);
 			if( bmp != null )
 			if( bmp != null )
 				bmp.smooth = v;
 				bmp.smooth = v;
 		}
 		}
@@ -201,7 +201,7 @@ class KeyFrames extends Mask {
 
 
 		switch( f.property ) {
 		switch( f.property ) {
 		case AnchorPoint:
 		case AnchorPoint:
-			var bmp = Std.instance(l.spr, h2d.Bitmap);
+			var bmp = hxd.impl.Api.downcast(l.spr, h2d.Bitmap);
 			if( bmp != null ) {
 			if( bmp != null ) {
 				bmp.tile.dx = -calcValue(0);
 				bmp.tile.dx = -calcValue(0);
 				bmp.tile.dy = -calcValue(1);
 				bmp.tile.dy = -calcValue(1);

+ 1 - 1
h2d/Mask.hx

@@ -27,7 +27,7 @@ class Mask extends Object {
 		parentMask = null;
 		parentMask = null;
 		var p = parent;
 		var p = parent;
 		while( p != null ) {
 		while( p != null ) {
-			var m = Std.instance(p, Mask);
+			var m = hxd.impl.Api.downcast(p, Mask);
 			if( m != null ) {
 			if( m != null ) {
 				parentMask = m;
 				parentMask = m;
 				break;
 				break;

+ 1 - 1
h2d/Object.hx

@@ -300,7 +300,7 @@ class Object {
 	public function getScene() : Scene {
 	public function getScene() : Scene {
 		var p = this;
 		var p = this;
 		while( p.parent != null ) p = p.parent;
 		while( p.parent != null ) p = p.parent;
-		return Std.instance(p, Scene);
+		return hxd.impl.Api.downcast(p, Scene);
 	}
 	}
 
 
 	function set_visible(b) {
 	function set_visible(b) {

+ 18 - 18
h2d/Scene.hx

@@ -18,7 +18,7 @@ enum ScaleModeAlign {
 }
 }
 
 
 /**
 /**
-	Scaling mode of the 2D Scene.  
+	Scaling mode of the 2D Scene.
 	See `ScaleMode2D` sample for showcase.
 	See `ScaleMode2D` sample for showcase.
 **/
 **/
 enum ScaleMode {
 enum ScaleMode {
@@ -34,34 +34,34 @@ enum ScaleMode {
 	Stretch(width : Int, height : Int);
 	Stretch(width : Int, height : Int);
 
 
 	/**
 	/**
-		Sets constant scene size and upscales it with preserving aspect-ratio to fit the window.  
-		If `integerScale` is `true` - scaling will be performed  with only integer increments (1x, 2x, 3x, ...). Default: `false`  
-		`horizontalAlign` controls viewport anchoring horizontally. Accepted values are `Left`, `Center` and `Right`. Default: `Center`  
-		`verticalAlign` controls viewport anchoring vertically. Accepted values are `Top`, `Center` and `Bottom`. Default: `Center`  
+		Sets constant scene size and upscales it with preserving aspect-ratio to fit the window.
+		If `integerScale` is `true` - scaling will be performed  with only integer increments (1x, 2x, 3x, ...). Default: `false`
+		`horizontalAlign` controls viewport anchoring horizontally. Accepted values are `Left`, `Center` and `Right`. Default: `Center`
+		`verticalAlign` controls viewport anchoring vertically. Accepted values are `Top`, `Center` and `Bottom`. Default: `Center`
 		With `800x600` window, `LetterBox(320, 260)` will result in center-aligned Scene of size `320x260` upscaled to fit into screen.
 		With `800x600` window, `LetterBox(320, 260)` will result in center-aligned Scene of size `320x260` upscaled to fit into screen.
 	**/
 	**/
 	LetterBox(width : Int, height : Int, ?integerScale : Bool, ?horizontalAlign : ScaleModeAlign, ?verticalAlign : ScaleModeAlign);
 	LetterBox(width : Int, height : Int, ?integerScale : Bool, ?horizontalAlign : ScaleModeAlign, ?verticalAlign : ScaleModeAlign);
 
 
 	/**
 	/**
 		Sets constant Scene size, scale and alignment. Does not perform any adaptation to the screen apart from alignment.
 		Sets constant Scene size, scale and alignment. Does not perform any adaptation to the screen apart from alignment.
-		`horizontalAlign` controls viewport anchoring horizontally. Accepted values are `Left`, `Center` and `Right`. Default: `Center`  
-		`verticalAlign` controls viewport anchoring vertically. Accepted values are `Top`, `Center` and `Bottom`. Default: `Center`  
+		`horizontalAlign` controls viewport anchoring horizontally. Accepted values are `Left`, `Center` and `Right`. Default: `Center`
+		`verticalAlign` controls viewport anchoring vertically. Accepted values are `Top`, `Center` and `Bottom`. Default: `Center`
 		With `800x600` window, `Fixed(200, 150, 2, Left, Center)` will result in Scene size of `200x150`, and visually upscaled to `400x300`, and aligned to middle-left of the window.
 		With `800x600` window, `Fixed(200, 150, 2, Left, Center)` will result in Scene size of `200x150`, and visually upscaled to `400x300`, and aligned to middle-left of the window.
 	**/
 	**/
 	Fixed(width : Int, height: Int, zoom : Float, ?horizontalAlign : ScaleModeAlign, ?verticalAlign : ScaleModeAlign);
 	Fixed(width : Int, height: Int, zoom : Float, ?horizontalAlign : ScaleModeAlign, ?verticalAlign : ScaleModeAlign);
 
 
 	/**
 	/**
-		Upscales/downscales Scene according to `level` and matches Scene size to `ceil(window size / level)`.  
+		Upscales/downscales Scene according to `level` and matches Scene size to `ceil(window size / level)`.
 		With `800x600` window, `Zoom(2)` will result in `400x300` Scene size upscaled to fill entire window.
 		With `800x600` window, `Zoom(2)` will result in `400x300` Scene size upscaled to fill entire window.
 	**/
 	**/
 	Zoom(level : Float);
 	Zoom(level : Float);
 
 
 	/**
 	/**
-		Ensures that Scene size will be of minimum specified size.  
+		Ensures that Scene size will be of minimum specified size.
 		Automatically calculates zoom level based on provided size according to `min(window width / min width, window height / min height)`, then applies same scaling as `Zoom(level)`.
 		Automatically calculates zoom level based on provided size according to `min(window width / min width, window height / min height)`, then applies same scaling as `Zoom(level)`.
-		Behavior is similiar to LetterBox, however instead of letterboxing effect, Scene size will change to cover the letterboxed parts.  
-		`minWidth` or `minHeight` can be set to `0` in order to force scaling adjustment account only for either horizontal of vertical window size.  
-		If `integerScale` is `true` - scaling will be performed  with only integer increments (1x, 2x, 3x, ...). Default: `false`  
+		Behavior is similiar to LetterBox, however instead of letterboxing effect, Scene size will change to cover the letterboxed parts.
+		`minWidth` or `minHeight` can be set to `0` in order to force scaling adjustment account only for either horizontal of vertical window size.
+		If `integerScale` is `true` - scaling will be performed  with only integer increments (1x, 2x, 3x, ...). Default: `false`
 		With `800x600` window, `AutoZoom(320, 260, false)` will result in Scene size of `347x260`. `AutoZoom(320, 260, true)` will result in size of `400x300`.
 		With `800x600` window, `AutoZoom(320, 260, false)` will result in Scene size of `347x260`. `AutoZoom(320, 260, true)` will result in size of `400x300`.
 	**/
 	**/
 	AutoZoom(minWidth : Int, minHeight : Int, ?integerScaling : Bool);
 	AutoZoom(minWidth : Int, minHeight : Int, ?integerScaling : Bool);
@@ -83,22 +83,22 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 	public var height(default, null) : Int;
 	public var height(default, null) : Int;
 
 
 	/**
 	/**
-		Horizontal viewport offset relative to top-left corner of the window. Can change if the screen gets resized or `scaleMode` changes.  
+		Horizontal viewport offset relative to top-left corner of the window. Can change if the screen gets resized or `scaleMode` changes.
 		Offset is in internal Scene resolution pixels.
 		Offset is in internal Scene resolution pixels.
 	**/
 	**/
 	public var viewportX(default, null) : Float;
 	public var viewportX(default, null) : Float;
 	/**
 	/**
-		Vertical viewport offset relative to top-left corner of the window. Can change if the screen gets resized or `scaleMode` changes.  
+		Vertical viewport offset relative to top-left corner of the window. Can change if the screen gets resized or `scaleMode` changes.
 		Offset is in internal Scene resolution pixels.
 		Offset is in internal Scene resolution pixels.
 	**/
 	**/
 	public var viewportY(default, null) : Float;
 	public var viewportY(default, null) : Float;
 	/**
 	/**
-		Physical vertical viewport offset relative to the center of the window. Assigned if the screen gets resized or `scaleMode` changes.  
+		Physical vertical viewport offset relative to the center of the window. Assigned if the screen gets resized or `scaleMode` changes.
 		Offset is in internal Scene resolution pixels.
 		Offset is in internal Scene resolution pixels.
 	**/
 	**/
 	public var offsetX : Float;
 	public var offsetX : Float;
 	/**
 	/**
-		Physical horizontal viewport offset relative to the center of the window. Assigned if the screen gets resized or `scaleMode` changes.  
+		Physical horizontal viewport offset relative to the center of the window. Assigned if the screen gets resized or `scaleMode` changes.
 		Offset is in internal Scene resolution pixels.
 		Offset is in internal Scene resolution pixels.
 	**/
 	**/
 	public var offsetY : Float;
 	public var offsetY : Float;
@@ -132,7 +132,7 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 	/**
 	/**
 		Scene scaling mode. ( default : Fill )
 		Scene scaling mode. ( default : Fill )
 		Important thing to keep in mind - Scene does not clip rendering to it's scaled size and
 		Important thing to keep in mind - Scene does not clip rendering to it's scaled size and
-		graphics can render outside of it. However `drawTile` does check for those bounds and 
+		graphics can render outside of it. However `drawTile` does check for those bounds and
 		will clip out tiles that are outside of the scene bounds.
 		will clip out tiles that are outside of the scene bounds.
 	**/
 	**/
 	public var scaleMode(default, set) : ScaleMode = Resize;
 	public var scaleMode(default, set) : ScaleMode = Resize;
@@ -561,7 +561,7 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 		var f = events.getFocus();
 		var f = events.getFocus();
 		if( f == null )
 		if( f == null )
 			return null;
 			return null;
-		var i = Std.instance(f, h2d.Interactive);
+		var i = hxd.impl.Api.downcast(f, h2d.Interactive);
 		if( i == null )
 		if( i == null )
 			return null;
 			return null;
 		return interactive[interactive.indexOf(i)];
 		return interactive[interactive.indexOf(i)];

+ 1 - 1
h3d/anim/Animation.hx

@@ -156,7 +156,7 @@ class Animation implements hxd.impl.Serializable {
 				objects.remove(a);
 				objects.remove(a);
 				continue;
 				continue;
 			}
 			}
-			var joint = Std.instance(obj, h3d.scene.Skin.Joint);
+			var joint = hxd.impl.Api.downcast(obj, h3d.scene.Skin.Joint);
 			if( joint != null ) {
 			if( joint != null ) {
 				currentSkin = cast joint.parent;
 				currentSkin = cast joint.parent;
 				a.targetSkin = currentSkin;
 				a.targetSkin = currentSkin;

+ 1 - 1
h3d/anim/BufferAnimation.hx

@@ -81,7 +81,7 @@ class BufferAnimation extends Animation {
 		if( a == null )
 		if( a == null )
 			a = new BufferAnimation(name, frameCount, sampling);
 			a = new BufferAnimation(name, frameCount, sampling);
 		super.clone(a);
 		super.clone(a);
-		var la = Std.instance(a, BufferAnimation);
+		var la = hxd.impl.Api.downcast(a, BufferAnimation);
 		la.setData(data, stride);
 		la.setData(data, stride);
 		return a;
 		return a;
 	}
 	}

+ 1 - 1
h3d/mat/MaterialDatabase.hx

@@ -26,7 +26,7 @@ class MaterialDatabase {
 	function saveData( model : hxd.res.Resource, data : Dynamic ) {
 	function saveData( model : hxd.res.Resource, data : Dynamic ) {
 		var file = getFilePath(model);
 		var file = getFilePath(model);
 		#if (sys || nodejs)
 		#if (sys || nodejs)
-		var fs = Std.instance(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
+		var fs = hxd.impl.Api.downcast(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
 		if( fs != null && !haxe.io.Path.isAbsolute(file) )
 		if( fs != null && !haxe.io.Path.isAbsolute(file) )
 			file = fs.baseDir + file;
 			file = fs.baseDir + file;
 		if( data == null )
 		if( data == null )

+ 1 - 1
h3d/mat/Pass.hx

@@ -233,7 +233,7 @@ class Pass implements hxd.impl.Serializable {
 	public function getShader< T:hxsl.Shader >(t:Class<T>) : T {
 	public function getShader< T:hxsl.Shader >(t:Class<T>) : T {
 		var s = shaders;
 		var s = shaders;
 		while( s != parentShaders ) {
 		while( s != parentShaders ) {
-			var sh = Std.instance(s.s, t);
+			var sh = hxd.impl.Api.downcast(s.s, t);
 			if( sh != null )
 			if( sh != null )
 				return sh;
 				return sh;
 			s = s.next;
 			s = s.next;

+ 1 - 1
h3d/pass/ScreenFx.hx

@@ -55,7 +55,7 @@ class ScreenFx<T:h3d.shader.ScreenShader> {
 
 
 	public function getShader<T:hxsl.Shader>(cl:Class<T>) : T {
 	public function getShader<T:hxsl.Shader>(cl:Class<T>) : T {
 		for( s in shaders ) {
 		for( s in shaders ) {
-			var si = Std.instance(s, cl);
+			var si = hxd.impl.Api.downcast(s, cl);
 			if( si != null ) return si;
 			if( si != null ) return si;
 		}
 		}
 		return null;
 		return null;

+ 7 - 7
h3d/scene/Object.hx

@@ -364,7 +364,7 @@ class Object implements hxd.impl.Serializable {
 	**/
 	**/
 	public function getMeshes( ?out : Array<Mesh> ) {
 	public function getMeshes( ?out : Array<Mesh> ) {
 		if( out == null ) out = [];
 		if( out == null ) out = [];
-		var m = Std.instance(this, Mesh);
+		var m = hxd.impl.Api.downcast(this, Mesh);
 		if( m != null ) out.push(m);
 		if( m != null ) out.push(m);
 		for( c in children )
 		for( c in children )
 			c.getMeshes(out);
 			c.getMeshes(out);
@@ -375,7 +375,7 @@ class Object implements hxd.impl.Serializable {
 		Search for an mesh recursively by name, return null if not found.
 		Search for an mesh recursively by name, return null if not found.
 	**/
 	**/
 	public function getMeshByName( name : String) {
 	public function getMeshByName( name : String) {
-		return Std.instance(getObjectByName(name), Mesh);
+		return hxd.impl.Api.downcast(getObjectByName(name), Mesh);
 	}
 	}
 
 
 	/**
 	/**
@@ -466,7 +466,7 @@ class Object implements hxd.impl.Serializable {
 		if( !visible || (culled && inheritCulled) )
 		if( !visible || (culled && inheritCulled) )
 			return;
 			return;
 		if( !culled ) {
 		if( !culled ) {
-			var m = Std.instance(this, Mesh);
+			var m = hxd.impl.Api.downcast(this, Mesh);
 			if( m != null ) callb(m);
 			if( m != null ) callb(m);
 		}
 		}
 		for( o in children )
 		for( o in children )
@@ -525,7 +525,7 @@ class Object implements hxd.impl.Serializable {
 	public function getScene() {
 	public function getScene() {
 		var p = this;
 		var p = this;
 		while( p.parent != null ) p = p.parent;
 		while( p.parent != null ) p = p.parent;
-		return Std.instance(p, Scene);
+		return hxd.impl.Api.downcast(p, Scene);
 	}
 	}
 
 
 	/**
 	/**
@@ -540,14 +540,14 @@ class Object implements hxd.impl.Serializable {
 		Tell if the object is a Mesh.
 		Tell if the object is a Mesh.
 	**/
 	**/
 	public inline function isMesh() {
 	public inline function isMesh() {
-		return Std.instance(this, Mesh) != null;
+		return hxd.impl.Api.downcast(this, Mesh) != null;
 	}
 	}
 
 
 	/**
 	/**
 		If the object is a Mesh, return the corresponding Mesh. If not, throw an exception.
 		If the object is a Mesh, return the corresponding Mesh. If not, throw an exception.
 	**/
 	**/
 	public function toMesh() : Mesh {
 	public function toMesh() : Mesh {
-		var m = Std.instance(this, Mesh);
+		var m = hxd.impl.Api.downcast(this, Mesh);
 		if( m != null )
 		if( m != null )
 			return m;
 			return m;
 		throw this + " is not a Mesh";
 		throw this + " is not a Mesh";
@@ -567,7 +567,7 @@ class Object implements hxd.impl.Serializable {
 		for( obj in children ) {
 		for( obj in children ) {
 			var c = obj.getCollider();
 			var c = obj.getCollider();
 			if( c == null ) continue;
 			if( c == null ) continue;
-			var cgrp = Std.instance(c, h3d.col.Collider.GroupCollider);
+			var cgrp = hxd.impl.Api.downcast(c, h3d.col.Collider.GroupCollider);
 			if( cgrp != null ) {
 			if( cgrp != null ) {
 				for( c in cgrp.colliders )
 				for( c in cgrp.colliders )
 					colliders.push(c);
 					colliders.push(c);

+ 1 - 1
h3d/scene/World.hx

@@ -532,7 +532,7 @@ class World extends Object {
 					c.buffers.set(g.m.bits, b);
 					c.buffers.set(g.m.bits, b);
 					initMaterial(b, g.m);
 					initMaterial(b, g.m);
 				}
 				}
-				var p = Std.instance(b.primitive, h3d.prim.BigPrimitive);
+				var p = hxd.impl.Api.downcast(b.primitive, h3d.prim.BigPrimitive);
 
 
 				if(e.optimized) {
 				if(e.optimized) {
 					var m = e.transform;
 					var m = e.transform;

+ 2 - 2
h3d/scene/fwd/LightSystem.hx

@@ -21,11 +21,11 @@ class LightSystem extends h3d.scene.LightSystem {
 	}
 	}
 
 
 	function get_additiveLighting() {
 	function get_additiveLighting() {
-		return Std.instance(ambientShader,h3d.shader.AmbientLight).additive;
+		return hxd.impl.Api.downcast(ambientShader,h3d.shader.AmbientLight).additive;
 	}
 	}
 
 
 	function set_additiveLighting(b) {
 	function set_additiveLighting(b) {
-		return Std.instance(ambientShader,h3d.shader.AmbientLight).additive = b;
+		return hxd.impl.Api.downcast(ambientShader,h3d.shader.AmbientLight).additive = b;
 	}
 	}
 
 
 	override function initLights(ctx) {
 	override function initLights(ctx) {

+ 2 - 2
h3d/scene/pbr/LightSystem.hx

@@ -4,7 +4,7 @@ package h3d.scene.pbr;
 class LightSystem extends h3d.scene.LightSystem {
 class LightSystem extends h3d.scene.LightSystem {
 
 
 	override function computeLight( obj : h3d.scene.Object, shaders : hxsl.ShaderList ) : hxsl.ShaderList {
 	override function computeLight( obj : h3d.scene.Object, shaders : hxsl.ShaderList ) : hxsl.ShaderList {
-		var light = Std.instance(obj, h3d.scene.pbr.Light);
+		var light = hxd.impl.Api.downcast(obj, h3d.scene.pbr.Light);
 		if( light != null ) {
 		if( light != null ) {
 			shaders = ctx.allocShaderList(light.shader, shaders);
 			shaders = ctx.allocShaderList(light.shader, shaders);
 			if( light.shadows.shader != null && light.shadows.mode != None )
 			if( light.shadows.shader != null && light.shadows.mode != None )
@@ -26,7 +26,7 @@ class LightSystem extends h3d.scene.LightSystem {
 		var width = currentTarget == null ? ctx.engine.width : currentTarget.width;
 		var width = currentTarget == null ? ctx.engine.width : currentTarget.width;
 		var height = currentTarget == null ? ctx.engine.height : currentTarget.height;
 		var height = currentTarget == null ? ctx.engine.height : currentTarget.height;
 		while( plight != null ) {
 		while( plight != null ) {
-			var light = Std.instance(plight, h3d.scene.pbr.Light);
+			var light = hxd.impl.Api.downcast(plight, h3d.scene.pbr.Light);
 			if( light != null && light.primitive == null ) {
 			if( light != null && light.primitive == null ) {
 				if( light.shadows.shader != null ) lightPass.addShader(light.shadows.shader);
 				if( light.shadows.shader != null ) lightPass.addShader(light.shadows.shader);
 				lightPass.addShader(light.shader);
 				lightPass.addShader(light.shader);

+ 3 - 3
h3d/scene/pbr/Renderer.hx

@@ -206,7 +206,7 @@ class Renderer extends h3d.scene.Renderer {
 		if( !shadows )
 		if( !shadows )
 			passes.clear();
 			passes.clear();
 		while( light != null ) {
 		while( light != null ) {
-			var plight = Std.instance(light, h3d.scene.pbr.Light);
+			var plight = hxd.impl.Api.downcast(light, h3d.scene.pbr.Light);
 			if( plight != null ) ls.drawLight(plight, passes);
 			if( plight != null ) ls.drawLight(plight, passes);
 			light = light.next;
 			light = light.next;
 		}
 		}
@@ -222,7 +222,7 @@ class Renderer extends h3d.scene.Renderer {
 		var light = @:privateAccess ctx.lights;
 		var light = @:privateAccess ctx.lights;
 		var passes = get("shadow");
 		var passes = get("shadow");
 		while( light != null ) {
 		while( light != null ) {
-			var plight = Std.instance(light, h3d.scene.pbr.Light);
+			var plight = hxd.impl.Api.downcast(light, h3d.scene.pbr.Light);
 			if( plight != null ) {
 			if( plight != null ) {
 				plight.shadows.setContext(ctx);
 				plight.shadows.setContext(ctx);
 				plight.shadows.computeStatic(passes);
 				plight.shadows.computeStatic(passes);
@@ -246,7 +246,7 @@ class Renderer extends h3d.scene.Renderer {
 		ctx.setGlobal("occlusionMap",{ texture : pbr, channel : hxsl.Channel.B });
 		ctx.setGlobal("occlusionMap",{ texture : pbr, channel : hxsl.Channel.B });
 		ctx.setGlobal("bloom",null);
 		ctx.setGlobal("bloom",null);
 
 
-		var ls = Std.instance(getLightSystem(), LightSystem);
+		var ls = hxd.impl.Api.downcast(getLightSystem(), LightSystem);
 		var count = ctx.engine.drawCalls;
 		var count = ctx.engine.drawCalls;
 		if( ls != null ) drawShadows(ls);
 		if( ls != null ) drawShadows(ls);
 		if( ctx.lightSystem != null ) ctx.lightSystem.drawPasses = ctx.engine.drawCalls - count;
 		if( ctx.lightSystem != null ) ctx.lightSystem.drawPasses = ctx.engine.drawCalls - count;

+ 2 - 2
hxd/App.hx

@@ -64,8 +64,8 @@ class App implements h3d.IDrawable {
 		If you call disposePrevious, it will call dispose() on the previous scene.
 		If you call disposePrevious, it will call dispose() on the previous scene.
 	**/
 	**/
 	public function setScene( scene : hxd.SceneEvents.InteractiveScene, disposePrevious = true ) {
 	public function setScene( scene : hxd.SceneEvents.InteractiveScene, disposePrevious = true ) {
-		var new2D = Std.instance(scene, h2d.Scene);
-		var new3D = Std.instance(scene, h3d.scene.Scene);
+		var new2D = hxd.impl.Api.downcast(scene, h2d.Scene);
+		var new3D = hxd.impl.Api.downcast(scene, h3d.scene.Scene);
 		if( new2D != null )
 		if( new2D != null )
 			sevents.removeScene(s2d);
 			sevents.removeScene(s2d);
 		if( new3D != null )
 		if( new3D != null )

+ 3 - 3
hxd/fmt/fbx/Library.hx

@@ -113,7 +113,7 @@ class Library extends BaseLibrary {
 			if( o.parent.isJoint )
 			if( o.parent.isJoint )
 				o.obj.follow = scene.getObjectByName(o.parent.joint.name);
 				o.obj.follow = scene.getObjectByName(o.parent.joint.name);
 
 
-			var skin = Std.instance(o.obj, h3d.scene.Skin);
+			var skin = hxd.impl.Api.downcast(o.obj, h3d.scene.Skin);
 			if( skin == null ) continue;
 			if( skin == null ) continue;
 			var rootJoints = [];
 			var rootJoints = [];
 			for( j in o.childs )
 			for( j in o.childs )
@@ -126,7 +126,7 @@ class Library extends BaseLibrary {
 				var m = o2.obj.toMesh();
 				var m = o2.obj.toMesh();
 				if( m.primitive != skinData.primitive ) continue;
 				if( m.primitive != skinData.primitive ) continue;
 
 
-				var mt = Std.instance(m, h3d.scene.MultiMaterial);
+				var mt = hxd.impl.Api.downcast(m, h3d.scene.MultiMaterial);
 				skin.materials = mt == null ? [m.material] : mt.materials;
 				skin.materials = mt == null ? [m.material] : mt.materials;
 				skin.material = skin.materials[0];
 				skin.material = skin.materials[0];
 				m.remove();
 				m.remove();
@@ -135,7 +135,7 @@ class Library extends BaseLibrary {
 			}
 			}
 			// set skin after materials
 			// set skin after materials
 			if( skinData.boundJoints.length > maxBonesPerSkin ) {
 			if( skinData.boundJoints.length > maxBonesPerSkin ) {
-				var model = Std.instance(skinData.primitive, h3d.prim.FBXModel);
+				var model = hxd.impl.Api.downcast(skinData.primitive, h3d.prim.FBXModel);
 				var idx = model.geom.getIndexes();
 				var idx = model.geom.getIndexes();
 				skinData.split(maxBonesPerSkin, [for( i in idx.idx) idx.vidx[i]], model.multiMaterial ? model.geom.getMaterialByTriangle() : null);
 				skinData.split(maxBonesPerSkin, [for( i in idx.idx) idx.vidx[i]], model.multiMaterial ? model.geom.getMaterialByTriangle() : null);
 			}
 			}

+ 2 - 2
hxd/fmt/hsd/Serializer.hx

@@ -45,7 +45,7 @@ class Serializer extends hxbit.Serializer {
 			}
 			}
 			return true;
 			return true;
 		}
 		}
-		var tch = Std.instance(t, h3d.mat.TextureChannels);
+		var tch = hxd.impl.Api.downcast(t, h3d.mat.TextureChannels);
 		if( tch != null ) {
 		if( tch != null ) {
 			addInt(3);
 			addInt(3);
 			var channels = @:privateAccess tch.channels;
 			var channels = @:privateAccess tch.channels;
@@ -161,7 +161,7 @@ class Serializer extends hxbit.Serializer {
 		} else
 		} else
 			s = Type.createEmptyInstance(cl);
 			s = Type.createEmptyInstance(cl);
 		@:privateAccess s.initialize();
 		@:privateAccess s.initialize();
-		var sdyn = Std.instance(s, hxsl.DynamicShader);
+		var sdyn = hxd.impl.Api.downcast(s, hxsl.DynamicShader);
 		for( v in @:privateAccess s.shader.data.vars ) {
 		for( v in @:privateAccess s.shader.data.vars ) {
 			if( !canSerializeVar(v) ) continue;
 			if( !canSerializeVar(v) ) continue;
 			var val : Dynamic = getShaderVar(v, s);
 			var val : Dynamic = getShaderVar(v, s);

+ 1 - 1
hxd/fmt/pak/Loader.hx

@@ -16,7 +16,7 @@ class Loader extends h2d.Object {
 		this.onDone = onDone;
 		this.onDone = onDone;
 		if( hxd.res.Loader.currentInstance == null )
 		if( hxd.res.Loader.currentInstance == null )
 			hxd.res.Loader.currentInstance = new hxd.res.Loader(new FileSystem());
 			hxd.res.Loader.currentInstance = new hxd.res.Loader(new FileSystem());
-		fs = Std.instance(hxd.res.Loader.currentInstance.fs, FileSystem);
+		fs = hxd.impl.Api.downcast(hxd.res.Loader.currentInstance.fs, FileSystem);
 		if( fs == null )
 		if( fs == null )
 			throw "Can only use loader with PAK file system";
 			throw "Can only use loader with PAK file system";
 		hxd.System.setLoop(render);
 		hxd.System.setLoop(render);

+ 13 - 0
hxd/impl/Api.hx

@@ -0,0 +1,13 @@
+package hxd.impl;
+
+class Api {
+
+	public static inline function downcast<T:{},S:T>( value : T, c : Class<S> ) : S {
+		#if haxe4
+		return Std.downcast(value,c);
+		#else
+		return Std.instance(value,c);
+		#end
+	}
+
+}

+ 1 - 1
hxd/inspect/PropManager.hx

@@ -230,7 +230,7 @@ class PropManager extends vdom.Client {
 	public function getResPath() {
 	public function getResPath() {
 		if( cachedResPath != null )
 		if( cachedResPath != null )
 			return cachedResPath;
 			return cachedResPath;
-		var lfs = Std.instance(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
+		var lfs = hxd.impl.Api.downcast(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
 		if( lfs != null )
 		if( lfs != null )
 			cachedResPath = lfs.baseDir;
 			cachedResPath = lfs.baseDir;
 		else {
 		else {

+ 3 - 3
hxd/inspect/ScenePanel.hx

@@ -200,15 +200,15 @@ private class CustomSceneProps extends SceneProps {
 
 
 	override function getObjectProps( o : h3d.scene.Object ) {
 	override function getObjectProps( o : h3d.scene.Object ) {
 		var props = super.getObjectProps(o);
 		var props = super.getObjectProps(o);
-		var world = Std.instance(o, h3d.scene.World);
+		var world = hxd.impl.Api.downcast(o, h3d.scene.World);
 		var worldObject = world == null ? o : null;
 		var worldObject = world == null ? o : null;
 		if( world == null ) {
 		if( world == null ) {
-			world = Std.instance(o.parent, h3d.scene.World);
+			world = hxd.impl.Api.downcast(o.parent, h3d.scene.World);
 			if( world != null && !Lambda.exists(@:privateAccess world.allChunks, function(c) return c.root == o) )
 			if( world != null && !Lambda.exists(@:privateAccess world.allChunks, function(c) return c.root == o) )
 				world = null;
 				world = null;
 		}
 		}
 		if( world == null && o.parent != null ) {
 		if( world == null && o.parent != null ) {
-			world = Std.instance(o.parent.parent, h3d.scene.World);
+			world = hxd.impl.Api.downcast(o.parent.parent, h3d.scene.World);
 			if( world != null && !Lambda.exists(@:privateAccess world.allChunks, function(c) return c.root == o.parent) )
 			if( world != null && !Lambda.exists(@:privateAccess world.allChunks, function(c) return c.root == o.parent) )
 				world = null;
 				world = null;
 		}
 		}

+ 10 - 10
hxd/inspect/SceneProps.hx

@@ -81,7 +81,7 @@ class SceneProps {
 
 
 			var ls = scene.lightSystem;
 			var ls = scene.lightSystem;
 			var props = [];
 			var props = [];
-			var fls = Std.instance(ls, h3d.scene.fwd.LightSystem);
+			var fls = hxd.impl.Api.downcast(ls, h3d.scene.fwd.LightSystem);
 			if( fls != null )
 			if( fls != null )
 				props.push(PGroup("LightSystem",[
 				props.push(PGroup("LightSystem",[
 					PRange("maxLightsPerObject", 0, 10, function() return fls.maxLightsPerObject, function(s) fls.maxLightsPerObject = Std.int(s), 1),
 					PRange("maxLightsPerObject", 0, 10, function() return fls.maxLightsPerObject, function(s) fls.maxLightsPerObject = Std.int(s), 1),
@@ -249,13 +249,13 @@ class SceneProps {
 		props.push(PColor("color", false, function() return l.color, function(c) l.color.load(c)));
 		props.push(PColor("color", false, function() return l.color, function(c) l.color.load(c)));
 		props.push(PRange("priority", 0, 10, function() return l.priority, function(p) l.priority = Std.int(p),1));
 		props.push(PRange("priority", 0, 10, function() return l.priority, function(p) l.priority = Std.int(p),1));
 		props.push(PBool("enableSpecular", function() return l.enableSpecular, function(b) l.enableSpecular = b));
 		props.push(PBool("enableSpecular", function() return l.enableSpecular, function(b) l.enableSpecular = b));
-		var dl = Std.instance(l, h3d.scene.fwd.DirLight);
+		var dl = hxd.impl.Api.downcast(l, h3d.scene.fwd.DirLight);
 		if( dl != null )
 		if( dl != null )
 			props.push(PFloats("direction", function() {
 			props.push(PFloats("direction", function() {
 				var dir = dl.getDirection();
 				var dir = dl.getDirection();
 				return [dl.x, dl.y, dl.z];
 				return [dl.x, dl.y, dl.z];
 			}, function(fl) dl.setDirection(new h3d.Vector(fl[0], fl[1], fl[2]))));
 			}, function(fl) dl.setDirection(new h3d.Vector(fl[0], fl[1], fl[2]))));
-		var pl = Std.instance(l, h3d.scene.fwd.PointLight);
+		var pl = hxd.impl.Api.downcast(l, h3d.scene.fwd.PointLight);
 		if( pl != null )
 		if( pl != null )
 			props.push(PFloats("params", function() return [pl.params.x, pl.params.y, pl.params.z], function(fl) pl.params.set(fl[0], fl[1], fl[2], fl[3])));
 			props.push(PFloats("params", function() return [pl.params.x, pl.params.y, pl.params.z], function(fl) pl.params.set(fl[0], fl[1], fl[2], fl[3])));
 		return PGroup("Light", props);
 		return PGroup("Light", props);
@@ -269,17 +269,17 @@ class SceneProps {
 		props.push(PBool("visible", function() return o.visible, function(v) o.visible = v));
 		props.push(PBool("visible", function() return o.visible, function(v) o.visible = v));
 
 
 		if( o.isMesh() ) {
 		if( o.isMesh() ) {
-			var multi = Std.instance(o, h3d.scene.MultiMaterial);
+			var multi = hxd.impl.Api.downcast(o, h3d.scene.MultiMaterial);
 			if( multi != null && multi.materials.length > 1 ) {
 			if( multi != null && multi.materials.length > 1 ) {
 				for( m in multi.materials )
 				for( m in multi.materials )
 					props.push(getMaterialProps(m));
 					props.push(getMaterialProps(m));
 			} else
 			} else
 				props.push(getMaterialProps(o.toMesh().material));
 				props.push(getMaterialProps(o.toMesh().material));
 		} else {
 		} else {
-			var c = Std.instance(o, h3d.scene.CustomObject);
+			var c = hxd.impl.Api.downcast(o, h3d.scene.CustomObject);
 			if( c != null )
 			if( c != null )
 				props.push(getMaterialProps(c.material));
 				props.push(getMaterialProps(c.material));
-			var l = Std.instance(o, h3d.scene.Light);
+			var l = hxd.impl.Api.downcast(o, h3d.scene.Light);
 			if( l != null )
 			if( l != null )
 				props.push(getLightProps(l));
 				props.push(getLightProps(l));
 		}
 		}
@@ -292,13 +292,13 @@ class SceneProps {
 			addDynamicProps(props, v);
 			addDynamicProps(props, v);
 			return props;
 			return props;
 		}
 		}
-		var s = Std.instance(v, hxsl.Shader);
+		var s = hxd.impl.Api.downcast(v, hxsl.Shader);
 		if( s != null )
 		if( s != null )
 			return [getShaderProps(s)];
 			return [getShaderProps(s)];
-		var o = Std.instance(v, h3d.scene.Object);
+		var o = hxd.impl.Api.downcast(v, h3d.scene.Object);
 		if( o != null )
 		if( o != null )
 			return getObjectProps(o);
 			return getObjectProps(o);
-		var s = Std.instance(v, hxsl.Shader);
+		var s = hxd.impl.Api.downcast(v, hxsl.Shader);
 		if( s != null )
 		if( s != null )
 			return [getShaderProps(s)];
 			return [getShaderProps(s)];
 		return null;
 		return null;
@@ -366,7 +366,7 @@ class SceneProps {
 
 
 	function getPassProps( p : h3d.pass.Base ) {
 	function getPassProps( p : h3d.pass.Base ) {
 		var props = [];
 		var props = [];
-		var def = Std.instance(p, h3d.pass.Default);
+		var def = hxd.impl.Api.downcast(p, h3d.pass.Default);
 		if( def == null ) return props;
 		if( def == null ) return props;
 
 
 		addDynamicProps(props, p);
 		addDynamicProps(props, p);

+ 1 - 1
hxd/res/Loader.hx

@@ -46,7 +46,7 @@ class Loader {
 			currentInstance = old;
 			currentInstance = old;
 			cache.set(path, res);
 			cache.set(path, res);
 		} else {
 		} else {
-			if( Std.instance(res,c) == null )
+			if( hxd.impl.Api.downcast(res,c) == null )
 				throw path+" has been reintrepreted from "+Type.getClass(res)+" to "+c;
 				throw path+" has been reintrepreted from "+Type.getClass(res)+" to "+c;
 		}
 		}
 		return res;
 		return res;

+ 1 - 1
hxd/snd/ChannelBase.hx

@@ -18,7 +18,7 @@ class ChannelBase {
 	public function getEffect<T:Effect>( etype : Class<T> ) : T {
 	public function getEffect<T:Effect>( etype : Class<T> ) : T {
 		if(effects == null) return null;  // Already released
 		if(effects == null) return null;  // Already released
 		for (e in effects) {
 		for (e in effects) {
-			var e = Std.instance(e, etype);
+			var e = hxd.impl.Api.downcast(e, etype);
 			if (e != null) return e;
 			if (e != null) return e;
 		}
 		}
 		return null;
 		return null;

+ 1 - 1
hxd/snd/openal/PitchDriver.hx

@@ -7,7 +7,7 @@ import hxd.snd.effect.Pitch;
 class PitchDriver extends EffectDriver<Pitch> {
 class PitchDriver extends EffectDriver<Pitch> {
 
 
 	override function apply(e : Pitch, source : SourceHandle) : Void {
 	override function apply(e : Pitch, source : SourceHandle) : Void {
-		AL.sourcef(source.inst, AL.PITCH, Std.instance(e, hxd.snd.effect.Pitch).value);
+		AL.sourcef(source.inst, AL.PITCH, hxd.impl.Api.downcast(e, hxd.snd.effect.Pitch).value);
 	}
 	}
 
 
 	override function unbind(e : Pitch, source : SourceHandle) : Void {
 	override function unbind(e : Pitch, source : SourceHandle) : Void {

+ 3 - 3
hxd/snd/openal/ReverbDriver.hx

@@ -17,7 +17,7 @@ class ReverbDriver extends hxd.snd.Driver.EffectDriver<Reverb> {
 		this.driver = driver;
 		this.driver = driver;
 		this.dryFilter = new LowPass();
 		this.dryFilter = new LowPass();
 	}
 	}
-	
+
 	override function acquire() : Void {
 	override function acquire() : Void {
 		// create effect
 		// create effect
 		var bytes = driver.getTmpBytes(4);
 		var bytes = driver.getTmpBytes(4);
@@ -70,7 +70,7 @@ class ReverbDriver extends hxd.snd.Driver.EffectDriver<Reverb> {
 		EFX.auxiliaryEffectSloti(slot, EFX.EFFECTSLOT_EFFECT, inst.toInt());
 		EFX.auxiliaryEffectSloti(slot, EFX.EFFECTSLOT_EFFECT, inst.toInt());
 		EFX.auxiliaryEffectSlotf(slot, EFX.EFFECTSLOT_GAIN, e.wetDryMix / 100.0);
 		EFX.auxiliaryEffectSlotf(slot, EFX.EFFECTSLOT_GAIN, e.wetDryMix / 100.0);
 
 
-		@:privateAccess 
+		@:privateAccess
 		e.retainTime = e.decayTime + e.reflectionsDelay + e.reverbDelay;
 		e.retainTime = e.decayTime + e.reflectionsDelay + e.reverbDelay;
 	}
 	}
 
 
@@ -80,7 +80,7 @@ class ReverbDriver extends hxd.snd.Driver.EffectDriver<Reverb> {
 	}
 	}
 
 
 	override function apply(e : Reverb, s : SourceHandle) : Void {
 	override function apply(e : Reverb, s : SourceHandle) : Void {
-		var e = Std.instance(e, hxd.snd.effect.Reverb);
+		var e = hxd.impl.Api.downcast(e, hxd.snd.effect.Reverb);
 		var send = s.getAuxiliarySend(e);
 		var send = s.getAuxiliarySend(e);
 		AL.source3i(s.inst, EFX.AUXILIARY_SEND_FILTER, slot.toInt(), send, EFX.FILTER_NULL);
 		AL.source3i(s.inst, EFX.AUXILIARY_SEND_FILTER, slot.toInt(), send, EFX.FILTER_NULL);
 	}
 	}

+ 1 - 1
hxd/snd/openal/SpatializationDriver.hx

@@ -17,7 +17,7 @@ class SpatializationDriver extends EffectDriver<Spatialization> {
 	}
 	}
 
 
 	override function apply(e : Spatialization, s : SourceHandle) : Void {
 	override function apply(e : Spatialization, s : SourceHandle) : Void {
-		var e = Std.instance(e, hxd.snd.effect.Spatialization);
+		var e = hxd.impl.Api.downcast(e, hxd.snd.effect.Spatialization);
 
 
 		AL.source3f(s.inst, AL.POSITION,  -e.position.x,  e.position.y,  e.position.z);
 		AL.source3f(s.inst, AL.POSITION,  -e.position.x,  e.position.y,  e.position.z);
 		AL.source3f(s.inst, AL.VELOCITY,  -e.velocity.x,  e.velocity.y,  e.velocity.z);
 		AL.source3f(s.inst, AL.VELOCITY,  -e.velocity.x,  e.velocity.y,  e.velocity.z);