Skip to content

Commit

Permalink
Adds copy construction and copy assignment for World instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-langholtz committed Jun 14, 2017
1 parent a8aef25 commit 1988b9e
Show file tree
Hide file tree
Showing 24 changed files with 687 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Box2D/Dynamics/Body.cpp
Expand Up @@ -208,9 +208,9 @@ void Body::SetMassData(const MassData& massData)
Position{Transform(massData.center, GetTransformation()), GetAngle()},
massData.center
};
const auto newCenter = GetWorldCenter();

// Update center of mass velocity.
const auto newCenter = GetWorldCenter();
const auto deltaCenter = newCenter - oldCenter;
m_velocity.linear += GetRevPerpendicular(deltaCenter) * m_velocity.angular / Radian;

Expand Down
11 changes: 10 additions & 1 deletion Box2D/Dynamics/BodyAtty.hpp
Expand Up @@ -114,7 +114,16 @@ namespace box2d
{
return b.Insert(value);
}


static bool Insert(Body* b, Joint* value)
{
if (b)
{
return Insert(*b, value);
}
return false;
}

static bool Insert(Body& b, Contact* value)
{
return b.Insert(value);
Expand Down
48 changes: 48 additions & 0 deletions Box2D/Dynamics/BodyDef.cpp
@@ -0,0 +1,48 @@
/*
* Original work Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
* Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/Box2D
*
* 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 <Box2D/Dynamics/BodyDef.hpp>
#include <Box2D/Dynamics/Body.hpp>

namespace box2d
{
BodyDef GetBodyDef(const Body& body) noexcept
{
auto def = BodyDef{};
def.type = body.GetType();
def.position = body.GetLocation();
def.angle = body.GetAngle();
def.linearVelocity = GetLinearVelocity(body);
def.angularVelocity = GetAngularVelocity(body);
def.linearAcceleration = body.GetLinearAcceleration();
def.angularAcceleration = body.GetAngularAcceleration();
def.linearDamping = body.GetLinearDamping();
def.angularDamping = body.GetAngularDamping();
def.underActiveTime = body.GetUnderActiveTime();
def.allowSleep = body.IsSleepingAllowed();
def.awake = body.IsAwake();
def.fixedRotation = body.IsFixedRotation();
def.bullet = body.IsAccelerable() && body.IsImpenetrable();
def.enabled = body.IsEnabled();
def.userData = body.GetUserData();
return def;
}
}
14 changes: 9 additions & 5 deletions Box2D/Dynamics/BodyDef.hpp
Expand Up @@ -3,17 +3,19 @@
* Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/Box2D
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* 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.
* 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.
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

Expand Down Expand Up @@ -225,6 +227,8 @@ namespace box2d
return BodyDef{};
}

BodyDef GetBodyDef(const Body& body) noexcept;

} // namespace box2d

#endif /* BodyDef_hpp */
12 changes: 11 additions & 1 deletion Box2D/Dynamics/ContactAtty.hpp
Expand Up @@ -45,6 +45,11 @@ namespace box2d
return c.GetMutableManifold();
}

static void CopyFlags(Contact& to, const Contact& from) noexcept
{
to.m_flags = from.m_flags;
}

static void SetToi(Contact& c, RealNum value) noexcept
{
c.SetToi(value);
Expand All @@ -60,9 +65,14 @@ namespace box2d
++c.m_toiCount;
}

static void SetToiCount(Contact& c, Contact::substep_type value) noexcept
{
c.SetToiCount(value);
}

static void ResetToiCount(Contact& c) noexcept
{
c.ResetToiCount();
c.SetToiCount(0);
}

static void UnflagForFiltering(Contact& c) noexcept
Expand Down
6 changes: 3 additions & 3 deletions Box2D/Dynamics/Contacts/Contact.hpp
Expand Up @@ -237,7 +237,7 @@ class Contact

void UnsetToi() noexcept;

void ResetToiCount() noexcept;
void SetToiCount(substep_type value) noexcept;

/// Sets the touching flag state.
/// @note This should only be called if either:
Expand Down Expand Up @@ -445,9 +445,9 @@ inline void Contact::UnsetToi() noexcept
m_flags &= ~Contact::e_toiFlag;
}

inline void Contact::ResetToiCount() noexcept
inline void Contact::SetToiCount(substep_type value) noexcept
{
m_toiCount = 0;
m_toiCount = value;
}

inline Contact::substep_type Contact::GetToiCount() const noexcept
Expand Down
6 changes: 3 additions & 3 deletions Box2D/Dynamics/Fixture.hpp
Expand Up @@ -104,7 +104,7 @@ class Fixture

/// Gets the child shape.
/// @details The shape is not modifiable. Use a new fixture instead.
const Shape* GetShape() const noexcept;
std::shared_ptr<const Shape> GetShape() const noexcept;

/// Set if this fixture is a sensor.
void SetSensor(bool sensor) noexcept;
Expand Down Expand Up @@ -185,9 +185,9 @@ class Fixture
bool m_isSensor = false; ///< Is/is-not sensor. 1-bytes.
};

inline const Shape* Fixture::GetShape() const noexcept
inline std::shared_ptr<const Shape> Fixture::GetShape() const noexcept
{
return m_shape.get();
return m_shape;
}

inline bool Fixture::IsSensor() const noexcept
Expand Down
30 changes: 30 additions & 0 deletions Box2D/Dynamics/FixtureDef.cpp
@@ -0,0 +1,30 @@
/*
* Original work Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
* Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/Box2D
*
* 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 <Box2D/Dynamics/FixtureDef.hpp>
#include <Box2D/Dynamics/Fixture.hpp>

using namespace box2d;

FixtureDef box2d::GetFixtureDef(const Fixture& fixture) noexcept
{
return FixtureDef{fixture.GetUserData(), fixture.IsSensor(), fixture.GetFilterData()};
}
16 changes: 11 additions & 5 deletions Box2D/Dynamics/FixtureDef.hpp
Expand Up @@ -3,17 +3,19 @@
* Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/Box2D
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* 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.
* 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.
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

Expand All @@ -27,6 +29,8 @@

namespace box2d {

class Fixture;

/// @brief Fixture definition.
///
/// @details A fixture definition is used to create a fixture.
Expand Down Expand Up @@ -72,6 +76,8 @@ namespace box2d {
return FixtureDef{};
}

FixtureDef GetFixtureDef(const Fixture& fixture) noexcept;

} // namespace box2d

#endif /* FixtureDef_hpp */

0 comments on commit 1988b9e

Please sign in to comment.