Skip to content

Commit

Permalink
Merge branch 'main' into refactor/dont-use-statics
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon authored Aug 6, 2024
2 parents 3d350b1 + d05b0ed commit 9eff207
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 139 deletions.
4 changes: 1 addition & 3 deletions packages/benchmark/web/bench2d.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ class Bench2d {
y.setFrom(x);

for (var j = i; j < pyramidSize; ++j) {
final bd = BodyDef()
..type = BodyType.dynamic
..position.setFrom(y);
final bd = BodyDef(type: BodyType.dynamic, position: y.clone());
world.createBody(bd).createFixtureFromShape(shape, density: 5.0);
y.add(deltaY);
}
Expand Down
20 changes: 12 additions & 8 deletions packages/forge2d/example/web/ball_cage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ class BallCage extends Demo {
@override
void initialize() {
// Define the circle shape.
final circleShape = CircleShape()..radius = wallBallRadius;
final circleShape = CircleShape(radius: wallBallRadius);

// Create fixture using the circle shape.
final circleFixtureDef = FixtureDef(circleShape)
..friction = .9
..restitution = 1.0;
final circleFixtureDef = FixtureDef(
circleShape,
friction: .9,
restitution: 1.0,
);

// Create a body def.
final circleBodyDef = BodyDef();
Expand Down Expand Up @@ -67,12 +69,14 @@ class BallCage extends Demo {
}

// Create a bouncing ball.
final bouncingCircle = CircleShape()..radius = activeBallRadius;
final bouncingCircle = CircleShape(radius: activeBallRadius);

// Create fixture for that ball shape.
final activeFixtureDef = FixtureDef(bouncingCircle)
..restitution = 1.0
..density = 0.05;
final activeFixtureDef = FixtureDef(
bouncingCircle,
restitution: 1.0,
density: 0.05,
);

// Create the active ball body.
final activeBodyDef = BodyDef();
Expand Down
2 changes: 1 addition & 1 deletion packages/forge2d/example/web/blob_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BlobTest extends Demo {
bd.type = BodyType.dynamic;
final body = world.createBody(bd);

final shape = CircleShape()..radius = bodyRadius;
final shape = CircleShape(radius: bodyRadius);
final fixtureDef = FixtureDef(shape)
..density = 1.0
..filter.groupIndex = -2;
Expand Down
11 changes: 5 additions & 6 deletions packages/forge2d/example/web/box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ class BoxTest extends Demo {
shape.setAsBox(3.0, 1.5, Vector2.zero(), pi / 2);

// Define fixture (links body and shape)
final activeFixtureDef = FixtureDef(shape)
..restitution = 0.5
..density = 0.05;
final activeFixtureDef = FixtureDef(shape, restitution: 0.5, density: 0.05);

// Define body
final bodyDef = BodyDef();
bodyDef.type = BodyType.dynamic;
bodyDef.position = Vector2(0.0, 30.0);
final bodyDef = BodyDef(
type: BodyType.dynamic,
position: Vector2(0.0, 30.0),
);

// Create body and fixture from definitions
final fallingBox = world.createBody(bodyDef);
Expand Down
71 changes: 31 additions & 40 deletions packages/forge2d/example/web/circle_stress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ class CircleStress extends Demo {
// Ground
final shape = PolygonShape();
shape.setAsBoxXY(50.0, 10.0);
final bodyDef = BodyDef()
..type = BodyType.static
..position = Vector2(0.0, -10.0);
final bodyDef = BodyDef(position: Vector2(0.0, -10.0));
final body = world.createBody(bodyDef);
bodies.add(body);
final fixtureDef = FixtureDef(shape)..friction = 1.0;
final fixtureDef = FixtureDef(shape, friction: 1.0);
body.createFixture(fixtureDef);

// Walls
shape.setAsBoxXY(3.0, 50.0);
final wallDef = BodyDef()..position = Vector2(45.0, 25.0);
final wallDef = BodyDef(position: Vector2(45.0, 25.0));
final rightWall = world.createBody(wallDef);
bodies.add(rightWall);
rightWall.createFixtureFromShape(shape);
Expand All @@ -51,10 +49,11 @@ class CircleStress extends Demo {
leftWall.createFixtureFromShape(shape);

// Corners
final cornerDef = BodyDef();
final cornerDef = BodyDef(
angle: -pi / 4.0,
position: Vector2(-35.0, 8.0),
);
shape.setAsBoxXY(20.0, 3.0);
cornerDef.angle = -pi / 4.0;
cornerDef.position = Vector2(-35.0, 8.0);
var myBod = world.createBody(cornerDef);
bodies.add(myBod);
myBod.createFixtureFromShape(shape);
Expand All @@ -66,10 +65,7 @@ class CircleStress extends Demo {

// top
shape.setAsBoxXY(50.0, 10.0);
final topDef = BodyDef()
..type = BodyType.static
..angle = 0.0
..position = Vector2(0.0, 75.0);
final topDef = BodyDef(position: Vector2(0.0, 75.0));
final topBody = world.createBody(topDef);
bodies.add(topBody);
fixtureDef.shape = shape;
Expand All @@ -85,22 +81,14 @@ class CircleStress extends Demo {
);
shape.createChain(vertices);

final fixtureDef = FixtureDef(shape)
..restitution = 0.0
..friction = 0.1;

final bodyDef = BodyDef()
..position = Vector2.zero()
..type = BodyType.static;

final fixtureDef = FixtureDef(shape, friction: 0.1);
final bodyDef = BodyDef(position: Vector2.zero());
final body = world.createBody(bodyDef)..createFixture(fixtureDef);
bodies.add(body);
}

{
final bd = BodyDef()
..type = BodyType.dynamic
..position = Vector2(0.0, 10.0);
final bd = BodyDef(type: BodyType.dynamic, position: Vector2(0.0, 10.0));
const numPieces = 5;
const radius = 6.0;
final body = world.createBody(bd);
Expand All @@ -110,14 +98,13 @@ class CircleStress extends Demo {
final xPos = radius * cos(2 * pi * (i / numPieces.toDouble()));
final yPos = radius * sin(2 * pi * (i / numPieces.toDouble()));

final shape = CircleShape()
..radius = 1.2
..position.setValues(xPos, yPos);

final fixtureDef = FixtureDef(shape)
..density = 25.0
..friction = .1
..restitution = .9;
final shape = CircleShape(radius: 1.2, position: Vector2(xPos, yPos));
final fixtureDef = FixtureDef(
shape,
density: 25.0,
friction: 0.1,
restitution: 0.9,
);

body.createFixture(fixtureDef);
}
Expand All @@ -139,17 +126,21 @@ class CircleStress extends Demo {

for (var j = 0; j < columns; j++) {
for (var i = 0; i < loadSize; i++) {
final shape = CircleShape()
..radius = 1.0 + (i.isEven ? 1.0 : -1.0) * .5 * .75;
final fd2 = FixtureDef(shape)
..density = shape.radius * 1.5
..friction = 0.5
..restitution = 0.7;
final shape = CircleShape(
radius: 1.0 + (i.isEven ? 1.0 : -1.0) * .5 * .75,
);
final fd2 = FixtureDef(
shape,
density: shape.radius * 1.5,
friction: 0.5,
restitution: 0.7,
);
final xPos = -39.0 + 2 * i;
final yPos = 50.0 + j;
final bodyDef = BodyDef()
..type = BodyType.dynamic
..position = Vector2(xPos, yPos);
final bodyDef = BodyDef(
type: BodyType.dynamic,
position: Vector2(xPos, yPos),
);
final body = world.createBody(bodyDef);
bodies.add(body);
body.createFixture(fd2);
Expand Down
16 changes: 6 additions & 10 deletions packages/forge2d/example/web/domino_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ class DominoTest extends Demo {
{
// Floor
final shape = PolygonShape()..setAsBoxXY(50.0, 10.0);
final fixtureDef = FixtureDef(shape)..friction = 0.1;
final fixtureDef = FixtureDef(shape, friction: 0.1);

final bd = BodyDef();
bd.position = Vector2(0.0, -10.0);
final bd = BodyDef(position: Vector2(0.0, -10.0));
final body = world.createBody(bd);
body.createFixture(fixtureDef);
bodies.add(body);
Expand All @@ -24,9 +23,9 @@ class DominoTest extends Demo {
// Platforms
for (var i = 0; i < 4; i++) {
final shape = PolygonShape()..setAsBoxXY(15.0, 0.125);
final fixtureDef = FixtureDef(shape)..friction = 0.1;
final fixtureDef = FixtureDef(shape, friction: 0.1);

final bodyDef = BodyDef()..position = Vector2(0.0, 5.0 + 5 * i);
final bodyDef = BodyDef(position: Vector2(0.0, 5.0 + 5 * i));
final body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
bodies.add(body);
Expand All @@ -36,11 +35,8 @@ class DominoTest extends Demo {
// Dominoes
{
final shape = PolygonShape()..setAsBoxXY(0.125, 2.0);
final fixtureDef = FixtureDef(shape)
..density = 25.0
..friction = 0.5;

final bodyDef = BodyDef()..type = BodyType.dynamic;
final fixtureDef = FixtureDef(shape, density: 25.0, friction: 0.5);
final bodyDef = BodyDef(type: BodyType.dynamic);

const numPerRow = 25;

Expand Down
36 changes: 18 additions & 18 deletions packages/forge2d/example/web/domino_tower.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ class DominoTower extends Demo {
void makeDomino(double x, double y, {required bool horizontal}) {
final shape = PolygonShape()
..setAsBoxXY(.5 * dominoWidth, .5 * dominoHeight);
final fixtureDef = FixtureDef(shape)
..density = dominoDensity
..friction = dominoFriction
..restitution = 0.65;
final bodyDef = BodyDef()..type = BodyType.dynamic;
bodyDef.position = Vector2(x, y);
bodyDef.angle = horizontal ? (pi / 2.0) : 0.0;
final fixtureDef = FixtureDef(
shape,
density: dominoDensity,
friction: dominoFriction,
restitution: 0.65,
);
final bodyDef = BodyDef(
type: BodyType.dynamic,
position: Vector2(x, y),
angle: horizontal ? (pi / 2.0) : 0.0,
);
final body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
bodies.add(body);
Expand All @@ -48,8 +52,7 @@ class DominoTower extends Demo {
final sd = PolygonShape();
sd.setAsBoxXY(50.0, 10.0);

final bd = BodyDef();
bd.position = Vector2(0.0, -10.0);
final bd = BodyDef(position: Vector2(0.0, -10.0));
final body = world.createBody(bd);
body.createFixtureFromShape(sd);
bodies.add(body);
Expand All @@ -59,15 +62,12 @@ class DominoTower extends Demo {
dominoDensity = 10.0;
// Make bullet
final shape = PolygonShape()..setAsBoxXY(.7, .7);
final fixtureDef = FixtureDef(shape)
..density = 35.0
..shape = shape
..friction = 0.0
..restitution = 0.85;
final bodyDef = BodyDef()
..type = BodyType.dynamic
..bullet = true
..position = Vector2(30.0, 5.00);
final fixtureDef = FixtureDef(shape, density: 35.0, restitution: 0.85);
final bodyDef = BodyDef(
type: BodyType.dynamic,
bullet: true,
position: Vector2(30.0, 5.00),
);
var body = world.createBody(bodyDef);
bodies.add(body);
body.createFixture(fixtureDef);
Expand Down
18 changes: 9 additions & 9 deletions packages/forge2d/example/web/friction_joint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ class FrictionJointTest extends Demo {
boxShape.setAsBox(3.0, 1.5, Vector2.zero(), pi / 2);

// Define fixture (links body and shape)
_boxFixture = FixtureDef(boxShape)
..restitution = 0.5
..density = 0.10;
_boxFixture = FixtureDef(boxShape, restitution: 0.5, density: 0.10);
}

void _createBox() {
// Define body
final bodyDef = BodyDef();
bodyDef.type = BodyType.dynamic;
bodyDef.position = Vector2(-10.0, 30.0);
final bodyDef = BodyDef(
type: BodyType.dynamic,
position: Vector2(-10.0, 30.0),
);

// Create body and fixture from definitions
final fallingBox = world.createBody(bodyDef);
Expand All @@ -76,9 +75,10 @@ class FrictionJointTest extends Demo {

void _createFrictionBox() {
// Define body
final bodyDef = BodyDef();
bodyDef.type = BodyType.dynamic;
bodyDef.position = Vector2(10.0, 30.0);
final bodyDef = BodyDef(
type: BodyType.dynamic,
position: Vector2(10.0, 30.0),
);

// Create body and fixture from definitions
final fallingBox = world.createBody(bodyDef);
Expand Down
20 changes: 12 additions & 8 deletions packages/forge2d/example/web/particles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class Particles extends Demo {
@override
void initialize() {
// Define the circle shape.
final circleShape = CircleShape()..radius = wallBallRadius;
final circleShape = CircleShape(radius: wallBallRadius);

// Create fixture using the circle shape.
final circleFixtureDef = FixtureDef(circleShape)
..friction = .9
..restitution = 1.0;
final circleFixtureDef = FixtureDef(
circleShape,
friction: 0.9,
restitution: 1.0,
);

// Create a body def.
final circleBodyDef = BodyDef();
Expand Down Expand Up @@ -70,9 +72,11 @@ class Particles extends Demo {
bouncingCircle.radius = activeBallRadius;

// Create fixture for that ball shape.
final activeFixtureDef = FixtureDef(bouncingCircle)
..restitution = 1.0
..density = 0.05;
final activeFixtureDef = FixtureDef(
bouncingCircle,
restitution: 1.0,
density: 0.05,
);

// Create the active ball body.
final activeBodyDef = BodyDef();
Expand All @@ -87,7 +91,7 @@ class Particles extends Demo {
world.particleSystem.particleRadius = 0.35;
world.particleSystem.dampingStrength = 0.2;

final shape = CircleShape()..radius = 5;
final shape = CircleShape(radius: 5);
final particleGroup = ParticleGroupDef()
..position.setFrom(fixture.renderCenter)
..destroyAutomatically = true
Expand Down
8 changes: 5 additions & 3 deletions packages/forge2d/example/web/racer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ class Racer extends Demo implements ContactListener {
final shape = PolygonShape()
..setAsBox(27.0, 21.0, Vector2(-30.0, 30.0), radians(20.0));

final fixtureDef = FixtureDef(shape)
..isSensor = true
..userData = GroundArea(0.001, outOfCourse: false);
final fixtureDef = FixtureDef(
shape,
isSensor: true,
userData: GroundArea(0.001, outOfCourse: false),
);
_groundBody.createFixture(fixtureDef);

fixtureDef.userData = GroundArea(0.2, outOfCourse: false);
Expand Down
Loading

0 comments on commit 9eff207

Please sign in to comment.