Skip to content

Commit

Permalink
Merge branch 'master' of github.com:AustinEast/echo into listener-sha…
Browse files Browse the repository at this point in the history
…pe-issue
  • Loading branch information
MondayHopscotch committed Mar 2, 2024
2 parents 1927b63 + d889af5 commit 3d4789a
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/composites/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runs:
steps:
- uses: krdlab/setup-haxe@v1
with:
haxe-version: 4.2.4
haxe-version: 4.3.2

- uses: actions/checkout@v3
with:
Expand All @@ -16,7 +16,7 @@ runs:
shell: bash
run: |
haxelib git dox https://github.com/HaxeFoundation/dox.git
haxelib git heaps https://github.com/HeapsIO/heaps.git
haxelib install heaps 2.0.0
haxelib dev echo .
- name: Run Builds
Expand Down
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"[haxe]": {
"editor.formatOnSave": true
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": false,
}
}
}
2 changes: 2 additions & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
<h1>Echo</h1>
<p>Simple Arcade Physics Library for Haxe</p>
<canvas width="640" height="360" id="webgl"></canvas>
<p style="font-style: italic; font-size: x-small; margin-bottom: 0.1em">Known issue: the sample buttons do not work correctly! as a quick fix, resize your browser window and they'll work just fine ;)</a></p>

<div class="buttons">
<a href="https://github.com/AustinEast/echo/">Get Started</a>
<a href="./api/echo/Echo" target="_blank">API</a>
Expand Down
5 changes: 3 additions & 2 deletions echo/Body.hx
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ class Body implements Disposable #if cog implements cog.IComponent #end {
/**
* If set, this method is called whenever the Body's X or Y changes.
*/
public var on_move:Null<Float->Float->Void>;
public var on_move:Null<(x:Float, y:Float) -> Void>;
/**
* If set, this method is called whenever the Body's rotation changes.
*/
public var on_rotate:Null<Float->Void>;
public var on_rotate:Null<(angle:Float) -> Void>;

@:allow(echo.Physics.step_body)
public var last_x(default, null):Float;
Expand Down Expand Up @@ -231,6 +231,7 @@ class Body implements Disposable #if cog implements cog.IComponent #end {
* Sets a Body's values from a `BodyOptions` object.
* @param options
*/
@:haxe.warning("-WDeprecated")
public function load_options(?options:BodyOptions) {
options = echo.util.JSON.copy_fields(options, defaults);
clear_shapes();
Expand Down
59 changes: 37 additions & 22 deletions echo/Echo.hx
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,46 @@ class Echo {
/**
* Steps a `World` forward.
* @param world
* @param dt
* @param dt The Delta Time to step the `World` Forward
* @param rate The target rate of Step-Per-Second. If set to 0, the target rate is unlimited.
*/
public static function step(world:World, dt:Float) {
// Save World State to History
if (world.history != null) world.history.add([
for (b in world.members) {
id: b.id,
x: b.x,
y: b.y,
rotation: b.rotation,
velocity_x: b.velocity.x,
velocity_y: b.velocity.y,
acceleration_x: b.acceleration.x,
acceleration_y: b.acceleration.y,
rotational_velocity: b.rotational_velocity
public static function step(world:World, dt:Float, rate:Float = 0) {
function step_world(world:World, dt:Float) {
// Save World State to History
if (world.history != null) world.history.add([
for (b in world.members) {
id: b.id,
x: b.x,
y: b.y,
rotation: b.rotation,
velocity_x: b.velocity.x,
velocity_y: b.velocity.y,
acceleration_x: b.acceleration.x,
acceleration_y: b.acceleration.y,
rotational_velocity: b.rotational_velocity
}
]);

// Step the World incrementally based on the number of iterations
var fdt = dt / world.iterations;
for (i in 0...world.iterations) {
Physics.step(world, fdt);
Collisions.query(world);
Physics.separate(world);
Collisions.notify(world);
}
]);
}

// Step the World incrementally based on the number of iterations
var fdt = dt / world.iterations;
for (i in 0...world.iterations) {
Physics.step(world, fdt);
Collisions.query(world);
Physics.separate(world);
Collisions.notify(world);
if (rate > 0) {
world.accumulatedTime += dt;
var step = 1.0 / rate;
while (world.accumulatedTime >= step) {
world.accumulatedTime -= step;
step_world(world, step);
}
}
else {
step_world(world, dt);
}
}
/**
Expand Down
2 changes: 1 addition & 1 deletion echo/Physics.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Physics {

// Apply Rotational Acceleration, Drag, and Max Velocity
var accel_rot = body.torque * body.inverse_mass;
body.rotational_velocity = compute_velocity(body.rotational_velocity, body.rotational_drag, accel_rot, body.max_rotational_velocity, dt);
body.rotational_velocity = compute_velocity(body.rotational_velocity, accel_rot, body.rotational_drag, body.max_rotational_velocity, dt);

// Apply Rotational Velocity
body.rotation += body.rotational_velocity * dt;
Expand Down
2 changes: 2 additions & 0 deletions echo/World.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class World implements Disposable {

public var history:Null<History<Array<BodyState>>>;

public var accumulatedTime:Float = 0;

var init:Bool;

public function new(options:WorldOptions) {
Expand Down
3 changes: 1 addition & 2 deletions echo/data/Data.hx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ class QuadTreeData {
public var flag = false;
}

@:enum
abstract Direction(Int) from Int to Int {
enum abstract Direction(Int) from Int to Int {
var TOP = 0;
}
6 changes: 3 additions & 3 deletions echo/data/Types.hx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package echo.data;

@:enum abstract MassType(Float) from Float to Float {
enum abstract MassType(Float) from Float to Float {
var AUTO = -1;
var STATIC = 0;
}

@:enum abstract ShapeType(Int) from Int to Int {
enum abstract ShapeType(Int) from Int to Int {
var RECT;
var CIRCLE;
var POLYGON;
}

@:enum abstract ForceType(Int) from Int to Int {
enum abstract ForceType(Int) from Int to Int {
var ACCELERATION;
var VELOCITY;
var POSITION;
Expand Down
2 changes: 1 addition & 1 deletion echo/util/Bezier.hx
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ class Bezier implements Disposable {
}
}

@:enum abstract BezierCurve(Int) to Int from Int {
enum abstract BezierCurve(Int) to Int from Int {
var Linear = 1;
var Quadratic = 2;
var Cubic = 3;
Expand Down
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"austineast"
],
"url": "https://austineast.dev/echo",
"releasenote": "fix webpage gen",
"version": "4.2.2"
"releasenote": "revert regression",
"version": "4.2.4"
}
7 changes: 3 additions & 4 deletions sample/Main.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package;

import state.test.ListenerState;
import state.test.OverlappingSpawnState;
import hxd.Window;
import hxd.Key;
import echo.Echo;
import echo.World;
Expand Down Expand Up @@ -89,8 +88,8 @@ class Main extends BaseApp {
var fdt = Key.isDown(Key.SHIFT) ? dt * 0.3 : dt;
// Update the current Sample State
fsm.step(fdt);
// Step the World Forward
if (playing) world.step(fdt);
// Step the World Forward, with a fixed step rate of 60 per second
if (playing) world.step(fdt, 60);

// Update GUI text
members_text.text = 'Bodies: ${world.count}';
Expand Down

0 comments on commit 3d4789a

Please sign in to comment.