Skip to content

Commit

Permalink
Reorganized object member variable and added prefetch to optimize cac…
Browse files Browse the repository at this point in the history
…he hit during syncRec
  • Loading branch information
TothBenoit committed Oct 25, 2024
1 parent 08011cd commit a0b4e1a
Showing 1 changed file with 56 additions and 54 deletions.
110 changes: 56 additions & 54 deletions h3d/scene/Object.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class Object {

var flags : ObjectFlags;
var lastFrame : Int;

public var currentAnimation(default, null) : h3d.anim.Animation;

var children : Array<Object>;

/**
Expand All @@ -54,66 +57,13 @@ 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).
**/
public var visible(get, set) : Bool;

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.
**/
Expand Down Expand Up @@ -189,13 +139,64 @@ 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;
var invPos : h3d.Matrix;
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.
**/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a0b4e1a

Please sign in to comment.