Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
5f6917a
Fix strong mode error in buffer_utils.sort
yourpalal Feb 10, 2018
c7eef7e
version bump
feroult Jul 15, 2018
f388bc1
publish a flame fork
feroult Jul 15, 2018
ae9eb9a
Fixes for dart 2
luanpotter Aug 12, 2018
8ccfa6d
Fixes for dart 2.1
luanpotter Aug 25, 2018
2864275
Merge pull request #1 from feroult/fixes-for-dart2
luanpotter Aug 25, 2018
38e67df
fixes pubspec and bump version
luanpotter Aug 25, 2018
862d70a
added getVertex with a dart-style return on chain shape
japalekhin Jan 29, 2019
7d49458
version bump to 0.4.3
japalekhin Jan 29, 2019
18493ab
Merge pull request #2 from japalekhin/master
feroult Jan 30, 2019
d73bd35
Another bad assert in transform removed
msywensky May 30, 2019
6d85810
Merge pull request #3 from msywensky/master
feroult Jul 14, 2019
f0d5307
v0.4.4
feroult Jul 14, 2019
41f2ec9
Remove 'new' keyword
spydon Nov 6, 2019
2451828
Merge pull request #4 from spydon/remove-new-keyword
luanpotter Nov 8, 2019
89371fd
Dart syntax for viewport functions
spydon Nov 6, 2019
201cde3
Merge pull request #5 from spydon/dart-standard
feroult Dec 31, 2019
90a0974
fixing warnings and formatting
luanpotter Jan 13, 2020
6da51b6
compilation errors
luanpotter Jan 13, 2020
cfa1f5b
Merge pull request #6 from flame-engine/luan.fix-warnings
luanpotter Jan 15, 2020
e99409c
Fixing comments to new format
luanpotter Jan 15, 2020
7c88735
Merge pull request #7 from flame-engine/luan.fix-docs
feroult Apr 22, 2020
d6161af
Fix torque bug
spydon Jun 6, 2020
b1bffe3
Merge pull request #8 from spydon/spydon.fix-torque
erickzanardo Jun 7, 2020
dc3405e
Fix hit test bug
tfoel Aug 27, 2020
4094d41
Merge pull request #10 from tfoel/master
spydon Sep 2, 2020
8d4cb2a
GetMassData as dart
spydon Jun 13, 2020
a4e023f
Change function definitions for Transform and Rot
spydon Jun 14, 2020
fe67a11
Update some of the joints
spydon Jun 14, 2020
33a0e7a
Fix joint function calls
spydon Jun 15, 2020
4f77382
Fix function calls for time of impact
spydon Jun 15, 2020
c4306d7
Fix collision and distance function calls
spydon Jun 15, 2020
bbe718f
Fix polygon shape
spydon Jun 15, 2020
53a0c3b
Fix formatting
spydon Jun 15, 2020
7c3b6eb
Bump version
spydon Jun 15, 2020
ef25668
Bump pubspec version
spydon Jun 15, 2020
173df1e
Use setFrom for Rot
spydon Jun 15, 2020
4c335a6
Don't use new keyword
spydon Jun 15, 2020
c80f6dc
Remove more "new" keywords
spydon Jun 15, 2020
db37005
Remove debug prints
spydon Jun 15, 2020
3950bfe
Remove more "new" keywords
spydon Jun 15, 2020
0333e0a
Remove unnecessary declarations and comments
spydon Jun 15, 2020
134f58c
Remove unnecessary comments
spydon Jun 15, 2020
ad492ab
Copyright notice already included in LICENSE
spydon Jun 15, 2020
9adade7
Remove more new keywords
spydon Jun 17, 2020
115c775
Do not skip first loop step if i0 is 0
spydon Jun 17, 2020
05f8f8a
Fix island to use more readable code
spydon Jun 17, 2020
cb280f0
Remove explicit null checks on assignment
spydon Jun 17, 2020
9ad9792
Rename buffer functions
spydon Jun 17, 2020
bb616a9
Fix some list initializations
spydon Jun 17, 2020
192f71a
Fix formatting
spydon Jun 17, 2020
bab1033
Remove some vector pooling
spydon Jun 27, 2020
423bf2e
Don't use pooling
spydon Jul 5, 2020
11398ff
Remove unnecessary declarations and comments
spydon Jun 15, 2020
4359997
Fix corresponding position and velocity
spydon Jul 7, 2020
0e24fde
Remove distance and collision pooling
spydon Jul 7, 2020
91762e7
Reintroduce contacts pooling
spydon Jul 8, 2020
5185857
Fix island so that contacts work
spydon Jul 11, 2020
19cb9f1
Rename p -> position for circle and polygon
spydon Jul 11, 2020
23c2ad0
Remove unused pooling classes
spydon Jul 12, 2020
aaf8e7a
Remove StackQueue and use built in ListQueue
spydon Jul 12, 2020
086d820
Remove usage of contact pools
spydon Jul 16, 2020
98b28eb
Delete last parts of pooling code
spydon Jul 16, 2020
8039a23
Remove pooling from polygon shape
spydon Sep 2, 2020
613f507
Use generate instead of filled to have different objects
spydon Sep 8, 2020
34ae7ad
Format code
spydon Sep 12, 2020
dde0d10
Change imports to local from examples
spydon Sep 15, 2020
7e7f3bf
Replace Pair list by int list (original optimisation done on jbox2d h…
tommybuonomo Sep 24, 2020
ba105dc
Remove print comment
tommybuonomo Sep 24, 2020
508e801
Merge pull request #11 from tommybuonomo/opti
spydon Sep 24, 2020
a59b10d
Avoid bodies being destroyed with bad timing
spydon Sep 25, 2020
d5d72b8
Do the removal when the world is unlocked
spydon Sep 25, 2020
97f407d
Simplify constructor
spydon Sep 26, 2020
b856ed5
Revert "Do the removal when the world is unlocked"
spydon Sep 26, 2020
6366b61
Revert "Avoid bodies being destroyed with bad timing"
spydon Sep 26, 2020
58f48d3
Updated the readme
spydon Sep 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.idea
.packages
.pub
packages
pubspec.lock
.dart_tool
build/
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
### 1.0.0
* Make code more like the dart standard and less C++

### 0.4.6
* Fix bug with torque not being modified from applyTorque

### 0.4.5
* Fixing warnings and formatting

### 0.4.1 - 0.4.4
* Updates related to Flame interop + bugfixes

### 0.4.0

* Breaking: Made package strong-mode compliant
Expand Down
32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
### A Dart 2D physics engine

[![Build Status](https://travis-ci.org/google/box2d.dart.svg?branch=master)](https://travis-ci.org/google/box2d.dart)
[![Coverage Status](https://coveralls.io/repos/google/box2d.dart/badge.svg?branch=master)](https://coveralls.io/r/google/box2d.dart)

*This is a Dart port of Java's Box2D libraries.*

*The Java Box2D library was originally written by Daniel Murphy (status
February 2015).*

```
benchmark/bench2d.dart Benchmark used by Joel Webber
example/index.html Browser demos as written by Dominic Hamon
lib/ Port of Daniel Murphy's jbox2d
```

First Dart port of an earlier version of Box2D library was
done by Dominic Hamon. We are grateful for his work.

__*Not an official Google project*__
## Forge2D - A Dart port of the Box2D physics engine
This is a dart port of the famous Box2D physics engine.
You can use it indepentently in Dart or in your [flame](https://github.com/flame-engine/flame) project with the help of [flame_forge2d](https://github.com/flame-engine/flame_forge2d).
Some documentation of how to use it together with flame can be found [here](https://github.com/flame-engine/flame/blob/master/doc/box2d.md).

### Timeline
Box2D was first written in C++ and released by [Erin Catto](https://github.com/erincatto) in 2007, but it is still maintained.
It was then ported to Java (jbox2d) by Daniel Murphy around 2015.
It was then ported from that Java port to Dart by [Dominic Hamon](https://github.com/dominichamon) and [Kevin Moore](https://github.com/kevmoo).
Then [Lukas Klingsbo](https://github.com/spydon) refactored the code to follow the dart standard more, since it still had a lot of reminiscence from C++.
After this refactor we renamed it to Forge2D since the upstream wasn't maintained to take in our PRs.
There has also been countless other contributors which we are very thankful to!
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
linter:
rules:
- slash_for_doc_comments
15 changes: 15 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Benchmark for Dart Box2D

Run:
```sh
pub global run webdev build --output=benchmark:build
```

Either from the command line or from your IDE.

Then run:
```sh
pub global run webdev daemon example:53322 --launch-app=benchmark/index.html
```


61 changes: 21 additions & 40 deletions benchmark/bench2d.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
/*******************************************************************************
* Copyright (c) 2015, Daniel Murphy, Google
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/

import 'package:box2d/box2d.dart';
import '../lib/box2d.dart';

void main() {
new Bench2d()
Bench2d()
..initialize()
..warmup()
..bench();
Expand Down Expand Up @@ -64,30 +40,33 @@ double percentile(List<double> values, double pc) {
class Bench2d {
final World world;

Bench2d() : world = new World.withGravity(new Vector2(0.0, -10.0));
Bench2d() : world = World(Vector2(0.0, -10.0));

void initialize() {
BodyDef bd = new BodyDef();
BodyDef bd = BodyDef();
Body ground = world.createBody(bd);

EdgeShape groundShape = new EdgeShape()
..set(new Vector2(-40.0, 0.0), new Vector2(40.0, 0.0));
PolygonShape groundShape = PolygonShape()
..setAsEdge(Vector2(-20.0, -30.0), Vector2(20.0, -30.0));
ground.createFixtureFromShape(groundShape, 0.0);
//EdgeShape groundShape = EdgeShape()
// ..set(Vector2(-40.0, -30.0), Vector2(40.0, -30.0));
//ground.createFixtureFromShape(groundShape, 0.0);

// add boxes
const boxSize = .5;
PolygonShape shape = new PolygonShape()..setAsBoxXY(boxSize, boxSize);
PolygonShape shape = PolygonShape()..setAsBoxXY(boxSize, boxSize);

Vector2 x = new Vector2(-7.0, 0.75);
Vector2 y = new Vector2.zero();
Vector2 deltaX = new Vector2(0.5625, 1.0);
Vector2 deltaY = new Vector2(1.125, 0.0);
Vector2 x = Vector2(-7.0, 0.75);
Vector2 y = Vector2.zero();
Vector2 deltaX = Vector2(0.5625, 1.0);
Vector2 deltaY = Vector2(1.125, 0.0);

for (int i = 0; i < PYRAMID_SIZE; ++i) {
y.setFrom(x);

for (int j = i; j < PYRAMID_SIZE; ++j) {
BodyDef bd = new BodyDef()
BodyDef bd = BodyDef()
..type = BodyType.DYNAMIC
..position.setFrom(y);
world.createBody(bd)..createFixtureFromShape(shape, 5.0);
Expand All @@ -96,11 +75,13 @@ class Bench2d {

x.add(deltaX);
}
// TODO: Why does some bodies sleep prematurely
world.setAllowSleep(false);
}

List<double> bench() {
List<double> times = new List<double>(FRAMES);
Stopwatch stopwatch = new Stopwatch()..start();
List<double> times = List<double>(FRAMES);
Stopwatch stopwatch = Stopwatch()..start();
for (int i = 0; i < FRAMES; ++i) {
int begin = stopwatch.elapsedMilliseconds;
step();
Expand Down Expand Up @@ -132,8 +113,8 @@ class Bench2d {
}

void checksum(World world) {
Vector2 positionSum = new Vector2.zero();
Vector2 linearVelocitySum = new Vector2.zero();
Vector2 positionSum = Vector2.zero();
Vector2 linearVelocitySum = Vector2.zero();
double angularVelocitySum = 0.0;
var checksum = (Body b) {
positionSum = positionSum + b.position;
Expand Down
42 changes: 8 additions & 34 deletions benchmark/bench2d_web.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
/*******************************************************************************
* Copyright (c) 2015, Daniel Murphy, Google
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/

import 'dart:html';

import 'package:box2d/box2d_browser.dart';
import '../lib/box2d_browser.dart';

import 'bench2d.dart';

void main() {
// Render version
new Bench2dWeb()
Bench2dWeb()
..initializeAnimation()
..runAnimation();
}
Expand All @@ -45,26 +21,24 @@ class Bench2dWeb extends Bench2d {
ViewportTransform viewport;
DebugDraw debugDraw;

/**
* Creates the canvas and readies the demo for animation. Must be called
* before calling runAnimation.
*/
/// Creates the canvas and readies the demo for animation. Must be called
/// before calling runAnimation.
void initializeAnimation() {
// Setup the canvas.
canvas = new CanvasElement()
canvas = CanvasElement()
..width = CANVAS_WIDTH
..height = CANVAS_HEIGHT;

ctx = canvas.getContext("2d") as CanvasRenderingContext2D;
document.body.append(canvas);

// Create the viewport transform with the center at extents.
final extents = new Vector2(CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2);
viewport = new CanvasViewportTransform(extents, extents)
final extents = Vector2(CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2);
viewport = CanvasViewportTransform(extents, extents)
..scale = _VIEWPORT_SCALE;

// Create our canvas drawing tool to give to the world.
debugDraw = new CanvasDraw(viewport, ctx);
debugDraw = CanvasDraw(viewport, ctx);

// Have the world draw itself for debugging purposes.
world.debugDraw = debugDraw;
Expand Down
9 changes: 9 additions & 0 deletions benchmark/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -e

shopt -s nullglob
for f in *.dart; do
if [ "$f" == "demo.dart" ] ; then
continue;
fi
dart2js -o $f.js $f
done
3 changes: 1 addition & 2 deletions benchmark/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
console.log('Browser does not support Dart. Expect JS fallback.');
}
</script>
<script type="application/dart" src="bench2d_web.dart"></script>
<script src="packages/browser/dart.js"></script>
<script defer src="bench2d_web.dart.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js
*.js.deps
*.js.map
24 changes: 24 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Examples for Dart Box2D

Run:
```sh
pub global run webdev build --output=example:build
```

Either from the command line or from your IDE.

Then run:
```sh
pub global run webdev daemon example:53322 --launch-app=example/index.html
```

## Old way

Run:
```sh
./compile.sh
```

and then open index.html in a browser.


Loading