[Scummvm-git-logs] scummvm master -> b930cb702c71314de50185329bf610a73923562a
sev-
noreply at scummvm.org
Sat Nov 28 16:22:26 UTC 2026
This automated email contains information about 11 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
b97609a5a6 NGI: Add Box2D 2.2.1
0845e75654 NGI: Name Interact and Entrance fields after Android XML attributes
516337f01b NGI: Rename Interact::_ves to _weight
c1b08167e3 NGI: Name startMove, startFade and updateCmdPause after Android
d3672cc79e NGI: Rename ModalQuery to QueryDlg and SaveGameDlg accessors after Android
9ecfa34e39 NGI: Add CommandKind enum for the command kind numbers
7bc6ee1581 NGI: Add MessageKind enum for the system message numbers
43e52b6706 NGI: Name the padding fields of PicAniInfo, MessageHandler and Sc2
99b44a7898 NGI: Rename InteractionController::addInteraction to addInteract
8f9b5c5ce0 NGI: Silence unused variable warnings in Box2D
b930cb702c NGI: Fix the remaining Box2D compiler warnings
Commit: b97609a5a687721d95c72454305f5a0a8a48ca17
https://github.com/scummvm/scummvm/commit/b97609a5a687721d95c72454305f5a0a8a48ca17
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Add Box2D 2.2.1
Changed paths:
A engines/ngi/box2d/Box2D.h
A engines/ngi/box2d/Collision/Shapes/b2ChainShape.cpp
A engines/ngi/box2d/Collision/Shapes/b2ChainShape.h
A engines/ngi/box2d/Collision/Shapes/b2CircleShape.cpp
A engines/ngi/box2d/Collision/Shapes/b2CircleShape.h
A engines/ngi/box2d/Collision/Shapes/b2EdgeShape.cpp
A engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h
A engines/ngi/box2d/Collision/Shapes/b2PolygonShape.cpp
A engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h
A engines/ngi/box2d/Collision/Shapes/b2Shape.h
A engines/ngi/box2d/Collision/b2BroadPhase.cpp
A engines/ngi/box2d/Collision/b2BroadPhase.h
A engines/ngi/box2d/Collision/b2CollideCircle.cpp
A engines/ngi/box2d/Collision/b2CollideEdge.cpp
A engines/ngi/box2d/Collision/b2CollidePolygon.cpp
A engines/ngi/box2d/Collision/b2Collision.cpp
A engines/ngi/box2d/Collision/b2Collision.h
A engines/ngi/box2d/Collision/b2Distance.cpp
A engines/ngi/box2d/Collision/b2Distance.h
A engines/ngi/box2d/Collision/b2DynamicTree.cpp
A engines/ngi/box2d/Collision/b2DynamicTree.h
A engines/ngi/box2d/Collision/b2TimeOfImpact.cpp
A engines/ngi/box2d/Collision/b2TimeOfImpact.h
A engines/ngi/box2d/Common/b2BlockAllocator.cpp
A engines/ngi/box2d/Common/b2BlockAllocator.h
A engines/ngi/box2d/Common/b2Draw.cpp
A engines/ngi/box2d/Common/b2Draw.h
A engines/ngi/box2d/Common/b2GrowableStack.h
A engines/ngi/box2d/Common/b2Math.cpp
A engines/ngi/box2d/Common/b2Math.h
A engines/ngi/box2d/Common/b2Settings.cpp
A engines/ngi/box2d/Common/b2Settings.h
A engines/ngi/box2d/Common/b2StackAllocator.cpp
A engines/ngi/box2d/Common/b2StackAllocator.h
A engines/ngi/box2d/Common/b2Timer.cpp
A engines/ngi/box2d/Common/b2Timer.h
A engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.h
A engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.h
A engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.h
A engines/ngi/box2d/Dynamics/Contacts/b2Contact.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2Contact.h
A engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.h
A engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.h
A engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.h
A engines/ngi/box2d/Dynamics/Contacts/b2PolygonAndCircleContact.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2PolygonAndCircleContact.h
A engines/ngi/box2d/Dynamics/Contacts/b2PolygonContact.cpp
A engines/ngi/box2d/Dynamics/Contacts/b2PolygonContact.h
A engines/ngi/box2d/Dynamics/Joints/b2DistanceJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2DistanceJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2FrictionJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2FrictionJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2GearJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2GearJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2Joint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2Joint.h
A engines/ngi/box2d/Dynamics/Joints/b2MouseJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2MouseJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2PrismaticJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2PrismaticJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2PulleyJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2PulleyJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2RevoluteJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2RevoluteJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2RopeJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2RopeJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2WeldJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2WeldJoint.h
A engines/ngi/box2d/Dynamics/Joints/b2WheelJoint.cpp
A engines/ngi/box2d/Dynamics/Joints/b2WheelJoint.h
A engines/ngi/box2d/Dynamics/b2Body.cpp
A engines/ngi/box2d/Dynamics/b2Body.h
A engines/ngi/box2d/Dynamics/b2ContactManager.cpp
A engines/ngi/box2d/Dynamics/b2ContactManager.h
A engines/ngi/box2d/Dynamics/b2Fixture.cpp
A engines/ngi/box2d/Dynamics/b2Fixture.h
A engines/ngi/box2d/Dynamics/b2Island.cpp
A engines/ngi/box2d/Dynamics/b2Island.h
A engines/ngi/box2d/Dynamics/b2TimeStep.h
A engines/ngi/box2d/Dynamics/b2World.cpp
A engines/ngi/box2d/Dynamics/b2World.h
A engines/ngi/box2d/Dynamics/b2WorldCallbacks.cpp
A engines/ngi/box2d/Dynamics/b2WorldCallbacks.h
A engines/ngi/box2d/License.txt
A engines/ngi/box2d/Rope/b2Rope.cpp
A engines/ngi/box2d/Rope/b2Rope.h
engines/ngi/module.mk
diff --git a/engines/ngi/box2d/Box2D.h b/engines/ngi/box2d/Box2D.h
new file mode 100644
index 00000000000..ea2d8ef48db
--- /dev/null
+++ b/engines/ngi/box2d/Box2D.h
@@ -0,0 +1,67 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef BOX2D_H
+#define BOX2D_H
+
+/**
+\mainpage Box2D API Documentation
+
+\section intro_sec Getting Started
+
+For documentation please see http://box2d.org/documentation.html
+
+For discussion please visit http://box2d.org/forum
+*/
+
+// These include files constitute the main Box2D API
+
+#include "engines/ngi/box2d/Common/b2Settings.h"
+#include "engines/ngi/box2d/Common/b2Draw.h"
+#include "engines/ngi/box2d/Common/b2Timer.h"
+
+#include "engines/ngi/box2d/Collision/Shapes/b2CircleShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2ChainShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h"
+
+#include "engines/ngi/box2d/Collision/b2BroadPhase.h"
+#include "engines/ngi/box2d/Collision/b2Distance.h"
+#include "engines/ngi/box2d/Collision/b2DynamicTree.h"
+#include "engines/ngi/box2d/Collision/b2TimeOfImpact.h"
+
+#include "engines/ngi/box2d/Dynamics/b2Body.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+#include "engines/ngi/box2d/Dynamics/b2WorldCallbacks.h"
+#include "engines/ngi/box2d/Dynamics/b2TimeStep.h"
+#include "engines/ngi/box2d/Dynamics/b2World.h"
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2Contact.h"
+
+#include "engines/ngi/box2d/Dynamics/Joints/b2DistanceJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2FrictionJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2GearJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2WheelJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2MouseJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2PrismaticJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2PulleyJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2RevoluteJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2RopeJoint.h"
+#include "engines/ngi/box2d/Dynamics/Joints/b2WeldJoint.h"
+
+#endif
diff --git a/engines/ngi/box2d/Collision/Shapes/b2ChainShape.cpp b/engines/ngi/box2d/Collision/Shapes/b2ChainShape.cpp
new file mode 100644
index 00000000000..fcba6d01d7f
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2ChainShape.cpp
@@ -0,0 +1,175 @@
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/Shapes/b2ChainShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h"
+#include <new>
+#include <cstring>
+
+namespace NGI {
+using namespace std;
+
+b2ChainShape::~b2ChainShape()
+{
+ b2Free(m_vertices);
+ m_vertices = NULL;
+ m_count = 0;
+}
+
+void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
+{
+ b2Assert(m_vertices == NULL && m_count == 0);
+ b2Assert(count >= 3);
+ m_count = count + 1;
+ m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
+ memcpy(m_vertices, vertices, count * sizeof(b2Vec2));
+ m_vertices[count] = m_vertices[0];
+ m_prevVertex = m_vertices[m_count - 2];
+ m_nextVertex = m_vertices[1];
+ m_hasPrevVertex = true;
+ m_hasNextVertex = true;
+}
+
+void b2ChainShape::CreateChain(const b2Vec2* vertices, int32 count)
+{
+ b2Assert(m_vertices == NULL && m_count == 0);
+ b2Assert(count >= 2);
+ m_count = count;
+ m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));
+ memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));
+ m_hasPrevVertex = false;
+ m_hasNextVertex = false;
+}
+
+void b2ChainShape::SetPrevVertex(const b2Vec2& prevVertex)
+{
+ m_prevVertex = prevVertex;
+ m_hasPrevVertex = true;
+}
+
+void b2ChainShape::SetNextVertex(const b2Vec2& nextVertex)
+{
+ m_nextVertex = nextVertex;
+ m_hasNextVertex = true;
+}
+
+b2Shape* b2ChainShape::Clone(b2BlockAllocator* allocator) const
+{
+ void* mem = allocator->Allocate(sizeof(b2ChainShape));
+ b2ChainShape* clone = new (mem) b2ChainShape;
+ clone->CreateChain(m_vertices, m_count);
+ clone->m_prevVertex = m_prevVertex;
+ clone->m_nextVertex = m_nextVertex;
+ clone->m_hasPrevVertex = m_hasPrevVertex;
+ clone->m_hasNextVertex = m_hasNextVertex;
+ return clone;
+}
+
+int32 b2ChainShape::GetChildCount() const
+{
+ // edge count = vertex count - 1
+ return m_count - 1;
+}
+
+void b2ChainShape::GetChildEdge(b2EdgeShape* edge, int32 index) const
+{
+ b2Assert(0 <= index && index < m_count - 1);
+ edge->m_type = b2Shape::e_edge;
+ edge->m_radius = m_radius;
+
+ edge->m_vertex1 = m_vertices[index + 0];
+ edge->m_vertex2 = m_vertices[index + 1];
+
+ if (index > 0)
+ {
+ edge->m_vertex0 = m_vertices[index - 1];
+ edge->m_hasVertex0 = true;
+ }
+ else
+ {
+ edge->m_vertex0 = m_prevVertex;
+ edge->m_hasVertex0 = m_hasPrevVertex;
+ }
+
+ if (index < m_count - 2)
+ {
+ edge->m_vertex3 = m_vertices[index + 2];
+ edge->m_hasVertex3 = true;
+ }
+ else
+ {
+ edge->m_vertex3 = m_nextVertex;
+ edge->m_hasVertex3 = m_hasNextVertex;
+ }
+}
+
+bool b2ChainShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
+{
+ B2_NOT_USED(xf);
+ B2_NOT_USED(p);
+ return false;
+}
+
+bool b2ChainShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& xf, int32 childIndex) const
+{
+ b2Assert(childIndex < m_count);
+
+ b2EdgeShape edgeShape;
+
+ int32 i1 = childIndex;
+ int32 i2 = childIndex + 1;
+ if (i2 == m_count)
+ {
+ i2 = 0;
+ }
+
+ edgeShape.m_vertex1 = m_vertices[i1];
+ edgeShape.m_vertex2 = m_vertices[i2];
+
+ return edgeShape.RayCast(output, input, xf, 0);
+}
+
+void b2ChainShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
+{
+ b2Assert(childIndex < m_count);
+
+ int32 i1 = childIndex;
+ int32 i2 = childIndex + 1;
+ if (i2 == m_count)
+ {
+ i2 = 0;
+ }
+
+ b2Vec2 v1 = b2Mul(xf, m_vertices[i1]);
+ b2Vec2 v2 = b2Mul(xf, m_vertices[i2]);
+
+ aabb->lowerBound = b2Min(v1, v2);
+ aabb->upperBound = b2Max(v1, v2);
+}
+
+void b2ChainShape::ComputeMass(b2MassData* massData, float32 density) const
+{
+ B2_NOT_USED(density);
+
+ massData->mass = 0.0f;
+ massData->center.SetZero();
+ massData->I = 0.0f;
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/Shapes/b2ChainShape.h b/engines/ngi/box2d/Collision/Shapes/b2ChainShape.h
new file mode 100644
index 00000000000..a78e62cb0b2
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2ChainShape.h
@@ -0,0 +1,106 @@
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_CHAIN_SHAPE_H
+#define B2_CHAIN_SHAPE_H
+
+#include "engines/ngi/box2d/Collision/Shapes/b2Shape.h"
+
+namespace NGI {
+
+class b2EdgeShape;
+
+/// A chain shape is a free form sequence of line segments.
+/// The chain has two-sided collision, so you can use inside and outside collision.
+/// Therefore, you may use any winding order.
+/// Since there may be many vertices, they are allocated using b2Alloc.
+/// Connectivity information is used to create smooth collisions.
+/// WARNING: The chain will not collide properly if there are self-intersections.
+class b2ChainShape : public b2Shape
+{
+public:
+ b2ChainShape();
+
+ /// The destructor frees the vertices using b2Free.
+ ~b2ChainShape();
+
+ /// Create a loop. This automatically adjusts connectivity.
+ /// @param vertices an array of vertices, these are copied
+ /// @param count the vertex count
+ void CreateLoop(const b2Vec2* vertices, int32 count);
+
+ /// Create a chain with isolated end vertices.
+ /// @param vertices an array of vertices, these are copied
+ /// @param count the vertex count
+ void CreateChain(const b2Vec2* vertices, int32 count);
+
+ /// Establish connectivity to a vertex that precedes the first vertex.
+ /// Don't call this for loops.
+ void SetPrevVertex(const b2Vec2& prevVertex);
+
+ /// Establish connectivity to a vertex that follows the last vertex.
+ /// Don't call this for loops.
+ void SetNextVertex(const b2Vec2& nextVertex);
+
+ /// Implement b2Shape. Vertices are cloned using b2Alloc.
+ b2Shape* Clone(b2BlockAllocator* allocator) const;
+
+ /// @see b2Shape::GetChildCount
+ int32 GetChildCount() const;
+
+ /// Get a child edge.
+ void GetChildEdge(b2EdgeShape* edge, int32 index) const;
+
+ /// This always return false.
+ /// @see b2Shape::TestPoint
+ bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
+
+ /// Implement b2Shape.
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& transform, int32 childIndex) const;
+
+ /// @see b2Shape::ComputeAABB
+ void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
+
+ /// Chains have zero mass.
+ /// @see b2Shape::ComputeMass
+ void ComputeMass(b2MassData* massData, float32 density) const;
+
+ /// The vertices. Owned by this class.
+ b2Vec2* m_vertices;
+
+ /// The vertex count.
+ int32 m_count;
+
+ b2Vec2 m_prevVertex, m_nextVertex;
+ bool m_hasPrevVertex, m_hasNextVertex;
+};
+
+inline b2ChainShape::b2ChainShape()
+{
+ m_type = e_chain;
+ m_radius = b2_polygonRadius;
+ m_vertices = NULL;
+ m_count = 0;
+ m_hasPrevVertex = NULL;
+ m_hasNextVertex = NULL;
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/Shapes/b2CircleShape.cpp b/engines/ngi/box2d/Collision/Shapes/b2CircleShape.cpp
new file mode 100644
index 00000000000..3f163b6c925
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2CircleShape.cpp
@@ -0,0 +1,104 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/Shapes/b2CircleShape.h"
+#include <new>
+
+namespace NGI {
+using namespace std;
+
+b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const
+{
+ void* mem = allocator->Allocate(sizeof(b2CircleShape));
+ b2CircleShape* clone = new (mem) b2CircleShape;
+ *clone = *this;
+ return clone;
+}
+
+int32 b2CircleShape::GetChildCount() const
+{
+ return 1;
+}
+
+bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const
+{
+ b2Vec2 center = transform.p + b2Mul(transform.q, m_p);
+ b2Vec2 d = p - center;
+ return b2Dot(d, d) <= m_radius * m_radius;
+}
+
+// Collision Detection in Interactive 3D Environments by Gino van den Bergen
+// From Section 3.1.2
+// x = s + a * r
+// norm(x) = radius
+bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& transform, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ b2Vec2 position = transform.p + b2Mul(transform.q, m_p);
+ b2Vec2 s = input.p1 - position;
+ float32 b = b2Dot(s, s) - m_radius * m_radius;
+
+ // Solve quadratic equation.
+ b2Vec2 r = input.p2 - input.p1;
+ float32 c = b2Dot(s, r);
+ float32 rr = b2Dot(r, r);
+ float32 sigma = c * c - rr * b;
+
+ // Check for negative discriminant and short segment.
+ if (sigma < 0.0f || rr < b2_epsilon)
+ {
+ return false;
+ }
+
+ // Find the point of intersection of the line with the circle.
+ float32 a = -(c + b2Sqrt(sigma));
+
+ // Is the intersection point on the segment?
+ if (0.0f <= a && a <= input.maxFraction * rr)
+ {
+ a /= rr;
+ output->fraction = a;
+ output->normal = s + a * r;
+ output->normal.Normalize();
+ return true;
+ }
+
+ return false;
+}
+
+void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ b2Vec2 p = transform.p + b2Mul(transform.q, m_p);
+ aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);
+ aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);
+}
+
+void b2CircleShape::ComputeMass(b2MassData* massData, float32 density) const
+{
+ massData->mass = density * b2_pi * m_radius * m_radius;
+ massData->center = m_p;
+
+ // inertia about the local origin
+ massData->I = massData->mass * (0.5f * m_radius * m_radius + b2Dot(m_p, m_p));
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/Shapes/b2CircleShape.h b/engines/ngi/box2d/Collision/Shapes/b2CircleShape.h
new file mode 100644
index 00000000000..7b02cd97756
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2CircleShape.h
@@ -0,0 +1,95 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_CIRCLE_SHAPE_H
+#define B2_CIRCLE_SHAPE_H
+
+#include "engines/ngi/box2d/Collision/Shapes/b2Shape.h"
+
+namespace NGI {
+
+/// A circle shape.
+class b2CircleShape : public b2Shape
+{
+public:
+ b2CircleShape();
+
+ /// Implement b2Shape.
+ b2Shape* Clone(b2BlockAllocator* allocator) const;
+
+ /// @see b2Shape::GetChildCount
+ int32 GetChildCount() const;
+
+ /// Implement b2Shape.
+ bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
+
+ /// Implement b2Shape.
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& transform, int32 childIndex) const;
+
+ /// @see b2Shape::ComputeAABB
+ void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
+
+ /// @see b2Shape::ComputeMass
+ void ComputeMass(b2MassData* massData, float32 density) const;
+
+ /// Get the supporting vertex index in the given direction.
+ int32 GetSupport(const b2Vec2& d) const;
+
+ /// Get the supporting vertex in the given direction.
+ const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
+
+ /// Get the vertex count.
+ int32 GetVertexCount() const { return 1; }
+
+ /// Get a vertex by index. Used by b2Distance.
+ const b2Vec2& GetVertex(int32 index) const;
+
+ /// Position
+ b2Vec2 m_p;
+};
+
+inline b2CircleShape::b2CircleShape()
+{
+ m_type = e_circle;
+ m_radius = 0.0f;
+ m_p.SetZero();
+}
+
+inline int32 b2CircleShape::GetSupport(const b2Vec2 &d) const
+{
+ B2_NOT_USED(d);
+ return 0;
+}
+
+inline const b2Vec2& b2CircleShape::GetSupportVertex(const b2Vec2 &d) const
+{
+ B2_NOT_USED(d);
+ return m_p;
+}
+
+inline const b2Vec2& b2CircleShape::GetVertex(int32 index) const
+{
+ B2_NOT_USED(index);
+ b2Assert(index == 0);
+ return m_p;
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/Shapes/b2EdgeShape.cpp b/engines/ngi/box2d/Collision/Shapes/b2EdgeShape.cpp
new file mode 100644
index 00000000000..cfcea8f1647
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2EdgeShape.cpp
@@ -0,0 +1,143 @@
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h"
+#include <new>
+
+namespace NGI {
+using namespace std;
+
+void b2EdgeShape::Set(const b2Vec2& v1, const b2Vec2& v2)
+{
+ m_vertex1 = v1;
+ m_vertex2 = v2;
+ m_hasVertex0 = false;
+ m_hasVertex3 = false;
+}
+
+b2Shape* b2EdgeShape::Clone(b2BlockAllocator* allocator) const
+{
+ void* mem = allocator->Allocate(sizeof(b2EdgeShape));
+ b2EdgeShape* clone = new (mem) b2EdgeShape;
+ *clone = *this;
+ return clone;
+}
+
+int32 b2EdgeShape::GetChildCount() const
+{
+ return 1;
+}
+
+bool b2EdgeShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
+{
+ B2_NOT_USED(xf);
+ B2_NOT_USED(p);
+ return false;
+}
+
+// p = p1 + t * d
+// v = v1 + s * e
+// p1 + t * d = v1 + s * e
+// s * e - t * d = p1 - v1
+bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& xf, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ // Put the ray into the edge's frame of reference.
+ b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
+ b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
+ b2Vec2 d = p2 - p1;
+
+ b2Vec2 v1 = m_vertex1;
+ b2Vec2 v2 = m_vertex2;
+ b2Vec2 e = v2 - v1;
+ b2Vec2 normal(e.y, -e.x);
+ normal.Normalize();
+
+ // q = p1 + t * d
+ // dot(normal, q - v1) = 0
+ // dot(normal, p1 - v1) + t * dot(normal, d) = 0
+ float32 numerator = b2Dot(normal, v1 - p1);
+ float32 denominator = b2Dot(normal, d);
+
+ if (denominator == 0.0f)
+ {
+ return false;
+ }
+
+ float32 t = numerator / denominator;
+ if (t < 0.0f || input.maxFraction < t)
+ {
+ return false;
+ }
+
+ b2Vec2 q = p1 + t * d;
+
+ // q = v1 + s * r
+ // s = dot(q - v1, r) / dot(r, r)
+ b2Vec2 r = v2 - v1;
+ float32 rr = b2Dot(r, r);
+ if (rr == 0.0f)
+ {
+ return false;
+ }
+
+ float32 s = b2Dot(q - v1, r) / rr;
+ if (s < 0.0f || 1.0f < s)
+ {
+ return false;
+ }
+
+ output->fraction = t;
+ if (numerator > 0.0f)
+ {
+ output->normal = -normal;
+ }
+ else
+ {
+ output->normal = normal;
+ }
+ return true;
+}
+
+void b2EdgeShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ b2Vec2 v1 = b2Mul(xf, m_vertex1);
+ b2Vec2 v2 = b2Mul(xf, m_vertex2);
+
+ b2Vec2 lower = b2Min(v1, v2);
+ b2Vec2 upper = b2Max(v1, v2);
+
+ b2Vec2 r(m_radius, m_radius);
+ aabb->lowerBound = lower - r;
+ aabb->upperBound = upper + r;
+}
+
+void b2EdgeShape::ComputeMass(b2MassData* massData, float32 density) const
+{
+ B2_NOT_USED(density);
+
+ massData->mass = 0.0f;
+ massData->center = 0.5f * (m_vertex1 + m_vertex2);
+ massData->I = 0.0f;
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h b/engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h
new file mode 100644
index 00000000000..b33dd9c7694
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h
@@ -0,0 +1,78 @@
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_EDGE_SHAPE_H
+#define B2_EDGE_SHAPE_H
+
+#include "engines/ngi/box2d/Collision/Shapes/b2Shape.h"
+
+namespace NGI {
+
+/// A line segment (edge) shape. These can be connected in chains or loops
+/// to other edge shapes. The connectivity information is used to ensure
+/// correct contact normals.
+class b2EdgeShape : public b2Shape
+{
+public:
+ b2EdgeShape();
+
+ /// Set this as an isolated edge.
+ void Set(const b2Vec2& v1, const b2Vec2& v2);
+
+ /// Implement b2Shape.
+ b2Shape* Clone(b2BlockAllocator* allocator) const;
+
+ /// @see b2Shape::GetChildCount
+ int32 GetChildCount() const;
+
+ /// @see b2Shape::TestPoint
+ bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
+
+ /// Implement b2Shape.
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& transform, int32 childIndex) const;
+
+ /// @see b2Shape::ComputeAABB
+ void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
+
+ /// @see b2Shape::ComputeMass
+ void ComputeMass(b2MassData* massData, float32 density) const;
+
+ /// These are the edge vertices
+ b2Vec2 m_vertex1, m_vertex2;
+
+ /// Optional adjacent vertices. These are used for smooth collision.
+ b2Vec2 m_vertex0, m_vertex3;
+ bool m_hasVertex0, m_hasVertex3;
+};
+
+inline b2EdgeShape::b2EdgeShape()
+{
+ m_type = e_edge;
+ m_radius = b2_polygonRadius;
+ m_vertex0.x = 0.0f;
+ m_vertex0.y = 0.0f;
+ m_vertex3.x = 0.0f;
+ m_vertex3.y = 0.0f;
+ m_hasVertex0 = false;
+ m_hasVertex3 = false;
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/Shapes/b2PolygonShape.cpp b/engines/ngi/box2d/Collision/Shapes/b2PolygonShape.cpp
new file mode 100644
index 00000000000..3e68755f61f
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2PolygonShape.cpp
@@ -0,0 +1,365 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h"
+#include <new>
+
+namespace NGI {
+
+b2Shape* b2PolygonShape::Clone(b2BlockAllocator* allocator) const
+{
+ void* mem = allocator->Allocate(sizeof(b2PolygonShape));
+ b2PolygonShape* clone = new (mem) b2PolygonShape;
+ *clone = *this;
+ return clone;
+}
+
+void b2PolygonShape::SetAsBox(float32 hx, float32 hy)
+{
+ m_vertexCount = 4;
+ m_vertices[0].Set(-hx, -hy);
+ m_vertices[1].Set( hx, -hy);
+ m_vertices[2].Set( hx, hy);
+ m_vertices[3].Set(-hx, hy);
+ m_normals[0].Set(0.0f, -1.0f);
+ m_normals[1].Set(1.0f, 0.0f);
+ m_normals[2].Set(0.0f, 1.0f);
+ m_normals[3].Set(-1.0f, 0.0f);
+ m_centroid.SetZero();
+}
+
+void b2PolygonShape::SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle)
+{
+ m_vertexCount = 4;
+ m_vertices[0].Set(-hx, -hy);
+ m_vertices[1].Set( hx, -hy);
+ m_vertices[2].Set( hx, hy);
+ m_vertices[3].Set(-hx, hy);
+ m_normals[0].Set(0.0f, -1.0f);
+ m_normals[1].Set(1.0f, 0.0f);
+ m_normals[2].Set(0.0f, 1.0f);
+ m_normals[3].Set(-1.0f, 0.0f);
+ m_centroid = center;
+
+ b2Transform xf;
+ xf.p = center;
+ xf.q.Set(angle);
+
+ // Transform vertices and normals.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ m_vertices[i] = b2Mul(xf, m_vertices[i]);
+ m_normals[i] = b2Mul(xf.q, m_normals[i]);
+ }
+}
+
+int32 b2PolygonShape::GetChildCount() const
+{
+ return 1;
+}
+
+static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count)
+{
+ b2Assert(count >= 3);
+
+ b2Vec2 c; c.Set(0.0f, 0.0f);
+ float32 area = 0.0f;
+
+ // pRef is the reference point for forming triangles.
+ // It's location doesn't change the result (except for rounding error).
+ b2Vec2 pRef(0.0f, 0.0f);
+#if 0
+ // This code would put the reference point inside the polygon.
+ for (int32 i = 0; i < count; ++i)
+ {
+ pRef += vs[i];
+ }
+ pRef *= 1.0f / count;
+#endif
+
+ const float32 inv3 = 1.0f / 3.0f;
+
+ for (int32 i = 0; i < count; ++i)
+ {
+ // Triangle vertices.
+ b2Vec2 p1 = pRef;
+ b2Vec2 p2 = vs[i];
+ b2Vec2 p3 = i + 1 < count ? vs[i+1] : vs[0];
+
+ b2Vec2 e1 = p2 - p1;
+ b2Vec2 e2 = p3 - p1;
+
+ float32 D = b2Cross(e1, e2);
+
+ float32 triangleArea = 0.5f * D;
+ area += triangleArea;
+
+ // Area weighted centroid
+ c += triangleArea * inv3 * (p1 + p2 + p3);
+ }
+
+ // Centroid
+ b2Assert(area > b2_epsilon);
+ c *= 1.0f / area;
+ return c;
+}
+
+void b2PolygonShape::Set(const b2Vec2* vertices, int32 count)
+{
+ b2Assert(3 <= count && count <= b2_maxPolygonVertices);
+ m_vertexCount = count;
+
+ // Copy vertices.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ m_vertices[i] = vertices[i];
+ }
+
+ // Compute normals. Ensure the edges have non-zero length.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ int32 i1 = i;
+ int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
+ b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
+ b2Assert(edge.LengthSquared() > b2_epsilon * b2_epsilon);
+ m_normals[i] = b2Cross(edge, 1.0f);
+ m_normals[i].Normalize();
+ }
+
+#ifdef _DEBUG
+ // Ensure the polygon is convex and the interior
+ // is to the left of each edge.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ int32 i1 = i;
+ int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
+ b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
+
+ for (int32 j = 0; j < m_vertexCount; ++j)
+ {
+ // Don't check vertices on the current edge.
+ if (j == i1 || j == i2)
+ {
+ continue;
+ }
+
+ b2Vec2 r = m_vertices[j] - m_vertices[i1];
+
+ // If this crashes, your polygon is non-convex, has colinear edges,
+ // or the winding order is wrong.
+ float32 s = b2Cross(edge, r);
+ b2Assert(s > 0.0f && "ERROR: Please ensure your polygon is convex and has a CCW winding order");
+ }
+ }
+#endif
+
+ // Compute the polygon centroid.
+ m_centroid = ComputeCentroid(m_vertices, m_vertexCount);
+}
+
+bool b2PolygonShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
+{
+ b2Vec2 pLocal = b2MulT(xf.q, p - xf.p);
+
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ float32 dot = b2Dot(m_normals[i], pLocal - m_vertices[i]);
+ if (dot > 0.0f)
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool b2PolygonShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& xf, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ // Put the ray into the polygon's frame of reference.
+ b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
+ b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
+ b2Vec2 d = p2 - p1;
+
+ float32 lower = 0.0f, upper = input.maxFraction;
+
+ int32 index = -1;
+
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ // p = p1 + a * d
+ // dot(normal, p - v) = 0
+ // dot(normal, p1 - v) + a * dot(normal, d) = 0
+ float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1);
+ float32 denominator = b2Dot(m_normals[i], d);
+
+ if (denominator == 0.0f)
+ {
+ if (numerator < 0.0f)
+ {
+ return false;
+ }
+ }
+ else
+ {
+ // Note: we want this predicate without division:
+ // lower < numerator / denominator, where denominator < 0
+ // Since denominator < 0, we have to flip the inequality:
+ // lower < numerator / denominator <==> denominator * lower > numerator.
+ if (denominator < 0.0f && numerator < lower * denominator)
+ {
+ // Increase lower.
+ // The segment enters this half-space.
+ lower = numerator / denominator;
+ index = i;
+ }
+ else if (denominator > 0.0f && numerator < upper * denominator)
+ {
+ // Decrease upper.
+ // The segment exits this half-space.
+ upper = numerator / denominator;
+ }
+ }
+
+ // The use of epsilon here causes the assert on lower to trip
+ // in some cases. Apparently the use of epsilon was to make edge
+ // shapes work, but now those are handled separately.
+ //if (upper < lower - b2_epsilon)
+ if (upper < lower)
+ {
+ return false;
+ }
+ }
+
+ b2Assert(0.0f <= lower && lower <= input.maxFraction);
+
+ if (index >= 0)
+ {
+ output->fraction = lower;
+ output->normal = b2Mul(xf.q, m_normals[index]);
+ return true;
+ }
+
+ return false;
+}
+
+void b2PolygonShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ b2Vec2 lower = b2Mul(xf, m_vertices[0]);
+ b2Vec2 upper = lower;
+
+ for (int32 i = 1; i < m_vertexCount; ++i)
+ {
+ b2Vec2 v = b2Mul(xf, m_vertices[i]);
+ lower = b2Min(lower, v);
+ upper = b2Max(upper, v);
+ }
+
+ b2Vec2 r(m_radius, m_radius);
+ aabb->lowerBound = lower - r;
+ aabb->upperBound = upper + r;
+}
+
+void b2PolygonShape::ComputeMass(b2MassData* massData, float32 density) const
+{
+ // Polygon mass, centroid, and inertia.
+ // Let rho be the polygon density in mass per unit area.
+ // Then:
+ // mass = rho * int(dA)
+ // centroid.x = (1/mass) * rho * int(x * dA)
+ // centroid.y = (1/mass) * rho * int(y * dA)
+ // I = rho * int((x*x + y*y) * dA)
+ //
+ // We can compute these integrals by summing all the integrals
+ // for each triangle of the polygon. To evaluate the integral
+ // for a single triangle, we make a change of variables to
+ // the (u,v) coordinates of the triangle:
+ // x = x0 + e1x * u + e2x * v
+ // y = y0 + e1y * u + e2y * v
+ // where 0 <= u && 0 <= v && u + v <= 1.
+ //
+ // We integrate u from [0,1-v] and then v from [0,1].
+ // We also need to use the Jacobian of the transformation:
+ // D = cross(e1, e2)
+ //
+ // Simplification: triangle centroid = (1/3) * (p1 + p2 + p3)
+ //
+ // The rest of the derivation is handled by computer algebra.
+
+ b2Assert(m_vertexCount >= 3);
+
+ b2Vec2 center; center.Set(0.0f, 0.0f);
+ float32 area = 0.0f;
+ float32 I = 0.0f;
+
+ // s is the reference point for forming triangles.
+ // It's location doesn't change the result (except for rounding error).
+ b2Vec2 s(0.0f, 0.0f);
+
+ // This code would put the reference point inside the polygon.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ s += m_vertices[i];
+ }
+ s *= 1.0f / m_vertexCount;
+
+ const float32 k_inv3 = 1.0f / 3.0f;
+
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ // Triangle vertices.
+ b2Vec2 e1 = m_vertices[i] - s;
+ b2Vec2 e2 = i + 1 < m_vertexCount ? m_vertices[i+1] - s : m_vertices[0] - s;
+
+ float32 D = b2Cross(e1, e2);
+
+ float32 triangleArea = 0.5f * D;
+ area += triangleArea;
+
+ // Area weighted centroid
+ center += triangleArea * k_inv3 * (e1 + e2);
+
+ float32 ex1 = e1.x, ey1 = e1.y;
+ float32 ex2 = e2.x, ey2 = e2.y;
+
+ float32 intx2 = ex1*ex1 + ex2*ex1 + ex2*ex2;
+ float32 inty2 = ey1*ey1 + ey2*ey1 + ey2*ey2;
+
+ I += (0.25f * k_inv3 * D) * (intx2 + inty2);
+ }
+
+ // Total mass
+ massData->mass = density * area;
+
+ // Center of mass
+ b2Assert(area > b2_epsilon);
+ center *= 1.0f / area;
+ massData->center = center + s;
+
+ // Inertia tensor relative to the local origin (point s).
+ massData->I = density * I;
+
+ // Shift to center of mass then to original body origin.
+ massData->I += massData->mass * (b2Dot(massData->center, massData->center) - b2Dot(center, center));
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h b/engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h
new file mode 100644
index 00000000000..b01ab757952
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h
@@ -0,0 +1,99 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_POLYGON_SHAPE_H
+#define B2_POLYGON_SHAPE_H
+
+#include "engines/ngi/box2d/Collision/Shapes/b2Shape.h"
+
+namespace NGI {
+
+/// A convex polygon. It is assumed that the interior of the polygon is to
+/// the left of each edge.
+/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.
+/// In most cases you should not need many vertices for a convex polygon.
+class b2PolygonShape : public b2Shape
+{
+public:
+ b2PolygonShape();
+
+ /// Implement b2Shape.
+ b2Shape* Clone(b2BlockAllocator* allocator) const;
+
+ /// @see b2Shape::GetChildCount
+ int32 GetChildCount() const;
+
+ /// Copy vertices. This assumes the vertices define a convex polygon.
+ /// It is assumed that the exterior is the the right of each edge.
+ /// The count must be in the range [3, b2_maxPolygonVertices].
+ void Set(const b2Vec2* vertices, int32 vertexCount);
+
+ /// Build vertices to represent an axis-aligned box.
+ /// @param hx the half-width.
+ /// @param hy the half-height.
+ void SetAsBox(float32 hx, float32 hy);
+
+ /// Build vertices to represent an oriented box.
+ /// @param hx the half-width.
+ /// @param hy the half-height.
+ /// @param center the center of the box in local coordinates.
+ /// @param angle the rotation of the box in local coordinates.
+ void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);
+
+ /// @see b2Shape::TestPoint
+ bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
+
+ /// Implement b2Shape.
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& transform, int32 childIndex) const;
+
+ /// @see b2Shape::ComputeAABB
+ void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
+
+ /// @see b2Shape::ComputeMass
+ void ComputeMass(b2MassData* massData, float32 density) const;
+
+ /// Get the vertex count.
+ int32 GetVertexCount() const { return m_vertexCount; }
+
+ /// Get a vertex by index.
+ const b2Vec2& GetVertex(int32 index) const;
+
+ b2Vec2 m_centroid;
+ b2Vec2 m_vertices[b2_maxPolygonVertices];
+ b2Vec2 m_normals[b2_maxPolygonVertices];
+ int32 m_vertexCount;
+};
+
+inline b2PolygonShape::b2PolygonShape()
+{
+ m_type = e_polygon;
+ m_radius = b2_polygonRadius;
+ m_vertexCount = 0;
+ m_centroid.SetZero();
+}
+
+inline const b2Vec2& b2PolygonShape::GetVertex(int32 index) const
+{
+ b2Assert(0 <= index && index < m_vertexCount);
+ return m_vertices[index];
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/Shapes/b2Shape.h b/engines/ngi/box2d/Collision/Shapes/b2Shape.h
new file mode 100644
index 00000000000..fc5f5be402c
--- /dev/null
+++ b/engines/ngi/box2d/Collision/Shapes/b2Shape.h
@@ -0,0 +1,105 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_SHAPE_H
+#define B2_SHAPE_H
+
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include "engines/ngi/box2d/Common/b2Math.h"
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+
+namespace NGI {
+
+/// This holds the mass data computed for a shape.
+struct b2MassData
+{
+ /// The mass of the shape, usually in kilograms.
+ float32 mass;
+
+ /// The position of the shape's centroid relative to the shape's origin.
+ b2Vec2 center;
+
+ /// The rotational inertia of the shape about the local origin.
+ float32 I;
+};
+
+/// A shape is used for collision detection. You can create a shape however you like.
+/// Shapes used for simulation in b2World are created automatically when a b2Fixture
+/// is created. Shapes may encapsulate a one or more child shapes.
+class b2Shape
+{
+public:
+
+ enum Type
+ {
+ e_circle = 0,
+ e_edge = 1,
+ e_polygon = 2,
+ e_chain = 3,
+ e_typeCount = 4
+ };
+
+ virtual ~b2Shape() {}
+
+ /// Clone the concrete shape using the provided allocator.
+ virtual b2Shape* Clone(b2BlockAllocator* allocator) const = 0;
+
+ /// Get the type of this shape. You can use this to down cast to the concrete shape.
+ /// @return the shape type.
+ Type GetType() const;
+
+ /// Get the number of child primitives.
+ virtual int32 GetChildCount() const = 0;
+
+ /// Test a point for containment in this shape. This only works for convex shapes.
+ /// @param xf the shape world transform.
+ /// @param p a point in world coordinates.
+ virtual bool TestPoint(const b2Transform& xf, const b2Vec2& p) const = 0;
+
+ /// Cast a ray against a child shape.
+ /// @param output the ray-cast results.
+ /// @param input the ray-cast input parameters.
+ /// @param transform the transform to be applied to the shape.
+ /// @param childIndex the child shape index
+ virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& transform, int32 childIndex) const = 0;
+
+ /// Given a transform, compute the associated axis aligned bounding box for a child shape.
+ /// @param aabb returns the axis aligned box.
+ /// @param xf the world transform of the shape.
+ /// @param childIndex the child shape
+ virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const = 0;
+
+ /// Compute the mass properties of this shape using its dimensions and density.
+ /// The inertia tensor is computed about the local origin.
+ /// @param massData returns the mass data for this shape.
+ /// @param density the density in kilograms per meter squared.
+ virtual void ComputeMass(b2MassData* massData, float32 density) const = 0;
+
+ Type m_type;
+ float32 m_radius;
+};
+
+inline b2Shape::Type b2Shape::GetType() const
+{
+ return m_type;
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/b2BroadPhase.cpp b/engines/ngi/box2d/Collision/b2BroadPhase.cpp
new file mode 100644
index 00000000000..6030102c925
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2BroadPhase.cpp
@@ -0,0 +1,126 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/b2BroadPhase.h"
+#include <cstring>
+
+namespace NGI {
+using namespace std;
+
+b2BroadPhase::b2BroadPhase()
+{
+ m_proxyCount = 0;
+
+ m_pairCapacity = 16;
+ m_pairCount = 0;
+ m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
+
+ m_moveCapacity = 16;
+ m_moveCount = 0;
+ m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
+}
+
+b2BroadPhase::~b2BroadPhase()
+{
+ b2Free(m_moveBuffer);
+ b2Free(m_pairBuffer);
+}
+
+int32 b2BroadPhase::CreateProxy(const b2AABB& aabb, void* userData)
+{
+ int32 proxyId = m_tree.CreateProxy(aabb, userData);
+ ++m_proxyCount;
+ BufferMove(proxyId);
+ return proxyId;
+}
+
+void b2BroadPhase::DestroyProxy(int32 proxyId)
+{
+ UnBufferMove(proxyId);
+ --m_proxyCount;
+ m_tree.DestroyProxy(proxyId);
+}
+
+void b2BroadPhase::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement)
+{
+ bool buffer = m_tree.MoveProxy(proxyId, aabb, displacement);
+ if (buffer)
+ {
+ BufferMove(proxyId);
+ }
+}
+
+void b2BroadPhase::TouchProxy(int32 proxyId)
+{
+ BufferMove(proxyId);
+}
+
+void b2BroadPhase::BufferMove(int32 proxyId)
+{
+ if (m_moveCount == m_moveCapacity)
+ {
+ int32* oldBuffer = m_moveBuffer;
+ m_moveCapacity *= 2;
+ m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
+ memcpy(m_moveBuffer, oldBuffer, m_moveCount * sizeof(int32));
+ b2Free(oldBuffer);
+ }
+
+ m_moveBuffer[m_moveCount] = proxyId;
+ ++m_moveCount;
+}
+
+void b2BroadPhase::UnBufferMove(int32 proxyId)
+{
+ for (int32 i = 0; i < m_moveCount; ++i)
+ {
+ if (m_moveBuffer[i] == proxyId)
+ {
+ m_moveBuffer[i] = e_nullProxy;
+ return;
+ }
+ }
+}
+
+// This is called from b2DynamicTree::Query when we are gathering pairs.
+bool b2BroadPhase::QueryCallback(int32 proxyId)
+{
+ // A proxy cannot form a pair with itself.
+ if (proxyId == m_queryProxyId)
+ {
+ return true;
+ }
+
+ // Grow the pair buffer as needed.
+ if (m_pairCount == m_pairCapacity)
+ {
+ b2Pair* oldBuffer = m_pairBuffer;
+ m_pairCapacity *= 2;
+ m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
+ memcpy(m_pairBuffer, oldBuffer, m_pairCount * sizeof(b2Pair));
+ b2Free(oldBuffer);
+ }
+
+ m_pairBuffer[m_pairCount].proxyIdA = b2Min(proxyId, m_queryProxyId);
+ m_pairBuffer[m_pairCount].proxyIdB = b2Max(proxyId, m_queryProxyId);
+ ++m_pairCount;
+
+ return true;
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/b2BroadPhase.h b/engines/ngi/box2d/Collision/b2BroadPhase.h
new file mode 100644
index 00000000000..5020f4a4b0c
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2BroadPhase.h
@@ -0,0 +1,252 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_BROAD_PHASE_H
+#define B2_BROAD_PHASE_H
+
+#include "engines/ngi/box2d/Common/b2Settings.h"
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Collision/b2DynamicTree.h"
+#include <algorithm>
+
+namespace NGI {
+
+struct b2Pair
+{
+ int32 proxyIdA;
+ int32 proxyIdB;
+ int32 next;
+};
+
+/// The broad-phase is used for computing pairs and performing volume queries and ray casts.
+/// This broad-phase does not persist pairs. Instead, this reports potentially new pairs.
+/// It is up to the client to consume the new pairs and to track subsequent overlap.
+class b2BroadPhase
+{
+public:
+
+ enum
+ {
+ e_nullProxy = -1
+ };
+
+ b2BroadPhase();
+ ~b2BroadPhase();
+
+ /// Create a proxy with an initial AABB. Pairs are not reported until
+ /// UpdatePairs is called.
+ int32 CreateProxy(const b2AABB& aabb, void* userData);
+
+ /// Destroy a proxy. It is up to the client to remove any pairs.
+ void DestroyProxy(int32 proxyId);
+
+ /// Call MoveProxy as many times as you like, then when you are done
+ /// call UpdatePairs to finalized the proxy pairs (for your time step).
+ void MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement);
+
+ /// Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.
+ void TouchProxy(int32 proxyId);
+
+ /// Get the fat AABB for a proxy.
+ const b2AABB& GetFatAABB(int32 proxyId) const;
+
+ /// Get user data from a proxy. Returns NULL if the id is invalid.
+ void* GetUserData(int32 proxyId) const;
+
+ /// Test overlap of fat AABBs.
+ bool TestOverlap(int32 proxyIdA, int32 proxyIdB) const;
+
+ /// Get the number of proxies.
+ int32 GetProxyCount() const;
+
+ /// Update the pairs. This results in pair callbacks. This can only add pairs.
+ template <typename T>
+ void UpdatePairs(T* callback);
+
+ /// Query an AABB for overlapping proxies. The callback class
+ /// is called for each proxy that overlaps the supplied AABB.
+ template <typename T>
+ void Query(T* callback, const b2AABB& aabb) const;
+
+ /// Ray-cast against the proxies in the tree. This relies on the callback
+ /// to perform a exact ray-cast in the case were the proxy contains a shape.
+ /// The callback also performs the any collision filtering. This has performance
+ /// roughly equal to k * log(n), where k is the number of collisions and n is the
+ /// number of proxies in the tree.
+ /// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
+ /// @param callback a callback class that is called for each proxy that is hit by the ray.
+ template <typename T>
+ void RayCast(T* callback, const b2RayCastInput& input) const;
+
+ /// Get the height of the embedded tree.
+ int32 GetTreeHeight() const;
+
+ /// Get the balance of the embedded tree.
+ int32 GetTreeBalance() const;
+
+ /// Get the quality metric of the embedded tree.
+ float32 GetTreeQuality() const;
+
+private:
+
+ friend class b2DynamicTree;
+
+ void BufferMove(int32 proxyId);
+ void UnBufferMove(int32 proxyId);
+
+ bool QueryCallback(int32 proxyId);
+
+ b2DynamicTree m_tree;
+
+ int32 m_proxyCount;
+
+ int32* m_moveBuffer;
+ int32 m_moveCapacity;
+ int32 m_moveCount;
+
+ b2Pair* m_pairBuffer;
+ int32 m_pairCapacity;
+ int32 m_pairCount;
+
+ int32 m_queryProxyId;
+};
+
+/// This is used to sort pairs.
+inline bool b2PairLessThan(const b2Pair& pair1, const b2Pair& pair2)
+{
+ if (pair1.proxyIdA < pair2.proxyIdA)
+ {
+ return true;
+ }
+
+ if (pair1.proxyIdA == pair2.proxyIdA)
+ {
+ return pair1.proxyIdB < pair2.proxyIdB;
+ }
+
+ return false;
+}
+
+inline void* b2BroadPhase::GetUserData(int32 proxyId) const
+{
+ return m_tree.GetUserData(proxyId);
+}
+
+inline bool b2BroadPhase::TestOverlap(int32 proxyIdA, int32 proxyIdB) const
+{
+ const b2AABB& aabbA = m_tree.GetFatAABB(proxyIdA);
+ const b2AABB& aabbB = m_tree.GetFatAABB(proxyIdB);
+ return b2TestOverlap(aabbA, aabbB);
+}
+
+inline const b2AABB& b2BroadPhase::GetFatAABB(int32 proxyId) const
+{
+ return m_tree.GetFatAABB(proxyId);
+}
+
+inline int32 b2BroadPhase::GetProxyCount() const
+{
+ return m_proxyCount;
+}
+
+inline int32 b2BroadPhase::GetTreeHeight() const
+{
+ return m_tree.GetHeight();
+}
+
+inline int32 b2BroadPhase::GetTreeBalance() const
+{
+ return m_tree.GetMaxBalance();
+}
+
+inline float32 b2BroadPhase::GetTreeQuality() const
+{
+ return m_tree.GetAreaRatio();
+}
+
+template <typename T>
+void b2BroadPhase::UpdatePairs(T* callback)
+{
+ // Reset pair buffer
+ m_pairCount = 0;
+
+ // Perform tree queries for all moving proxies.
+ for (int32 i = 0; i < m_moveCount; ++i)
+ {
+ m_queryProxyId = m_moveBuffer[i];
+ if (m_queryProxyId == e_nullProxy)
+ {
+ continue;
+ }
+
+ // We have to query the tree with the fat AABB so that
+ // we don't fail to create a pair that may touch later.
+ const b2AABB& fatAABB = m_tree.GetFatAABB(m_queryProxyId);
+
+ // Query tree, create pairs and add them pair buffer.
+ m_tree.Query(this, fatAABB);
+ }
+
+ // Reset move buffer
+ m_moveCount = 0;
+
+ // Sort the pair buffer to expose duplicates.
+ std::sort(m_pairBuffer, m_pairBuffer + m_pairCount, b2PairLessThan);
+
+ // Send the pairs back to the client.
+ int32 i = 0;
+ while (i < m_pairCount)
+ {
+ b2Pair* primaryPair = m_pairBuffer + i;
+ void* userDataA = m_tree.GetUserData(primaryPair->proxyIdA);
+ void* userDataB = m_tree.GetUserData(primaryPair->proxyIdB);
+
+ callback->AddPair(userDataA, userDataB);
+ ++i;
+
+ // Skip any duplicate pairs.
+ while (i < m_pairCount)
+ {
+ b2Pair* pair = m_pairBuffer + i;
+ if (pair->proxyIdA != primaryPair->proxyIdA || pair->proxyIdB != primaryPair->proxyIdB)
+ {
+ break;
+ }
+ ++i;
+ }
+ }
+
+ // Try to keep the tree balanced.
+ //m_tree.Rebalance(4);
+}
+
+template <typename T>
+inline void b2BroadPhase::Query(T* callback, const b2AABB& aabb) const
+{
+ m_tree.Query(callback, aabb);
+}
+
+template <typename T>
+inline void b2BroadPhase::RayCast(T* callback, const b2RayCastInput& input) const
+{
+ m_tree.RayCast(callback, input);
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/b2CollideCircle.cpp b/engines/ngi/box2d/Collision/b2CollideCircle.cpp
new file mode 100644
index 00000000000..0e38f180992
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2CollideCircle.cpp
@@ -0,0 +1,158 @@
+/*
+* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2CircleShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h"
+
+namespace NGI {
+
+void b2CollideCircles(
+ b2Manifold* manifold,
+ const b2CircleShape* circleA, const b2Transform& xfA,
+ const b2CircleShape* circleB, const b2Transform& xfB)
+{
+ manifold->pointCount = 0;
+
+ b2Vec2 pA = b2Mul(xfA, circleA->m_p);
+ b2Vec2 pB = b2Mul(xfB, circleB->m_p);
+
+ b2Vec2 d = pB - pA;
+ float32 distSqr = b2Dot(d, d);
+ float32 rA = circleA->m_radius, rB = circleB->m_radius;
+ float32 radius = rA + rB;
+ if (distSqr > radius * radius)
+ {
+ return;
+ }
+
+ manifold->type = b2Manifold::e_circles;
+ manifold->localPoint = circleA->m_p;
+ manifold->localNormal.SetZero();
+ manifold->pointCount = 1;
+
+ manifold->points[0].localPoint = circleB->m_p;
+ manifold->points[0].id.key = 0;
+}
+
+void b2CollidePolygonAndCircle(
+ b2Manifold* manifold,
+ const b2PolygonShape* polygonA, const b2Transform& xfA,
+ const b2CircleShape* circleB, const b2Transform& xfB)
+{
+ manifold->pointCount = 0;
+
+ // Compute circle position in the frame of the polygon.
+ b2Vec2 c = b2Mul(xfB, circleB->m_p);
+ b2Vec2 cLocal = b2MulT(xfA, c);
+
+ // Find the min separating edge.
+ int32 normalIndex = 0;
+ float32 separation = -b2_maxFloat;
+ float32 radius = polygonA->m_radius + circleB->m_radius;
+ int32 vertexCount = polygonA->m_vertexCount;
+ const b2Vec2* vertices = polygonA->m_vertices;
+ const b2Vec2* normals = polygonA->m_normals;
+
+ for (int32 i = 0; i < vertexCount; ++i)
+ {
+ float32 s = b2Dot(normals[i], cLocal - vertices[i]);
+
+ if (s > radius)
+ {
+ // Early out.
+ return;
+ }
+
+ if (s > separation)
+ {
+ separation = s;
+ normalIndex = i;
+ }
+ }
+
+ // Vertices that subtend the incident face.
+ int32 vertIndex1 = normalIndex;
+ int32 vertIndex2 = vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0;
+ b2Vec2 v1 = vertices[vertIndex1];
+ b2Vec2 v2 = vertices[vertIndex2];
+
+ // If the center is inside the polygon ...
+ if (separation < b2_epsilon)
+ {
+ manifold->pointCount = 1;
+ manifold->type = b2Manifold::e_faceA;
+ manifold->localNormal = normals[normalIndex];
+ manifold->localPoint = 0.5f * (v1 + v2);
+ manifold->points[0].localPoint = circleB->m_p;
+ manifold->points[0].id.key = 0;
+ return;
+ }
+
+ // Compute barycentric coordinates
+ float32 u1 = b2Dot(cLocal - v1, v2 - v1);
+ float32 u2 = b2Dot(cLocal - v2, v1 - v2);
+ if (u1 <= 0.0f)
+ {
+ if (b2DistanceSquared(cLocal, v1) > radius * radius)
+ {
+ return;
+ }
+
+ manifold->pointCount = 1;
+ manifold->type = b2Manifold::e_faceA;
+ manifold->localNormal = cLocal - v1;
+ manifold->localNormal.Normalize();
+ manifold->localPoint = v1;
+ manifold->points[0].localPoint = circleB->m_p;
+ manifold->points[0].id.key = 0;
+ }
+ else if (u2 <= 0.0f)
+ {
+ if (b2DistanceSquared(cLocal, v2) > radius * radius)
+ {
+ return;
+ }
+
+ manifold->pointCount = 1;
+ manifold->type = b2Manifold::e_faceA;
+ manifold->localNormal = cLocal - v2;
+ manifold->localNormal.Normalize();
+ manifold->localPoint = v2;
+ manifold->points[0].localPoint = circleB->m_p;
+ manifold->points[0].id.key = 0;
+ }
+ else
+ {
+ b2Vec2 faceCenter = 0.5f * (v1 + v2);
+ float32 separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]);
+ if (separation > radius)
+ {
+ return;
+ }
+
+ manifold->pointCount = 1;
+ manifold->type = b2Manifold::e_faceA;
+ manifold->localNormal = normals[vertIndex1];
+ manifold->localPoint = faceCenter;
+ manifold->points[0].localPoint = circleB->m_p;
+ manifold->points[0].id.key = 0;
+ }
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/b2CollideEdge.cpp b/engines/ngi/box2d/Collision/b2CollideEdge.cpp
new file mode 100644
index 00000000000..23e45bdedd0
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2CollideEdge.cpp
@@ -0,0 +1,702 @@
+/*
+ * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2CircleShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h"
+
+namespace NGI {
+
+
+// Compute contact points for edge versus circle.
+// This accounts for edge connectivity.
+void b2CollideEdgeAndCircle(b2Manifold* manifold,
+ const b2EdgeShape* edgeA, const b2Transform& xfA,
+ const b2CircleShape* circleB, const b2Transform& xfB)
+{
+ manifold->pointCount = 0;
+
+ // Compute circle in frame of edge
+ b2Vec2 Q = b2MulT(xfA, b2Mul(xfB, circleB->m_p));
+
+ b2Vec2 A = edgeA->m_vertex1, B = edgeA->m_vertex2;
+ b2Vec2 e = B - A;
+
+ // Barycentric coordinates
+ float32 u = b2Dot(e, B - Q);
+ float32 v = b2Dot(e, Q - A);
+
+ float32 radius = edgeA->m_radius + circleB->m_radius;
+
+ b2ContactFeature cf;
+ cf.indexB = 0;
+ cf.typeB = b2ContactFeature::e_vertex;
+
+ // Region A
+ if (v <= 0.0f)
+ {
+ b2Vec2 P = A;
+ b2Vec2 d = Q - P;
+ float32 dd = b2Dot(d, d);
+ if (dd > radius * radius)
+ {
+ return;
+ }
+
+ // Is there an edge connected to A?
+ if (edgeA->m_hasVertex0)
+ {
+ b2Vec2 A1 = edgeA->m_vertex0;
+ b2Vec2 B1 = A;
+ b2Vec2 e1 = B1 - A1;
+ float32 u1 = b2Dot(e1, B1 - Q);
+
+ // Is the circle in Region AB of the previous edge?
+ if (u1 > 0.0f)
+ {
+ return;
+ }
+ }
+
+ cf.indexA = 0;
+ cf.typeA = b2ContactFeature::e_vertex;
+ manifold->pointCount = 1;
+ manifold->type = b2Manifold::e_circles;
+ manifold->localNormal.SetZero();
+ manifold->localPoint = P;
+ manifold->points[0].id.key = 0;
+ manifold->points[0].id.cf = cf;
+ manifold->points[0].localPoint = circleB->m_p;
+ return;
+ }
+
+ // Region B
+ if (u <= 0.0f)
+ {
+ b2Vec2 P = B;
+ b2Vec2 d = Q - P;
+ float32 dd = b2Dot(d, d);
+ if (dd > radius * radius)
+ {
+ return;
+ }
+
+ // Is there an edge connected to B?
+ if (edgeA->m_hasVertex3)
+ {
+ b2Vec2 B2 = edgeA->m_vertex3;
+ b2Vec2 A2 = B;
+ b2Vec2 e2 = B2 - A2;
+ float32 v2 = b2Dot(e2, Q - A2);
+
+ // Is the circle in Region AB of the next edge?
+ if (v2 > 0.0f)
+ {
+ return;
+ }
+ }
+
+ cf.indexA = 1;
+ cf.typeA = b2ContactFeature::e_vertex;
+ manifold->pointCount = 1;
+ manifold->type = b2Manifold::e_circles;
+ manifold->localNormal.SetZero();
+ manifold->localPoint = P;
+ manifold->points[0].id.key = 0;
+ manifold->points[0].id.cf = cf;
+ manifold->points[0].localPoint = circleB->m_p;
+ return;
+ }
+
+ // Region AB
+ float32 den = b2Dot(e, e);
+ b2Assert(den > 0.0f);
+ b2Vec2 P = (1.0f / den) * (u * A + v * B);
+ b2Vec2 d = Q - P;
+ float32 dd = b2Dot(d, d);
+ if (dd > radius * radius)
+ {
+ return;
+ }
+
+ b2Vec2 n(-e.y, e.x);
+ if (b2Dot(n, Q - A) < 0.0f)
+ {
+ n.Set(-n.x, -n.y);
+ }
+ n.Normalize();
+
+ cf.indexA = 0;
+ cf.typeA = b2ContactFeature::e_face;
+ manifold->pointCount = 1;
+ manifold->type = b2Manifold::e_faceA;
+ manifold->localNormal = n;
+ manifold->localPoint = A;
+ manifold->points[0].id.key = 0;
+ manifold->points[0].id.cf = cf;
+ manifold->points[0].localPoint = circleB->m_p;
+}
+
+// This structure is used to keep track of the best separating axis.
+struct b2EPAxis
+{
+ enum Type
+ {
+ e_unknown,
+ e_edgeA,
+ e_edgeB
+ };
+
+ Type type;
+ int32 index;
+ float32 separation;
+};
+
+// This holds polygon B expressed in frame A.
+struct b2TempPolygon
+{
+ b2Vec2 vertices[b2_maxPolygonVertices];
+ b2Vec2 normals[b2_maxPolygonVertices];
+ int32 count;
+};
+
+// Reference face used for clipping
+struct b2ReferenceFace
+{
+ int32 i1, i2;
+
+ b2Vec2 v1, v2;
+
+ b2Vec2 normal;
+
+ b2Vec2 sideNormal1;
+ float32 sideOffset1;
+
+ b2Vec2 sideNormal2;
+ float32 sideOffset2;
+};
+
+// This class collides and edge and a polygon, taking into account edge adjacency.
+struct b2EPCollider
+{
+ void Collide(b2Manifold* manifold, const b2EdgeShape* edgeA, const b2Transform& xfA,
+ const b2PolygonShape* polygonB, const b2Transform& xfB);
+ b2EPAxis ComputeEdgeSeparation();
+ b2EPAxis ComputePolygonSeparation();
+
+ enum VertexType
+ {
+ e_isolated,
+ e_concave,
+ e_convex
+ };
+
+ b2TempPolygon m_polygonB;
+
+ b2Transform m_xf;
+ b2Vec2 m_centroidB;
+ b2Vec2 m_v0, m_v1, m_v2, m_v3;
+ b2Vec2 m_normal0, m_normal1, m_normal2;
+ b2Vec2 m_normal;
+ VertexType m_type1, m_type2;
+ b2Vec2 m_lowerLimit, m_upperLimit;
+ float32 m_radius;
+ bool m_front;
+};
+
+// Algorithm:
+// 1. Classify v1 and v2
+// 2. Classify polygon centroid as front or back
+// 3. Flip normal if necessary
+// 4. Initialize normal range to [-pi, pi] about face normal
+// 5. Adjust normal range according to adjacent edges
+// 6. Visit each separating axes, only accept axes within the range
+// 7. Return if _any_ axis indicates separation
+// 8. Clip
+void b2EPCollider::Collide(b2Manifold* manifold, const b2EdgeShape* edgeA, const b2Transform& xfA,
+ const b2PolygonShape* polygonB, const b2Transform& xfB)
+{
+ m_xf = b2MulT(xfA, xfB);
+
+ m_centroidB = b2Mul(m_xf, polygonB->m_centroid);
+
+ m_v0 = edgeA->m_vertex0;
+ m_v1 = edgeA->m_vertex1;
+ m_v2 = edgeA->m_vertex2;
+ m_v3 = edgeA->m_vertex3;
+
+ bool hasVertex0 = edgeA->m_hasVertex0;
+ bool hasVertex3 = edgeA->m_hasVertex3;
+
+ b2Vec2 edge1 = m_v2 - m_v1;
+ edge1.Normalize();
+ m_normal1.Set(edge1.y, -edge1.x);
+ float32 offset1 = b2Dot(m_normal1, m_centroidB - m_v1);
+ float32 offset0 = 0.0f, offset2 = 0.0f;
+ bool convex1 = false, convex2 = false;
+
+ // Is there a preceding edge?
+ if (hasVertex0)
+ {
+ b2Vec2 edge0 = m_v1 - m_v0;
+ edge0.Normalize();
+ m_normal0.Set(edge0.y, -edge0.x);
+ convex1 = b2Cross(edge0, edge1) >= 0.0f;
+ offset0 = b2Dot(m_normal0, m_centroidB - m_v0);
+ }
+
+ // Is there a following edge?
+ if (hasVertex3)
+ {
+ b2Vec2 edge2 = m_v3 - m_v2;
+ edge2.Normalize();
+ m_normal2.Set(edge2.y, -edge2.x);
+ convex2 = b2Cross(edge1, edge2) > 0.0f;
+ offset2 = b2Dot(m_normal2, m_centroidB - m_v2);
+ }
+
+ // Determine front or back collision. Determine collision normal limits.
+ if (hasVertex0 && hasVertex3)
+ {
+ if (convex1 && convex2)
+ {
+ m_front = offset0 >= 0.0f || offset1 >= 0.0f || offset2 >= 0.0f;
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = m_normal0;
+ m_upperLimit = m_normal2;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = -m_normal1;
+ m_upperLimit = -m_normal1;
+ }
+ }
+ else if (convex1)
+ {
+ m_front = offset0 >= 0.0f || (offset1 >= 0.0f && offset2 >= 0.0f);
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = m_normal0;
+ m_upperLimit = m_normal1;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = -m_normal2;
+ m_upperLimit = -m_normal1;
+ }
+ }
+ else if (convex2)
+ {
+ m_front = offset2 >= 0.0f || (offset0 >= 0.0f && offset1 >= 0.0f);
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = m_normal1;
+ m_upperLimit = m_normal2;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = -m_normal1;
+ m_upperLimit = -m_normal0;
+ }
+ }
+ else
+ {
+ m_front = offset0 >= 0.0f && offset1 >= 0.0f && offset2 >= 0.0f;
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = m_normal1;
+ m_upperLimit = m_normal1;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = -m_normal2;
+ m_upperLimit = -m_normal0;
+ }
+ }
+ }
+ else if (hasVertex0)
+ {
+ if (convex1)
+ {
+ m_front = offset0 >= 0.0f || offset1 >= 0.0f;
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = m_normal0;
+ m_upperLimit = -m_normal1;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = m_normal1;
+ m_upperLimit = -m_normal1;
+ }
+ }
+ else
+ {
+ m_front = offset0 >= 0.0f && offset1 >= 0.0f;
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = m_normal1;
+ m_upperLimit = -m_normal1;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = m_normal1;
+ m_upperLimit = -m_normal0;
+ }
+ }
+ }
+ else if (hasVertex3)
+ {
+ if (convex2)
+ {
+ m_front = offset1 >= 0.0f || offset2 >= 0.0f;
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = -m_normal1;
+ m_upperLimit = m_normal2;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = -m_normal1;
+ m_upperLimit = m_normal1;
+ }
+ }
+ else
+ {
+ m_front = offset1 >= 0.0f && offset2 >= 0.0f;
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = -m_normal1;
+ m_upperLimit = m_normal1;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = -m_normal2;
+ m_upperLimit = m_normal1;
+ }
+ }
+ }
+ else
+ {
+ m_front = offset1 >= 0.0f;
+ if (m_front)
+ {
+ m_normal = m_normal1;
+ m_lowerLimit = -m_normal1;
+ m_upperLimit = -m_normal1;
+ }
+ else
+ {
+ m_normal = -m_normal1;
+ m_lowerLimit = m_normal1;
+ m_upperLimit = m_normal1;
+ }
+ }
+
+ // Get polygonB in frameA
+ m_polygonB.count = polygonB->m_vertexCount;
+ for (int32 i = 0; i < polygonB->m_vertexCount; ++i)
+ {
+ m_polygonB.vertices[i] = b2Mul(m_xf, polygonB->m_vertices[i]);
+ m_polygonB.normals[i] = b2Mul(m_xf.q, polygonB->m_normals[i]);
+ }
+
+ m_radius = 2.0f * b2_polygonRadius;
+
+ manifold->pointCount = 0;
+
+ b2EPAxis edgeAxis = ComputeEdgeSeparation();
+
+ // If no valid normal can be found than this edge should not collide.
+ if (edgeAxis.type == b2EPAxis::e_unknown)
+ {
+ return;
+ }
+
+ if (edgeAxis.separation > m_radius)
+ {
+ return;
+ }
+
+ b2EPAxis polygonAxis = ComputePolygonSeparation();
+ if (polygonAxis.type != b2EPAxis::e_unknown && polygonAxis.separation > m_radius)
+ {
+ return;
+ }
+
+ // Use hysteresis for jitter reduction.
+ const float32 k_relativeTol = 0.98f;
+ const float32 k_absoluteTol = 0.001f;
+
+ b2EPAxis primaryAxis;
+ if (polygonAxis.type == b2EPAxis::e_unknown)
+ {
+ primaryAxis = edgeAxis;
+ }
+ else if (polygonAxis.separation > k_relativeTol * edgeAxis.separation + k_absoluteTol)
+ {
+ primaryAxis = polygonAxis;
+ }
+ else
+ {
+ primaryAxis = edgeAxis;
+ }
+
+ b2ClipVertex ie[2];
+ b2ReferenceFace rf;
+ if (primaryAxis.type == b2EPAxis::e_edgeA)
+ {
+ manifold->type = b2Manifold::e_faceA;
+
+ // Search for the polygon normal that is most anti-parallel to the edge normal.
+ int32 bestIndex = 0;
+ float32 bestValue = b2Dot(m_normal, m_polygonB.normals[0]);
+ for (int32 i = 1; i < m_polygonB.count; ++i)
+ {
+ float32 value = b2Dot(m_normal, m_polygonB.normals[i]);
+ if (value < bestValue)
+ {
+ bestValue = value;
+ bestIndex = i;
+ }
+ }
+
+ int32 i1 = bestIndex;
+ int32 i2 = i1 + 1 < m_polygonB.count ? i1 + 1 : 0;
+
+ ie[0].v = m_polygonB.vertices[i1];
+ ie[0].id.cf.indexA = 0;
+ ie[0].id.cf.indexB = i1;
+ ie[0].id.cf.typeA = b2ContactFeature::e_face;
+ ie[0].id.cf.typeB = b2ContactFeature::e_vertex;
+
+ ie[1].v = m_polygonB.vertices[i2];
+ ie[1].id.cf.indexA = 0;
+ ie[1].id.cf.indexB = i2;
+ ie[1].id.cf.typeA = b2ContactFeature::e_face;
+ ie[1].id.cf.typeB = b2ContactFeature::e_vertex;
+
+ if (m_front)
+ {
+ rf.i1 = 0;
+ rf.i2 = 1;
+ rf.v1 = m_v1;
+ rf.v2 = m_v2;
+ rf.normal = m_normal1;
+ }
+ else
+ {
+ rf.i1 = 1;
+ rf.i2 = 0;
+ rf.v1 = m_v2;
+ rf.v2 = m_v1;
+ rf.normal = -m_normal1;
+ }
+ }
+ else
+ {
+ manifold->type = b2Manifold::e_faceB;
+
+ ie[0].v = m_v1;
+ ie[0].id.cf.indexA = 0;
+ ie[0].id.cf.indexB = primaryAxis.index;
+ ie[0].id.cf.typeA = b2ContactFeature::e_vertex;
+ ie[0].id.cf.typeB = b2ContactFeature::e_face;
+
+ ie[1].v = m_v2;
+ ie[1].id.cf.indexA = 0;
+ ie[1].id.cf.indexB = primaryAxis.index;
+ ie[1].id.cf.typeA = b2ContactFeature::e_vertex;
+ ie[1].id.cf.typeB = b2ContactFeature::e_face;
+
+ rf.i1 = primaryAxis.index;
+ rf.i2 = rf.i1 + 1 < m_polygonB.count ? rf.i1 + 1 : 0;
+ rf.v1 = m_polygonB.vertices[rf.i1];
+ rf.v2 = m_polygonB.vertices[rf.i2];
+ rf.normal = m_polygonB.normals[rf.i1];
+ }
+
+ rf.sideNormal1.Set(rf.normal.y, -rf.normal.x);
+ rf.sideNormal2 = -rf.sideNormal1;
+ rf.sideOffset1 = b2Dot(rf.sideNormal1, rf.v1);
+ rf.sideOffset2 = b2Dot(rf.sideNormal2, rf.v2);
+
+ // Clip incident edge against extruded edge1 side edges.
+ b2ClipVertex clipPoints1[2];
+ b2ClipVertex clipPoints2[2];
+ int32 np;
+
+ // Clip to box side 1
+ np = b2ClipSegmentToLine(clipPoints1, ie, rf.sideNormal1, rf.sideOffset1, rf.i1);
+
+ if (np < b2_maxManifoldPoints)
+ {
+ return;
+ }
+
+ // Clip to negative box side 1
+ np = b2ClipSegmentToLine(clipPoints2, clipPoints1, rf.sideNormal2, rf.sideOffset2, rf.i2);
+
+ if (np < b2_maxManifoldPoints)
+ {
+ return;
+ }
+
+ // Now clipPoints2 contains the clipped points.
+ if (primaryAxis.type == b2EPAxis::e_edgeA)
+ {
+ manifold->localNormal = rf.normal;
+ manifold->localPoint = rf.v1;
+ }
+ else
+ {
+ manifold->localNormal = polygonB->m_normals[rf.i1];
+ manifold->localPoint = polygonB->m_vertices[rf.i1];
+ }
+
+ int32 pointCount = 0;
+ for (int32 i = 0; i < b2_maxManifoldPoints; ++i)
+ {
+ float32 separation;
+
+ separation = b2Dot(rf.normal, clipPoints2[i].v - rf.v1);
+
+ if (separation <= m_radius)
+ {
+ b2ManifoldPoint* cp = manifold->points + pointCount;
+
+ if (primaryAxis.type == b2EPAxis::e_edgeA)
+ {
+ cp->localPoint = b2MulT(m_xf, clipPoints2[i].v);
+ cp->id = clipPoints2[i].id;
+ }
+ else
+ {
+ cp->localPoint = clipPoints2[i].v;
+ cp->id.cf.typeA = clipPoints2[i].id.cf.typeB;
+ cp->id.cf.typeB = clipPoints2[i].id.cf.typeA;
+ cp->id.cf.indexA = clipPoints2[i].id.cf.indexB;
+ cp->id.cf.indexB = clipPoints2[i].id.cf.indexA;
+ }
+
+ ++pointCount;
+ }
+ }
+
+ manifold->pointCount = pointCount;
+}
+
+b2EPAxis b2EPCollider::ComputeEdgeSeparation()
+{
+ b2EPAxis axis;
+ axis.type = b2EPAxis::e_edgeA;
+ axis.index = m_front ? 0 : 1;
+ axis.separation = FLT_MAX;
+
+ for (int32 i = 0; i < m_polygonB.count; ++i)
+ {
+ float32 s = b2Dot(m_normal, m_polygonB.vertices[i] - m_v1);
+ if (s < axis.separation)
+ {
+ axis.separation = s;
+ }
+ }
+
+ return axis;
+}
+
+b2EPAxis b2EPCollider::ComputePolygonSeparation()
+{
+ b2EPAxis axis;
+ axis.type = b2EPAxis::e_unknown;
+ axis.index = -1;
+ axis.separation = -FLT_MAX;
+
+ b2Vec2 perp(-m_normal.y, m_normal.x);
+
+ for (int32 i = 0; i < m_polygonB.count; ++i)
+ {
+ b2Vec2 n = -m_polygonB.normals[i];
+
+ float32 s1 = b2Dot(n, m_polygonB.vertices[i] - m_v1);
+ float32 s2 = b2Dot(n, m_polygonB.vertices[i] - m_v2);
+ float32 s = b2Min(s1, s2);
+
+ if (s > m_radius)
+ {
+ // No collision
+ axis.type = b2EPAxis::e_edgeB;
+ axis.index = i;
+ axis.separation = s;
+ return axis;
+ }
+
+ // Adjacency
+ if (b2Dot(n, perp) >= 0.0f)
+ {
+ if (b2Dot(n - m_upperLimit, m_normal) < -b2_angularSlop)
+ {
+ continue;
+ }
+ }
+ else
+ {
+ if (b2Dot(n - m_lowerLimit, m_normal) < -b2_angularSlop)
+ {
+ continue;
+ }
+ }
+
+ if (s > axis.separation)
+ {
+ axis.type = b2EPAxis::e_edgeB;
+ axis.index = i;
+ axis.separation = s;
+ }
+ }
+
+ return axis;
+}
+
+void b2CollideEdgeAndPolygon( b2Manifold* manifold,
+ const b2EdgeShape* edgeA, const b2Transform& xfA,
+ const b2PolygonShape* polygonB, const b2Transform& xfB)
+{
+ b2EPCollider collider;
+ collider.Collide(manifold, edgeA, xfA, polygonB, xfB);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/b2CollidePolygon.cpp b/engines/ngi/box2d/Collision/b2CollidePolygon.cpp
new file mode 100644
index 00000000000..33b1c645a23
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2CollidePolygon.cpp
@@ -0,0 +1,321 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h"
+
+namespace NGI {
+
+// Find the separation between poly1 and poly2 for a give edge normal on poly1.
+static float32 b2EdgeSeparation(const b2PolygonShape* poly1, const b2Transform& xf1, int32 edge1,
+ const b2PolygonShape* poly2, const b2Transform& xf2)
+{
+ const b2Vec2* vertices1 = poly1->m_vertices;
+ const b2Vec2* normals1 = poly1->m_normals;
+
+ int32 count2 = poly2->m_vertexCount;
+ const b2Vec2* vertices2 = poly2->m_vertices;
+
+ b2Assert(0 <= edge1 && edge1 < poly1->m_vertexCount);
+
+ // Convert normal from poly1's frame into poly2's frame.
+ b2Vec2 normal1World = b2Mul(xf1.q, normals1[edge1]);
+ b2Vec2 normal1 = b2MulT(xf2.q, normal1World);
+
+ // Find support vertex on poly2 for -normal.
+ int32 index = 0;
+ float32 minDot = b2_maxFloat;
+
+ for (int32 i = 0; i < count2; ++i)
+ {
+ float32 dot = b2Dot(vertices2[i], normal1);
+ if (dot < minDot)
+ {
+ minDot = dot;
+ index = i;
+ }
+ }
+
+ b2Vec2 v1 = b2Mul(xf1, vertices1[edge1]);
+ b2Vec2 v2 = b2Mul(xf2, vertices2[index]);
+ float32 separation = b2Dot(v2 - v1, normal1World);
+ return separation;
+}
+
+// Find the max separation between poly1 and poly2 using edge normals from poly1.
+static float32 b2FindMaxSeparation(int32* edgeIndex,
+ const b2PolygonShape* poly1, const b2Transform& xf1,
+ const b2PolygonShape* poly2, const b2Transform& xf2)
+{
+ int32 count1 = poly1->m_vertexCount;
+ const b2Vec2* normals1 = poly1->m_normals;
+
+ // Vector pointing from the centroid of poly1 to the centroid of poly2.
+ b2Vec2 d = b2Mul(xf2, poly2->m_centroid) - b2Mul(xf1, poly1->m_centroid);
+ b2Vec2 dLocal1 = b2MulT(xf1.q, d);
+
+ // Find edge normal on poly1 that has the largest projection onto d.
+ int32 edge = 0;
+ float32 maxDot = -b2_maxFloat;
+ for (int32 i = 0; i < count1; ++i)
+ {
+ float32 dot = b2Dot(normals1[i], dLocal1);
+ if (dot > maxDot)
+ {
+ maxDot = dot;
+ edge = i;
+ }
+ }
+
+ // Get the separation for the edge normal.
+ float32 s = b2EdgeSeparation(poly1, xf1, edge, poly2, xf2);
+
+ // Check the separation for the previous edge normal.
+ int32 prevEdge = edge - 1 >= 0 ? edge - 1 : count1 - 1;
+ float32 sPrev = b2EdgeSeparation(poly1, xf1, prevEdge, poly2, xf2);
+
+ // Check the separation for the next edge normal.
+ int32 nextEdge = edge + 1 < count1 ? edge + 1 : 0;
+ float32 sNext = b2EdgeSeparation(poly1, xf1, nextEdge, poly2, xf2);
+
+ // Find the best edge and the search direction.
+ int32 bestEdge;
+ float32 bestSeparation;
+ int32 increment;
+ if (sPrev > s && sPrev > sNext)
+ {
+ increment = -1;
+ bestEdge = prevEdge;
+ bestSeparation = sPrev;
+ }
+ else if (sNext > s)
+ {
+ increment = 1;
+ bestEdge = nextEdge;
+ bestSeparation = sNext;
+ }
+ else
+ {
+ *edgeIndex = edge;
+ return s;
+ }
+
+ // Perform a local search for the best edge normal.
+ for ( ; ; )
+ {
+ if (increment == -1)
+ edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
+ else
+ edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;
+
+ s = b2EdgeSeparation(poly1, xf1, edge, poly2, xf2);
+
+ if (s > bestSeparation)
+ {
+ bestEdge = edge;
+ bestSeparation = s;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ *edgeIndex = bestEdge;
+ return bestSeparation;
+}
+
+static void b2FindIncidentEdge(b2ClipVertex c[2],
+ const b2PolygonShape* poly1, const b2Transform& xf1, int32 edge1,
+ const b2PolygonShape* poly2, const b2Transform& xf2)
+{
+ const b2Vec2* normals1 = poly1->m_normals;
+
+ int32 count2 = poly2->m_vertexCount;
+ const b2Vec2* vertices2 = poly2->m_vertices;
+ const b2Vec2* normals2 = poly2->m_normals;
+
+ b2Assert(0 <= edge1 && edge1 < poly1->m_vertexCount);
+
+ // Get the normal of the reference edge in poly2's frame.
+ b2Vec2 normal1 = b2MulT(xf2.q, b2Mul(xf1.q, normals1[edge1]));
+
+ // Find the incident edge on poly2.
+ int32 index = 0;
+ float32 minDot = b2_maxFloat;
+ for (int32 i = 0; i < count2; ++i)
+ {
+ float32 dot = b2Dot(normal1, normals2[i]);
+ if (dot < minDot)
+ {
+ minDot = dot;
+ index = i;
+ }
+ }
+
+ // Build the clip vertices for the incident edge.
+ int32 i1 = index;
+ int32 i2 = i1 + 1 < count2 ? i1 + 1 : 0;
+
+ c[0].v = b2Mul(xf2, vertices2[i1]);
+ c[0].id.cf.indexA = (uint8)edge1;
+ c[0].id.cf.indexB = (uint8)i1;
+ c[0].id.cf.typeA = b2ContactFeature::e_face;
+ c[0].id.cf.typeB = b2ContactFeature::e_vertex;
+
+ c[1].v = b2Mul(xf2, vertices2[i2]);
+ c[1].id.cf.indexA = (uint8)edge1;
+ c[1].id.cf.indexB = (uint8)i2;
+ c[1].id.cf.typeA = b2ContactFeature::e_face;
+ c[1].id.cf.typeB = b2ContactFeature::e_vertex;
+}
+
+// Find edge normal of max separation on A - return if separating axis is found
+// Find edge normal of max separation on B - return if separation axis is found
+// Choose reference edge as min(minA, minB)
+// Find incident edge
+// Clip
+
+// The normal points from 1 to 2
+void b2CollidePolygons(b2Manifold* manifold,
+ const b2PolygonShape* polyA, const b2Transform& xfA,
+ const b2PolygonShape* polyB, const b2Transform& xfB)
+{
+ manifold->pointCount = 0;
+ float32 totalRadius = polyA->m_radius + polyB->m_radius;
+
+ int32 edgeA = 0;
+ float32 separationA = b2FindMaxSeparation(&edgeA, polyA, xfA, polyB, xfB);
+ if (separationA > totalRadius)
+ return;
+
+ int32 edgeB = 0;
+ float32 separationB = b2FindMaxSeparation(&edgeB, polyB, xfB, polyA, xfA);
+ if (separationB > totalRadius)
+ return;
+
+ const b2PolygonShape* poly1; // reference polygon
+ const b2PolygonShape* poly2; // incident polygon
+ b2Transform xf1, xf2;
+ int32 edge1; // reference edge
+ uint8 flip;
+ const float32 k_relativeTol = 0.98f;
+ const float32 k_absoluteTol = 0.001f;
+
+ if (separationB > k_relativeTol * separationA + k_absoluteTol)
+ {
+ poly1 = polyB;
+ poly2 = polyA;
+ xf1 = xfB;
+ xf2 = xfA;
+ edge1 = edgeB;
+ manifold->type = b2Manifold::e_faceB;
+ flip = 1;
+ }
+ else
+ {
+ poly1 = polyA;
+ poly2 = polyB;
+ xf1 = xfA;
+ xf2 = xfB;
+ edge1 = edgeA;
+ manifold->type = b2Manifold::e_faceA;
+ flip = 0;
+ }
+
+ b2ClipVertex incidentEdge[2];
+ b2FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2);
+
+ int32 count1 = poly1->m_vertexCount;
+ const b2Vec2* vertices1 = poly1->m_vertices;
+
+ int32 iv1 = edge1;
+ int32 iv2 = edge1 + 1 < count1 ? edge1 + 1 : 0;
+
+ b2Vec2 v11 = vertices1[iv1];
+ b2Vec2 v12 = vertices1[iv2];
+
+ b2Vec2 localTangent = v12 - v11;
+ localTangent.Normalize();
+
+ b2Vec2 localNormal = b2Cross(localTangent, 1.0f);
+ b2Vec2 planePoint = 0.5f * (v11 + v12);
+
+ b2Vec2 tangent = b2Mul(xf1.q, localTangent);
+ b2Vec2 normal = b2Cross(tangent, 1.0f);
+
+ v11 = b2Mul(xf1, v11);
+ v12 = b2Mul(xf1, v12);
+
+ // Face offset.
+ float32 frontOffset = b2Dot(normal, v11);
+
+ // Side offsets, extended by polytope skin thickness.
+ float32 sideOffset1 = -b2Dot(tangent, v11) + totalRadius;
+ float32 sideOffset2 = b2Dot(tangent, v12) + totalRadius;
+
+ // Clip incident edge against extruded edge1 side edges.
+ b2ClipVertex clipPoints1[2];
+ b2ClipVertex clipPoints2[2];
+ int np;
+
+ // Clip to box side 1
+ np = b2ClipSegmentToLine(clipPoints1, incidentEdge, -tangent, sideOffset1, iv1);
+
+ if (np < 2)
+ return;
+
+ // Clip to negative box side 1
+ np = b2ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2, iv2);
+
+ if (np < 2)
+ {
+ return;
+ }
+
+ // Now clipPoints2 contains the clipped points.
+ manifold->localNormal = localNormal;
+ manifold->localPoint = planePoint;
+
+ int32 pointCount = 0;
+ for (int32 i = 0; i < b2_maxManifoldPoints; ++i)
+ {
+ float32 separation = b2Dot(normal, clipPoints2[i].v) - frontOffset;
+
+ if (separation <= totalRadius)
+ {
+ b2ManifoldPoint* cp = manifold->points + pointCount;
+ cp->localPoint = b2MulT(xf2, clipPoints2[i].v);
+ cp->id = clipPoints2[i].id;
+ if (flip)
+ {
+ // Swap features
+ b2ContactFeature cf = cp->id.cf;
+ cp->id.cf.indexA = cf.indexB;
+ cp->id.cf.indexB = cf.indexA;
+ cp->id.cf.typeA = cf.typeB;
+ cp->id.cf.typeB = cf.typeA;
+ }
+ ++pointCount;
+ }
+ }
+
+ manifold->pointCount = pointCount;
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/b2Collision.cpp b/engines/ngi/box2d/Collision/b2Collision.cpp
new file mode 100644
index 00000000000..0a28e62301b
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2Collision.cpp
@@ -0,0 +1,253 @@
+/*
+* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Collision/b2Distance.h"
+
+namespace NGI {
+
+void b2WorldManifold::Initialize(const b2Manifold* manifold,
+ const b2Transform& xfA, float32 radiusA,
+ const b2Transform& xfB, float32 radiusB)
+{
+ if (manifold->pointCount == 0)
+ {
+ return;
+ }
+
+ switch (manifold->type)
+ {
+ case b2Manifold::e_circles:
+ {
+ normal.Set(1.0f, 0.0f);
+ b2Vec2 pointA = b2Mul(xfA, manifold->localPoint);
+ b2Vec2 pointB = b2Mul(xfB, manifold->points[0].localPoint);
+ if (b2DistanceSquared(pointA, pointB) > b2_epsilon * b2_epsilon)
+ {
+ normal = pointB - pointA;
+ normal.Normalize();
+ }
+
+ b2Vec2 cA = pointA + radiusA * normal;
+ b2Vec2 cB = pointB - radiusB * normal;
+ points[0] = 0.5f * (cA + cB);
+ }
+ break;
+
+ case b2Manifold::e_faceA:
+ {
+ normal = b2Mul(xfA.q, manifold->localNormal);
+ b2Vec2 planePoint = b2Mul(xfA, manifold->localPoint);
+
+ for (int32 i = 0; i < manifold->pointCount; ++i)
+ {
+ b2Vec2 clipPoint = b2Mul(xfB, manifold->points[i].localPoint);
+ b2Vec2 cA = clipPoint + (radiusA - b2Dot(clipPoint - planePoint, normal)) * normal;
+ b2Vec2 cB = clipPoint - radiusB * normal;
+ points[i] = 0.5f * (cA + cB);
+ }
+ }
+ break;
+
+ case b2Manifold::e_faceB:
+ {
+ normal = b2Mul(xfB.q, manifold->localNormal);
+ b2Vec2 planePoint = b2Mul(xfB, manifold->localPoint);
+
+ for (int32 i = 0; i < manifold->pointCount; ++i)
+ {
+ b2Vec2 clipPoint = b2Mul(xfA, manifold->points[i].localPoint);
+ b2Vec2 cB = clipPoint + (radiusB - b2Dot(clipPoint - planePoint, normal)) * normal;
+ b2Vec2 cA = clipPoint - radiusA * normal;
+ points[i] = 0.5f * (cA + cB);
+ }
+
+ // Ensure normal points from A to B.
+ normal = -normal;
+ }
+ break;
+ }
+}
+
+void b2GetPointStates(b2PointState state1[b2_maxManifoldPoints], b2PointState state2[b2_maxManifoldPoints],
+ const b2Manifold* manifold1, const b2Manifold* manifold2)
+{
+ for (int32 i = 0; i < b2_maxManifoldPoints; ++i)
+ {
+ state1[i] = b2_nullState;
+ state2[i] = b2_nullState;
+ }
+
+ // Detect persists and removes.
+ for (int32 i = 0; i < manifold1->pointCount; ++i)
+ {
+ b2ContactID id = manifold1->points[i].id;
+
+ state1[i] = b2_removeState;
+
+ for (int32 j = 0; j < manifold2->pointCount; ++j)
+ {
+ if (manifold2->points[j].id.key == id.key)
+ {
+ state1[i] = b2_persistState;
+ break;
+ }
+ }
+ }
+
+ // Detect persists and adds.
+ for (int32 i = 0; i < manifold2->pointCount; ++i)
+ {
+ b2ContactID id = manifold2->points[i].id;
+
+ state2[i] = b2_addState;
+
+ for (int32 j = 0; j < manifold1->pointCount; ++j)
+ {
+ if (manifold1->points[j].id.key == id.key)
+ {
+ state2[i] = b2_persistState;
+ break;
+ }
+ }
+ }
+}
+
+// From Real-time Collision Detection, p179.
+bool b2AABB::RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const
+{
+ float32 tmin = -b2_maxFloat;
+ float32 tmax = b2_maxFloat;
+
+ b2Vec2 p = input.p1;
+ b2Vec2 d = input.p2 - input.p1;
+ b2Vec2 absD = b2Abs(d);
+
+ b2Vec2 normal;
+
+ for (int32 i = 0; i < 2; ++i)
+ {
+ if (absD(i) < b2_epsilon)
+ {
+ // Parallel.
+ if (p(i) < lowerBound(i) || upperBound(i) < p(i))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ float32 inv_d = 1.0f / d(i);
+ float32 t1 = (lowerBound(i) - p(i)) * inv_d;
+ float32 t2 = (upperBound(i) - p(i)) * inv_d;
+
+ // Sign of the normal vector.
+ float32 s = -1.0f;
+
+ if (t1 > t2)
+ {
+ b2Swap(t1, t2);
+ s = 1.0f;
+ }
+
+ // Push the min up
+ if (t1 > tmin)
+ {
+ normal.SetZero();
+ normal(i) = s;
+ tmin = t1;
+ }
+
+ // Pull the max down
+ tmax = b2Min(tmax, t2);
+
+ if (tmin > tmax)
+ {
+ return false;
+ }
+ }
+ }
+
+ // Does the ray start inside the box?
+ // Does the ray intersect beyond the max fraction?
+ if (tmin < 0.0f || input.maxFraction < tmin)
+ {
+ return false;
+ }
+
+ // Intersection.
+ output->fraction = tmin;
+ output->normal = normal;
+ return true;
+}
+
+// Sutherland-Hodgman clipping.
+int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2],
+ const b2Vec2& normal, float32 offset, int32 vertexIndexA)
+{
+ // Start with no output points
+ int32 numOut = 0;
+
+ // Calculate the distance of end points to the line
+ float32 distance0 = b2Dot(normal, vIn[0].v) - offset;
+ float32 distance1 = b2Dot(normal, vIn[1].v) - offset;
+
+ // If the points are behind the plane
+ if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
+ if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
+
+ // If the points are on different sides of the plane
+ if (distance0 * distance1 < 0.0f)
+ {
+ // Find intersection point of edge and plane
+ float32 interp = distance0 / (distance0 - distance1);
+ vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v);
+
+ // VertexA is hitting edgeB.
+ vOut[numOut].id.cf.indexA = vertexIndexA;
+ vOut[numOut].id.cf.indexB = vIn[0].id.cf.indexB;
+ vOut[numOut].id.cf.typeA = b2ContactFeature::e_vertex;
+ vOut[numOut].id.cf.typeB = b2ContactFeature::e_face;
+ ++numOut;
+ }
+
+ return numOut;
+}
+
+bool b2TestOverlap( const b2Shape* shapeA, int32 indexA,
+ const b2Shape* shapeB, int32 indexB,
+ const b2Transform& xfA, const b2Transform& xfB)
+{
+ b2DistanceInput input;
+ input.proxyA.Set(shapeA, indexA);
+ input.proxyB.Set(shapeB, indexB);
+ input.transformA = xfA;
+ input.transformB = xfB;
+ input.useRadii = true;
+
+ b2SimplexCache cache;
+ cache.count = 0;
+
+ b2DistanceOutput output;
+
+ b2Distance(&output, &cache, &input);
+
+ return output.distance < 10.0f * b2_epsilon;
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/b2Collision.h b/engines/ngi/box2d/Collision/b2Collision.h
new file mode 100644
index 00000000000..07215d20f37
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2Collision.h
@@ -0,0 +1,280 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_COLLISION_H
+#define B2_COLLISION_H
+
+#include "engines/ngi/box2d/Common/b2Math.h"
+#include <climits>
+
+namespace NGI {
+
+/// @file
+/// Structures and functions used for computing contact points, distance
+/// queries, and TOI queries.
+
+class b2Shape;
+class b2CircleShape;
+class b2EdgeShape;
+class b2PolygonShape;
+
+const uint8 b2_nullFeature = UCHAR_MAX;
+
+/// The features that intersect to form the contact point
+/// This must be 4 bytes or less.
+struct b2ContactFeature
+{
+ enum Type
+ {
+ e_vertex = 0,
+ e_face = 1
+ };
+
+ uint8 indexA; ///< Feature index on shapeA
+ uint8 indexB; ///< Feature index on shapeB
+ uint8 typeA; ///< The feature type on shapeA
+ uint8 typeB; ///< The feature type on shapeB
+};
+
+/// Contact ids to facilitate warm starting.
+union b2ContactID
+{
+ b2ContactFeature cf;
+ uint32 key; ///< Used to quickly compare contact ids.
+};
+
+/// A manifold point is a contact point belonging to a contact
+/// manifold. It holds details related to the geometry and dynamics
+/// of the contact points.
+/// The local point usage depends on the manifold type:
+/// -e_circles: the local center of circleB
+/// -e_faceA: the local center of cirlceB or the clip point of polygonB
+/// -e_faceB: the clip point of polygonA
+/// This structure is stored across time steps, so we keep it small.
+/// Note: the impulses are used for internal caching and may not
+/// provide reliable contact forces, especially for high speed collisions.
+struct b2ManifoldPoint
+{
+ b2Vec2 localPoint; ///< usage depends on manifold type
+ float32 normalImpulse; ///< the non-penetration impulse
+ float32 tangentImpulse; ///< the friction impulse
+ b2ContactID id; ///< uniquely identifies a contact point between two shapes
+};
+
+/// A manifold for two touching convex shapes.
+/// Box2D supports multiple types of contact:
+/// - clip point versus plane with radius
+/// - point versus point with radius (circles)
+/// The local point usage depends on the manifold type:
+/// -e_circles: the local center of circleA
+/// -e_faceA: the center of faceA
+/// -e_faceB: the center of faceB
+/// Similarly the local normal usage:
+/// -e_circles: not used
+/// -e_faceA: the normal on polygonA
+/// -e_faceB: the normal on polygonB
+/// We store contacts in this way so that position correction can
+/// account for movement, which is critical for continuous physics.
+/// All contact scenarios must be expressed in one of these types.
+/// This structure is stored across time steps, so we keep it small.
+struct b2Manifold
+{
+ enum Type
+ {
+ e_circles,
+ e_faceA,
+ e_faceB
+ };
+
+ b2ManifoldPoint points[b2_maxManifoldPoints]; ///< the points of contact
+ b2Vec2 localNormal; ///< not use for Type::e_points
+ b2Vec2 localPoint; ///< usage depends on manifold type
+ Type type;
+ int32 pointCount; ///< the number of manifold points
+};
+
+/// This is used to compute the current state of a contact manifold.
+struct b2WorldManifold
+{
+ /// Evaluate the manifold with supplied transforms. This assumes
+ /// modest motion from the original state. This does not change the
+ /// point count, impulses, etc. The radii must come from the shapes
+ /// that generated the manifold.
+ void Initialize(const b2Manifold* manifold,
+ const b2Transform& xfA, float32 radiusA,
+ const b2Transform& xfB, float32 radiusB);
+
+ b2Vec2 normal; ///< world vector pointing from A to B
+ b2Vec2 points[b2_maxManifoldPoints]; ///< world contact point (point of intersection)
+};
+
+/// This is used for determining the state of contact points.
+enum b2PointState
+{
+ b2_nullState, ///< point does not exist
+ b2_addState, ///< point was added in the update
+ b2_persistState, ///< point persisted across the update
+ b2_removeState ///< point was removed in the update
+};
+
+/// Compute the point states given two manifolds. The states pertain to the transition from manifold1
+/// to manifold2. So state1 is either persist or remove while state2 is either add or persist.
+void b2GetPointStates(b2PointState state1[b2_maxManifoldPoints], b2PointState state2[b2_maxManifoldPoints],
+ const b2Manifold* manifold1, const b2Manifold* manifold2);
+
+/// Used for computing contact manifolds.
+struct b2ClipVertex
+{
+ b2Vec2 v;
+ b2ContactID id;
+};
+
+/// Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
+struct b2RayCastInput
+{
+ b2Vec2 p1, p2;
+ float32 maxFraction;
+};
+
+/// Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2
+/// come from b2RayCastInput.
+struct b2RayCastOutput
+{
+ b2Vec2 normal;
+ float32 fraction;
+};
+
+/// An axis aligned bounding box.
+struct b2AABB
+{
+ /// Verify that the bounds are sorted.
+ bool IsValid() const;
+
+ /// Get the center of the AABB.
+ b2Vec2 GetCenter() const
+ {
+ return 0.5f * (lowerBound + upperBound);
+ }
+
+ /// Get the extents of the AABB (half-widths).
+ b2Vec2 GetExtents() const
+ {
+ return 0.5f * (upperBound - lowerBound);
+ }
+
+ /// Get the perimeter length
+ float32 GetPerimeter() const
+ {
+ float32 wx = upperBound.x - lowerBound.x;
+ float32 wy = upperBound.y - lowerBound.y;
+ return 2.0f * (wx + wy);
+ }
+
+ /// Combine an AABB into this one.
+ void Combine(const b2AABB& aabb)
+ {
+ lowerBound = b2Min(lowerBound, aabb.lowerBound);
+ upperBound = b2Max(upperBound, aabb.upperBound);
+ }
+
+ /// Combine two AABBs into this one.
+ void Combine(const b2AABB& aabb1, const b2AABB& aabb2)
+ {
+ lowerBound = b2Min(aabb1.lowerBound, aabb2.lowerBound);
+ upperBound = b2Max(aabb1.upperBound, aabb2.upperBound);
+ }
+
+ /// Does this aabb contain the provided AABB.
+ bool Contains(const b2AABB& aabb) const
+ {
+ bool result = true;
+ result = result && lowerBound.x <= aabb.lowerBound.x;
+ result = result && lowerBound.y <= aabb.lowerBound.y;
+ result = result && aabb.upperBound.x <= upperBound.x;
+ result = result && aabb.upperBound.y <= upperBound.y;
+ return result;
+ }
+
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const;
+
+ b2Vec2 lowerBound; ///< the lower vertex
+ b2Vec2 upperBound; ///< the upper vertex
+};
+
+/// Compute the collision manifold between two circles.
+void b2CollideCircles(b2Manifold* manifold,
+ const b2CircleShape* circleA, const b2Transform& xfA,
+ const b2CircleShape* circleB, const b2Transform& xfB);
+
+/// Compute the collision manifold between a polygon and a circle.
+void b2CollidePolygonAndCircle(b2Manifold* manifold,
+ const b2PolygonShape* polygonA, const b2Transform& xfA,
+ const b2CircleShape* circleB, const b2Transform& xfB);
+
+/// Compute the collision manifold between two polygons.
+void b2CollidePolygons(b2Manifold* manifold,
+ const b2PolygonShape* polygonA, const b2Transform& xfA,
+ const b2PolygonShape* polygonB, const b2Transform& xfB);
+
+/// Compute the collision manifold between an edge and a circle.
+void b2CollideEdgeAndCircle(b2Manifold* manifold,
+ const b2EdgeShape* polygonA, const b2Transform& xfA,
+ const b2CircleShape* circleB, const b2Transform& xfB);
+
+/// Compute the collision manifold between an edge and a circle.
+void b2CollideEdgeAndPolygon(b2Manifold* manifold,
+ const b2EdgeShape* edgeA, const b2Transform& xfA,
+ const b2PolygonShape* circleB, const b2Transform& xfB);
+
+/// Clipping for contact manifolds.
+int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2],
+ const b2Vec2& normal, float32 offset, int32 vertexIndexA);
+
+/// Determine if two generic shapes overlap.
+bool b2TestOverlap( const b2Shape* shapeA, int32 indexA,
+ const b2Shape* shapeB, int32 indexB,
+ const b2Transform& xfA, const b2Transform& xfB);
+
+// ---------------- Inline Functions ------------------------------------------
+
+inline bool b2AABB::IsValid() const
+{
+ b2Vec2 d = upperBound - lowerBound;
+ bool valid = d.x >= 0.0f && d.y >= 0.0f;
+ valid = valid && lowerBound.IsValid() && upperBound.IsValid();
+ return valid;
+}
+
+inline bool b2TestOverlap(const b2AABB& a, const b2AABB& b)
+{
+ b2Vec2 d1, d2;
+ d1 = b.lowerBound - a.upperBound;
+ d2 = a.lowerBound - b.upperBound;
+
+ if (d1.x > 0.0f || d1.y > 0.0f)
+ return false;
+
+ if (d2.x > 0.0f || d2.y > 0.0f)
+ return false;
+
+ return true;
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/b2Distance.cpp b/engines/ngi/box2d/Collision/b2Distance.cpp
new file mode 100644
index 00000000000..ffedad5af63
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2Distance.cpp
@@ -0,0 +1,607 @@
+/*
+* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/b2Distance.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2CircleShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2ChainShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h"
+
+namespace NGI {
+
+// GJK using Voronoi regions (Christer Ericson) and Barycentric coordinates.
+int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;
+
+void b2DistanceProxy::Set(const b2Shape* shape, int32 index)
+{
+ switch (shape->GetType())
+ {
+ case b2Shape::e_circle:
+ {
+ const b2CircleShape* circle = (b2CircleShape*)shape;
+ m_vertices = &circle->m_p;
+ m_count = 1;
+ m_radius = circle->m_radius;
+ }
+ break;
+
+ case b2Shape::e_polygon:
+ {
+ const b2PolygonShape* polygon = (b2PolygonShape*)shape;
+ m_vertices = polygon->m_vertices;
+ m_count = polygon->m_vertexCount;
+ m_radius = polygon->m_radius;
+ }
+ break;
+
+ case b2Shape::e_chain:
+ {
+ const b2ChainShape* chain = (b2ChainShape*)shape;
+ b2Assert(0 <= index && index < chain->m_count);
+
+ m_buffer[0] = chain->m_vertices[index];
+ if (index + 1 < chain->m_count)
+ {
+ m_buffer[1] = chain->m_vertices[index + 1];
+ }
+ else
+ {
+ m_buffer[1] = chain->m_vertices[0];
+ }
+
+ m_vertices = m_buffer;
+ m_count = 2;
+ m_radius = chain->m_radius;
+ }
+ break;
+
+ case b2Shape::e_edge:
+ {
+ const b2EdgeShape* edge = (b2EdgeShape*)shape;
+ m_vertices = &edge->m_vertex1;
+ m_count = 2;
+ m_radius = edge->m_radius;
+ }
+ break;
+
+ default:
+ b2Assert(false);
+ }
+}
+
+
+struct b2SimplexVertex
+{
+ b2Vec2 wA; // support point in proxyA
+ b2Vec2 wB; // support point in proxyB
+ b2Vec2 w; // wB - wA
+ float32 a; // barycentric coordinate for closest point
+ int32 indexA; // wA index
+ int32 indexB; // wB index
+};
+
+struct b2Simplex
+{
+ void ReadCache( const b2SimplexCache* cache,
+ const b2DistanceProxy* proxyA, const b2Transform& transformA,
+ const b2DistanceProxy* proxyB, const b2Transform& transformB)
+ {
+ b2Assert(cache->count <= 3);
+
+ // Copy data from cache.
+ m_count = cache->count;
+ b2SimplexVertex* vertices = &m_v1;
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ b2SimplexVertex* v = vertices + i;
+ v->indexA = cache->indexA[i];
+ v->indexB = cache->indexB[i];
+ b2Vec2 wALocal = proxyA->GetVertex(v->indexA);
+ b2Vec2 wBLocal = proxyB->GetVertex(v->indexB);
+ v->wA = b2Mul(transformA, wALocal);
+ v->wB = b2Mul(transformB, wBLocal);
+ v->w = v->wB - v->wA;
+ v->a = 0.0f;
+ }
+
+ // Compute the new simplex metric, if it is substantially different than
+ // old metric then flush the simplex.
+ if (m_count > 1)
+ {
+ float32 metric1 = cache->metric;
+ float32 metric2 = GetMetric();
+ if (metric2 < 0.5f * metric1 || 2.0f * metric1 < metric2 || metric2 < b2_epsilon)
+ {
+ // Reset the simplex.
+ m_count = 0;
+ }
+ }
+
+ // If the cache is empty or invalid ...
+ if (m_count == 0)
+ {
+ b2SimplexVertex* v = vertices + 0;
+ v->indexA = 0;
+ v->indexB = 0;
+ b2Vec2 wALocal = proxyA->GetVertex(0);
+ b2Vec2 wBLocal = proxyB->GetVertex(0);
+ v->wA = b2Mul(transformA, wALocal);
+ v->wB = b2Mul(transformB, wBLocal);
+ v->w = v->wB - v->wA;
+ m_count = 1;
+ }
+ }
+
+ void WriteCache(b2SimplexCache* cache) const
+ {
+ cache->metric = GetMetric();
+ cache->count = uint16(m_count);
+ const b2SimplexVertex* vertices = &m_v1;
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ cache->indexA[i] = uint8(vertices[i].indexA);
+ cache->indexB[i] = uint8(vertices[i].indexB);
+ }
+ }
+
+ b2Vec2 GetSearchDirection() const
+ {
+ switch (m_count)
+ {
+ case 1:
+ return -m_v1.w;
+
+ case 2:
+ {
+ b2Vec2 e12 = m_v2.w - m_v1.w;
+ float32 sgn = b2Cross(e12, -m_v1.w);
+ if (sgn > 0.0f)
+ {
+ // Origin is left of e12.
+ return b2Cross(1.0f, e12);
+ }
+ else
+ {
+ // Origin is right of e12.
+ return b2Cross(e12, 1.0f);
+ }
+ }
+
+ default:
+ b2Assert(false);
+ return b2Vec2_zero;
+ }
+ }
+
+ b2Vec2 GetClosestPoint() const
+ {
+ switch (m_count)
+ {
+ case 0:
+ b2Assert(false);
+ return b2Vec2_zero;
+
+ case 1:
+ return m_v1.w;
+
+ case 2:
+ return m_v1.a * m_v1.w + m_v2.a * m_v2.w;
+
+ case 3:
+ return b2Vec2_zero;
+
+ default:
+ b2Assert(false);
+ return b2Vec2_zero;
+ }
+ }
+
+ void GetWitnessPoints(b2Vec2* pA, b2Vec2* pB) const
+ {
+ switch (m_count)
+ {
+ case 0:
+ b2Assert(false);
+ break;
+
+ case 1:
+ *pA = m_v1.wA;
+ *pB = m_v1.wB;
+ break;
+
+ case 2:
+ *pA = m_v1.a * m_v1.wA + m_v2.a * m_v2.wA;
+ *pB = m_v1.a * m_v1.wB + m_v2.a * m_v2.wB;
+ break;
+
+ case 3:
+ *pA = m_v1.a * m_v1.wA + m_v2.a * m_v2.wA + m_v3.a * m_v3.wA;
+ *pB = *pA;
+ break;
+
+ default:
+ b2Assert(false);
+ break;
+ }
+ }
+
+ float32 GetMetric() const
+ {
+ switch (m_count)
+ {
+ case 0:
+ b2Assert(false);
+ return 0.0;
+
+ case 1:
+ return 0.0f;
+
+ case 2:
+ return b2Distance(m_v1.w, m_v2.w);
+
+ case 3:
+ return b2Cross(m_v2.w - m_v1.w, m_v3.w - m_v1.w);
+
+ default:
+ b2Assert(false);
+ return 0.0f;
+ }
+ }
+
+ void Solve2();
+ void Solve3();
+
+ b2SimplexVertex m_v1, m_v2, m_v3;
+ int32 m_count;
+};
+
+
+// Solve a line segment using barycentric coordinates.
+//
+// p = a1 * w1 + a2 * w2
+// a1 + a2 = 1
+//
+// The vector from the origin to the closest point on the line is
+// perpendicular to the line.
+// e12 = w2 - w1
+// dot(p, e) = 0
+// a1 * dot(w1, e) + a2 * dot(w2, e) = 0
+//
+// 2-by-2 linear system
+// [1 1 ][a1] = [1]
+// [w1.e12 w2.e12][a2] = [0]
+//
+// Define
+// d12_1 = dot(w2, e12)
+// d12_2 = -dot(w1, e12)
+// d12 = d12_1 + d12_2
+//
+// Solution
+// a1 = d12_1 / d12
+// a2 = d12_2 / d12
+void b2Simplex::Solve2()
+{
+ b2Vec2 w1 = m_v1.w;
+ b2Vec2 w2 = m_v2.w;
+ b2Vec2 e12 = w2 - w1;
+
+ // w1 region
+ float32 d12_2 = -b2Dot(w1, e12);
+ if (d12_2 <= 0.0f)
+ {
+ // a2 <= 0, so we clamp it to 0
+ m_v1.a = 1.0f;
+ m_count = 1;
+ return;
+ }
+
+ // w2 region
+ float32 d12_1 = b2Dot(w2, e12);
+ if (d12_1 <= 0.0f)
+ {
+ // a1 <= 0, so we clamp it to 0
+ m_v2.a = 1.0f;
+ m_count = 1;
+ m_v1 = m_v2;
+ return;
+ }
+
+ // Must be in e12 region.
+ float32 inv_d12 = 1.0f / (d12_1 + d12_2);
+ m_v1.a = d12_1 * inv_d12;
+ m_v2.a = d12_2 * inv_d12;
+ m_count = 2;
+}
+
+// Possible regions:
+// - points[2]
+// - edge points[0]-points[2]
+// - edge points[1]-points[2]
+// - inside the triangle
+void b2Simplex::Solve3()
+{
+ b2Vec2 w1 = m_v1.w;
+ b2Vec2 w2 = m_v2.w;
+ b2Vec2 w3 = m_v3.w;
+
+ // Edge12
+ // [1 1 ][a1] = [1]
+ // [w1.e12 w2.e12][a2] = [0]
+ // a3 = 0
+ b2Vec2 e12 = w2 - w1;
+ float32 w1e12 = b2Dot(w1, e12);
+ float32 w2e12 = b2Dot(w2, e12);
+ float32 d12_1 = w2e12;
+ float32 d12_2 = -w1e12;
+
+ // Edge13
+ // [1 1 ][a1] = [1]
+ // [w1.e13 w3.e13][a3] = [0]
+ // a2 = 0
+ b2Vec2 e13 = w3 - w1;
+ float32 w1e13 = b2Dot(w1, e13);
+ float32 w3e13 = b2Dot(w3, e13);
+ float32 d13_1 = w3e13;
+ float32 d13_2 = -w1e13;
+
+ // Edge23
+ // [1 1 ][a2] = [1]
+ // [w2.e23 w3.e23][a3] = [0]
+ // a1 = 0
+ b2Vec2 e23 = w3 - w2;
+ float32 w2e23 = b2Dot(w2, e23);
+ float32 w3e23 = b2Dot(w3, e23);
+ float32 d23_1 = w3e23;
+ float32 d23_2 = -w2e23;
+
+ // Triangle123
+ float32 n123 = b2Cross(e12, e13);
+
+ float32 d123_1 = n123 * b2Cross(w2, w3);
+ float32 d123_2 = n123 * b2Cross(w3, w1);
+ float32 d123_3 = n123 * b2Cross(w1, w2);
+
+ // w1 region
+ if (d12_2 <= 0.0f && d13_2 <= 0.0f)
+ {
+ m_v1.a = 1.0f;
+ m_count = 1;
+ return;
+ }
+
+ // e12
+ if (d12_1 > 0.0f && d12_2 > 0.0f && d123_3 <= 0.0f)
+ {
+ float32 inv_d12 = 1.0f / (d12_1 + d12_2);
+ m_v1.a = d12_1 * inv_d12;
+ m_v2.a = d12_2 * inv_d12;
+ m_count = 2;
+ return;
+ }
+
+ // e13
+ if (d13_1 > 0.0f && d13_2 > 0.0f && d123_2 <= 0.0f)
+ {
+ float32 inv_d13 = 1.0f / (d13_1 + d13_2);
+ m_v1.a = d13_1 * inv_d13;
+ m_v3.a = d13_2 * inv_d13;
+ m_count = 2;
+ m_v2 = m_v3;
+ return;
+ }
+
+ // w2 region
+ if (d12_1 <= 0.0f && d23_2 <= 0.0f)
+ {
+ m_v2.a = 1.0f;
+ m_count = 1;
+ m_v1 = m_v2;
+ return;
+ }
+
+ // w3 region
+ if (d13_1 <= 0.0f && d23_1 <= 0.0f)
+ {
+ m_v3.a = 1.0f;
+ m_count = 1;
+ m_v1 = m_v3;
+ return;
+ }
+
+ // e23
+ if (d23_1 > 0.0f && d23_2 > 0.0f && d123_1 <= 0.0f)
+ {
+ float32 inv_d23 = 1.0f / (d23_1 + d23_2);
+ m_v2.a = d23_1 * inv_d23;
+ m_v3.a = d23_2 * inv_d23;
+ m_count = 2;
+ m_v1 = m_v3;
+ return;
+ }
+
+ // Must be in triangle123
+ float32 inv_d123 = 1.0f / (d123_1 + d123_2 + d123_3);
+ m_v1.a = d123_1 * inv_d123;
+ m_v2.a = d123_2 * inv_d123;
+ m_v3.a = d123_3 * inv_d123;
+ m_count = 3;
+}
+
+void b2Distance(b2DistanceOutput* output,
+ b2SimplexCache* cache,
+ const b2DistanceInput* input)
+{
+ ++b2_gjkCalls;
+
+ const b2DistanceProxy* proxyA = &input->proxyA;
+ const b2DistanceProxy* proxyB = &input->proxyB;
+
+ b2Transform transformA = input->transformA;
+ b2Transform transformB = input->transformB;
+
+ // Initialize the simplex.
+ b2Simplex simplex;
+ simplex.ReadCache(cache, proxyA, transformA, proxyB, transformB);
+
+ // Get simplex vertices as an array.
+ b2SimplexVertex* vertices = &simplex.m_v1;
+ const int32 k_maxIters = 20;
+
+ // These store the vertices of the last simplex so that we
+ // can check for duplicates and prevent cycling.
+ int32 saveA[3], saveB[3];
+ int32 saveCount = 0;
+
+ b2Vec2 closestPoint = simplex.GetClosestPoint();
+ float32 distanceSqr1 = closestPoint.LengthSquared();
+ float32 distanceSqr2 = distanceSqr1;
+
+ // Main iteration loop.
+ int32 iter = 0;
+ while (iter < k_maxIters)
+ {
+ // Copy simplex so we can identify duplicates.
+ saveCount = simplex.m_count;
+ for (int32 i = 0; i < saveCount; ++i)
+ {
+ saveA[i] = vertices[i].indexA;
+ saveB[i] = vertices[i].indexB;
+ }
+
+ switch (simplex.m_count)
+ {
+ case 1:
+ break;
+
+ case 2:
+ simplex.Solve2();
+ break;
+
+ case 3:
+ simplex.Solve3();
+ break;
+
+ default:
+ b2Assert(false);
+ }
+
+ // If we have 3 points, then the origin is in the corresponding triangle.
+ if (simplex.m_count == 3)
+ {
+ break;
+ }
+
+ // Compute closest point.
+ b2Vec2 p = simplex.GetClosestPoint();
+ distanceSqr2 = p.LengthSquared();
+
+ // Ensure progress
+ if (distanceSqr2 >= distanceSqr1)
+ {
+ //break;
+ }
+ distanceSqr1 = distanceSqr2;
+
+ // Get search direction.
+ b2Vec2 d = simplex.GetSearchDirection();
+
+ // Ensure the search direction is numerically fit.
+ if (d.LengthSquared() < b2_epsilon * b2_epsilon)
+ {
+ // The origin is probably contained by a line segment
+ // or triangle. Thus the shapes are overlapped.
+
+ // We can't return zero here even though there may be overlap.
+ // In case the simplex is a point, segment, or triangle it is difficult
+ // to determine if the origin is contained in the CSO or very close to it.
+ break;
+ }
+
+ // Compute a tentative new simplex vertex using support points.
+ b2SimplexVertex* vertex = vertices + simplex.m_count;
+ vertex->indexA = proxyA->GetSupport(b2MulT(transformA.q, -d));
+ vertex->wA = b2Mul(transformA, proxyA->GetVertex(vertex->indexA));
+ b2Vec2 wBLocal;
+ vertex->indexB = proxyB->GetSupport(b2MulT(transformB.q, d));
+ vertex->wB = b2Mul(transformB, proxyB->GetVertex(vertex->indexB));
+ vertex->w = vertex->wB - vertex->wA;
+
+ // Iteration count is equated to the number of support point calls.
+ ++iter;
+ ++b2_gjkIters;
+
+ // Check for duplicate support points. This is the main termination criteria.
+ bool duplicate = false;
+ for (int32 i = 0; i < saveCount; ++i)
+ {
+ if (vertex->indexA == saveA[i] && vertex->indexB == saveB[i])
+ {
+ duplicate = true;
+ break;
+ }
+ }
+
+ // If we found a duplicate support point we must exit to avoid cycling.
+ if (duplicate)
+ {
+ break;
+ }
+
+ // New vertex is ok and needed.
+ ++simplex.m_count;
+ }
+
+ b2_gjkMaxIters = b2Max(b2_gjkMaxIters, iter);
+
+ // Prepare output.
+ simplex.GetWitnessPoints(&output->pointA, &output->pointB);
+ output->distance = b2Distance(output->pointA, output->pointB);
+ output->iterations = iter;
+
+ // Cache the simplex.
+ simplex.WriteCache(cache);
+
+ // Apply radii if requested.
+ if (input->useRadii)
+ {
+ float32 rA = proxyA->m_radius;
+ float32 rB = proxyB->m_radius;
+
+ if (output->distance > rA + rB && output->distance > b2_epsilon)
+ {
+ // Shapes are still no overlapped.
+ // Move the witness points to the outer surface.
+ output->distance -= rA + rB;
+ b2Vec2 normal = output->pointB - output->pointA;
+ normal.Normalize();
+ output->pointA += rA * normal;
+ output->pointB -= rB * normal;
+ }
+ else
+ {
+ // Shapes are overlapped when radii are considered.
+ // Move the witness points to the middle.
+ b2Vec2 p = 0.5f * (output->pointA + output->pointB);
+ output->pointA = p;
+ output->pointB = p;
+ output->distance = 0.0f;
+ }
+ }
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/b2Distance.h b/engines/ngi/box2d/Collision/b2Distance.h
new file mode 100644
index 00000000000..407c4ee9385
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2Distance.h
@@ -0,0 +1,145 @@
+
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_DISTANCE_H
+#define B2_DISTANCE_H
+
+#include "engines/ngi/box2d/Common/b2Math.h"
+
+namespace NGI {
+
+class b2Shape;
+
+/// A distance proxy is used by the GJK algorithm.
+/// It encapsulates any shape.
+struct b2DistanceProxy
+{
+ b2DistanceProxy() : m_vertices(NULL), m_count(0), m_radius(0.0f) {}
+
+ /// Initialize the proxy using the given shape. The shape
+ /// must remain in scope while the proxy is in use.
+ void Set(const b2Shape* shape, int32 index);
+
+ /// Get the supporting vertex index in the given direction.
+ int32 GetSupport(const b2Vec2& d) const;
+
+ /// Get the supporting vertex in the given direction.
+ const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
+
+ /// Get the vertex count.
+ int32 GetVertexCount() const;
+
+ /// Get a vertex by index. Used by b2Distance.
+ const b2Vec2& GetVertex(int32 index) const;
+
+ b2Vec2 m_buffer[2];
+ const b2Vec2* m_vertices;
+ int32 m_count;
+ float32 m_radius;
+};
+
+/// Used to warm start b2Distance.
+/// Set count to zero on first call.
+struct b2SimplexCache
+{
+ float32 metric; ///< length or area
+ uint16 count;
+ uint8 indexA[3]; ///< vertices on shape A
+ uint8 indexB[3]; ///< vertices on shape B
+};
+
+/// Input for b2Distance.
+/// You have to option to use the shape radii
+/// in the computation. Even
+struct b2DistanceInput
+{
+ b2DistanceProxy proxyA;
+ b2DistanceProxy proxyB;
+ b2Transform transformA;
+ b2Transform transformB;
+ bool useRadii;
+};
+
+/// Output for b2Distance.
+struct b2DistanceOutput
+{
+ b2Vec2 pointA; ///< closest point on shapeA
+ b2Vec2 pointB; ///< closest point on shapeB
+ float32 distance;
+ int32 iterations; ///< number of GJK iterations used
+};
+
+/// Compute the closest points between two shapes. Supports any combination of:
+/// b2CircleShape, b2PolygonShape, b2EdgeShape. The simplex cache is input/output.
+/// On the first call set b2SimplexCache.count to zero.
+void b2Distance(b2DistanceOutput* output,
+ b2SimplexCache* cache,
+ const b2DistanceInput* input);
+
+
+//////////////////////////////////////////////////////////////////////////
+
+inline int32 b2DistanceProxy::GetVertexCount() const
+{
+ return m_count;
+}
+
+inline const b2Vec2& b2DistanceProxy::GetVertex(int32 index) const
+{
+ b2Assert(0 <= index && index < m_count);
+ return m_vertices[index];
+}
+
+inline int32 b2DistanceProxy::GetSupport(const b2Vec2& d) const
+{
+ int32 bestIndex = 0;
+ float32 bestValue = b2Dot(m_vertices[0], d);
+ for (int32 i = 1; i < m_count; ++i)
+ {
+ float32 value = b2Dot(m_vertices[i], d);
+ if (value > bestValue)
+ {
+ bestIndex = i;
+ bestValue = value;
+ }
+ }
+
+ return bestIndex;
+}
+
+inline const b2Vec2& b2DistanceProxy::GetSupportVertex(const b2Vec2& d) const
+{
+ int32 bestIndex = 0;
+ float32 bestValue = b2Dot(m_vertices[0], d);
+ for (int32 i = 1; i < m_count; ++i)
+ {
+ float32 value = b2Dot(m_vertices[i], d);
+ if (value > bestValue)
+ {
+ bestIndex = i;
+ bestValue = value;
+ }
+ }
+
+ return m_vertices[bestIndex];
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/b2DynamicTree.cpp b/engines/ngi/box2d/Collision/b2DynamicTree.cpp
new file mode 100644
index 00000000000..1339d6886f1
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2DynamicTree.cpp
@@ -0,0 +1,775 @@
+/*
+* Copyright (c) 2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/b2DynamicTree.h"
+#include <cstring>
+#include <cfloat>
+
+namespace NGI {
+using namespace std;
+
+
+b2DynamicTree::b2DynamicTree()
+{
+ m_root = b2_nullNode;
+
+ m_nodeCapacity = 16;
+ m_nodeCount = 0;
+ m_nodes = (b2TreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2TreeNode));
+ memset(m_nodes, 0, m_nodeCapacity * sizeof(b2TreeNode));
+
+ // Build a linked list for the free list.
+ for (int32 i = 0; i < m_nodeCapacity - 1; ++i)
+ {
+ m_nodes[i].next = i + 1;
+ m_nodes[i].height = -1;
+ }
+ m_nodes[m_nodeCapacity-1].next = b2_nullNode;
+ m_nodes[m_nodeCapacity-1].height = -1;
+ m_freeList = 0;
+
+ m_path = 0;
+
+ m_insertionCount = 0;
+}
+
+b2DynamicTree::~b2DynamicTree()
+{
+ // This frees the entire tree in one shot.
+ b2Free(m_nodes);
+}
+
+// Allocate a node from the pool. Grow the pool if necessary.
+int32 b2DynamicTree::AllocateNode()
+{
+ // Expand the node pool as needed.
+ if (m_freeList == b2_nullNode)
+ {
+ b2Assert(m_nodeCount == m_nodeCapacity);
+
+ // The free list is empty. Rebuild a bigger pool.
+ b2TreeNode* oldNodes = m_nodes;
+ m_nodeCapacity *= 2;
+ m_nodes = (b2TreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2TreeNode));
+ memcpy(m_nodes, oldNodes, m_nodeCount * sizeof(b2TreeNode));
+ b2Free(oldNodes);
+
+ // Build a linked list for the free list. The parent
+ // pointer becomes the "next" pointer.
+ for (int32 i = m_nodeCount; i < m_nodeCapacity - 1; ++i)
+ {
+ m_nodes[i].next = i + 1;
+ m_nodes[i].height = -1;
+ }
+ m_nodes[m_nodeCapacity-1].next = b2_nullNode;
+ m_nodes[m_nodeCapacity-1].height = -1;
+ m_freeList = m_nodeCount;
+ }
+
+ // Peel a node off the free list.
+ int32 nodeId = m_freeList;
+ m_freeList = m_nodes[nodeId].next;
+ m_nodes[nodeId].parent = b2_nullNode;
+ m_nodes[nodeId].child1 = b2_nullNode;
+ m_nodes[nodeId].child2 = b2_nullNode;
+ m_nodes[nodeId].height = 0;
+ m_nodes[nodeId].userData = NULL;
+ ++m_nodeCount;
+ return nodeId;
+}
+
+// Return a node to the pool.
+void b2DynamicTree::FreeNode(int32 nodeId)
+{
+ b2Assert(0 <= nodeId && nodeId < m_nodeCapacity);
+ b2Assert(0 < m_nodeCount);
+ m_nodes[nodeId].next = m_freeList;
+ m_nodes[nodeId].height = -1;
+ m_freeList = nodeId;
+ --m_nodeCount;
+}
+
+// Create a proxy in the tree as a leaf node. We return the index
+// of the node instead of a pointer so that we can grow
+// the node pool.
+int32 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData)
+{
+ int32 proxyId = AllocateNode();
+
+ // Fatten the aabb.
+ b2Vec2 r(b2_aabbExtension, b2_aabbExtension);
+ m_nodes[proxyId].aabb.lowerBound = aabb.lowerBound - r;
+ m_nodes[proxyId].aabb.upperBound = aabb.upperBound + r;
+ m_nodes[proxyId].userData = userData;
+ m_nodes[proxyId].height = 0;
+
+ InsertLeaf(proxyId);
+
+ return proxyId;
+}
+
+void b2DynamicTree::DestroyProxy(int32 proxyId)
+{
+ b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
+ b2Assert(m_nodes[proxyId].IsLeaf());
+
+ RemoveLeaf(proxyId);
+ FreeNode(proxyId);
+}
+
+bool b2DynamicTree::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement)
+{
+ b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
+
+ b2Assert(m_nodes[proxyId].IsLeaf());
+
+ if (m_nodes[proxyId].aabb.Contains(aabb))
+ {
+ return false;
+ }
+
+ RemoveLeaf(proxyId);
+
+ // Extend AABB.
+ b2AABB b = aabb;
+ b2Vec2 r(b2_aabbExtension, b2_aabbExtension);
+ b.lowerBound = b.lowerBound - r;
+ b.upperBound = b.upperBound + r;
+
+ // Predict AABB displacement.
+ b2Vec2 d = b2_aabbMultiplier * displacement;
+
+ if (d.x < 0.0f)
+ {
+ b.lowerBound.x += d.x;
+ }
+ else
+ {
+ b.upperBound.x += d.x;
+ }
+
+ if (d.y < 0.0f)
+ {
+ b.lowerBound.y += d.y;
+ }
+ else
+ {
+ b.upperBound.y += d.y;
+ }
+
+ m_nodes[proxyId].aabb = b;
+
+ InsertLeaf(proxyId);
+ return true;
+}
+
+void b2DynamicTree::InsertLeaf(int32 leaf)
+{
+ ++m_insertionCount;
+
+ if (m_root == b2_nullNode)
+ {
+ m_root = leaf;
+ m_nodes[m_root].parent = b2_nullNode;
+ return;
+ }
+
+ // Find the best sibling for this node
+ b2AABB leafAABB = m_nodes[leaf].aabb;
+ int32 index = m_root;
+ while (m_nodes[index].IsLeaf() == false)
+ {
+ int32 child1 = m_nodes[index].child1;
+ int32 child2 = m_nodes[index].child2;
+
+ float32 area = m_nodes[index].aabb.GetPerimeter();
+
+ b2AABB combinedAABB;
+ combinedAABB.Combine(m_nodes[index].aabb, leafAABB);
+ float32 combinedArea = combinedAABB.GetPerimeter();
+
+ // Cost of creating a new parent for this node and the new leaf
+ float32 cost = 2.0f * combinedArea;
+
+ // Minimum cost of pushing the leaf further down the tree
+ float32 inheritanceCost = 2.0f * (combinedArea - area);
+
+ // Cost of descending into child1
+ float32 cost1;
+ if (m_nodes[child1].IsLeaf())
+ {
+ b2AABB aabb;
+ aabb.Combine(leafAABB, m_nodes[child1].aabb);
+ cost1 = aabb.GetPerimeter() + inheritanceCost;
+ }
+ else
+ {
+ b2AABB aabb;
+ aabb.Combine(leafAABB, m_nodes[child1].aabb);
+ float32 oldArea = m_nodes[child1].aabb.GetPerimeter();
+ float32 newArea = aabb.GetPerimeter();
+ cost1 = (newArea - oldArea) + inheritanceCost;
+ }
+
+ // Cost of descending into child2
+ float32 cost2;
+ if (m_nodes[child2].IsLeaf())
+ {
+ b2AABB aabb;
+ aabb.Combine(leafAABB, m_nodes[child2].aabb);
+ cost2 = aabb.GetPerimeter() + inheritanceCost;
+ }
+ else
+ {
+ b2AABB aabb;
+ aabb.Combine(leafAABB, m_nodes[child2].aabb);
+ float32 oldArea = m_nodes[child2].aabb.GetPerimeter();
+ float32 newArea = aabb.GetPerimeter();
+ cost2 = newArea - oldArea + inheritanceCost;
+ }
+
+ // Descend according to the minimum cost.
+ if (cost < cost1 && cost < cost2)
+ {
+ break;
+ }
+
+ // Descend
+ if (cost1 < cost2)
+ {
+ index = child1;
+ }
+ else
+ {
+ index = child2;
+ }
+ }
+
+ int32 sibling = index;
+
+ // Create a new parent.
+ int32 oldParent = m_nodes[sibling].parent;
+ int32 newParent = AllocateNode();
+ m_nodes[newParent].parent = oldParent;
+ m_nodes[newParent].userData = NULL;
+ m_nodes[newParent].aabb.Combine(leafAABB, m_nodes[sibling].aabb);
+ m_nodes[newParent].height = m_nodes[sibling].height + 1;
+
+ if (oldParent != b2_nullNode)
+ {
+ // The sibling was not the root.
+ if (m_nodes[oldParent].child1 == sibling)
+ {
+ m_nodes[oldParent].child1 = newParent;
+ }
+ else
+ {
+ m_nodes[oldParent].child2 = newParent;
+ }
+
+ m_nodes[newParent].child1 = sibling;
+ m_nodes[newParent].child2 = leaf;
+ m_nodes[sibling].parent = newParent;
+ m_nodes[leaf].parent = newParent;
+ }
+ else
+ {
+ // The sibling was the root.
+ m_nodes[newParent].child1 = sibling;
+ m_nodes[newParent].child2 = leaf;
+ m_nodes[sibling].parent = newParent;
+ m_nodes[leaf].parent = newParent;
+ m_root = newParent;
+ }
+
+ // Walk back up the tree fixing heights and AABBs
+ index = m_nodes[leaf].parent;
+ while (index != b2_nullNode)
+ {
+ index = Balance(index);
+
+ int32 child1 = m_nodes[index].child1;
+ int32 child2 = m_nodes[index].child2;
+
+ b2Assert(child1 != b2_nullNode);
+ b2Assert(child2 != b2_nullNode);
+
+ m_nodes[index].height = 1 + b2Max(m_nodes[child1].height, m_nodes[child2].height);
+ m_nodes[index].aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb);
+
+ index = m_nodes[index].parent;
+ }
+
+ //Validate();
+}
+
+void b2DynamicTree::RemoveLeaf(int32 leaf)
+{
+ if (leaf == m_root)
+ {
+ m_root = b2_nullNode;
+ return;
+ }
+
+ int32 parent = m_nodes[leaf].parent;
+ int32 grandParent = m_nodes[parent].parent;
+ int32 sibling;
+ if (m_nodes[parent].child1 == leaf)
+ {
+ sibling = m_nodes[parent].child2;
+ }
+ else
+ {
+ sibling = m_nodes[parent].child1;
+ }
+
+ if (grandParent != b2_nullNode)
+ {
+ // Destroy parent and connect sibling to grandParent.
+ if (m_nodes[grandParent].child1 == parent)
+ {
+ m_nodes[grandParent].child1 = sibling;
+ }
+ else
+ {
+ m_nodes[grandParent].child2 = sibling;
+ }
+ m_nodes[sibling].parent = grandParent;
+ FreeNode(parent);
+
+ // Adjust ancestor bounds.
+ int32 index = grandParent;
+ while (index != b2_nullNode)
+ {
+ index = Balance(index);
+
+ int32 child1 = m_nodes[index].child1;
+ int32 child2 = m_nodes[index].child2;
+
+ m_nodes[index].aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb);
+ m_nodes[index].height = 1 + b2Max(m_nodes[child1].height, m_nodes[child2].height);
+
+ index = m_nodes[index].parent;
+ }
+ }
+ else
+ {
+ m_root = sibling;
+ m_nodes[sibling].parent = b2_nullNode;
+ FreeNode(parent);
+ }
+
+ //Validate();
+}
+
+// Perform a left or right rotation if node A is imbalanced.
+// Returns the new root index.
+int32 b2DynamicTree::Balance(int32 iA)
+{
+ b2Assert(iA != b2_nullNode);
+
+ b2TreeNode* A = m_nodes + iA;
+ if (A->IsLeaf() || A->height < 2)
+ {
+ return iA;
+ }
+
+ int32 iB = A->child1;
+ int32 iC = A->child2;
+ b2Assert(0 <= iB && iB < m_nodeCapacity);
+ b2Assert(0 <= iC && iC < m_nodeCapacity);
+
+ b2TreeNode* B = m_nodes + iB;
+ b2TreeNode* C = m_nodes + iC;
+
+ int32 balance = C->height - B->height;
+
+ // Rotate C up
+ if (balance > 1)
+ {
+ int32 iF = C->child1;
+ int32 iG = C->child2;
+ b2TreeNode* F = m_nodes + iF;
+ b2TreeNode* G = m_nodes + iG;
+ b2Assert(0 <= iF && iF < m_nodeCapacity);
+ b2Assert(0 <= iG && iG < m_nodeCapacity);
+
+ // Swap A and C
+ C->child1 = iA;
+ C->parent = A->parent;
+ A->parent = iC;
+
+ // A's old parent should point to C
+ if (C->parent != b2_nullNode)
+ {
+ if (m_nodes[C->parent].child1 == iA)
+ {
+ m_nodes[C->parent].child1 = iC;
+ }
+ else
+ {
+ b2Assert(m_nodes[C->parent].child2 == iA);
+ m_nodes[C->parent].child2 = iC;
+ }
+ }
+ else
+ {
+ m_root = iC;
+ }
+
+ // Rotate
+ if (F->height > G->height)
+ {
+ C->child2 = iF;
+ A->child2 = iG;
+ G->parent = iA;
+ A->aabb.Combine(B->aabb, G->aabb);
+ C->aabb.Combine(A->aabb, F->aabb);
+
+ A->height = 1 + b2Max(B->height, G->height);
+ C->height = 1 + b2Max(A->height, F->height);
+ }
+ else
+ {
+ C->child2 = iG;
+ A->child2 = iF;
+ F->parent = iA;
+ A->aabb.Combine(B->aabb, F->aabb);
+ C->aabb.Combine(A->aabb, G->aabb);
+
+ A->height = 1 + b2Max(B->height, F->height);
+ C->height = 1 + b2Max(A->height, G->height);
+ }
+
+ return iC;
+ }
+
+ // Rotate B up
+ if (balance < -1)
+ {
+ int32 iD = B->child1;
+ int32 iE = B->child2;
+ b2TreeNode* D = m_nodes + iD;
+ b2TreeNode* E = m_nodes + iE;
+ b2Assert(0 <= iD && iD < m_nodeCapacity);
+ b2Assert(0 <= iE && iE < m_nodeCapacity);
+
+ // Swap A and B
+ B->child1 = iA;
+ B->parent = A->parent;
+ A->parent = iB;
+
+ // A's old parent should point to B
+ if (B->parent != b2_nullNode)
+ {
+ if (m_nodes[B->parent].child1 == iA)
+ {
+ m_nodes[B->parent].child1 = iB;
+ }
+ else
+ {
+ b2Assert(m_nodes[B->parent].child2 == iA);
+ m_nodes[B->parent].child2 = iB;
+ }
+ }
+ else
+ {
+ m_root = iB;
+ }
+
+ // Rotate
+ if (D->height > E->height)
+ {
+ B->child2 = iD;
+ A->child1 = iE;
+ E->parent = iA;
+ A->aabb.Combine(C->aabb, E->aabb);
+ B->aabb.Combine(A->aabb, D->aabb);
+
+ A->height = 1 + b2Max(C->height, E->height);
+ B->height = 1 + b2Max(A->height, D->height);
+ }
+ else
+ {
+ B->child2 = iE;
+ A->child1 = iD;
+ D->parent = iA;
+ A->aabb.Combine(C->aabb, D->aabb);
+ B->aabb.Combine(A->aabb, E->aabb);
+
+ A->height = 1 + b2Max(C->height, D->height);
+ B->height = 1 + b2Max(A->height, E->height);
+ }
+
+ return iB;
+ }
+
+ return iA;
+}
+
+int32 b2DynamicTree::GetHeight() const
+{
+ if (m_root == b2_nullNode)
+ {
+ return 0;
+ }
+
+ return m_nodes[m_root].height;
+}
+
+//
+float32 b2DynamicTree::GetAreaRatio() const
+{
+ if (m_root == b2_nullNode)
+ {
+ return 0.0f;
+ }
+
+ const b2TreeNode* root = m_nodes + m_root;
+ float32 rootArea = root->aabb.GetPerimeter();
+
+ float32 totalArea = 0.0f;
+ for (int32 i = 0; i < m_nodeCapacity; ++i)
+ {
+ const b2TreeNode* node = m_nodes + i;
+ if (node->height < 0)
+ {
+ // Free node in pool
+ continue;
+ }
+
+ totalArea += node->aabb.GetPerimeter();
+ }
+
+ return totalArea / rootArea;
+}
+
+// Compute the height of a sub-tree.
+int32 b2DynamicTree::ComputeHeight(int32 nodeId) const
+{
+ b2Assert(0 <= nodeId && nodeId < m_nodeCapacity);
+ b2TreeNode* node = m_nodes + nodeId;
+
+ if (node->IsLeaf())
+ {
+ return 0;
+ }
+
+ int32 height1 = ComputeHeight(node->child1);
+ int32 height2 = ComputeHeight(node->child2);
+ return 1 + b2Max(height1, height2);
+}
+
+int32 b2DynamicTree::ComputeHeight() const
+{
+ int32 height = ComputeHeight(m_root);
+ return height;
+}
+
+void b2DynamicTree::ValidateStructure(int32 index) const
+{
+ if (index == b2_nullNode)
+ {
+ return;
+ }
+
+ if (index == m_root)
+ {
+ b2Assert(m_nodes[index].parent == b2_nullNode);
+ }
+
+ const b2TreeNode* node = m_nodes + index;
+
+ int32 child1 = node->child1;
+ int32 child2 = node->child2;
+
+ if (node->IsLeaf())
+ {
+ b2Assert(child1 == b2_nullNode);
+ b2Assert(child2 == b2_nullNode);
+ b2Assert(node->height == 0);
+ return;
+ }
+
+ b2Assert(0 <= child1 && child1 < m_nodeCapacity);
+ b2Assert(0 <= child2 && child2 < m_nodeCapacity);
+
+ b2Assert(m_nodes[child1].parent == index);
+ b2Assert(m_nodes[child2].parent == index);
+
+ ValidateStructure(child1);
+ ValidateStructure(child2);
+}
+
+void b2DynamicTree::ValidateMetrics(int32 index) const
+{
+ if (index == b2_nullNode)
+ {
+ return;
+ }
+
+ const b2TreeNode* node = m_nodes + index;
+
+ int32 child1 = node->child1;
+ int32 child2 = node->child2;
+
+ if (node->IsLeaf())
+ {
+ b2Assert(child1 == b2_nullNode);
+ b2Assert(child2 == b2_nullNode);
+ b2Assert(node->height == 0);
+ return;
+ }
+
+ b2Assert(0 <= child1 && child1 < m_nodeCapacity);
+ b2Assert(0 <= child2 && child2 < m_nodeCapacity);
+
+ int32 height1 = m_nodes[child1].height;
+ int32 height2 = m_nodes[child2].height;
+ int32 height;
+ height = 1 + b2Max(height1, height2);
+ b2Assert(node->height == height);
+
+ b2AABB aabb;
+ aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb);
+
+ b2Assert(aabb.lowerBound == node->aabb.lowerBound);
+ b2Assert(aabb.upperBound == node->aabb.upperBound);
+
+ ValidateMetrics(child1);
+ ValidateMetrics(child2);
+}
+
+void b2DynamicTree::Validate() const
+{
+ ValidateStructure(m_root);
+ ValidateMetrics(m_root);
+
+ int32 freeCount = 0;
+ int32 freeIndex = m_freeList;
+ while (freeIndex != b2_nullNode)
+ {
+ b2Assert(0 <= freeIndex && freeIndex < m_nodeCapacity);
+ freeIndex = m_nodes[freeIndex].next;
+ ++freeCount;
+ }
+
+ b2Assert(GetHeight() == ComputeHeight());
+
+ b2Assert(m_nodeCount + freeCount == m_nodeCapacity);
+}
+
+int32 b2DynamicTree::GetMaxBalance() const
+{
+ int32 maxBalance = 0;
+ for (int32 i = 0; i < m_nodeCapacity; ++i)
+ {
+ const b2TreeNode* node = m_nodes + i;
+ if (node->height <= 1)
+ {
+ continue;
+ }
+
+ b2Assert(node->IsLeaf() == false);
+
+ int32 child1 = node->child1;
+ int32 child2 = node->child2;
+ int32 balance = b2Abs(m_nodes[child2].height - m_nodes[child1].height);
+ maxBalance = b2Max(maxBalance, balance);
+ }
+
+ return maxBalance;
+}
+
+void b2DynamicTree::RebuildBottomUp()
+{
+ int32* nodes = (int32*)b2Alloc(m_nodeCount * sizeof(int32));
+ int32 count = 0;
+
+ // Build array of leaves. Free the rest.
+ for (int32 i = 0; i < m_nodeCapacity; ++i)
+ {
+ if (m_nodes[i].height < 0)
+ {
+ // free node in pool
+ continue;
+ }
+
+ if (m_nodes[i].IsLeaf())
+ {
+ m_nodes[i].parent = b2_nullNode;
+ nodes[count] = i;
+ ++count;
+ }
+ else
+ {
+ FreeNode(i);
+ }
+ }
+
+ while (count > 1)
+ {
+ float32 minCost = b2_maxFloat;
+ int32 iMin = -1, jMin = -1;
+ for (int32 i = 0; i < count; ++i)
+ {
+ b2AABB aabbi = m_nodes[nodes[i]].aabb;
+
+ for (int32 j = i + 1; j < count; ++j)
+ {
+ b2AABB aabbj = m_nodes[nodes[j]].aabb;
+ b2AABB b;
+ b.Combine(aabbi, aabbj);
+ float32 cost = b.GetPerimeter();
+ if (cost < minCost)
+ {
+ iMin = i;
+ jMin = j;
+ minCost = cost;
+ }
+ }
+ }
+
+ int32 index1 = nodes[iMin];
+ int32 index2 = nodes[jMin];
+ b2TreeNode* child1 = m_nodes + index1;
+ b2TreeNode* child2 = m_nodes + index2;
+
+ int32 parentIndex = AllocateNode();
+ b2TreeNode* parent = m_nodes + parentIndex;
+ parent->child1 = index1;
+ parent->child2 = index2;
+ parent->height = 1 + b2Max(child1->height, child2->height);
+ parent->aabb.Combine(child1->aabb, child2->aabb);
+ parent->parent = b2_nullNode;
+
+ child1->parent = parentIndex;
+ child2->parent = parentIndex;
+
+ nodes[jMin] = nodes[count-1];
+ nodes[iMin] = parentIndex;
+ --count;
+ }
+
+ m_root = nodes[0];
+ b2Free(nodes);
+
+ Validate();
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/b2DynamicTree.h b/engines/ngi/box2d/Collision/b2DynamicTree.h
new file mode 100644
index 00000000000..7460f05db8c
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2DynamicTree.h
@@ -0,0 +1,288 @@
+/*
+* Copyright (c) 2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_DYNAMIC_TREE_H
+#define B2_DYNAMIC_TREE_H
+
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Common/b2GrowableStack.h"
+
+namespace NGI {
+
+#define b2_nullNode (-1)
+
+/// A node in the dynamic tree. The client does not interact with this directly.
+struct b2TreeNode
+{
+ bool IsLeaf() const
+ {
+ return child1 == b2_nullNode;
+ }
+
+ /// Enlarged AABB
+ b2AABB aabb;
+
+ void* userData;
+
+ union
+ {
+ int32 parent;
+ int32 next;
+ };
+
+ int32 child1;
+ int32 child2;
+
+ // leaf = 0, free node = -1
+ int32 height;
+};
+
+/// A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt.
+/// A dynamic tree arranges data in a binary tree to accelerate
+/// queries such as volume queries and ray casts. Leafs are proxies
+/// with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor
+/// so that the proxy AABB is bigger than the client object. This allows the client
+/// object to move by small amounts without triggering a tree update.
+///
+/// Nodes are pooled and relocatable, so we use node indices rather than pointers.
+class b2DynamicTree
+{
+public:
+ /// Constructing the tree initializes the node pool.
+ b2DynamicTree();
+
+ /// Destroy the tree, freeing the node pool.
+ ~b2DynamicTree();
+
+ /// Create a proxy. Provide a tight fitting AABB and a userData pointer.
+ int32 CreateProxy(const b2AABB& aabb, void* userData);
+
+ /// Destroy a proxy. This asserts if the id is invalid.
+ void DestroyProxy(int32 proxyId);
+
+ /// Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB,
+ /// then the proxy is removed from the tree and re-inserted. Otherwise
+ /// the function returns immediately.
+ /// @return true if the proxy was re-inserted.
+ bool MoveProxy(int32 proxyId, const b2AABB& aabb1, const b2Vec2& displacement);
+
+ /// Get proxy user data.
+ /// @return the proxy user data or 0 if the id is invalid.
+ void* GetUserData(int32 proxyId) const;
+
+ /// Get the fat AABB for a proxy.
+ const b2AABB& GetFatAABB(int32 proxyId) const;
+
+ /// Query an AABB for overlapping proxies. The callback class
+ /// is called for each proxy that overlaps the supplied AABB.
+ template <typename T>
+ void Query(T* callback, const b2AABB& aabb) const;
+
+ /// Ray-cast against the proxies in the tree. This relies on the callback
+ /// to perform a exact ray-cast in the case were the proxy contains a shape.
+ /// The callback also performs the any collision filtering. This has performance
+ /// roughly equal to k * log(n), where k is the number of collisions and n is the
+ /// number of proxies in the tree.
+ /// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
+ /// @param callback a callback class that is called for each proxy that is hit by the ray.
+ template <typename T>
+ void RayCast(T* callback, const b2RayCastInput& input) const;
+
+ /// Validate this tree. For testing.
+ void Validate() const;
+
+ /// Compute the height of the binary tree in O(N) time. Should not be
+ /// called often.
+ int32 GetHeight() const;
+
+ /// Get the maximum balance of an node in the tree. The balance is the difference
+ /// in height of the two children of a node.
+ int32 GetMaxBalance() const;
+
+ /// Get the ratio of the sum of the node areas to the root area.
+ float32 GetAreaRatio() const;
+
+ /// Build an optimal tree. Very expensive. For testing.
+ void RebuildBottomUp();
+
+private:
+
+ int32 AllocateNode();
+ void FreeNode(int32 node);
+
+ void InsertLeaf(int32 node);
+ void RemoveLeaf(int32 node);
+
+ int32 Balance(int32 index);
+
+ int32 ComputeHeight() const;
+ int32 ComputeHeight(int32 nodeId) const;
+
+ void ValidateStructure(int32 index) const;
+ void ValidateMetrics(int32 index) const;
+
+ int32 m_root;
+
+ b2TreeNode* m_nodes;
+ int32 m_nodeCount;
+ int32 m_nodeCapacity;
+
+ int32 m_freeList;
+
+ /// This is used to incrementally traverse the tree for re-balancing.
+ uint32 m_path;
+
+ int32 m_insertionCount;
+};
+
+inline void* b2DynamicTree::GetUserData(int32 proxyId) const
+{
+ b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
+ return m_nodes[proxyId].userData;
+}
+
+inline const b2AABB& b2DynamicTree::GetFatAABB(int32 proxyId) const
+{
+ b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
+ return m_nodes[proxyId].aabb;
+}
+
+template <typename T>
+inline void b2DynamicTree::Query(T* callback, const b2AABB& aabb) const
+{
+ b2GrowableStack<int32, 256> stack;
+ stack.Push(m_root);
+
+ while (stack.GetCount() > 0)
+ {
+ int32 nodeId = stack.Pop();
+ if (nodeId == b2_nullNode)
+ {
+ continue;
+ }
+
+ const b2TreeNode* node = m_nodes + nodeId;
+
+ if (b2TestOverlap(node->aabb, aabb))
+ {
+ if (node->IsLeaf())
+ {
+ bool proceed = callback->QueryCallback(nodeId);
+ if (proceed == false)
+ {
+ return;
+ }
+ }
+ else
+ {
+ stack.Push(node->child1);
+ stack.Push(node->child2);
+ }
+ }
+ }
+}
+
+template <typename T>
+inline void b2DynamicTree::RayCast(T* callback, const b2RayCastInput& input) const
+{
+ b2Vec2 p1 = input.p1;
+ b2Vec2 p2 = input.p2;
+ b2Vec2 r = p2 - p1;
+ b2Assert(r.LengthSquared() > 0.0f);
+ r.Normalize();
+
+ // v is perpendicular to the segment.
+ b2Vec2 v = b2Cross(1.0f, r);
+ b2Vec2 abs_v = b2Abs(v);
+
+ // Separating axis for segment (Gino, p80).
+ // |dot(v, p1 - c)| > dot(|v|, h)
+
+ float32 maxFraction = input.maxFraction;
+
+ // Build a bounding box for the segment.
+ b2AABB segmentAABB;
+ {
+ b2Vec2 t = p1 + maxFraction * (p2 - p1);
+ segmentAABB.lowerBound = b2Min(p1, t);
+ segmentAABB.upperBound = b2Max(p1, t);
+ }
+
+ b2GrowableStack<int32, 256> stack;
+ stack.Push(m_root);
+
+ while (stack.GetCount() > 0)
+ {
+ int32 nodeId = stack.Pop();
+ if (nodeId == b2_nullNode)
+ {
+ continue;
+ }
+
+ const b2TreeNode* node = m_nodes + nodeId;
+
+ if (b2TestOverlap(node->aabb, segmentAABB) == false)
+ {
+ continue;
+ }
+
+ // Separating axis for segment (Gino, p80).
+ // |dot(v, p1 - c)| > dot(|v|, h)
+ b2Vec2 c = node->aabb.GetCenter();
+ b2Vec2 h = node->aabb.GetExtents();
+ float32 separation = b2Abs(b2Dot(v, p1 - c)) - b2Dot(abs_v, h);
+ if (separation > 0.0f)
+ {
+ continue;
+ }
+
+ if (node->IsLeaf())
+ {
+ b2RayCastInput subInput;
+ subInput.p1 = input.p1;
+ subInput.p2 = input.p2;
+ subInput.maxFraction = maxFraction;
+
+ float32 value = callback->RayCastCallback(subInput, nodeId);
+
+ if (value == 0.0f)
+ {
+ // The client has terminated the ray cast.
+ return;
+ }
+
+ if (value > 0.0f)
+ {
+ // Update segment bounding box.
+ maxFraction = value;
+ b2Vec2 t = p1 + maxFraction * (p2 - p1);
+ segmentAABB.lowerBound = b2Min(p1, t);
+ segmentAABB.upperBound = b2Max(p1, t);
+ }
+ }
+ else
+ {
+ stack.Push(node->child1);
+ stack.Push(node->child2);
+ }
+ }
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Collision/b2TimeOfImpact.cpp b/engines/ngi/box2d/Collision/b2TimeOfImpact.cpp
new file mode 100644
index 00000000000..c647e67aea7
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2TimeOfImpact.cpp
@@ -0,0 +1,487 @@
+/*
+* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Collision/b2Distance.h"
+#include "engines/ngi/box2d/Collision/b2TimeOfImpact.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2CircleShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2PolygonShape.h"
+
+#include <cstdio>
+
+namespace NGI {
+using namespace std;
+
+int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters;
+int32 b2_toiRootIters, b2_toiMaxRootIters;
+
+struct b2SeparationFunction
+{
+ enum Type
+ {
+ e_points,
+ e_faceA,
+ e_faceB
+ };
+
+ // TODO_ERIN might not need to return the separation
+
+ float32 Initialize(const b2SimplexCache* cache,
+ const b2DistanceProxy* proxyA, const b2Sweep& sweepA,
+ const b2DistanceProxy* proxyB, const b2Sweep& sweepB,
+ float32 t1)
+ {
+ m_proxyA = proxyA;
+ m_proxyB = proxyB;
+ int32 count = cache->count;
+ b2Assert(0 < count && count < 3);
+
+ m_sweepA = sweepA;
+ m_sweepB = sweepB;
+
+ b2Transform xfA, xfB;
+ m_sweepA.GetTransform(&xfA, t1);
+ m_sweepB.GetTransform(&xfB, t1);
+
+ if (count == 1)
+ {
+ m_type = e_points;
+ b2Vec2 localPointA = m_proxyA->GetVertex(cache->indexA[0]);
+ b2Vec2 localPointB = m_proxyB->GetVertex(cache->indexB[0]);
+ b2Vec2 pointA = b2Mul(xfA, localPointA);
+ b2Vec2 pointB = b2Mul(xfB, localPointB);
+ m_axis = pointB - pointA;
+ float32 s = m_axis.Normalize();
+ return s;
+ }
+ else if (cache->indexA[0] == cache->indexA[1])
+ {
+ // Two points on B and one on A.
+ m_type = e_faceB;
+ b2Vec2 localPointB1 = proxyB->GetVertex(cache->indexB[0]);
+ b2Vec2 localPointB2 = proxyB->GetVertex(cache->indexB[1]);
+
+ m_axis = b2Cross(localPointB2 - localPointB1, 1.0f);
+ m_axis.Normalize();
+ b2Vec2 normal = b2Mul(xfB.q, m_axis);
+
+ m_localPoint = 0.5f * (localPointB1 + localPointB2);
+ b2Vec2 pointB = b2Mul(xfB, m_localPoint);
+
+ b2Vec2 localPointA = proxyA->GetVertex(cache->indexA[0]);
+ b2Vec2 pointA = b2Mul(xfA, localPointA);
+
+ float32 s = b2Dot(pointA - pointB, normal);
+ if (s < 0.0f)
+ {
+ m_axis = -m_axis;
+ s = -s;
+ }
+ return s;
+ }
+ else
+ {
+ // Two points on A and one or two points on B.
+ m_type = e_faceA;
+ b2Vec2 localPointA1 = m_proxyA->GetVertex(cache->indexA[0]);
+ b2Vec2 localPointA2 = m_proxyA->GetVertex(cache->indexA[1]);
+
+ m_axis = b2Cross(localPointA2 - localPointA1, 1.0f);
+ m_axis.Normalize();
+ b2Vec2 normal = b2Mul(xfA.q, m_axis);
+
+ m_localPoint = 0.5f * (localPointA1 + localPointA2);
+ b2Vec2 pointA = b2Mul(xfA, m_localPoint);
+
+ b2Vec2 localPointB = m_proxyB->GetVertex(cache->indexB[0]);
+ b2Vec2 pointB = b2Mul(xfB, localPointB);
+
+ float32 s = b2Dot(pointB - pointA, normal);
+ if (s < 0.0f)
+ {
+ m_axis = -m_axis;
+ s = -s;
+ }
+ return s;
+ }
+ }
+
+ float32 FindMinSeparation(int32* indexA, int32* indexB, float32 t) const
+ {
+ b2Transform xfA, xfB;
+ m_sweepA.GetTransform(&xfA, t);
+ m_sweepB.GetTransform(&xfB, t);
+
+ switch (m_type)
+ {
+ case e_points:
+ {
+ b2Vec2 axisA = b2MulT(xfA.q, m_axis);
+ b2Vec2 axisB = b2MulT(xfB.q, -m_axis);
+
+ *indexA = m_proxyA->GetSupport(axisA);
+ *indexB = m_proxyB->GetSupport(axisB);
+
+ b2Vec2 localPointA = m_proxyA->GetVertex(*indexA);
+ b2Vec2 localPointB = m_proxyB->GetVertex(*indexB);
+
+ b2Vec2 pointA = b2Mul(xfA, localPointA);
+ b2Vec2 pointB = b2Mul(xfB, localPointB);
+
+ float32 separation = b2Dot(pointB - pointA, m_axis);
+ return separation;
+ }
+
+ case e_faceA:
+ {
+ b2Vec2 normal = b2Mul(xfA.q, m_axis);
+ b2Vec2 pointA = b2Mul(xfA, m_localPoint);
+
+ b2Vec2 axisB = b2MulT(xfB.q, -normal);
+
+ *indexA = -1;
+ *indexB = m_proxyB->GetSupport(axisB);
+
+ b2Vec2 localPointB = m_proxyB->GetVertex(*indexB);
+ b2Vec2 pointB = b2Mul(xfB, localPointB);
+
+ float32 separation = b2Dot(pointB - pointA, normal);
+ return separation;
+ }
+
+ case e_faceB:
+ {
+ b2Vec2 normal = b2Mul(xfB.q, m_axis);
+ b2Vec2 pointB = b2Mul(xfB, m_localPoint);
+
+ b2Vec2 axisA = b2MulT(xfA.q, -normal);
+
+ *indexB = -1;
+ *indexA = m_proxyA->GetSupport(axisA);
+
+ b2Vec2 localPointA = m_proxyA->GetVertex(*indexA);
+ b2Vec2 pointA = b2Mul(xfA, localPointA);
+
+ float32 separation = b2Dot(pointA - pointB, normal);
+ return separation;
+ }
+
+ default:
+ b2Assert(false);
+ *indexA = -1;
+ *indexB = -1;
+ return 0.0f;
+ }
+ }
+
+ float32 Evaluate(int32 indexA, int32 indexB, float32 t) const
+ {
+ b2Transform xfA, xfB;
+ m_sweepA.GetTransform(&xfA, t);
+ m_sweepB.GetTransform(&xfB, t);
+
+ switch (m_type)
+ {
+ case e_points:
+ {
+ b2Vec2 axisA = b2MulT(xfA.q, m_axis);
+ b2Vec2 axisB = b2MulT(xfB.q, -m_axis);
+
+ b2Vec2 localPointA = m_proxyA->GetVertex(indexA);
+ b2Vec2 localPointB = m_proxyB->GetVertex(indexB);
+
+ b2Vec2 pointA = b2Mul(xfA, localPointA);
+ b2Vec2 pointB = b2Mul(xfB, localPointB);
+ float32 separation = b2Dot(pointB - pointA, m_axis);
+
+ return separation;
+ }
+
+ case e_faceA:
+ {
+ b2Vec2 normal = b2Mul(xfA.q, m_axis);
+ b2Vec2 pointA = b2Mul(xfA, m_localPoint);
+
+ b2Vec2 axisB = b2MulT(xfB.q, -normal);
+
+ b2Vec2 localPointB = m_proxyB->GetVertex(indexB);
+ b2Vec2 pointB = b2Mul(xfB, localPointB);
+
+ float32 separation = b2Dot(pointB - pointA, normal);
+ return separation;
+ }
+
+ case e_faceB:
+ {
+ b2Vec2 normal = b2Mul(xfB.q, m_axis);
+ b2Vec2 pointB = b2Mul(xfB, m_localPoint);
+
+ b2Vec2 axisA = b2MulT(xfA.q, -normal);
+
+ b2Vec2 localPointA = m_proxyA->GetVertex(indexA);
+ b2Vec2 pointA = b2Mul(xfA, localPointA);
+
+ float32 separation = b2Dot(pointA - pointB, normal);
+ return separation;
+ }
+
+ default:
+ b2Assert(false);
+ return 0.0f;
+ }
+ }
+
+ const b2DistanceProxy* m_proxyA;
+ const b2DistanceProxy* m_proxyB;
+ b2Sweep m_sweepA, m_sweepB;
+ Type m_type;
+ b2Vec2 m_localPoint;
+ b2Vec2 m_axis;
+};
+
+// CCD via the local separating axis method. This seeks progression
+// by computing the largest time at which separation is maintained.
+void b2TimeOfImpact(b2TOIOutput* output, const b2TOIInput* input)
+{
+ ++b2_toiCalls;
+
+ output->state = b2TOIOutput::e_unknown;
+ output->t = input->tMax;
+
+ const b2DistanceProxy* proxyA = &input->proxyA;
+ const b2DistanceProxy* proxyB = &input->proxyB;
+
+ b2Sweep sweepA = input->sweepA;
+ b2Sweep sweepB = input->sweepB;
+
+ // Large rotations can make the root finder fail, so we normalize the
+ // sweep angles.
+ sweepA.Normalize();
+ sweepB.Normalize();
+
+ float32 tMax = input->tMax;
+
+ float32 totalRadius = proxyA->m_radius + proxyB->m_radius;
+ float32 target = b2Max(b2_linearSlop, totalRadius - 3.0f * b2_linearSlop);
+ float32 tolerance = 0.25f * b2_linearSlop;
+ b2Assert(target > tolerance);
+
+ float32 t1 = 0.0f;
+ const int32 k_maxIterations = 20; // TODO_ERIN b2Settings
+ int32 iter = 0;
+
+ // Prepare input for distance query.
+ b2SimplexCache cache;
+ cache.count = 0;
+ b2DistanceInput distanceInput;
+ distanceInput.proxyA = input->proxyA;
+ distanceInput.proxyB = input->proxyB;
+ distanceInput.useRadii = false;
+
+ // The outer loop progressively attempts to compute new separating axes.
+ // This loop terminates when an axis is repeated (no progress is made).
+ for(;;)
+ {
+ b2Transform xfA, xfB;
+ sweepA.GetTransform(&xfA, t1);
+ sweepB.GetTransform(&xfB, t1);
+
+ // Get the distance between shapes. We can also use the results
+ // to get a separating axis.
+ distanceInput.transformA = xfA;
+ distanceInput.transformB = xfB;
+ b2DistanceOutput distanceOutput;
+ b2Distance(&distanceOutput, &cache, &distanceInput);
+
+ // If the shapes are overlapped, we give up on continuous collision.
+ if (distanceOutput.distance <= 0.0f)
+ {
+ // Failure!
+ output->state = b2TOIOutput::e_overlapped;
+ output->t = 0.0f;
+ break;
+ }
+
+ if (distanceOutput.distance < target + tolerance)
+ {
+ // Victory!
+ output->state = b2TOIOutput::e_touching;
+ output->t = t1;
+ break;
+ }
+
+ // Initialize the separating axis.
+ b2SeparationFunction fcn;
+ fcn.Initialize(&cache, proxyA, sweepA, proxyB, sweepB, t1);
+#if 0
+ // Dump the curve seen by the root finder
+ {
+ const int32 N = 100;
+ float32 dx = 1.0f / N;
+ float32 xs[N+1];
+ float32 fs[N+1];
+
+ float32 x = 0.0f;
+
+ for (int32 i = 0; i <= N; ++i)
+ {
+ sweepA.GetTransform(&xfA, x);
+ sweepB.GetTransform(&xfB, x);
+ float32 f = fcn.Evaluate(xfA, xfB) - target;
+
+ printf("%g %g\n", x, f);
+
+ xs[i] = x;
+ fs[i] = f;
+
+ x += dx;
+ }
+ }
+#endif
+
+ // Compute the TOI on the separating axis. We do this by successively
+ // resolving the deepest point. This loop is bounded by the number of vertices.
+ bool done = false;
+ float32 t2 = tMax;
+ int32 pushBackIter = 0;
+ for (;;)
+ {
+ // Find the deepest point at t2. Store the witness point indices.
+ int32 indexA, indexB;
+ float32 s2 = fcn.FindMinSeparation(&indexA, &indexB, t2);
+
+ // Is the final configuration separated?
+ if (s2 > target + tolerance)
+ {
+ // Victory!
+ output->state = b2TOIOutput::e_separated;
+ output->t = tMax;
+ done = true;
+ break;
+ }
+
+ // Has the separation reached tolerance?
+ if (s2 > target - tolerance)
+ {
+ // Advance the sweeps
+ t1 = t2;
+ break;
+ }
+
+ // Compute the initial separation of the witness points.
+ float32 s1 = fcn.Evaluate(indexA, indexB, t1);
+
+ // Check for initial overlap. This might happen if the root finder
+ // runs out of iterations.
+ if (s1 < target - tolerance)
+ {
+ output->state = b2TOIOutput::e_failed;
+ output->t = t1;
+ done = true;
+ break;
+ }
+
+ // Check for touching
+ if (s1 <= target + tolerance)
+ {
+ // Victory! t1 should hold the TOI (could be 0.0).
+ output->state = b2TOIOutput::e_touching;
+ output->t = t1;
+ done = true;
+ break;
+ }
+
+ // Compute 1D root of: f(x) - target = 0
+ int32 rootIterCount = 0;
+ float32 a1 = t1, a2 = t2;
+ for (;;)
+ {
+ // Use a mix of the secant rule and bisection.
+ float32 t;
+ if (rootIterCount & 1)
+ {
+ // Secant rule to improve convergence.
+ t = a1 + (target - s1) * (a2 - a1) / (s2 - s1);
+ }
+ else
+ {
+ // Bisection to guarantee progress.
+ t = 0.5f * (a1 + a2);
+ }
+
+ float32 s = fcn.Evaluate(indexA, indexB, t);
+
+ if (b2Abs(s - target) < tolerance)
+ {
+ // t2 holds a tentative value for t1
+ t2 = t;
+ break;
+ }
+
+ // Ensure we continue to bracket the root.
+ if (s > target)
+ {
+ a1 = t;
+ s1 = s;
+ }
+ else
+ {
+ a2 = t;
+ s2 = s;
+ }
+
+ ++rootIterCount;
+ ++b2_toiRootIters;
+
+ if (rootIterCount == 50)
+ {
+ break;
+ }
+ }
+
+ b2_toiMaxRootIters = b2Max(b2_toiMaxRootIters, rootIterCount);
+
+ ++pushBackIter;
+
+ if (pushBackIter == b2_maxPolygonVertices)
+ {
+ break;
+ }
+ }
+
+ ++iter;
+ ++b2_toiIters;
+
+ if (done)
+ {
+ break;
+ }
+
+ if (iter == k_maxIterations)
+ {
+ // Root finder got stuck. Semi-victory.
+ output->state = b2TOIOutput::e_failed;
+ output->t = t1;
+ break;
+ }
+ }
+
+ b2_toiMaxIters = b2Max(b2_toiMaxIters, iter);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Collision/b2TimeOfImpact.h b/engines/ngi/box2d/Collision/b2TimeOfImpact.h
new file mode 100644
index 00000000000..f147695a053
--- /dev/null
+++ b/engines/ngi/box2d/Collision/b2TimeOfImpact.h
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_TIME_OF_IMPACT_H
+#define B2_TIME_OF_IMPACT_H
+
+#include "engines/ngi/box2d/Common/b2Math.h"
+#include "engines/ngi/box2d/Collision/b2Distance.h"
+
+namespace NGI {
+
+/// Input parameters for b2TimeOfImpact
+struct b2TOIInput
+{
+ b2DistanceProxy proxyA;
+ b2DistanceProxy proxyB;
+ b2Sweep sweepA;
+ b2Sweep sweepB;
+ float32 tMax; // defines sweep interval [0, tMax]
+};
+
+// Output parameters for b2TimeOfImpact.
+struct b2TOIOutput
+{
+ enum State
+ {
+ e_unknown,
+ e_failed,
+ e_overlapped,
+ e_touching,
+ e_separated
+ };
+
+ State state;
+ float32 t;
+};
+
+/// Compute the upper bound on time before two shapes penetrate. Time is represented as
+/// a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate,
+/// non-tunneling collision. If you change the time interval, you should call this function
+/// again.
+/// Note: use b2Distance to compute the contact point and normal at the time of impact.
+void b2TimeOfImpact(b2TOIOutput* output, const b2TOIInput* input);
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Common/b2BlockAllocator.cpp b/engines/ngi/box2d/Common/b2BlockAllocator.cpp
new file mode 100644
index 00000000000..0537d303c6e
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2BlockAllocator.cpp
@@ -0,0 +1,221 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include <cstdlib>
+#include <climits>
+#include <cstring>
+#include <memory>
+
+namespace NGI {
+using namespace std;
+
+int32 b2BlockAllocator::s_blockSizes[b2_blockSizes] =
+{
+ 16, // 0
+ 32, // 1
+ 64, // 2
+ 96, // 3
+ 128, // 4
+ 160, // 5
+ 192, // 6
+ 224, // 7
+ 256, // 8
+ 320, // 9
+ 384, // 10
+ 448, // 11
+ 512, // 12
+ 640, // 13
+};
+uint8 b2BlockAllocator::s_blockSizeLookup[b2_maxBlockSize + 1];
+bool b2BlockAllocator::s_blockSizeLookupInitialized;
+
+struct b2Chunk
+{
+ int32 blockSize;
+ b2Block* blocks;
+};
+
+struct b2Block
+{
+ b2Block* next;
+};
+
+b2BlockAllocator::b2BlockAllocator()
+{
+ b2Assert(b2_blockSizes < UCHAR_MAX);
+
+ m_chunkSpace = b2_chunkArrayIncrement;
+ m_chunkCount = 0;
+ m_chunks = (b2Chunk*)b2Alloc(m_chunkSpace * sizeof(b2Chunk));
+
+ memset(m_chunks, 0, m_chunkSpace * sizeof(b2Chunk));
+ memset(m_freeLists, 0, sizeof(m_freeLists));
+
+ if (s_blockSizeLookupInitialized == false)
+ {
+ int32 j = 0;
+ for (int32 i = 1; i <= b2_maxBlockSize; ++i)
+ {
+ b2Assert(j < b2_blockSizes);
+ if (i <= s_blockSizes[j])
+ {
+ s_blockSizeLookup[i] = (uint8)j;
+ }
+ else
+ {
+ ++j;
+ s_blockSizeLookup[i] = (uint8)j;
+ }
+ }
+
+ s_blockSizeLookupInitialized = true;
+ }
+}
+
+b2BlockAllocator::~b2BlockAllocator()
+{
+ for (int32 i = 0; i < m_chunkCount; ++i)
+ {
+ b2Free(m_chunks[i].blocks);
+ }
+
+ b2Free(m_chunks);
+}
+
+void* b2BlockAllocator::Allocate(int32 size)
+{
+ if (size == 0)
+ return NULL;
+
+ b2Assert(0 < size);
+
+ if (size > b2_maxBlockSize)
+ {
+ return b2Alloc(size);
+ }
+
+ int32 index = s_blockSizeLookup[size];
+ b2Assert(0 <= index && index < b2_blockSizes);
+
+ if (m_freeLists[index])
+ {
+ b2Block* block = m_freeLists[index];
+ m_freeLists[index] = block->next;
+ return block;
+ }
+ else
+ {
+ if (m_chunkCount == m_chunkSpace)
+ {
+ b2Chunk* oldChunks = m_chunks;
+ m_chunkSpace += b2_chunkArrayIncrement;
+ m_chunks = (b2Chunk*)b2Alloc(m_chunkSpace * sizeof(b2Chunk));
+ memcpy(m_chunks, oldChunks, m_chunkCount * sizeof(b2Chunk));
+ memset(m_chunks + m_chunkCount, 0, b2_chunkArrayIncrement * sizeof(b2Chunk));
+ b2Free(oldChunks);
+ }
+
+ b2Chunk* chunk = m_chunks + m_chunkCount;
+ chunk->blocks = (b2Block*)b2Alloc(b2_chunkSize);
+#if defined(_DEBUG)
+ memset(chunk->blocks, 0xcd, b2_chunkSize);
+#endif
+ int32 blockSize = s_blockSizes[index];
+ chunk->blockSize = blockSize;
+ int32 blockCount = b2_chunkSize / blockSize;
+ b2Assert(blockCount * blockSize <= b2_chunkSize);
+ for (int32 i = 0; i < blockCount - 1; ++i)
+ {
+ b2Block* block = (b2Block*)((int8*)chunk->blocks + blockSize * i);
+ b2Block* next = (b2Block*)((int8*)chunk->blocks + blockSize * (i + 1));
+ block->next = next;
+ }
+ b2Block* last = (b2Block*)((int8*)chunk->blocks + blockSize * (blockCount - 1));
+ last->next = NULL;
+
+ m_freeLists[index] = chunk->blocks->next;
+ ++m_chunkCount;
+
+ return chunk->blocks;
+ }
+}
+
+void b2BlockAllocator::Free(void* p, int32 size)
+{
+ if (size == 0)
+ {
+ return;
+ }
+
+ b2Assert(0 < size);
+
+ if (size > b2_maxBlockSize)
+ {
+ b2Free(p);
+ return;
+ }
+
+ int32 index = s_blockSizeLookup[size];
+ b2Assert(0 <= index && index < b2_blockSizes);
+
+#ifdef _DEBUG
+ // Verify the memory address and size is valid.
+ int32 blockSize = s_blockSizes[index];
+ bool found = false;
+ for (int32 i = 0; i < m_chunkCount; ++i)
+ {
+ b2Chunk* chunk = m_chunks + i;
+ if (chunk->blockSize != blockSize)
+ {
+ b2Assert( (int8*)p + blockSize <= (int8*)chunk->blocks ||
+ (int8*)chunk->blocks + b2_chunkSize <= (int8*)p);
+ }
+ else
+ {
+ if ((int8*)chunk->blocks <= (int8*)p && (int8*)p + blockSize <= (int8*)chunk->blocks + b2_chunkSize)
+ {
+ found = true;
+ }
+ }
+ }
+
+ b2Assert(found);
+
+ memset(p, 0xfd, blockSize);
+#endif
+
+ b2Block* block = (b2Block*)p;
+ block->next = m_freeLists[index];
+ m_freeLists[index] = block;
+}
+
+void b2BlockAllocator::Clear()
+{
+ for (int32 i = 0; i < m_chunkCount; ++i)
+ {
+ b2Free(m_chunks[i].blocks);
+ }
+
+ m_chunkCount = 0;
+ memset(m_chunks, 0, m_chunkSpace * sizeof(b2Chunk));
+
+ memset(m_freeLists, 0, sizeof(m_freeLists));
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Common/b2BlockAllocator.h b/engines/ngi/box2d/Common/b2BlockAllocator.h
new file mode 100644
index 00000000000..8736862553b
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2BlockAllocator.h
@@ -0,0 +1,66 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_BLOCK_ALLOCATOR_H
+#define B2_BLOCK_ALLOCATOR_H
+
+#include "engines/ngi/box2d/Common/b2Settings.h"
+
+namespace NGI {
+
+const int32 b2_chunkSize = 16 * 1024;
+const int32 b2_maxBlockSize = 640;
+const int32 b2_blockSizes = 14;
+const int32 b2_chunkArrayIncrement = 128;
+
+struct b2Block;
+struct b2Chunk;
+
+/// This is a small object allocator used for allocating small
+/// objects that persist for more than one time step.
+/// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp
+class b2BlockAllocator
+{
+public:
+ b2BlockAllocator();
+ ~b2BlockAllocator();
+
+ /// Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize.
+ void* Allocate(int32 size);
+
+ /// Free memory. This will use b2Free if the size is larger than b2_maxBlockSize.
+ void Free(void* p, int32 size);
+
+ void Clear();
+
+private:
+
+ b2Chunk* m_chunks;
+ int32 m_chunkCount;
+ int32 m_chunkSpace;
+
+ b2Block* m_freeLists[b2_blockSizes];
+
+ static int32 s_blockSizes[b2_blockSizes];
+ static uint8 s_blockSizeLookup[b2_maxBlockSize + 1];
+ static bool s_blockSizeLookupInitialized;
+};
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Common/b2Draw.cpp b/engines/ngi/box2d/Common/b2Draw.cpp
new file mode 100644
index 00000000000..e8f4b86eb62
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2Draw.cpp
@@ -0,0 +1,48 @@
+/*
+* Copyright (c) 2011 Erin Catto http://box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Common/b2Draw.h"
+
+namespace NGI {
+
+b2Draw::b2Draw()
+{
+ m_drawFlags = 0;
+}
+
+void b2Draw::SetFlags(uint32 flags)
+{
+ m_drawFlags = flags;
+}
+
+uint32 b2Draw::GetFlags() const
+{
+ return m_drawFlags;
+}
+
+void b2Draw::AppendFlags(uint32 flags)
+{
+ m_drawFlags |= flags;
+}
+
+void b2Draw::ClearFlags(uint32 flags)
+{
+ m_drawFlags &= ~flags;
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Common/b2Draw.h b/engines/ngi/box2d/Common/b2Draw.h
new file mode 100644
index 00000000000..015b9977463
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2Draw.h
@@ -0,0 +1,85 @@
+/*
+* Copyright (c) 2011 Erin Catto http://box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Common/b2Math.h"
+
+namespace NGI {
+
+/// Color for debug drawing. Each value has the range [0,1].
+struct b2Color
+{
+ b2Color() {}
+ b2Color(float32 r, float32 g, float32 b) : r(r), g(g), b(b) {}
+ void Set(float32 ri, float32 gi, float32 bi) { r = ri; g = gi; b = bi; }
+ float32 r, g, b;
+};
+
+/// Implement and register this class with a b2World to provide debug drawing of physics
+/// entities in your game.
+class b2Draw
+{
+public:
+ b2Draw();
+
+ virtual ~b2Draw() {}
+
+ enum
+ {
+ e_shapeBit = 0x0001, ///< draw shapes
+ e_jointBit = 0x0002, ///< draw joint connections
+ e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes
+ e_pairBit = 0x0008, ///< draw broad-phase pairs
+ e_centerOfMassBit = 0x0010 ///< draw center of mass frame
+ };
+
+ /// Set the drawing flags.
+ void SetFlags(uint32 flags);
+
+ /// Get the drawing flags.
+ uint32 GetFlags() const;
+
+ /// Append flags to the current flags.
+ void AppendFlags(uint32 flags);
+
+ /// Clear flags from the current flags.
+ void ClearFlags(uint32 flags);
+
+ /// Draw a closed polygon provided in CCW order.
+ virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
+
+ /// Draw a solid closed polygon provided in CCW order.
+ virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
+
+ /// Draw a circle.
+ virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) = 0;
+
+ /// Draw a solid circle.
+ virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) = 0;
+
+ /// Draw a line segment.
+ virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0;
+
+ /// Draw a transform. Choose your own length scale.
+ /// @param xf a transform.
+ virtual void DrawTransform(const b2Transform& xf) = 0;
+
+protected:
+ uint32 m_drawFlags;
+};
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Common/b2GrowableStack.h b/engines/ngi/box2d/Common/b2GrowableStack.h
new file mode 100644
index 00000000000..496df867a55
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2GrowableStack.h
@@ -0,0 +1,88 @@
+/*
+* Copyright (c) 2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_GROWABLE_STACK_H
+#define B2_GROWABLE_STACK_H
+#include "engines/ngi/box2d/Common/b2Settings.h"
+#include <cstring>
+
+namespace NGI {
+
+/// This is a growable LIFO stack with an initial capacity of N.
+/// If the stack size exceeds the initial capacity, the heap is used
+/// to increase the size of the stack.
+template <typename T, int32 N>
+class b2GrowableStack
+{
+public:
+ b2GrowableStack()
+ {
+ m_stack = m_array;
+ m_count = 0;
+ m_capacity = N;
+ }
+
+ ~b2GrowableStack()
+ {
+ if (m_stack != m_array)
+ {
+ b2Free(m_stack);
+ m_stack = NULL;
+ }
+ }
+
+ void Push(const T& element)
+ {
+ if (m_count == m_capacity)
+ {
+ T* old = m_stack;
+ m_capacity *= 2;
+ m_stack = (T*)b2Alloc(m_capacity * sizeof(T));
+ std::memcpy(m_stack, old, m_count * sizeof(T));
+ if (old != m_array)
+ {
+ b2Free(old);
+ }
+ }
+
+ m_stack[m_count] = element;
+ ++m_count;
+ }
+
+ T Pop()
+ {
+ b2Assert(m_count > 0);
+ --m_count;
+ return m_stack[m_count];
+ }
+
+ int32 GetCount()
+ {
+ return m_count;
+ }
+
+private:
+ T* m_stack;
+ T m_array[N];
+ int32 m_count;
+ int32 m_capacity;
+};
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Common/b2Math.cpp b/engines/ngi/box2d/Common/b2Math.cpp
new file mode 100644
index 00000000000..b17e0bbfa4f
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2Math.cpp
@@ -0,0 +1,98 @@
+/*
+* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Common/b2Math.h"
+
+namespace NGI {
+
+const b2Vec2 b2Vec2_zero(0.0f, 0.0f);
+
+/// Solve A * x = b, where b is a column vector. This is more efficient
+/// than computing the inverse in one-shot cases.
+b2Vec3 b2Mat33::Solve33(const b2Vec3& b) const
+{
+ float32 det = b2Dot(ex, b2Cross(ey, ez));
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+ b2Vec3 x;
+ x.x = det * b2Dot(b, b2Cross(ey, ez));
+ x.y = det * b2Dot(ex, b2Cross(b, ez));
+ x.z = det * b2Dot(ex, b2Cross(ey, b));
+ return x;
+}
+
+/// Solve A * x = b, where b is a column vector. This is more efficient
+/// than computing the inverse in one-shot cases.
+b2Vec2 b2Mat33::Solve22(const b2Vec2& b) const
+{
+ float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
+ float32 det = a11 * a22 - a12 * a21;
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+ b2Vec2 x;
+ x.x = det * (a22 * b.x - a12 * b.y);
+ x.y = det * (a11 * b.y - a21 * b.x);
+ return x;
+}
+
+///
+void b2Mat33::GetInverse22(b2Mat33* M) const
+{
+ float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
+ float32 det = a * d - b * c;
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+
+ M->ex.x = det * d; M->ey.x = -det * b; M->ex.z = 0.0f;
+ M->ex.y = -det * c; M->ey.y = det * a; M->ey.z = 0.0f;
+ M->ez.x = 0.0f; M->ez.y = 0.0f; M->ez.z = 0.0f;
+}
+
+/// Returns the zero matrix if singular.
+void b2Mat33::GetSymInverse33(b2Mat33* M) const
+{
+ float32 det = b2Dot(ex, b2Cross(ey, ez));
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+
+ float32 a11 = ex.x, a12 = ey.x, a13 = ez.x;
+ float32 a22 = ey.y, a23 = ez.y;
+ float32 a33 = ez.z;
+
+ M->ex.x = det * (a22 * a33 - a23 * a23);
+ M->ex.y = det * (a13 * a23 - a12 * a33);
+ M->ex.z = det * (a12 * a23 - a13 * a22);
+
+ M->ey.x = M->ex.y;
+ M->ey.y = det * (a11 * a33 - a13 * a13);
+ M->ey.z = det * (a13 * a12 - a11 * a23);
+
+ M->ez.x = M->ex.z;
+ M->ez.y = M->ey.z;
+ M->ez.z = det * (a11 * a22 - a12 * a12);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Common/b2Math.h b/engines/ngi/box2d/Common/b2Math.h
new file mode 100644
index 00000000000..f9b5477bb4f
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2Math.h
@@ -0,0 +1,735 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_MATH_H
+#define B2_MATH_H
+
+#include "engines/ngi/box2d/Common/b2Settings.h"
+
+#include <cmath>
+#include <cfloat>
+#include <cstddef>
+#include <limits>
+
+namespace NGI {
+
+/// This function is used to ensure that a floating point number is
+/// not a NaN or infinity.
+inline bool b2IsValid(float32 x)
+{
+ if (x != x)
+ {
+ // NaN.
+ return false;
+ }
+
+ float32 infinity = std::numeric_limits<float32>::infinity();
+ return -infinity < x && x < infinity;
+}
+
+/// This is a approximate yet fast inverse square-root.
+inline float32 b2InvSqrt(float32 x)
+{
+ union
+ {
+ float32 x;
+ int32 i;
+ } convert;
+
+ convert.x = x;
+ float32 xhalf = 0.5f * x;
+ convert.i = 0x5f3759df - (convert.i >> 1);
+ x = convert.x;
+ x = x * (1.5f - xhalf * x * x);
+ return x;
+}
+
+#define b2Sqrt(x) std::sqrt(x)
+#define b2Atan2(y, x) std::atan2(y, x)
+
+/// A 2D column vector.
+struct b2Vec2
+{
+ /// Default constructor does nothing (for performance).
+ b2Vec2() {}
+
+ /// Construct using coordinates.
+ b2Vec2(float32 x, float32 y) : x(x), y(y) {}
+
+ /// Set this vector to all zeros.
+ void SetZero() { x = 0.0f; y = 0.0f; }
+
+ /// Set this vector to some specified coordinates.
+ void Set(float32 x_, float32 y_) { x = x_; y = y_; }
+
+ /// Negate this vector.
+ b2Vec2 operator -() const { b2Vec2 v; v.Set(-x, -y); return v; }
+
+ /// Read from and indexed element.
+ float32 operator () (int32 i) const
+ {
+ return (&x)[i];
+ }
+
+ /// Write to an indexed element.
+ float32& operator () (int32 i)
+ {
+ return (&x)[i];
+ }
+
+ /// Add a vector to this vector.
+ void operator += (const b2Vec2& v)
+ {
+ x += v.x; y += v.y;
+ }
+
+ /// Subtract a vector from this vector.
+ void operator -= (const b2Vec2& v)
+ {
+ x -= v.x; y -= v.y;
+ }
+
+ /// Multiply this vector by a scalar.
+ void operator *= (float32 a)
+ {
+ x *= a; y *= a;
+ }
+
+ /// Get the length of this vector (the norm).
+ float32 Length() const
+ {
+ return b2Sqrt(x * x + y * y);
+ }
+
+ /// Get the length squared. For performance, use this instead of
+ /// b2Vec2::Length (if possible).
+ float32 LengthSquared() const
+ {
+ return x * x + y * y;
+ }
+
+ /// Convert this vector into a unit vector. Returns the length.
+ float32 Normalize()
+ {
+ float32 length = Length();
+ if (length < b2_epsilon)
+ {
+ return 0.0f;
+ }
+ float32 invLength = 1.0f / length;
+ x *= invLength;
+ y *= invLength;
+
+ return length;
+ }
+
+ /// Does this vector contain finite coordinates?
+ bool IsValid() const
+ {
+ return b2IsValid(x) && b2IsValid(y);
+ }
+
+ /// Get the skew vector such that dot(skew_vec, other) == cross(vec, other)
+ b2Vec2 Skew() const
+ {
+ return b2Vec2(-y, x);
+ }
+
+ float32 x, y;
+};
+
+/// A 2D column vector with 3 elements.
+struct b2Vec3
+{
+ /// Default constructor does nothing (for performance).
+ b2Vec3() {}
+
+ /// Construct using coordinates.
+ b2Vec3(float32 x, float32 y, float32 z) : x(x), y(y), z(z) {}
+
+ /// Set this vector to all zeros.
+ void SetZero() { x = 0.0f; y = 0.0f; z = 0.0f; }
+
+ /// Set this vector to some specified coordinates.
+ void Set(float32 x_, float32 y_, float32 z_) { x = x_; y = y_; z = z_; }
+
+ /// Negate this vector.
+ b2Vec3 operator -() const { b2Vec3 v; v.Set(-x, -y, -z); return v; }
+
+ /// Add a vector to this vector.
+ void operator += (const b2Vec3& v)
+ {
+ x += v.x; y += v.y; z += v.z;
+ }
+
+ /// Subtract a vector from this vector.
+ void operator -= (const b2Vec3& v)
+ {
+ x -= v.x; y -= v.y; z -= v.z;
+ }
+
+ /// Multiply this vector by a scalar.
+ void operator *= (float32 s)
+ {
+ x *= s; y *= s; z *= s;
+ }
+
+ float32 x, y, z;
+};
+
+/// A 2-by-2 matrix. Stored in column-major order.
+struct b2Mat22
+{
+ /// The default constructor does nothing (for performance).
+ b2Mat22() {}
+
+ /// Construct this matrix using columns.
+ b2Mat22(const b2Vec2& c1, const b2Vec2& c2)
+ {
+ ex = c1;
+ ey = c2;
+ }
+
+ /// Construct this matrix using scalars.
+ b2Mat22(float32 a11, float32 a12, float32 a21, float32 a22)
+ {
+ ex.x = a11; ex.y = a21;
+ ey.x = a12; ey.y = a22;
+ }
+
+ /// Initialize this matrix using columns.
+ void Set(const b2Vec2& c1, const b2Vec2& c2)
+ {
+ ex = c1;
+ ey = c2;
+ }
+
+ /// Set this to the identity matrix.
+ void SetIdentity()
+ {
+ ex.x = 1.0f; ey.x = 0.0f;
+ ex.y = 0.0f; ey.y = 1.0f;
+ }
+
+ /// Set this matrix to all zeros.
+ void SetZero()
+ {
+ ex.x = 0.0f; ey.x = 0.0f;
+ ex.y = 0.0f; ey.y = 0.0f;
+ }
+
+ b2Mat22 GetInverse() const
+ {
+ float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
+ b2Mat22 B;
+ float32 det = a * d - b * c;
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+ B.ex.x = det * d; B.ey.x = -det * b;
+ B.ex.y = -det * c; B.ey.y = det * a;
+ return B;
+ }
+
+ /// Solve A * x = b, where b is a column vector. This is more efficient
+ /// than computing the inverse in one-shot cases.
+ b2Vec2 Solve(const b2Vec2& b) const
+ {
+ float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
+ float32 det = a11 * a22 - a12 * a21;
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+ b2Vec2 x;
+ x.x = det * (a22 * b.x - a12 * b.y);
+ x.y = det * (a11 * b.y - a21 * b.x);
+ return x;
+ }
+
+ b2Vec2 ex, ey;
+};
+
+/// A 3-by-3 matrix. Stored in column-major order.
+struct b2Mat33
+{
+ /// The default constructor does nothing (for performance).
+ b2Mat33() {}
+
+ /// Construct this matrix using columns.
+ b2Mat33(const b2Vec3& c1, const b2Vec3& c2, const b2Vec3& c3)
+ {
+ ex = c1;
+ ey = c2;
+ ez = c3;
+ }
+
+ /// Set this matrix to all zeros.
+ void SetZero()
+ {
+ ex.SetZero();
+ ey.SetZero();
+ ez.SetZero();
+ }
+
+ /// Solve A * x = b, where b is a column vector. This is more efficient
+ /// than computing the inverse in one-shot cases.
+ b2Vec3 Solve33(const b2Vec3& b) const;
+
+ /// Solve A * x = b, where b is a column vector. This is more efficient
+ /// than computing the inverse in one-shot cases. Solve only the upper
+ /// 2-by-2 matrix equation.
+ b2Vec2 Solve22(const b2Vec2& b) const;
+
+ /// Get the inverse of this matrix as a 2-by-2.
+ /// Returns the zero matrix if singular.
+ void GetInverse22(b2Mat33* M) const;
+
+ /// Get the symmetric inverse of this matrix as a 3-by-3.
+ /// Returns the zero matrix if singular.
+ void GetSymInverse33(b2Mat33* M) const;
+
+ b2Vec3 ex, ey, ez;
+};
+
+/// Rotation
+struct b2Rot
+{
+ b2Rot() {}
+
+ /// Initialize from an angle in radians
+ explicit b2Rot(float32 angle)
+ {
+ /// TODO_ERIN optimize
+ s = sinf(angle);
+ c = cosf(angle);
+ }
+
+ /// Set using an angle in radians.
+ void Set(float32 angle)
+ {
+ /// TODO_ERIN optimize
+ s = sinf(angle);
+ c = cosf(angle);
+ }
+
+ /// Set to the identity rotation
+ void SetIdentity()
+ {
+ s = 0.0f;
+ c = 1.0f;
+ }
+
+ /// Get the angle in radians
+ float32 GetAngle() const
+ {
+ return b2Atan2(s, c);
+ }
+
+ /// Get the x-axis
+ b2Vec2 GetXAxis() const
+ {
+ return b2Vec2(c, s);
+ }
+
+ /// Get the u-axis
+ b2Vec2 GetYAxis() const
+ {
+ return b2Vec2(-s, c);
+ }
+
+ /// Sine and cosine
+ float32 s, c;
+};
+
+/// A transform contains translation and rotation. It is used to represent
+/// the position and orientation of rigid frames.
+struct b2Transform
+{
+ /// The default constructor does nothing.
+ b2Transform() {}
+
+ /// Initialize using a position vector and a rotation.
+ b2Transform(const b2Vec2& position, const b2Rot& rotation) : p(position), q(rotation) {}
+
+ /// Set this to the identity transform.
+ void SetIdentity()
+ {
+ p.SetZero();
+ q.SetIdentity();
+ }
+
+ /// Set this based on the position and angle.
+ void Set(const b2Vec2& position, float32 angle)
+ {
+ p = position;
+ q.Set(angle);
+ }
+
+ b2Vec2 p;
+ b2Rot q;
+};
+
+/// This describes the motion of a body/shape for TOI computation.
+/// Shapes are defined with respect to the body origin, which may
+/// no coincide with the center of mass. However, to support dynamics
+/// we must interpolate the center of mass position.
+struct b2Sweep
+{
+ /// Get the interpolated transform at a specific time.
+ /// @param beta is a factor in [0,1], where 0 indicates alpha0.
+ void GetTransform(b2Transform* xfb, float32 beta) const;
+
+ /// Advance the sweep forward, yielding a new initial state.
+ /// @param alpha the new initial time.
+ void Advance(float32 alpha);
+
+ /// Normalize the angles.
+ void Normalize();
+
+ b2Vec2 localCenter; ///< local center of mass position
+ b2Vec2 c0, c; ///< center world positions
+ float32 a0, a; ///< world angles
+
+ /// Fraction of the current time step in the range [0,1]
+ /// c0 and a0 are the positions at alpha0.
+ float32 alpha0;
+};
+
+/// Useful constant
+extern const b2Vec2 b2Vec2_zero;
+
+/// Perform the dot product on two vectors.
+inline float32 b2Dot(const b2Vec2& a, const b2Vec2& b)
+{
+ return a.x * b.x + a.y * b.y;
+}
+
+/// Perform the cross product on two vectors. In 2D this produces a scalar.
+inline float32 b2Cross(const b2Vec2& a, const b2Vec2& b)
+{
+ return a.x * b.y - a.y * b.x;
+}
+
+/// Perform the cross product on a vector and a scalar. In 2D this produces
+/// a vector.
+inline b2Vec2 b2Cross(const b2Vec2& a, float32 s)
+{
+ return b2Vec2(s * a.y, -s * a.x);
+}
+
+/// Perform the cross product on a scalar and a vector. In 2D this produces
+/// a vector.
+inline b2Vec2 b2Cross(float32 s, const b2Vec2& a)
+{
+ return b2Vec2(-s * a.y, s * a.x);
+}
+
+/// Multiply a matrix times a vector. If a rotation matrix is provided,
+/// then this transforms the vector from one frame to another.
+inline b2Vec2 b2Mul(const b2Mat22& A, const b2Vec2& v)
+{
+ return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
+}
+
+/// Multiply a matrix transpose times a vector. If a rotation matrix is provided,
+/// then this transforms the vector from one frame to another (inverse transform).
+inline b2Vec2 b2MulT(const b2Mat22& A, const b2Vec2& v)
+{
+ return b2Vec2(b2Dot(v, A.ex), b2Dot(v, A.ey));
+}
+
+/// Add two vectors component-wise.
+inline b2Vec2 operator + (const b2Vec2& a, const b2Vec2& b)
+{
+ return b2Vec2(a.x + b.x, a.y + b.y);
+}
+
+/// Subtract two vectors component-wise.
+inline b2Vec2 operator - (const b2Vec2& a, const b2Vec2& b)
+{
+ return b2Vec2(a.x - b.x, a.y - b.y);
+}
+
+inline b2Vec2 operator * (float32 s, const b2Vec2& a)
+{
+ return b2Vec2(s * a.x, s * a.y);
+}
+
+inline bool operator == (const b2Vec2& a, const b2Vec2& b)
+{
+ return a.x == b.x && a.y == b.y;
+}
+
+inline float32 b2Distance(const b2Vec2& a, const b2Vec2& b)
+{
+ b2Vec2 c = a - b;
+ return c.Length();
+}
+
+inline float32 b2DistanceSquared(const b2Vec2& a, const b2Vec2& b)
+{
+ b2Vec2 c = a - b;
+ return b2Dot(c, c);
+}
+
+inline b2Vec3 operator * (float32 s, const b2Vec3& a)
+{
+ return b2Vec3(s * a.x, s * a.y, s * a.z);
+}
+
+/// Add two vectors component-wise.
+inline b2Vec3 operator + (const b2Vec3& a, const b2Vec3& b)
+{
+ return b2Vec3(a.x + b.x, a.y + b.y, a.z + b.z);
+}
+
+/// Subtract two vectors component-wise.
+inline b2Vec3 operator - (const b2Vec3& a, const b2Vec3& b)
+{
+ return b2Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
+}
+
+/// Perform the dot product on two vectors.
+inline float32 b2Dot(const b2Vec3& a, const b2Vec3& b)
+{
+ return a.x * b.x + a.y * b.y + a.z * b.z;
+}
+
+/// Perform the cross product on two vectors.
+inline b2Vec3 b2Cross(const b2Vec3& a, const b2Vec3& b)
+{
+ return b2Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
+}
+
+inline b2Mat22 operator + (const b2Mat22& A, const b2Mat22& B)
+{
+ return b2Mat22(A.ex + B.ex, A.ey + B.ey);
+}
+
+// A * B
+inline b2Mat22 b2Mul(const b2Mat22& A, const b2Mat22& B)
+{
+ return b2Mat22(b2Mul(A, B.ex), b2Mul(A, B.ey));
+}
+
+// A^T * B
+inline b2Mat22 b2MulT(const b2Mat22& A, const b2Mat22& B)
+{
+ b2Vec2 c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
+ b2Vec2 c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
+ return b2Mat22(c1, c2);
+}
+
+/// Multiply a matrix times a vector.
+inline b2Vec3 b2Mul(const b2Mat33& A, const b2Vec3& v)
+{
+ return v.x * A.ex + v.y * A.ey + v.z * A.ez;
+}
+
+/// Multiply a matrix times a vector.
+inline b2Vec2 b2Mul22(const b2Mat33& A, const b2Vec2& v)
+{
+ return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
+}
+
+/// Multiply two rotations: q * r
+inline b2Rot b2Mul(const b2Rot& q, const b2Rot& r)
+{
+ // [qc -qs] * [rc -rs] = [qc*rc-qs*rs -qc*rs-qs*rc]
+ // [qs qc] [rs rc] [qs*rc+qc*rs -qs*rs+qc*rc]
+ // s = qs * rc + qc * rs
+ // c = qc * rc - qs * rs
+ b2Rot qr;
+ qr.s = q.s * r.c + q.c * r.s;
+ qr.c = q.c * r.c - q.s * r.s;
+ return qr;
+}
+
+/// Transpose multiply two rotations: qT * r
+inline b2Rot b2MulT(const b2Rot& q, const b2Rot& r)
+{
+ // [ qc qs] * [rc -rs] = [qc*rc+qs*rs -qc*rs+qs*rc]
+ // [-qs qc] [rs rc] [-qs*rc+qc*rs qs*rs+qc*rc]
+ // s = qc * rs - qs * rc
+ // c = qc * rc + qs * rs
+ b2Rot qr;
+ qr.s = q.c * r.s - q.s * r.c;
+ qr.c = q.c * r.c + q.s * r.s;
+ return qr;
+}
+
+/// Rotate a vector
+inline b2Vec2 b2Mul(const b2Rot& q, const b2Vec2& v)
+{
+ return b2Vec2(q.c * v.x - q.s * v.y, q.s * v.x + q.c * v.y);
+}
+
+/// Inverse rotate a vector
+inline b2Vec2 b2MulT(const b2Rot& q, const b2Vec2& v)
+{
+ return b2Vec2(q.c * v.x + q.s * v.y, -q.s * v.x + q.c * v.y);
+}
+
+inline b2Vec2 b2Mul(const b2Transform& T, const b2Vec2& v)
+{
+ float32 x = (T.q.c * v.x - T.q.s * v.y) + T.p.x;
+ float32 y = (T.q.s * v.x + T.q.c * v.y) + T.p.y;
+
+ return b2Vec2(x, y);
+}
+
+inline b2Vec2 b2MulT(const b2Transform& T, const b2Vec2& v)
+{
+ float32 px = v.x - T.p.x;
+ float32 py = v.y - T.p.y;
+ float32 x = (T.q.c * px + T.q.s * py);
+ float32 y = (-T.q.s * px + T.q.c * py);
+
+ return b2Vec2(x, y);
+}
+
+// v2 = A.q.Rot(B.q.Rot(v1) + B.p) + A.p
+// = (A.q * B.q).Rot(v1) + A.q.Rot(B.p) + A.p
+inline b2Transform b2Mul(const b2Transform& A, const b2Transform& B)
+{
+ b2Transform C;
+ C.q = b2Mul(A.q, B.q);
+ C.p = b2Mul(A.q, B.p) + A.p;
+ return C;
+}
+
+// v2 = A.q' * (B.q * v1 + B.p - A.p)
+// = A.q' * B.q * v1 + A.q' * (B.p - A.p)
+inline b2Transform b2MulT(const b2Transform& A, const b2Transform& B)
+{
+ b2Transform C;
+ C.q = b2MulT(A.q, B.q);
+ C.p = b2MulT(A.q, B.p - A.p);
+ return C;
+}
+
+template <typename T>
+inline T b2Abs(T a)
+{
+ return a > T(0) ? a : -a;
+}
+
+inline b2Vec2 b2Abs(const b2Vec2& a)
+{
+ return b2Vec2(b2Abs(a.x), b2Abs(a.y));
+}
+
+inline b2Mat22 b2Abs(const b2Mat22& A)
+{
+ return b2Mat22(b2Abs(A.ex), b2Abs(A.ey));
+}
+
+template <typename T>
+inline T b2Min(T a, T b)
+{
+ return a < b ? a : b;
+}
+
+inline b2Vec2 b2Min(const b2Vec2& a, const b2Vec2& b)
+{
+ return b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
+}
+
+template <typename T>
+inline T b2Max(T a, T b)
+{
+ return a > b ? a : b;
+}
+
+inline b2Vec2 b2Max(const b2Vec2& a, const b2Vec2& b)
+{
+ return b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
+}
+
+template <typename T>
+inline T b2Clamp(T a, T low, T high)
+{
+ return b2Max(low, b2Min(a, high));
+}
+
+inline b2Vec2 b2Clamp(const b2Vec2& a, const b2Vec2& low, const b2Vec2& high)
+{
+ return b2Max(low, b2Min(a, high));
+}
+
+template<typename T> inline void b2Swap(T& a, T& b)
+{
+ T tmp = a;
+ a = b;
+ b = tmp;
+}
+
+/// "Next Largest Power of 2
+/// Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm
+/// that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with
+/// the same most significant 1 as x, but all 1's below it. Adding 1 to that value yields the next
+/// largest power of 2. For a 32-bit value:"
+inline uint32 b2NextPowerOfTwo(uint32 x)
+{
+ x |= (x >> 1);
+ x |= (x >> 2);
+ x |= (x >> 4);
+ x |= (x >> 8);
+ x |= (x >> 16);
+ return x + 1;
+}
+
+inline bool b2IsPowerOfTwo(uint32 x)
+{
+ bool result = x > 0 && (x & (x - 1)) == 0;
+ return result;
+}
+
+inline void b2Sweep::GetTransform(b2Transform* xf, float32 beta) const
+{
+ xf->p = (1.0f - beta) * c0 + beta * c;
+ float32 angle = (1.0f - beta) * a0 + beta * a;
+ xf->q.Set(angle);
+
+ // Shift to origin
+ xf->p -= b2Mul(xf->q, localCenter);
+}
+
+inline void b2Sweep::Advance(float32 alpha)
+{
+ b2Assert(alpha0 < 1.0f);
+ float32 beta = (alpha - alpha0) / (1.0f - alpha0);
+ c0 = (1.0f - beta) * c0 + beta * c;
+ a0 = (1.0f - beta) * a0 + beta * a;
+ alpha0 = alpha;
+}
+
+/// Normalize an angle in radians to be between -pi and pi
+inline void b2Sweep::Normalize()
+{
+ float32 twoPi = 2.0f * b2_pi;
+ float32 d = twoPi * floorf(a0 / twoPi);
+ a0 -= d;
+ a -= d;
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Common/b2Settings.cpp b/engines/ngi/box2d/Common/b2Settings.cpp
new file mode 100644
index 00000000000..c136153e6cb
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2Settings.cpp
@@ -0,0 +1,48 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Common/b2Settings.h"
+#include <cstdlib>
+#include <cstdio>
+#include <cstdarg>
+
+namespace NGI {
+
+b2Version b2_version = {2, 2, 1};
+
+// Memory allocators. Modify these to use your own allocator.
+void* b2Alloc(int32 size)
+{
+ return malloc(size);
+}
+
+void b2Free(void* mem)
+{
+ free(mem);
+}
+
+// You can modify this to use your logging facility.
+void b2Log(const char* string, ...)
+{
+ va_list args;
+ va_start(args, string);
+ vprintf(string, args);
+ va_end(args);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Common/b2Settings.h b/engines/ngi/box2d/Common/b2Settings.h
new file mode 100644
index 00000000000..4b1d2d2564d
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2Settings.h
@@ -0,0 +1,154 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_SETTINGS_H
+#define B2_SETTINGS_H
+
+#include <cassert>
+#include <cmath>
+
+namespace NGI {
+
+#define B2_NOT_USED(x) ((void)(x))
+#define b2Assert(A) assert(A)
+
+typedef signed char int8;
+typedef signed short int16;
+typedef signed int int32;
+typedef unsigned char uint8;
+typedef unsigned short uint16;
+typedef unsigned int uint32;
+typedef float float32;
+typedef double float64;
+
+#define b2_maxFloat FLT_MAX
+#define b2_epsilon FLT_EPSILON
+#define b2_pi 3.14159265359f
+
+/// @file
+/// Global tuning constants based on meters-kilograms-seconds (MKS) units.
+///
+
+// Collision
+
+/// The maximum number of contact points between two convex shapes. Do
+/// not change this value.
+#define b2_maxManifoldPoints 2
+
+/// The maximum number of vertices on a convex polygon. You cannot increase
+/// this too much because b2BlockAllocator has a maximum object size.
+#define b2_maxPolygonVertices 8
+
+/// This is used to fatten AABBs in the dynamic tree. This allows proxies
+/// to move by a small amount without triggering a tree adjustment.
+/// This is in meters.
+#define b2_aabbExtension 0.1f
+
+/// This is used to fatten AABBs in the dynamic tree. This is used to predict
+/// the future position based on the current displacement.
+/// This is a dimensionless multiplier.
+#define b2_aabbMultiplier 2.0f
+
+/// A small length used as a collision and constraint tolerance. Usually it is
+/// chosen to be numerically significant, but visually insignificant.
+#define b2_linearSlop 0.005f
+
+/// A small angle used as a collision and constraint tolerance. Usually it is
+/// chosen to be numerically significant, but visually insignificant.
+#define b2_angularSlop (2.0f / 180.0f * b2_pi)
+
+/// The radius of the polygon/edge shape skin. This should not be modified. Making
+/// this smaller means polygons will have an insufficient buffer for continuous collision.
+/// Making it larger may create artifacts for vertex collision.
+#define b2_polygonRadius (2.0f * b2_linearSlop)
+
+/// Maximum number of sub-steps per contact in continuous physics simulation.
+#define b2_maxSubSteps 8
+
+
+// Dynamics
+
+/// Maximum number of contacts to be handled to solve a TOI impact.
+#define b2_maxTOIContacts 32
+
+/// A velocity threshold for elastic collisions. Any collision with a relative linear
+/// velocity below this threshold will be treated as inelastic.
+#define b2_velocityThreshold 1.0f
+
+/// The maximum linear position correction used when solving constraints. This helps to
+/// prevent overshoot.
+#define b2_maxLinearCorrection 0.2f
+
+/// The maximum angular position correction used when solving constraints. This helps to
+/// prevent overshoot.
+#define b2_maxAngularCorrection (8.0f / 180.0f * b2_pi)
+
+/// The maximum linear velocity of a body. This limit is very large and is used
+/// to prevent numerical problems. You shouldn't need to adjust this.
+#define b2_maxTranslation 2.0f
+#define b2_maxTranslationSquared (b2_maxTranslation * b2_maxTranslation)
+
+/// The maximum angular velocity of a body. This limit is very large and is used
+/// to prevent numerical problems. You shouldn't need to adjust this.
+#define b2_maxRotation (0.5f * b2_pi)
+#define b2_maxRotationSquared (b2_maxRotation * b2_maxRotation)
+
+/// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
+/// that overlap is removed in one time step. However using values close to 1 often lead
+/// to overshoot.
+#define b2_baumgarte 0.2f
+#define b2_toiBaugarte 0.75f
+
+
+// Sleep
+
+/// The time that a body must be still before it will go to sleep.
+#define b2_timeToSleep 0.5f
+
+/// A body cannot sleep if its linear velocity is above this tolerance.
+#define b2_linearSleepTolerance 0.01f
+
+/// A body cannot sleep if its angular velocity is above this tolerance.
+#define b2_angularSleepTolerance (2.0f / 180.0f * b2_pi)
+
+// Memory Allocation
+
+/// Implement this function to use your own memory allocator.
+void* b2Alloc(int32 size);
+
+/// If you implement b2Alloc, you should also implement this function.
+void b2Free(void* mem);
+
+/// Logging function.
+void b2Log(const char* string, ...);
+
+/// Version numbering scheme.
+/// See http://en.wikipedia.org/wiki/Software_versioning
+struct b2Version
+{
+ int32 major; ///< significant changes
+ int32 minor; ///< incremental changes
+ int32 revision; ///< bug fixes
+};
+
+/// Current version.
+extern b2Version b2_version;
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Common/b2StackAllocator.cpp b/engines/ngi/box2d/Common/b2StackAllocator.cpp
new file mode 100644
index 00000000000..2ece9f2682d
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2StackAllocator.cpp
@@ -0,0 +1,87 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Common/b2StackAllocator.h"
+#include "engines/ngi/box2d/Common/b2Math.h"
+
+namespace NGI {
+
+b2StackAllocator::b2StackAllocator()
+{
+ m_index = 0;
+ m_allocation = 0;
+ m_maxAllocation = 0;
+ m_entryCount = 0;
+}
+
+b2StackAllocator::~b2StackAllocator()
+{
+ b2Assert(m_index == 0);
+ b2Assert(m_entryCount == 0);
+}
+
+void* b2StackAllocator::Allocate(int32 size)
+{
+ b2Assert(m_entryCount < b2_maxStackEntries);
+
+ b2StackEntry* entry = m_entries + m_entryCount;
+ entry->size = size;
+ if (m_index + size > b2_stackSize)
+ {
+ entry->data = (char*)b2Alloc(size);
+ entry->usedMalloc = true;
+ }
+ else
+ {
+ entry->data = m_data + m_index;
+ entry->usedMalloc = false;
+ m_index += size;
+ }
+
+ m_allocation += size;
+ m_maxAllocation = b2Max(m_maxAllocation, m_allocation);
+ ++m_entryCount;
+
+ return entry->data;
+}
+
+void b2StackAllocator::Free(void* p)
+{
+ b2Assert(m_entryCount > 0);
+ b2StackEntry* entry = m_entries + m_entryCount - 1;
+ b2Assert(p == entry->data);
+ if (entry->usedMalloc)
+ {
+ b2Free(p);
+ }
+ else
+ {
+ m_index -= entry->size;
+ }
+ m_allocation -= entry->size;
+ --m_entryCount;
+
+ p = NULL;
+}
+
+int32 b2StackAllocator::GetMaxAllocation() const
+{
+ return m_maxAllocation;
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Common/b2StackAllocator.h b/engines/ngi/box2d/Common/b2StackAllocator.h
new file mode 100644
index 00000000000..5715e45bb48
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2StackAllocator.h
@@ -0,0 +1,64 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_STACK_ALLOCATOR_H
+#define B2_STACK_ALLOCATOR_H
+
+#include "engines/ngi/box2d/Common/b2Settings.h"
+
+namespace NGI {
+
+const int32 b2_stackSize = 100 * 1024; // 100k
+const int32 b2_maxStackEntries = 32;
+
+struct b2StackEntry
+{
+ char* data;
+ int32 size;
+ bool usedMalloc;
+};
+
+// This is a stack allocator used for fast per step allocations.
+// You must nest allocate/free pairs. The code will assert
+// if you try to interleave multiple allocate/free pairs.
+class b2StackAllocator
+{
+public:
+ b2StackAllocator();
+ ~b2StackAllocator();
+
+ void* Allocate(int32 size);
+ void Free(void* p);
+
+ int32 GetMaxAllocation() const;
+
+private:
+
+ char m_data[b2_stackSize];
+ int32 m_index;
+
+ int32 m_allocation;
+ int32 m_maxAllocation;
+
+ b2StackEntry m_entries[b2_maxStackEntries];
+ int32 m_entryCount;
+};
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Common/b2Timer.cpp b/engines/ngi/box2d/Common/b2Timer.cpp
new file mode 100644
index 00000000000..b5f7a16d6dc
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2Timer.cpp
@@ -0,0 +1,106 @@
+/*
+* Copyright (c) 2011 Erin Catto http://box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Common/b2Timer.h"
+
+#if defined(_WIN32)
+#include <windows.h>
+#elif defined(__linux__) || defined (__APPLE__)
+#include <sys/time.h>
+#endif
+
+namespace NGI {
+
+#if defined(_WIN32)
+
+float64 b2Timer::s_invFrequency = 0.0f;
+
+b2Timer::b2Timer()
+{
+ LARGE_INTEGER largeInteger;
+
+ if (s_invFrequency == 0.0f)
+ {
+ QueryPerformanceFrequency(&largeInteger);
+ s_invFrequency = float64(largeInteger.QuadPart);
+ if (s_invFrequency > 0.0f)
+ {
+ s_invFrequency = 1000.0f / s_invFrequency;
+ }
+ }
+
+ QueryPerformanceCounter(&largeInteger);
+ m_start = float64(largeInteger.QuadPart);
+}
+
+void b2Timer::Reset()
+{
+ LARGE_INTEGER largeInteger;
+ QueryPerformanceCounter(&largeInteger);
+ m_start = float64(largeInteger.QuadPart);
+}
+
+float32 b2Timer::GetMilliseconds() const
+{
+ LARGE_INTEGER largeInteger;
+ QueryPerformanceCounter(&largeInteger);
+ float64 count = float64(largeInteger.QuadPart);
+ float32 ms = float32(s_invFrequency * (count - m_start));
+ return ms;
+}
+
+#elif defined(__linux__) || defined (__APPLE__)
+
+b2Timer::b2Timer()
+{
+ Reset();
+}
+
+void b2Timer::Reset()
+{
+ timeval t;
+ gettimeofday(&t, 0);
+ m_start_sec = t.tv_sec;
+ m_start_msec = t.tv_usec * 0.001f;
+}
+
+float32 b2Timer::GetMilliseconds() const
+{
+ timeval t;
+ gettimeofday(&t, 0);
+ return (t.tv_sec - m_start_sec) * 1000 + t.tv_usec * 0.001f - m_start_msec;
+}
+
+#else
+
+b2Timer::b2Timer()
+{
+}
+
+void b2Timer::Reset()
+{
+}
+
+float32 b2Timer::GetMilliseconds() const
+{
+ return 0.0f;
+}
+
+#endif
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Common/b2Timer.h b/engines/ngi/box2d/Common/b2Timer.h
new file mode 100644
index 00000000000..fdd52431e17
--- /dev/null
+++ b/engines/ngi/box2d/Common/b2Timer.h
@@ -0,0 +1,49 @@
+/*
+* Copyright (c) 2011 Erin Catto http://box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Common/b2Settings.h"
+
+namespace NGI {
+
+/// Timer for profiling. This has platform specific code and may
+/// not work on every platform.
+class b2Timer
+{
+public:
+
+ /// Constructor
+ b2Timer();
+
+ /// Reset the timer.
+ void Reset();
+
+ /// Get the time since construction or the last reset.
+ float32 GetMilliseconds() const;
+
+private:
+
+#if defined(_WIN32)
+ float64 m_start;
+ static float64 s_invFrequency;
+#elif defined(__linux__) || defined (__APPLE__)
+ unsigned long m_start_sec;
+ unsigned long m_start_msec;
+#endif
+};
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.cpp b/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.cpp
new file mode 100644
index 00000000000..55ed8602bd1
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.cpp
@@ -0,0 +1,58 @@
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.h"
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2ChainShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h"
+
+#include <new>
+
+namespace NGI {
+using namespace std;
+
+b2Contact* b2ChainAndCircleContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator)
+{
+ void* mem = allocator->Allocate(sizeof(b2ChainAndCircleContact));
+ return new (mem) b2ChainAndCircleContact(fixtureA, indexA, fixtureB, indexB);
+}
+
+void b2ChainAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
+{
+ ((b2ChainAndCircleContact*)contact)->~b2ChainAndCircleContact();
+ allocator->Free(contact, sizeof(b2ChainAndCircleContact));
+}
+
+b2ChainAndCircleContact::b2ChainAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB)
+: b2Contact(fixtureA, indexA, fixtureB, indexB)
+{
+ b2Assert(m_fixtureA->GetType() == b2Shape::e_chain);
+ b2Assert(m_fixtureB->GetType() == b2Shape::e_circle);
+}
+
+void b2ChainAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)
+{
+ b2ChainShape* chain = (b2ChainShape*)m_fixtureA->GetShape();
+ b2EdgeShape edge;
+ chain->GetChildEdge(&edge, m_indexA);
+ b2CollideEdgeAndCircle( manifold, &edge, xfA,
+ (b2CircleShape*)m_fixtureB->GetShape(), xfB);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.h b/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.h
new file mode 100644
index 00000000000..4a327ec348b
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.h
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_CHAIN_AND_CIRCLE_CONTACT_H
+#define B2_CHAIN_AND_CIRCLE_CONTACT_H
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2Contact.h"
+
+namespace NGI {
+
+class b2BlockAllocator;
+
+class b2ChainAndCircleContact : public b2Contact
+{
+public:
+ static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
+ b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
+ static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
+
+ b2ChainAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);
+ ~b2ChainAndCircleContact() {}
+
+ void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
+};
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.cpp b/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.cpp
new file mode 100644
index 00000000000..95fbc5aa648
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.cpp
@@ -0,0 +1,58 @@
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.h"
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2ChainShape.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2EdgeShape.h"
+
+#include <new>
+
+namespace NGI {
+using namespace std;
+
+b2Contact* b2ChainAndPolygonContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator)
+{
+ void* mem = allocator->Allocate(sizeof(b2ChainAndPolygonContact));
+ return new (mem) b2ChainAndPolygonContact(fixtureA, indexA, fixtureB, indexB);
+}
+
+void b2ChainAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
+{
+ ((b2ChainAndPolygonContact*)contact)->~b2ChainAndPolygonContact();
+ allocator->Free(contact, sizeof(b2ChainAndPolygonContact));
+}
+
+b2ChainAndPolygonContact::b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB)
+: b2Contact(fixtureA, indexA, fixtureB, indexB)
+{
+ b2Assert(m_fixtureA->GetType() == b2Shape::e_chain);
+ b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon);
+}
+
+void b2ChainAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)
+{
+ b2ChainShape* chain = (b2ChainShape*)m_fixtureA->GetShape();
+ b2EdgeShape edge;
+ chain->GetChildEdge(&edge, m_indexA);
+ b2CollideEdgeAndPolygon( manifold, &edge, xfA,
+ (b2PolygonShape*)m_fixtureB->GetShape(), xfB);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.h b/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.h
new file mode 100644
index 00000000000..9e806e2fe95
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.h
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_CHAIN_AND_POLYGON_CONTACT_H
+#define B2_CHAIN_AND_POLYGON_CONTACT_H
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2Contact.h"
+
+namespace NGI {
+
+class b2BlockAllocator;
+
+class b2ChainAndPolygonContact : public b2Contact
+{
+public:
+ static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
+ b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
+ static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
+
+ b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);
+ ~b2ChainAndPolygonContact() {}
+
+ void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
+};
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.cpp b/engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.cpp
new file mode 100644
index 00000000000..ec6df780593
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.cpp
@@ -0,0 +1,57 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.h"
+#include "engines/ngi/box2d/Dynamics/b2Body.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+#include "engines/ngi/box2d/Dynamics/b2WorldCallbacks.h"
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include "engines/ngi/box2d/Collision/b2TimeOfImpact.h"
+
+#include <new>
+
+namespace NGI {
+using namespace std;
+
+b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)
+{
+ void* mem = allocator->Allocate(sizeof(b2CircleContact));
+ return new (mem) b2CircleContact(fixtureA, fixtureB);
+}
+
+void b2CircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
+{
+ ((b2CircleContact*)contact)->~b2CircleContact();
+ allocator->Free(contact, sizeof(b2CircleContact));
+}
+
+b2CircleContact::b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB)
+ : b2Contact(fixtureA, 0, fixtureB, 0)
+{
+ b2Assert(m_fixtureA->GetType() == b2Shape::e_circle);
+ b2Assert(m_fixtureB->GetType() == b2Shape::e_circle);
+}
+
+void b2CircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)
+{
+ b2CollideCircles(manifold,
+ (b2CircleShape*)m_fixtureA->GetShape(), xfA,
+ (b2CircleShape*)m_fixtureB->GetShape(), xfB);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.h b/engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.h
new file mode 100644
index 00000000000..ec53b4241f0
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.h
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_CIRCLE_CONTACT_H
+#define B2_CIRCLE_CONTACT_H
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2Contact.h"
+
+namespace NGI {
+
+class b2BlockAllocator;
+
+class b2CircleContact : public b2Contact
+{
+public:
+ static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
+ b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
+ static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
+
+ b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB);
+ ~b2CircleContact() {}
+
+ void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
+};
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2Contact.cpp b/engines/ngi/box2d/Dynamics/Contacts/b2Contact.cpp
new file mode 100644
index 00000000000..f95c78775fa
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2Contact.cpp
@@ -0,0 +1,244 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2Contact.h"
+#include "engines/ngi/box2d/Dynamics/Contacts/b2CircleContact.h"
+#include "engines/ngi/box2d/Dynamics/Contacts/b2PolygonAndCircleContact.h"
+#include "engines/ngi/box2d/Dynamics/Contacts/b2PolygonContact.h"
+#include "engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.h"
+#include "engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.h"
+#include "engines/ngi/box2d/Dynamics/Contacts/b2ChainAndCircleContact.h"
+#include "engines/ngi/box2d/Dynamics/Contacts/b2ChainAndPolygonContact.h"
+#include "engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.h"
+
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Collision/b2TimeOfImpact.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2Shape.h"
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include "engines/ngi/box2d/Dynamics/b2Body.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+#include "engines/ngi/box2d/Dynamics/b2World.h"
+
+namespace NGI {
+
+b2ContactRegister b2Contact::s_registers[b2Shape::e_typeCount][b2Shape::e_typeCount];
+bool b2Contact::s_initialized = false;
+
+void b2Contact::InitializeRegisters()
+{
+ AddType(b2CircleContact::Create, b2CircleContact::Destroy, b2Shape::e_circle, b2Shape::e_circle);
+ AddType(b2PolygonAndCircleContact::Create, b2PolygonAndCircleContact::Destroy, b2Shape::e_polygon, b2Shape::e_circle);
+ AddType(b2PolygonContact::Create, b2PolygonContact::Destroy, b2Shape::e_polygon, b2Shape::e_polygon);
+ AddType(b2EdgeAndCircleContact::Create, b2EdgeAndCircleContact::Destroy, b2Shape::e_edge, b2Shape::e_circle);
+ AddType(b2EdgeAndPolygonContact::Create, b2EdgeAndPolygonContact::Destroy, b2Shape::e_edge, b2Shape::e_polygon);
+ AddType(b2ChainAndCircleContact::Create, b2ChainAndCircleContact::Destroy, b2Shape::e_chain, b2Shape::e_circle);
+ AddType(b2ChainAndPolygonContact::Create, b2ChainAndPolygonContact::Destroy, b2Shape::e_chain, b2Shape::e_polygon);
+}
+
+void b2Contact::AddType(b2ContactCreateFcn* createFcn, b2ContactDestroyFcn* destoryFcn,
+ b2Shape::Type type1, b2Shape::Type type2)
+{
+ b2Assert(0 <= type1 && type1 < b2Shape::e_typeCount);
+ b2Assert(0 <= type2 && type2 < b2Shape::e_typeCount);
+
+ s_registers[type1][type2].createFcn = createFcn;
+ s_registers[type1][type2].destroyFcn = destoryFcn;
+ s_registers[type1][type2].primary = true;
+
+ if (type1 != type2)
+ {
+ s_registers[type2][type1].createFcn = createFcn;
+ s_registers[type2][type1].destroyFcn = destoryFcn;
+ s_registers[type2][type1].primary = false;
+ }
+}
+
+b2Contact* b2Contact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator)
+{
+ if (s_initialized == false)
+ {
+ InitializeRegisters();
+ s_initialized = true;
+ }
+
+ b2Shape::Type type1 = fixtureA->GetType();
+ b2Shape::Type type2 = fixtureB->GetType();
+
+ b2Assert(0 <= type1 && type1 < b2Shape::e_typeCount);
+ b2Assert(0 <= type2 && type2 < b2Shape::e_typeCount);
+
+ b2ContactCreateFcn* createFcn = s_registers[type1][type2].createFcn;
+ if (createFcn)
+ {
+ if (s_registers[type1][type2].primary)
+ {
+ return createFcn(fixtureA, indexA, fixtureB, indexB, allocator);
+ }
+ else
+ {
+ return createFcn(fixtureB, indexB, fixtureA, indexA, allocator);
+ }
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+void b2Contact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
+{
+ b2Assert(s_initialized == true);
+
+ if (contact->m_manifold.pointCount > 0)
+ {
+ contact->GetFixtureA()->GetBody()->SetAwake(true);
+ contact->GetFixtureB()->GetBody()->SetAwake(true);
+ }
+
+ b2Shape::Type typeA = contact->GetFixtureA()->GetType();
+ b2Shape::Type typeB = contact->GetFixtureB()->GetType();
+
+ b2Assert(0 <= typeA && typeB < b2Shape::e_typeCount);
+ b2Assert(0 <= typeA && typeB < b2Shape::e_typeCount);
+
+ b2ContactDestroyFcn* destroyFcn = s_registers[typeA][typeB].destroyFcn;
+ destroyFcn(contact, allocator);
+}
+
+b2Contact::b2Contact(b2Fixture* fA, int32 indexA, b2Fixture* fB, int32 indexB)
+{
+ m_flags = e_enabledFlag;
+
+ m_fixtureA = fA;
+ m_fixtureB = fB;
+
+ m_indexA = indexA;
+ m_indexB = indexB;
+
+ m_manifold.pointCount = 0;
+
+ m_prev = NULL;
+ m_next = NULL;
+
+ m_nodeA.contact = NULL;
+ m_nodeA.prev = NULL;
+ m_nodeA.next = NULL;
+ m_nodeA.other = NULL;
+
+ m_nodeB.contact = NULL;
+ m_nodeB.prev = NULL;
+ m_nodeB.next = NULL;
+ m_nodeB.other = NULL;
+
+ m_toiCount = 0;
+
+ m_friction = b2MixFriction(m_fixtureA->m_friction, m_fixtureB->m_friction);
+ m_restitution = b2MixRestitution(m_fixtureA->m_restitution, m_fixtureB->m_restitution);
+}
+
+// Update the contact manifold and touching status.
+// Note: do not assume the fixture AABBs are overlapping or are valid.
+void b2Contact::Update(b2ContactListener* listener)
+{
+ b2Manifold oldManifold = m_manifold;
+
+ // Re-enable this contact.
+ m_flags |= e_enabledFlag;
+
+ bool touching = false;
+ bool wasTouching = (m_flags & e_touchingFlag) == e_touchingFlag;
+
+ bool sensorA = m_fixtureA->IsSensor();
+ bool sensorB = m_fixtureB->IsSensor();
+ bool sensor = sensorA || sensorB;
+
+ b2Body* bodyA = m_fixtureA->GetBody();
+ b2Body* bodyB = m_fixtureB->GetBody();
+ const b2Transform& xfA = bodyA->GetTransform();
+ const b2Transform& xfB = bodyB->GetTransform();
+
+ // Is this contact a sensor?
+ if (sensor)
+ {
+ const b2Shape* shapeA = m_fixtureA->GetShape();
+ const b2Shape* shapeB = m_fixtureB->GetShape();
+ touching = b2TestOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB);
+
+ // Sensors don't generate manifolds.
+ m_manifold.pointCount = 0;
+ }
+ else
+ {
+ Evaluate(&m_manifold, xfA, xfB);
+ touching = m_manifold.pointCount > 0;
+
+ // Match old contact ids to new contact ids and copy the
+ // stored impulses to warm start the solver.
+ for (int32 i = 0; i < m_manifold.pointCount; ++i)
+ {
+ b2ManifoldPoint* mp2 = m_manifold.points + i;
+ mp2->normalImpulse = 0.0f;
+ mp2->tangentImpulse = 0.0f;
+ b2ContactID id2 = mp2->id;
+
+ for (int32 j = 0; j < oldManifold.pointCount; ++j)
+ {
+ b2ManifoldPoint* mp1 = oldManifold.points + j;
+
+ if (mp1->id.key == id2.key)
+ {
+ mp2->normalImpulse = mp1->normalImpulse;
+ mp2->tangentImpulse = mp1->tangentImpulse;
+ break;
+ }
+ }
+ }
+
+ if (touching != wasTouching)
+ {
+ bodyA->SetAwake(true);
+ bodyB->SetAwake(true);
+ }
+ }
+
+ if (touching)
+ {
+ m_flags |= e_touchingFlag;
+ }
+ else
+ {
+ m_flags &= ~e_touchingFlag;
+ }
+
+ if (wasTouching == false && touching == true && listener)
+ {
+ listener->BeginContact(this);
+ }
+
+ if (wasTouching == true && touching == false && listener)
+ {
+ listener->EndContact(this);
+ }
+
+ if (sensor == false && touching && listener)
+ {
+ listener->PreSolve(this, &oldManifold);
+ }
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2Contact.h b/engines/ngi/box2d/Dynamics/Contacts/b2Contact.h
new file mode 100644
index 00000000000..162e8ea2a13
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2Contact.h
@@ -0,0 +1,335 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_CONTACT_H
+#define B2_CONTACT_H
+
+#include "engines/ngi/box2d/Common/b2Math.h"
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Collision/Shapes/b2Shape.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+
+namespace NGI {
+
+class b2Body;
+class b2Contact;
+class b2Fixture;
+class b2World;
+class b2BlockAllocator;
+class b2StackAllocator;
+class b2ContactListener;
+
+/// Friction mixing law. The idea is to allow either fixture to drive the restitution to zero.
+/// For example, anything slides on ice.
+inline float32 b2MixFriction(float32 friction1, float32 friction2)
+{
+ return std::sqrt(friction1 * friction2);
+}
+
+/// Restitution mixing law. The idea is allow for anything to bounce off an inelastic surface.
+/// For example, a superball bounces on anything.
+inline float32 b2MixRestitution(float32 restitution1, float32 restitution2)
+{
+ return restitution1 > restitution2 ? restitution1 : restitution2;
+}
+
+typedef b2Contact* b2ContactCreateFcn( b2Fixture* fixtureA, int32 indexA,
+ b2Fixture* fixtureB, int32 indexB,
+ b2BlockAllocator* allocator);
+typedef void b2ContactDestroyFcn(b2Contact* contact, b2BlockAllocator* allocator);
+
+struct b2ContactRegister
+{
+ b2ContactCreateFcn* createFcn;
+ b2ContactDestroyFcn* destroyFcn;
+ bool primary;
+};
+
+/// A contact edge is used to connect bodies and contacts together
+/// in a contact graph where each body is a node and each contact
+/// is an edge. A contact edge belongs to a doubly linked list
+/// maintained in each attached body. Each contact has two contact
+/// nodes, one for each attached body.
+struct b2ContactEdge
+{
+ b2Body* other; ///< provides quick access to the other body attached.
+ b2Contact* contact; ///< the contact
+ b2ContactEdge* prev; ///< the previous contact edge in the body's contact list
+ b2ContactEdge* next; ///< the next contact edge in the body's contact list
+};
+
+/// The class manages contact between two shapes. A contact exists for each overlapping
+/// AABB in the broad-phase (except if filtered). Therefore a contact object may exist
+/// that has no contact points.
+class b2Contact
+{
+public:
+
+ /// Get the contact manifold. Do not modify the manifold unless you understand the
+ /// internals of Box2D.
+ b2Manifold* GetManifold();
+ const b2Manifold* GetManifold() const;
+
+ /// Get the world manifold.
+ void GetWorldManifold(b2WorldManifold* worldManifold) const;
+
+ /// Is this contact touching?
+ bool IsTouching() const;
+
+ /// Enable/disable this contact. This can be used inside the pre-solve
+ /// contact listener. The contact is only disabled for the current
+ /// time step (or sub-step in continuous collisions).
+ void SetEnabled(bool flag);
+
+ /// Has this contact been disabled?
+ bool IsEnabled() const;
+
+ /// Get the next contact in the world's contact list.
+ b2Contact* GetNext();
+ const b2Contact* GetNext() const;
+
+ /// Get fixture A in this contact.
+ b2Fixture* GetFixtureA();
+ const b2Fixture* GetFixtureA() const;
+
+ /// Get the child primitive index for fixture A.
+ int32 GetChildIndexA() const;
+
+ /// Get fixture B in this contact.
+ b2Fixture* GetFixtureB();
+ const b2Fixture* GetFixtureB() const;
+
+ /// Get the child primitive index for fixture B.
+ int32 GetChildIndexB() const;
+
+ /// Override the default friction mixture. You can call this in b2ContactListener::PreSolve.
+ /// This value persists until set or reset.
+ void SetFriction(float32 friction);
+
+ /// Get the friction.
+ float32 GetFriction() const;
+
+ /// Reset the friction mixture to the default value.
+ void ResetFriction();
+
+ /// Override the default restitution mixture. You can call this in b2ContactListener::PreSolve.
+ /// The value persists until you set or reset.
+ void SetRestitution(float32 restitution);
+
+ /// Get the restitution.
+ float32 GetRestitution() const;
+
+ /// Reset the restitution to the default value.
+ void ResetRestitution();
+
+ /// Evaluate this contact with your own manifold and transforms.
+ virtual void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) = 0;
+
+protected:
+ friend class b2ContactManager;
+ friend class b2World;
+ friend class b2ContactSolver;
+ friend class b2Body;
+ friend class b2Fixture;
+
+ // Flags stored in m_flags
+ enum
+ {
+ // Used when crawling contact graph when forming islands.
+ e_islandFlag = 0x0001,
+
+ // Set when the shapes are touching.
+ e_touchingFlag = 0x0002,
+
+ // This contact can be disabled (by user)
+ e_enabledFlag = 0x0004,
+
+ // This contact needs filtering because a fixture filter was changed.
+ e_filterFlag = 0x0008,
+
+ // This bullet contact had a TOI event
+ e_bulletHitFlag = 0x0010,
+
+ // This contact has a valid TOI in m_toi
+ e_toiFlag = 0x0020
+ };
+
+ /// Flag this contact for filtering. Filtering will occur the next time step.
+ void FlagForFiltering();
+
+ static void AddType(b2ContactCreateFcn* createFcn, b2ContactDestroyFcn* destroyFcn,
+ b2Shape::Type typeA, b2Shape::Type typeB);
+ static void InitializeRegisters();
+ static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
+ static void Destroy(b2Contact* contact, b2Shape::Type typeA, b2Shape::Type typeB, b2BlockAllocator* allocator);
+ static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
+
+ b2Contact() : m_fixtureA(NULL), m_fixtureB(NULL) {}
+ b2Contact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);
+ virtual ~b2Contact() {}
+
+ void Update(b2ContactListener* listener);
+
+ static b2ContactRegister s_registers[b2Shape::e_typeCount][b2Shape::e_typeCount];
+ static bool s_initialized;
+
+ uint32 m_flags;
+
+ // World pool and list pointers.
+ b2Contact* m_prev;
+ b2Contact* m_next;
+
+ // Nodes for connecting bodies.
+ b2ContactEdge m_nodeA;
+ b2ContactEdge m_nodeB;
+
+ b2Fixture* m_fixtureA;
+ b2Fixture* m_fixtureB;
+
+ int32 m_indexA;
+ int32 m_indexB;
+
+ b2Manifold m_manifold;
+
+ int32 m_toiCount;
+ float32 m_toi;
+
+ float32 m_friction;
+ float32 m_restitution;
+};
+
+inline b2Manifold* b2Contact::GetManifold()
+{
+ return &m_manifold;
+}
+
+inline const b2Manifold* b2Contact::GetManifold() const
+{
+ return &m_manifold;
+}
+
+inline void b2Contact::GetWorldManifold(b2WorldManifold* worldManifold) const
+{
+ const b2Body* bodyA = m_fixtureA->GetBody();
+ const b2Body* bodyB = m_fixtureB->GetBody();
+ const b2Shape* shapeA = m_fixtureA->GetShape();
+ const b2Shape* shapeB = m_fixtureB->GetShape();
+
+ worldManifold->Initialize(&m_manifold, bodyA->GetTransform(), shapeA->m_radius, bodyB->GetTransform(), shapeB->m_radius);
+}
+
+inline void b2Contact::SetEnabled(bool flag)
+{
+ if (flag)
+ {
+ m_flags |= e_enabledFlag;
+ }
+ else
+ {
+ m_flags &= ~e_enabledFlag;
+ }
+}
+
+inline bool b2Contact::IsEnabled() const
+{
+ return (m_flags & e_enabledFlag) == e_enabledFlag;
+}
+
+inline bool b2Contact::IsTouching() const
+{
+ return (m_flags & e_touchingFlag) == e_touchingFlag;
+}
+
+inline b2Contact* b2Contact::GetNext()
+{
+ return m_next;
+}
+
+inline const b2Contact* b2Contact::GetNext() const
+{
+ return m_next;
+}
+
+inline b2Fixture* b2Contact::GetFixtureA()
+{
+ return m_fixtureA;
+}
+
+inline const b2Fixture* b2Contact::GetFixtureA() const
+{
+ return m_fixtureA;
+}
+
+inline b2Fixture* b2Contact::GetFixtureB()
+{
+ return m_fixtureB;
+}
+
+inline int32 b2Contact::GetChildIndexA() const
+{
+ return m_indexA;
+}
+
+inline const b2Fixture* b2Contact::GetFixtureB() const
+{
+ return m_fixtureB;
+}
+
+inline int32 b2Contact::GetChildIndexB() const
+{
+ return m_indexB;
+}
+
+inline void b2Contact::FlagForFiltering()
+{
+ m_flags |= e_filterFlag;
+}
+
+inline void b2Contact::SetFriction(float32 friction)
+{
+ m_friction = friction;
+}
+
+inline float32 b2Contact::GetFriction() const
+{
+ return m_friction;
+}
+
+inline void b2Contact::ResetFriction()
+{
+ m_friction = b2MixFriction(m_fixtureA->m_friction, m_fixtureB->m_friction);
+}
+
+inline void b2Contact::SetRestitution(float32 restitution)
+{
+ m_restitution = restitution;
+}
+
+inline float32 b2Contact::GetRestitution() const
+{
+ return m_restitution;
+}
+
+inline void b2Contact::ResetRestitution()
+{
+ m_restitution = b2MixRestitution(m_fixtureA->m_restitution, m_fixtureB->m_restitution);
+}
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.cpp b/engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.cpp
new file mode 100644
index 00000000000..07609c3aff4
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.cpp
@@ -0,0 +1,836 @@
+/*
+* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.h"
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2Contact.h"
+#include "engines/ngi/box2d/Dynamics/b2Body.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+#include "engines/ngi/box2d/Dynamics/b2World.h"
+#include "engines/ngi/box2d/Common/b2StackAllocator.h"
+
+namespace NGI {
+
+#define B2_DEBUG_SOLVER 0
+
+struct b2ContactPositionConstraint
+{
+ b2Vec2 localPoints[b2_maxManifoldPoints];
+ b2Vec2 localNormal;
+ b2Vec2 localPoint;
+ int32 indexA;
+ int32 indexB;
+ float32 invMassA, invMassB;
+ b2Vec2 localCenterA, localCenterB;
+ float32 invIA, invIB;
+ b2Manifold::Type type;
+ float32 radiusA, radiusB;
+ int32 pointCount;
+};
+
+b2ContactSolver::b2ContactSolver(b2ContactSolverDef* def)
+{
+ m_step = def->step;
+ m_allocator = def->allocator;
+ m_count = def->count;
+ m_positionConstraints = (b2ContactPositionConstraint*)m_allocator->Allocate(m_count * sizeof(b2ContactPositionConstraint));
+ m_velocityConstraints = (b2ContactVelocityConstraint*)m_allocator->Allocate(m_count * sizeof(b2ContactVelocityConstraint));
+ m_positions = def->positions;
+ m_velocities = def->velocities;
+ m_contacts = def->contacts;
+
+ // Initialize position independent portions of the constraints.
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ b2Contact* contact = m_contacts[i];
+
+ b2Fixture* fixtureA = contact->m_fixtureA;
+ b2Fixture* fixtureB = contact->m_fixtureB;
+ b2Shape* shapeA = fixtureA->GetShape();
+ b2Shape* shapeB = fixtureB->GetShape();
+ float32 radiusA = shapeA->m_radius;
+ float32 radiusB = shapeB->m_radius;
+ b2Body* bodyA = fixtureA->GetBody();
+ b2Body* bodyB = fixtureB->GetBody();
+ b2Manifold* manifold = contact->GetManifold();
+
+ int32 pointCount = manifold->pointCount;
+ b2Assert(pointCount > 0);
+
+ b2ContactVelocityConstraint* vc = m_velocityConstraints + i;
+ vc->friction = contact->m_friction;
+ vc->restitution = contact->m_restitution;
+ vc->indexA = bodyA->m_islandIndex;
+ vc->indexB = bodyB->m_islandIndex;
+ vc->invMassA = bodyA->m_invMass;
+ vc->invMassB = bodyB->m_invMass;
+ vc->invIA = bodyA->m_invI;
+ vc->invIB = bodyB->m_invI;
+ vc->contactIndex = i;
+ vc->pointCount = pointCount;
+ vc->K.SetZero();
+ vc->normalMass.SetZero();
+
+ b2ContactPositionConstraint* pc = m_positionConstraints + i;
+ pc->indexA = bodyA->m_islandIndex;
+ pc->indexB = bodyB->m_islandIndex;
+ pc->invMassA = bodyA->m_invMass;
+ pc->invMassB = bodyB->m_invMass;
+ pc->localCenterA = bodyA->m_sweep.localCenter;
+ pc->localCenterB = bodyB->m_sweep.localCenter;
+ pc->invIA = bodyA->m_invI;
+ pc->invIB = bodyB->m_invI;
+ pc->localNormal = manifold->localNormal;
+ pc->localPoint = manifold->localPoint;
+ pc->pointCount = pointCount;
+ pc->radiusA = radiusA;
+ pc->radiusB = radiusB;
+ pc->type = manifold->type;
+
+ for (int32 j = 0; j < pointCount; ++j)
+ {
+ b2ManifoldPoint* cp = manifold->points + j;
+ b2VelocityConstraintPoint* vcp = vc->points + j;
+
+ if (m_step.warmStarting)
+ {
+ vcp->normalImpulse = m_step.dtRatio * cp->normalImpulse;
+ vcp->tangentImpulse = m_step.dtRatio * cp->tangentImpulse;
+ }
+ else
+ {
+ vcp->normalImpulse = 0.0f;
+ vcp->tangentImpulse = 0.0f;
+ }
+
+ vcp->rA.SetZero();
+ vcp->rB.SetZero();
+ vcp->normalMass = 0.0f;
+ vcp->tangentMass = 0.0f;
+ vcp->velocityBias = 0.0f;
+
+ pc->localPoints[j] = cp->localPoint;
+ }
+ }
+}
+
+b2ContactSolver::~b2ContactSolver()
+{
+ m_allocator->Free(m_velocityConstraints);
+ m_allocator->Free(m_positionConstraints);
+}
+
+// Initialize position dependent portions of the velocity constraints.
+void b2ContactSolver::InitializeVelocityConstraints()
+{
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ b2ContactVelocityConstraint* vc = m_velocityConstraints + i;
+ b2ContactPositionConstraint* pc = m_positionConstraints + i;
+
+ float32 radiusA = pc->radiusA;
+ float32 radiusB = pc->radiusB;
+ b2Manifold* manifold = m_contacts[vc->contactIndex]->GetManifold();
+
+ int32 indexA = vc->indexA;
+ int32 indexB = vc->indexB;
+
+ float32 mA = vc->invMassA;
+ float32 mB = vc->invMassB;
+ float32 iA = vc->invIA;
+ float32 iB = vc->invIB;
+ b2Vec2 localCenterA = pc->localCenterA;
+ b2Vec2 localCenterB = pc->localCenterB;
+
+ b2Vec2 cA = m_positions[indexA].c;
+ float32 aA = m_positions[indexA].a;
+ b2Vec2 vA = m_velocities[indexA].v;
+ float32 wA = m_velocities[indexA].w;
+
+ b2Vec2 cB = m_positions[indexB].c;
+ float32 aB = m_positions[indexB].a;
+ b2Vec2 vB = m_velocities[indexB].v;
+ float32 wB = m_velocities[indexB].w;
+
+ b2Assert(manifold->pointCount > 0);
+
+ b2Transform xfA, xfB;
+ xfA.q.Set(aA);
+ xfB.q.Set(aB);
+ xfA.p = cA - b2Mul(xfA.q, localCenterA);
+ xfB.p = cB - b2Mul(xfB.q, localCenterB);
+
+ b2WorldManifold worldManifold;
+ worldManifold.Initialize(manifold, xfA, radiusA, xfB, radiusB);
+
+ vc->normal = worldManifold.normal;
+
+ int32 pointCount = vc->pointCount;
+ for (int32 j = 0; j < pointCount; ++j)
+ {
+ b2VelocityConstraintPoint* vcp = vc->points + j;
+
+ vcp->rA = worldManifold.points[j] - cA;
+ vcp->rB = worldManifold.points[j] - cB;
+
+ float32 rnA = b2Cross(vcp->rA, vc->normal);
+ float32 rnB = b2Cross(vcp->rB, vc->normal);
+
+ float32 kNormal = mA + mB + iA * rnA * rnA + iB * rnB * rnB;
+
+ vcp->normalMass = kNormal > 0.0f ? 1.0f / kNormal : 0.0f;
+
+ b2Vec2 tangent = b2Cross(vc->normal, 1.0f);
+
+ float32 rtA = b2Cross(vcp->rA, tangent);
+ float32 rtB = b2Cross(vcp->rB, tangent);
+
+ float32 kTangent = mA + mB + iA * rtA * rtA + iB * rtB * rtB;
+
+ vcp->tangentMass = kTangent > 0.0f ? 1.0f / kTangent : 0.0f;
+
+ // Setup a velocity bias for restitution.
+ vcp->velocityBias = 0.0f;
+ float32 vRel = b2Dot(vc->normal, vB + b2Cross(wB, vcp->rB) - vA - b2Cross(wA, vcp->rA));
+ if (vRel < -b2_velocityThreshold)
+ {
+ vcp->velocityBias = -vc->restitution * vRel;
+ }
+ }
+
+ // If we have two points, then prepare the block solver.
+ if (vc->pointCount == 2)
+ {
+ b2VelocityConstraintPoint* vcp1 = vc->points + 0;
+ b2VelocityConstraintPoint* vcp2 = vc->points + 1;
+
+ float32 rn1A = b2Cross(vcp1->rA, vc->normal);
+ float32 rn1B = b2Cross(vcp1->rB, vc->normal);
+ float32 rn2A = b2Cross(vcp2->rA, vc->normal);
+ float32 rn2B = b2Cross(vcp2->rB, vc->normal);
+
+ float32 k11 = mA + mB + iA * rn1A * rn1A + iB * rn1B * rn1B;
+ float32 k22 = mA + mB + iA * rn2A * rn2A + iB * rn2B * rn2B;
+ float32 k12 = mA + mB + iA * rn1A * rn2A + iB * rn1B * rn2B;
+
+ // Ensure a reasonable condition number.
+ const float32 k_maxConditionNumber = 1000.0f;
+ if (k11 * k11 < k_maxConditionNumber * (k11 * k22 - k12 * k12))
+ {
+ // K is safe to invert.
+ vc->K.ex.Set(k11, k12);
+ vc->K.ey.Set(k12, k22);
+ vc->normalMass = vc->K.GetInverse();
+ }
+ else
+ {
+ // The constraints are redundant, just use one.
+ // TODO_ERIN use deepest?
+ vc->pointCount = 1;
+ }
+ }
+ }
+}
+
+void b2ContactSolver::WarmStart()
+{
+ // Warm start.
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ b2ContactVelocityConstraint* vc = m_velocityConstraints + i;
+
+ int32 indexA = vc->indexA;
+ int32 indexB = vc->indexB;
+ float32 mA = vc->invMassA;
+ float32 iA = vc->invIA;
+ float32 mB = vc->invMassB;
+ float32 iB = vc->invIB;
+ int32 pointCount = vc->pointCount;
+
+ b2Vec2 vA = m_velocities[indexA].v;
+ float32 wA = m_velocities[indexA].w;
+ b2Vec2 vB = m_velocities[indexB].v;
+ float32 wB = m_velocities[indexB].w;
+
+ b2Vec2 normal = vc->normal;
+ b2Vec2 tangent = b2Cross(normal, 1.0f);
+
+ for (int32 j = 0; j < pointCount; ++j)
+ {
+ b2VelocityConstraintPoint* vcp = vc->points + j;
+ b2Vec2 P = vcp->normalImpulse * normal + vcp->tangentImpulse * tangent;
+ wA -= iA * b2Cross(vcp->rA, P);
+ vA -= mA * P;
+ wB += iB * b2Cross(vcp->rB, P);
+ vB += mB * P;
+ }
+
+ m_velocities[indexA].v = vA;
+ m_velocities[indexA].w = wA;
+ m_velocities[indexB].v = vB;
+ m_velocities[indexB].w = wB;
+ }
+}
+
+void b2ContactSolver::SolveVelocityConstraints()
+{
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ b2ContactVelocityConstraint* vc = m_velocityConstraints + i;
+
+ int32 indexA = vc->indexA;
+ int32 indexB = vc->indexB;
+ float32 mA = vc->invMassA;
+ float32 iA = vc->invIA;
+ float32 mB = vc->invMassB;
+ float32 iB = vc->invIB;
+ int32 pointCount = vc->pointCount;
+
+ b2Vec2 vA = m_velocities[indexA].v;
+ float32 wA = m_velocities[indexA].w;
+ b2Vec2 vB = m_velocities[indexB].v;
+ float32 wB = m_velocities[indexB].w;
+
+ b2Vec2 normal = vc->normal;
+ b2Vec2 tangent = b2Cross(normal, 1.0f);
+ float32 friction = vc->friction;
+
+ b2Assert(pointCount == 1 || pointCount == 2);
+
+ // Solve tangent constraints first because non-penetration is more important
+ // than friction.
+ for (int32 j = 0; j < pointCount; ++j)
+ {
+ b2VelocityConstraintPoint* vcp = vc->points + j;
+
+ // Relative velocity at contact
+ b2Vec2 dv = vB + b2Cross(wB, vcp->rB) - vA - b2Cross(wA, vcp->rA);
+
+ // Compute tangent force
+ float32 vt = b2Dot(dv, tangent);
+ float32 lambda = vcp->tangentMass * (-vt);
+
+ // b2Clamp the accumulated force
+ float32 maxFriction = friction * vcp->normalImpulse;
+ float32 newImpulse = b2Clamp(vcp->tangentImpulse + lambda, -maxFriction, maxFriction);
+ lambda = newImpulse - vcp->tangentImpulse;
+ vcp->tangentImpulse = newImpulse;
+
+ // Apply contact impulse
+ b2Vec2 P = lambda * tangent;
+
+ vA -= mA * P;
+ wA -= iA * b2Cross(vcp->rA, P);
+
+ vB += mB * P;
+ wB += iB * b2Cross(vcp->rB, P);
+ }
+
+ // Solve normal constraints
+ if (vc->pointCount == 1)
+ {
+ b2VelocityConstraintPoint* vcp = vc->points + 0;
+
+ // Relative velocity at contact
+ b2Vec2 dv = vB + b2Cross(wB, vcp->rB) - vA - b2Cross(wA, vcp->rA);
+
+ // Compute normal impulse
+ float32 vn = b2Dot(dv, normal);
+ float32 lambda = -vcp->normalMass * (vn - vcp->velocityBias);
+
+ // b2Clamp the accumulated impulse
+ float32 newImpulse = b2Max(vcp->normalImpulse + lambda, 0.0f);
+ lambda = newImpulse - vcp->normalImpulse;
+ vcp->normalImpulse = newImpulse;
+
+ // Apply contact impulse
+ b2Vec2 P = lambda * normal;
+ vA -= mA * P;
+ wA -= iA * b2Cross(vcp->rA, P);
+
+ vB += mB * P;
+ wB += iB * b2Cross(vcp->rB, P);
+ }
+ else
+ {
+ // Block solver developed in collaboration with Dirk Gregorius (back in 01/07 on Box2D_Lite).
+ // Build the mini LCP for this contact patch
+ //
+ // vn = A * x + b, vn >= 0, , vn >= 0, x >= 0 and vn_i * x_i = 0 with i = 1..2
+ //
+ // A = J * W * JT and J = ( -n, -r1 x n, n, r2 x n )
+ // b = vn0 - velocityBias
+ //
+ // The system is solved using the "Total enumeration method" (s. Murty). The complementary constraint vn_i * x_i
+ // implies that we must have in any solution either vn_i = 0 or x_i = 0. So for the 2D contact problem the cases
+ // vn1 = 0 and vn2 = 0, x1 = 0 and x2 = 0, x1 = 0 and vn2 = 0, x2 = 0 and vn1 = 0 need to be tested. The first valid
+ // solution that satisfies the problem is chosen.
+ //
+ // In order to account of the accumulated impulse 'a' (because of the iterative nature of the solver which only requires
+ // that the accumulated impulse is clamped and not the incremental impulse) we change the impulse variable (x_i).
+ //
+ // Substitute:
+ //
+ // x = a + d
+ //
+ // a := old total impulse
+ // x := new total impulse
+ // d := incremental impulse
+ //
+ // For the current iteration we extend the formula for the incremental impulse
+ // to compute the new total impulse:
+ //
+ // vn = A * d + b
+ // = A * (x - a) + b
+ // = A * x + b - A * a
+ // = A * x + b'
+ // b' = b - A * a;
+
+ b2VelocityConstraintPoint* cp1 = vc->points + 0;
+ b2VelocityConstraintPoint* cp2 = vc->points + 1;
+
+ b2Vec2 a(cp1->normalImpulse, cp2->normalImpulse);
+ b2Assert(a.x >= 0.0f && a.y >= 0.0f);
+
+ // Relative velocity at contact
+ b2Vec2 dv1 = vB + b2Cross(wB, cp1->rB) - vA - b2Cross(wA, cp1->rA);
+ b2Vec2 dv2 = vB + b2Cross(wB, cp2->rB) - vA - b2Cross(wA, cp2->rA);
+
+ // Compute normal velocity
+ float32 vn1 = b2Dot(dv1, normal);
+ float32 vn2 = b2Dot(dv2, normal);
+
+ b2Vec2 b;
+ b.x = vn1 - cp1->velocityBias;
+ b.y = vn2 - cp2->velocityBias;
+
+ // Compute b'
+ b -= b2Mul(vc->K, a);
+
+ const float32 k_errorTol = 1e-3f;
+ B2_NOT_USED(k_errorTol);
+
+ for (;;)
+ {
+ //
+ // Case 1: vn = 0
+ //
+ // 0 = A * x + b'
+ //
+ // Solve for x:
+ //
+ // x = - inv(A) * b'
+ //
+ b2Vec2 x = - b2Mul(vc->normalMass, b);
+
+ if (x.x >= 0.0f && x.y >= 0.0f)
+ {
+ // Get the incremental impulse
+ b2Vec2 d = x - a;
+
+ // Apply incremental impulse
+ b2Vec2 P1 = d.x * normal;
+ b2Vec2 P2 = d.y * normal;
+ vA -= mA * (P1 + P2);
+ wA -= iA * (b2Cross(cp1->rA, P1) + b2Cross(cp2->rA, P2));
+
+ vB += mB * (P1 + P2);
+ wB += iB * (b2Cross(cp1->rB, P1) + b2Cross(cp2->rB, P2));
+
+ // Accumulate
+ cp1->normalImpulse = x.x;
+ cp2->normalImpulse = x.y;
+
+#if B2_DEBUG_SOLVER == 1
+ // Postconditions
+ dv1 = vB + b2Cross(wB, cp1->rB) - vA - b2Cross(wA, cp1->rA);
+ dv2 = vB + b2Cross(wB, cp2->rB) - vA - b2Cross(wA, cp2->rA);
+
+ // Compute normal velocity
+ vn1 = b2Dot(dv1, normal);
+ vn2 = b2Dot(dv2, normal);
+
+ b2Assert(b2Abs(vn1 - cp1->velocityBias) < k_errorTol);
+ b2Assert(b2Abs(vn2 - cp2->velocityBias) < k_errorTol);
+#endif
+ break;
+ }
+
+ //
+ // Case 2: vn1 = 0 and x2 = 0
+ //
+ // 0 = a11 * x1 + a12 * 0 + b1'
+ // vn2 = a21 * x1 + a22 * 0 + b2'
+ //
+ x.x = - cp1->normalMass * b.x;
+ x.y = 0.0f;
+ vn1 = 0.0f;
+ vn2 = vc->K.ex.y * x.x + b.y;
+
+ if (x.x >= 0.0f && vn2 >= 0.0f)
+ {
+ // Get the incremental impulse
+ b2Vec2 d = x - a;
+
+ // Apply incremental impulse
+ b2Vec2 P1 = d.x * normal;
+ b2Vec2 P2 = d.y * normal;
+ vA -= mA * (P1 + P2);
+ wA -= iA * (b2Cross(cp1->rA, P1) + b2Cross(cp2->rA, P2));
+
+ vB += mB * (P1 + P2);
+ wB += iB * (b2Cross(cp1->rB, P1) + b2Cross(cp2->rB, P2));
+
+ // Accumulate
+ cp1->normalImpulse = x.x;
+ cp2->normalImpulse = x.y;
+
+#if B2_DEBUG_SOLVER == 1
+ // Postconditions
+ dv1 = vB + b2Cross(wB, cp1->rB) - vA - b2Cross(wA, cp1->rA);
+
+ // Compute normal velocity
+ vn1 = b2Dot(dv1, normal);
+
+ b2Assert(b2Abs(vn1 - cp1->velocityBias) < k_errorTol);
+#endif
+ break;
+ }
+
+
+ //
+ // Case 3: vn2 = 0 and x1 = 0
+ //
+ // vn1 = a11 * 0 + a12 * x2 + b1'
+ // 0 = a21 * 0 + a22 * x2 + b2'
+ //
+ x.x = 0.0f;
+ x.y = - cp2->normalMass * b.y;
+ vn1 = vc->K.ey.x * x.y + b.x;
+ vn2 = 0.0f;
+
+ if (x.y >= 0.0f && vn1 >= 0.0f)
+ {
+ // Resubstitute for the incremental impulse
+ b2Vec2 d = x - a;
+
+ // Apply incremental impulse
+ b2Vec2 P1 = d.x * normal;
+ b2Vec2 P2 = d.y * normal;
+ vA -= mA * (P1 + P2);
+ wA -= iA * (b2Cross(cp1->rA, P1) + b2Cross(cp2->rA, P2));
+
+ vB += mB * (P1 + P2);
+ wB += iB * (b2Cross(cp1->rB, P1) + b2Cross(cp2->rB, P2));
+
+ // Accumulate
+ cp1->normalImpulse = x.x;
+ cp2->normalImpulse = x.y;
+
+#if B2_DEBUG_SOLVER == 1
+ // Postconditions
+ dv2 = vB + b2Cross(wB, cp2->rB) - vA - b2Cross(wA, cp2->rA);
+
+ // Compute normal velocity
+ vn2 = b2Dot(dv2, normal);
+
+ b2Assert(b2Abs(vn2 - cp2->velocityBias) < k_errorTol);
+#endif
+ break;
+ }
+
+ //
+ // Case 4: x1 = 0 and x2 = 0
+ //
+ // vn1 = b1
+ // vn2 = b2;
+ x.x = 0.0f;
+ x.y = 0.0f;
+ vn1 = b.x;
+ vn2 = b.y;
+
+ if (vn1 >= 0.0f && vn2 >= 0.0f )
+ {
+ // Resubstitute for the incremental impulse
+ b2Vec2 d = x - a;
+
+ // Apply incremental impulse
+ b2Vec2 P1 = d.x * normal;
+ b2Vec2 P2 = d.y * normal;
+ vA -= mA * (P1 + P2);
+ wA -= iA * (b2Cross(cp1->rA, P1) + b2Cross(cp2->rA, P2));
+
+ vB += mB * (P1 + P2);
+ wB += iB * (b2Cross(cp1->rB, P1) + b2Cross(cp2->rB, P2));
+
+ // Accumulate
+ cp1->normalImpulse = x.x;
+ cp2->normalImpulse = x.y;
+
+ break;
+ }
+
+ // No solution, give up. This is hit sometimes, but it doesn't seem to matter.
+ break;
+ }
+ }
+
+ m_velocities[indexA].v = vA;
+ m_velocities[indexA].w = wA;
+ m_velocities[indexB].v = vB;
+ m_velocities[indexB].w = wB;
+ }
+}
+
+void b2ContactSolver::StoreImpulses()
+{
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ b2ContactVelocityConstraint* vc = m_velocityConstraints + i;
+ b2Manifold* manifold = m_contacts[vc->contactIndex]->GetManifold();
+
+ for (int32 j = 0; j < vc->pointCount; ++j)
+ {
+ manifold->points[j].normalImpulse = vc->points[j].normalImpulse;
+ manifold->points[j].tangentImpulse = vc->points[j].tangentImpulse;
+ }
+ }
+}
+
+struct b2PositionSolverManifold
+{
+ void Initialize(b2ContactPositionConstraint* pc, const b2Transform& xfA, const b2Transform& xfB, int32 index)
+ {
+ b2Assert(pc->pointCount > 0);
+
+ switch (pc->type)
+ {
+ case b2Manifold::e_circles:
+ {
+ b2Vec2 pointA = b2Mul(xfA, pc->localPoint);
+ b2Vec2 pointB = b2Mul(xfB, pc->localPoints[0]);
+ normal = pointB - pointA;
+ normal.Normalize();
+ point = 0.5f * (pointA + pointB);
+ separation = b2Dot(pointB - pointA, normal) - pc->radiusA - pc->radiusB;
+ }
+ break;
+
+ case b2Manifold::e_faceA:
+ {
+ normal = b2Mul(xfA.q, pc->localNormal);
+ b2Vec2 planePoint = b2Mul(xfA, pc->localPoint);
+
+ b2Vec2 clipPoint = b2Mul(xfB, pc->localPoints[index]);
+ separation = b2Dot(clipPoint - planePoint, normal) - pc->radiusA - pc->radiusB;
+ point = clipPoint;
+ }
+ break;
+
+ case b2Manifold::e_faceB:
+ {
+ normal = b2Mul(xfB.q, pc->localNormal);
+ b2Vec2 planePoint = b2Mul(xfB, pc->localPoint);
+
+ b2Vec2 clipPoint = b2Mul(xfA, pc->localPoints[index]);
+ separation = b2Dot(clipPoint - planePoint, normal) - pc->radiusA - pc->radiusB;
+ point = clipPoint;
+
+ // Ensure normal points from A to B
+ normal = -normal;
+ }
+ break;
+ }
+ }
+
+ b2Vec2 normal;
+ b2Vec2 point;
+ float32 separation;
+};
+
+// Sequential solver.
+bool b2ContactSolver::SolvePositionConstraints()
+{
+ float32 minSeparation = 0.0f;
+
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ b2ContactPositionConstraint* pc = m_positionConstraints + i;
+
+ int32 indexA = pc->indexA;
+ int32 indexB = pc->indexB;
+ b2Vec2 localCenterA = pc->localCenterA;
+ float32 mA = pc->invMassA;
+ float32 iA = pc->invIA;
+ b2Vec2 localCenterB = pc->localCenterB;
+ float32 mB = pc->invMassB;
+ float32 iB = pc->invIB;
+ int32 pointCount = pc->pointCount;
+
+ b2Vec2 cA = m_positions[indexA].c;
+ float32 aA = m_positions[indexA].a;
+
+ b2Vec2 cB = m_positions[indexB].c;
+ float32 aB = m_positions[indexB].a;
+
+ // Solve normal constraints
+ for (int32 j = 0; j < pointCount; ++j)
+ {
+ b2Transform xfA, xfB;
+ xfA.q.Set(aA);
+ xfB.q.Set(aB);
+ xfA.p = cA - b2Mul(xfA.q, localCenterA);
+ xfB.p = cB - b2Mul(xfB.q, localCenterB);
+
+ b2PositionSolverManifold psm;
+ psm.Initialize(pc, xfA, xfB, j);
+ b2Vec2 normal = psm.normal;
+
+ b2Vec2 point = psm.point;
+ float32 separation = psm.separation;
+
+ b2Vec2 rA = point - cA;
+ b2Vec2 rB = point - cB;
+
+ // Track max constraint error.
+ minSeparation = b2Min(minSeparation, separation);
+
+ // Prevent large corrections and allow slop.
+ float32 C = b2Clamp(b2_baumgarte * (separation + b2_linearSlop), -b2_maxLinearCorrection, 0.0f);
+
+ // Compute the effective mass.
+ float32 rnA = b2Cross(rA, normal);
+ float32 rnB = b2Cross(rB, normal);
+ float32 K = mA + mB + iA * rnA * rnA + iB * rnB * rnB;
+
+ // Compute normal impulse
+ float32 impulse = K > 0.0f ? - C / K : 0.0f;
+
+ b2Vec2 P = impulse * normal;
+
+ cA -= mA * P;
+ aA -= iA * b2Cross(rA, P);
+
+ cB += mB * P;
+ aB += iB * b2Cross(rB, P);
+ }
+
+ m_positions[indexA].c = cA;
+ m_positions[indexA].a = aA;
+
+ m_positions[indexB].c = cB;
+ m_positions[indexB].a = aB;
+ }
+
+ // We can't expect minSpeparation >= -b2_linearSlop because we don't
+ // push the separation above -b2_linearSlop.
+ return minSeparation >= -3.0f * b2_linearSlop;
+}
+
+// Sequential position solver for position constraints.
+bool b2ContactSolver::SolveTOIPositionConstraints(int32 toiIndexA, int32 toiIndexB)
+{
+ float32 minSeparation = 0.0f;
+
+ for (int32 i = 0; i < m_count; ++i)
+ {
+ b2ContactPositionConstraint* pc = m_positionConstraints + i;
+
+ int32 indexA = pc->indexA;
+ int32 indexB = pc->indexB;
+ b2Vec2 localCenterA = pc->localCenterA;
+ b2Vec2 localCenterB = pc->localCenterB;
+ int32 pointCount = pc->pointCount;
+
+ float32 mA = 0.0f;
+ float32 iA = 0.0f;
+ if (indexA == toiIndexA || indexA == toiIndexB)
+ {
+ mA = pc->invMassA;
+ iA = pc->invIA;
+ }
+
+ float32 mB = pc->invMassB;
+ float32 iB = pc->invIB;
+ if (indexB == toiIndexA || indexB == toiIndexB)
+ {
+ mB = pc->invMassB;
+ iB = pc->invIB;
+ }
+
+ b2Vec2 cA = m_positions[indexA].c;
+ float32 aA = m_positions[indexA].a;
+
+ b2Vec2 cB = m_positions[indexB].c;
+ float32 aB = m_positions[indexB].a;
+
+ // Solve normal constraints
+ for (int32 j = 0; j < pointCount; ++j)
+ {
+ b2Transform xfA, xfB;
+ xfA.q.Set(aA);
+ xfB.q.Set(aB);
+ xfA.p = cA - b2Mul(xfA.q, localCenterA);
+ xfB.p = cB - b2Mul(xfB.q, localCenterB);
+
+ b2PositionSolverManifold psm;
+ psm.Initialize(pc, xfA, xfB, j);
+ b2Vec2 normal = psm.normal;
+
+ b2Vec2 point = psm.point;
+ float32 separation = psm.separation;
+
+ b2Vec2 rA = point - cA;
+ b2Vec2 rB = point - cB;
+
+ // Track max constraint error.
+ minSeparation = b2Min(minSeparation, separation);
+
+ // Prevent large corrections and allow slop.
+ float32 C = b2Clamp(b2_toiBaugarte * (separation + b2_linearSlop), -b2_maxLinearCorrection, 0.0f);
+
+ // Compute the effective mass.
+ float32 rnA = b2Cross(rA, normal);
+ float32 rnB = b2Cross(rB, normal);
+ float32 K = mA + mB + iA * rnA * rnA + iB * rnB * rnB;
+
+ // Compute normal impulse
+ float32 impulse = K > 0.0f ? - C / K : 0.0f;
+
+ b2Vec2 P = impulse * normal;
+
+ cA -= mA * P;
+ aA -= iA * b2Cross(rA, P);
+
+ cB += mB * P;
+ aB += iB * b2Cross(rB, P);
+ }
+
+ m_positions[indexA].c = cA;
+ m_positions[indexA].a = aA;
+
+ m_positions[indexB].c = cB;
+ m_positions[indexB].a = aB;
+ }
+
+ // We can't expect minSpeparation >= -b2_linearSlop because we don't
+ // push the separation above -b2_linearSlop.
+ return minSeparation >= -1.5f * b2_linearSlop;
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.h b/engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.h
new file mode 100644
index 00000000000..74be92efe71
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2ContactSolver.h
@@ -0,0 +1,98 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_CONTACT_SOLVER_H
+#define B2_CONTACT_SOLVER_H
+
+#include "engines/ngi/box2d/Common/b2Math.h"
+#include "engines/ngi/box2d/Collision/b2Collision.h"
+#include "engines/ngi/box2d/Dynamics/b2TimeStep.h"
+
+namespace NGI {
+
+class b2Contact;
+class b2Body;
+class b2StackAllocator;
+struct b2ContactPositionConstraint;
+
+struct b2VelocityConstraintPoint
+{
+ b2Vec2 rA;
+ b2Vec2 rB;
+ float32 normalImpulse;
+ float32 tangentImpulse;
+ float32 normalMass;
+ float32 tangentMass;
+ float32 velocityBias;
+};
+
+struct b2ContactVelocityConstraint
+{
+ b2VelocityConstraintPoint points[b2_maxManifoldPoints];
+ b2Vec2 normal;
+ b2Mat22 normalMass;
+ b2Mat22 K;
+ int32 indexA;
+ int32 indexB;
+ float32 invMassA, invMassB;
+ float32 invIA, invIB;
+ float32 friction;
+ float32 restitution;
+ int32 pointCount;
+ int32 contactIndex;
+};
+
+struct b2ContactSolverDef
+{
+ b2TimeStep step;
+ b2Contact** contacts;
+ int32 count;
+ b2Position* positions;
+ b2Velocity* velocities;
+ b2StackAllocator* allocator;
+};
+
+class b2ContactSolver
+{
+public:
+ b2ContactSolver(b2ContactSolverDef* def);
+ ~b2ContactSolver();
+
+ void InitializeVelocityConstraints();
+
+ void WarmStart();
+ void SolveVelocityConstraints();
+ void StoreImpulses();
+
+ bool SolvePositionConstraints();
+ bool SolveTOIPositionConstraints(int32 toiIndexA, int32 toiIndexB);
+
+ b2TimeStep m_step;
+ b2Position* m_positions;
+ b2Velocity* m_velocities;
+ b2StackAllocator* m_allocator;
+ b2ContactPositionConstraint* m_positionConstraints;
+ b2ContactVelocityConstraint* m_velocityConstraints;
+ b2Contact** m_contacts;
+ int m_count;
+};
+
+} // End of namespace NGI
+
+#endif
+
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.cpp b/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.cpp
new file mode 100644
index 00000000000..fab0dff9e2b
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.cpp
@@ -0,0 +1,54 @@
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.h"
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+
+#include <new>
+
+namespace NGI {
+using namespace std;
+
+b2Contact* b2EdgeAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)
+{
+ void* mem = allocator->Allocate(sizeof(b2EdgeAndCircleContact));
+ return new (mem) b2EdgeAndCircleContact(fixtureA, fixtureB);
+}
+
+void b2EdgeAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
+{
+ ((b2EdgeAndCircleContact*)contact)->~b2EdgeAndCircleContact();
+ allocator->Free(contact, sizeof(b2EdgeAndCircleContact));
+}
+
+b2EdgeAndCircleContact::b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB)
+: b2Contact(fixtureA, 0, fixtureB, 0)
+{
+ b2Assert(m_fixtureA->GetType() == b2Shape::e_edge);
+ b2Assert(m_fixtureB->GetType() == b2Shape::e_circle);
+}
+
+void b2EdgeAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)
+{
+ b2CollideEdgeAndCircle( manifold,
+ (b2EdgeShape*)m_fixtureA->GetShape(), xfA,
+ (b2CircleShape*)m_fixtureB->GetShape(), xfB);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.h b/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.h
new file mode 100644
index 00000000000..b4daba70dff
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndCircleContact.h
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_EDGE_AND_CIRCLE_CONTACT_H
+#define B2_EDGE_AND_CIRCLE_CONTACT_H
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2Contact.h"
+
+namespace NGI {
+
+class b2BlockAllocator;
+
+class b2EdgeAndCircleContact : public b2Contact
+{
+public:
+ static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
+ b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
+ static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
+
+ b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB);
+ ~b2EdgeAndCircleContact() {}
+
+ void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
+};
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp b/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp
new file mode 100644
index 00000000000..2a740384014
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp
@@ -0,0 +1,54 @@
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.h"
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+
+#include <new>
+
+namespace NGI {
+using namespace std;
+
+b2Contact* b2EdgeAndPolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)
+{
+ void* mem = allocator->Allocate(sizeof(b2EdgeAndPolygonContact));
+ return new (mem) b2EdgeAndPolygonContact(fixtureA, fixtureB);
+}
+
+void b2EdgeAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
+{
+ ((b2EdgeAndPolygonContact*)contact)->~b2EdgeAndPolygonContact();
+ allocator->Free(contact, sizeof(b2EdgeAndPolygonContact));
+}
+
+b2EdgeAndPolygonContact::b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB)
+: b2Contact(fixtureA, 0, fixtureB, 0)
+{
+ b2Assert(m_fixtureA->GetType() == b2Shape::e_edge);
+ b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon);
+}
+
+void b2EdgeAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)
+{
+ b2CollideEdgeAndPolygon( manifold,
+ (b2EdgeShape*)m_fixtureA->GetShape(), xfA,
+ (b2PolygonShape*)m_fixtureB->GetShape(), xfB);
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.h b/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.h
new file mode 100644
index 00000000000..d0f9f7101ea
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.h
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef B2_EDGE_AND_POLYGON_CONTACT_H
+#define B2_EDGE_AND_POLYGON_CONTACT_H
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2Contact.h"
+
+namespace NGI {
+
+class b2BlockAllocator;
+
+class b2EdgeAndPolygonContact : public b2Contact
+{
+public:
+ static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
+ b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
+ static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
+
+ b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB);
+ ~b2EdgeAndPolygonContact() {}
+
+ void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
+};
+
+} // End of namespace NGI
+
+#endif
diff --git a/engines/ngi/box2d/Dynamics/Contacts/b2PolygonAndCircleContact.cpp b/engines/ngi/box2d/Dynamics/Contacts/b2PolygonAndCircleContact.cpp
new file mode 100644
index 00000000000..32c6120b70b
--- /dev/null
+++ b/engines/ngi/box2d/Dynamics/Contacts/b2PolygonAndCircleContact.cpp
@@ -0,0 +1,54 @@
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "engines/ngi/box2d/Dynamics/Contacts/b2PolygonAndCircleContact.h"
+#include "engines/ngi/box2d/Common/b2BlockAllocator.h"
+#include "engines/ngi/box2d/Dynamics/b2Fixture.h"
+
+#include <new>
+
+namespace NGI {
+using namespace std;
+
+b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)
+{
+ void* mem = allocator->Allocate(sizeof(b2PolygonAndCircleContact));
+ return new (mem) b2PolygonAndCircleContact(fixtureA, fixtureB);
+}
+
+void b2PolygonAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
+{
+ ((b2PolygonAndCircleContact*)contact)->~b2PolygonAndCircleContact();
+ allocator->Free(contact, sizeof(b2PolygonAndCircleContact));
+}
+
+b2PolygonAndCircleContact::b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB)
+: b2Contact(fixtureA, 0, fixtureB, 0)
+{
+ b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon);
Commit: 0845e75654710a0250e856a462a744f4820819f8
https://github.com/scummvm/scummvm/commit/0845e75654710a0250e856a462a744f4820819f8
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Name Interact and Entrance fields after Android XML attributes
Changed paths:
engines/ngi/interaction.cpp
engines/ngi/interaction.h
engines/ngi/xmlproject.cpp
diff --git a/engines/ngi/interaction.cpp b/engines/ngi/interaction.cpp
index e447f3dabd2..779ba3256e4 100644
--- a/engines/ngi/interaction.cpp
+++ b/engines/ngi/interaction.cpp
@@ -102,7 +102,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
return false;
Interact *action = nullptr;
for (Interact *candidate : _interactions) {
- if (candidate->canRun(subj, obj, invId) && (!action || candidate->_field_28 > action->_field_28))
+ if (candidate->canRun(subj, obj, invId) && (!action || candidate->_ves > action->_ves))
action = candidate;
}
if (!action)
@@ -470,7 +470,7 @@ Interact::Interact() {
_heroOffsetY = 0;
_heroOffsetX = 0;
_heroStaticId = 0;
- _field_28 = 0;
+ _ves = 0;
_sceneId = -1;
}
@@ -585,7 +585,7 @@ bool Entrance::load(MfcArchive &file) {
_id = file.readUint32LE();
_queueId = file.readUint32LE();
file.skip(292); // FIXME: Ugh
- _field_130 = file.readUint32LE();
+ _heroId = file.readUint32LE();
return true;
}
diff --git a/engines/ngi/interaction.h b/engines/ngi/interaction.h
index 336e5307c17..3404225424b 100644
--- a/engines/ngi/interaction.h
+++ b/engines/ngi/interaction.h
@@ -48,7 +48,7 @@ class Interact : public CObject {
bool _heroMirror = false;
MessageQueue *_messageQueue;
int _sceneId;
- int _field_28;
+ int _ves;
uint _flags;
Common::String _actionName;
@@ -93,7 +93,7 @@ struct Entrance {
int32 _sceneId;
int32 _id;
int32 _queueId;
- int32 _field_130;
+ int32 _heroId;
bool load(MfcArchive &file);
};
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index 2ab389878dd..5fd0d9b818d 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -1082,7 +1082,7 @@ private:
action->_heroOffsetX = intProperty(*node, "x");
action->_heroOffsetY = intProperty(*node, "y");
action->_heroMirror = boolProperty(*node, "heroMirror");
- action->_field_28 = intProperty(*node, "ves");
+ action->_ves = intProperty(*node, "ves");
const Common::String item = node->values.getValOrDefault("curor_obj_id");
if (item == "ANY_OBJECT")
action->_cursorObjectId = -2;
Commit: 516337f01b81775099e64edb6ec8bedab3716baf
https://github.com/scummvm/scummvm/commit/516337f01b81775099e64edb6ec8bedab3716baf
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Rename Interact::_ves to _weight
Changed paths:
engines/ngi/interaction.cpp
engines/ngi/interaction.h
engines/ngi/xmlproject.cpp
diff --git a/engines/ngi/interaction.cpp b/engines/ngi/interaction.cpp
index 779ba3256e4..c1e672af4c5 100644
--- a/engines/ngi/interaction.cpp
+++ b/engines/ngi/interaction.cpp
@@ -102,7 +102,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
return false;
Interact *action = nullptr;
for (Interact *candidate : _interactions) {
- if (candidate->canRun(subj, obj, invId) && (!action || candidate->_ves > action->_ves))
+ if (candidate->canRun(subj, obj, invId) && (!action || candidate->_weight > action->_weight))
action = candidate;
}
if (!action)
@@ -470,7 +470,7 @@ Interact::Interact() {
_heroOffsetY = 0;
_heroOffsetX = 0;
_heroStaticId = 0;
- _ves = 0;
+ _weight = 0;
_sceneId = -1;
}
diff --git a/engines/ngi/interaction.h b/engines/ngi/interaction.h
index 3404225424b..6450174dc6b 100644
--- a/engines/ngi/interaction.h
+++ b/engines/ngi/interaction.h
@@ -48,7 +48,7 @@ class Interact : public CObject {
bool _heroMirror = false;
MessageQueue *_messageQueue;
int _sceneId;
- int _ves;
+ int _weight;
uint _flags;
Common::String _actionName;
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index 5fd0d9b818d..d6ebfe87775 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -1082,7 +1082,7 @@ private:
action->_heroOffsetX = intProperty(*node, "x");
action->_heroOffsetY = intProperty(*node, "y");
action->_heroMirror = boolProperty(*node, "heroMirror");
- action->_ves = intProperty(*node, "ves");
+ action->_weight = intProperty(*node, "ves");
const Common::String item = node->values.getValOrDefault("curor_obj_id");
if (item == "ANY_OBJECT")
action->_cursorObjectId = -2;
Commit: c1b08167e3052c0481b3eda3fb707459e9d7fc6b
https://github.com/scummvm/scummvm/commit/c1b08167e3052c0481b3eda3fb707459e9d7fc6b
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Name startMove, startFade and updateCmdPause after Android
Changed paths:
engines/ngi/fullpipe/sceneChapter.cpp
engines/ngi/fullpipe/sceneIntro.cpp
engines/ngi/messages.cpp
engines/ngi/messages.h
engines/ngi/motion.cpp
engines/ngi/motion.h
engines/ngi/scene.cpp
engines/ngi/scenes.cpp
engines/ngi/scenes.h
diff --git a/engines/ngi/fullpipe/sceneChapter.cpp b/engines/ngi/fullpipe/sceneChapter.cpp
index 4013321937e..51476408ac2 100644
--- a/engines/ngi/fullpipe/sceneChapter.cpp
+++ b/engines/ngi/fullpipe/sceneChapter.cpp
@@ -161,7 +161,7 @@ public:
const uint32 hold = MIN<int64>(UINT32_MAX, MAX(soundTime, textTime));
_shown = true;
setModal(true);
- _fader.start(_settings._fadeIn, hold, _settings._fadeOut);
+ _fader.startFade(_settings._fadeIn, hold, _settings._fadeOut);
if (_scene._soundList) {
Sound *sound = _scene._soundList->getSound(SND_CHAPTER_DLG);
if (sound)
diff --git a/engines/ngi/fullpipe/sceneIntro.cpp b/engines/ngi/fullpipe/sceneIntro.cpp
index f54cc5e6bc7..214102f4c0e 100644
--- a/engines/ngi/fullpipe/sceneIntro.cpp
+++ b/engines/ngi/fullpipe/sceneIntro.cpp
@@ -66,7 +66,7 @@ void sceneIntro_initMan(Scene &scene) {
g_vars->sceneIntro_needSleep = true;
g_vars->sceneIntro_needGetup = false;
g_vars->sceneIntro_playing = true;
- g_vars->sceneIntro_fader.start(1025, 0, 0);
+ g_vars->sceneIntro_fader.startFade(1025, 0, 0);
}
static bool sceneIntro_updateMan() {
diff --git a/engines/ngi/messages.cpp b/engines/ngi/messages.cpp
index 9de446ba421..40735aadf84 100644
--- a/engines/ngi/messages.cpp
+++ b/engines/ngi/messages.cpp
@@ -466,7 +466,7 @@ void MessageQueue::next() {
}
}
-bool MessageQueue::updatePause(uint32 elapsed) {
+bool MessageQueue::updateCmdPause(uint32 elapsed) {
if (!_pauseCommand)
return false;
diff --git a/engines/ngi/messages.h b/engines/ngi/messages.h
index a67e2108dde..ace0d394e37 100644
--- a/engines/ngi/messages.h
+++ b/engines/ngi/messages.h
@@ -153,7 +153,7 @@ class MessageQueue : public CObject {
bool run(AniObject *ani);
void update();
void next();
- bool updatePause(uint32 elapsed);
+ bool updateCmdPause(uint32 elapsed);
void finish();
void messageQueueCallback1(int par);
diff --git a/engines/ngi/motion.cpp b/engines/ngi/motion.cpp
index 1217edf22c5..a218b088aff 100644
--- a/engines/ngi/motion.cpp
+++ b/engines/ngi/motion.cpp
@@ -998,7 +998,7 @@ MessageQueue *MovGraph::startMove(AniObject *ani, int xpos, int ypos, int fuzzyM
movitems = _items[idx].candidatePaths;
}
- return method50(ani, _selFunc(ani, movitems, count), staticsId);
+ return startMove(ani, _selFunc(ani, movitems, count), staticsId);
}
void MovGraph::setSelFunc(GrPathDesc *(*callback1)(AniObject *ani, Common::Array<PathDesc *> *items, signed int counter)) {
@@ -1285,8 +1285,8 @@ MessageQueue *MovGraph::makeWholeQueue(AniObject *ani, GrPathDesc *movarr, int s
return mq;
}
-MessageQueue *MovGraph::method50(AniObject *ani, GrPathDesc *movarr, int staticsId) {
- debugC(4, kDebugPathfinding, "MovGraph::method50(*%d, *, %d)", (ani ? ani->_id : -1), staticsId);
+MessageQueue *MovGraph::startMove(AniObject *ani, GrPathDesc *movarr, int staticsId) {
+ debugC(4, kDebugPathfinding, "MovGraph::startMove(*%d, *, %d)", (ani ? ani->_id : -1), staticsId);
if (_items.size() == 0)
return nullptr;
diff --git a/engines/ngi/motion.h b/engines/ngi/motion.h
index 508b1e8b01a..c0dde09457b 100644
--- a/engines/ngi/motion.h
+++ b/engines/ngi/motion.h
@@ -54,6 +54,7 @@ public:
virtual void detachAllObjects() {}
virtual Common::Array<PathDesc *> *getPaths(AniObject *ani, int x, int y, int flag1, int *rescount) { return 0; }
virtual bool setPosImmediate(AniObject *obj, int x, int y) { return false; }
+ // Android CMotionController::StartMove(CAniObject *, ulong): empty stub, never overridden
virtual int method30() { return 0; }
virtual MessageQueue *startMove(AniObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) { return 0; }
virtual void setSelFunc(GrPathDesc *(*_callback1)(AniObject *ani, Common::Array<PathDesc *> *items, signed int counter)) {}
@@ -307,7 +308,7 @@ public:
bool resetPosition(AniObject *ani, int flag) override;
bool canDropInventory(AniObject *ani, int x, int y) override;
MessageQueue *makeQueue(AniObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
- virtual MessageQueue *method50(AniObject *ani, GrPathDesc *movarr, int staticsId);
+ virtual MessageQueue *startMove(AniObject *ani, GrPathDesc *movarr, int staticsId);
double putToLink(Common::Point *point, MovGraphLink *link, int fuzzyMatch);
void recalcLinkParams();
@@ -388,6 +389,7 @@ public:
void attachObject(AniObject *obj) override;
int detachObject(AniObject *obj) override;
void detachAllObjects() override;
+ using MovGraph::startMove;
MessageQueue *startMove(AniObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
MessageQueue *makeQueue(AniObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
diff --git a/engines/ngi/scene.cpp b/engines/ngi/scene.cpp
index a9d640e0f5f..04192501f62 100644
--- a/engines/ngi/scene.cpp
+++ b/engines/ngi/scene.cpp
@@ -737,7 +737,7 @@ bool Scene::update(int counterdiff) {
if (_behaviorController)
changed |= _behaviorController->update(counterdiff);
for (MessageQueue *queue : *g_nmi->_globalMessageQueueList)
- changed |= queue->updatePause(counterdiff);
+ changed |= queue->updateCmdPause(counterdiff);
processMessages();
if (g_nmi->_modalObject || this != g_nmi->_currentScene)
return true;
diff --git a/engines/ngi/scenes.cpp b/engines/ngi/scenes.cpp
index 619d67e828e..995667b6152 100644
--- a/engines/ngi/scenes.cpp
+++ b/engines/ngi/scenes.cpp
@@ -36,7 +36,7 @@
namespace NGI {
-void Fader::start(uint32 fadeIn, uint32 hold, uint32 fadeOut) {
+void Fader::startFade(uint32 fadeIn, uint32 hold, uint32 fadeOut) {
_durations[kFadeIn] = fadeIn;
_durations[kHold] = hold;
_durations[kFadeOut] = fadeOut;
diff --git a/engines/ngi/scenes.h b/engines/ngi/scenes.h
index b29073b2e80..6949a46431a 100644
--- a/engines/ngi/scenes.h
+++ b/engines/ngi/scenes.h
@@ -36,7 +36,7 @@ struct WalkingBearder;
class Fader {
public:
- void start(uint32 fadeIn, uint32 hold, uint32 fadeOut);
+ void startFade(uint32 fadeIn, uint32 hold, uint32 fadeOut);
void update(uint32 elapsed);
void fadeOut();
bool active() const { return _stage != kDone; }
Commit: d3672cc79e33177ac68bcc257c7ece52d3e8a493
https://github.com/scummvm/scummvm/commit/d3672cc79e33177ac68bcc257c7ece52d3e8a493
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Rename ModalQuery to QueryDlg and SaveGameDlg accessors after Android
Changed paths:
engines/ngi/modal.cpp
engines/ngi/modal.h
diff --git a/engines/ngi/modal.cpp b/engines/ngi/modal.cpp
index 450486fb7f4..aef4807b8e0 100644
--- a/engines/ngi/modal.cpp
+++ b/engines/ngi/modal.cpp
@@ -1442,7 +1442,7 @@ bool MainMenu::init(int counterdiff) {
case PIC_MNU_EXIT_L:
{
- ModalQuery *mq = new ModalQuery();
+ QueryDlg *mq = new QueryDlg();
g_nmi->_modalObject = mq;
@@ -1850,7 +1850,7 @@ void ModalHelp::launch() {
}
}
-ModalQuery::ModalQuery() {
+QueryDlg::QueryDlg() {
_bgScene = nullptr;
_bg = nullptr;
_okBtn = nullptr;
@@ -1858,13 +1858,13 @@ ModalQuery::ModalQuery() {
_queryResult = -1;
}
-ModalQuery::~ModalQuery() {
+QueryDlg::~QueryDlg() {
_bg->_flags &= 0xFFFB;
_cancelBtn->_flags &= 0xFFFB;
_okBtn->_flags &= 0xFFFB;
}
-bool ModalQuery::create(Scene *sc, Scene *bgScene, int id) {
+bool QueryDlg::create(Scene *sc, Scene *bgScene, int id) {
if (g_nmi->isDemo() && g_nmi->getLanguage() == Common::RU_RUS) {
Common::Keymapper *keymapper = g_system->getEventManager()->getKeymapper();
keymapper->getKeymap("ngi-default")->setEnabled(false);
@@ -1936,7 +1936,7 @@ bool ModalQuery::create(Scene *sc, Scene *bgScene, int id) {
return true;
}
-void ModalQuery::update() {
+void QueryDlg::update() {
if (_bgScene)
_bgScene->render();
@@ -1949,7 +1949,7 @@ void ModalQuery::update() {
_cancelBtn->render();
}
-bool ModalQuery::handleMessage(Command *cmd) {
+bool QueryDlg::handleMessage(Command *cmd) {
if (cmd->_cmd == 17) {
if (cmd->_messageNum == 29) {
if (_okBtn->isPointInside(g_nmi->_mouseScreenPos.x, g_nmi->_mouseScreenPos.y)) {
@@ -1970,7 +1970,7 @@ bool ModalQuery::handleMessage(Command *cmd) {
return false;
}
-bool ModalQuery::init(int counterdiff) {
+bool QueryDlg::init(int counterdiff) {
if (_okBtn->isPointInside(g_nmi->_mouseScreenPos.x, g_nmi->_mouseScreenPos.y))
_okBtn->_flags |= 4;
else
@@ -2039,7 +2039,7 @@ SaveGameDlg::SaveGameDlg() {
_queryRes = -1;
_rect = g_nmi->_sceneRect;
_queryDlg = nullptr;
- _mode = 1;
+ _isSaving = 1;
_objtype = kObjTypeModalSaveGame;
@@ -2069,7 +2069,7 @@ void SaveGameDlg::processKey(int action) {
bool SaveGameDlg::init(int counterdiff) {
if (_queryDlg) {
if (!_queryDlg->init(counterdiff)) {
- if (!_queryDlg->getQueryResult())
+ if (!_queryDlg->getRetVal())
_queryRes = -1;
delete _queryDlg;
@@ -2111,7 +2111,7 @@ void SaveGameDlg::setup(Scene *sc, int mode) {
_files.clear();
_arrayL.clear();
_arrayD.clear();
- _mode = mode;
+ _isSaving = mode;
if (mode) {
_bgr = sc->findPictureObjectById(PIC_MSV_BGR, 0);
@@ -2192,7 +2192,7 @@ void SaveGameDlg::setup(Scene *sc, int mode) {
}
}
-char *SaveGameDlg::getSaveName() {
+char *SaveGameDlg::getRetVal() {
if (_queryRes < 0)
return nullptr;
@@ -2321,9 +2321,9 @@ void SaveGameDlg::processMouse(int x, int y) {
if (x >= _files[i].fx1 && x <= _files[i].fx2 && y >= _files[i].fy1 && y <= _files[i].fy2) {
_queryRes = i + 1;
- if (_mode) {
+ if (_isSaving) {
if (!_files[i].empty) {
- _queryDlg = new ModalQuery;
+ _queryDlg = new QueryDlg;
_queryDlg->create(_menuScene, nullptr, PIC_MOV_BGR);
}
@@ -2341,8 +2341,8 @@ void SaveGameDlg::saveload() {
if (_objtype != kObjTypeModalSaveGame)
return;
- if (_mode) {
- if (getSaveName()) {
+ if (_isSaving) {
+ if (getRetVal()) {
bool allowed = true;
for (Common::Array<MessageQueue *>::iterator s = g_nmi->_globalMessageQueueList->begin(); s != g_nmi->_globalMessageQueueList->end(); ++s) {
@@ -2351,10 +2351,10 @@ void SaveGameDlg::saveload() {
}
if (g_nmi->_isSaveAllowed && allowed)
- g_nmi->_gameLoader->writeSavegame(g_nmi->_currentScene, getSaveName(), "");
+ g_nmi->_gameLoader->writeSavegame(g_nmi->_currentScene, getRetVal(), "");
}
} else {
- if (getSaveName()) {
+ if (getRetVal()) {
if (_parentObj) {
delete _parentObj;
@@ -2364,7 +2364,7 @@ void SaveGameDlg::saveload() {
g_nmi->stopAllSoundStreams();
g_nmi->stopSoundStream2();
- g_nmi->_gameLoader->readSavegame(getSaveName());
+ g_nmi->_gameLoader->readSavegame(getRetVal());
}
}
}
@@ -2555,7 +2555,7 @@ void NGIEngine::openMainMenu() {
}
if (isDemo() && getLanguage() == Common::RU_RUS) {
- ModalQuery *q = new ModalQuery;
+ QueryDlg *q = new QueryDlg;
Scene *sc = findScene(SC_MAINMENU);
diff --git a/engines/ngi/modal.h b/engines/ngi/modal.h
index 8675495519c..e534867aad6 100644
--- a/engines/ngi/modal.h
+++ b/engines/ngi/modal.h
@@ -260,10 +260,10 @@ public:
void launch();
};
-class ModalQuery : public BaseModalObject {
+class QueryDlg : public BaseModalObject {
public:
- ModalQuery();
- ~ModalQuery() override;
+ QueryDlg();
+ ~QueryDlg() override;
bool pollEvent() override { return true; }
bool handleMessage(Command *message) override;
@@ -272,7 +272,7 @@ public:
void saveload() override {}
bool create(Scene *sc, Scene *bgScene, int picId);
- int getQueryResult() { return _queryResult; }
+ int getRetVal() { return _queryResult; }
private:
@@ -301,7 +301,7 @@ public:
void setup(Scene *sc, int mode);
void processKey(int action);
- char *getSaveName();
+ char *getRetVal();
bool getFileInfo(int slot, SavegameItem *fileinfo);
Common::Rect _rect;
@@ -317,8 +317,8 @@ public:
PictureObject *_fullD;
PictureObject *_fullL;
Scene *_menuScene;
- int _mode;
- ModalQuery *_queryDlg;
+ int _isSaving;
+ QueryDlg *_queryDlg;
Common::Array <SavegameItem> _files;
Common::Array <PictureObject *> _arrayL;
Common::Array <PictureObject *> _arrayD;
Commit: 9ecfa34e39901c4df50070450d86278104e909b7
https://github.com/scummvm/scummvm/commit/9ecfa34e39901c4df50070450d86278104e909b7
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Add CommandKind enum for the command kind numbers
Changed paths:
engines/ngi/anihandler.cpp
engines/ngi/fullpipe/scene01.cpp
engines/ngi/fullpipe/scene02.cpp
engines/ngi/fullpipe/scene03.cpp
engines/ngi/fullpipe/scene04.cpp
engines/ngi/fullpipe/scene05.cpp
engines/ngi/fullpipe/scene06.cpp
engines/ngi/fullpipe/scene07.cpp
engines/ngi/fullpipe/scene08.cpp
engines/ngi/fullpipe/scene09.cpp
engines/ngi/fullpipe/scene10.cpp
engines/ngi/fullpipe/scene11.cpp
engines/ngi/fullpipe/scene12.cpp
engines/ngi/fullpipe/scene13.cpp
engines/ngi/fullpipe/scene14.cpp
engines/ngi/fullpipe/scene15.cpp
engines/ngi/fullpipe/scene16.cpp
engines/ngi/fullpipe/scene17.cpp
engines/ngi/fullpipe/scene18and19.cpp
engines/ngi/fullpipe/scene20.cpp
engines/ngi/fullpipe/scene21.cpp
engines/ngi/fullpipe/scene22.cpp
engines/ngi/fullpipe/scene23.cpp
engines/ngi/fullpipe/scene24.cpp
engines/ngi/fullpipe/scene25.cpp
engines/ngi/fullpipe/scene26.cpp
engines/ngi/fullpipe/scene27.cpp
engines/ngi/fullpipe/scene28.cpp
engines/ngi/fullpipe/scene29.cpp
engines/ngi/fullpipe/scene30.cpp
engines/ngi/fullpipe/scene31.cpp
engines/ngi/fullpipe/scene32.cpp
engines/ngi/fullpipe/scene33.cpp
engines/ngi/fullpipe/scene34.cpp
engines/ngi/fullpipe/scene35.cpp
engines/ngi/fullpipe/scene36.cpp
engines/ngi/fullpipe/scene37.cpp
engines/ngi/fullpipe/scene38.cpp
engines/ngi/fullpipe/sceneChapter.cpp
engines/ngi/fullpipe/sceneDbg.cpp
engines/ngi/fullpipe/sceneFinal.cpp
engines/ngi/fullpipe/sceneIntro.cpp
engines/ngi/fullpipe/sceneIntroDemo.cpp
engines/ngi/fullpipe/sceneTutorial.cpp
engines/ngi/gameloader.cpp
engines/ngi/input.cpp
engines/ngi/interaction.cpp
engines/ngi/inventory.cpp
engines/ngi/lift.cpp
engines/ngi/messagehandlers.cpp
engines/ngi/messages.cpp
engines/ngi/messages.h
engines/ngi/modal.cpp
engines/ngi/motion.cpp
engines/ngi/ngi.cpp
engines/ngi/stateloader.cpp
engines/ngi/statics.cpp
engines/ngi/xmlproject.cpp
diff --git a/engines/ngi/anihandler.cpp b/engines/ngi/anihandler.cpp
index 18323379d95..d8df419a167 100644
--- a/engines/ngi/anihandler.cpp
+++ b/engines/ngi/anihandler.cpp
@@ -96,12 +96,12 @@ MessageQueue *AniHandler::makeQueue(AniObject *ani, int staticsIndex, int, int *
else
sz = _items[idx].transitions[subidx].movement->_phases.size();
- ex = new ExCommand2(20, ani->_id, &pointArr[i], sz);
+ ex = new ExCommand2(kCmdStartSliding, ani->_id, &pointArr[i], sz);
ex->_messageNum = _items[idx].transitions[subidx].movement->_id;
} else {
#endif
- ex = new Command(ani->_id, 1, _items[idx].transitions[subidx].movement->_id, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ani->_id, kCmdStartMovement, _items[idx].transitions[subidx].movement->_id, 0, 0, 0, 1, 0, 0, 0);
#if 0
}
#endif
@@ -396,7 +396,7 @@ MessageQueue *AniHandler::makeRunQueue(MakeQueueStruct *mkQueue) {
j = s.staticsIndex;
}
- Command *ex = new Command(mkQueue->ani->_id, 5, -1, mkQueue->x1, mkQueue->y1, 0, 1, 0, 0, 0);
+ Command *ex = new Command(mkQueue->ani->_id, kCmdShow, -1, mkQueue->x1, mkQueue->y1, 0, 1, 0, 0, 0);
ex->_z = mkQueue->destZ;
ex->_param = mkQueue->ani->_copyId;
@@ -742,7 +742,7 @@ ExCommand2 *AniHandler::createCommand(Movement *mov, int objId, int x1, int y1,
}
}
- ExCommand2 *ex = new ExCommand2(20, objId, points);
+ ExCommand2 *ex = new ExCommand2(kCmdStartSliding, objId, points);
ex->_excFlags = 2;
ex->_messageNum = mov->_id;
ex->_z = len;
diff --git a/engines/ngi/fullpipe/scene01.cpp b/engines/ngi/fullpipe/scene01.cpp
index 9284a5551b3..789f2596ef9 100644
--- a/engines/ngi/fullpipe/scene01.cpp
+++ b/engines/ngi/fullpipe/scene01.cpp
@@ -135,7 +135,7 @@ bool scene01_click(Common::Point pos) {
int sceneHandler01(Command *cmd) {
int res = 0;
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
if (g_nmi->isAndroidFullPipe() && !cmd->_messageName.empty()) {
diff --git a/engines/ngi/fullpipe/scene02.cpp b/engines/ngi/fullpipe/scene02.cpp
index e6f4619bf58..66aad1773a5 100644
--- a/engines/ngi/fullpipe/scene02.cpp
+++ b/engines/ngi/fullpipe/scene02.cpp
@@ -77,7 +77,7 @@ void sceneHandler02_onHideLadder() {
int sceneHandler02(Command *ex) {
int res = 0;
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
switch(ex->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene03.cpp b/engines/ngi/fullpipe/scene03.cpp
index 11d0cb1004e..4927482b75d 100644
--- a/engines/ngi/fullpipe/scene03.cpp
+++ b/engines/ngi/fullpipe/scene03.cpp
@@ -145,15 +145,15 @@ void sceneHandler03_giveCoin(Command *ex) {
Command *ex1 = mq->getCommandByIndex(1);
if (sceneHandler03_swallowedEgg1State()) {
- ex0->_cmd = 1;
- ex1->_cmd = 1;
+ ex0->_cmd = kCmdStartMovement;
+ ex1->_cmd = kCmdStartMovement;
getGameLoaderInventory()->removeItem(ANI_INV_COIN, 1);
} else {
- ex0->_cmd = 0;
+ ex0->_cmd = kCmdNone;
ex0->_excFlags |= 1;
- ex1->_cmd = 0;
+ ex1->_cmd = kCmdNone;
ex1->_excFlags |= 1;
g_vars->scene03_eggeater->_flags &= 0xFF7Fu;
@@ -218,11 +218,11 @@ void sceneHandler03_doTakeEgg(Command *ex) {
}
int sceneHandler03(Command *ex) {
- if (ex->_cmd != 17 && ex->_messageNum != 33)
+ if (ex->_cmd != kCmdMessage && ex->_messageNum != 33)
debugC(3, kDebugSceneLogic, "scene03: got message: kind %d, num: %d", ex->_cmd, ex->_messageNum);
- if (ex->_cmd != 17) {
- if (ex->_cmd == 57)
+ if (ex->_cmd != kCmdMessage) {
+ if (ex->_cmd == kCmdRemoveInvItem)
sceneHandler03_giveItem(ex);
return 0;
}
@@ -281,7 +281,7 @@ int sceneHandler03(Command *ex) {
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(ex->_sceneClickX, ex->_sceneClickY);
if (ani && ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
return 0;
}
@@ -292,7 +292,7 @@ int sceneHandler03(Command *ex) {
if (g_nmi->_aniMan->isIdle())
if (!(g_nmi->_aniMan->_flags & 0x100) && g_nmi->_msgObjectId2 != g_vars->scene03_domino->_id) {
handleObjectInteraction(g_nmi->_aniMan, g_vars->scene03_domino, ex->_param);
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
return 0;
}
diff --git a/engines/ngi/fullpipe/scene04.cpp b/engines/ngi/fullpipe/scene04.cpp
index 0694509c31c..4b1c7fbc361 100644
--- a/engines/ngi/fullpipe/scene04.cpp
+++ b/engines/ngi/fullpipe/scene04.cpp
@@ -306,14 +306,14 @@ void sceneHandler04_downLadder(int x, int y) {
void sceneHandler04_walkClimbLadder(Command *ex) {
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- Command *ex1 = new Command(ANI_MAN, 1, MV_MAN_TOLADDER, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex1 = new Command(ANI_MAN, kCmdStartMovement, MV_MAN_TOLADDER, 0, 0, 0, 1, 0, 0, 0);
ex1->_param = g_nmi->_aniMan->_copyId;
ex1->_excFlags |= 2;
mq->addCommandToEnd(ex1);
- Command *ex2 = new Command(ANI_MAN, 1, MV_MAN_STOPLADDER, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex2 = new Command(ANI_MAN, kCmdStartMovement, MV_MAN_STOPLADDER, 0, 0, 0, 1, 0, 0, 0);
ex2->_param = g_nmi->_aniMan->_copyId;
ex2->_excFlags |= 2;
@@ -325,7 +325,7 @@ void sceneHandler04_walkClimbLadder(Command *ex) {
if (ex) {
ex3 = ex->createClone();
} else {
- ex3 = new Command(0, 17, MSG_SC4_CLICKLADDER, 0, 0, 0, 1, 0, 0, 0);
+ ex3 = new Command(0, kCmdMessage, MSG_SC4_CLICKLADDER, 0, 0, 0, 1, 0, 0, 0);
ex3->_excFlags |= 3;
}
@@ -395,7 +395,7 @@ void sceneHandler04_clickLadder() {
if (abs(1095 - g_vars->scene04_dudePosX) > 1 || abs(434 - g_vars->scene04_dudePosY) > 1) {
MessageQueue *mq = getSc2MctlCompoundBySceneId(g_nmi->_currentScene->_sceneId)->startMove(g_nmi->_aniMan, 1095, 434, 1, ST_MAN_UP);
if (mq) {
- Command *ex = new Command(0, 17, MSG_SC4_CLICKLADDER, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC4_CLICKLADDER, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 3;
mq->addCommandToEnd(ex);
@@ -504,19 +504,19 @@ void sceneHandler04_gotoLadder(Command *ex) {
if (mq) {
mq->removeCommand(mq->getCount() - 1, 1);
- Command *ex1 = new Command(ANI_MAN, 1, MV_MAN_TOLADDER, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex1 = new Command(ANI_MAN, kCmdStartMovement, MV_MAN_TOLADDER, 0, 0, 0, 1, 0, 0, 0);
ex1->_excFlags = 2;
ex1->_wait = 1;
ex1->_param = -1;
mq->addCommandToEnd(ex1);
- Command *ex2 = new Command(ANI_MAN, 1, MV_MAN_STOPLADDER, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex2 = new Command(ANI_MAN, kCmdStartMovement, MV_MAN_STOPLADDER, 0, 0, 0, 1, 0, 0, 0);
ex2->_excFlags = 2;
ex2->_wait = 1;
ex2->_param = -1;
mq->addCommandToEnd(ex2);
- Command *ex3 = new Command(g_nmi->_aniMan->_id, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex3 = new Command(g_nmi->_aniMan->_id, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
ex3->_z = 256;
ex3->_messageNum = 0;
ex3->_excFlags |= 3;
@@ -594,29 +594,29 @@ MessageQueue *sceneHandler04_kozFly3(AniObject *ani, double phase) {
MessageQueue *mq = aniHandler.makeRunQueue(&mkQueue);
if (mq) {
- Command *ex = new Command(ANI_KOZAWKA, 1, MV_KZW_STANDUP, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_STANDUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_KOZAWKA, 1, MV_KZW_TURN, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_TURN, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
for (int i = 0; i < 5; i++) {
- ex = new Command(ANI_KOZAWKA, 1, rMV_KZW_GOR, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdStartMovement, rMV_KZW_GOR, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
}
- ex = new Command(ANI_KOZAWKA, 6, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdHide, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_KOZAWKA, 17, MSG_KOZAWRESTART, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdMessage, MSG_KOZAWRESTART, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
@@ -664,29 +664,29 @@ MessageQueue *sceneHandler04_kozFly5(AniObject *ani, double phase) {
delete mq2;
mq2 = nullptr;
- Command *ex = new Command(ANI_KOZAWKA, 1, MV_KZW_STANDUP, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_STANDUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq1->addCommandToEnd(ex);
- ex = new Command(ANI_KOZAWKA, 1, MV_KZW_TURN, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_TURN, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq1->addCommandToEnd(ex);
for (int i = 0; i < 5; i++) {
- ex = new Command(ANI_KOZAWKA, 1, rMV_KZW_GOR, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdStartMovement, rMV_KZW_GOR, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq1->addCommandToEnd(ex);
}
- ex = new Command(ANI_KOZAWKA, 6, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdHide, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = ani->_copyId;
mq1->addCommandToEnd(ex);
- ex = new Command(ANI_KOZAWKA, 17, MSG_KOZAWRESTART, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdMessage, MSG_KOZAWRESTART, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = ani->_copyId;
mq1->addCommandToEnd(ex);
@@ -720,17 +720,17 @@ MessageQueue *sceneHandler04_kozFly6(AniObject *ani) {
if (mq) {
mq->removeCommand(mq->getCount() - 1, 1);
- Command *ex = new Command(ANI_KOZAWKA, 1, MV_KZW_STANDUP, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_STANDUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_KOZAWKA, 1, MV_KZW_GOR, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_GOR, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_KOZAWKA, 1, MV_KZW_RAISEHEAD, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_RAISEHEAD, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
@@ -782,29 +782,29 @@ MessageQueue *sceneHandler04_kozFly7(AniObject *ani, double phase) {
ani->_z = 10;
- Command *ex = new Command(ANI_KOZAWKA, 1, MV_KZW_STANDUP, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_STANDUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_KOZAWKA, 1, MV_KZW_TURN, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdStartMovement, MV_KZW_TURN, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
for (int i = 0; i < 2; i++) {
- ex = new Command(ANI_KOZAWKA, 1, rMV_KZW_GOR, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdStartMovement, rMV_KZW_GOR, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
}
- ex = new Command(ANI_KOZAWKA, 6, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdHide, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_KOZAWKA, 17, MSG_KOZAWRESTART, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_KOZAWKA, kCmdMessage, MSG_KOZAWRESTART, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = ani->_copyId;
mq->addCommandToEnd(ex);
@@ -1025,7 +1025,7 @@ void sceneHandler04_leaveScene() {
Command *ex = nullptr;
for (uint i = 0; i < mq->getCount(); i++) {
- if (mq->getCommandByIndex(i)->_cmd == 27) {
+ if (mq->getCommandByIndex(i)->_cmd == kCmdShowFromScene) {
ex = mq->getCommandByIndex(i);
break;
}
@@ -1147,7 +1147,7 @@ void sceneHandler04_leaveLadder(Command *ex) {
mq->addCommandToEnd(ex->createClone());
if (mq->run(g_nmi->_aniMan) )
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
else
delete mq;
@@ -1161,18 +1161,18 @@ void sceneHandler04_leaveLadder(Command *ex) {
Command *ex1;
if (g_nmi->_aniMan->_statics->_staticsId == ST_MAN_LADDERDOWN) {
- ex1 = new Command(ANI_MAN, 1, MV_MAN_LOOKLADDERRV, 0, 0, 0, 1, 0, 0, 0);
+ ex1 = new Command(ANI_MAN, kCmdStartMovement, MV_MAN_LOOKLADDERRV, 0, 0, 0, 1, 0, 0, 0);
ex1->_param = g_nmi->_aniMan->_copyId;
ex1->_excFlags |= 2;
mq->addCommandToEnd(ex1);
}
- ex1 = new Command(ANI_MAN, 1, MV_MAN_STARTLADDERD, 0, 0, 0, 1, 0, 0, 0);
+ ex1 = new Command(ANI_MAN, kCmdStartMovement, MV_MAN_STARTLADDERD, 0, 0, 0, 1, 0, 0, 0);
ex1->_param = g_nmi->_aniMan->_copyId;
ex1->_excFlags |= 2;
mq->addCommandToEnd(ex1);
- ex1 = new Command(ANI_MAN, 1, MV_MAN_FROMLADDER, 0, 0, 0, 1, 0, 0, 0);
+ ex1 = new Command(ANI_MAN, kCmdStartMovement, MV_MAN_FROMLADDER, 0, 0, 0, 1, 0, 0, 0);
ex1->_param = g_nmi->_aniMan->_copyId;
ex1->_excFlags |= 2;
mq->addCommandToEnd(ex1);
@@ -1189,7 +1189,7 @@ void sceneHandler04_leaveLadder(Command *ex) {
g_vars->scene04_ladder = nullptr;
g_vars->scene04_dudeOnLadder = 0;
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
mc->activate();
getGameLoaderInteractionController()->enable();
@@ -1355,7 +1355,7 @@ void sceneHandler04_doWinArcade() {
}
int sceneHandler04(Command *ex) {
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
switch (ex->_messageNum) {
@@ -1524,7 +1524,7 @@ int sceneHandler04(Command *ex) {
sceneHandler04_clickLadder();
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
break;
}
@@ -1539,7 +1539,7 @@ int sceneHandler04(Command *ex) {
if ((ani && ani->_id == ANI_PLANK) || picid == PIC_SC4_PLANK) {
sceneHandler04_clickPlank();
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
} else if (g_vars->scene04_dudeOnLadder) {
sceneHandler04_leaveLadder(ex);
} else if (!ani || !canInteractAny(g_nmi->_aniMan, ani, ex->_param)) {
@@ -1595,9 +1595,9 @@ int sceneHandler04(Command *ex) {
g_vars->scene04_kozHeadRaised = 0;
- exnew = new Command(0, 35, SND_4_010, 0, 0, 0, 1, 0, 0, 0);
+ exnew = new Command(0, kCmdSound, SND_4_010, 0, 0, 0, 1, 0, 0, 0);
} else {
- exnew = new Command(0, 35, SND_4_012, 0, 0, 0, 1, 0, 0, 0);
+ exnew = new Command(0, kCmdSound, SND_4_012, 0, 0, 0, 1, 0, 0, 0);
}
exnew->_z = 5;
diff --git a/engines/ngi/fullpipe/scene05.cpp b/engines/ngi/fullpipe/scene05.cpp
index b3837f25ebf..efa050e3589 100644
--- a/engines/ngi/fullpipe/scene05.cpp
+++ b/engines/ngi/fullpipe/scene05.cpp
@@ -128,7 +128,7 @@ void sceneHandler05_doOtmFeedback() {
if (mq) {
mq->setFlags(mq->getFlags() | 1);
- Command *ex = new Command(0, 17, MSG_SC5_MAKEOTMFEEDBACK, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC5_MAKEOTMFEEDBACK, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
@@ -198,7 +198,7 @@ void sceneHandler05_testHatch(Command *inex) {
Command *ex;
if (g_nmi->_currentScene->findAniObjectById(ANI_BIGLUK, -1)->_statics->_staticsId == ST_BLK_CLOSED) {
- ex = new Command(SC_5, 17, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
ex->postMessage();
@@ -227,11 +227,11 @@ void sceneHandler05_testHatch(Command *inex) {
mq->setFlags(mq->getFlags() | 1);
- ex = new Command(ANI_OTMOROZ, 1, MV_OTM_HANDLEUP, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_OTMOROZ, kCmdStartMovement, MV_OTM_HANDLEUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2u;
mq->addCommandToEnd(ex);
- ex = new Command(SC_5, 17, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -243,11 +243,11 @@ void sceneHandler05_testHatch(Command *inex) {
mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
mq->setFlags(mq->getFlags() | 1);
- ex = new Command(ANI_OTMOROZ, 1, MV_OTM_HANDLEUP, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_OTMOROZ, kCmdStartMovement, MV_OTM_HANDLEUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(SC_5, 17, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -269,11 +269,11 @@ void sceneHandler05_testHatch(Command *inex) {
mq->setFlags(mq->getFlags() | 1);
- ex = new Command(ANI_OTMOROZ, 1, MV_OTM_BOXHANDLEUP, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_OTMOROZ, kCmdStartMovement, MV_OTM_BOXHANDLEUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(SC_5, 17, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -289,11 +289,11 @@ void sceneHandler05_testHatch(Command *inex) {
mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
mq->setFlags(mq->getFlags() | 1);
- ex = new Command(ANI_OTMOROZ, 1, MV_OTM_BOXHANDLEUP, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_OTMOROZ, kCmdStartMovement, MV_OTM_BOXHANDLEUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(SC_5, 17, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -303,7 +303,7 @@ void sceneHandler05_testHatch(Command *inex) {
return;
} else {
- ex = new Command(SC_5, 17, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
ex->postMessage();
@@ -314,7 +314,7 @@ void sceneHandler05_testHatch(Command *inex) {
int sceneHandler05(Command *ex) {
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
switch (ex->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene06.cpp b/engines/ngi/fullpipe/scene06.cpp
index 89efa98a227..7a3f8e2a78c 100644
--- a/engines/ngi/fullpipe/scene06.cpp
+++ b/engines/ngi/fullpipe/scene06.cpp
@@ -163,7 +163,7 @@ void sceneHandler06_mumsyBallTake() {
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- Command *ex = new Command(ANI_MAMASHA, 2, 50, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_MAMASHA, kCmdSetAniQueue, 50, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2u;
mq->addCommandToEnd(ex);
@@ -174,51 +174,51 @@ void sceneHandler06_mumsyBallTake() {
if (g_nmi->getStateId(sO_ClockAxis) == g_nmi->getStateValue(sO_ClockAxis, sO_IsNotAvailable))
g_nmi->setState(sO_ClockAxis, g_nmi->getStateValue(sO_ClockAxis, sO_WithoutHandle));
- ex = new Command(ANI_MAMASHA, 1, momAni, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAMASHA, kCmdStartMovement, momAni, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
if (g_vars->scene06_mumsyPos + 3 >= 0) {
- ex = new Command(ANI_MAMASHA, 1, MV_MOM_STARTBK, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAMASHA, kCmdStartMovement, MV_MOM_STARTBK, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2u;
mq->addCommandToEnd(ex);
for (int i = 0; i < g_vars->scene06_mumsyPos + 3; i++) {
- ex = new Command(ANI_MAMASHA, 1, MV_MOM_CYCLEBK, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAMASHA, kCmdStartMovement, MV_MOM_CYCLEBK, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
}
- ex = new Command(ANI_MAMASHA, 1, MV_MOM_STOPBK, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAMASHA, kCmdStartMovement, MV_MOM_STOPBK, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
}
- ex = new Command(0, 18, QU_MOM_TOLIFT, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdQueue, QU_MOM_TOLIFT, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
} else {
if (momAni) {
- ex = new Command(ANI_MAMASHA, 1, momAni, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAMASHA, kCmdStartMovement, momAni, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
}
if (g_vars->scene06_mumsyPos < 0) {
for (int i = 0; i > g_vars->scene06_mumsyPos; i--) {
- ex = new Command(ANI_MAMASHA, 1, MV_MOM_JUMPFW, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAMASHA, kCmdStartMovement, MV_MOM_JUMPFW, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
}
} else if (g_vars->scene06_mumsyPos > 0) {
for (int i = 0; i < g_vars->scene06_mumsyPos; i++) {
- ex = new Command(ANI_MAMASHA, 1, MV_MOM_JUMPBK, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAMASHA, kCmdStartMovement, MV_MOM_JUMPBK, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
}
}
- ex = new Command(0, 18, QU_MOM_SITDOWN, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdQueue, QU_MOM_SITDOWN, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3u;
mq->addCommandToEnd(ex);
}
@@ -316,7 +316,7 @@ void sceneHandler06_takeBall() {
MessageQueue *mq = getCurrSceneSc2MotionController()->startMove(g_nmi->_aniMan, 1158, 452, 1, (0x4000 | ST_MAN_RIGHT));
if (mq) {
- Command *ex = new Command(0, 17, MSG_SC6_TAKEBALL, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC6_TAKEBALL, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -536,7 +536,7 @@ void scene06_initScene(Scene *sc) {
}
int sceneHandler06(Command *ex) {
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
switch(ex->_messageNum) {
@@ -644,7 +644,7 @@ int sceneHandler06(Command *ex) {
if (st) {
if (!g_vars->scene06_arcadeEnabled && st->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(st);
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
return 0;
}
@@ -652,7 +652,7 @@ int sceneHandler06(Command *ex) {
if (g_vars->scene06_numBallsGiven == 1)
sceneHandler06_takeBall();
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
} else if (g_vars->scene06_ballInHands && g_nmi->_aniMan == st && !g_nmi->_aniMan->_movement && g_nmi->_aniMan->_statics->_staticsId == ST_MAN6_BALL) {
g_vars->scene06_sceneClickX = ex->_sceneClickX;
g_vars->scene06_sceneClickY = ex->_sceneClickY;
diff --git a/engines/ngi/fullpipe/scene07.cpp b/engines/ngi/fullpipe/scene07.cpp
index f86d76b30b8..8d74d2d52bc 100644
--- a/engines/ngi/fullpipe/scene07.cpp
+++ b/engines/ngi/fullpipe/scene07.cpp
@@ -116,7 +116,7 @@ void sceneHandler07_hideBox() {
}
int sceneHandler07(Command *ex) {
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
switch(ex->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene08.cpp b/engines/ngi/fullpipe/scene08.cpp
index 391449e44bb..b463fdb5a21 100644
--- a/engines/ngi/fullpipe/scene08.cpp
+++ b/engines/ngi/fullpipe/scene08.cpp
@@ -302,7 +302,7 @@ void sceneHandler08_jumpLogic(Command *cmd) {
if (g_nmi->_currentScene->getPictureObjectIdAtPos(cmd->_sceneClickX, cmd->_sceneClickY) == PIC_SC8_LADDERD) {
sceneHandler08_jumpOff(cmd);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
} else {
sceneHandler08_standUp();
}
@@ -317,7 +317,7 @@ void sceneHandler08_badLuck() {
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- Command *ex = new Command(g_nmi->_aniMan->_id, 1, MV_MAN8_BADLUCK, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(g_nmi->_aniMan->_id, kCmdStartMovement, MV_MAN8_BADLUCK, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_param = g_nmi->_aniMan->_copyId;
mq->addCommandToEnd(ex);
@@ -414,7 +414,7 @@ void sceneHandler08_checkEndArcade() {
return;
}
- Command *ex = new Command(SC_8, 17, 0, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(SC_8, kCmdMessage, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_messageNum = 61;
ex->_excFlags |= 2;
ex->_param = TrubaUp;
@@ -425,7 +425,7 @@ void sceneHandler08_checkEndArcade() {
}
int sceneHandler08(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene09.cpp b/engines/ngi/fullpipe/scene09.cpp
index 6acd61ffaf9..d0a3fcf384e 100644
--- a/engines/ngi/fullpipe/scene09.cpp
+++ b/engines/ngi/fullpipe/scene09.cpp
@@ -200,7 +200,7 @@ void sceneHandler09_spitterClick() {
MessageQueue *mq = getCurrSceneSc2MotionController()->startMove(g_nmi->_aniMan, x, y, 1, ST_MAN_UP);
if (mq) {
- Command *ex = new Command(0, 17, MSG_SC9_PLVCLICK, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC9_PLVCLICK, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
mq->addCommandToEnd(ex);
@@ -240,7 +240,7 @@ void sceneHandler09_eatBall() {
MessageQueue *mq = g_vars->scene09_gulper->getMessageQueue();
if (mq) {
- Command *ex = new Command(ANI_GLOTATEL, 1, MV_GLT_FLYAWAY, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_GLOTATEL, kCmdStartMovement, MV_GLT_FLYAWAY, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -399,7 +399,7 @@ void sceneHandler09_hangerStartCycle() {
g_vars->scene09_hangers[g_vars->scene09_interactingHanger]->phase = g_vars->scene09_intHangerPhase + (g_nmi->_mouseScreenPos.y - g_vars->scene09_clickY) / 2;
if (g_vars->scene09_intHangerMaxPhase != -1000 && g_vars->scene09_hangers[g_vars->scene09_interactingHanger]->phase != g_vars->scene09_intHangerMaxPhase) {
- Command *ex = new Command(0, 35, SND_9_019, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdSound, SND_9_019, 0, 0, 0, 1, 0, 0, 0);
ex->_z = 1;
ex->_excFlags |= 2;
@@ -417,7 +417,7 @@ void scene09_visCallback(int *phase) {
}
int sceneHandler09(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -551,7 +551,7 @@ int sceneHandler09(Command *cmd) {
g_vars->scene09_hangers[hng]->ani->_callback2 = scene09_visCallback;
}
- Command *ex = new Command(0, 35, SND_9_018, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdSound, SND_9_018, 0, 0, 0, 1, 0, 0, 0);
ex->_z = 1;
ex->_excFlags |= 2;
diff --git a/engines/ngi/fullpipe/scene10.cpp b/engines/ngi/fullpipe/scene10.cpp
index c36b33d7504..bfc957419c8 100644
--- a/engines/ngi/fullpipe/scene10.cpp
+++ b/engines/ngi/fullpipe/scene10.cpp
@@ -83,7 +83,7 @@ void sceneHandler10_clickGum() {
if (abs(x - g_nmi->_aniMan->_x) > 1 || abs(y - g_nmi->_aniMan->_y) > 1) {
MessageQueue *mq = getCurrSceneSc2MotionController()->startMove(g_nmi->_aniMan, x, y, 1, ST_MAN_RIGHT);
if (mq) {
- Command *ex = new Command(0, 17, MSG_SC10_CLICKGUM, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC10_CLICKGUM, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
mq->addCommandToEnd(ex);
@@ -122,7 +122,7 @@ void sceneHandler10_showGum() {
int sceneHandler10(Command *ex) {
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
switch(ex->_messageNum) {
@@ -157,7 +157,7 @@ int sceneHandler10(Command *ex) {
case MSG_SC10_CLICKGUM:
sceneHandler10_clickGum();
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
break;
case MSG_SC10_HIDEGUM:
@@ -176,7 +176,7 @@ int sceneHandler10(Command *ex) {
{
if (g_nmi->_currentScene->getPictureObjectIdAtPos(ex->_sceneClickX, ex->_sceneClickY) == PIC_SC10_LADDER) {
handleObjectInteraction(g_nmi->_aniMan, g_nmi->_currentScene->findPictureObjectById(PIC_SC10_DTRUBA, 0), ex->_param);
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
return 0;
}
@@ -185,7 +185,7 @@ int sceneHandler10(Command *ex) {
if (ani && ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
return 0;
}
diff --git a/engines/ngi/fullpipe/scene11.cpp b/engines/ngi/fullpipe/scene11.cpp
index cf81507d222..2cbd85a1106 100644
--- a/engines/ngi/fullpipe/scene11.cpp
+++ b/engines/ngi/fullpipe/scene11.cpp
@@ -272,7 +272,7 @@ void sceneHandler11_putBoot() {
MessageQueue *mq = getCurrSceneSc2MotionController()->startMove(g_nmi->_aniMan, 353, 498, 1, ST_MAN_RIGHT);
if (mq) {
- Command *ex = new Command(0, 17, MSG_SC11_PUTBOOT, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC11_PUTBOOT, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -314,7 +314,7 @@ void sceneHandler11_jumpFromSwing() {
g_vars->scene11_dudeOnSwing->_flags |= 4;
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- Command *ex = new Command(g_nmi->_aniMan->_id, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(g_nmi->_aniMan->_id, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
ex->_z = 256;
ex->_messageNum = 0;
ex->_excFlags |= 3;
@@ -414,13 +414,13 @@ void sceneHandler11_jumpHitAndWin() {
if (mq) {
g_vars->scene11_crySound = SND_11_024;
- Command *ex = new Command(ANI_MAN, 2, 36, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_MAN, kCmdSetAniQueue, 36, 0, 0, 0, 1, 0, 0, 0);
ex->_param = -1;
ex->_excFlags = 2;
mq->addCommandToEnd(ex);
- ex = new Command(SC_11, 17, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_11, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaRight;
ex->_excFlags = 3;
@@ -460,7 +460,7 @@ void sceneHandler11_jumpOver(double angle) {
if (mq) {
g_vars->scene11_crySound = SND_11_022;
- Command *ex = new Command(0, 17, MSG_SC11_RESTARTMAN, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC11_RESTARTMAN, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
mq->addCommandToEnd(ex);
@@ -500,7 +500,7 @@ void sceneHandler11_jumpHit(double angle) {
if (mq) {
g_vars->scene11_crySound = SND_11_022;
- Command *ex = new Command(0, 17, MSG_SC11_RESTARTMAN, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC11_RESTARTMAN, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
mq->addCommandToEnd(ex);
@@ -588,7 +588,7 @@ void sceneHandler11_winArcade() {
}
int sceneHandler11(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene12.cpp b/engines/ngi/fullpipe/scene12.cpp
index 8d5841b27fe..70f2346ac53 100644
--- a/engines/ngi/fullpipe/scene12.cpp
+++ b/engines/ngi/fullpipe/scene12.cpp
@@ -57,7 +57,7 @@ void sceneHandler12_updateFloaters() {
int sceneHandler12(Command *cmd) {
int res = 0;
- if (cmd->_cmd == 17 && cmd->_messageNum == 33) {
+ if (cmd->_cmd == kCmdMessage && cmd->_messageNum == 33) {
if (g_nmi->_aniMan2) {
if (g_nmi->_aniMan2->_x < g_nmi->_sceneRect.left + 200)
g_nmi->_currentScene->_x = g_nmi->_aniMan2->_x - g_nmi->_sceneRect.left - 300;
diff --git a/engines/ngi/fullpipe/scene13.cpp b/engines/ngi/fullpipe/scene13.cpp
index 10d5f7eae28..10cce82ca32 100644
--- a/engines/ngi/fullpipe/scene13.cpp
+++ b/engines/ngi/fullpipe/scene13.cpp
@@ -260,7 +260,7 @@ void sceneHandler13_walkBackward(bool flag) {
}
int sceneHandler13(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch(cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene14.cpp b/engines/ngi/fullpipe/scene14.cpp
index 7117a9f17b2..b47aa4090a1 100644
--- a/engines/ngi/fullpipe/scene14.cpp
+++ b/engines/ngi/fullpipe/scene14.cpp
@@ -140,14 +140,14 @@ void sceneHandler14_showBallGrandmaHit() {
g_vars->scene14_flyingBall->_z = 27;
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- Command *ex = new Command(ANI_BALL14, 1, MV_BAL14_TOGMA, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_BALL14, kCmdStartMovement, MV_BAL14_TOGMA, 0, 0, 0, 1, 0, 0, 0);
ex->_param = g_vars->scene14_flyingBall->_copyId;
ex->_excFlags |= 2;
ex->_wait = 1;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_BALL14, 6, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_BALL14, kCmdHide, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_param = g_vars->scene14_flyingBall->_copyId;
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -182,14 +182,14 @@ void sceneHandler14_showBallMan() {
g_vars->scene14_flyingBall->_z = 27;
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- Command *ex = new Command(ANI_BALL14, 1, MV_BAL14_TOGMA, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_BALL14, kCmdStartMovement, MV_BAL14_TOGMA, 0, 0, 0, 1, 0, 0, 0);
ex->_param = g_vars->scene14_flyingBall->_copyId;
ex->_excFlags |= 2;
ex->_wait = 1;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_BALL14, 6, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_BALL14, kCmdHide, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_param = g_vars->scene14_flyingBall->_copyId;
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -437,7 +437,7 @@ bool sceneHandler14_arcadeProcessClick(Command *cmd) {
if (g_vars->scene14_pink->_flags & 4) {
if (cmd->_sceneClickX < g_vars->scene14_pink->_x + 40) {
handleObjectInteraction(g_nmi->_aniMan, g_vars->scene14_pink, 0);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
return true;
}
}
@@ -460,7 +460,7 @@ bool sceneHandler14_arcadeProcessClick(Command *cmd) {
if (!mq)
return false;
- Command *ex = new Command(0, 17, MSG_SC14_STARTARCADE, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC14_STARTARCADE, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -468,7 +468,7 @@ bool sceneHandler14_arcadeProcessClick(Command *cmd) {
postExCommand(g_nmi->_aniMan->_id, 2, 1237, 451, 0, -1);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
getCurrSceneSc2MotionController()->deactivate();
getGameLoaderInteractionController()->disable();
@@ -479,12 +479,12 @@ void sceneHandler14_grandmaThrow() {
g_vars->scene14_grandma->setStatic(ST_GMA_SIT);
MessageQueue *mq = new MessageQueue(0);
- Command *ex = new Command(ANI_GRANDMA, 2, 30, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_GRANDMA, kCmdSetAniQueue, 30, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_GRANDMA, 1, MV_GMA_THROW, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_GRANDMA, kCmdStartMovement, MV_GMA_THROW, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -496,14 +496,14 @@ void sceneHandler14_passToGrandma() {
g_vars->scene14_flyingBall->_z = 27;
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- Command *ex = new Command(ANI_BALL14, 1, MV_BAL14_FALL, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_BALL14, kCmdStartMovement, MV_BAL14_FALL, 0, 0, 0, 1, 0, 0, 0);
ex->_param = g_vars->scene14_flyingBall->_copyId;
ex->_excFlags |= 2;
ex->_wait = 1;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_BALL14, 6, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_BALL14, kCmdHide, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_param = g_vars->scene14_flyingBall->_copyId;
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -519,16 +519,16 @@ void sceneHandler14_grandmaJumpThrow() {
g_vars->scene14_grandma->setStatic(ST_GMA_SIT);
MessageQueue *mq = new MessageQueue(0);
- Command *ex = new Command(ANI_GRANDMA, 2, 30, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_GRANDMA, kCmdSetAniQueue, 30, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_GRANDMA, 1, MV_GMA_JUMPFW, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_GRANDMA, kCmdStartMovement, MV_GMA_JUMPFW, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_GRANDMA, 1, MV_GMA_THROW, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_GRANDMA, kCmdStartMovement, MV_GMA_THROW, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -590,11 +590,11 @@ void sceneHandler14_arcadeLogic() {
if (g_vars->scene14_hitsLeft != 3 || g_vars->scene14_pink) {
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- ex = new Command(ANI_GRANDMA, 1, MV_GMA_BACKOFF, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_GRANDMA, kCmdStartMovement, MV_GMA_BACKOFF, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_GRANDMA, 1, MV_GMA_THROW, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_GRANDMA, kCmdStartMovement, MV_GMA_THROW, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -602,11 +602,11 @@ void sceneHandler14_arcadeLogic() {
} else {
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- ex = new Command(ANI_GRANDMA, 1, MV_GMA_BACKOFF2, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_GRANDMA, kCmdStartMovement, MV_GMA_BACKOFF2, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(ANI_GRANDMA, 1, MV_GMA_THROW, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_GRANDMA, kCmdStartMovement, MV_GMA_THROW, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -650,7 +650,7 @@ void sceneHandler14_animateBall() {
}
int sceneHandler14(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch(cmd->_messageNum) {
@@ -818,7 +818,7 @@ int sceneHandler14(Command *cmd) {
if (ani && ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
diff --git a/engines/ngi/fullpipe/scene15.cpp b/engines/ngi/fullpipe/scene15.cpp
index a1345edaf35..e5a55a9f467 100644
--- a/engines/ngi/fullpipe/scene15.cpp
+++ b/engines/ngi/fullpipe/scene15.cpp
@@ -100,7 +100,7 @@ int scene15_updateCursor() {
}
int sceneHandler15(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch(cmd->_messageNum) {
@@ -162,7 +162,7 @@ int sceneHandler15(Command *cmd) {
{
if (g_nmi->_currentScene->getPictureObjectIdAtPos(cmd->_sceneClickX, cmd->_sceneClickY) == PIC_SC15_LADDER) {
handleObjectInteraction(g_nmi->_aniMan, g_nmi->_currentScene->findPictureObjectById(PIC_SC15_DTRUBA, 0), cmd->_param);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
return 0;
}
@@ -172,7 +172,7 @@ int sceneHandler15(Command *cmd) {
if (ani && ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
}
break;
diff --git a/engines/ngi/fullpipe/scene16.cpp b/engines/ngi/fullpipe/scene16.cpp
index f3b5a360080..83057841528 100644
--- a/engines/ngi/fullpipe/scene16.cpp
+++ b/engines/ngi/fullpipe/scene16.cpp
@@ -260,7 +260,7 @@ void sceneHandler16_drink() {
mq->setObjectCopy(-1, g_vars->scene16_walkingBoy->_copyId);
- ex = new Command(ANI_MAN, 34, 384, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAN, kCmdSetFlags, 384, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3u;
ex->_z = 384;
ex->_messageNum = 0;
@@ -273,7 +273,7 @@ void sceneHandler16_drink() {
mq = new MessageQueue(g_nmi->_currentScene->findMessageQueue(QU_SC16_MANDRINK), 0, 1);
- ex = new Command(ANI_MAN, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAN, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3u;
ex->_z = 256;
ex->_messageNum = 0;
@@ -301,7 +301,7 @@ void sceneHandler16_onMugClick() {
MessageQueue *mq = getCurrSceneSc2MotionController()->startMove(g_nmi->_aniMan, 310, 449, 1, ST_MAN_RIGHT);
if (mq) {
- Command *ex = new Command(0, 17, MSG_SC16_MUGCLICK, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC16_MUGCLICK, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
mq->addCommandToEnd(ex);
@@ -390,7 +390,7 @@ void sceneHandler16_girlROTFL() {
}
int sceneHandler16(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch(cmd->_messageNum) {
@@ -416,7 +416,7 @@ int sceneHandler16(Command *cmd) {
case MSG_SC16_MUGCLICK:
if (!g_nmi->_aniMan->isIdle() || g_nmi->_aniMan->_flags & 0x100) {
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
} else {
sceneHandler16_onMugClick();
}
diff --git a/engines/ngi/fullpipe/scene17.cpp b/engines/ngi/fullpipe/scene17.cpp
index 20d4d5c6a34..7b8f3bdb888 100644
--- a/engines/ngi/fullpipe/scene17.cpp
+++ b/engines/ngi/fullpipe/scene17.cpp
@@ -163,7 +163,7 @@ void sceneHandler17_updateFlies() {
int sceneHandler17(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene18and19.cpp b/engines/ngi/fullpipe/scene18and19.cpp
index b1a2f4a5c11..e2b196c9d09 100644
--- a/engines/ngi/fullpipe/scene18and19.cpp
+++ b/engines/ngi/fullpipe/scene18and19.cpp
@@ -379,7 +379,7 @@ int scene19_updateCursor() {
void sceneHandler18_clickBoard() {
if (ABS(967 - g_nmi->_aniMan->_x) > 1 || ABS(379 - g_nmi->_aniMan->_y) > 1 || g_nmi->_aniMan->_statics->_staticsId != ST_MAN_RIGHT) {
MessageQueue *mq = getCurrSceneSc2MotionController()->startMove(g_nmi->_aniMan, 967, 379, 1, ST_MAN_RIGHT);
- Command *ex = new Command(0, 17, MSG_SC18_MANREADY, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC18_MANREADY, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
@@ -684,7 +684,7 @@ void sceneHandler18and19_animateRiders() {
}
int sceneHandler18(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -727,7 +727,7 @@ int sceneHandler18(Command *cmd) {
case 29:
{
if (g_vars->scene18_enteredTrubaRight) {
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
@@ -741,7 +741,7 @@ int sceneHandler18(Command *cmd) {
&& (g_vars->scene18_domino->_flags & 4) && g_nmi->_aniMan->isIdle()) {
if (!(g_nmi->_aniMan->_flags & 0x100) && g_nmi->_msgObjectId2 != g_vars->scene18_domino->_id) {
handleObjectInteraction(g_nmi->_aniMan, g_vars->scene18_domino, cmd->_param);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
@@ -822,7 +822,7 @@ void sceneHandler19_updateNumRides() {
}
int sceneHandler19(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -856,25 +856,25 @@ int sceneHandler19(Command *cmd) {
case PIC_SC19_RTRUBA1:
g_vars->scene18_jumpDistance = 1;
g_vars->scene18_jumpAngle = 331;
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
case PIC_SC19_RTRUBA2:
g_vars->scene18_jumpDistance = 2;
g_vars->scene18_jumpAngle = 350;
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
case PIC_SC19_RTRUBA3:
g_vars->scene18_jumpDistance = 3;
g_vars->scene18_jumpAngle = 9;
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
default:
g_vars->scene18_jumpDistance = -1;
g_vars->scene18_jumpAngle = -1;
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
} else {
diff --git a/engines/ngi/fullpipe/scene20.cpp b/engines/ngi/fullpipe/scene20.cpp
index a6917e0101a..36ea1f84496 100644
--- a/engines/ngi/fullpipe/scene20.cpp
+++ b/engines/ngi/fullpipe/scene20.cpp
@@ -115,7 +115,7 @@ void sceneHandler20_updateFlies() {
}
int sceneHandler20(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene21.cpp b/engines/ngi/fullpipe/scene21.cpp
index c93621ad0ba..dfde82ace8d 100644
--- a/engines/ngi/fullpipe/scene21.cpp
+++ b/engines/ngi/fullpipe/scene21.cpp
@@ -80,7 +80,7 @@ void sceneHandler21_doWiggle() {
}
int sceneHandler21(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene22.cpp b/engines/ngi/fullpipe/scene22.cpp
index d1bdb135023..f87301f49b4 100644
--- a/engines/ngi/fullpipe/scene22.cpp
+++ b/engines/ngi/fullpipe/scene22.cpp
@@ -291,7 +291,7 @@ void sceneHandler22_stoolLogic(Command *cmd) {
}
int sceneHandler22(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -363,7 +363,7 @@ int sceneHandler22(Command *cmd) {
}
}
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
case 33:
diff --git a/engines/ngi/fullpipe/scene23.cpp b/engines/ngi/fullpipe/scene23.cpp
index 3fb04ef0017..4be9a427cb7 100644
--- a/engines/ngi/fullpipe/scene23.cpp
+++ b/engines/ngi/fullpipe/scene23.cpp
@@ -367,7 +367,7 @@ void sceneHandler23_sendClick(AniObject *ani) {
break;
}
- Command *ex = new Command(0, 17, msg, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, msg, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->postMessage();
@@ -411,12 +411,12 @@ void sceneHandler23_fromStool(Command *cmd) {
mq->setFlags(mq->getFlags() | 1);
mq->run(nullptr);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
}
int sceneHandler23(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -499,7 +499,7 @@ int sceneHandler23(Command *cmd) {
if (ani && ani->_id == ANI_CALENDWHEEL) {
sceneHandler23_sendClick(ani);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
sceneHandler23_checkReachingTop();
@@ -510,14 +510,14 @@ int sceneHandler23(Command *cmd) {
if (picId == PIC_SC23_LADDER) {
sceneHandler23_exitCalendar();
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
if (cmd->_sceneClickY > 450) {
sceneHandler23_fromCalendar(cmd);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
break;
@@ -529,7 +529,7 @@ int sceneHandler23(Command *cmd) {
if (picId == PIC_SC23_LADDERU && !g_vars->scene23_topReached) {
sceneHandler23_pushButton(cmd);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
break;
@@ -537,11 +537,11 @@ int sceneHandler23(Command *cmd) {
if (ani && ani->_id == ANI_HANDLE23) {
handleObjectInteraction(g_nmi->_aniMan, ani, cmd->_param);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
} else {
sceneHandler23_fromStool(cmd);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
}
diff --git a/engines/ngi/fullpipe/scene24.cpp b/engines/ngi/fullpipe/scene24.cpp
index 5ef483e33ab..510ef7fc4f3 100644
--- a/engines/ngi/fullpipe/scene24.cpp
+++ b/engines/ngi/fullpipe/scene24.cpp
@@ -97,7 +97,7 @@ void scene24_setPoolState() {
}
int sceneHandler24(Command *cmd) {
- if (cmd->_cmd == 17 && cmd->_messageNum == 33) {
+ if (cmd->_cmd == kCmdMessage && cmd->_messageNum == 33) {
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene25.cpp b/engines/ngi/fullpipe/scene25.cpp
index ecc814f2121..2aebab8421c 100644
--- a/engines/ngi/fullpipe/scene25.cpp
+++ b/engines/ngi/fullpipe/scene25.cpp
@@ -457,7 +457,7 @@ void sceneHandler25_walkOnLadder(AniObject *ani, Common::Point *pnt, MessageQueu
ex = mq->getCommandByIndex(i);
- if (ex->_cmd == 1 && ani->_id == ex->_parentId) {
+ if (ex->_cmd == kCmdStartMovement && ani->_id == ex->_parentId) {
if (ex->_excFlags & 0x10000) {
if (ex->_messageNum == MV_MAN_TOLADDER)
ex->_messageNum = MV_MAN_TOLADDER2;
@@ -486,7 +486,7 @@ void sceneHandler25_walkOnLadder(AniObject *ani, Common::Point *pnt, MessageQueu
for (int i = 0; i < numObsolete; i++)
mq->removeCommand(0, 1);
- ex = new Command(ani->_id, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ani->_id, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
ex->_z = 256;
ex->_messageNum = 0;
@@ -544,7 +544,7 @@ bool sceneHandler25_isOnLadder(Command *cmd) {
}
int sceneHandler25(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -639,7 +639,7 @@ int sceneHandler25(Command *cmd) {
if (!g_vars->scene25_waterIsPresent) {
if ((picId == PIC_SC25_LADDERUP || picId == PIC_SC25_LADDERDOWN) && sceneHandler25_isOnLadder(cmd))
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
return 0;
}
@@ -683,7 +683,7 @@ int sceneHandler25(Command *cmd) {
}
if (picId == PIC_SC25_LADDERUP && sceneHandler25_isOnLadder(cmd))
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
if (!g_nmi->_aniMan->isIdle() || (g_nmi->_aniMan->_flags & 0x100))
return 0;
diff --git a/engines/ngi/fullpipe/scene26.cpp b/engines/ngi/fullpipe/scene26.cpp
index 208867f83aa..6460580ceab 100644
--- a/engines/ngi/fullpipe/scene26.cpp
+++ b/engines/ngi/fullpipe/scene26.cpp
@@ -264,7 +264,7 @@ void sceneHandler26_clickVent(AniObject *ani, Command *cmd) {
MessageQueue *mq = getCurrSceneSc2MotionController()->startMove(g_nmi->_aniMan, x, y, 1, ST_MAN_UP);
if (mq) {
- Command *ex = new Command(0, 17, MSG_SC26_CLICKVENT, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC26_CLICKVENT, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = ani->_copyId;
@@ -279,11 +279,11 @@ void sceneHandler26_clickVent(AniObject *ani, Command *cmd) {
}
}
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
int sceneHandler26(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene27.cpp b/engines/ngi/fullpipe/scene27.cpp
index 22f7d39d1d9..f59d10dd5c8 100644
--- a/engines/ngi/fullpipe/scene27.cpp
+++ b/engines/ngi/fullpipe/scene27.cpp
@@ -489,11 +489,11 @@ void sceneHandler27_batLogic() {
mq->setFlags(mq->getFlags() | 1);
- Command *ex = new Command(g_vars->scene27_batHandler->_id, 1, mv, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(g_vars->scene27_batHandler->_id, kCmdStartMovement, mv, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(0, 17, MSG_SC27_CLICKBET, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, MSG_SC27_CLICKBET, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -617,7 +617,7 @@ void sceneHandler27_animateBats() {
}
int sceneHandler27(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene28.cpp b/engines/ngi/fullpipe/scene28.cpp
index 79d95b0d378..f46d2b9c5fb 100644
--- a/engines/ngi/fullpipe/scene28.cpp
+++ b/engines/ngi/fullpipe/scene28.cpp
@@ -266,7 +266,7 @@ void sceneHandler28_clickLift(int numLift) {
MessageQueue *mq = getCurrSceneSc2MotionController()->startMove(g_nmi->_aniMan, x, 472, 1, ST_MAN_UP);
if (mq) {
- Command *ex = new Command(0, 17, MSG_SC28_CLICKLIFT, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_SC28_CLICKLIFT, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = numLift;
@@ -304,7 +304,7 @@ void sceneHandler28_clickLift(int numLift) {
}
int sceneHandler28(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -414,7 +414,7 @@ int sceneHandler28(Command *cmd) {
if (ani->_id == ANI_LIFT || ani->_id == ANI_LIFT_28 ) {
sceneHandler28_clickLift(ani->_copyId);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
diff --git a/engines/ngi/fullpipe/scene29.cpp b/engines/ngi/fullpipe/scene29.cpp
index a9427830b79..ea446bbb4df 100644
--- a/engines/ngi/fullpipe/scene29.cpp
+++ b/engines/ngi/fullpipe/scene29.cpp
@@ -286,12 +286,12 @@ void sceneHandler29_manHit() {
if (mq) {
if (g_vars->scene29_manX <= 638) {
- ex = new Command(ANI_MAN, 1, MV_MAN29_STANDUP_NORM, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAN, kCmdStartMovement, MV_MAN29_STANDUP_NORM, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
ex->_param = g_nmi->_aniMan->_copyId;
mq->addCommandToEnd(ex);
- ex = new Command(0, 17, MSG_SC29_STOPRIDE, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, MSG_SC29_STOPRIDE, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
mq->addCommandToEnd(ex);
@@ -300,7 +300,7 @@ void sceneHandler29_manHit() {
g_vars->scene29_reachedFarRight = false;
g_vars->scene29_rideBackEnabled = false;
} else {
- ex = new Command(ANI_MAN, 1, MV_MAN29_STANDUP, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ANI_MAN, kCmdStartMovement, MV_MAN29_STANDUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
ex->_param = g_nmi->_aniMan->_copyId;
mq->addCommandToEnd(ex);
@@ -474,7 +474,7 @@ void sceneHandler29_manToR() {
void sceneHandler29_clickPorter(Command *cmd) {
if (!g_nmi->_aniMan->isIdle() || g_nmi->_aniMan->_flags & 0x100) {
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
return;
}
@@ -675,7 +675,7 @@ void sceneHandler29_animBearded() {
int sceneHandler29(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -757,12 +757,12 @@ int sceneHandler29(Command *cmd) {
if (ani && ani == g_vars->scene29_porter) {
sceneHandler29_clickPorter(cmd);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
} else {
sceneHandler29_manJump();
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
}
break;
diff --git a/engines/ngi/fullpipe/scene30.cpp b/engines/ngi/fullpipe/scene30.cpp
index 650f284deaf..e104aefd56e 100644
--- a/engines/ngi/fullpipe/scene30.cpp
+++ b/engines/ngi/fullpipe/scene30.cpp
@@ -85,7 +85,7 @@ int scene30_updateCursor() {
}
int sceneHandler30(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch(cmd->_messageNum) {
@@ -124,7 +124,7 @@ int sceneHandler30(Command *cmd) {
if (ani && ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
}
break;
diff --git a/engines/ngi/fullpipe/scene31.cpp b/engines/ngi/fullpipe/scene31.cpp
index 0823798e2f7..9979cef5525 100644
--- a/engines/ngi/fullpipe/scene31.cpp
+++ b/engines/ngi/fullpipe/scene31.cpp
@@ -64,17 +64,17 @@ void sceneHandler31_testCactus(Command *cmd) {
MessageQueue *mq = g_nmi->_globalMessageQueueList->getMessageQueueById(cmd->_parId);
if (mq) {
- mq->getCommandByIndex(0)->_cmd = 0;
+ mq->getCommandByIndex(0)->_cmd = kCmdNone;
mq->getCommandByIndex(0)->_excFlags |= 1;
- mq->getCommandByIndex(1)->_cmd = 0;
+ mq->getCommandByIndex(1)->_cmd = kCmdNone;
mq->getCommandByIndex(1)->_excFlags |= 1;
}
}
}
int sceneHandler31(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene32.cpp b/engines/ngi/fullpipe/scene32.cpp
index 0255d775c6c..7048dd1ee4a 100644
--- a/engines/ngi/fullpipe/scene32.cpp
+++ b/engines/ngi/fullpipe/scene32.cpp
@@ -187,11 +187,11 @@ void sceneHandler32_trySit(Command *cmd) {
if (g_vars->scene32_cactusIsGrowing || g_vars->scene32_cactus->_movement
|| g_vars->scene32_cactus->_statics->_staticsId != ST_CTS_EMPTY
|| (g_vars->scene32_cactusCounter >= 0 && g_vars->scene32_cactusCounter <= 20)) {
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
ex->_excFlags |= 1;
} else {
ex->_parentId = ANI_MAN;
- ex->_cmd = 1;
+ ex->_cmd = kCmdStartMovement;
ex->_messageNum = MV_MAN32_SITDOWN;
ex->_param = g_nmi->_aniMan->_copyId;
@@ -252,7 +252,7 @@ void sceneHandler32_potLogic(Command *cmd) {
if (g_vars->scene32_cactusCounter < 0 || g_vars->scene32_cactusCounter > 20) {
MessageQueue *mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- Command *ex = new Command(ANI_MAN, 1, MV_MAN32_STANDUP, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_MAN, kCmdStartMovement, MV_MAN32_STANDUP, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
@@ -274,7 +274,7 @@ void sceneHandler32_potLogic(Command *cmd) {
}
int sceneHandler32(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -405,7 +405,7 @@ int sceneHandler32(Command *cmd) {
case 29:
if (g_vars->scene32_dudeOnLadder) {
sceneHandler32_ladderLogic(cmd);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
@@ -415,7 +415,7 @@ int sceneHandler32(Command *cmd) {
if (ani && ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
@@ -430,7 +430,7 @@ int sceneHandler32(Command *cmd) {
if (!g_vars->scene32_cactusIsGrowing)
sceneHandler32_potLogic(cmd);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
diff --git a/engines/ngi/fullpipe/scene33.cpp b/engines/ngi/fullpipe/scene33.cpp
index b5cdcd9d3d2..5dfe2093da1 100644
--- a/engines/ngi/fullpipe/scene33.cpp
+++ b/engines/ngi/fullpipe/scene33.cpp
@@ -81,14 +81,14 @@ void sceneHandler33_processJettie(Command *cmd) {
Command *ex = mq->getCommandByIndex(0);
if (ex) {
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
ex->_excFlags |= 1;
}
ex = mq->getCommandByIndex(1);
if (ex) {
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
ex->_excFlags |= 1;
}
}
@@ -229,7 +229,7 @@ void sceneHandler33_clickZones(Command *cmd) {
}
int sceneHandler33(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene34.cpp b/engines/ngi/fullpipe/scene34.cpp
index 6162b99b4bd..2f64aac25db 100644
--- a/engines/ngi/fullpipe/scene34.cpp
+++ b/engines/ngi/fullpipe/scene34.cpp
@@ -168,14 +168,14 @@ void sceneHandler34_genFlies() {
void sceneHandler34_fromCactus(Command *cmd) {
if (g_nmi->_aniMan->_movement || g_vars->scene34_cactus->_movement || (g_nmi->_aniMan->_flags & 0x100)) {
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
return;
}
MessageQueue *mq = new MessageQueue(g_nmi->_currentScene->findMessageQueue(QU_SC34_FROMCACTUS), 0, 0);
- Command *ex = new Command(ANI_MAN, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_MAN, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
ex->_messageNum = 0;
ex->_excFlags |= 3;
@@ -200,7 +200,7 @@ void sceneHandler34_animateLeaveBoard(Command *cmd) {
mq->run(nullptr);
}
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
void sceneHandler34_animateAction(Command *cmd) {
@@ -295,7 +295,7 @@ void sceneHandler34_unclimb() {
}
int sceneHandler34(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -419,13 +419,13 @@ int sceneHandler34(Command *cmd) {
if ((ani->_id == ANI_STOOL_34 && cmd->_param == ANI_INV_BOX) || (ani->_id == ANI_BOX_34 && cmd->_param == ANI_INV_STOOL)) {
getGameLoaderInteractionController()->handleInteraction(g_nmi->_aniMan, g_vars->scene34_vent, cmd->_param);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
if (ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
diff --git a/engines/ngi/fullpipe/scene35.cpp b/engines/ngi/fullpipe/scene35.cpp
index e2607555283..b2aef7e1e75 100644
--- a/engines/ngi/fullpipe/scene35.cpp
+++ b/engines/ngi/fullpipe/scene35.cpp
@@ -93,7 +93,7 @@ void sceneHandler35_startFlow() {
mq->setFlags(mq->getFlags() | 1);
- Command *cmd = new Command(g_vars->scene35_bellyInflater->_id, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ Command *cmd = new Command(g_vars->scene35_bellyInflater->_id, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
cmd->_excFlags |= 3;
cmd->_z = 256;
@@ -150,7 +150,7 @@ void sceneHandler35_genFlies() {
}
int sceneHandler35(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -207,7 +207,7 @@ int sceneHandler35(Command *cmd) {
if (ani)
if (ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
}
diff --git a/engines/ngi/fullpipe/scene36.cpp b/engines/ngi/fullpipe/scene36.cpp
index 57d1af55572..934d77774af 100644
--- a/engines/ngi/fullpipe/scene36.cpp
+++ b/engines/ngi/fullpipe/scene36.cpp
@@ -53,7 +53,7 @@ int scene36_updateCursor() {
}
int sceneHandler36(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -65,7 +65,7 @@ int sceneHandler36(Command *cmd) {
if (!(g_nmi->_aniMan->_flags & 0x100) && g_nmi->_msgObjectId2 != g_vars->scene36_scissors->_id ) {
handleObjectInteraction(g_nmi->_aniMan, g_vars->scene36_scissors, cmd->_param);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
break;
diff --git a/engines/ngi/fullpipe/scene37.cpp b/engines/ngi/fullpipe/scene37.cpp
index e005480ce0d..b874469ad70 100644
--- a/engines/ngi/fullpipe/scene37.cpp
+++ b/engines/ngi/fullpipe/scene37.cpp
@@ -232,7 +232,7 @@ void sceneHandler37_setRingsState() {
}
int sceneHandler37(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch(cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/scene38.cpp b/engines/ngi/fullpipe/scene38.cpp
index 5254f76df33..5243ff565e9 100644
--- a/engines/ngi/fullpipe/scene38.cpp
+++ b/engines/ngi/fullpipe/scene38.cpp
@@ -318,7 +318,7 @@ void sceneHandler38_animateAlcoholics() {
}
int sceneHandler38(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
@@ -377,7 +377,7 @@ int sceneHandler38(Command *cmd) {
if (ani && ani->_id == ANI_LIFTBUTTON) {
g_nmi->lift_animateButton(ani);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
}
break;
diff --git a/engines/ngi/fullpipe/sceneChapter.cpp b/engines/ngi/fullpipe/sceneChapter.cpp
index 51476408ac2..d0b4aefb83e 100644
--- a/engines/ngi/fullpipe/sceneChapter.cpp
+++ b/engines/ngi/fullpipe/sceneChapter.cpp
@@ -175,7 +175,7 @@ public:
void saveload() override {}
bool handleMessage(Command *message) override {
- if (message->_cmd != 17 || (message->_messageNum != 30 &&
+ if (message->_cmd != kCmdMessage || (message->_messageNum != 30 &&
!(message->_messageNum == 37 && message->_param == kActionCloseDialog)))
return false;
_visibleChars = _settings._title.size() + _settings._text.size();
diff --git a/engines/ngi/fullpipe/sceneDbg.cpp b/engines/ngi/fullpipe/sceneDbg.cpp
index 8f491100ac2..e2aaf1a1801 100644
--- a/engines/ngi/fullpipe/sceneDbg.cpp
+++ b/engines/ngi/fullpipe/sceneDbg.cpp
@@ -57,7 +57,7 @@ GameObject *sceneHandlerDbgMenu_getObjectAtXY(int x, int y) {
}
int sceneHandlerDbgMenu(Command *ex) {
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
int mx = g_nmi->_mouseScreenPos.x + g_nmi->_sceneRect.left;
diff --git a/engines/ngi/fullpipe/sceneFinal.cpp b/engines/ngi/fullpipe/sceneFinal.cpp
index f991b135827..cc984269e68 100644
--- a/engines/ngi/fullpipe/sceneFinal.cpp
+++ b/engines/ngi/fullpipe/sceneFinal.cpp
@@ -129,7 +129,7 @@ void updateMusic() {
}
int sceneHandlerFinal(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
switch (cmd->_messageNum) {
diff --git a/engines/ngi/fullpipe/sceneIntro.cpp b/engines/ngi/fullpipe/sceneIntro.cpp
index 214102f4c0e..5d748867c7f 100644
--- a/engines/ngi/fullpipe/sceneIntro.cpp
+++ b/engines/ngi/fullpipe/sceneIntro.cpp
@@ -144,7 +144,7 @@ void sceneIntro_end() {
}
int sceneHandlerIntro(Command *ex) {
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
if (g_nmi->isAndroidFullPipe() && !ex->_messageName.empty()) {
diff --git a/engines/ngi/fullpipe/sceneIntroDemo.cpp b/engines/ngi/fullpipe/sceneIntroDemo.cpp
index c85e3d52944..6474b9fc13f 100644
--- a/engines/ngi/fullpipe/sceneIntroDemo.cpp
+++ b/engines/ngi/fullpipe/sceneIntroDemo.cpp
@@ -58,7 +58,7 @@ void sceneHandlerIntroDemo_part2() {
}
int sceneHandlerIntroDemo(Command *ex) {
- if (ex->_cmd != 17)
+ if (ex->_cmd != kCmdMessage)
return 0;
switch (ex->_messageNum) {
diff --git a/engines/ngi/fullpipe/sceneTutorial.cpp b/engines/ngi/fullpipe/sceneTutorial.cpp
index 9a536eb347e..289ad7f934d 100644
--- a/engines/ngi/fullpipe/sceneTutorial.cpp
+++ b/engines/ngi/fullpipe/sceneTutorial.cpp
@@ -176,7 +176,7 @@ public:
}
bool handleMessage(Command *cmd) override {
- if (cmd->_cmd != 17 || cmd->_messageNum != 30)
+ if (cmd->_cmd != kCmdMessage || cmd->_messageNum != 30)
return false;
const Common::Point pos(cmd->_x, cmd->_y);
GameVar *root = g_nmi->getGameLoaderGameVar();
@@ -260,7 +260,7 @@ public:
_font.drawCentered(g_nmi->_backgroundSurface, Common::Rect(130, 240, 380, 360), _title);
}
bool handleMessage(Command *cmd) override {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return false;
GuiElement *close = _scene._guiManager->getElement("BTN_SC_NOTEBOOK_CLOSE");
if ((cmd->_messageNum == 30 && close && close->hit(Common::Point(cmd->_x, cmd->_y))) ||
diff --git a/engines/ngi/gameloader.cpp b/engines/ngi/gameloader.cpp
index 18e15970dcb..8ec52b6cdf5 100644
--- a/engines/ngi/gameloader.cpp
+++ b/engines/ngi/gameloader.cpp
@@ -249,7 +249,7 @@ bool GameLoader::setScene(int sceneId, int entranceId) {
if (stobj) {
stobj->_flags &= 0x100;
- Command *ex = new Command(stobj->_id, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(stobj->_id, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
ex->_z = 256;
ex->_messageNum = 0;
@@ -418,7 +418,7 @@ bool GameLoader::preloadScene(int sceneId, int entranceId) {
loadScene(_preloadItems[idx].sceneId);
- Command *ex = new Command(_preloadItems[idx].sceneId, 17, 62, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(_preloadItems[idx].sceneId, kCmdMessage, 62, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
ex->_param = _preloadItems[idx].param;
@@ -587,7 +587,7 @@ bool GameLoader::updateContent(int counterdiff) {
if (g_nmi->_gameVersion >= 201509)
return changed;
- _exCommand._cmd = 17;
+ _exCommand._cmd = kCmdMessage;
_updateCounter++;
_exCommand._messageNum = 33;
_exCommand._excFlags = 0;
diff --git a/engines/ngi/input.cpp b/engines/ngi/input.cpp
index afb2a48a8e3..da5ea01ff29 100644
--- a/engines/ngi/input.cpp
+++ b/engines/ngi/input.cpp
@@ -182,7 +182,7 @@ void NGIEngine::defHandleKeyDown(int key) {
}
void NGIEngine::winArcade() {
- Command *ex = new Command(0, 17, MSG_CMN_WINARCADE, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_CMN_WINARCADE, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->postMessage();
diff --git a/engines/ngi/interaction.cpp b/engines/ngi/interaction.cpp
index c1e672af4c5..a30469702e6 100644
--- a/engines/ngi/interaction.cpp
+++ b/engines/ngi/interaction.cpp
@@ -127,7 +127,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
if (!queue)
queue.reset(new MessageQueue(0));
if (action->_heroId) {
- Command *mirror = new Command(subj->_id, 34, action->_heroMirror ? 8 : 0, 0, 0, 0, 1, 0, 0, 0);
+ Command *mirror = new Command(subj->_id, kCmdSetFlags, action->_heroMirror ? 8 : 0, 0, 0, 0, 1, 0, 0, 0);
mirror->_z = 8;
mirror->_excFlags = 3;
queue->addCommandToEnd(mirror);
@@ -224,7 +224,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
if (!mq)
return false;
- ex = new Command((subj ? subj->_id : 0), 55, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command((subj ? subj->_id : 0), kCmdObjectInteraction, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_x = obj->_id;
ex->_y = obj->_copyId;
ex->_param = subj ? subj->_copyId : 0;
@@ -300,7 +300,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
mq->_flags |= 1;
if (!(inter->_flags & 0x10000)) {
- ex = new Command(obj->_id, 34, 0x80, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(obj->_id, kCmdSetFlags, 0x80, 0, 0, 0, 1, 0, 0, 0);
ex->_param = obj->_copyId;
ex->_z = 0x80;
ex->_messageNum = 0;
@@ -308,21 +308,21 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
mq->addCommandToEnd(ex);
}
- ex = new Command(obj->_id, 34, 0x100, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(obj->_id, kCmdSetFlags, 0x100, 0, 0, 0, 1, 0, 0, 0);
ex->_param = obj->_copyId;
ex->_z = 0x100;
ex->_messageNum = 0;
ex->_excFlags = 3;
mq->addCommandToEnd(ex);
- ex = new Command(subj->_id, 34, 0x100, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(subj->_id, kCmdSetFlags, 0x100, 0, 0, 0, 1, 0, 0, 0);
ex->_param = subj->_copyId;
ex->_z = 0x100;
ex->_messageNum = 0;
ex->_excFlags = 3;
mq->addCommandToEnd(ex);
- ex = new Command(subj->_id, 17, 0x40, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(subj->_id, kCmdMessage, 0x40, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = 0;
mq->addCommandToEnd(ex);
@@ -360,7 +360,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
if (!mq)
return false;
- ex = new Command(subj->_id, 55, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(subj->_id, kCmdObjectInteraction, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_x = obj->_id;
ex->_y = obj->_copyId;
ex->_param = subj->_copyId;
@@ -371,7 +371,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
someFlag = true;
- ex = new Command(subj->_id, 17, 0x40, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(subj->_id, kCmdMessage, 0x40, 0, 0, 0, 1, 0, 0, 0);
ex->_x = xpos;
ex->_y = ypos;
ex->_excFlags |= 3;
@@ -406,20 +406,20 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
if (mq->_isFinished) {
ani->_flags |= 0x80u;
} else {
- ex = new Command(ani->_id, 34, 0x80, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ani->_id, kCmdSetFlags, 0x80, 0, 0, 0, 1, 0, 0, 0);
ex->_z = 0x80;
ex->_param = ani->_copyId;
ex->_excFlags = 3;
mq->addCommandToEnd(ex);
}
}
- ex = new Command(ani->_id, 34, 0x100, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ani->_id, kCmdSetFlags, 0x100, 0, 0, 0, 1, 0, 0, 0);
ex->_param = ani->_copyId;
ex->_z = 0x100;
ex->_excFlags = 3;
mq->addCommandToEnd(ex);
} else {
- ex = new Command(subj->_id, 55, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(subj->_id, kCmdObjectInteraction, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_x = ani->_id;
ex->_y = ani->_copyId;
ex->_param = subj->_copyId;
diff --git a/engines/ngi/inventory.cpp b/engines/ngi/inventory.cpp
index 56567bc6f2e..4501a39064f 100644
--- a/engines/ngi/inventory.cpp
+++ b/engines/ngi/inventory.cpp
@@ -401,7 +401,7 @@ reset:
void Inventory::slideIn() {
_isInventoryOut = false;
- Command *ex = new Command(0, 17, 65, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, 65, 0, 0, 0, 1, 0, 0, 0);
ex->_auxParam = 10;
ex->_z = _isInventoryOut;
@@ -413,7 +413,7 @@ void Inventory::slideIn() {
void Inventory::slideOut() {
_isInventoryOut = true;
- Command *ex = new Command(0, 17, 65, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, 65, 0, 0, 0, 1, 0, 0, 0);
ex->_auxParam = 10;
ex->_z = _isInventoryOut;
@@ -437,7 +437,7 @@ bool Inventory::onMouseLKeyDown(Command *cmd) {
unselectItem(0);
}
if (getItemFlags(icon.inventoryItemId) & 1) {
- Command *ex = new Command(0, 17, 65, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, 65, 0, 0, 0, 1, 0, 0, 0);
ex->_auxParam = 11;
ex->_z = _inventoryIcons[i].inventoryItemId;
ex->_excFlags |= 3;
diff --git a/engines/ngi/lift.cpp b/engines/ngi/lift.cpp
index 228139aab30..b35e6f41f40 100644
--- a/engines/ngi/lift.cpp
+++ b/engines/ngi/lift.cpp
@@ -223,14 +223,14 @@ void NGIEngine::lift_exitSeq(Command *cmd) {
MessageQueue *mq = _globalMessageQueueList->getMessageQueueById(cmd->_parId);
if (mq)
- mq->activateExCommandsByKind(34);
+ mq->activateExCommandsByKind(kCmdSetFlags);
}
_lift->setStatic(ST_LFT_CLOSED);
MessageQueue *mq = new MessageQueue(_globalMessageQueueList->compact());
- Command *ex = new Command(_aniMan->_id, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(_aniMan->_id, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
ex->_z = 256;
ex->_messageNum = 256;
@@ -238,23 +238,23 @@ void NGIEngine::lift_exitSeq(Command *cmd) {
mq->addCommandToEnd(ex);
if (!cmd) {
- ex = new Command(_aniMan->_id, 2, 40, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(_aniMan->_id, kCmdSetAniQueue, 40, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _aniMan->_copyId;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
}
- ex = new Command(_lift->_id, 1, MV_LFT_OPEN, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(_lift->_id, kCmdStartMovement, MV_LFT_OPEN, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _lift->_copyId;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(_aniMan->_id, 1, MV_MAN_STARTD, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(_aniMan->_id, kCmdStartMovement, MV_MAN_STARTD, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _aniMan->_copyId;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(_aniMan->_id, 5, -1, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(_aniMan->_id, kCmdShow, -1, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _aniMan->_copyId;
ex->_z = 10;
ex->_x = -1;
@@ -262,17 +262,17 @@ void NGIEngine::lift_exitSeq(Command *cmd) {
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
- ex = new Command(_aniMan->_id, 34, 256, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(_aniMan->_id, kCmdSetFlags, 256, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_z = 256;
ex->_messageNum = 0;
mq->addCommandToEnd(ex);
- ex = new Command(0, 17, MSG_LIFT_STARTEXITQUEUE, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, MSG_LIFT_STARTEXITQUEUE, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
- ex = new Command(_lift->_id, 1, MV_LFT_CLOSE, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(_lift->_id, kCmdStartMovement, MV_LFT_CLOSE, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _lift->_copyId;
ex->_excFlags |= 2;
@@ -309,7 +309,7 @@ void NGIEngine::lift_closedoorSeq() {
}
MessageQueue *mq = new MessageQueue(_globalMessageQueueList->compact());
- Command *ex = new Command(0, 17, MSG_LIFT_GO, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, MSG_LIFT_GO, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -326,7 +326,7 @@ void NGIEngine::lift_walkAndGo() {
mq = getCurrSceneSc2MotionController()->startMove(_aniMan, _liftX, _liftY, 1, ST_MAN_UP);
if (mq) {
- ex = new Command(0, 17, MSG_LIFT_CLICKBUTTON, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, MSG_LIFT_CLICKBUTTON, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -338,12 +338,12 @@ void NGIEngine::lift_walkAndGo() {
mq->setFlags(mq->getFlags() | 1);
- ex = new Command(_aniMan->_id, 2, 15, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(_aniMan->_id, kCmdSetAniQueue, 15, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _aniMan->_copyId;
ex->_excFlags |= 2;
mq->addCommandToFront(ex);
- ex = new Command(_aniMan->_id, 5, -1, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(_aniMan->_id, kCmdShow, -1, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _aniMan->_copyId;
ex->_z = _lift->_z + 1;
ex->_x = -1;
@@ -351,7 +351,7 @@ void NGIEngine::lift_walkAndGo() {
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
- ex = new Command(0, 17, MSG_LIFT_CLOSEDOOR, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, MSG_LIFT_CLOSEDOOR, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
@@ -407,7 +407,7 @@ void NGIEngine::lift_goAnimation() {
if (pre.preloadId2 == buttonId && pre.preloadId1 == _currentScene->_sceneId) {
MessageQueue *mq = new MessageQueue(_globalMessageQueueList->compact());
- Command *ex = new Command(ANI_MAN, 1, (pre.param != LiftDown ? MV_MAN_LIFTDOWN : MV_MAN_LIFTUP), 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ANI_MAN, kCmdStartMovement, (pre.param != LiftDown ? MV_MAN_LIFTDOWN : MV_MAN_LIFTUP), 0, 0, 0, 1, 0, 0, 0);
ex->_param = -1;
ex->_wait = 1;
@@ -415,7 +415,7 @@ void NGIEngine::lift_goAnimation() {
mq->addCommandToEnd(ex);
- ex = new Command(parentId, 17, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(parentId, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
ex->_param = buttonId;
ex->_excFlags |= 3;
@@ -462,7 +462,7 @@ void NGIEngine::lift_animateButton(AniObject *button) {
_lastLiftButton = button;
button->_statics = button->getStatic(butId);
- Command *ex = new Command(0, 35, SND_CMN_032, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdSound, SND_CMN_032, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_z = 1;
ex->postMessage();
diff --git a/engines/ngi/messagehandlers.cpp b/engines/ngi/messagehandlers.cpp
index 1b635a171ed..7bf151bf8d4 100644
--- a/engines/ngi/messagehandlers.cpp
+++ b/engines/ngi/messagehandlers.cpp
@@ -40,7 +40,7 @@ void global_messageHandler_KickStucco() {
for (int i = 0; i < end; i++) {
Command *ex = mov->getPhase(i)->getCommand();
- if (ex && ex->_cmd == 35 && ex->_messageNum == SND_CMN_015) {
+ if (ex && ex->_cmd == kCmdSound && ex->_messageNum == SND_CMN_015) {
if (flip) {
ex->_messageNum = SND_CMN_055;
} else {
@@ -57,7 +57,7 @@ void global_messageHandler_KickStucco() {
for (int i = 0; i < end; i++) {
Command *ex = mov->getPhase(i)->getCommand();
- if (ex && ex->_cmd == 35 && ex->_messageNum == SND_CMN_015) {
+ if (ex && ex->_cmd == kCmdSound && ex->_messageNum == SND_CMN_015) {
if (flip) {
ex->_messageNum = SND_CMN_055;
} else {
@@ -75,7 +75,7 @@ void global_messageHandler_KickMetal() {
for (int i = 0; i < end; i++) {
Command *ex = mov->getPhase(i)->getCommand();
- if (ex && ex->_cmd == 35) {
+ if (ex && ex->_cmd == kCmdSound) {
if (ex->_messageNum == SND_CMN_054 || ex->_messageNum == SND_CMN_055)
ex->_messageNum = SND_CMN_015;
}
@@ -87,7 +87,7 @@ void global_messageHandler_KickMetal() {
for (int i = 0; i < end; i++) {
Command *ex = mov->getPhase(i)->getCommand();
- if (ex && ex->_cmd == 35) {
+ if (ex && ex->_cmd == kCmdSound) {
if (ex->_messageNum == SND_CMN_054 || ex->_messageNum == SND_CMN_055)
ex->_messageNum = SND_CMN_015;
}
@@ -109,19 +109,19 @@ int global_messageHandler1(Command *cmd) {
}
if (g_nmi->_inputDisabled) {
- if (cmd->_cmd == 17) {
+ if (cmd->_cmd == kCmdMessage) {
switch (cmd->_messageNum) {
case 29:
case 30:
case 36:
case 106:
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
default:
break;
}
}
- } else if (cmd->_cmd == 17) {
+ } else if (cmd->_cmd == kCmdMessage) {
switch (cmd->_messageNum) {
case MSG_MANSHADOWSON:
g_nmi->_aniMan->_shadowsOn = 1;
@@ -144,13 +144,13 @@ int global_messageHandler1(Command *cmd) {
case 29: // left mouse
if (g_nmi->_inventoryScene) {
if (getGameLoaderInventory()->onMouseLKeyDown(cmd))
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
break;
case 107: // right mouse
if (getGameLoaderInventory()->getSelectedItemId()) {
getGameLoaderInventory()->unselectItem(0);
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
break;
case 36: // keydown
@@ -161,16 +161,16 @@ int global_messageHandler1(Command *cmd) {
if (g_nmi->_currentScene) {
getGameLoaderInventory()->unselectItem(0);
g_nmi->openMainMenu();
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
break;
case kActionStopSounds:
g_nmi->stopAllSounds();
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
case kActionToggleMute:
g_nmi->toggleMute();
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
case kActionInventory:
if (getGameLoaderInventory()->getIsLocked()) {
@@ -185,12 +185,12 @@ int global_messageHandler1(Command *cmd) {
case kActionMapOpen:
if (g_nmi->_flgCanOpenMap)
g_nmi->openMap();
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
case kActionHelp:
if (g_nmi->_flgCanOpenMap)
g_nmi->openHelp();
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
case Common::KEYCODE_8:
{
@@ -219,9 +219,9 @@ int global_messageHandler1(Command *cmd) {
Command *newex = nullptr;
if (st == ST_MAN_RIGHT) {
- newex = new Command(g_nmi->_aniMan->_id, 1, rMV_MAN_LOOKUP, 0, 0, 0, 1, 0, 0, 0);
+ newex = new Command(g_nmi->_aniMan->_id, kCmdStartMovement, rMV_MAN_LOOKUP, 0, 0, 0, 1, 0, 0, 0);
} else if (st == (0x4000 | ST_MAN_RIGHT)) {
- newex = new Command(g_nmi->_aniMan->_id, 1, MV_MAN_LOOKUP, 0, 0, 0, 1, 0, 0, 0);
+ newex = new Command(g_nmi->_aniMan->_id, kCmdStartMovement, MV_MAN_LOOKUP, 0, 0, 0, 1, 0, 0, 0);
}
if (newex) {
@@ -253,17 +253,17 @@ int global_messageHandler1(Command *cmd) {
}
}
- if (cmd->_cmd == 56) {
+ if (cmd->_cmd == kCmdAddInvItem) {
getGameLoaderInventory()->recalcItemPos();
- Command *newex = new Command(0, 35, SND_CMN_031, 0, 0, 0, 1, 0, 0, 0);
+ Command *newex = new Command(0, kCmdSound, SND_CMN_031, 0, 0, 0, 1, 0, 0, 0);
newex->_z = 1;
newex->_excFlags |= 3;
newex->postMessage();
return 1;
- } else if (cmd->_cmd == 57) {
+ } else if (cmd->_cmd == kCmdRemoveInvItem) {
getGameLoaderInventory()->recalcItemPos();
return 1;
@@ -277,7 +277,7 @@ void staticANIObjectCallback(int *arg) {
}
int global_messageHandler2(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
int res = 0;
@@ -347,7 +347,7 @@ int global_messageHandler2(Command *cmd) {
int global_messageHandler3(Command *cmd) {
int result = 0;
- if (cmd->_cmd == 17) {
+ if (cmd->_cmd == kCmdMessage) {
switch (cmd->_messageNum) {
case 29:
case 30:
@@ -355,7 +355,7 @@ int global_messageHandler3(Command *cmd) {
case 32:
case 36:
if (g_nmi->_inputDisabled)
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
break;
default:
break;
@@ -365,7 +365,7 @@ int global_messageHandler3(Command *cmd) {
AniObject *ani, *ani2;
switch (cmd->_cmd) {
- case 17:
+ case kCmdMessage:
switch (cmd->_messageNum) {
case 61:
debugC(0, kDebugEvents, "preload: { %d, %d },", cmd->_parentId, cmd->_param);
@@ -402,7 +402,7 @@ int global_messageHandler3(Command *cmd) {
if (ani) {
if (g_nmi->_msgObjectId2 == ani->_id && g_nmi->_msgId == ani->_copyId) {
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
return result;
}
if (canInteractAny(ani2, ani, cmd->_param)) {
@@ -414,7 +414,7 @@ int global_messageHandler3(Command *cmd) {
PictureObject *pic = g_nmi->_currentScene->findPictureObjectById(id, 0);
if (pic) {
if (g_nmi->_msgObjectId2 == pic->_id && g_nmi->_msgId == pic->_copyId) {
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
return result;
}
if (!ani2 || canInteractAny(ani2, pic, cmd->_param)) {
@@ -432,7 +432,7 @@ int global_messageHandler3(Command *cmd) {
debugC(0, kDebugPathfinding, "WWW 1");
result = startWalkTo(g_nmi->_gameLoader->_heroId, -1, cmd->_sceneClickX, cmd->_sceneClickY, 0);
if (result) {
- Command *ex = new Command(g_nmi->_gameLoader->_heroId, 17, 64, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(g_nmi->_gameLoader->_heroId, kCmdMessage, 64, 0, 0, 0, 1, 0, 0, 0);
ex->_param = 1;
ex->_excFlags |= 3;
@@ -442,23 +442,23 @@ int global_messageHandler3(Command *cmd) {
}
}
} else {
- cmd->_cmd = 0;
+ cmd->_cmd = kCmdNone;
}
}
return result;
default:
return result;
}
- case 58:
+ case kCmdSetCursor:
g_nmi->setCursor(cmd->_param);
return result;
- case 59:
+ case kCmdDisableInput:
setInputDisabled(1);
return result;
- case 60:
+ case kCmdEnableInput:
setInputDisabled(0);
return result;
- case 56:
+ case kCmdAddInvItem:
if (cmd->_auxParam) {
ani = g_nmi->_currentScene->findAniObjectById(cmd->_parentId, cmd->_param);
if (ani) {
@@ -471,7 +471,7 @@ int global_messageHandler3(Command *cmd) {
}
getGameLoaderInventory()->recalcItemPos();
return result;
- case 57:
+ case kCmdRemoveInvItem:
if (cmd->_auxParam) {
if (!cmd->_invId) {
getGameLoaderInventory()->removeItem2(g_nmi->_currentScene, cmd->_parentId, cmd->_x, cmd->_y, cmd->_z);
@@ -489,7 +489,7 @@ int global_messageHandler3(Command *cmd) {
}
getGameLoaderInventory()->recalcItemPos();
return 1;
- case 55:
+ case kCmdObjectInteraction:
if (g_nmi->_currentScene) {
GameObject *obj;
if (cmd->_z)
@@ -500,13 +500,13 @@ int global_messageHandler3(Command *cmd) {
result = 1;
}
return result;
- case 51:
+ case kCmdStartWalkTo:
return startWalkTo(cmd->_parentId, cmd->_param, cmd->_x, cmd->_y, cmd->_invId);
- case 52:
+ case kCmdDoSomeAnimation:
return doSomeAnimation(cmd->_parentId, cmd->_param, cmd->_invId);
- case 53:
+ case kCmdDoSomeAnimation2:
return doSomeAnimation2(cmd->_parentId, cmd->_param);
- case 63:
+ case kCmdUser:
if (cmd->_objtype == kObjTypeObjstateCommand) {
ObjstateCommand *c = static_cast<ObjstateCommand *>(cmd);
result = 1;
@@ -522,7 +522,7 @@ int global_messageHandler4(Command *cmd) {
AniObject *ani = nullptr;
switch (cmd->_cmd) {
- case 18: {
+ case kCmdQueue: {
MessageQueue *source = g_nmi->_currentScene ? g_nmi->_currentScene->findMessageQueue(cmd->_messageNum) : nullptr;
if (!source) {
warning("Could not find message queue %d", cmd->_messageNum);
@@ -543,7 +543,7 @@ int global_messageHandler4(Command *cmd) {
mq->next();
break;
}
- case 2:
+ case kCmdSetAniQueue:
if (!g_nmi->_currentScene)
break;
@@ -554,7 +554,7 @@ int global_messageHandler4(Command *cmd) {
ani->trySetMessageQueue(cmd->_messageNum, cmd->_parId);
break;
- case 1: {
+ case kCmdStartMovement: {
if (!g_nmi->_currentScene)
break;
@@ -570,7 +570,7 @@ int global_messageHandler4(Command *cmd) {
break;
}
- case 8:
+ case kCmdStartAnimEx:
if (!g_nmi->_currentScene)
break;
@@ -581,7 +581,7 @@ int global_messageHandler4(Command *cmd) {
ani->startAnimEx(cmd->_messageNum, cmd->_parId, -1, -1);
break;
- case 20: {
+ case kCmdStartSliding: {
if (!g_nmi->_currentScene)
break;
@@ -604,7 +604,7 @@ int global_messageHandler4(Command *cmd) {
}
break;
}
- case 21:
+ case kCmdPlayIdle:
if (!g_nmi->_currentScene)
break;
@@ -615,18 +615,18 @@ int global_messageHandler4(Command *cmd) {
ani->setQueue(nullptr);
ani->playIdle();
break;
- case 9:
+ case kCmdUnused9:
// Nop in original
break;
- case 3:
+ case kCmdSetSceneY:
g_nmi->_currentScene->_y = cmd->_messageNum - cmd->_messageNum % g_nmi->_scrollSpeed;
break;
- case 4:
+ case kCmdSetSceneX:
g_nmi->_currentScene->_x = cmd->_messageNum - cmd->_messageNum % g_nmi->_scrollSpeed;
break;
- case 19: {
+ case kCmdMoveToStatic: {
if (!g_nmi->_currentScene)
break;
ani = g_nmi->_currentScene->findAniObjectById(cmd->_parentId, cmd->_param);
@@ -649,7 +649,7 @@ int global_messageHandler4(Command *cmd) {
mq2->_flag1 = (cmd->_wait == 0);
break;
}
- case 22:
+ case kCmdSetStatic:
if (!g_nmi->_currentScene)
break;
@@ -661,7 +661,7 @@ int global_messageHandler4(Command *cmd) {
ani->setStatic(cmd->_messageNum);
break;
- case 6:
+ case kCmdHide:
if (!g_nmi->_currentScene)
break;
@@ -672,7 +672,7 @@ int global_messageHandler4(Command *cmd) {
ani->hide();
break;
- case 27:
+ case kCmdShowFromScene:
if (!g_nmi->_currentScene || g_nmi->_currentScene->findAniObjectById(cmd->_parentId, cmd->_param) == nullptr) {
ani = g_nmi->findScene(cmd->_invId)->findAniObjectById(cmd->_parentId, -1);
if (ani) {
@@ -682,7 +682,7 @@ int global_messageHandler4(Command *cmd) {
}
// fall through
- case 5:
+ case kCmdShow:
if (g_nmi->_currentScene)
ani = g_nmi->_currentScene->findAniObjectById(cmd->_parentId, cmd->_param);
@@ -701,7 +701,7 @@ int global_messageHandler4(Command *cmd) {
}
break;
- case 10:
+ case kCmdShow2:
if (!g_nmi->_currentScene)
break;
@@ -715,7 +715,7 @@ int global_messageHandler4(Command *cmd) {
ani->show2(cmd->_x, cmd->_y, cmd->_messageNum, cmd->_parId);
break;
- case 7: {
+ case kCmdScrollScene: {
if (!g_nmi->_currentScene->_pictureObjects.size())
break;
@@ -739,7 +739,7 @@ int global_messageHandler4(Command *cmd) {
}
break;
}
- case 34:
+ case kCmdSetFlags:
if (!g_nmi->_currentScene)
break;
@@ -751,34 +751,34 @@ int global_messageHandler4(Command *cmd) {
break;
- case 35:
+ case kCmdSound:
global_messageHandler_handleSound(cmd);
break;
- case Command::kCmdSetScene:
+ case kCmdSetScene:
g_nmi->_gameLoader->preloadScene(cmd->_parentId, cmd->_messageNum);
break;
- case Command::kCmdSetLogic:
+ case kCmdSetLogic:
g_nmi->setState(cmd->_messageName, cmd->_messageNum);
break;
- case 56:
- case 57:
+ case kCmdAddInvItem:
+ case kCmdRemoveInvItem:
if (!g_nmi->usesXMLProject())
return 0;
- if (cmd->_cmd == 56)
+ if (cmd->_cmd == kCmdAddInvItem)
getGameLoaderInventory()->addItem(cmd->_parentId, 1);
else if (getGameLoaderInventory()->getCountItemsWithId(cmd->_parentId))
getGameLoaderInventory()->removeItem(cmd->_parentId, 1);
getGameLoaderInventory()->recalcItemPos();
break;
- case 63:
+ case kCmdUser:
if (g_nmi->_gameVersion < 201509)
return 0;
warning("Android command %s not implemented", cmd->_messageName.c_str());
break;
- case 11:
- case 12:
+ case kCmdUnused11:
+ case kCmdUnused12:
break;
default:
return 0;
@@ -789,7 +789,7 @@ int global_messageHandler4(Command *cmd) {
}
int MovGraph::messageHandler(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return 0;
if (cmd->_messageNum != 33)
diff --git a/engines/ngi/messages.cpp b/engines/ngi/messages.cpp
index 40735aadf84..fb86ca04a58 100644
--- a/engines/ngi/messages.cpp
+++ b/engines/ngi/messages.cpp
@@ -61,17 +61,44 @@ struct exDesc {
byte num;
const char *name;
} static const exTypes[] = {
- { 1, "START_MOVEMENT" },
- { 5, "SHOW" },
- { 17, "MESSAGE" },
- { 63, "USER" },
- { 0, "" }
+ { kCmdStartMovement, "START_MOVEMENT" },
+ { kCmdSetAniQueue, "SET_ANI_QUEUE" },
+ { kCmdSetSceneY, "SET_SCENE_Y" },
+ { kCmdSetSceneX, "SET_SCENE_X" },
+ { kCmdShow, "SHOW" },
+ { kCmdHide, "HIDE" },
+ { kCmdScrollScene, "SCROLL_SCENE" },
+ { kCmdStartAnimEx, "START_ANIM_EX" },
+ { kCmdShow2, "SHOW2" },
+ { kCmdMessage, "MESSAGE" },
+ { kCmdQueue, "QUEUE" },
+ { kCmdMoveToStatic, "MOVE_TO_STATIC" },
+ { kCmdStartSliding, "START_SLIDING" },
+ { kCmdPlayIdle, "PLAY_IDLE" },
+ { kCmdSetStatic, "SET_STATIC" },
+ { kCmdShowFromScene, "SHOW_FROM_SCENE" },
+ { kCmdSetFlags, "SET_FLAGS" },
+ { kCmdSound, "SOUND" },
+ { kCmdStartWalkTo, "START_WALK_TO" },
+ { kCmdDoSomeAnimation, "DO_SOME_ANIMATION" },
+ { kCmdDoSomeAnimation2, "DO_SOME_ANIMATION2" },
+ { kCmdObjectInteraction, "OBJECT_INTERACTION" },
+ { kCmdAddInvItem, "ADD_INV_ITEM" },
+ { kCmdRemoveInvItem, "REMOVE_INV_ITEM" },
+ { kCmdSetCursor, "SET_CURSOR" },
+ { kCmdDisableInput, "DISABLE_INPUT" },
+ { kCmdEnableInput, "ENABLE_INPUT" },
+ { kCmdUser, "USER" },
+ { kCmdPause, "PAUSE" },
+ { kCmdSetScene, "SET_SCENE" },
+ { kCmdSetLogic, "SET_LOGIC" },
+ { kCmdNone, "" }
};
static const char *exCommandType2str(int type) {
static char buf[10];
- for (int i = 0; exTypes[i].num; i++)
+ for (int i = 0; exTypes[i].num != kCmdNone; i++)
if (exTypes[i].num == type)
return exTypes[i].name;
@@ -120,7 +147,7 @@ bool Command::handleMessage() {
for (MessageHandler *m = g_nmi->_messageHandlers; m; m = m->nextItem)
cnt += m->callback(this);
- if (_cmd == 17 || (_excFlags & 1)) {
+ if (_cmd == kCmdMessage || (_excFlags & 1)) {
if (_parId) {
MessageQueue *mq = g_nmi->_globalMessageQueueList->getMessageQueueById(_parId);
if (mq)
@@ -186,7 +213,7 @@ ExCommand2 *ExCommand2::createClone() {
}
Message::Message() {
- _cmd = 0;
+ _cmd = kCmdNone;
_parentId = 0;
_x = 0;
@@ -456,7 +483,7 @@ void MessageQueue::next() {
ex->_excFlags |= (ex->_wait == 0 ? 1 : 0) | (ex->_field_3C != 0 ? 2 : 0);
_flags |= 4;
- if (ex->_cmd == Command::kCmdPause && ex->_wait && g_nmi->_gameVersion >= 201509)
+ if (ex->_cmd == kCmdPause && ex->_wait && g_nmi->_gameVersion >= 201509)
_pauseCommand.reset(ex);
else
ex->sendMessage();
@@ -485,13 +512,13 @@ bool MessageQueue::checkGlobalExCommandList1() {
for (uint i = 0; i < getCount(); i++) {
ex = getCommandByIndex(i);
- if (ex->_cmd != 1 && ex->_cmd != 20 && ex->_cmd != 5 && ex->_cmd != 27)
+ if (ex->_cmd != kCmdStartMovement && ex->_cmd != kCmdStartSliding && ex->_cmd != kCmdShow && ex->_cmd != kCmdShowFromScene)
continue;
for (Common::List<Command *>::iterator it = g_nmi->_exCommandList.begin(); it != g_nmi->_exCommandList.end(); it++) {
ex1 = *it;
- if (ex1->_cmd != 1 && ex1->_cmd != 20 && ex1->_cmd != 5 && ex1->_cmd != 27)
+ if (ex1->_cmd != kCmdStartMovement && ex1->_cmd != kCmdStartSliding && ex1->_cmd != kCmdShow && ex1->_cmd != kCmdShowFromScene)
continue;
if (ex1->_parentId != ex->_parentId)
@@ -517,13 +544,13 @@ bool MessageQueue::checkGlobalExCommandList2() {
for (uint i = 0; i < getCount(); i++) {
ex = getCommandByIndex(i);
- if (ex->_cmd != 1 && ex->_cmd != 20 && ex->_cmd != 5 && ex->_cmd != 27)
+ if (ex->_cmd != kCmdStartMovement && ex->_cmd != kCmdStartSliding && ex->_cmd != kCmdShow && ex->_cmd != kCmdShowFromScene)
continue;
for (Common::List<Command *>::iterator it = g_nmi->_exCommandList.begin(); it != g_nmi->_exCommandList.end();) {
ex1 = *it;
- if (ex1->_cmd != 1 && ex1->_cmd != 20 && ex1->_cmd != 5 && ex1->_cmd != 27) {
+ if (ex1->_cmd != kCmdStartMovement && ex1->_cmd != kCmdStartSliding && ex1->_cmd != kCmdShow && ex1->_cmd != kCmdShowFromScene) {
it++;
continue;
}
@@ -583,7 +610,7 @@ void MessageQueue::setObjectCopy(int key1, int key2) {
for (uint i = 0; i < getCount(); i++) {
Command *ex = getCommandByIndex(i);
int k = ex->_cmd;
- if ((k == 1 || k == 20 || k == 5 || k == 6 || k == 2 || k == 18 || k == 19 || k == 22 || k == 55)
+ if ((k == kCmdStartMovement || k == kCmdStartSliding || k == kCmdShow || k == kCmdHide || k == kCmdSetAniQueue || k == kCmdQueue || k == kCmdMoveToStatic || k == kCmdSetStatic || k == kCmdObjectInteraction)
&& ex->_param == key1)
ex->_param = key2;
}
@@ -597,7 +624,7 @@ int MessageQueue::calcDuration(AniObject *obj) {
for (uint i = 0; i < getCount(); i++) {
ex = getCommandByIndex(i);
if (ex->_parentId == obj->_id) {
- if (ex->_cmd == 1 || ex->_cmd == 20) {
+ if (ex->_cmd == kCmdStartMovement || ex->_cmd == kCmdStartSliding) {
if ((mov = obj->getMovement(ex->_messageNum)) != nullptr) {
if (ex->_z >= 1)
res += ex->_z;
@@ -616,7 +643,7 @@ void MessageQueue::setObjectCopyForId(int objId, int oldCopyId, int newCopyId) {
Command *ex = getCommandByIndex(i);
int k = ex->_cmd;
- if ((k == 1 || k == 20 || k == 5 || k == 6 || k == 2 || k == 18 || k == 19 || k == 22 || k == 55)
+ if ((k == kCmdStartMovement || k == kCmdStartSliding || k == kCmdShow || k == kCmdHide || k == kCmdSetAniQueue || k == kCmdQueue || k == kCmdMoveToStatic || k == kCmdSetStatic || k == kCmdObjectInteraction)
&& ex->_param == oldCopyId
&& ex->_parentId == objId)
ex->_param = newCopyId;
@@ -630,7 +657,7 @@ int MessageQueue::activateExCommandsByKind(int kind) {
Command *ex = getCommandByIndex(i);
if (ex->_cmd == kind) {
- ex->_cmd = 0;
+ ex->_cmd = kCmdNone;
ex->_excFlags |= 1;
res++;
@@ -969,7 +996,7 @@ bool runQueueByIdWithAni(AniObject *obj, int queueId, int flags) {
}
void postExCommand(int parentId, int keyCode, int x, int y, int f20, int f14) {
- Command *ex = new Command(parentId, 17, 64, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(parentId, kCmdMessage, 64, 0, 0, 0, 1, 0, 0, 0);
ex->_param = keyCode;
ex->_excFlags |= 3;
diff --git a/engines/ngi/messages.h b/engines/ngi/messages.h
index ace0d394e37..1f9fff40e2d 100644
--- a/engines/ngi/messages.h
+++ b/engines/ngi/messages.h
@@ -35,6 +35,52 @@ enum QueueFlags {
kBehaviorQueue = 8
};
+/**
+ * Kinds of commands (Message::_cmd), in the numbering of the Windows engine.
+ *
+ * The Android build numbers its command types differently (CMessageQueue::Execute: SHOW is 1,
+ * HIDE 2, START_MOVEMENT 3, ...): the XML loader translates them. Names with an Android
+ * counterpart use its command names, the others are named after what their handler does.
+ */
+enum CommandKind {
+ kCmdNone = 0,
+ kCmdStartMovement = 1, // Android START_MOVEMENT
+ kCmdSetAniQueue = 2,
+ kCmdSetSceneY = 3,
+ kCmdSetSceneX = 4,
+ kCmdShow = 5, // Android SHOW
+ kCmdHide = 6, // Android HIDE
+ kCmdScrollScene = 7,
+ kCmdStartAnimEx = 8,
+ kCmdUnused9 = 9, // no-op in the original
+ kCmdShow2 = 10,
+ kCmdUnused11 = 11, // no-op
+ kCmdUnused12 = 12, // no-op
+ kCmdMessage = 17, // Android MESSAGE, _messageNum selects the message
+ kCmdQueue = 18, // Android QUEUE
+ kCmdMoveToStatic = 19,
+ kCmdStartSliding = 20, // Android START_SLIDING
+ kCmdPlayIdle = 21,
+ kCmdSetStatic = 22, // Android STATIC
+ kCmdShowFromScene = 27,
+ kCmdSetFlags = 34, // Android SET_FLAGS
+ kCmdSound = 35, // Android SOUND
+ kCmdStartWalkTo = 51,
+ kCmdDoSomeAnimation = 52,
+ kCmdDoSomeAnimation2 = 53,
+ kCmdObjectInteraction = 55,
+ kCmdAddInvItem = 56, // Android ADD_INV_ITEM
+ kCmdRemoveInvItem = 57, // Android REMOVE_INV_ITEM
+ kCmdSetCursor = 58,
+ kCmdDisableInput = 59,
+ kCmdEnableInput = 60,
+ kCmdUser = 63, // Android USER
+ // Only produced by the XML loader, not present in the Windows engine
+ kCmdPause = 64, // Android PAUSE
+ kCmdSetScene = 65, // Android SETSC
+ kCmdSetLogic = 66
+};
+
class Message : public CObject {
public:
int _cmd;
@@ -59,7 +105,6 @@ class Message : public CObject {
class Command : public Message {
public:
- enum { kCmdPause = 64, kCmdSetScene, kCmdSetLogic }; // Timed pause in XML queues.
Common::String _messageName;
bool _mirror = false;
int _messageNum;
diff --git a/engines/ngi/modal.cpp b/engines/ngi/modal.cpp
index aef4807b8e0..2bebf6444c6 100644
--- a/engines/ngi/modal.cpp
+++ b/engines/ngi/modal.cpp
@@ -73,7 +73,7 @@ ModalIntro::~ModalIntro() {
}
bool ModalIntro::handleMessage(Command *message) {
- if (message->_cmd != 17)
+ if (message->_cmd != kCmdMessage)
return false;
if (message->_messageNum != 36)
@@ -265,7 +265,7 @@ ModalIntroDemo::~ModalIntroDemo() {
}
bool ModalIntroDemo::handleMessage(Command *message) {
- if (message->_cmd != 17)
+ if (message->_cmd != kCmdMessage)
return false;
if (message->_messageNum != 36)
@@ -609,7 +609,7 @@ void MapWindow::update() {
}
bool MapWindow::handleMessage(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return false;
switch (cmd->_messageNum) {
@@ -1138,7 +1138,7 @@ void ModalFinal::unloadScenes() {
}
bool ModalFinal::handleMessage(Command *cmd) {
- if (cmd->_cmd == 17 && cmd->_messageNum == 36 && cmd->_param == kActionPause) {
+ if (cmd->_cmd == kCmdMessage && cmd->_messageNum == 36 && cmd->_param == kActionPause) {
g_nmi->_modalObject = new MainMenu();
g_nmi->_modalObject->_parentObj = this;
@@ -1217,7 +1217,7 @@ CreditsController::~CreditsController() {
}
bool CreditsController::handleMessage(Command *cmd) {
- if (cmd->_cmd == 17 && cmd->_messageNum == 36 && cmd->_param == kActionSkipCredits) {
+ if (cmd->_cmd == kCmdMessage && cmd->_messageNum == 36 && cmd->_param == kActionSkipCredits) {
_fadeIn = false;
return true;
@@ -1376,7 +1376,7 @@ void MainMenu::update() {
}
bool MainMenu::handleMessage(Command *message) {
- if (message->_cmd != 17)
+ if (message->_cmd != kCmdMessage)
return false;
if (!_scene)
@@ -1810,7 +1810,7 @@ ModalHelp::~ModalHelp() {
}
bool ModalHelp::handleMessage(Command *cmd) {
- if (cmd->_cmd == 17) {
+ if (cmd->_cmd == kCmdMessage) {
int msg = cmd->_messageNum;
if (msg == 29 || msg == 36 || msg == 107) {
@@ -1950,7 +1950,7 @@ void QueryDlg::update() {
}
bool QueryDlg::handleMessage(Command *cmd) {
- if (cmd->_cmd == 17) {
+ if (cmd->_cmd == kCmdMessage) {
if (cmd->_messageNum == 29) {
if (_okBtn->isPointInside(g_nmi->_mouseScreenPos.x, g_nmi->_mouseScreenPos.y)) {
_queryResult = 1;
@@ -2518,7 +2518,7 @@ void ModalDemo::update() {
}
bool ModalDemo::handleMessage(Command *cmd) {
- if (cmd->_cmd != 17)
+ if (cmd->_cmd != kCmdMessage)
return false;
if (cmd->_messageNum == 29) {
diff --git a/engines/ngi/motion.cpp b/engines/ngi/motion.cpp
index a218b088aff..8b93d482aeb 100644
--- a/engines/ngi/motion.cpp
+++ b/engines/ngi/motion.cpp
@@ -253,7 +253,7 @@ MessageQueue *MctlCompound::startMove(AniObject *ani, int sourceX, int sourceY,
mq->addCommandToEnd(ex);
}
- Command *ex = new Command(ani->_id, 51, 0, sourceX, sourceY, 0, 1, 0, 0, 0);
+ Command *ex = new Command(ani->_id, kCmdStartWalkTo, 0, sourceX, sourceY, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_invId = fuzzyMatch;
@@ -322,7 +322,7 @@ MessageQueue *MctlCompound::makeQueue(AniObject *subj, int xpos, int ypos, int f
mq->addCommandToEnd(ex);
}
- ex = new Command(subj->_id, 51, 0, xpos, ypos, 0, 1, 0, 0, 0);
+ ex = new Command(subj->_id, kCmdStartWalkTo, 0, xpos, ypos, 0, 1, 0, 0, 0);
ex->_invId = fuzzyMatch;
ex->_param = subj->_copyId;
@@ -572,7 +572,7 @@ MessageQueue *MctlLadder::makeQueue(AniObject *ani, int xpos, int ypos, int fuzz
mq = _aniHandler.makeRunQueue(&mkQueue);
- ex = new Command(ani->_id, 1, _ladmovements[pos]->movementIds->upStopId, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ani->_id, kCmdStartMovement, _ladmovements[pos]->movementIds->upStopId, 0, 0, 0, 1, 0, 0, 0);
ex->_param = ani->_copyId;
ex->_excFlags |= 2;
@@ -638,7 +638,7 @@ MessageQueue *MctlLadder::makeQueue(AniObject *ani, int xpos, int ypos, int fuzz
mq = _aniHandler.makeRunQueue(&mkQueue);
- ex = new Command(ani->_id, 1, _ladmovements[pos]->movementIds->downStopId, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ani->_id, kCmdStartMovement, _ladmovements[pos]->movementIds->downStopId, 0, 0, 0, 1, 0, 0, 0);
ex->_param = ani->_copyId;
ex->_excFlags |= 2;
@@ -963,17 +963,17 @@ MessageQueue *MovGraph::startMove(AniObject *ani, int xpos, int ypos, int fuzzyM
Command *ex = mq->getCommandByIndex(0);
- if ((ex->_cmd != 1 && ex->_cmd != 20) || ex->_messageNum != ani->_movement->_id ||
+ if ((ex->_cmd != kCmdStartMovement && ex->_cmd != kCmdStartSliding) || ex->_messageNum != ani->_movement->_id ||
(ex->_z >= 1 && ex->_z <= ani->_movement->_curFrame)) {
mq = new MessageQueue(g_nmi->_globalMessageQueueList->compact());
- ex = new Command(ani->_id, 21, 0, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(ani->_id, kCmdPlayIdle, 0, 0, 0, 0, 1, 0, 0, 0);
ex->_param = ani->_copyId;
ex->_field_3C = 1;
ex->_wait = 0;
mq->addCommandToEnd(ex);
- ex = new Command(ani->_id, 51, 0, xpos, ypos, 0, 1, 0, 0, 0);
+ ex = new Command(ani->_id, kCmdStartWalkTo, 0, xpos, ypos, 0, 1, 0, 0, 0);
ex->_param = ani->_copyId;
ex->_field_3C = 1;
ex->_wait = 0;
@@ -1097,7 +1097,7 @@ MessageQueue *MovGraph::makeQueue(AniObject *subj, int xpos, int ypos, int fuzzy
Command *ex = mq->getCommandByIndex(0);
- if ((ex->_cmd != 1 && ex->_cmd != 20) ||
+ if ((ex->_cmd != kCmdStartMovement && ex->_cmd != kCmdStartSliding) ||
ex->_messageNum != subj->_movement->_id ||
(ex->_z >= 1 && ex->_z <= subj->_movement->_curFrame))
subj->playIdle();
@@ -1132,7 +1132,7 @@ MessageQueue *MovGraph::makeQueue(AniObject *subj, int xpos, int ypos, int fuzzy
MessageQueue *mq = makeWholeQueue(_items[idx].ani, &_items[idx].currentPath, staticsId);
if (mq) {
Command *ex = new Command();
- ex->_cmd = 17;
+ ex->_cmd = kCmdMessage;
ex->_messageNum = 54;
ex->_parentId = subj->_id;
ex->_field_3C = 1;
@@ -1329,7 +1329,7 @@ MessageQueue *MovGraph::startMove(AniObject *ani, GrPathDesc *movarr, int static
Command *ex = new Command();
- ex->_cmd = 17;
+ ex->_cmd = kCmdMessage;
ex->_messageNum = 54;
ex->_parentId = ani->_id;
ex->_field_3C = 1;
@@ -1967,7 +1967,7 @@ MessageQueue *MctlGraph::makeWholeQueue(GmctlMqStruct &mctlMQ) {
|| mctlMQ.items[i + 1].x == -1
|| mctlMQ.items[i + 1].y == -1) {
- Command *ex = new Command(_aniData[mctlMQ.objectIndex]._objectId, 1, mg2i->_movementId, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(_aniData[mctlMQ.objectIndex]._objectId, kCmdStartMovement, mg2i->_movementId, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 2;
ex->_mirror = mg2i->_mirror;
@@ -2095,7 +2095,7 @@ MessageQueue *MctlGraph::startMove(AniObject *ani, int xpos, int ypos, int fuzzy
return nullptr;
if (ani->_movement) {
- if (mq->getCount() <= 1 || mq->getCommandByIndex(0)->_cmd != 22) {
+ if (mq->getCount() <= 1 || mq->getCommandByIndex(0)->_cmd != kCmdSetStatic) {
PicAniInfo picAniInfo;
ani->getPicAniInfo(picAniInfo);
@@ -2204,7 +2204,7 @@ MessageQueue *MctlGraph::makeQueue(AniObject *obj, int xpos, int ypos, int fuzzy
return nullptr;
}
- Command *ex = new Command(picAniInfo.objectId, 1, _aniData[idx]._directions[idxsub]._turnS[idxwalk]._movementId, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(picAniInfo.objectId, kCmdStartMovement, _aniData[idx]._directions[idxsub]._turnS[idxwalk]._movementId, 0, 0, 0, 1, 0, 0, 0);
ex->_wait = 1;
ex->_param = picAniInfo.copyId;
@@ -2212,13 +2212,13 @@ MessageQueue *MctlGraph::makeQueue(AniObject *obj, int xpos, int ypos, int fuzzy
mq->addCommandToEnd(ex);
} else {
- Command *ex = new Command(picAniInfo.objectId, 22, obj->_statics->_staticsId, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(picAniInfo.objectId, kCmdSetStatic, obj->_statics->_staticsId, 0, 0, 0, 1, 0, 0, 0);
ex->_param = picAniInfo.copyId;
ex->_excFlags |= 3;
mq->addCommandToEnd(ex);
- ex = new Command(picAniInfo.objectId, 5, -1, obj->_x, obj->_y, 0, 1, 0, 0, 0);
+ ex = new Command(picAniInfo.objectId, kCmdShow, -1, obj->_x, obj->_y, 0, 1, 0, 0, 0);
ex->_z = -1;
ex->_param = picAniInfo.copyId;
@@ -2337,18 +2337,18 @@ MessageQueue *MctlGraph::makeQueue(AniObject *obj, int xpos, int ypos, int fuzzy
if (mq && mq->getCount() > 0 && picAniInfo.movementId) {
Command *ex = mq->getCommandByIndex(0);
- if (ex && (ex->_cmd == 1 || ex->_cmd == 20)
+ if (ex && (ex->_cmd == kCmdStartMovement || ex->_cmd == kCmdStartSliding)
&& picAniInfo.movementId == ex->_messageNum
&& picAniInfo.targetFrame == ex->_z) {
mq->removeCommand(0, 1);
} else {
- ex = new Command(picAniInfo.objectId, 5, ex->_messageNum, obj->_x, obj->_y, 0, 1, 0, 0, 0);
+ ex = new Command(picAniInfo.objectId, kCmdShow, ex->_messageNum, obj->_x, obj->_y, 0, 1, 0, 0, 0);
ex->_z = -1;
ex->_param = picAniInfo.copyId;
ex->_excFlags |= 2;
mq->addCommandToFront(ex);
- ex = new Command(picAniInfo.objectId, 22, _aniData[idx]._directions[idxsub]._prevStaticId, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(picAniInfo.objectId, kCmdSetStatic, _aniData[idx]._directions[idxsub]._prevStaticId, 0, 0, 0, 1, 0, 0, 0);
ex->_param = picAniInfo.copyId;
ex->_excFlags |= 3;
@@ -2559,7 +2559,7 @@ MessageQueue *MctlGraph::makeLineQueue(GmctlMqStruct *info) {
if (info->flags & 2) {
ex = new Command(
_aniData[info->objectIndex]._objectId,
- 5,
+ kCmdShow,
_aniData[info->objectIndex]._directions[info->sourceDir]._walk[1]._movementId,
info->sourcePos.x,
info->sourcePos.y,
@@ -2577,7 +2577,7 @@ MessageQueue *MctlGraph::makeLineQueue(GmctlMqStruct *info) {
} else {
ex = new Command(
_aniData[info->objectIndex]._objectId,
- 5,
+ kCmdShow,
_aniData[info->objectIndex]._directions[info->sourceDir]._walk[0]._movementId,
info->sourcePos.x,
info->sourcePos.y,
@@ -2647,7 +2647,7 @@ MessageQueue *MctlGraph::makeLineQueue(GmctlMqStruct *info) {
mq->addCommandToEnd(ex);
}
- ex = new Command(_aniData[info->objectIndex]._objectId, 5, -1, info->destPos.x, info->destPos.y, 0, 1, 0, 0, 0);
+ ex = new Command(_aniData[info->objectIndex]._objectId, kCmdShow, -1, info->destPos.x, info->destPos.y, 0, 1, 0, 0, 0);
ex->_z = info->destZ;
ex->_param = _aniData[info->objectIndex]._ani->_copyId;
diff --git a/engines/ngi/ngi.cpp b/engines/ngi/ngi.cpp
index f7f8b4f81d1..554db810737 100644
--- a/engines/ngi/ngi.cpp
+++ b/engines/ngi/ngi.cpp
@@ -298,7 +298,7 @@ bool NGIEngine::handleGuiEvent(const Common::Event &event) {
(event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END && event.customType == kActionCloseDialog);
if (event.type == Common::EVENT_LBUTTONUP || back) {
Command cmd;
- cmd._cmd = 17;
+ cmd._cmd = kCmdMessage;
cmd._messageNum = back ? 37 : 30;
cmd._x = event.mouse.x;
cmd._y = event.mouse.y;
@@ -485,7 +485,7 @@ bool NGIEngine::updateEvents() {
}
switch (event.type) {
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
- ex = new Command(0, 17, 36, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 36, 0, 0, 0, 1, 0, 0, 0);
ex->_param = event.customType;
ex->_excFlags |= 3;
ex->handle();
@@ -508,7 +508,7 @@ bool NGIEngine::updateEvents() {
return redraw;
}
- ex = new Command(0, 17, 36, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 36, 0, 0, 0, 1, 0, 0, 0);
ex->_param = 32;
ex->_excFlags |= 3;
ex->handle();
@@ -520,7 +520,7 @@ bool NGIEngine::updateEvents() {
return redraw;
}
- ex = new Command(0, 17, 36, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 36, 0, 0, 0, 1, 0, 0, 0);
ex->_param = event.kbd.keycode;
ex->_excFlags |= 3;
ex->handle();
@@ -529,7 +529,7 @@ bool NGIEngine::updateEvents() {
return redraw;
break;
default:
- ex = new Command(0, 17, 36, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 36, 0, 0, 0, 1, 0, 0, 0);
ex->_param = event.kbd.keycode;
ex->_excFlags |= 3;
ex->handle();
@@ -538,7 +538,7 @@ bool NGIEngine::updateEvents() {
break;
case Common::EVENT_KEYUP:
if (!_inputArFlag) {
- ex = new Command(0, 17, 37, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 37, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->handle();
}
@@ -546,7 +546,7 @@ bool NGIEngine::updateEvents() {
break;
case Common::EVENT_MOUSEMOVE:
if (_recordEvents) {
- ex = new Command(0, 17, 31, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 31, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->handle();
}
@@ -557,7 +557,7 @@ bool NGIEngine::updateEvents() {
return redraw;
case Common::EVENT_RBUTTONDOWN:
if (!_inputArFlag && (_updateTicks - _lastInputTicks) >= 2) {
- ex = new Command(0, 17, 107, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 107, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
_lastInputTicks = _updateTicks;
ex->handle();
@@ -566,7 +566,7 @@ bool NGIEngine::updateEvents() {
break;
case Common::EVENT_LBUTTONDOWN:
if (!_inputArFlag && (_updateTicks - _lastInputTicks) >= 2) {
- ex = new Command(0, 17, 29, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 29, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
ex->_sceneClickX = _sceneRect.left + ex->_x;
ex->_sceneClickY = _sceneRect.top + ex->_y;
@@ -579,7 +579,7 @@ bool NGIEngine::updateEvents() {
break;
case Common::EVENT_LBUTTONUP:
if (!_inputArFlag && (_updateTicks - _lastButtonUpTicks) >= 2) {
- ex = new Command(0, 17, 30, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, 30, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
_lastButtonUpTicks = _updateTicks;
ex->handle();
diff --git a/engines/ngi/stateloader.cpp b/engines/ngi/stateloader.cpp
index 032433581ad..9233e0c2fee 100644
--- a/engines/ngi/stateloader.cpp
+++ b/engines/ngi/stateloader.cpp
@@ -158,7 +158,7 @@ bool GameLoader::readSavegame(const char *fname) {
loadScene(preloadItem.sceneId);
- Command *ex = new Command(preloadItem.sceneId, 17, 62, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(preloadItem.sceneId, kCmdMessage, 62, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
ex->_param = preloadItem.param;
diff --git a/engines/ngi/statics.cpp b/engines/ngi/statics.cpp
index 67e7b3ebad7..8097726003b 100644
--- a/engines/ngi/statics.cpp
+++ b/engines/ngi/statics.cpp
@@ -277,7 +277,7 @@ bool AniObject::setQueue(MessageQueue *mq) {
void AniObject::restartMessageQueue(MessageQueue *mq) {
Command *ex = mq->getCommandByIndex(0);
if (ex) {
- while (ex->_cmd != 1 || ex->_parentId != _id) {
+ while (ex->_cmd != kCmdStartMovement || ex->_parentId != _id) {
ex->_parId = 0;
ex->_excFlags |= 2;
ex->handleMessage();
@@ -329,7 +329,7 @@ void AniObject::startMQIfIdle(int qId, int flag) {
Command *ex = mq->getCommandByIndex(0);
if (ex) {
- while (ex->_cmd != 1 || ex->_parentId != _id) {
+ while (ex->_cmd != kCmdStartMovement || ex->_parentId != _id) {
ex->_parId = 0;
ex->_excFlags |= 2;
ex->handleMessage();
@@ -787,10 +787,10 @@ bool AniObject::update(int counterdiff) {
if (!timedMovement && dyn->_delay == dyn->_countdown) {
ex = dyn->getCommand();
- if (ex && ex->_cmd != 35) {
+ if (ex && ex->_cmd != kCmdSound) {
newex = ex->createClone();
newex->_excFlags |= 2;
- if (newex->_cmd == 17) {
+ if (newex->_cmd == kCmdMessage) {
newex->_parentId = _id;
newex->_param = _copyId;
}
@@ -802,7 +802,7 @@ bool AniObject::update(int counterdiff) {
}
if (dyn->_delay == dyn->_countdown && dyn->_messageNum != 0) {
- newex = new Command(_id, 17, dyn->_messageNum, 0, 0, 0, 1, 0, 0, 0);
+ newex = new Command(_id, kCmdMessage, dyn->_messageNum, 0, 0, 0, 1, 0, 0, 0);
newex->_excFlags = 2;
newex->_param = _copyId;
newex->sendMessage();
@@ -823,7 +823,7 @@ bool AniObject::update(int counterdiff) {
} else if (dyn->_delay == dyn->_countdown) {
ex = dyn->getCommand();
if (ex) {
- if (ex->_cmd == 35) {
+ if (ex->_cmd == kCmdSound) {
newex = ex->createClone();
newex->_excFlags |= 2;
newex->sendMessage();
@@ -981,7 +981,7 @@ L12:
}
_movement = nullptr;
- Command *ex = new Command(_id, 17, 24, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(_id, kCmdMessage, 24, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _copyId;
ex->_excFlags = 2;
ex->postMessage();
@@ -1227,7 +1227,7 @@ void AniObject::startSliding(int movementId, int messageQueueId, int x, int y, c
Command *ex = _movement->_curPhase->getCommand();
if (ex) {
- if (ex->_cmd == 35) {
+ if (ex->_cmd == kCmdSound) {
Command *newEx = ex->createClone();
newEx->_excFlags |= 2u;
@@ -1252,7 +1252,7 @@ void AniObject::startSliding(int movementId, int messageQueueId, int x, int y, c
_counter = _initialCounter;
_targetFrame = someDynamicPhaseIndex;
- Command *ex = new Command(_id, 17, 23, 0, 0, movementId, 1, 0, 0, 0);
+ Command *ex = new Command(_id, kCmdMessage, 23, 0, 0, movementId, 1, 0, 0, 0);
ex->_param = _copyId;
ex->_excFlags = 2;
@@ -1344,7 +1344,7 @@ bool AniObject::startMovement(int movementId, int messageQueueId, int dynPhaseId
Command *ex = _movement->_curPhase->getCommand();
if (ex && !timedMovement) {
- if (ex->_cmd == 35) {
+ if (ex->_cmd == kCmdSound) {
Command *newex = ex->createClone();
newex->_excFlags |= 2;
newex->sendMessage();
@@ -1373,7 +1373,7 @@ bool AniObject::startMovement(int movementId, int messageQueueId, int dynPhaseId
_stepArray.clear();
- Command *newex = new Command(_id, 17, 23, 0, 0, movementId, 1, 0, 0, 0);
+ Command *newex = new Command(_id, kCmdMessage, 23, 0, 0, movementId, 1, 0, 0, 0);
newex->_param = _copyId;
newex->_excFlags = 2;
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index d6ebfe87775..4f5c08e14ac 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -803,7 +803,7 @@ private:
const char *idProperty = nullptr;
if (kind == "SHOW" || kind == "1") {
- cmd->_cmd = 5;
+ cmd->_cmd = kCmdShow;
cmd->_wait = 0;
if (!readId(node->values.getValOrDefault("ani"), cmd->_parentId))
return parserError("Unknown animation in SHOW");
@@ -815,59 +815,59 @@ private:
cmd->_z = atoi(node->values.getValOrDefault("z", "-1").c_str());
cmd->_auxParam = node->values.contains("mirror") ? (int)boolProperty(*node, "mirror") : -1;
} else if (kind == "SETSCENE") {
- cmd->_cmd = Command::kCmdSetScene;
+ cmd->_cmd = kCmdSetScene;
if (!readId(node->values.getValOrDefault("scene"), cmd->_parentId))
return parserError("Unknown destination scene");
idProperty = "entr";
} else if (kind == "ADD_INV_ITEM" || kind == "REMOVE_INV_ITEM") {
- cmd->_cmd = kind == "ADD_INV_ITEM" ? 56 : 57;
+ cmd->_cmd = kind == "ADD_INV_ITEM" ? kCmdAddInvItem : kCmdRemoveInvItem;
if (!readId(node->values.getValOrDefault("id"), cmd->_parentId))
return parserError("Unknown inventory item");
} else if (kind == "USER" && node->values.getValOrDefault("type") == "SET_LOGIC") {
- cmd->_cmd = Command::kCmdSetLogic;
+ cmd->_cmd = kCmdSetLogic;
cmd->_messageName = node->values.getValOrDefault("title");
cmd->_messageNum = intProperty(*node, "state");
} else if (kind == "USER" && node->values.getValOrDefault("type") == "MOVE_TO_STATIC") {
- cmd->_cmd = 19;
+ cmd->_cmd = kCmdMoveToStatic;
cmd->_auxParam = !node->values.contains("needShow") || boolProperty(*node, "needShow");
if (!readId(node->values.getValOrDefault("ani"), cmd->_parentId))
return parserError("Unknown object in MOVE_TO_STATIC");
if (!node->values.getValOrDefault("static").empty())
idProperty = "static";
} else if (kind == "USER" || kind == "12" || kind == "SET_STATIC" || kind == "25") {
- cmd->_cmd = 63;
+ cmd->_cmd = kCmdUser;
cmd->_messageName = node->values.getValOrDefault("type", kind);
cmd->_wait = 0;
} else if (kind == "START_MOVEMENT" || kind == "3") {
- cmd->_cmd = 1;
+ cmd->_cmd = kCmdStartMovement;
cmd->_mirror = boolProperty(*node, "mirror");
if (!readId(node->values.getValOrDefault("ani"), cmd->_parentId))
return parserError("Unknown animation in START_MOVEMENT");
idProperty = "mov";
} else if (kind == "HIDE" || kind == "2") {
- cmd->_cmd = 6;
+ cmd->_cmd = kCmdHide;
cmd->_wait = 0;
if (!readId(node->values.getValOrDefault("vis"), cmd->_parentId))
return parserError("Unknown object in HIDE");
} else if (kind == "QUEUE" || kind == "24") {
- cmd->_cmd = 18;
+ cmd->_cmd = kCmdQueue;
idProperty = "id";
} else if (kind == "SOUND" || kind == "7") {
if (cmd->_wait)
return parserError("Waiting for an XML sound is not implemented");
- cmd->_cmd = 35;
+ cmd->_cmd = kCmdSound;
cmd->_param = boolProperty(*node, "cycled");
cmd->_z = boolProperty(*node, "stop") ? 2 : 1;
if (!readId(node->values.getValOrDefault("id"), cmd->_messageNum))
return parserError("Unknown sound in SOUND");
} else if (kind == "MESSAGE" || kind == "5") {
- cmd->_cmd = 17;
+ cmd->_cmd = kCmdMessage;
cmd->_messageName = node->values.getValOrDefault("msg");
uint32 id;
if (_project._objectIds.findId(cmd->_messageName, id))
cmd->_messageNum = id;
} else if (kind == "PAUSE" || kind == "22") {
- cmd->_cmd = Command::kCmdPause;
+ cmd->_cmd = kCmdPause;
cmd->_messageNum = MAX(0, atoi(node->values.getValOrDefault("delay").c_str()));
} else {
return parserError("Unsupported XML command " + kind);
Commit: 7bc6ee1581eb21ac0e6e6e706901bbc54998c669
https://github.com/scummvm/scummvm/commit/7bc6ee1581eb21ac0e6e6e706901bbc54998c669
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Add MessageKind enum for the system message numbers
Changed paths:
engines/ngi/fullpipe/scene01.cpp
engines/ngi/fullpipe/scene02.cpp
engines/ngi/fullpipe/scene03.cpp
engines/ngi/fullpipe/scene04.cpp
engines/ngi/fullpipe/scene05.cpp
engines/ngi/fullpipe/scene06.cpp
engines/ngi/fullpipe/scene07.cpp
engines/ngi/fullpipe/scene08.cpp
engines/ngi/fullpipe/scene09.cpp
engines/ngi/fullpipe/scene10.cpp
engines/ngi/fullpipe/scene11.cpp
engines/ngi/fullpipe/scene12.cpp
engines/ngi/fullpipe/scene13.cpp
engines/ngi/fullpipe/scene14.cpp
engines/ngi/fullpipe/scene15.cpp
engines/ngi/fullpipe/scene16.cpp
engines/ngi/fullpipe/scene17.cpp
engines/ngi/fullpipe/scene18and19.cpp
engines/ngi/fullpipe/scene20.cpp
engines/ngi/fullpipe/scene21.cpp
engines/ngi/fullpipe/scene22.cpp
engines/ngi/fullpipe/scene23.cpp
engines/ngi/fullpipe/scene24.cpp
engines/ngi/fullpipe/scene25.cpp
engines/ngi/fullpipe/scene26.cpp
engines/ngi/fullpipe/scene27.cpp
engines/ngi/fullpipe/scene28.cpp
engines/ngi/fullpipe/scene29.cpp
engines/ngi/fullpipe/scene30.cpp
engines/ngi/fullpipe/scene31.cpp
engines/ngi/fullpipe/scene32.cpp
engines/ngi/fullpipe/scene33.cpp
engines/ngi/fullpipe/scene34.cpp
engines/ngi/fullpipe/scene35.cpp
engines/ngi/fullpipe/scene36.cpp
engines/ngi/fullpipe/scene37.cpp
engines/ngi/fullpipe/scene38.cpp
engines/ngi/fullpipe/sceneChapter.cpp
engines/ngi/fullpipe/sceneDbg.cpp
engines/ngi/fullpipe/sceneFinal.cpp
engines/ngi/fullpipe/sceneIntro.cpp
engines/ngi/fullpipe/sceneIntroDemo.cpp
engines/ngi/fullpipe/sceneTutorial.cpp
engines/ngi/gameloader.cpp
engines/ngi/interaction.cpp
engines/ngi/inventory.cpp
engines/ngi/lift.cpp
engines/ngi/messagehandlers.cpp
engines/ngi/messages.cpp
engines/ngi/messages.h
engines/ngi/modal.cpp
engines/ngi/ngi.cpp
engines/ngi/stateloader.cpp
engines/ngi/statics.cpp
diff --git a/engines/ngi/fullpipe/scene01.cpp b/engines/ngi/fullpipe/scene01.cpp
index 789f2596ef9..8c557317c0a 100644
--- a/engines/ngi/fullpipe/scene01.cpp
+++ b/engines/ngi/fullpipe/scene01.cpp
@@ -185,7 +185,7 @@ int sceneHandler01(Command *cmd) {
return 0;
}
- if (cmd->_messageNum != 0x21) {
+ if (cmd->_messageNum != kMsgUpdate) {
if (cmd->_messageNum == MSG_SC1_SHOWOSK2) {
g_vars->scene01_picSc01Osk2->_flags |= 4;
g_vars->scene01_picSc01Osk2->_z = 20;
diff --git a/engines/ngi/fullpipe/scene02.cpp b/engines/ngi/fullpipe/scene02.cpp
index 66aad1773a5..72e79b67af8 100644
--- a/engines/ngi/fullpipe/scene02.cpp
+++ b/engines/ngi/fullpipe/scene02.cpp
@@ -97,7 +97,7 @@ int sceneHandler02(Command *ex) {
sceneHandler02_onHideLadder();
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
if (g_nmi->_aniMan2->_x < g_nmi->_sceneRect.left + 200)
g_nmi->_currentScene->_x = g_nmi->_aniMan2->_x - g_nmi->_sceneRect.left - 300;
diff --git a/engines/ngi/fullpipe/scene03.cpp b/engines/ngi/fullpipe/scene03.cpp
index 4927482b75d..f2741e36cbb 100644
--- a/engines/ngi/fullpipe/scene03.cpp
+++ b/engines/ngi/fullpipe/scene03.cpp
@@ -218,7 +218,7 @@ void sceneHandler03_doTakeEgg(Command *ex) {
}
int sceneHandler03(Command *ex) {
- if (ex->_cmd != kCmdMessage && ex->_messageNum != 33)
+ if (ex->_cmd != kCmdMessage && ex->_messageNum != kMsgUpdate)
debugC(3, kDebugSceneLogic, "scene03: got message: kind %d, num: %d", ex->_cmd, ex->_messageNum);
if (ex->_cmd != kCmdMessage) {
@@ -272,11 +272,11 @@ int sceneHandler03(Command *ex) {
sceneHandler03_giveCoin(ex);
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(ex);
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(ex->_sceneClickX, ex->_sceneClickY);
if (ani && ani->_id == ANI_LIFTBUTTON) {
@@ -300,7 +300,7 @@ int sceneHandler03(Command *ex) {
}
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
diff --git a/engines/ngi/fullpipe/scene04.cpp b/engines/ngi/fullpipe/scene04.cpp
index 4b1c7fbc361..60183b29a2e 100644
--- a/engines/ngi/fullpipe/scene04.cpp
+++ b/engines/ngi/fullpipe/scene04.cpp
@@ -1425,7 +1425,7 @@ int sceneHandler04(Command *ex) {
sceneHandler04_testPlank(ex);
break;
- case 33:
+ case kMsgUpdate:
{
g_vars->scene04_dudePosX = g_nmi->_aniMan->_x;
g_vars->scene04_dudePosY = g_nmi->_aniMan->_y;
@@ -1507,7 +1507,7 @@ int sceneHandler04(Command *ex) {
}
break;
- case 29:
+ case kMsgLButtonDown:
{
int picid = g_nmi->_currentScene->getPictureObjectIdAtPos(ex->_sceneClickX, ex->_sceneClickY);
diff --git a/engines/ngi/fullpipe/scene05.cpp b/engines/ngi/fullpipe/scene05.cpp
index efa050e3589..ff10897a6ba 100644
--- a/engines/ngi/fullpipe/scene05.cpp
+++ b/engines/ngi/fullpipe/scene05.cpp
@@ -198,7 +198,7 @@ void sceneHandler05_testHatch(Command *inex) {
Command *ex;
if (g_nmi->_currentScene->findAniObjectById(ANI_BIGLUK, -1)->_statics->_staticsId == ST_BLK_CLOSED) {
- ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, kMsgPreloadScene, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
ex->postMessage();
@@ -231,7 +231,7 @@ void sceneHandler05_testHatch(Command *inex) {
ex->_excFlags |= 2u;
mq->addCommandToEnd(ex);
- ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, kMsgPreloadScene, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -247,7 +247,7 @@ void sceneHandler05_testHatch(Command *inex) {
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, kMsgPreloadScene, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -273,7 +273,7 @@ void sceneHandler05_testHatch(Command *inex) {
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, kMsgPreloadScene, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -293,7 +293,7 @@ void sceneHandler05_testHatch(Command *inex) {
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
- ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, kMsgPreloadScene, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
mq->addCommandToEnd(ex);
@@ -303,7 +303,7 @@ void sceneHandler05_testHatch(Command *inex) {
return;
} else {
- ex = new Command(SC_5, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_5, kCmdMessage, kMsgPreloadScene, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaLeft;
ex->_excFlags |= 2;
ex->postMessage();
@@ -360,7 +360,7 @@ int sceneHandler05(Command *ex) {
sceneHandler05_testHatch(ex);
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
if (g_nmi->_aniMan2) {
diff --git a/engines/ngi/fullpipe/scene06.cpp b/engines/ngi/fullpipe/scene06.cpp
index 7a3f8e2a78c..f5a9d90db04 100644
--- a/engines/ngi/fullpipe/scene06.cpp
+++ b/engines/ngi/fullpipe/scene06.cpp
@@ -617,7 +617,7 @@ int sceneHandler06(Command *ex) {
sceneHandler06_enableDrops();
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(ex);
break;
@@ -625,7 +625,7 @@ int sceneHandler06(Command *ex) {
sceneHandler06_takeBall();
break;
- case 30:
+ case kMsgLButtonUp:
if (g_vars->scene06_aimingBall) {
sceneHandler06_aiming();
break;
@@ -637,7 +637,7 @@ int sceneHandler06(Command *ex) {
}
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *st = g_nmi->_currentScene->findAniObjectAtPos(ex->_sceneClickX, ex->_sceneClickY);
@@ -677,7 +677,7 @@ int sceneHandler06(Command *ex) {
}
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
diff --git a/engines/ngi/fullpipe/scene07.cpp b/engines/ngi/fullpipe/scene07.cpp
index 8d74d2d52bc..ccaf6633d1a 100644
--- a/engines/ngi/fullpipe/scene07.cpp
+++ b/engines/ngi/fullpipe/scene07.cpp
@@ -148,7 +148,7 @@ int sceneHandler07(Command *ex) {
sceneHandler07_hideBox();
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
diff --git a/engines/ngi/fullpipe/scene08.cpp b/engines/ngi/fullpipe/scene08.cpp
index b463fdb5a21..7752882b4c6 100644
--- a/engines/ngi/fullpipe/scene08.cpp
+++ b/engines/ngi/fullpipe/scene08.cpp
@@ -415,7 +415,7 @@ void sceneHandler08_checkEndArcade() {
}
Command *ex = new Command(SC_8, kCmdMessage, 0, 0, 0, 0, 1, 0, 0, 0);
- ex->_messageNum = 61;
+ ex->_messageNum = kMsgPreloadScene;
ex->_excFlags |= 2;
ex->_param = TrubaUp;
@@ -467,7 +467,7 @@ int sceneHandler08(Command *cmd) {
sceneHandler08_startArcade();
break;
- case 29:
+ case kMsgLButtonDown:
if (g_vars->scene08_inArcade) {
if (g_vars->scene08_inAir) {
sceneHandler08_airMoves();
@@ -480,7 +480,7 @@ int sceneHandler08(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
diff --git a/engines/ngi/fullpipe/scene09.cpp b/engines/ngi/fullpipe/scene09.cpp
index d0a3fcf384e..0bd58a987f0 100644
--- a/engines/ngi/fullpipe/scene09.cpp
+++ b/engines/ngi/fullpipe/scene09.cpp
@@ -466,7 +466,7 @@ int sceneHandler09(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
@@ -504,7 +504,7 @@ int sceneHandler09(Command *cmd) {
}
break;
- case 30:
+ case kMsgLButtonUp:
if (g_vars->scene09_interactingHanger >= 0) {
if (ABS(g_vars->scene09_hangers[g_vars->scene09_interactingHanger]->phase) < 15) {
g_vars->scene09_hangers[g_vars->scene09_interactingHanger]->ani->_callback2 = nullptr; // Really NULL
@@ -516,7 +516,7 @@ int sceneHandler09(Command *cmd) {
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(g_nmi->_sceneRect.left + cmd->_x, g_nmi->_sceneRect.top + cmd->_y);
diff --git a/engines/ngi/fullpipe/scene10.cpp b/engines/ngi/fullpipe/scene10.cpp
index bfc957419c8..3f800102e36 100644
--- a/engines/ngi/fullpipe/scene10.cpp
+++ b/engines/ngi/fullpipe/scene10.cpp
@@ -168,11 +168,11 @@ int sceneHandler10(Command *ex) {
sceneHandler10_showGum();
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(ex);
break;
- case 29:
+ case kMsgLButtonDown:
{
if (g_nmi->_currentScene->getPictureObjectIdAtPos(ex->_sceneClickX, ex->_sceneClickY) == PIC_SC10_LADDER) {
handleObjectInteraction(g_nmi->_aniMan, g_nmi->_currentScene->findPictureObjectById(PIC_SC10_DTRUBA, 0), ex->_param);
@@ -192,7 +192,7 @@ int sceneHandler10(Command *ex) {
}
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
diff --git a/engines/ngi/fullpipe/scene11.cpp b/engines/ngi/fullpipe/scene11.cpp
index 2cbd85a1106..d3e15fb1383 100644
--- a/engines/ngi/fullpipe/scene11.cpp
+++ b/engines/ngi/fullpipe/scene11.cpp
@@ -420,7 +420,7 @@ void sceneHandler11_jumpHitAndWin() {
mq->addCommandToEnd(ex);
- ex = new Command(SC_11, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(SC_11, kCmdMessage, kMsgPreloadScene, 0, 0, 0, 1, 0, 0, 0);
ex->_param = TrubaRight;
ex->_excFlags = 3;
@@ -629,13 +629,13 @@ int sceneHandler11(Command *cmd) {
sceneHandler11_showSwing();
break;
- case 107:
+ case kMsgRButtonDown:
if (g_vars->scene11_arcadeIsOn) {
sceneHandler11_swingLogic();
}
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
@@ -731,7 +731,7 @@ int sceneHandler11(Command *cmd) {
}
break;
- case 29:
+ case kMsgLButtonDown:
if (g_vars->scene11_swingIsSwinging) {
if (g_nmi->_currentScene->findAniObjectAtPos(g_nmi->_sceneRect.left + cmd->_x, g_nmi->_sceneRect.top + cmd->_y) == g_vars->scene11_swingie
&& cmd->_param == ANI_INV_BOOT)
diff --git a/engines/ngi/fullpipe/scene12.cpp b/engines/ngi/fullpipe/scene12.cpp
index 70f2346ac53..e4342b62c4c 100644
--- a/engines/ngi/fullpipe/scene12.cpp
+++ b/engines/ngi/fullpipe/scene12.cpp
@@ -57,7 +57,7 @@ void sceneHandler12_updateFloaters() {
int sceneHandler12(Command *cmd) {
int res = 0;
- if (cmd->_cmd == kCmdMessage && cmd->_messageNum == 33) {
+ if (cmd->_cmd == kCmdMessage && cmd->_messageNum == kMsgUpdate) {
if (g_nmi->_aniMan2) {
if (g_nmi->_aniMan2->_x < g_nmi->_sceneRect.left + 200)
g_nmi->_currentScene->_x = g_nmi->_aniMan2->_x - g_nmi->_sceneRect.left - 300;
diff --git a/engines/ngi/fullpipe/scene13.cpp b/engines/ngi/fullpipe/scene13.cpp
index 10cce82ca32..621ce534344 100644
--- a/engines/ngi/fullpipe/scene13.cpp
+++ b/engines/ngi/fullpipe/scene13.cpp
@@ -316,7 +316,7 @@ int sceneHandler13(Command *cmd) {
sceneHandler13_showGum();
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
@@ -335,7 +335,7 @@ int sceneHandler13(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
{
int res = 0;
int x;
diff --git a/engines/ngi/fullpipe/scene14.cpp b/engines/ngi/fullpipe/scene14.cpp
index b47aa4090a1..3fa0151305b 100644
--- a/engines/ngi/fullpipe/scene14.cpp
+++ b/engines/ngi/fullpipe/scene14.cpp
@@ -745,11 +745,11 @@ int sceneHandler14(Command *cmd) {
g_vars->scene14_grandmaIsHere = false;
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(cmd);
break;
- case 33:
+ case kMsgUpdate:
{
Movement *mov = g_nmi->_aniMan->_movement;
@@ -796,7 +796,7 @@ int sceneHandler14(Command *cmd) {
}
break;
- case 30:
+ case kMsgLButtonUp:
if (g_vars->scene14_dudeIsKicking) {
sceneHandler14_kickAnimation();
break;
@@ -807,7 +807,7 @@ int sceneHandler14(Command *cmd) {
}
break;
- case 29:
+ case kMsgLButtonDown:
if (g_vars->scene14_arcadeIsOn) {
if (g_vars->scene14_dudeCanKick && g_nmi->_aniMan->hit(cmd->_sceneClickX, cmd->_sceneClickY) && !g_nmi->_aniMan->_movement) {
sceneHandler14_dudeDecline();
diff --git a/engines/ngi/fullpipe/scene15.cpp b/engines/ngi/fullpipe/scene15.cpp
index e5a55a9f467..680ab583ebf 100644
--- a/engines/ngi/fullpipe/scene15.cpp
+++ b/engines/ngi/fullpipe/scene15.cpp
@@ -154,11 +154,11 @@ int sceneHandler15(Command *cmd) {
}
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(cmd);
break;
- case 29:
+ case kMsgLButtonDown:
{
if (g_nmi->_currentScene->getPictureObjectIdAtPos(cmd->_sceneClickX, cmd->_sceneClickY) == PIC_SC15_LADDER) {
handleObjectInteraction(g_nmi->_aniMan, g_nmi->_currentScene->findPictureObjectById(PIC_SC15_DTRUBA, 0), cmd->_param);
@@ -177,11 +177,11 @@ int sceneHandler15(Command *cmd) {
}
break;
- case 30:
+ case kMsgLButtonUp:
// nop
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene16.cpp b/engines/ngi/fullpipe/scene16.cpp
index 83057841528..782ffc2a443 100644
--- a/engines/ngi/fullpipe/scene16.cpp
+++ b/engines/ngi/fullpipe/scene16.cpp
@@ -446,7 +446,7 @@ int sceneHandler16(Command *cmd) {
sceneHandler16_showWire();
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene17.cpp b/engines/ngi/fullpipe/scene17.cpp
index 7b8f3bdb888..17e6ab808ee 100644
--- a/engines/ngi/fullpipe/scene17.cpp
+++ b/engines/ngi/fullpipe/scene17.cpp
@@ -205,7 +205,7 @@ int sceneHandler17(Command *cmd) {
sceneHandler17_showSugar();
break;
- case 29:
+ case kMsgLButtonDown:
{
int pic = g_nmi->_currentScene->getPictureObjectIdAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
@@ -224,7 +224,7 @@ int sceneHandler17(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
{
int x = g_vars->scene17_sceneEdgeX;
g_vars->scene17_sceneOldEdgeX = g_vars->scene17_sceneEdgeX;
diff --git a/engines/ngi/fullpipe/scene18and19.cpp b/engines/ngi/fullpipe/scene18and19.cpp
index e2b196c9d09..9cc8bc3f7ae 100644
--- a/engines/ngi/fullpipe/scene18and19.cpp
+++ b/engines/ngi/fullpipe/scene18and19.cpp
@@ -724,7 +724,7 @@ int sceneHandler18(Command *cmd) {
sceneHandler18and19_showBoyJump();
break;
- case 29:
+ case kMsgLButtonDown:
{
if (g_vars->scene18_enteredTrubaRight) {
cmd->_cmd = kCmdNone;
@@ -761,7 +761,7 @@ int sceneHandler18(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
@@ -850,7 +850,7 @@ int sceneHandler19(Command *cmd) {
sceneHandler18and19_showBoyJump();
break;
- case 29:
+ case kMsgLButtonDown:
if (g_vars->scene18_enteredTrubaRight) {
switch (g_nmi->_currentScene->getPictureObjectIdAtPos(cmd->_sceneClickX, cmd->_sceneClickY)) {
case PIC_SC19_RTRUBA1:
@@ -893,7 +893,7 @@ int sceneHandler19(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene20.cpp b/engines/ngi/fullpipe/scene20.cpp
index 36ea1f84496..5f1053f757b 100644
--- a/engines/ngi/fullpipe/scene20.cpp
+++ b/engines/ngi/fullpipe/scene20.cpp
@@ -123,7 +123,7 @@ int sceneHandler20(Command *cmd) {
scene20_setExits(g_nmi->_currentScene);
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene21.cpp b/engines/ngi/fullpipe/scene21.cpp
index dfde82ace8d..b04746b093b 100644
--- a/engines/ngi/fullpipe/scene21.cpp
+++ b/engines/ngi/fullpipe/scene21.cpp
@@ -97,7 +97,7 @@ int sceneHandler21(Command *cmd) {
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
if (!ani || !canInteractAny(g_nmi->_aniMan, ani, cmd->_param)) {
@@ -114,7 +114,7 @@ int sceneHandler21(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene22.cpp b/engines/ngi/fullpipe/scene22.cpp
index f87301f49b4..9c926657a03 100644
--- a/engines/ngi/fullpipe/scene22.cpp
+++ b/engines/ngi/fullpipe/scene22.cpp
@@ -331,7 +331,7 @@ int sceneHandler22(Command *cmd) {
sceneHandler22_onHandleDown();
break;
- case 29:
+ case kMsgLButtonDown:
if (!g_vars->scene22_interactionIsDisabled) {
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
@@ -366,7 +366,7 @@ int sceneHandler22(Command *cmd) {
cmd->_cmd = kCmdNone;
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene23.cpp b/engines/ngi/fullpipe/scene23.cpp
index 4be9a427cb7..72aadad0b93 100644
--- a/engines/ngi/fullpipe/scene23.cpp
+++ b/engines/ngi/fullpipe/scene23.cpp
@@ -474,7 +474,7 @@ int sceneHandler23(Command *cmd) {
sceneHandler23_pushButton(cmd);
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
@@ -492,7 +492,7 @@ int sceneHandler23(Command *cmd) {
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
int picId;
diff --git a/engines/ngi/fullpipe/scene24.cpp b/engines/ngi/fullpipe/scene24.cpp
index 510ef7fc4f3..9e86c3f04db 100644
--- a/engines/ngi/fullpipe/scene24.cpp
+++ b/engines/ngi/fullpipe/scene24.cpp
@@ -97,7 +97,7 @@ void scene24_setPoolState() {
}
int sceneHandler24(Command *cmd) {
- if (cmd->_cmd == kCmdMessage && cmd->_messageNum == 33) {
+ if (cmd->_cmd == kCmdMessage && cmd->_messageNum == kMsgUpdate) {
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene25.cpp b/engines/ngi/fullpipe/scene25.cpp
index 2aebab8421c..4905ba8f54f 100644
--- a/engines/ngi/fullpipe/scene25.cpp
+++ b/engines/ngi/fullpipe/scene25.cpp
@@ -585,7 +585,7 @@ int sceneHandler25(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
int y = g_nmi->_aniMan2->_y;
@@ -633,7 +633,7 @@ int sceneHandler25(Command *cmd) {
}
break;
- case 29:
+ case kMsgLButtonDown:
{
int picId = g_nmi->_currentScene->getPictureObjectIdAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
diff --git a/engines/ngi/fullpipe/scene26.cpp b/engines/ngi/fullpipe/scene26.cpp
index 6460580ceab..a772c8a4c5d 100644
--- a/engines/ngi/fullpipe/scene26.cpp
+++ b/engines/ngi/fullpipe/scene26.cpp
@@ -325,7 +325,7 @@ int sceneHandler26(Command *cmd) {
sceneHandler26_hideVent();
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
@@ -335,7 +335,7 @@ int sceneHandler26(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene27.cpp b/engines/ngi/fullpipe/scene27.cpp
index f59d10dd5c8..610a2902c73 100644
--- a/engines/ngi/fullpipe/scene27.cpp
+++ b/engines/ngi/fullpipe/scene27.cpp
@@ -655,19 +655,19 @@ int sceneHandler27(Command *cmd) {
}
break;
- case 30:
+ case kMsgLButtonUp:
if (g_vars->scene27_dudeIsAiming) {
sceneHandler27_startAiming();
}
break;
- case 29:
+ case kMsgLButtonDown:
if (g_nmi->_aniMan == g_nmi->_currentScene->findAniObjectAtPos(g_nmi->_sceneRect.left + cmd->_x, g_nmi->_sceneRect.top + cmd->_y) && g_vars->scene27_maxPhaseReached) {
sceneHandler27_initAiming(cmd);
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene28.cpp b/engines/ngi/fullpipe/scene28.cpp
index f46d2b9c5fb..a8ff5a5bf82 100644
--- a/engines/ngi/fullpipe/scene28.cpp
+++ b/engines/ngi/fullpipe/scene28.cpp
@@ -398,7 +398,7 @@ int sceneHandler28(Command *cmd) {
g_nmi->_aniMan->_flags &= 0xFEFF;
break;
- case 29:
+ case kMsgLButtonDown:
{
if (g_vars->scene28_lift6inside) {
runQueueByIdWithAni(g_nmi->_aniMan, QU_SC28_LIFT6_END, 1);
@@ -431,7 +431,7 @@ int sceneHandler28(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene29.cpp b/engines/ngi/fullpipe/scene29.cpp
index ea446bbb4df..50f1db3bfce 100644
--- a/engines/ngi/fullpipe/scene29.cpp
+++ b/engines/ngi/fullpipe/scene29.cpp
@@ -749,7 +749,7 @@ int sceneHandler29(Command *cmd) {
g_vars->scene29_manIsHit = false;
break;
- case 29:
+ case kMsgLButtonDown:
if (!g_vars->scene29_manIsRiding || g_vars->scene29_arcadeIsOn) {
if (!g_vars->scene29_arcadeIsOn) {
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(g_nmi->_sceneRect.left + cmd->_x, g_nmi->_sceneRect.top + cmd->_y);
@@ -767,13 +767,13 @@ int sceneHandler29(Command *cmd) {
}
break;
- case 107:
+ case kMsgRButtonDown:
if (g_vars->scene29_arcadeIsOn) {
sceneHandler29_manBend();
}
break;
- case 33:
+ case kMsgUpdate:
if (g_vars->scene29_arcadeIsOn) {
if (g_vars->scene29_manX > g_nmi->_sceneRect.right - 500)
g_nmi->_currentScene->_x = g_nmi->_sceneRect.right - g_vars->scene29_manX - 350;
diff --git a/engines/ngi/fullpipe/scene30.cpp b/engines/ngi/fullpipe/scene30.cpp
index e104aefd56e..2b12adf7edf 100644
--- a/engines/ngi/fullpipe/scene30.cpp
+++ b/engines/ngi/fullpipe/scene30.cpp
@@ -109,7 +109,7 @@ int sceneHandler30(Command *cmd) {
scene30_enablePass(g_nmi->_currentScene);
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(cmd);
break;
@@ -117,7 +117,7 @@ int sceneHandler30(Command *cmd) {
g_nmi->lift_goAnimation();
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(g_nmi->_sceneRect.left + cmd->_x, g_nmi->_sceneRect.top + cmd->_y);
@@ -129,7 +129,7 @@ int sceneHandler30(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene31.cpp b/engines/ngi/fullpipe/scene31.cpp
index 9979cef5525..1766db77c4b 100644
--- a/engines/ngi/fullpipe/scene31.cpp
+++ b/engines/ngi/fullpipe/scene31.cpp
@@ -96,7 +96,7 @@ int sceneHandler31(Command *cmd) {
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene32.cpp b/engines/ngi/fullpipe/scene32.cpp
index 7048dd1ee4a..a446410e276 100644
--- a/engines/ngi/fullpipe/scene32.cpp
+++ b/engines/ngi/fullpipe/scene32.cpp
@@ -346,7 +346,7 @@ int sceneHandler32(Command *cmd) {
sceneHandler32_buttonPush();
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(cmd);
break;
@@ -354,7 +354,7 @@ int sceneHandler32(Command *cmd) {
sceneHandler32_installHandle();
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
@@ -402,7 +402,7 @@ int sceneHandler32(Command *cmd) {
}
break;
- case 29:
+ case kMsgLButtonDown:
if (g_vars->scene32_dudeOnLadder) {
sceneHandler32_ladderLogic(cmd);
cmd->_cmd = kCmdNone;
diff --git a/engines/ngi/fullpipe/scene33.cpp b/engines/ngi/fullpipe/scene33.cpp
index 5dfe2093da1..a69ed76f9ee 100644
--- a/engines/ngi/fullpipe/scene33.cpp
+++ b/engines/ngi/fullpipe/scene33.cpp
@@ -265,7 +265,7 @@ int sceneHandler33(Command *cmd) {
sceneHandler33_handleDown();
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(g_nmi->_sceneRect.left + cmd->_x, g_nmi->_sceneRect.top + cmd->_y);
@@ -286,7 +286,7 @@ int sceneHandler33(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene34.cpp b/engines/ngi/fullpipe/scene34.cpp
index 2f64aac25db..7afc67461ba 100644
--- a/engines/ngi/fullpipe/scene34.cpp
+++ b/engines/ngi/fullpipe/scene34.cpp
@@ -388,7 +388,7 @@ int sceneHandler34(Command *cmd) {
sceneHandler34_showVent();
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(cmd);
break;
@@ -396,7 +396,7 @@ int sceneHandler34(Command *cmd) {
g_nmi->lift_goAnimation();
break;
- case 29:
+ case kMsgLButtonDown:
{
if (g_vars->scene34_dudeClimbed) {
sceneHandler34_animateAction(cmd);
@@ -445,7 +445,7 @@ int sceneHandler34(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene35.cpp b/engines/ngi/fullpipe/scene35.cpp
index b2aef7e1e75..2452e53407e 100644
--- a/engines/ngi/fullpipe/scene35.cpp
+++ b/engines/ngi/fullpipe/scene35.cpp
@@ -196,11 +196,11 @@ int sceneHandler35(Command *cmd) {
sceneHandler35_startFlow();
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(cmd);
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(g_nmi->_sceneRect.left + cmd->_x, g_nmi->_sceneRect.top + cmd->_y);
@@ -225,7 +225,7 @@ int sceneHandler35(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene36.cpp b/engines/ngi/fullpipe/scene36.cpp
index 934d77774af..68c865aa52c 100644
--- a/engines/ngi/fullpipe/scene36.cpp
+++ b/engines/ngi/fullpipe/scene36.cpp
@@ -57,7 +57,7 @@ int sceneHandler36(Command *cmd) {
return 0;
switch (cmd->_messageNum) {
- case 29:
+ case kMsgLButtonDown:
if (g_nmi->_currentScene->getPictureObjectIdAtPos(cmd->_sceneClickX, cmd->_sceneClickY) == PIC_SC36_MASK)
if (g_vars->scene36_scissors)
if (g_vars->scene36_scissors->_flags & 4)
@@ -70,7 +70,7 @@ int sceneHandler36(Command *cmd) {
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene37.cpp b/engines/ngi/fullpipe/scene37.cpp
index b874469ad70..f84a58a2e2f 100644
--- a/engines/ngi/fullpipe/scene37.cpp
+++ b/engines/ngi/fullpipe/scene37.cpp
@@ -242,7 +242,7 @@ int sceneHandler37(Command *cmd) {
sceneHandler37_updateRing(2);
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
@@ -261,7 +261,7 @@ int sceneHandler37(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/scene38.cpp b/engines/ngi/fullpipe/scene38.cpp
index 5243ff565e9..0e50090404a 100644
--- a/engines/ngi/fullpipe/scene38.cpp
+++ b/engines/ngi/fullpipe/scene38.cpp
@@ -366,11 +366,11 @@ int sceneHandler38(Command *cmd) {
sceneHandler38_drink();
break;
- case 64:
+ case kMsgResetDest:
g_nmi->lift_hoverButton(cmd);
break;
- case 29:
+ case kMsgLButtonDown:
{
AniObject *ani = g_nmi->_currentScene->findAniObjectAtPos(g_nmi->_sceneRect.left + cmd->_x, g_nmi->_sceneRect.top + cmd->_y);
@@ -382,7 +382,7 @@ int sceneHandler38(Command *cmd) {
}
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
int x = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/sceneChapter.cpp b/engines/ngi/fullpipe/sceneChapter.cpp
index d0b4aefb83e..54f4b5f3a73 100644
--- a/engines/ngi/fullpipe/sceneChapter.cpp
+++ b/engines/ngi/fullpipe/sceneChapter.cpp
@@ -175,8 +175,8 @@ public:
void saveload() override {}
bool handleMessage(Command *message) override {
- if (message->_cmd != kCmdMessage || (message->_messageNum != 30 &&
- !(message->_messageNum == 37 && message->_param == kActionCloseDialog)))
+ if (message->_cmd != kCmdMessage || (message->_messageNum != kMsgLButtonUp &&
+ !(message->_messageNum == kMsgKeyUp && message->_param == kActionCloseDialog)))
return false;
_visibleChars = _settings._title.size() + _settings._text.size();
_fader.fadeOut();
diff --git a/engines/ngi/fullpipe/sceneDbg.cpp b/engines/ngi/fullpipe/sceneDbg.cpp
index e2aaf1a1801..ca3e2ba614c 100644
--- a/engines/ngi/fullpipe/sceneDbg.cpp
+++ b/engines/ngi/fullpipe/sceneDbg.cpp
@@ -63,7 +63,7 @@ int sceneHandlerDbgMenu(Command *ex) {
int mx = g_nmi->_mouseScreenPos.x + g_nmi->_sceneRect.left;
int my = g_nmi->_mouseScreenPos.y + g_nmi->_sceneRect.top;
- if (ex->_messageNum == 29) {
+ if (ex->_messageNum == kMsgLButtonDown) {
GameObject *obj = sceneHandlerDbgMenu_getObjectAtXY(mx, my);
if (obj && canInteractAny(nullptr, obj, -3) ) {
getGameLoaderInteractionController()->enable();
@@ -71,7 +71,7 @@ int sceneHandlerDbgMenu(Command *ex) {
}
return 0;
}
- if (ex->_messageNum != 33) {
+ if (ex->_messageNum != kMsgUpdate) {
if (ex->_messageNum == MSG_RESTARTGAME) {
g_nmi->_needRestart = true;
return 0;
diff --git a/engines/ngi/fullpipe/sceneFinal.cpp b/engines/ngi/fullpipe/sceneFinal.cpp
index cc984269e68..66361c248f3 100644
--- a/engines/ngi/fullpipe/sceneFinal.cpp
+++ b/engines/ngi/fullpipe/sceneFinal.cpp
@@ -159,7 +159,7 @@ int sceneHandlerFinal(Command *cmd) {
sceneHandlerFinal_startFinal();
break;
- case 33:
+ case kMsgUpdate:
if (g_nmi->_aniMan2) {
g_vars->sceneFinal_var03 = g_nmi->_aniMan2->_x;
diff --git a/engines/ngi/fullpipe/sceneIntro.cpp b/engines/ngi/fullpipe/sceneIntro.cpp
index 5d748867c7f..a77629a4588 100644
--- a/engines/ngi/fullpipe/sceneIntro.cpp
+++ b/engines/ngi/fullpipe/sceneIntro.cpp
@@ -174,7 +174,7 @@ int sceneHandlerIntro(Command *ex) {
sceneHandlerIntro_part2();
return 0;
- case 33:
+ case kMsgUpdate:
// fall through
break;
diff --git a/engines/ngi/fullpipe/sceneIntroDemo.cpp b/engines/ngi/fullpipe/sceneIntroDemo.cpp
index 6474b9fc13f..4a0bc732ddc 100644
--- a/engines/ngi/fullpipe/sceneIntroDemo.cpp
+++ b/engines/ngi/fullpipe/sceneIntroDemo.cpp
@@ -79,7 +79,7 @@ int sceneHandlerIntroDemo(Command *ex) {
sceneHandlerIntroDemo_part2();
return 0;
- case 33:
+ case kMsgUpdate:
g_nmi->startSceneTrack();
break;
diff --git a/engines/ngi/fullpipe/sceneTutorial.cpp b/engines/ngi/fullpipe/sceneTutorial.cpp
index 289ad7f934d..6662d9e27e2 100644
--- a/engines/ngi/fullpipe/sceneTutorial.cpp
+++ b/engines/ngi/fullpipe/sceneTutorial.cpp
@@ -176,7 +176,7 @@ public:
}
bool handleMessage(Command *cmd) override {
- if (cmd->_cmd != kCmdMessage || cmd->_messageNum != 30)
+ if (cmd->_cmd != kCmdMessage || cmd->_messageNum != kMsgLButtonUp)
return false;
const Common::Point pos(cmd->_x, cmd->_y);
GameVar *root = g_nmi->getGameLoaderGameVar();
@@ -263,8 +263,8 @@ public:
if (cmd->_cmd != kCmdMessage)
return false;
GuiElement *close = _scene._guiManager->getElement("BTN_SC_NOTEBOOK_CLOSE");
- if ((cmd->_messageNum == 30 && close && close->hit(Common::Point(cmd->_x, cmd->_y))) ||
- cmd->_messageNum == 37) {
+ if ((cmd->_messageNum == kMsgLButtonUp && close && close->hit(Common::Point(cmd->_x, cmd->_y))) ||
+ cmd->_messageNum == kMsgKeyUp) {
_closed = true;
return true;
}
diff --git a/engines/ngi/gameloader.cpp b/engines/ngi/gameloader.cpp
index 8ec52b6cdf5..48e6bcb5fba 100644
--- a/engines/ngi/gameloader.cpp
+++ b/engines/ngi/gameloader.cpp
@@ -418,7 +418,7 @@ bool GameLoader::preloadScene(int sceneId, int entranceId) {
loadScene(_preloadItems[idx].sceneId);
- Command *ex = new Command(_preloadItems[idx].sceneId, kCmdMessage, 62, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(_preloadItems[idx].sceneId, kCmdMessage, kMsgSetScene, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
ex->_param = _preloadItems[idx].param;
@@ -589,7 +589,7 @@ bool GameLoader::updateContent(int counterdiff) {
_exCommand._cmd = kCmdMessage;
_updateCounter++;
- _exCommand._messageNum = 33;
+ _exCommand._messageNum = kMsgUpdate;
_exCommand._excFlags = 0;
_exCommand.postMessage();
}
diff --git a/engines/ngi/interaction.cpp b/engines/ngi/interaction.cpp
index a30469702e6..5829293bfe0 100644
--- a/engines/ngi/interaction.cpp
+++ b/engines/ngi/interaction.cpp
@@ -322,7 +322,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
ex->_excFlags = 3;
mq->addCommandToEnd(ex);
- ex = new Command(subj->_id, kCmdMessage, 0x40, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(subj->_id, kCmdMessage, kMsgResetDest, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->_param = 0;
mq->addCommandToEnd(ex);
@@ -371,7 +371,7 @@ bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj,
someFlag = true;
- ex = new Command(subj->_id, kCmdMessage, 0x40, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(subj->_id, kCmdMessage, kMsgResetDest, 0, 0, 0, 1, 0, 0, 0);
ex->_x = xpos;
ex->_y = ypos;
ex->_excFlags |= 3;
diff --git a/engines/ngi/inventory.cpp b/engines/ngi/inventory.cpp
index 4501a39064f..500b44620b1 100644
--- a/engines/ngi/inventory.cpp
+++ b/engines/ngi/inventory.cpp
@@ -401,7 +401,7 @@ reset:
void Inventory::slideIn() {
_isInventoryOut = false;
- Command *ex = new Command(0, kCmdMessage, 65, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, kMsgInventory, 0, 0, 0, 1, 0, 0, 0);
ex->_auxParam = 10;
ex->_z = _isInventoryOut;
@@ -413,7 +413,7 @@ void Inventory::slideIn() {
void Inventory::slideOut() {
_isInventoryOut = true;
- Command *ex = new Command(0, kCmdMessage, 65, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, kMsgInventory, 0, 0, 0, 1, 0, 0, 0);
ex->_auxParam = 10;
ex->_z = _isInventoryOut;
@@ -437,7 +437,7 @@ bool Inventory::onMouseLKeyDown(Command *cmd) {
unselectItem(0);
}
if (getItemFlags(icon.inventoryItemId) & 1) {
- Command *ex = new Command(0, kCmdMessage, 65, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(0, kCmdMessage, kMsgInventory, 0, 0, 0, 1, 0, 0, 0);
ex->_auxParam = 11;
ex->_z = _inventoryIcons[i].inventoryItemId;
ex->_excFlags |= 3;
diff --git a/engines/ngi/lift.cpp b/engines/ngi/lift.cpp
index b35e6f41f40..1fc419a9751 100644
--- a/engines/ngi/lift.cpp
+++ b/engines/ngi/lift.cpp
@@ -415,7 +415,7 @@ void NGIEngine::lift_goAnimation() {
mq->addCommandToEnd(ex);
- ex = new Command(parentId, kCmdMessage, 61, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(parentId, kCmdMessage, kMsgPreloadScene, 0, 0, 0, 1, 0, 0, 0);
ex->_param = buttonId;
ex->_excFlags |= 3;
diff --git a/engines/ngi/messagehandlers.cpp b/engines/ngi/messagehandlers.cpp
index 7bf151bf8d4..e9184e72f70 100644
--- a/engines/ngi/messagehandlers.cpp
+++ b/engines/ngi/messagehandlers.cpp
@@ -111,9 +111,9 @@ int global_messageHandler1(Command *cmd) {
if (g_nmi->_inputDisabled) {
if (cmd->_cmd == kCmdMessage) {
switch (cmd->_messageNum) {
- case 29:
- case 30:
- case 36:
+ case kMsgLButtonDown:
+ case kMsgLButtonUp:
+ case kMsgKeyDown:
case 106:
cmd->_cmd = kCmdNone;
break;
@@ -141,19 +141,19 @@ int global_messageHandler1(Command *cmd) {
case MSG_HMRKICK_METAL:
global_messageHandler_KickMetal();
break;
- case 29: // left mouse
+ case kMsgLButtonDown: // left mouse
if (g_nmi->_inventoryScene) {
if (getGameLoaderInventory()->onMouseLKeyDown(cmd))
cmd->_cmd = kCmdNone;
}
break;
- case 107: // right mouse
+ case kMsgRButtonDown: // right mouse
if (getGameLoaderInventory()->getSelectedItemId()) {
getGameLoaderInventory()->unselectItem(0);
cmd->_cmd = kCmdNone;
}
break;
- case 36: // keydown
+ case kMsgKeyDown: // keydown
g_nmi->defHandleKeyDown(cmd->_param);
switch (cmd->_param) {
@@ -205,7 +205,7 @@ int global_messageHandler1(Command *cmd) {
break;
}
break;
- case 33:
+ case kMsgUpdate:
if (!g_nmi->_inventoryScene)
break;
@@ -244,7 +244,7 @@ int global_messageHandler1(Command *cmd) {
g_nmi->_currSelectedInventoryItemId = 0;
g_nmi->setCursor(g_nmi->_cursorId);
break;
- case 65: // open map
+ case kMsgInventory: // open map
if (cmd->_auxParam == 11 && cmd->_z == ANI_INV_MAP && g_nmi->_flgCanOpenMap)
g_nmi->openMap();
break;
@@ -289,13 +289,13 @@ int global_messageHandler2(Command *cmd) {
// Unk3_sub_4477A0(&unk3, _parentId, _z != 0);
break;
- case 28:
+ case kMsgSetAniZ:
ani = g_nmi->_currentScene->findAniObjectById(cmd->_parentId, cmd->_param);
if (ani)
ani->_z = cmd->_z;
break;
- case 25:
+ case kMsgSetAniCallback:
ani = g_nmi->_currentScene->findAniObjectById(cmd->_parentId, cmd->_param);
if (ani) {
if (cmd->_z) {
@@ -308,7 +308,7 @@ int global_messageHandler2(Command *cmd) {
}
break;
- case 26:
+ case kMsgClearPhaseMessage:
ani = g_nmi->_currentScene->findAniObjectById(cmd->_parentId, cmd->_param);
if (ani) {
Movement *mov = ani->_movement;
@@ -329,7 +329,7 @@ int global_messageHandler2(Command *cmd) {
//debug_msg(_messageNum);
- if (!g_nmi->_soundEnabled || cmd->_messageNum != 33 || g_nmi->_currSoundListCount <= 0)
+ if (!g_nmi->_soundEnabled || cmd->_messageNum != kMsgUpdate || g_nmi->_currSoundListCount <= 0)
return res;
for (int snd = 0; snd < g_nmi->_currSoundListCount; snd++) {
@@ -349,11 +349,11 @@ int global_messageHandler3(Command *cmd) {
if (cmd->_cmd == kCmdMessage) {
switch (cmd->_messageNum) {
- case 29:
- case 30:
- case 31:
+ case kMsgLButtonDown:
+ case kMsgLButtonUp:
+ case kMsgMouseMove:
case 32:
- case 36:
+ case kMsgKeyDown:
if (g_nmi->_inputDisabled)
cmd->_cmd = kCmdNone;
break;
@@ -367,12 +367,12 @@ int global_messageHandler3(Command *cmd) {
switch (cmd->_cmd) {
case kCmdMessage:
switch (cmd->_messageNum) {
- case 61:
+ case kMsgPreloadScene:
debugC(0, kDebugEvents, "preload: { %d, %d },", cmd->_parentId, cmd->_param);
return g_nmi->_gameLoader->preloadScene(cmd->_parentId, cmd->_param);
- case 62:
+ case kMsgSetScene:
return g_nmi->_gameLoader->setScene(cmd->_parentId, cmd->_param);
- case 64:
+ case kMsgResetDest:
if (g_nmi->_currentScene && g_nmi->_msgObjectId2
&& (!(cmd->_param & 4) || g_nmi->_msgObjectId2 != cmd->_z || g_nmi->_msgId != cmd->_invId)) {
ani = g_nmi->_currentScene->findAniObjectById(g_nmi->_msgObjectId2, g_nmi->_msgId);
@@ -395,7 +395,7 @@ int global_messageHandler3(Command *cmd) {
g_nmi->_msgId = cmd->_invId;
}
return result;
- case 29:
+ case kMsgLButtonDown:
if (g_nmi->_gameLoader->_interactionController->_enabled && g_nmi->_currentScene) {
ani = g_nmi->_currentScene->findAniObjectAtPos(cmd->_sceneClickX, cmd->_sceneClickY);
ani2 = g_nmi->_currentScene->findAniObjectById(g_nmi->_gameLoader->_heroId, -1);
@@ -432,7 +432,7 @@ int global_messageHandler3(Command *cmd) {
debugC(0, kDebugPathfinding, "WWW 1");
result = startWalkTo(g_nmi->_gameLoader->_heroId, -1, cmd->_sceneClickX, cmd->_sceneClickY, 0);
if (result) {
- Command *ex = new Command(g_nmi->_gameLoader->_heroId, kCmdMessage, 64, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(g_nmi->_gameLoader->_heroId, kCmdMessage, kMsgResetDest, 0, 0, 0, 1, 0, 0, 0);
ex->_param = 1;
ex->_excFlags |= 3;
@@ -792,7 +792,7 @@ int MovGraph::messageHandler(Command *cmd) {
if (cmd->_cmd != kCmdMessage)
return 0;
- if (cmd->_messageNum != 33)
+ if (cmd->_messageNum != kMsgUpdate)
return 0;
AniObject *ani = g_nmi->_currentScene->findAniObjectById(g_nmi->_gameLoader->_heroId, -1);
diff --git a/engines/ngi/messages.cpp b/engines/ngi/messages.cpp
index fb86ca04a58..5a657d0b167 100644
--- a/engines/ngi/messages.cpp
+++ b/engines/ngi/messages.cpp
@@ -996,7 +996,7 @@ bool runQueueByIdWithAni(AniObject *obj, int queueId, int flags) {
}
void postExCommand(int parentId, int keyCode, int x, int y, int f20, int f14) {
- Command *ex = new Command(parentId, kCmdMessage, 64, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(parentId, kCmdMessage, kMsgResetDest, 0, 0, 0, 1, 0, 0, 0);
ex->_param = keyCode;
ex->_excFlags |= 3;
diff --git a/engines/ngi/messages.h b/engines/ngi/messages.h
index 1f9fff40e2d..1a116c6ac80 100644
--- a/engines/ngi/messages.h
+++ b/engines/ngi/messages.h
@@ -81,6 +81,33 @@ enum CommandKind {
kCmdSetLogic = 66
};
+/**
+ * Messages of the kCmdMessage command (_messageNum) that the engine itself posts or handles,
+ * as opposed to the per-scene MSG_* ids of the id list (constants.h).
+ *
+ * Android has no numbers for them: input arrives through the On* handlers of the controllers,
+ * and the few named ones are strings handled by CFPController::OnMessage. Only kMsgResetDest
+ * has an original name (MSG_RESETDEST), the others are named after what they do.
+ */
+enum MessageKind {
+ kMsgAniMovementStarted = 23, // posted by AniObject::startMovement / startSliding
+ kMsgAniMovementEnded = 24, // posted by AniObject::stopMovement
+ kMsgSetAniCallback = 25,
+ kMsgClearPhaseMessage = 26,
+ kMsgSetAniZ = 28,
+ kMsgLButtonDown = 29,
+ kMsgLButtonUp = 30,
+ kMsgMouseMove = 31,
+ kMsgUpdate = 33, // once per frame, not sent by the Android version
+ kMsgKeyDown = 36, // also keymapper actions, _param is the action or key
+ kMsgKeyUp = 37,
+ kMsgPreloadScene = 61,
+ kMsgSetScene = 62,
+ kMsgResetDest = 64, // Android MSG_RESETDEST
+ kMsgInventory = 65, // _auxParam selects slide (10) or item click (11)
+ kMsgRButtonDown = 107
+};
+
class Message : public CObject {
public:
int _cmd;
diff --git a/engines/ngi/modal.cpp b/engines/ngi/modal.cpp
index 2bebf6444c6..48484eba0e2 100644
--- a/engines/ngi/modal.cpp
+++ b/engines/ngi/modal.cpp
@@ -76,7 +76,7 @@ bool ModalIntro::handleMessage(Command *message) {
if (message->_cmd != kCmdMessage)
return false;
- if (message->_messageNum != 36)
+ if (message->_messageNum != kMsgKeyDown)
return false;
if (message->_param != kActionSkipIntro)
@@ -268,7 +268,7 @@ bool ModalIntroDemo::handleMessage(Command *message) {
if (message->_cmd != kCmdMessage)
return false;
- if (message->_messageNum != 36)
+ if (message->_messageNum != kMsgKeyDown)
return false;
if (message->_param != kActionSkipIntro)
@@ -613,7 +613,7 @@ bool MapWindow::handleMessage(Command *cmd) {
return false;
switch (cmd->_messageNum) {
- case 29:
+ case kMsgLButtonDown:
if (_picI03) {
if (_highlightedPic)
clickButton(_highlightedPic);
@@ -630,20 +630,20 @@ bool MapWindow::handleMessage(Command *cmd) {
return false;
- case 30:
+ case kMsgLButtonUp:
if (_picI03)
return false;
_flag = 0;
return false;
- case 36:
+ case kMsgKeyDown:
if (cmd->_param != kActionMapClose)
return false;
break;
- case 107:
+ case kMsgRButtonDown:
break;
default:
@@ -1138,7 +1138,7 @@ void ModalFinal::unloadScenes() {
}
bool ModalFinal::handleMessage(Command *cmd) {
- if (cmd->_cmd == kCmdMessage && cmd->_messageNum == 36 && cmd->_param == kActionPause) {
+ if (cmd->_cmd == kCmdMessage && cmd->_messageNum == kMsgKeyDown && cmd->_param == kActionPause) {
g_nmi->_modalObject = new MainMenu();
g_nmi->_modalObject->_parentObj = this;
@@ -1217,7 +1217,7 @@ CreditsController::~CreditsController() {
}
bool CreditsController::handleMessage(Command *cmd) {
- if (cmd->_cmd == kCmdMessage && cmd->_messageNum == 36 && cmd->_param == kActionSkipCredits) {
+ if (cmd->_cmd == kCmdMessage && cmd->_messageNum == kMsgKeyDown && cmd->_param == kActionSkipCredits) {
_fadeIn = false;
return true;
@@ -1384,7 +1384,7 @@ bool MainMenu::handleMessage(Command *message) {
Common::Point point;
- if (message->_messageNum == 29) {
+ if (message->_messageNum == kMsgLButtonDown) {
point.x = message->_x;
point.y = message->_y;
@@ -1411,14 +1411,14 @@ bool MainMenu::handleMessage(Command *message) {
return false;
}
- if (message->_messageNum == 30) {
+ if (message->_messageNum == kMsgLButtonUp) {
if (_lastArea)
_lastArea = nullptr;
return false;
}
- if (message->_messageNum != 36)
+ if (message->_messageNum != kMsgKeyDown)
return false;
if (message->_param == kActionPause)
@@ -1951,7 +1951,7 @@ void QueryDlg::update() {
bool QueryDlg::handleMessage(Command *cmd) {
if (cmd->_cmd == kCmdMessage) {
- if (cmd->_messageNum == 29) {
+ if (cmd->_messageNum == kMsgLButtonDown) {
if (_okBtn->isPointInside(g_nmi->_mouseScreenPos.x, g_nmi->_mouseScreenPos.y)) {
_queryResult = 1;
@@ -1960,7 +1960,7 @@ bool QueryDlg::handleMessage(Command *cmd) {
if (_cancelBtn->isPointInside(g_nmi->_mouseScreenPos.x, g_nmi->_mouseScreenPos.y))
_queryResult = 0;
- } else if (cmd->_messageNum == 36 && cmd->_param == kActionCloseDialog) {
+ } else if (cmd->_messageNum == kMsgKeyDown && cmd->_param == kActionCloseDialog) {
_queryResult = 0;
return false;
@@ -2308,9 +2308,9 @@ bool SaveGameDlg::handleMessage(Command *cmd) {
if (_queryDlg)
return _queryDlg->handleMessage(cmd);
- if (cmd->_messageNum == 29)
+ if (cmd->_messageNum == kMsgLButtonDown)
processMouse(cmd->_x, cmd->_y);
- else if (cmd->_messageNum == 36)
+ else if (cmd->_messageNum == kMsgKeyDown)
processKey(cmd->_param);
return false;
@@ -2521,10 +2521,10 @@ bool ModalDemo::handleMessage(Command *cmd) {
if (cmd->_cmd != kCmdMessage)
return false;
- if (cmd->_messageNum == 29) {
+ if (cmd->_messageNum == kMsgLButtonDown) {
if (_button->isPointInside(g_nmi->_mouseScreenPos.x, g_nmi->_mouseScreenPos.y))
_clickedQuit = 1;
- } else if (cmd->_messageNum == 36 && (cmd->_param == kActionPause || g_nmi->getLanguage() == Common::RU_RUS)) {
+ } else if (cmd->_messageNum == kMsgKeyDown && (cmd->_param == kActionPause || g_nmi->getLanguage() == Common::RU_RUS)) {
_clickedQuit = 1;
}
diff --git a/engines/ngi/ngi.cpp b/engines/ngi/ngi.cpp
index 554db810737..eee8e01945d 100644
--- a/engines/ngi/ngi.cpp
+++ b/engines/ngi/ngi.cpp
@@ -485,7 +485,7 @@ bool NGIEngine::updateEvents() {
}
switch (event.type) {
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
- ex = new Command(0, kCmdMessage, 36, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgKeyDown, 0, 0, 0, 1, 0, 0, 0);
ex->_param = event.customType;
ex->_excFlags |= 3;
ex->handle();
@@ -508,7 +508,7 @@ bool NGIEngine::updateEvents() {
return redraw;
}
- ex = new Command(0, kCmdMessage, 36, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgKeyDown, 0, 0, 0, 1, 0, 0, 0);
ex->_param = 32;
ex->_excFlags |= 3;
ex->handle();
@@ -520,7 +520,7 @@ bool NGIEngine::updateEvents() {
return redraw;
}
- ex = new Command(0, kCmdMessage, 36, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgKeyDown, 0, 0, 0, 1, 0, 0, 0);
ex->_param = event.kbd.keycode;
ex->_excFlags |= 3;
ex->handle();
@@ -529,7 +529,7 @@ bool NGIEngine::updateEvents() {
return redraw;
break;
default:
- ex = new Command(0, kCmdMessage, 36, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgKeyDown, 0, 0, 0, 1, 0, 0, 0);
ex->_param = event.kbd.keycode;
ex->_excFlags |= 3;
ex->handle();
@@ -538,7 +538,7 @@ bool NGIEngine::updateEvents() {
break;
case Common::EVENT_KEYUP:
if (!_inputArFlag) {
- ex = new Command(0, kCmdMessage, 37, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgKeyUp, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->handle();
}
@@ -546,7 +546,7 @@ bool NGIEngine::updateEvents() {
break;
case Common::EVENT_MOUSEMOVE:
if (_recordEvents) {
- ex = new Command(0, kCmdMessage, 31, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgMouseMove, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
ex->handle();
}
@@ -557,7 +557,7 @@ bool NGIEngine::updateEvents() {
return redraw;
case Common::EVENT_RBUTTONDOWN:
if (!_inputArFlag && (_updateTicks - _lastInputTicks) >= 2) {
- ex = new Command(0, kCmdMessage, 107, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgRButtonDown, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
_lastInputTicks = _updateTicks;
ex->handle();
@@ -566,7 +566,7 @@ bool NGIEngine::updateEvents() {
break;
case Common::EVENT_LBUTTONDOWN:
if (!_inputArFlag && (_updateTicks - _lastInputTicks) >= 2) {
- ex = new Command(0, kCmdMessage, 29, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgLButtonDown, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
ex->_sceneClickX = _sceneRect.left + ex->_x;
ex->_sceneClickY = _sceneRect.top + ex->_y;
@@ -579,7 +579,7 @@ bool NGIEngine::updateEvents() {
break;
case Common::EVENT_LBUTTONUP:
if (!_inputArFlag && (_updateTicks - _lastButtonUpTicks) >= 2) {
- ex = new Command(0, kCmdMessage, 30, 0, 0, 0, 1, 0, 0, 0);
+ ex = new Command(0, kCmdMessage, kMsgLButtonUp, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags |= 3;
_lastButtonUpTicks = _updateTicks;
ex->handle();
diff --git a/engines/ngi/stateloader.cpp b/engines/ngi/stateloader.cpp
index 9233e0c2fee..37bc7c81ead 100644
--- a/engines/ngi/stateloader.cpp
+++ b/engines/ngi/stateloader.cpp
@@ -158,7 +158,7 @@ bool GameLoader::readSavegame(const char *fname) {
loadScene(preloadItem.sceneId);
- Command *ex = new Command(preloadItem.sceneId, kCmdMessage, 62, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(preloadItem.sceneId, kCmdMessage, kMsgSetScene, 0, 0, 0, 1, 0, 0, 0);
ex->_excFlags = 2;
ex->_param = preloadItem.param;
diff --git a/engines/ngi/statics.cpp b/engines/ngi/statics.cpp
index 8097726003b..d403d22acbc 100644
--- a/engines/ngi/statics.cpp
+++ b/engines/ngi/statics.cpp
@@ -981,7 +981,7 @@ L12:
}
_movement = nullptr;
- Command *ex = new Command(_id, kCmdMessage, 24, 0, 0, 0, 1, 0, 0, 0);
+ Command *ex = new Command(_id, kCmdMessage, kMsgAniMovementEnded, 0, 0, 0, 1, 0, 0, 0);
ex->_param = _copyId;
ex->_excFlags = 2;
ex->postMessage();
@@ -1252,7 +1252,7 @@ void AniObject::startSliding(int movementId, int messageQueueId, int x, int y, c
_counter = _initialCounter;
_targetFrame = someDynamicPhaseIndex;
- Command *ex = new Command(_id, kCmdMessage, 23, 0, 0, movementId, 1, 0, 0, 0);
+ Command *ex = new Command(_id, kCmdMessage, kMsgAniMovementStarted, 0, 0, movementId, 1, 0, 0, 0);
ex->_param = _copyId;
ex->_excFlags = 2;
@@ -1373,7 +1373,7 @@ bool AniObject::startMovement(int movementId, int messageQueueId, int dynPhaseId
_stepArray.clear();
- Command *newex = new Command(_id, kCmdMessage, 23, 0, 0, movementId, 1, 0, 0, 0);
+ Command *newex = new Command(_id, kCmdMessage, kMsgAniMovementStarted, 0, 0, movementId, 1, 0, 0, 0);
newex->_param = _copyId;
newex->_excFlags = 2;
Commit: 43e52b67064de739001475a65bcbd6256af9996f
https://github.com/scummvm/scummvm/commit/43e52b67064de739001475a65bcbd6256af9996f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Name the padding fields of PicAniInfo, MessageHandler and Sc2
Changed paths:
engines/ngi/gameloader.cpp
engines/ngi/gameloader.h
engines/ngi/messages.h
engines/ngi/objects.h
engines/ngi/stateloader.cpp
engines/ngi/statesaver.cpp
diff --git a/engines/ngi/gameloader.cpp b/engines/ngi/gameloader.cpp
index 48e6bcb5fba..b8817fa857e 100644
--- a/engines/ngi/gameloader.cpp
+++ b/engines/ngi/gameloader.cpp
@@ -605,7 +605,7 @@ bool GameLoader::updateContent(int counterdiff) {
Sc2::Sc2() :
_sceneId(0),
- _field_2(0),
+ _padding2(0),
_scene(nullptr),
_isLoaded(false),
_motionController(nullptr) {}
diff --git a/engines/ngi/gameloader.h b/engines/ngi/gameloader.h
index f4dca09bdc3..43f741fc305 100644
--- a/engines/ngi/gameloader.h
+++ b/engines/ngi/gameloader.h
@@ -43,7 +43,7 @@ class MovGraph;
class Sc2 : public CObject {
public:
int16 _sceneId;
- int16 _field_2;
+ int16 _padding2;
Scene *_scene;
/** owned */
MotionController *_motionController;
diff --git a/engines/ngi/messages.h b/engines/ngi/messages.h
index 1a116c6ac80..c53faa1610b 100644
--- a/engines/ngi/messages.h
+++ b/engines/ngi/messages.h
@@ -255,7 +255,7 @@ public:
struct MessageHandler {
int (*callback)(Command *cmd);
int16 id;
- int16 field_6;
+ int16 padding6;
int index;
MessageHandler *nextItem;
};
diff --git a/engines/ngi/objects.h b/engines/ngi/objects.h
index b8bea5ffe05..d777a0824d3 100644
--- a/engines/ngi/objects.h
+++ b/engines/ngi/objects.h
@@ -45,10 +45,10 @@ private:
struct PicAniInfo {
uint32 type;
int16 objectId;
- int16 field_6;
+ int16 padding6;
int32 copyId;
int16 sceneId;
- int16 field_E;
+ int16 paddingE;
int32 ox;
int32 oy;
int32 priority;
diff --git a/engines/ngi/stateloader.cpp b/engines/ngi/stateloader.cpp
index 37bc7c81ead..cd0aa12bde6 100644
--- a/engines/ngi/stateloader.cpp
+++ b/engines/ngi/stateloader.cpp
@@ -517,10 +517,10 @@ bool PicAniInfo::load(MfcArchive &file) {
type = file.readUint32LE();
objectId = file.readUint16LE();
- field_6 = file.readUint16LE();
+ padding6 = file.readUint16LE();
copyId = file.readUint32LE();
sceneId = file.readUint16LE();
- field_E = file.readUint16LE();
+ paddingE = file.readUint16LE();
ox = file.readSint32LE();
oy = file.readSint32LE();
priority = file.readUint32LE();
diff --git a/engines/ngi/statesaver.cpp b/engines/ngi/statesaver.cpp
index 3a2afc9777c..b0a981ecbfe 100644
--- a/engines/ngi/statesaver.cpp
+++ b/engines/ngi/statesaver.cpp
@@ -171,10 +171,10 @@ void PicAniInfo::save(MfcArchive &file) {
file.writeUint32LE(type);
file.writeUint16LE(objectId);
- file.writeUint16LE(field_6);
+ file.writeUint16LE(padding6);
file.writeUint32LE(copyId);
file.writeUint16LE(sceneId);
- file.writeUint16LE(field_E);
+ file.writeUint16LE(paddingE);
file.writeSint32LE(ox);
file.writeSint32LE(oy);
file.writeUint32LE(priority);
@@ -187,8 +187,8 @@ void PicAniInfo::save(MfcArchive &file) {
}
void PicAniInfo::print() {
- debug("type: %d objectId: %d field_6: %d copyId: %d", type, objectId, field_6, copyId);
- debug("sceneId: %d field_E: %d ox: %d oy: %d priority: %d", sceneId, field_E, ox, oy, priority);
+ debug("type: %d objectId: %d padding6: %d copyId: %d", type, objectId, padding6, copyId);
+ debug("sceneId: %d paddingE: %d ox: %d oy: %d priority: %d", sceneId, paddingE, ox, oy, priority);
debug("staticsId: %d movementId: %d curFrame: %d flags: %x objectFlags: %d targetFrame: %d",
staticsId, movementId, curFrame, flags, objectFlags, targetFrame);
}
Commit: 99b44a7898b8a7be10d0c17d6d0fda4382ba1165
https://github.com/scummvm/scummvm/commit/99b44a7898b8a7be10d0c17d6d0fda4382ba1165
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:15:08+01:00
Commit Message:
NGI: Rename InteractionController::addInteraction to addInteract
Changed paths:
engines/ngi/interaction.h
engines/ngi/xmlproject.cpp
diff --git a/engines/ngi/interaction.h b/engines/ngi/interaction.h
index 6450174dc6b..7b1a078d95e 100644
--- a/engines/ngi/interaction.h
+++ b/engines/ngi/interaction.h
@@ -78,7 +78,7 @@ public:
bool load(MfcArchive &file) override;
- void addInteraction(Interact *interaction) { _interactions.push_back(interaction); }
+ void addInteract(Interact *interaction) { _interactions.push_back(interaction); }
void enable() { _enabled = true; }
void disable() { _enabled = false; }
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index 4f5c08e14ac..8fcd60aa6ed 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -297,7 +297,7 @@ public:
void registerInteractions() {
for (Interact *action : _actions)
- getGameLoaderInteractionController()->addInteraction(action);
+ getGameLoaderInteractionController()->addInteract(action);
_actions.clear();
}
Commit: 8f9b5c5ce0e6ab5c7ad8d42f5b5319c06736b144
https://github.com/scummvm/scummvm/commit/8f9b5c5ce0e6ab5c7ad8d42f5b5319c06736b144
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:17:34+01:00
Commit Message:
NGI: Silence unused variable warnings in Box2D
Changed paths:
engines/ngi/box2d/Collision/b2TimeOfImpact.cpp
engines/ngi/box2d/Dynamics/Joints/b2GearJoint.cpp
engines/ngi/box2d/Dynamics/Joints/b2PrismaticJoint.cpp
engines/ngi/box2d/Dynamics/Joints/b2RevoluteJoint.cpp
engines/ngi/box2d/Dynamics/Joints/b2WeldJoint.cpp
diff --git a/engines/ngi/box2d/Collision/b2TimeOfImpact.cpp b/engines/ngi/box2d/Collision/b2TimeOfImpact.cpp
index c647e67aea7..bf65be442b2 100644
--- a/engines/ngi/box2d/Collision/b2TimeOfImpact.cpp
+++ b/engines/ngi/box2d/Collision/b2TimeOfImpact.cpp
@@ -200,7 +200,9 @@ struct b2SeparationFunction
case e_points:
{
b2Vec2 axisA = b2MulT(xfA.q, m_axis);
+ (void)axisA;
b2Vec2 axisB = b2MulT(xfB.q, -m_axis);
+ (void)axisB;
b2Vec2 localPointA = m_proxyA->GetVertex(indexA);
b2Vec2 localPointB = m_proxyB->GetVertex(indexB);
@@ -218,6 +220,7 @@ struct b2SeparationFunction
b2Vec2 pointA = b2Mul(xfA, m_localPoint);
b2Vec2 axisB = b2MulT(xfB.q, -normal);
+ (void)axisB;
b2Vec2 localPointB = m_proxyB->GetVertex(indexB);
b2Vec2 pointB = b2Mul(xfB, localPointB);
@@ -232,6 +235,7 @@ struct b2SeparationFunction
b2Vec2 pointB = b2Mul(xfB, m_localPoint);
b2Vec2 axisA = b2MulT(xfA.q, -normal);
+ (void)axisA;
b2Vec2 localPointA = m_proxyA->GetVertex(indexA);
b2Vec2 pointA = b2Mul(xfA, localPointA);
diff --git a/engines/ngi/box2d/Dynamics/Joints/b2GearJoint.cpp b/engines/ngi/box2d/Dynamics/Joints/b2GearJoint.cpp
index 8ad4a80ff75..9a329e39cfa 100644
--- a/engines/ngi/box2d/Dynamics/Joints/b2GearJoint.cpp
+++ b/engines/ngi/box2d/Dynamics/Joints/b2GearJoint.cpp
@@ -150,21 +150,25 @@ void b2GearJoint::InitVelocityConstraints(const b2SolverData& data)
m_iD = m_bodyD->m_invI;
b2Vec2 cA = data.positions[m_indexA].c;
+ (void)cA;
float32 aA = data.positions[m_indexA].a;
b2Vec2 vA = data.velocities[m_indexA].v;
float32 wA = data.velocities[m_indexA].w;
b2Vec2 cB = data.positions[m_indexB].c;
+ (void)cB;
float32 aB = data.positions[m_indexB].a;
b2Vec2 vB = data.velocities[m_indexB].v;
float32 wB = data.velocities[m_indexB].w;
b2Vec2 cC = data.positions[m_indexC].c;
+ (void)cC;
float32 aC = data.positions[m_indexC].a;
b2Vec2 vC = data.velocities[m_indexC].v;
float32 wC = data.velocities[m_indexC].w;
b2Vec2 cD = data.positions[m_indexD].c;
+ (void)cD;
float32 aD = data.positions[m_indexD].a;
b2Vec2 vD = data.velocities[m_indexD].v;
float32 wD = data.velocities[m_indexD].w;
diff --git a/engines/ngi/box2d/Dynamics/Joints/b2PrismaticJoint.cpp b/engines/ngi/box2d/Dynamics/Joints/b2PrismaticJoint.cpp
index 509b89660c8..c3547a9b63c 100644
--- a/engines/ngi/box2d/Dynamics/Joints/b2PrismaticJoint.cpp
+++ b/engines/ngi/box2d/Dynamics/Joints/b2PrismaticJoint.cpp
@@ -353,6 +353,7 @@ void b2PrismaticJoint::SolveVelocityConstraints(const b2SolverData& data)
wB += iB * LB;
b2Vec2 Cdot10 = Cdot1;
+ (void)Cdot10;
Cdot1.x = b2Dot(m_perp, vB - vA) + m_s2 * wB - m_s1 * wA;
Cdot1.y = wB - wA;
@@ -360,6 +361,7 @@ void b2PrismaticJoint::SolveVelocityConstraints(const b2SolverData& data)
if (b2Abs(Cdot1.x) > 0.01f || b2Abs(Cdot1.y) > 0.01f)
{
b2Vec2 test = b2Mul22(m_K, df);
+ (void)test;
Cdot1.x += 0.0f;
}
}
diff --git a/engines/ngi/box2d/Dynamics/Joints/b2RevoluteJoint.cpp b/engines/ngi/box2d/Dynamics/Joints/b2RevoluteJoint.cpp
index d3d9c27ade7..d1277b66408 100644
--- a/engines/ngi/box2d/Dynamics/Joints/b2RevoluteJoint.cpp
+++ b/engines/ngi/box2d/Dynamics/Joints/b2RevoluteJoint.cpp
@@ -75,11 +75,13 @@ void b2RevoluteJoint::InitVelocityConstraints(const b2SolverData& data)
m_invIB = m_bodyB->m_invI;
b2Vec2 cA = data.positions[m_indexA].c;
+ (void)cA;
float32 aA = data.positions[m_indexA].a;
b2Vec2 vA = data.velocities[m_indexA].v;
float32 wA = data.velocities[m_indexA].w;
b2Vec2 cB = data.positions[m_indexB].c;
+ (void)cB;
float32 aB = data.positions[m_indexB].a;
b2Vec2 vB = data.velocities[m_indexB].v;
float32 wB = data.velocities[m_indexB].w;
diff --git a/engines/ngi/box2d/Dynamics/Joints/b2WeldJoint.cpp b/engines/ngi/box2d/Dynamics/Joints/b2WeldJoint.cpp
index b04e2a112cc..75fdaf907b7 100644
--- a/engines/ngi/box2d/Dynamics/Joints/b2WeldJoint.cpp
+++ b/engines/ngi/box2d/Dynamics/Joints/b2WeldJoint.cpp
@@ -69,11 +69,13 @@ void b2WeldJoint::InitVelocityConstraints(const b2SolverData& data)
m_invIB = m_bodyB->m_invI;
b2Vec2 cA = data.positions[m_indexA].c;
+ (void)cA;
float32 aA = data.positions[m_indexA].a;
b2Vec2 vA = data.velocities[m_indexA].v;
float32 wA = data.velocities[m_indexA].w;
b2Vec2 cB = data.positions[m_indexB].c;
+ (void)cB;
float32 aB = data.positions[m_indexB].a;
b2Vec2 vB = data.velocities[m_indexB].v;
float32 wB = data.velocities[m_indexB].w;
Commit: b930cb702c71314de50185329bf610a73923562a
https://github.com/scummvm/scummvm/commit/b930cb702c71314de50185329bf610a73923562a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T17:21:36+01:00
Commit Message:
NGI: Fix the remaining Box2D compiler warnings
Changed paths:
engines/ngi/box2d/Collision/b2CollideCircle.cpp
engines/ngi/box2d/Collision/b2Distance.cpp
engines/ngi/box2d/Common/b2Math.h
engines/ngi/box2d/Dynamics/Joints/b2Joint.cpp
engines/ngi/box2d/Dynamics/Joints/b2WheelJoint.cpp
engines/ngi/box2d/Dynamics/b2ContactManager.cpp
engines/ngi/box2d/Dynamics/b2ContactManager.h
engines/ngi/box2d/Dynamics/b2Island.cpp
engines/ngi/box2d/Dynamics/b2World.h
diff --git a/engines/ngi/box2d/Collision/b2CollideCircle.cpp b/engines/ngi/box2d/Collision/b2CollideCircle.cpp
index 0e38f180992..451145c311e 100644
--- a/engines/ngi/box2d/Collision/b2CollideCircle.cpp
+++ b/engines/ngi/box2d/Collision/b2CollideCircle.cpp
@@ -140,8 +140,8 @@ void b2CollidePolygonAndCircle(
else
{
b2Vec2 faceCenter = 0.5f * (v1 + v2);
- float32 separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]);
- if (separation > radius)
+ float32 faceSeparation = b2Dot(cLocal - faceCenter, normals[vertIndex1]);
+ if (faceSeparation > radius)
{
return;
}
diff --git a/engines/ngi/box2d/Collision/b2Distance.cpp b/engines/ngi/box2d/Collision/b2Distance.cpp
index ffedad5af63..69bc118a6e3 100644
--- a/engines/ngi/box2d/Collision/b2Distance.cpp
+++ b/engines/ngi/box2d/Collision/b2Distance.cpp
@@ -33,7 +33,7 @@ void b2DistanceProxy::Set(const b2Shape* shape, int32 index)
{
case b2Shape::e_circle:
{
- const b2CircleShape* circle = (b2CircleShape*)shape;
+ const b2CircleShape* circle = (const b2CircleShape*)shape;
m_vertices = &circle->m_p;
m_count = 1;
m_radius = circle->m_radius;
@@ -42,7 +42,7 @@ void b2DistanceProxy::Set(const b2Shape* shape, int32 index)
case b2Shape::e_polygon:
{
- const b2PolygonShape* polygon = (b2PolygonShape*)shape;
+ const b2PolygonShape* polygon = (const b2PolygonShape*)shape;
m_vertices = polygon->m_vertices;
m_count = polygon->m_vertexCount;
m_radius = polygon->m_radius;
@@ -51,7 +51,7 @@ void b2DistanceProxy::Set(const b2Shape* shape, int32 index)
case b2Shape::e_chain:
{
- const b2ChainShape* chain = (b2ChainShape*)shape;
+ const b2ChainShape* chain = (const b2ChainShape*)shape;
b2Assert(0 <= index && index < chain->m_count);
m_buffer[0] = chain->m_vertices[index];
@@ -72,7 +72,7 @@ void b2DistanceProxy::Set(const b2Shape* shape, int32 index)
case b2Shape::e_edge:
{
- const b2EdgeShape* edge = (b2EdgeShape*)shape;
+ const b2EdgeShape* edge = (const b2EdgeShape*)shape;
m_vertices = &edge->m_vertex1;
m_count = 2;
m_radius = edge->m_radius;
diff --git a/engines/ngi/box2d/Common/b2Math.h b/engines/ngi/box2d/Common/b2Math.h
index f9b5477bb4f..df42ee7b9c5 100644
--- a/engines/ngi/box2d/Common/b2Math.h
+++ b/engines/ngi/box2d/Common/b2Math.h
@@ -69,7 +69,7 @@ struct b2Vec2
b2Vec2() {}
/// Construct using coordinates.
- b2Vec2(float32 x, float32 y) : x(x), y(y) {}
+ constexpr b2Vec2(float32 x, float32 y) : x(x), y(y) {}
/// Set this vector to all zeros.
void SetZero() { x = 0.0f; y = 0.0f; }
diff --git a/engines/ngi/box2d/Dynamics/Joints/b2Joint.cpp b/engines/ngi/box2d/Dynamics/Joints/b2Joint.cpp
index f82098d4ec9..0a9a4f64850 100644
--- a/engines/ngi/box2d/Dynamics/Joints/b2Joint.cpp
+++ b/engines/ngi/box2d/Dynamics/Joints/b2Joint.cpp
@@ -44,70 +44,70 @@ b2Joint* b2Joint::Create(const b2JointDef* def, b2BlockAllocator* allocator)
case e_distanceJoint:
{
void* mem = allocator->Allocate(sizeof(b2DistanceJoint));
- joint = new (mem) b2DistanceJoint((b2DistanceJointDef*)def);
+ joint = new (mem) b2DistanceJoint((const b2DistanceJointDef*)def);
}
break;
case e_mouseJoint:
{
void* mem = allocator->Allocate(sizeof(b2MouseJoint));
- joint = new (mem) b2MouseJoint((b2MouseJointDef*)def);
+ joint = new (mem) b2MouseJoint((const b2MouseJointDef*)def);
}
break;
case e_prismaticJoint:
{
void* mem = allocator->Allocate(sizeof(b2PrismaticJoint));
- joint = new (mem) b2PrismaticJoint((b2PrismaticJointDef*)def);
+ joint = new (mem) b2PrismaticJoint((const b2PrismaticJointDef*)def);
}
break;
case e_revoluteJoint:
{
void* mem = allocator->Allocate(sizeof(b2RevoluteJoint));
- joint = new (mem) b2RevoluteJoint((b2RevoluteJointDef*)def);
+ joint = new (mem) b2RevoluteJoint((const b2RevoluteJointDef*)def);
}
break;
case e_pulleyJoint:
{
void* mem = allocator->Allocate(sizeof(b2PulleyJoint));
- joint = new (mem) b2PulleyJoint((b2PulleyJointDef*)def);
+ joint = new (mem) b2PulleyJoint((const b2PulleyJointDef*)def);
}
break;
case e_gearJoint:
{
void* mem = allocator->Allocate(sizeof(b2GearJoint));
- joint = new (mem) b2GearJoint((b2GearJointDef*)def);
+ joint = new (mem) b2GearJoint((const b2GearJointDef*)def);
}
break;
case e_wheelJoint:
{
void* mem = allocator->Allocate(sizeof(b2WheelJoint));
- joint = new (mem) b2WheelJoint((b2WheelJointDef*)def);
+ joint = new (mem) b2WheelJoint((const b2WheelJointDef*)def);
}
break;
case e_weldJoint:
{
void* mem = allocator->Allocate(sizeof(b2WeldJoint));
- joint = new (mem) b2WeldJoint((b2WeldJointDef*)def);
+ joint = new (mem) b2WeldJoint((const b2WeldJointDef*)def);
}
break;
case e_frictionJoint:
{
void* mem = allocator->Allocate(sizeof(b2FrictionJoint));
- joint = new (mem) b2FrictionJoint((b2FrictionJointDef*)def);
+ joint = new (mem) b2FrictionJoint((const b2FrictionJointDef*)def);
}
break;
case e_ropeJoint:
{
void* mem = allocator->Allocate(sizeof(b2RopeJoint));
- joint = new (mem) b2RopeJoint((b2RopeJointDef*)def);
+ joint = new (mem) b2RopeJoint((const b2RopeJointDef*)def);
}
break;
diff --git a/engines/ngi/box2d/Dynamics/Joints/b2WheelJoint.cpp b/engines/ngi/box2d/Dynamics/Joints/b2WheelJoint.cpp
index 6c32e928bd5..5199c208fb7 100644
--- a/engines/ngi/box2d/Dynamics/Joints/b2WheelJoint.cpp
+++ b/engines/ngi/box2d/Dynamics/Joints/b2WheelJoint.cpp
@@ -143,14 +143,14 @@ void b2WheelJoint::InitVelocityConstraints(const b2SolverData& data)
float32 omega = 2.0f * b2_pi * m_frequencyHz;
// Damping coefficient
- float32 d = 2.0f * m_springMass * m_dampingRatio * omega;
+ float32 dampingCoeff = 2.0f * m_springMass * m_dampingRatio * omega;
// Spring stiffness
float32 k = m_springMass * omega * omega;
// magic formulas
float32 h = data.step.dt;
- m_gamma = h * (d + h * k);
+ m_gamma = h * (dampingCoeff + h * k);
if (m_gamma > 0.0f)
{
m_gamma = 1.0f / m_gamma;
diff --git a/engines/ngi/box2d/Dynamics/b2ContactManager.cpp b/engines/ngi/box2d/Dynamics/b2ContactManager.cpp
index 6fde5194789..5d00dfd399d 100644
--- a/engines/ngi/box2d/Dynamics/b2ContactManager.cpp
+++ b/engines/ngi/box2d/Dynamics/b2ContactManager.cpp
@@ -24,15 +24,12 @@
namespace NGI {
-b2ContactFilter b2_defaultFilter;
-b2ContactListener b2_defaultListener;
-
b2ContactManager::b2ContactManager()
{
m_contactList = NULL;
m_contactCount = 0;
- m_contactFilter = &b2_defaultFilter;
- m_contactListener = &b2_defaultListener;
+ m_contactFilter = &m_defaultFilter;
+ m_contactListener = &m_defaultListener;
m_allocator = NULL;
}
diff --git a/engines/ngi/box2d/Dynamics/b2ContactManager.h b/engines/ngi/box2d/Dynamics/b2ContactManager.h
index d5a0bb96641..84136972464 100644
--- a/engines/ngi/box2d/Dynamics/b2ContactManager.h
+++ b/engines/ngi/box2d/Dynamics/b2ContactManager.h
@@ -20,12 +20,11 @@
#define B2_CONTACT_MANAGER_H
#include "engines/ngi/box2d/Collision/b2BroadPhase.h"
+#include "engines/ngi/box2d/Dynamics/b2WorldCallbacks.h"
namespace NGI {
class b2Contact;
-class b2ContactFilter;
-class b2ContactListener;
class b2BlockAllocator;
// Delegate of b2World.
@@ -49,6 +48,11 @@ public:
b2ContactFilter* m_contactFilter;
b2ContactListener* m_contactListener;
b2BlockAllocator* m_allocator;
+
+private:
+ // Used until the application registers its own filter and listener.
+ b2ContactFilter m_defaultFilter;
+ b2ContactListener m_defaultListener;
};
} // End of namespace NGI
diff --git a/engines/ngi/box2d/Dynamics/b2Island.cpp b/engines/ngi/box2d/Dynamics/b2Island.cpp
index 4b044170242..e274d0a8786 100644
--- a/engines/ngi/box2d/Dynamics/b2Island.cpp
+++ b/engines/ngi/box2d/Dynamics/b2Island.cpp
@@ -314,9 +314,9 @@ void b2Island::Solve(b2Profile* profile, const b2TimeStep& step, const b2Vec2& g
bool contactsOkay = contactSolver.SolvePositionConstraints();
bool jointsOkay = true;
- for (int32 i = 0; i < m_jointCount; ++i)
+ for (int32 j = 0; j < m_jointCount; ++j)
{
- bool jointOkay = m_joints[i]->SolvePositionConstraints(solverData);
+ bool jointOkay = m_joints[j]->SolvePositionConstraints(solverData);
jointsOkay = jointsOkay && jointOkay;
}
diff --git a/engines/ngi/box2d/Dynamics/b2World.h b/engines/ngi/box2d/Dynamics/b2World.h
index bfb59742bfb..d3aaf33beae 100644
--- a/engines/ngi/box2d/Dynamics/b2World.h
+++ b/engines/ngi/box2d/Dynamics/b2World.h
@@ -55,7 +55,7 @@ public:
void SetDestructionListener(b2DestructionListener* listener);
/// Register a contact filter to provide specific control over collision.
- /// Otherwise the default filter is used (b2_defaultFilter). The listener is
+ /// Otherwise the default filter of the contact manager is used. The listener is
/// owned by you and must remain in scope.
void SetContactFilter(b2ContactFilter* filter);
More information about the Scummvm-git-logs
mailing list