Commit 623b3ba0 authored by Viktor Lidholt's avatar Viktor Lidholt

Merge pull request #1677 from vlidholt/master

Renames PhysicsNode to PhysicsWorld
parents 8402b548 6bd4fb85
...@@ -47,10 +47,10 @@ main() async { ...@@ -47,10 +47,10 @@ main() async {
class TestBed extends NodeWithSize { class TestBed extends NodeWithSize {
Sprite _obstacle; Sprite _obstacle;
PhysicsNode _physicsNode; PhysicsWorld _physicsNode;
TestBed() : super(new Size(1024.0, 1024.0)) { TestBed() : super(new Size(1024.0, 1024.0)) {
_physicsNode = new PhysicsNode(new Offset(0.0, 100.0)); _physicsNode = new PhysicsWorld(new Offset(0.0, 100.0));
_obstacle = new Sprite(_spriteSheet["ship.png"]); _obstacle = new Sprite(_spriteSheet["ship.png"]);
_obstacle.position = new Point(512.0, 800.0); _obstacle.position = new Point(512.0, 800.0);
......
...@@ -36,8 +36,8 @@ part 'src/particle_system.dart'; ...@@ -36,8 +36,8 @@ part 'src/particle_system.dart';
part 'src/physics_body.dart'; part 'src/physics_body.dart';
part 'src/physics_debug.dart'; part 'src/physics_debug.dart';
part 'src/physics_joint.dart'; part 'src/physics_joint.dart';
part 'src/physics_node.dart';
part 'src/physics_shape.dart'; part 'src/physics_shape.dart';
part 'src/physics_world.dart';
part 'src/sound.dart'; part 'src/sound.dart';
part 'src/sound_manager.dart'; part 'src/sound_manager.dart';
part 'src/sprite.dart'; part 'src/sprite.dart';
......
...@@ -132,8 +132,8 @@ class Node { ...@@ -132,8 +132,8 @@ class Node {
void set rotation(double rotation) { void set rotation(double rotation) {
assert(rotation != null); assert(rotation != null);
if (_physicsBody != null && parent is PhysicsNode) { if (_physicsBody != null && parent is PhysicsWorld) {
PhysicsNode physicsNode = parent; PhysicsWorld physicsNode = parent;
physicsNode._updateRotation(this.physicsBody, rotation); physicsNode._updateRotation(this.physicsBody, rotation);
return; return;
} }
...@@ -150,7 +150,7 @@ class Node { ...@@ -150,7 +150,7 @@ class Node {
void teleportRotation(double rotation) { void teleportRotation(double rotation) {
assert(rotation != null); assert(rotation != null);
if (_physicsBody != null && parent is PhysicsNode) { if (_physicsBody != null && parent is PhysicsWorld) {
_physicsBody._body.setTransform(_physicsBody._body.position, radians(rotation)); _physicsBody._body.setTransform(_physicsBody._body.position, radians(rotation));
_physicsBody._body.angularVelocity = 0.0; _physicsBody._body.angularVelocity = 0.0;
_physicsBody._body.setType(box2d.BodyType.STATIC); _physicsBody._body.setType(box2d.BodyType.STATIC);
...@@ -166,8 +166,8 @@ class Node { ...@@ -166,8 +166,8 @@ class Node {
void set position(Point position) { void set position(Point position) {
assert(position != null); assert(position != null);
if (_physicsBody != null && parent is PhysicsNode) { if (_physicsBody != null && parent is PhysicsWorld) {
PhysicsNode physicsNode = parent; PhysicsWorld physicsNode = parent;
physicsNode._updatePosition(this.physicsBody, position); physicsNode._updatePosition(this.physicsBody, position);
return; return;
} }
...@@ -184,8 +184,8 @@ class Node { ...@@ -184,8 +184,8 @@ class Node {
void teleportPosition(Point position) { void teleportPosition(Point position) {
assert(position != null); assert(position != null);
if (_physicsBody != null && parent is PhysicsNode) { if (_physicsBody != null && parent is PhysicsWorld) {
PhysicsNode physicsNode = parent; PhysicsWorld physicsNode = parent;
_physicsBody._body.setTransform( _physicsBody._body.setTransform(
new Vector2( new Vector2(
position.x / physicsNode.b2WorldToNodeConversionFactor, position.x / physicsNode.b2WorldToNodeConversionFactor,
...@@ -252,8 +252,8 @@ class Node { ...@@ -252,8 +252,8 @@ class Node {
void set scale(double scale) { void set scale(double scale) {
assert(scale != null); assert(scale != null);
if (_physicsBody != null && parent is PhysicsNode) { if (_physicsBody != null && parent is PhysicsWorld) {
PhysicsNode physicsNode = parent; PhysicsWorld physicsNode = parent;
physicsNode._updateScale(this.physicsBody, scale); physicsNode._updateScale(this.physicsBody, scale);
} }
...@@ -681,7 +681,7 @@ class Node { ...@@ -681,7 +681,7 @@ class Node {
set physicsBody(PhysicsBody physicsBody) { set physicsBody(PhysicsBody physicsBody) {
if (parent != null) { if (parent != null) {
assert(parent is PhysicsNode); assert(parent is PhysicsWorld);
if (physicsBody == null) { if (physicsBody == null) {
physicsBody._detach(); physicsBody._detach();
......
...@@ -232,7 +232,7 @@ class PhysicsBody { ...@@ -232,7 +232,7 @@ class PhysicsBody {
double gravityScale; double gravityScale;
PhysicsNode _physicsNode; PhysicsWorld _physicsNode;
Node _node; Node _node;
box2d.Body _body; box2d.Body _body;
...@@ -293,7 +293,7 @@ class PhysicsBody { ...@@ -293,7 +293,7 @@ class PhysicsBody {
_body.applyAngularImpulse(impulse / _physicsNode.b2WorldToNodeConversionFactor); _body.applyAngularImpulse(impulse / _physicsNode.b2WorldToNodeConversionFactor);
} }
void _attach(PhysicsNode physicsNode, Node node) { void _attach(PhysicsWorld physicsNode, Node node) {
assert(_attached == false); assert(_attached == false);
// Update scale // Update scale
...@@ -340,7 +340,7 @@ class PhysicsBody { ...@@ -340,7 +340,7 @@ class PhysicsBody {
} }
} }
void _createFixtures(PhysicsNode physicsNode) { void _createFixtures(PhysicsWorld physicsNode) {
// Create FixtureDef // Create FixtureDef
box2d.FixtureDef fixtureDef = new box2d.FixtureDef(); box2d.FixtureDef fixtureDef = new box2d.FixtureDef();
fixtureDef.friction = friction; fixtureDef.friction = friction;
...@@ -371,7 +371,7 @@ class PhysicsBody { ...@@ -371,7 +371,7 @@ class PhysicsBody {
} }
} }
void _updateScale(PhysicsNode physicsNode) { void _updateScale(PhysicsWorld physicsNode) {
// Destroy old fixtures // Destroy old fixtures
for (box2d.Fixture fixture = _body.getFixtureList(); fixture != null; fixture = fixture.getNext()) { for (box2d.Fixture fixture = _body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
_body.destroyFixture(fixture); _body.destroyFixture(fixture);
...@@ -384,7 +384,7 @@ class PhysicsBody { ...@@ -384,7 +384,7 @@ class PhysicsBody {
_createFixtures(physicsNode); _createFixtures(physicsNode);
} }
void _addB2Shapes(PhysicsNode physicsNode, PhysicsShape shape, List<box2d.Shape> b2Shapes, List<PhysicsShape> physicsShapes) { void _addB2Shapes(PhysicsWorld physicsNode, PhysicsShape shape, List<box2d.Shape> b2Shapes, List<PhysicsShape> physicsShapes) {
if (shape is PhysicsShapeGroup) { if (shape is PhysicsShapeGroup) {
for (PhysicsShape child in shape.shapes) { for (PhysicsShape child in shape.shapes) {
_addB2Shapes(physicsNode, child, b2Shapes, physicsShapes); _addB2Shapes(physicsNode, child, b2Shapes, physicsShapes);
......
...@@ -12,7 +12,7 @@ class _PhysicsDebugDraw extends box2d.DebugDraw { ...@@ -12,7 +12,7 @@ class _PhysicsDebugDraw extends box2d.DebugDraw {
); );
} }
PhysicsNode physicsNode; PhysicsWorld physicsNode;
PaintingCanvas canvas; PaintingCanvas canvas;
......
...@@ -23,7 +23,7 @@ abstract class PhysicsJoint { ...@@ -23,7 +23,7 @@ abstract class PhysicsJoint {
bool _active = true; bool _active = true;
box2d.Joint _joint; box2d.Joint _joint;
PhysicsNode _physicsNode; PhysicsWorld _physicsNode;
void _completeCreation() { void _completeCreation() {
if (bodyA._attached && bodyB._attached) { if (bodyA._attached && bodyB._attached) {
...@@ -31,7 +31,7 @@ abstract class PhysicsJoint { ...@@ -31,7 +31,7 @@ abstract class PhysicsJoint {
} }
} }
void _attach(PhysicsNode physicsNode) { void _attach(PhysicsWorld physicsNode) {
if (_joint == null) { if (_joint == null) {
_physicsNode = physicsNode; _physicsNode = physicsNode;
_joint = _createB2Joint(physicsNode); _joint = _createB2Joint(physicsNode);
...@@ -48,7 +48,7 @@ abstract class PhysicsJoint { ...@@ -48,7 +48,7 @@ abstract class PhysicsJoint {
_active = false; _active = false;
} }
box2d.Joint _createB2Joint(PhysicsNode physicsNode); box2d.Joint _createB2Joint(PhysicsWorld physicsNode);
void destroy() { void destroy() {
_detach(); _detach();
...@@ -92,7 +92,7 @@ class PhysicsJointRevolute extends PhysicsJoint { ...@@ -92,7 +92,7 @@ class PhysicsJointRevolute extends PhysicsJoint {
final double upperAngle; final double upperAngle;
final bool enableLimit; final bool enableLimit;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
// Create Joint Definition // Create Joint Definition
Vector2 vecAnchor = new Vector2( Vector2 vecAnchor = new Vector2(
_worldAnchor.x / physicsNode.b2WorldToNodeConversionFactor, _worldAnchor.x / physicsNode.b2WorldToNodeConversionFactor,
...@@ -124,7 +124,7 @@ class PhysicsJointPrismatic extends PhysicsJoint { ...@@ -124,7 +124,7 @@ class PhysicsJointPrismatic extends PhysicsJoint {
Offset axis; Offset axis;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
box2d.PrismaticJointDef b2Def = new box2d.PrismaticJointDef(); box2d.PrismaticJointDef b2Def = new box2d.PrismaticJointDef();
b2Def.initialize(bodyA._body, bodyB._body, bodyA._body.position, new Vector2(axis.dx, axis.dy)); b2Def.initialize(bodyA._body, bodyB._body, bodyA._body.position, new Vector2(axis.dx, axis.dy));
return physicsNode.b2World.createJoint(b2Def); return physicsNode.b2World.createJoint(b2Def);
...@@ -147,7 +147,7 @@ class PhysicsJointWeld extends PhysicsJoint { ...@@ -147,7 +147,7 @@ class PhysicsJointWeld extends PhysicsJoint {
final double dampening; final double dampening;
final double frequency; final double frequency;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
box2d.WeldJointDef b2Def = new box2d.WeldJointDef(); box2d.WeldJointDef b2Def = new box2d.WeldJointDef();
Vector2 middle = new Vector2( Vector2 middle = new Vector2(
(bodyA._body.position.x + bodyB._body.position.x) / 2.0, (bodyA._body.position.x + bodyB._body.position.x) / 2.0,
...@@ -182,7 +182,7 @@ class PhysicsJointPulley extends PhysicsJoint { ...@@ -182,7 +182,7 @@ class PhysicsJointPulley extends PhysicsJoint {
final Point anchorB; final Point anchorB;
final double ratio; final double ratio;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
box2d.PulleyJointDef b2Def = new box2d.PulleyJointDef(); box2d.PulleyJointDef b2Def = new box2d.PulleyJointDef();
b2Def.initialize( b2Def.initialize(
bodyA._body, bodyA._body,
...@@ -211,7 +211,7 @@ class PhysicsJointGear extends PhysicsJoint { ...@@ -211,7 +211,7 @@ class PhysicsJointGear extends PhysicsJoint {
final double ratio; final double ratio;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
box2d.GearJointDef b2Def = new box2d.GearJointDef(); box2d.GearJointDef b2Def = new box2d.GearJointDef();
b2Def.bodyA = bodyA._body; b2Def.bodyA = bodyA._body;
b2Def.bodyB = bodyB._body; b2Def.bodyB = bodyB._body;
...@@ -243,7 +243,7 @@ class PhysicsJointDistance extends PhysicsJoint { ...@@ -243,7 +243,7 @@ class PhysicsJointDistance extends PhysicsJoint {
final double dampening; final double dampening;
final double frequency; final double frequency;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
box2d.DistanceJointDef b2Def = new box2d.DistanceJointDef(); box2d.DistanceJointDef b2Def = new box2d.DistanceJointDef();
b2Def.initialize( b2Def.initialize(
bodyA._body, bodyA._body,
...@@ -280,7 +280,7 @@ class PhysicsJointWheel extends PhysicsJoint { ...@@ -280,7 +280,7 @@ class PhysicsJointWheel extends PhysicsJoint {
final double dampening; final double dampening;
final double frequency; final double frequency;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
box2d.WheelJointDef b2Def = new box2d.WheelJointDef(); box2d.WheelJointDef b2Def = new box2d.WheelJointDef();
b2Def.initialize( b2Def.initialize(
bodyA._body, bodyA._body,
...@@ -313,7 +313,7 @@ class PhysicsJointFriction extends PhysicsJoint { ...@@ -313,7 +313,7 @@ class PhysicsJointFriction extends PhysicsJoint {
final double maxForce; final double maxForce;
final double maxTorque; final double maxTorque;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
box2d.FrictionJointDef b2Def = new box2d.FrictionJointDef(); box2d.FrictionJointDef b2Def = new box2d.FrictionJointDef();
b2Def.initialize( b2Def.initialize(
bodyA._body, bodyA._body,
...@@ -345,7 +345,7 @@ class PhysicsJointConstantVolume extends PhysicsJoint { ...@@ -345,7 +345,7 @@ class PhysicsJointConstantVolume extends PhysicsJoint {
final double dampening; final double dampening;
final double frequency; final double frequency;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsWorld physicsNode) {
box2d.ConstantVolumeJointDef b2Def = new box2d.ConstantVolumeJointDef(); box2d.ConstantVolumeJointDef b2Def = new box2d.ConstantVolumeJointDef();
for (PhysicsBody body in bodies) { for (PhysicsBody body in bodies) {
b2Def.addBody(body._body); b2Def.addBody(body._body);
...@@ -356,7 +356,7 @@ class PhysicsJointConstantVolume extends PhysicsJoint { ...@@ -356,7 +356,7 @@ class PhysicsJointConstantVolume extends PhysicsJoint {
} }
} }
Vector2 _convertPosToVec(Point pt, PhysicsNode physicsNode) { Vector2 _convertPosToVec(Point pt, PhysicsWorld physicsNode) {
return new Vector2( return new Vector2(
pt.x / physicsNode.b2WorldToNodeConversionFactor, pt.x / physicsNode.b2WorldToNodeConversionFactor,
pt.y / physicsNode.b2WorldToNodeConversionFactor pt.y / physicsNode.b2WorldToNodeConversionFactor
......
...@@ -6,14 +6,14 @@ abstract class PhysicsShape { ...@@ -6,14 +6,14 @@ abstract class PhysicsShape {
Object userObject; Object userObject;
box2d.Shape getB2Shape(PhysicsNode node, double scale) { box2d.Shape getB2Shape(PhysicsWorld node, double scale) {
if (_b2Shape == null) { if (_b2Shape == null) {
_b2Shape = _createB2Shape(node, scale); _b2Shape = _createB2Shape(node, scale);
} }
return _b2Shape; return _b2Shape;
} }
box2d.Shape _createB2Shape(PhysicsNode node, double scale); box2d.Shape _createB2Shape(PhysicsWorld node, double scale);
void _invalidate() { void _invalidate() {
_b2Shape = null; _b2Shape = null;
...@@ -26,7 +26,7 @@ class PhysicsShapeCircle extends PhysicsShape { ...@@ -26,7 +26,7 @@ class PhysicsShapeCircle extends PhysicsShape {
final Point point; final Point point;
final double radius; final double radius;
box2d.Shape _createB2Shape(PhysicsNode node, double scale) { box2d.Shape _createB2Shape(PhysicsWorld node, double scale) {
box2d.CircleShape shape = new box2d.CircleShape(); box2d.CircleShape shape = new box2d.CircleShape();
shape.p.x = scale * point.x / node.b2WorldToNodeConversionFactor; shape.p.x = scale * point.x / node.b2WorldToNodeConversionFactor;
shape.p.y = scale * point.y / node.b2WorldToNodeConversionFactor; shape.p.y = scale * point.y / node.b2WorldToNodeConversionFactor;
...@@ -40,7 +40,7 @@ class PhysicsShapePolygon extends PhysicsShape { ...@@ -40,7 +40,7 @@ class PhysicsShapePolygon extends PhysicsShape {
final List<Point> points; final List<Point> points;
box2d.Shape _createB2Shape(PhysicsNode node, double scale) { box2d.Shape _createB2Shape(PhysicsWorld node, double scale) {
List<Vector2> vectors = []; List<Vector2> vectors = [];
for (Point point in points) { for (Point point in points) {
Vector2 vec = new Vector2( Vector2 vec = new Vector2(
...@@ -69,7 +69,7 @@ class PhysicsShapeBox extends PhysicsShape { ...@@ -69,7 +69,7 @@ class PhysicsShapeBox extends PhysicsShape {
final Point center; final Point center;
final double rotation; final double rotation;
box2d.Shape _createB2Shape(PhysicsNode node, double scale) { box2d.Shape _createB2Shape(PhysicsWorld node, double scale) {
box2d.PolygonShape shape = new box2d.PolygonShape(); box2d.PolygonShape shape = new box2d.PolygonShape();
shape.setAsBox( shape.setAsBox(
scale * width / node.b2WorldToNodeConversionFactor, scale * width / node.b2WorldToNodeConversionFactor,
...@@ -90,7 +90,7 @@ class PhysicsShapeChain extends PhysicsShape { ...@@ -90,7 +90,7 @@ class PhysicsShapeChain extends PhysicsShape {
final List<Point> points; final List<Point> points;
final bool loop; final bool loop;
box2d.Shape _createB2Shape(PhysicsNode node, double scale) { box2d.Shape _createB2Shape(PhysicsWorld node, double scale) {
List<Vector2> vectors = []; List<Vector2> vectors = [];
for (Point point in points) { for (Point point in points) {
Vector2 vec = new Vector2( Vector2 vec = new Vector2(
...@@ -115,7 +115,7 @@ class PhysicsShapeEdge extends PhysicsShape { ...@@ -115,7 +115,7 @@ class PhysicsShapeEdge extends PhysicsShape {
final Point pointA; final Point pointA;
final Point pointB; final Point pointB;
box2d.Shape _createB2Shape(PhysicsNode node, double scale) { box2d.Shape _createB2Shape(PhysicsWorld node, double scale) {
box2d.EdgeShape shape = new box2d.EdgeShape(); box2d.EdgeShape shape = new box2d.EdgeShape();
shape.set( shape.set(
new Vector2( new Vector2(
...@@ -137,7 +137,7 @@ class PhysicsShapeGroup extends PhysicsShape { ...@@ -137,7 +137,7 @@ class PhysicsShapeGroup extends PhysicsShape {
final List<PhysicsShape> shapes; final List<PhysicsShape> shapes;
box2d.Shape _createB2Shape(PhysicsNode node, double scale) { box2d.Shape _createB2Shape(PhysicsWorld node, double scale) {
return null; return null;
} }
......
...@@ -9,8 +9,8 @@ enum PhysicsContactType { ...@@ -9,8 +9,8 @@ enum PhysicsContactType {
typedef void PhysicsContactCallback(PhysicsContactType type, PhysicsContact contact); typedef void PhysicsContactCallback(PhysicsContactType type, PhysicsContact contact);
class PhysicsNode extends Node { class PhysicsWorld extends Node {
PhysicsNode(Offset gravity) { PhysicsWorld(Offset gravity) {
b2World = new box2d.World.withGravity( b2World = new box2d.World.withGravity(
new Vector2( new Vector2(
gravity.dx / b2WorldToNodeConversionFactor, gravity.dx / b2WorldToNodeConversionFactor,
...@@ -18,7 +18,7 @@ class PhysicsNode extends Node { ...@@ -18,7 +18,7 @@ class PhysicsNode extends Node {
_init(); _init();
} }
PhysicsNode.fromB2World(this.b2World, this.b2WorldToNodeConversionFactor) { PhysicsWorld.fromB2World(this.b2World, this.b2WorldToNodeConversionFactor) {
_init(); _init();
} }
...@@ -252,7 +252,7 @@ class _ContactCallbackInfo { ...@@ -252,7 +252,7 @@ class _ContactCallbackInfo {
class _ContactHandler extends box2d.ContactListener { class _ContactHandler extends box2d.ContactListener {
_ContactHandler(this.physicsNode); _ContactHandler(this.physicsNode);
PhysicsNode physicsNode; PhysicsWorld physicsNode;
List<_ContactCallbackInfo> callbackInfos = []; List<_ContactCallbackInfo> callbackInfos = [];
......
...@@ -78,7 +78,7 @@ class SpriteBox extends RenderBox { ...@@ -78,7 +78,7 @@ class SpriteBox extends RenderBox {
List<Node> _constrainedNodes; List<Node> _constrainedNodes;
List<PhysicsNode> _physicsNodes; List<PhysicsWorld> _physicsNodes;
Rect _visibleArea; Rect _visibleArea;
...@@ -400,7 +400,7 @@ class SpriteBox extends RenderBox { ...@@ -400,7 +400,7 @@ class SpriteBox extends RenderBox {
void _addActionControllersAndPhysicsNodes(Node node) { void _addActionControllersAndPhysicsNodes(Node node) {
if (node._actions != null) _actionControllers.add(node._actions); if (node._actions != null) _actionControllers.add(node._actions);
if (node is PhysicsNode) _physicsNodes.add(node); if (node is PhysicsWorld) _physicsNodes.add(node);
for (int i = node.children.length - 1; i >= 0; i--) { for (int i = node.children.length - 1; i >= 0; i--) {
Node child = node.children[i]; Node child = node.children[i];
...@@ -422,7 +422,7 @@ class SpriteBox extends RenderBox { ...@@ -422,7 +422,7 @@ class SpriteBox extends RenderBox {
if (_physicsNodes == null) if (_physicsNodes == null)
_rebuildActionControllersAndPhysicsNodes(); _rebuildActionControllersAndPhysicsNodes();
for (PhysicsNode physicsNode in _physicsNodes) { for (PhysicsWorld physicsNode in _physicsNodes) {
physicsNode._stepPhysics(dt); physicsNode._stepPhysics(dt);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment