Skip to content

Commit 9eff207

Browse files
authored
Merge branch 'main' into refactor/dont-use-statics
2 parents 3d350b1 + d05b0ed commit 9eff207

File tree

16 files changed

+153
-139
lines changed

16 files changed

+153
-139
lines changed

packages/benchmark/web/bench2d.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ class Bench2d {
6464
y.setFrom(x);
6565

6666
for (var j = i; j < pyramidSize; ++j) {
67-
final bd = BodyDef()
68-
..type = BodyType.dynamic
69-
..position.setFrom(y);
67+
final bd = BodyDef(type: BodyType.dynamic, position: y.clone());
7068
world.createBody(bd).createFixtureFromShape(shape, density: 5.0);
7169
y.add(deltaY);
7270
}

packages/forge2d/example/web/ball_cage.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ class BallCage extends Demo {
2727
@override
2828
void initialize() {
2929
// Define the circle shape.
30-
final circleShape = CircleShape()..radius = wallBallRadius;
30+
final circleShape = CircleShape(radius: wallBallRadius);
3131

3232
// Create fixture using the circle shape.
33-
final circleFixtureDef = FixtureDef(circleShape)
34-
..friction = .9
35-
..restitution = 1.0;
33+
final circleFixtureDef = FixtureDef(
34+
circleShape,
35+
friction: .9,
36+
restitution: 1.0,
37+
);
3638

3739
// Create a body def.
3840
final circleBodyDef = BodyDef();
@@ -67,12 +69,14 @@ class BallCage extends Demo {
6769
}
6870

6971
// Create a bouncing ball.
70-
final bouncingCircle = CircleShape()..radius = activeBallRadius;
72+
final bouncingCircle = CircleShape(radius: activeBallRadius);
7173

7274
// Create fixture for that ball shape.
73-
final activeFixtureDef = FixtureDef(bouncingCircle)
74-
..restitution = 1.0
75-
..density = 0.05;
75+
final activeFixtureDef = FixtureDef(
76+
bouncingCircle,
77+
restitution: 1.0,
78+
density: 0.05,
79+
);
7680

7781
// Create the active ball body.
7882
final activeBodyDef = BodyDef();

packages/forge2d/example/web/blob_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class BlobTest extends Demo {
5353
bd.type = BodyType.dynamic;
5454
final body = world.createBody(bd);
5555

56-
final shape = CircleShape()..radius = bodyRadius;
56+
final shape = CircleShape(radius: bodyRadius);
5757
final fixtureDef = FixtureDef(shape)
5858
..density = 1.0
5959
..filter.groupIndex = -2;

packages/forge2d/example/web/box_test.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ class BoxTest extends Demo {
5151
shape.setAsBox(3.0, 1.5, Vector2.zero(), pi / 2);
5252

5353
// Define fixture (links body and shape)
54-
final activeFixtureDef = FixtureDef(shape)
55-
..restitution = 0.5
56-
..density = 0.05;
54+
final activeFixtureDef = FixtureDef(shape, restitution: 0.5, density: 0.05);
5755

5856
// Define body
59-
final bodyDef = BodyDef();
60-
bodyDef.type = BodyType.dynamic;
61-
bodyDef.position = Vector2(0.0, 30.0);
57+
final bodyDef = BodyDef(
58+
type: BodyType.dynamic,
59+
position: Vector2(0.0, 30.0),
60+
);
6261

6362
// Create body and fixture from definitions
6463
final fallingBox = world.createBody(bodyDef);

packages/forge2d/example/web/circle_stress.dart

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ class CircleStress extends Demo {
3131
// Ground
3232
final shape = PolygonShape();
3333
shape.setAsBoxXY(50.0, 10.0);
34-
final bodyDef = BodyDef()
35-
..type = BodyType.static
36-
..position = Vector2(0.0, -10.0);
34+
final bodyDef = BodyDef(position: Vector2(0.0, -10.0));
3735
final body = world.createBody(bodyDef);
3836
bodies.add(body);
39-
final fixtureDef = FixtureDef(shape)..friction = 1.0;
37+
final fixtureDef = FixtureDef(shape, friction: 1.0);
4038
body.createFixture(fixtureDef);
4139

4240
// Walls
4341
shape.setAsBoxXY(3.0, 50.0);
44-
final wallDef = BodyDef()..position = Vector2(45.0, 25.0);
42+
final wallDef = BodyDef(position: Vector2(45.0, 25.0));
4543
final rightWall = world.createBody(wallDef);
4644
bodies.add(rightWall);
4745
rightWall.createFixtureFromShape(shape);
@@ -51,10 +49,11 @@ class CircleStress extends Demo {
5149
leftWall.createFixtureFromShape(shape);
5250

5351
// Corners
54-
final cornerDef = BodyDef();
52+
final cornerDef = BodyDef(
53+
angle: -pi / 4.0,
54+
position: Vector2(-35.0, 8.0),
55+
);
5556
shape.setAsBoxXY(20.0, 3.0);
56-
cornerDef.angle = -pi / 4.0;
57-
cornerDef.position = Vector2(-35.0, 8.0);
5857
var myBod = world.createBody(cornerDef);
5958
bodies.add(myBod);
6059
myBod.createFixtureFromShape(shape);
@@ -66,10 +65,7 @@ class CircleStress extends Demo {
6665

6766
// top
6867
shape.setAsBoxXY(50.0, 10.0);
69-
final topDef = BodyDef()
70-
..type = BodyType.static
71-
..angle = 0.0
72-
..position = Vector2(0.0, 75.0);
68+
final topDef = BodyDef(position: Vector2(0.0, 75.0));
7369
final topBody = world.createBody(topDef);
7470
bodies.add(topBody);
7571
fixtureDef.shape = shape;
@@ -85,22 +81,14 @@ class CircleStress extends Demo {
8581
);
8682
shape.createChain(vertices);
8783

88-
final fixtureDef = FixtureDef(shape)
89-
..restitution = 0.0
90-
..friction = 0.1;
91-
92-
final bodyDef = BodyDef()
93-
..position = Vector2.zero()
94-
..type = BodyType.static;
95-
84+
final fixtureDef = FixtureDef(shape, friction: 0.1);
85+
final bodyDef = BodyDef(position: Vector2.zero());
9686
final body = world.createBody(bodyDef)..createFixture(fixtureDef);
9787
bodies.add(body);
9888
}
9989

10090
{
101-
final bd = BodyDef()
102-
..type = BodyType.dynamic
103-
..position = Vector2(0.0, 10.0);
91+
final bd = BodyDef(type: BodyType.dynamic, position: Vector2(0.0, 10.0));
10492
const numPieces = 5;
10593
const radius = 6.0;
10694
final body = world.createBody(bd);
@@ -110,14 +98,13 @@ class CircleStress extends Demo {
11098
final xPos = radius * cos(2 * pi * (i / numPieces.toDouble()));
11199
final yPos = radius * sin(2 * pi * (i / numPieces.toDouble()));
112100

113-
final shape = CircleShape()
114-
..radius = 1.2
115-
..position.setValues(xPos, yPos);
116-
117-
final fixtureDef = FixtureDef(shape)
118-
..density = 25.0
119-
..friction = .1
120-
..restitution = .9;
101+
final shape = CircleShape(radius: 1.2, position: Vector2(xPos, yPos));
102+
final fixtureDef = FixtureDef(
103+
shape,
104+
density: 25.0,
105+
friction: 0.1,
106+
restitution: 0.9,
107+
);
121108

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

140127
for (var j = 0; j < columns; j++) {
141128
for (var i = 0; i < loadSize; i++) {
142-
final shape = CircleShape()
143-
..radius = 1.0 + (i.isEven ? 1.0 : -1.0) * .5 * .75;
144-
final fd2 = FixtureDef(shape)
145-
..density = shape.radius * 1.5
146-
..friction = 0.5
147-
..restitution = 0.7;
129+
final shape = CircleShape(
130+
radius: 1.0 + (i.isEven ? 1.0 : -1.0) * .5 * .75,
131+
);
132+
final fd2 = FixtureDef(
133+
shape,
134+
density: shape.radius * 1.5,
135+
friction: 0.5,
136+
restitution: 0.7,
137+
);
148138
final xPos = -39.0 + 2 * i;
149139
final yPos = 50.0 + j;
150-
final bodyDef = BodyDef()
151-
..type = BodyType.dynamic
152-
..position = Vector2(xPos, yPos);
140+
final bodyDef = BodyDef(
141+
type: BodyType.dynamic,
142+
position: Vector2(xPos, yPos),
143+
);
153144
final body = world.createBody(bodyDef);
154145
bodies.add(body);
155146
body.createFixture(fd2);

packages/forge2d/example/web/domino_test.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ class DominoTest extends Demo {
1111
{
1212
// Floor
1313
final shape = PolygonShape()..setAsBoxXY(50.0, 10.0);
14-
final fixtureDef = FixtureDef(shape)..friction = 0.1;
14+
final fixtureDef = FixtureDef(shape, friction: 0.1);
1515

16-
final bd = BodyDef();
17-
bd.position = Vector2(0.0, -10.0);
16+
final bd = BodyDef(position: Vector2(0.0, -10.0));
1817
final body = world.createBody(bd);
1918
body.createFixture(fixtureDef);
2019
bodies.add(body);
@@ -24,9 +23,9 @@ class DominoTest extends Demo {
2423
// Platforms
2524
for (var i = 0; i < 4; i++) {
2625
final shape = PolygonShape()..setAsBoxXY(15.0, 0.125);
27-
final fixtureDef = FixtureDef(shape)..friction = 0.1;
26+
final fixtureDef = FixtureDef(shape, friction: 0.1);
2827

29-
final bodyDef = BodyDef()..position = Vector2(0.0, 5.0 + 5 * i);
28+
final bodyDef = BodyDef(position: Vector2(0.0, 5.0 + 5 * i));
3029
final body = world.createBody(bodyDef);
3130
body.createFixture(fixtureDef);
3231
bodies.add(body);
@@ -36,11 +35,8 @@ class DominoTest extends Demo {
3635
// Dominoes
3736
{
3837
final shape = PolygonShape()..setAsBoxXY(0.125, 2.0);
39-
final fixtureDef = FixtureDef(shape)
40-
..density = 25.0
41-
..friction = 0.5;
42-
43-
final bodyDef = BodyDef()..type = BodyType.dynamic;
38+
final fixtureDef = FixtureDef(shape, density: 25.0, friction: 0.5);
39+
final bodyDef = BodyDef(type: BodyType.dynamic);
4440

4541
const numPerRow = 25;
4642

packages/forge2d/example/web/domino_tower.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ class DominoTower extends Demo {
2828
void makeDomino(double x, double y, {required bool horizontal}) {
2929
final shape = PolygonShape()
3030
..setAsBoxXY(.5 * dominoWidth, .5 * dominoHeight);
31-
final fixtureDef = FixtureDef(shape)
32-
..density = dominoDensity
33-
..friction = dominoFriction
34-
..restitution = 0.65;
35-
final bodyDef = BodyDef()..type = BodyType.dynamic;
36-
bodyDef.position = Vector2(x, y);
37-
bodyDef.angle = horizontal ? (pi / 2.0) : 0.0;
31+
final fixtureDef = FixtureDef(
32+
shape,
33+
density: dominoDensity,
34+
friction: dominoFriction,
35+
restitution: 0.65,
36+
);
37+
final bodyDef = BodyDef(
38+
type: BodyType.dynamic,
39+
position: Vector2(x, y),
40+
angle: horizontal ? (pi / 2.0) : 0.0,
41+
);
3842
final body = world.createBody(bodyDef);
3943
body.createFixture(fixtureDef);
4044
bodies.add(body);
@@ -48,8 +52,7 @@ class DominoTower extends Demo {
4852
final sd = PolygonShape();
4953
sd.setAsBoxXY(50.0, 10.0);
5054

51-
final bd = BodyDef();
52-
bd.position = Vector2(0.0, -10.0);
55+
final bd = BodyDef(position: Vector2(0.0, -10.0));
5356
final body = world.createBody(bd);
5457
body.createFixtureFromShape(sd);
5558
bodies.add(body);
@@ -59,15 +62,12 @@ class DominoTower extends Demo {
5962
dominoDensity = 10.0;
6063
// Make bullet
6164
final shape = PolygonShape()..setAsBoxXY(.7, .7);
62-
final fixtureDef = FixtureDef(shape)
63-
..density = 35.0
64-
..shape = shape
65-
..friction = 0.0
66-
..restitution = 0.85;
67-
final bodyDef = BodyDef()
68-
..type = BodyType.dynamic
69-
..bullet = true
70-
..position = Vector2(30.0, 5.00);
65+
final fixtureDef = FixtureDef(shape, density: 35.0, restitution: 0.85);
66+
final bodyDef = BodyDef(
67+
type: BodyType.dynamic,
68+
bullet: true,
69+
position: Vector2(30.0, 5.00),
70+
);
7171
var body = world.createBody(bodyDef);
7272
bodies.add(body);
7373
body.createFixture(fixtureDef);

packages/forge2d/example/web/friction_joint_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,15 @@ class FrictionJointTest extends Demo {
5555
boxShape.setAsBox(3.0, 1.5, Vector2.zero(), pi / 2);
5656

5757
// Define fixture (links body and shape)
58-
_boxFixture = FixtureDef(boxShape)
59-
..restitution = 0.5
60-
..density = 0.10;
58+
_boxFixture = FixtureDef(boxShape, restitution: 0.5, density: 0.10);
6159
}
6260

6361
void _createBox() {
6462
// Define body
65-
final bodyDef = BodyDef();
66-
bodyDef.type = BodyType.dynamic;
67-
bodyDef.position = Vector2(-10.0, 30.0);
63+
final bodyDef = BodyDef(
64+
type: BodyType.dynamic,
65+
position: Vector2(-10.0, 30.0),
66+
);
6867

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

7776
void _createFrictionBox() {
7877
// Define body
79-
final bodyDef = BodyDef();
80-
bodyDef.type = BodyType.dynamic;
81-
bodyDef.position = Vector2(10.0, 30.0);
78+
final bodyDef = BodyDef(
79+
type: BodyType.dynamic,
80+
position: Vector2(10.0, 30.0),
81+
);
8282

8383
// Create body and fixture from definitions
8484
final fallingBox = world.createBody(bodyDef);

packages/forge2d/example/web/particles.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ class Particles extends Demo {
2626
@override
2727
void initialize() {
2828
// Define the circle shape.
29-
final circleShape = CircleShape()..radius = wallBallRadius;
29+
final circleShape = CircleShape(radius: wallBallRadius);
3030

3131
// Create fixture using the circle shape.
32-
final circleFixtureDef = FixtureDef(circleShape)
33-
..friction = .9
34-
..restitution = 1.0;
32+
final circleFixtureDef = FixtureDef(
33+
circleShape,
34+
friction: 0.9,
35+
restitution: 1.0,
36+
);
3537

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

7274
// Create fixture for that ball shape.
73-
final activeFixtureDef = FixtureDef(bouncingCircle)
74-
..restitution = 1.0
75-
..density = 0.05;
75+
final activeFixtureDef = FixtureDef(
76+
bouncingCircle,
77+
restitution: 1.0,
78+
density: 0.05,
79+
);
7680

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

90-
final shape = CircleShape()..radius = 5;
94+
final shape = CircleShape(radius: 5);
9195
final particleGroup = ParticleGroupDef()
9296
..position.setFrom(fixture.renderCenter)
9397
..destroyAutomatically = true

packages/forge2d/example/web/racer.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ class Racer extends Demo implements ContactListener {
7676
final shape = PolygonShape()
7777
..setAsBox(27.0, 21.0, Vector2(-30.0, 30.0), radians(20.0));
7878

79-
final fixtureDef = FixtureDef(shape)
80-
..isSensor = true
81-
..userData = GroundArea(0.001, outOfCourse: false);
79+
final fixtureDef = FixtureDef(
80+
shape,
81+
isSensor: true,
82+
userData: GroundArea(0.001, outOfCourse: false),
83+
);
8284
_groundBody.createFixture(fixtureDef);
8385

8486
fixtureDef.userData = GroundArea(0.2, outOfCourse: false);

0 commit comments

Comments
 (0)