Update leenkx/Sources/leenkx/trait/physics/bullet/PhysicsWorld.hx
This commit is contained in:
@ -7,7 +7,6 @@ import iron.system.Time;
|
|||||||
import iron.math.Vec4;
|
import iron.math.Vec4;
|
||||||
import iron.math.Quat;
|
import iron.math.Quat;
|
||||||
import iron.math.RayCaster;
|
import iron.math.RayCaster;
|
||||||
import iron.object.Object;
|
|
||||||
|
|
||||||
class Hit {
|
class Hit {
|
||||||
|
|
||||||
@ -73,10 +72,6 @@ class PhysicsWorld extends Trait {
|
|||||||
public var convexHitNormalWorld = new Vec4();
|
public var convexHitNormalWorld = new Vec4();
|
||||||
var pairCache: Bool = false;
|
var pairCache: Bool = false;
|
||||||
|
|
||||||
// Performance optimization: Global RigidBody trait cache
|
|
||||||
public static var rigidBodyCache: Map<Object, RigidBody> = new Map();
|
|
||||||
public static var cacheObjectRefs: Map<Object, Int> = new Map(); // Track trait counts
|
|
||||||
|
|
||||||
static var nullvec = true;
|
static var nullvec = true;
|
||||||
static var vec1: bullet.Bt.Vector3 = null;
|
static var vec1: bullet.Bt.Vector3 = null;
|
||||||
static var vec2: bullet.Bt.Vector3 = null;
|
static var vec2: bullet.Bt.Vector3 = null;
|
||||||
@ -150,36 +145,10 @@ class PhysicsWorld extends Trait {
|
|||||||
|
|
||||||
iron.Scene.active.notifyOnRemove(function() {
|
iron.Scene.active.notifyOnRemove(function() {
|
||||||
sceneRemoved = true;
|
sceneRemoved = true;
|
||||||
|
leenkx.trait.physics.PhysicsCache.clearCache();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function getCachedRigidBody(object: Object): RigidBody {
|
|
||||||
if (object == null) return null;
|
|
||||||
|
|
||||||
var shouldUpdate = false;
|
|
||||||
var cachedTraitCount = cacheObjectRefs.get(object);
|
|
||||||
|
|
||||||
if (cachedTraitCount == null || cachedTraitCount != object.traits.length) {
|
|
||||||
shouldUpdate = true;
|
|
||||||
} else if (rigidBodyCache.get(object) == null) {
|
|
||||||
var rb = object.getTrait(RigidBody);
|
|
||||||
if (rb != null) shouldUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldUpdate) {
|
|
||||||
var rb = object.getTrait(RigidBody);
|
|
||||||
rigidBodyCache.set(object, rb);
|
|
||||||
cacheObjectRefs.set(object, object.traits.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rigidBodyCache.get(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static inline function hasContactWith(contacts: Array<RigidBody>, target: RigidBody): Bool {
|
|
||||||
return contacts != null && target != null && contacts.indexOf(target) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reset() {
|
public function reset() {
|
||||||
for (rb in active.rbMap) removeRigidBody(rb);
|
for (rb in active.rbMap) removeRigidBody(rb);
|
||||||
}
|
}
|
||||||
@ -335,6 +304,8 @@ class PhysicsWorld extends Trait {
|
|||||||
var t = Time.fixedStep * timeScale * Time.scale;
|
var t = Time.fixedStep * timeScale * Time.scale;
|
||||||
if (t == 0.0) return; // Simulation paused
|
if (t == 0.0) return; // Simulation paused
|
||||||
|
|
||||||
|
leenkx.trait.physics.PhysicsCache.clearContactsCache();
|
||||||
|
|
||||||
#if lnx_debug
|
#if lnx_debug
|
||||||
var startTime = kha.Scheduler.realTime();
|
var startTime = kha.Scheduler.realTime();
|
||||||
#end
|
#end
|
||||||
|
Reference in New Issue
Block a user