diff --git a/include/sapien/component/component.h b/include/sapien/component/component.h index b05a3046..60db5c4a 100644 --- a/include/sapien/component/component.h +++ b/include/sapien/component/component.h @@ -45,6 +45,8 @@ class Component : public std::enable_shared_from_this { // internal only, set parent entity void internalSetEntity(std::shared_ptr const &entity) { mEntity = entity; } + uint64_t getId() const { return mId; } + virtual ~Component() = default; virtual std::vector getSerializationDependencies() const { return {}; } @@ -59,6 +61,18 @@ class Component : public std::enable_shared_from_this { uint64_t mId{}; }; +struct comp_cmp { + bool operator()(std::shared_ptr const &a, std::shared_ptr const &b) const { + if (!a) { + return true; + } + if (!b) { + return true; + } + return a->getId() < b->getId(); + } +}; + } // namespace component } // namespace sapien diff --git a/include/sapien/component/physx/articulation.h b/include/sapien/component/physx/articulation.h index 91b34766..c06136be 100644 --- a/include/sapien/component/physx/articulation.h +++ b/include/sapien/component/physx/articulation.h @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include #include diff --git a/include/sapien/component/physx/physx_system.h b/include/sapien/component/physx/physx_system.h index eb9e601d..a9283fa6 100644 --- a/include/sapien/component/physx/physx_system.h +++ b/include/sapien/component/physx/physx_system.h @@ -1,4 +1,5 @@ #pragma once +#include "../component.h" #include "../system.h" #include "mesh_manager.h" #include "sapien/scene.h" @@ -6,12 +7,15 @@ #include "simulation_callback.hpp" #include #include -#include +#include namespace sapien { namespace component { class PhysxArticulation; class PhysxMaterial; +class PhysxRigidDynamicComponent; +class PhysxRigidStaticComponent; +class PhysxArticulationLinkComponent; struct PhysxSceneConfig { Vec3 gravity = {0, 0, -9.81}; // default gravity @@ -100,10 +104,11 @@ class PhysxSystem : public System { physx::PxScene *mPxScene; float mTimestep{0.01f}; - std::unordered_set> + std::set,comp_cmp> mRigidDynamicComponents; - std::unordered_set> mRigidStaticComponents; - std::unordered_set> + std::set, comp_cmp> + mRigidStaticComponents; + std::set, comp_cmp> mArticulationLinkComponents; DefaultEventCallback mSimulationCallback; diff --git a/include/sapien/component/sapien_renderer/sapien_renderer_system.h b/include/sapien/component/sapien_renderer/sapien_renderer_system.h index 31d4f331..57c08d85 100644 --- a/include/sapien/component/sapien_renderer/sapien_renderer_system.h +++ b/include/sapien/component/sapien_renderer/sapien_renderer_system.h @@ -1,12 +1,13 @@ #pragma once +#include "../component.h" #include "../system.h" #include "cubemap.h" #include "sapien/math/vec3.h" #include "sapien/serialize.h" +#include #include #include -#include namespace sapien { namespace component { @@ -103,11 +104,11 @@ class SapienRendererSystem : public System { std::shared_ptr mEngine; std::shared_ptr mScene; - std::unordered_set> mRenderBodyComponents; - std::unordered_set> mRenderCameraComponents; - std::unordered_set> mRenderLightComponents; - std::unordered_set> mPointCloudComponents; - std::unordered_set> mCudaDeformableMeshComponents; + std::set, comp_cmp> mRenderBodyComponents; + std::set, comp_cmp> mRenderCameraComponents; + std::set, comp_cmp> mRenderLightComponents; + std::set, comp_cmp> mPointCloudComponents; + std::set, comp_cmp> mCudaDeformableMeshComponents; std::shared_ptr mCubemap; }; diff --git a/include/sapien/component/system.h b/include/sapien/component/system.h index 0936f599..b47e319f 100644 --- a/include/sapien/component/system.h +++ b/include/sapien/component/system.h @@ -6,9 +6,6 @@ namespace sapien { namespace component { -class PhysxRigidDynamicComponent; -class PhysxRigidStaticComponent; -class PhysxArticulationLinkComponent; /** System controls entity components in a scene. * Components should register themselves to a system to enable lifecycle methods */