Skip to content

Commit

Permalink
fix unordered components
Browse files Browse the repository at this point in the history
  • Loading branch information
fbxiang committed Nov 15, 2023
1 parent ba296c4 commit f4ea2ae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
14 changes: 14 additions & 0 deletions include/sapien/component/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Component : public std::enable_shared_from_this<Component> {
// internal only, set parent entity
void internalSetEntity(std::shared_ptr<Entity> const &entity) { mEntity = entity; }

uint64_t getId() const { return mId; }

virtual ~Component() = default;

virtual std::vector<uint64_t> getSerializationDependencies() const { return {}; }
Expand All @@ -59,6 +61,18 @@ class Component : public std::enable_shared_from_this<Component> {
uint64_t mId{};
};

struct comp_cmp {
bool operator()(std::shared_ptr<Component> const &a, std::shared_ptr<Component> const &b) const {
if (!a) {
return true;
}
if (!b) {
return true;
}
return a->getId() < b->getId();
}
};

} // namespace component
} // namespace sapien

Expand Down
2 changes: 0 additions & 2 deletions include/sapien/component/physx/articulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <Eigen/Eigen>
#include <PxPhysicsAPI.h>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cereal/cereal.hpp>
Expand Down
13 changes: 9 additions & 4 deletions include/sapien/component/physx/physx_system.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#pragma once
#include "../component.h"
#include "../system.h"
#include "mesh_manager.h"
#include "sapien/scene.h"
#include "scene_query.h"
#include "simulation_callback.hpp"
#include <PxPhysicsAPI.h>
#include <memory>
#include <unordered_set>
#include <set>

namespace sapien {
namespace component {
class PhysxArticulation;
class PhysxMaterial;
class PhysxRigidDynamicComponent;
class PhysxRigidStaticComponent;
class PhysxArticulationLinkComponent;

struct PhysxSceneConfig {
Vec3 gravity = {0, 0, -9.81}; // default gravity
Expand Down Expand Up @@ -100,10 +104,11 @@ class PhysxSystem : public System {
physx::PxScene *mPxScene;
float mTimestep{0.01f};

std::unordered_set<std::shared_ptr<component::PhysxRigidDynamicComponent>>
std::set<std::shared_ptr<component::PhysxRigidDynamicComponent>,comp_cmp>
mRigidDynamicComponents;
std::unordered_set<std::shared_ptr<component::PhysxRigidStaticComponent>> mRigidStaticComponents;
std::unordered_set<std::shared_ptr<component::PhysxArticulationLinkComponent>>
std::set<std::shared_ptr<component::PhysxRigidStaticComponent>, comp_cmp>
mRigidStaticComponents;
std::set<std::shared_ptr<component::PhysxArticulationLinkComponent>, comp_cmp>
mArticulationLinkComponents;

DefaultEventCallback mSimulationCallback;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <set>
#include <svulkan2/core/context.h>
#include <svulkan2/scene/scene.h>
#include <unordered_set>

namespace sapien {
namespace component {
Expand Down Expand Up @@ -103,11 +104,11 @@ class SapienRendererSystem : public System {
std::shared_ptr<SapienRenderEngine> mEngine;
std::shared_ptr<svulkan2::scene::Scene> mScene;

std::unordered_set<std::shared_ptr<SapienRenderBodyComponent>> mRenderBodyComponents;
std::unordered_set<std::shared_ptr<SapienRenderCameraComponent>> mRenderCameraComponents;
std::unordered_set<std::shared_ptr<SapienRenderLightComponent>> mRenderLightComponents;
std::unordered_set<std::shared_ptr<PointCloudComponent>> mPointCloudComponents;
std::unordered_set<std::shared_ptr<CudaDeformableMeshComponent>> mCudaDeformableMeshComponents;
std::set<std::shared_ptr<SapienRenderBodyComponent>, comp_cmp> mRenderBodyComponents;
std::set<std::shared_ptr<SapienRenderCameraComponent>, comp_cmp> mRenderCameraComponents;
std::set<std::shared_ptr<SapienRenderLightComponent>, comp_cmp> mRenderLightComponents;
std::set<std::shared_ptr<PointCloudComponent>, comp_cmp> mPointCloudComponents;
std::set<std::shared_ptr<CudaDeformableMeshComponent>, comp_cmp> mCudaDeformableMeshComponents;

std::shared_ptr<SapienRenderCubemap> mCubemap;
};
Expand Down
3 changes: 0 additions & 3 deletions include/sapien/component/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit f4ea2ae

Please sign in to comment.