From 1ec2665c33a632b26d1c8f84832efbd3c40422e0 Mon Sep 17 00:00:00 2001 From: Diego Ferigo Date: Thu, 1 Apr 2021 11:59:40 +0200 Subject: [PATCH 1/6] Vendor Physics system https://github.com/ignitionrobotics/ign-gazebo/commit/1924de9b2286a83424e96ca0d9f99903b4864070 --- cpp/scenario/plugins/Physics/CMakeLists.txt | 4 +- .../plugins/Physics/EntityFeatureMap.hh | 313 ++ cpp/scenario/plugins/Physics/Physics.cc | 2376 +++++++++++++++ cpp/scenario/plugins/Physics/Physics.cpp | 2556 ----------------- cpp/scenario/plugins/Physics/Physics.h | 143 - cpp/scenario/plugins/Physics/Physics.hh | 94 + 6 files changed, 2785 insertions(+), 2701 deletions(-) create mode 100644 cpp/scenario/plugins/Physics/EntityFeatureMap.hh create mode 100644 cpp/scenario/plugins/Physics/Physics.cc delete mode 100644 cpp/scenario/plugins/Physics/Physics.cpp delete mode 100644 cpp/scenario/plugins/Physics/Physics.h create mode 100644 cpp/scenario/plugins/Physics/Physics.hh diff --git a/cpp/scenario/plugins/Physics/CMakeLists.txt b/cpp/scenario/plugins/Physics/CMakeLists.txt index 80fca4065..ce817beb3 100644 --- a/cpp/scenario/plugins/Physics/CMakeLists.txt +++ b/cpp/scenario/plugins/Physics/CMakeLists.txt @@ -27,8 +27,8 @@ # ============= add_library(PhysicsSystem SHARED - Physics.h - Physics.cpp) + Physics.hh + Physics.cc) target_link_libraries(PhysicsSystem PUBLIC diff --git a/cpp/scenario/plugins/Physics/EntityFeatureMap.hh b/cpp/scenario/plugins/Physics/EntityFeatureMap.hh new file mode 100644 index 000000000..8008f478d --- /dev/null +++ b/cpp/scenario/plugins/Physics/EntityFeatureMap.hh @@ -0,0 +1,313 @@ +/* + * Copyright (C) 2021 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef IGNITION_GAZEBO_SYSTEMS_PHYSICS_ENTITY_FEATURE_MAP_HH_ +#define IGNITION_GAZEBO_SYSTEMS_PHYSICS_ENTITY_FEATURE_MAP_HH_ + +#include +#include +#include + +#include +#include +#include +#include + +#include "ignition/gazebo/Entity.hh" + +namespace ignition::gazebo +{ +inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { +namespace systems::physics_system +{ + // \brief Helper class that associates Gazebo entities with Physics entities + // with required and optional features. It can be used to cast a physics + // entity with the required features to another physics entity with one of + // the optional features. This class was created to keep all physics entities + // in one place so that when a gazebo entity is removed, all the mapped + // physics entitities can be removed at the same time. This ensures that + // reference counts are properly zeroed out in the underlying physics engines + // and the memory associated with the physics entities can be freed. + // + // DEV WARNING: There is an implicit conversion between physics EntityPtr and + // std::size_t in ign-physics. This seems also implicitly convert between + // EntityPtr and gazebo Entity. Therefore, any member function that takes a + // gazebo Entity can accidentally take an EntityPtr. To prevent this, for + // every function that takes a gazebo Entity, we should always have an + // overload that also takes an EntityPtr with required features. We can do + // this because there's a 1:1 mapping between the two in maps contained in + // this class. + // + // \tparam PhysicsEntityT Type of entity, such as World, Model, or Link + // \tparam PolicyT Policy of the physics engine (2D, 3D) + // \tparam RequiredFeatureList Required features of the physics entity + // \tparam OptionalFeatureLists One or more optional feature lists of the + // physics entity. + template