Procházet zdrojové kódy

Reorganized object member variable and added prefetch to optimize cache hit during syncRec

TothBenoit před 10 měsíci
rodič
revize
a0b4e1ad61
1 změnil soubory, kde provedl 56 přidání a 54 odebrání
  1. 56 54
      h3d/scene/Object.hx

+ 56 - 54
h3d/scene/Object.hx

@@ -42,6 +42,9 @@ class Object {
 
 	var flags : ObjectFlags;
 	var lastFrame : Int;
+
+	public var currentAnimation(default, null) : h3d.anim.Animation;
+
 	var children : Array<Object>;
 
 	/**
@@ -54,42 +57,6 @@ class Object {
 	**/
 	public var numChildren(get, never) : Int;
 
-	/**
-		The name of the object, can be used to retrieve an object within a tree by using `getObjectByName` (default null)
-	**/
-	public var name : Null<String>;
-
-	/**
-		The x position of the object relative to its parent.
-	**/
-	public var x(default,set) : Float;
-
-	/**
-		The y position of the object relative to its parent.
-	**/
-	public var y(default, set) : Float;
-
-	/**
-		The z position of the object relative to its parent.
-	**/
-	public var z(default, set) : Float;
-
-	/**
-		The amount of scaling along the X axis of this object (default 1.0)
-	**/
-	public var scaleX(default,set) : Float;
-
-	/**
-		The amount of scaling along the Y axis of this object (default 1.0)
-	**/
-	public var scaleY(default, set) : Float;
-
-	/**
-		The amount of scaling along the Z axis of this object (default 1.0)
-	**/
-	public var scaleZ(default,set) : Float;
-
-
 	/**
 		Is the object and its children are displayed on screen (default true).
 	**/
@@ -97,23 +64,6 @@ class Object {
 
 	var allocated(get,set) : Bool;
 
-	/**
-		Follow a given object or joint as if it was our parent. Ignore defaultTransform when set.
-	**/
-	public var follow(default, set) : Object;
-
-	/**
-		When follow is set, only follow the position and ignore both scale and rotation.
-	**/
-	public var followPositionOnly(get, set) : Bool;
-
-	/**
-		This is an additional optional transformation that is performed before other local transformations.
-		It is used by the animation system.
-	**/
-	public var defaultTransform(default, set) : h3d.Matrix;
-	public var currentAnimation(default, null) : h3d.anim.Animation;
-
 	/**
 		Inform that the object is not to be displayed and his animation doesn't have to be sync. Unlike visible, this doesn't apply to children unless inheritCulled is set to true.
 	**/
@@ -189,6 +139,36 @@ class Object {
 	**/
 	var cullingColliderInherited(get, set) : Bool;
 
+	/**
+		The x position of the object relative to its parent.
+	**/
+	public var x(default,set) : Float;
+
+	/**
+		The y position of the object relative to its parent.
+	**/
+	public var y(default, set) : Float;
+
+	/**
+		The z position of the object relative to its parent.
+	**/
+	public var z(default, set) : Float;
+
+	/**
+		The amount of scaling along the X axis of this object (default 1.0)
+	**/
+	public var scaleX(default,set) : Float;
+
+	/**
+		The amount of scaling along the Y axis of this object (default 1.0)
+	**/
+	public var scaleY(default, set) : Float;
+
+	/**
+		The amount of scaling along the Z axis of this object (default 1.0)
+	**/
+	public var scaleZ(default,set) : Float;
+
 	var absPos : h3d.Matrix;
 	var prevAbsPos : h3d.Matrix;
 	var prevAbsPosFrame : Int = NO_VELOCITY;
@@ -196,6 +176,27 @@ class Object {
 	var qRot : h3d.Quat;
 	var posChanged(get,set) : Bool;
 
+	/**
+		Follow a given object or joint as if it was our parent. Ignore defaultTransform when set.
+	**/
+	public var follow(default, set) : Object;
+
+	/**
+		When follow is set, only follow the position and ignore both scale and rotation.
+	**/
+	public var followPositionOnly(get, set) : Bool;
+
+	/**
+		This is an additional optional transformation that is performed before other local transformations.
+		It is used by the animation system.
+	**/
+	public var defaultTransform(default, set) : h3d.Matrix;
+
+	/**
+		The name of the object, can be used to retrieve an object within a tree by using `getObjectByName` (default null)
+	**/
+	public var name : Null<String>;
+
 	/**
 		Create a new empty object, and adds it to the parent object if not null.
 	**/
@@ -734,7 +735,7 @@ class Object {
 
 	function syncRec( ctx : RenderContext ) {
 		#if sceneprof h3d.impl.SceneProf.mark(this); #end
-
+		#if heaps_prefetch untyped $prefetch(children.length, 2); #end
 		if( currentAnimation != null ) {
 			var old = parent;
 			var dt = ctx.elapsedTime;
@@ -782,6 +783,7 @@ class Object {
 				break;
 			if( c.lastFrame != ctx.frame ) {
 				if( changed ) c.posChanged = true;
+				#if heaps_prefetch untyped $prefetch(children[p+1], 2); #end
 				c.syncRec(ctx);
 			}
 			// if the object was removed, let's restart again.