[haxe] 4.3 porting WIP - latest updates.

This commit is contained in:
Davide Tantillo 2025-06-16 09:53:07 +02:00
parent 8d046cbbf4
commit f4a6677097
4 changed files with 44 additions and 19 deletions

View File

@ -135,8 +135,8 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
ux = bx; ux = bx;
uy = by; uy = by;
} else { } else {
var a = remaining, i = p.inertia, f = skeleton.data.referenceScale, d = -1., m = 0., e = 0., qx = data.limit * delta, var a = remaining, i = p.inertia, f = skeleton.data.referenceScale, d = -1., m = 0., e = 0., ax = 0., ay = 0.,
qy = qx * Math.abs(skeleton.scaleY); qx = data.limit * delta, qy = qx * Math.abs(skeleton.scaleY);
qx *= Math.abs(skeleton.scaleX); qx *= Math.abs(skeleton.scaleX);
if (x || y) { if (x || y) {
if (x) { if (x) {
@ -154,8 +154,9 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
d = Math.pow(p.damping, 60 * t); d = Math.pow(p.damping, 60 * t);
m = t * p.massInverse; m = t * p.massInverse;
e = p.strength; e = p.strength;
var w = f * p.wind * skeleton.scaleX, g = f * p.gravity * skeleton.scaleY, var w = f * p.wind, g = f * p.gravity;
ax = w * skeleton.windX + g * skeleton.gravityX, ay = w * skeleton.windY + g * skeleton.gravityY; ax = (w * skeleton.windX + g * skeleton.gravityX) * skeleton.scaleX;
ay = (w * skeleton.windY + g * skeleton.gravityY) * skeleton.scaleY;
do { do {
if (x) { if (x) {
xVelocity += (ax - xOffset * e) * m; xVelocity += (ax - xOffset * e) * m;
@ -210,11 +211,11 @@ class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsConstraintD
d = Math.pow(p.damping, 60 * t); d = Math.pow(p.damping, 60 * t);
m = t * p.massInverse; m = t * p.massInverse;
e = p.strength; e = p.strength;
var w = f * p.wind, g = f * (Bone.yDown ? -p.gravity : p.gravity);
ax = (w * skeleton.windX + g * skeleton.gravityX) * skeleton.scaleX;
ay = (w * skeleton.windY + g * skeleton.gravityY) * skeleton.scaleY;
} }
var g = Bone.yDown ? -p.gravity : p.gravity; var rs = rotateOffset, ss = scaleOffset, h = l / f;
var rs = rotateOffset, ss = scaleOffset, h = l / f,
ax = p.wind * skeleton.windX + g * skeleton.gravityX,
ay = p.wind * skeleton.windY + g * skeleton.gravityY;
while (true) { while (true) {
a -= t; a -= t;
if (scaleX) { if (scaleX) {

View File

@ -36,23 +36,47 @@ abstract class Posed< //
/** The constraint's setup pose data. */ /** The constraint's setup pose data. */
public final data:D; public final data:D;
public final pose:A;
public final pose:P;
public final constrained:A; public final constrained:A;
public var applied:A; public var applied:A;
public function new (data:D, pose:P, constrained:A) { public function new (data:D, pose:A, constrained:A) {
if (data == null) throw new SpineException("data cannot be null."); if (data == null) throw new SpineException("data cannot be null.");
this.data = data; this.data = data;
this.pose = pose; this.pose = pose;
this.constrained = constrained; this.constrained = constrained;
applied = cast pose; applied = pose;
}
/** The constraint's setup pose data. */
public function getData ():D {
return data;
}
public function getPose ():P {
return pose;
}
public function getAppliedPose ():A {
return applied;
} }
public function setupPose ():Void { public function setupPose ():Void {
pose.set(data.setup); pose.set(data.setup);
} }
public function usePose ():Void { // Port: usePose - reference runtime: pose()
applied = pose;
}
public function useConstrained ():Void { // Port: useConstrained - reference runtime: constrained()
applied = constrained;
}
public function resetConstrained ():Void { // Port: resetConstrained - reference runtime: reset()
constrained.set(pose);
}
public function toString ():String { public function toString ():String {
return data.name; return data.name;
} }

View File

@ -37,7 +37,7 @@ abstract class PosedActive< //
public var active:Bool; public var active:Bool;
public function new (data:D, pose:P, constrained:A) { public function new (data:D, pose:A, constrained:A) {
super(data, pose, constrained); super(data, pose, constrained);
setupPose(); setupPose();
} }

View File

@ -154,12 +154,12 @@ class Skeleton {
resetCache.resize(0); resetCache.resize(0);
for (slot in slots) for (slot in slots)
slot.applied = slot.pose; slot.usePose();
for (bone in bones) { for (bone in bones) {
bone.sorted = bone.data.skinRequired; bone.sorted = bone.data.skinRequired;
bone.active = !bone.sorted; bone.active = !bone.sorted;
bone.applied = cast(bone.pose, BonePose); bone.usePose();
} }
if (skin != null) { if (skin != null) {
@ -175,7 +175,7 @@ class Skeleton {
} }
for (constraint in constraints) for (constraint in constraints)
constraint.applied = constraint.pose; constraint.usePose();
for (c in constraints) { for (c in constraints) {
var constraint:Constraint<Dynamic, Dynamic, Dynamic> = c; var constraint:Constraint<Dynamic, Dynamic, Dynamic> = c;
constraint.active = constraint.isSourceActive() constraint.active = constraint.isSourceActive()
@ -203,7 +203,7 @@ class Skeleton {
public function constrained (object:Posed<Dynamic, Dynamic, Dynamic>) { public function constrained (object:Posed<Dynamic, Dynamic, Dynamic>) {
if (object.pose == object.applied) { if (object.pose == object.applied) {
object.applied = object.constrained; object.useConstrained();
resetCache.push(object); resetCache.push(object);
} }
} }
@ -232,8 +232,8 @@ class Skeleton {
public function updateWorldTransform(physics:Physics):Void { public function updateWorldTransform(physics:Physics):Void {
_update++; _update++;
for (object in resetCache) for (resetable in resetCache)
object.applied.set(object.pose); resetable.resetConstrained();
for (updatable in _updateCache) for (updatable in _updateCache)
updatable.update(this, physics); updatable.update(this, physics);