diff --git a/.github/composites/build/action.yml b/.github/composites/build/action.yml index 5714a37..c578c32 100644 --- a/.github/composites/build/action.yml +++ b/.github/composites/build/action.yml @@ -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: @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json index 782aca5..2d19c9c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "[haxe]": { - "editor.formatOnSave": true + "editor.formatOnSave": true, + "files.trimTrailingWhitespace": false, } -} \ No newline at end of file +} diff --git a/assets/index.html b/assets/index.html index 920ac76..2c33100 100644 --- a/assets/index.html +++ b/assets/index.html @@ -84,6 +84,8 @@

Echo

Simple Arcade Physics Library for Haxe

+

Known issue: the sample buttons do not work correctly! as a quick fix, resize your browser window and they'll work just fine ;)

+
Get Started API diff --git a/echo/Body.hx b/echo/Body.hx index c1ce6ca..e13821e 100644 --- a/echo/Body.hx +++ b/echo/Body.hx @@ -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:NullFloat->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:NullVoid>; + public var on_rotate:Null<(angle:Float) -> Void>; @:allow(echo.Physics.step_body) public var last_x(default, null):Float; @@ -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(); diff --git a/echo/Echo.hx b/echo/Echo.hx index 092e8a6..e3cc466 100644 --- a/echo/Echo.hx +++ b/echo/Echo.hx @@ -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); } } /** diff --git a/echo/Physics.hx b/echo/Physics.hx index 2276cf8..9a9299f 100644 --- a/echo/Physics.hx +++ b/echo/Physics.hx @@ -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; diff --git a/echo/World.hx b/echo/World.hx index 8b010c2..b2072b6 100644 --- a/echo/World.hx +++ b/echo/World.hx @@ -52,6 +52,8 @@ class World implements Disposable { public var history:Null>>; + public var accumulatedTime:Float = 0; + var init:Bool; public function new(options:WorldOptions) { diff --git a/echo/data/Data.hx b/echo/data/Data.hx index 02eae63..7700094 100644 --- a/echo/data/Data.hx +++ b/echo/data/Data.hx @@ -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; } diff --git a/echo/data/Types.hx b/echo/data/Types.hx index 0f25d2c..8315c05 100644 --- a/echo/data/Types.hx +++ b/echo/data/Types.hx @@ -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; diff --git a/echo/util/Bezier.hx b/echo/util/Bezier.hx index 09a7e07..6819d1d 100644 --- a/echo/util/Bezier.hx +++ b/echo/util/Bezier.hx @@ -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; diff --git a/haxelib.json b/haxelib.json index 9f897b5..4a9e2fa 100644 --- a/haxelib.json +++ b/haxelib.json @@ -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" } diff --git a/sample/Main.hx b/sample/Main.hx index 85c55e8..7e20393 100644 --- a/sample/Main.hx +++ b/sample/Main.hx @@ -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; @@ -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}';