Skip to content

Commit 4cc0642

Browse files
committed
1.3.0->1.3.1
1 parent c08d62f commit 4cc0642

File tree

5 files changed

+54
-53
lines changed

5 files changed

+54
-53
lines changed

echo/Collisions.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class Collisions {
2727
if (r.transformed_rect != null) r.transformed_rect.collided = false;
2828
}
2929
}
30-
if (b.active && b.is_dynamic()) { // && (b.x != b.last_x || b.y != b.last_y)) {
31-
b.bounds(b.cache.quadtree_data.bounds);
30+
if (b.active && b.is_dynamic()) {
31+
b.cache.quadtree_data.bounds = b.bounds();
3232
quadtree.insert(b.cache.quadtree_data);
3333
}
3434
});

echo/Echo.hx

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,41 @@ class Echo {
6565

6666
return listener;
6767
}
68+
/**
69+
* Steps a `World` forward.
70+
* @param world
71+
* @param dt
72+
*/
73+
public static function step(world:World, dt:Float) {
74+
// Save World State to History
75+
if (world.history != null) world.history.add([
76+
for (b in world.members) {
77+
id: b.id,
78+
x: b.x,
79+
y: b.y,
80+
rotation: b.rotation,
81+
velocity: b.velocity,
82+
acceleration: b.acceleration,
83+
rotational_velocity: b.rotational_velocity
84+
}
85+
]);
86+
87+
// Apply Gravity
88+
world.for_each(member -> {
89+
member.acceleration.x += world.gravity.x * member.gravity_scale;
90+
member.acceleration.y += world.gravity.y * member.gravity_scale;
91+
});
92+
// Step the World incrementally based on the number of iterations
93+
var fdt = dt / world.iterations;
94+
for (i in 0...world.iterations) {
95+
Physics.step(world, fdt);
96+
Collisions.query(world);
97+
Physics.separate(world);
98+
Collisions.notify(world);
99+
}
100+
// Reset acceleration
101+
world.for_each(member -> member.acceleration.set(0, 0));
102+
}
68103
/**
69104
* Casts a Line Created from the supplied floats, returning the Intersection with the closest Body.
70105
* @param x The X position to start the cast.
@@ -198,41 +233,6 @@ class Echo {
198233

199234
return intersections;
200235
}
201-
/**
202-
* Steps a `World` forward.
203-
* @param world
204-
* @param dt
205-
*/
206-
public static function step(world:World, dt:Float) {
207-
// Save World State to History
208-
if (world.history != null) world.history.add([
209-
for (b in world.members) {
210-
id: b.id,
211-
x: b.x,
212-
y: b.y,
213-
rotation: b.rotation,
214-
velocity: b.velocity,
215-
acceleration: b.acceleration,
216-
rotational_velocity: b.rotational_velocity
217-
}
218-
]);
219-
220-
// Apply Gravity
221-
world.for_each(member -> {
222-
member.acceleration.x += world.gravity.x * member.gravity_scale;
223-
member.acceleration.y += world.gravity.y * member.gravity_scale;
224-
});
225-
// Step the World incrementally based on the number of iterations
226-
var fdt = dt / world.iterations;
227-
for (i in 0...world.iterations) {
228-
Physics.step(world, fdt);
229-
Collisions.query(world);
230-
Physics.separate(world);
231-
Collisions.notify(world);
232-
}
233-
// Reset acceleration
234-
world.for_each(member -> member.acceleration.set(0, 0));
235-
}
236236
/**
237237
* Undo the World's last step
238238
* @param world

echo/Listener.hx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,58 @@ import echo.util.BodyOrBodies;
1010
/**
1111
* Data Structure used to listen for Collisions between Bodies.
1212
*/
13-
typedef Listener = {
13+
@:structInit()
14+
class Listener {
1415
/**
1516
* The first Body or Array of Bodies the listener checks each step.
1617
*/
17-
var a:Either<Body, Array<Body>>;
18+
public var a:Either<Body, Array<Body>>;
1819
/**
1920
* The second Body or Array of Bodies the listener checks each step.
2021
*/
21-
var b:Either<Body, Array<Body>>;
22+
public var b:Either<Body, Array<Body>>;
2223
/**
2324
* Flag that determines if Collisions found by this listener should separate the Bodies. Defaults to `true`.
2425
*/
25-
var separate:Bool;
26+
public var separate:Bool;
2627
/**
2728
* Store of the latest Collisions.
2829
*/
29-
var collisions:Array<Collision>;
30+
public var collisions:Array<Collision>;
3031
/**
3132
* Store of the Collisions from the Prior Frame.
3233
*/
33-
var last_collisions:Array<Collision>;
34+
public var last_collisions:Array<Collision>;
3435
/**
3536
* A callback function that is called on the first frame that a collision starts.
3637
*/
37-
var ?enter:Body->Body->Array<CollisionData>->Void;
38+
@:optional public var enter:Body->Body->Array<CollisionData>->Void;
3839
/**
3940
* A callback function that is called on frames when two Bodies are continuing to collide.
4041
*/
41-
var ?stay:Body->Body->Array<CollisionData>->Void;
42+
@:optional public var stay:Body->Body->Array<CollisionData>->Void;
4243
/**
4344
* A callback function that is called when a collision between two Bodies ends.
4445
*/
45-
var ?exit:Body->Body->Void;
46+
@:optional public var exit:Body->Body->Void;
4647
/**
4748
* A callback function that allows extra logic to be run on a potential collision.
4849
*
4950
* If it returns true, the collision is valid. Otherwise the collision is discarded and no physics resolution/collision callbacks occur
5051
*/
51-
var ?condition:Body->Body->Array<CollisionData>->Bool;
52+
@:optional public var condition:Body->Body->Array<CollisionData>->Bool;
5253
/**
5354
* Store of the latest quadtree query results
5455
*/
55-
var ?quadtree_results:Array<Collision>;
56+
@:optional public var quadtree_results:Array<Collision>;
5657
/**
5758
* Percentage of correction along the collision normal to be applied to seperating bodies. Helps prevent objects sinking into each other.
5859
*/
59-
var percent_correction:Float;
60+
public var percent_correction:Float;
6061
/**
6162
* Threshold determining how close two separating bodies must be before position correction occurs. Helps reduce jitter.
6263
*/
63-
var correction_threshold:Float;
64+
public var correction_threshold:Float;
6465
}
6566
/**
6667
* Container used to store Listeners

haxelib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"description": "Simple Physics Library written in Haxe",
66
"contributors": ["austineast"],
77
"url": "https://austineast.dev/echo",
8-
"releasenote": "body integration",
9-
"version": "1.3.0",
8+
"releasenote": "null body bounds bug fixed",
9+
"version": "1.3.1",
1010
"dependencies": {
1111
"hxmath": ""
1212
}

sample/state/StackingState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class StackingState extends BaseState {
1414
var b = new Body({
1515
x: Random.range(60, world.width - 60),
1616
y: Random.range(0, world.height / 2),
17-
elasticity: 0.7,
17+
elasticity: 0.3,
1818
shape: {
1919
type: RECT,
2020
width: Random.range(16, 48),

0 commit comments

Comments
 (0)