17 #ifndef GZ_SIM_ENTITYCOMPONENTMANAGER_HH_
18 #define GZ_SIM_ENTITYCOMPONENTMANAGER_HH_
20 #include <gz/msgs/serialized.pb.h>
21 #include <gz/msgs/serialized_map.pb.h>
29 #include <type_traits>
30 #include <unordered_set>
31 #include <unordered_map>
35 #include <gz/common/Console.hh>
36 #include <gz/math/graph/Graph.hh>
38 #include "gz/sim/Export.hh"
42 #include "gz/sim/detail/View.hh"
49 inline namespace GZ_SIM_VERSION_NAMESPACE {
52 class EntityComponentManagerDiff;
85 public:
Entity CreateEntity();
124 public:
size_t EntityCount()
const;
137 public:
void RequestRemoveEntity(
const Entity _entity,
138 bool _recursive =
true);
155 public:
void PinEntity(
const Entity _entity,
bool _recursive =
true);
163 public:
void UnpinEntity(
const Entity _entity,
bool _recursive =
true);
167 public:
void UnpinAllEntities();
172 public:
void RequestRemoveEntities();
177 public:
bool HasEntity(
const Entity _entity)
const;
197 public:
bool SetParentEntity(
const Entity _child,
const Entity _parent);
209 public:
bool EntityHasComponentType(
const Entity _entity,
216 public:
bool EntityMatches(
Entity _entity,
224 public:
bool RemoveComponent(
232 public:
template<
typename ComponentTypeT>
233 bool RemoveComponent(
Entity _entity);
237 public:
void RebuildViews();
247 public:
template<
typename ComponentTypeT>
248 ComponentTypeT *CreateComponent(
250 const ComponentTypeT &_data);
257 public:
template<
typename ComponentTypeT>
258 const ComponentTypeT *Component(
const Entity _entity)
const;
265 public:
template<
typename ComponentTypeT>
266 ComponentTypeT *Component(
const Entity _entity);
276 public:
template<
typename ComponentTypeT>
277 ComponentTypeT *ComponentDefault(
Entity _entity,
278 const typename ComponentTypeT::Type &_default =
279 typename ComponentTypeT::Type());
289 public:
template<
typename ComponentTypeT>
290 std::optional<typename ComponentTypeT::Type> ComponentData(
291 const Entity _entity)
const;
303 public:
template<
typename ComponentTypeT>
304 bool SetComponentData(
const Entity _entity,
305 const typename ComponentTypeT::Type &_data);
324 public:
template<
typename ...ComponentTypeTs>
325 Entity EntityByComponents(
326 const ComponentTypeTs &..._desiredComponents)
const;
340 public:
template<
typename ...ComponentTypeTs>
342 const ComponentTypeTs &..._desiredComponents)
const;
359 public:
template<
typename ...ComponentTypeTs>
361 const ComponentTypeTs &..._desiredComponents)
const;
364 private:
template <
typename T>
394 public:
template<
typename ...ComponentTypeTs>
396 bool(
const Entity &_entity,
397 const ComponentTypeTs *...)>>::type _f)
const;
411 public:
template<
typename ...ComponentTypeTs>
413 bool(
const Entity &_entity,
414 ComponentTypeTs *...)>>::type _f);
428 public:
template<
typename ...ComponentTypeTs>
430 bool(
const Entity &_entity,
431 const ComponentTypeTs *...)>>::type _f)
const;
445 public:
template<
typename ...ComponentTypeTs>
447 bool(
const Entity &_entity,
448 ComponentTypeTs *...)>>::type _f);
454 public:
template <
class Function,
class... ComponentTypeTs>
455 static void ForEach(Function _f,
const ComponentTypeTs &... _components);
471 public:
template <
typename... ComponentTypeTs>
473 bool(
const Entity &_entity,
474 ComponentTypeTs *...)>>::type _f);
488 public:
template <
typename... ComponentTypeTs>
490 bool(
const Entity &_entity,
491 const ComponentTypeTs *...)>>::type _f)
const;
503 public:
template<
typename ...ComponentTypeTs>
505 bool(
const Entity &_entity,
506 const ComponentTypeTs *...)>>::type _f)
const;
548 public:
bool HasNewEntities()
const;
552 public:
bool HasEntitiesMarkedForRemoval()
const;
557 public:
bool HasOneTimeComponentChanges()
const;
562 public:
bool HasPeriodicComponentChanges()
const;
568 ComponentTypesWithPeriodicChanges()
const;
606 bool _full =
false)
const;
616 public:
void PeriodicStateFromCache(
650 public:
void SetChanged(
665 public:
void SetEntityCreateOffset(uint64_t _offset);
676 public:
bool HasRemovedComponents()
const;
683 public: std::optional<Entity> EntityByName(
689 protected:
void ClearNewlyCreatedEntities();
693 protected:
void ClearRemovedComponents();
698 protected:
void ProcessRemoveEntityRequests();
701 protected:
void SetAllComponentsUnchanged();
711 protected: EntityComponentManagerDiff ComputeEntityDiff(
720 const EntityComponentManagerDiff &_diff);
728 private:
bool IsNewEntity(
const Entity _entity)
const;
733 private:
bool IsMarkedForRemoval(
const Entity _entity)
const;
742 private:
bool CreateComponentImplementation(
769 private:
template<
typename ...ComponentTypeTs>
770 detail::View *FindView()
const;
787 private: detail::BaseView *AddView(
788 const detail::ComponentTypeKey &_types,
815 bool _full =
false)
const;
825 private:
void LockAddingEntitiesToViews(
bool _lock);
831 private:
bool LockAddingEntitiesToViews()
const;
836 friend class GuiRunner;
837 friend class SimulationRunner;
841 friend class NetworkManagerPrimary;
842 friend class NetworkManagerSecondary;
848 #include "gz/sim/detail/EntityComponentManager.hh"