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