22 #ifndef PLAYRHO_DYNAMICS_WORLD_HPP
23 #define PLAYRHO_DYNAMICS_WORLD_HPP
45 #include <unordered_set>
381 void RegisterForProxies(
Fixture& fixture);
385 void UnregisterForProxies(const
Fixture& fixture);
389 void RegisterForProxies(
Body& body);
393 void UnregisterForProxies(const
Body& body);
404 bool resetMassData = true);
423 void TouchProxies(
Fixture& fixture) noexcept;
426 void SetNewFixtures() noexcept;
429 using FlagsType = std::uint32_t;
435 using ContactKeyQueue = std::vector<
ContactKey>;
438 using ProxyQueue = std::vector<ProxyId>;
444 e_newFixture = 0x0001,
450 e_substepping = 0x0020,
453 e_stepComplete = 0x0040,
457 void CopyBodies(std::map<const Body*, Body*>& bodyMap,
458 std::map<const Fixture*, Fixture*>& fixtureMap,
462 void CopyJoints(
const std::map<const Body*, Body*>& bodyMap,
466 void CopyContacts(
const std::map<const Body*, Body*>& bodyMap,
467 const std::map<const Fixture*, Fixture*>& fixtureMap,
471 void InternalClear() noexcept;
475 void InternalDestroy(
Joint& joint) noexcept;
510 Bodies::size_type& remNumBodies,
511 Contacts::size_type& remNumContacts,
512 Joints::size_type& remNumJoints);
517 using BodyStack = std::vector<
Body*>;
520 void AddToIsland(
Island& island, BodyStack& stack,
521 Bodies::size_type& remNumBodies,
522 Contacts::size_type& remNumContacts,
523 Joints::size_type& remNumJoints);
526 void AddContactsToIsland(
Island& island, BodyStack& stack, const
Body* b);
529 void AddJointsToIsland(
Island& island, BodyStack& stack, const
Body* b);
532 Bodies::size_type RemoveUnspeedablesFromIslanded(const std::vector<
Body*>& bodies);
583 void ResetBodiesForSolveTOI() noexcept;
586 void ResetContactsForSolveTOI() noexcept;
589 void ResetContactsForSolveTOI(
Body& body) noexcept;
592 struct ProcessContactsOutput
612 ProcessContactsOutput ProcessContactsForTOI(Island& island, Body& body,
Real toi,
620 void Remove(
const Body& b) noexcept;
623 void Remove(
const Joint& j) noexcept;
626 void SetStepComplete(
bool value) noexcept;
629 void SetAllowSleeping() noexcept;
632 void UnsetAllowSleeping() noexcept;
635 struct UpdateContactsStats
648 struct DestroyContactsStats
655 struct ContactToiData
657 Contact* contact =
nullptr;
658 Real toi = std::numeric_limits<Real>::infinity();
663 struct UpdateContactsData
678 dist_iter_type maxDistIters = 0;
679 toi_iter_type maxToiIters = 0;
680 root_iter_type maxRootIters = 0;
684 UpdateContactsData UpdateContactTOIs(
const StepConf& conf);
690 ContactToiData GetSoonestContact() const noexcept;
693 bool HasNewFixtures() const noexcept;
696 void UnsetNewFixtures() noexcept;
710 DestroyContactsStats DestroyContacts(
Contacts& contacts);
713 UpdateContactsStats UpdateContacts(
Contacts& contacts, const StepConf& conf);
720 void Destroy(Contact* contact, Body* from);
736 bool Add(ContactKey key);
739 void RegisterForProcessing(ProxyId pid) noexcept;
742 void UnregisterForProcessing(ProxyId pid) noexcept;
745 void InternalDestroy(Contact* contact, Body* from =
nullptr);
749 void CreateProxies(Fixture& fixture,
Length aabbExtension);
753 void DestroyProxies(Fixture& fixture) noexcept;
757 void InternalTouchProxies(Fixture& fixture) noexcept;
763 Transformation xfm1, Transformation xfm2,
770 Transformation xfm1, Transformation xfm2,
774 void CreateAndDestroyProxies(const StepConf& conf);
777 void CreateAndDestroyProxies(Fixture& fixture, const StepConf& conf);
780 PreStepStats::counter_type SynchronizeProxies(const StepConf& conf);
783 bool IsIslanded(const Body* body) const noexcept;
786 bool IsIslanded(const Contact* contact) const noexcept;
789 bool IsIslanded(const Joint* joint) const noexcept;
792 void SetIslanded(Body* body) noexcept;
795 void SetIslanded(Contact* contact) noexcept;
798 void SetIslanded(Joint* joint) noexcept;
801 void UnsetIslanded(Body* body) noexcept;
804 void UnsetIslanded(Contact* contact) noexcept;
807 void UnsetIslanded(Joint* joint) noexcept;
813 ContactKeyQueue m_proxyKeys;
814 ProxyQueue m_proxies;
816 Bodies m_bodiesForProxies;
827 DestructionListener* m_destructionListener =
nullptr;
829 ContactListener* m_contactListener =
nullptr;
831 FlagsType m_flags = e_stepComplete;
863 return {begin(m_bodies), end(m_bodies),
size(m_bodies)};
868 return {begin(m_bodies), end(m_bodies),
size(m_bodies)};
873 return {cbegin(m_bodiesForProxies), cend(m_bodiesForProxies),
size(m_bodiesForProxies)};
878 return {cbegin(m_fixturesForProxies), cend(m_fixturesForProxies),
size(m_fixturesForProxies)};
883 return {begin(m_joints), end(m_joints),
size(m_joints)};
888 return {begin(m_joints), end(m_joints),
size(m_joints)};
893 return {begin(m_contacts), end(m_contacts),
size(m_contacts)};
898 return (m_flags & e_locked) == e_locked;
903 return (m_flags & e_stepComplete) != 0u;
906 inline void World::SetStepComplete(
bool value) noexcept
910 m_flags |= e_stepComplete;
914 m_flags &= ~e_stepComplete;
920 return (m_flags & e_substepping) != 0u;
927 m_flags |= e_substepping;
931 m_flags &= ~e_substepping;
935 inline bool World::HasNewFixtures() const noexcept
937 return (m_flags & e_newFixture) != 0u;
940 inline void World::SetNewFixtures() noexcept
942 m_flags |= e_newFixture;
945 inline void World::UnsetNewFixtures() noexcept
947 m_flags &= ~e_newFixture;
952 return m_minVertexRadius;
957 return m_maxVertexRadius;
972 m_destructionListener = listener;
977 m_contactListener = listener;
980 inline bool World::IsIslanded(
const Body* body)
const noexcept
982 return BodyAtty::IsIslanded(*body);
985 inline bool World::IsIslanded(
const Contact* contact)
const noexcept
987 return ContactAtty::IsIslanded(*contact);
990 inline bool World::IsIslanded(
const Joint* joint)
const noexcept
992 return JointAtty::IsIslanded(*joint);
995 inline void World::SetIslanded(Body* body) noexcept
997 BodyAtty::SetIslanded(*body);
1000 inline void World::SetIslanded(Contact* contact) noexcept
1002 ContactAtty::SetIslanded(*contact);
1005 inline void World::SetIslanded(Joint* joint) noexcept
1007 JointAtty::SetIslanded(*joint);
1010 inline void World::UnsetIslanded(Body* body) noexcept
1012 BodyAtty::UnsetIslanded(*body);
1015 inline void World::UnsetIslanded(Contact* contact) noexcept
1017 ContactAtty::UnsetIslanded(*contact);
1020 inline void World::UnsetIslanded(Joint* joint) noexcept
1022 JointAtty::UnsetIslanded(*joint);
1025 inline void World::RegisterForProcessing(ProxyId pid) noexcept
1028 m_proxies.push_back(pid);
1125 const auto bodies = world.GetBodies();
1126 std::for_each(begin(bodies), end(bodies), [&](World::Bodies::value_type &b) {
1157 RegStepStats&
Update(RegStepStats& lhs,
const IslandStats& rhs) noexcept;
1161 #endif // PLAYRHO_DYNAMICS_WORLD_HPP