22 #include <argos3/core/utility/datatypes/any.h>
23 #include <argos3/core/simulator/medium/medium.h>
24 #include <argos3/core/simulator/entity/embodied_entity.h>
25 #include <argos3/core/simulator/entity/controllable_entity.h>
56 typedef std::map <std::string, CAny, std::less <std::string> >
TMapPerType;
79 typedef std::map <std::string, TMapPerType, std::less <std::string> >
TMapPerTypePerId;
116 virtual void Reset();
163 return *(it->second);
166 "\" when requesting entity from space.");
178 const std::string& str_pattern);
227 return GetEntitiesByTypeImpl(str_type);
231 return GetEntitiesByTypeImpl(str_type);
273 template <
typename ENTITY>
275 std::string strEntityQualifiedName = c_entity.GetContext() + c_entity.GetId();
279 c_entity.GetTypeDescription() <<
280 " entity with id \"" <<
281 strEntityQualifiedName <<
282 "\". An entity with that id already exists.");
285 if(!c_entity.HasParent()) {
296 c_entity.SetIndex(unIdx);
306 template <
typename ENTITY>
308 std::string strEntityQualifiedName = c_entity.GetContext() + c_entity.GetId();
313 TMapPerType::iterator itMapPerTypePerId = itMapPerType->second.find(strEntityQualifiedName);
314 if(itMapPerTypePerId != itMapPerType->second.end()) {
316 CEntity::TVector::iterator itVec = find(
m_vecEntities.begin(),
321 itMapPerType->second.erase(itMapPerTypePerId);
323 if(!c_entity.HasParent()) {
336 strEntityQualifiedName <<
337 "\" has not been found in the indexes.");
506 TMapPerType& GetEntitiesByTypeImpl(
const std::string& str_type)
const;
513 template <
typename ACTION>
533 #define SPACE_OPERATION_ADD_ENTITY(ENTITY) \
534 class CSpaceOperationAdd ## ENTITY : public CSpaceOperationAddEntity { \
536 void ApplyTo(CSpace& c_space, ENTITY& c_entity) { \
537 c_space.AddEntity(c_entity); \
541 #define SPACE_OPERATION_REMOVE_ENTITY(ENTITY) \
542 class CSpaceOperationRemove ## ENTITY : public CSpaceOperationRemoveEntity { \
544 void ApplyTo(CSpace& c_space, ENTITY& c_entity) { \
545 c_space.RemoveEntity(c_entity); \
549 #define REGISTER_SPACE_OPERATION(ACTION, OPERATION, ENTITY) \
550 REGISTER_ENTITY_OPERATION(ACTION, CSpace, OPERATION, void, ENTITY);
552 #define REGISTER_STANDARD_SPACE_OPERATION_ADD_ENTITY(ENTITY) \
553 SPACE_OPERATION_ADD_ENTITY(ENTITY) \
554 REGISTER_SPACE_OPERATION(CSpaceOperationAddEntity, \
555 CSpaceOperationAdd ## ENTITY, \
558 #define REGISTER_STANDARD_SPACE_OPERATION_REMOVE_ENTITY(ENTITY) \
559 SPACE_OPERATION_REMOVE_ENTITY(ENTITY) \
560 REGISTER_SPACE_OPERATION(CSpaceOperationRemoveEntity, \
561 CSpaceOperationRemove ## ENTITY, \
564 #define REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(ENTITY) \
565 REGISTER_STANDARD_SPACE_OPERATION_ADD_ENTITY(ENTITY) \
566 REGISTER_STANDARD_SPACE_OPERATION_REMOVE_ENTITY(ENTITY)
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
unsigned int UInt32
32-bit unsigned integer.
The namespace containing all the ARGoS related code.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
An entity that contains a pointer to the user-defined controller.
std::vector< CControllableEntity * > TVector
A vector of controllable entities.
This entity is a link to a body in the physics engine.
std::vector< CEntity * > TVector
A vector of entities.
unordered_map< std::string, CEntity * > TMap
A map of entities.
The basic operation to be stored in the vtable.
std::vector< CMedium * > TVector
std::vector< CPhysicsEngine * > TVector
void Distribute(TConfigurationNode &t_tree)
CControllableEntity::TVector m_vecControllableEntities
A vector of controllable entities.
virtual void Init(TConfigurationNode &t_tree)
Initializes the space using the <arena> section of the XML configuration file.
virtual void Destroy()
Destroys the space and all its entities.
virtual void Reset()
Reset the space and all its entities.
void AddBoxStrip(TConfigurationNode &t_tree)
bool ControllableEntityIterationEnabled() const
CRange< CVector3 > m_cArenaLimits
Arena limits.
friend class CSpaceOperationRemoveControllableEntity
CFloorEntity & GetFloorEntity()
Returns the floor entity.
UInt32 GetNumberEntities() const
Returns the number of entities contained in the space.
virtual void UpdatePhysics()=0
virtual void Update()
Updates the space.
virtual ~CSpace()
Class destructor.
CSpace()
Class constructor.
CPhysicsEngine::TVector * m_ptPhysicsEngines
A pointer to the list of physics engines.
void SetArenaCenter(const CVector3 &c_center)
Sets the arena center.
CEntity::TMap & GetEntityMapPerId()
Returns a map of all entities ordered by id.
CEntity::TMap m_mapEntitiesPerId
A map of entities.
const CRange< CVector3 > & GetArenaLimits() const
Returns the arena limits.
std::map< std::string, TMapPerType, std::less< std::string > > TMapPerTypePerId
A map of entities indexed by type description and by id.
void SetFloorEntity(CFloorEntity &c_floor_entity)
Sets the floor entity.
UInt32 m_unSimulationClock
The current simulation clock.
TMapPerType & GetEntitiesByType(const std::string &str_type)
Returns a map containing all the objects of a given type.
void GetEntitiesMatching(CEntity::TVector &t_buffer, const std::string &str_pattern)
Returns the entities matching a given pattern.
TControllableEntityIterCBType m_cbControllableEntityIter
Callback for iterating over entities from within the loop functions.
TMapPerTypePerId m_mapEntitiesPerTypePerId
A map of maps of all the simulated entities.
CMedium::TVector * m_ptMedia
A pointer to the list of media.
void SetSimulationClock(UInt32 un_simulation_clock)
Sets a new value for the simulation clock.
virtual void ControllableEntityIterationWaitAbort()
If the loop functions do not perform entity iteration in either of the PreStep() or PostStep() functi...
virtual void IterateOverControllableEntities(const TControllableEntityIterCBType &c_cb)=0
Given a callback specified in the loop functions, iterate over all controllable entities currently pr...
virtual void UpdateControllableEntitiesAct()=0
const TMapPerType & GetEntitiesByType(const std::string &str_type) const
TMapPerTypePerId & GetEntityMapPerTypePerId()
Returns a nested map of entities, ordered by type and by id.
void AddEntity(ENTITY &c_entity)
Adds an entity of the given type.
void IncreaseSimulationClock(UInt32 un_increase=1)
Increases the simulation clock by the wanted value.
UInt32 GetSimulationClock() const
Returns the current value of the simulation clock.
CVector3 m_cArenaSize
Arena size.
CVector3 m_cArenaCenter
Arena center.
friend class CSpaceOperationAddEmbodiedEntity
CEntity & GetEntity(const std::string &str_id)
Returns the entity with the given id.
CEntity::TVector m_vecRootEntities
A vector of all the entities without a parent.
CFloorEntity * m_pcFloorEntity
The floor entity.
std::map< std::string, CAny, std::less< std::string > > TMapPerType
A map of entities indexed by type description.
virtual void UpdateMedia()=0
virtual void AddEntityToPhysicsEngine(CEmbodiedEntity &c_entity)
void SetArenaSize(const CVector3 &c_size)
Sets the arena size.
virtual void AddControllableEntity(CControllableEntity &c_entity)
CEntity::TVector & GetEntityVector()
Returns a vector of all the entities in the space.
const CVector3 & GetArenaSize() const
Returns the arena size.
const CVector3 & GetArenaCenter() const
Returns the arena center.
CSimulator & m_cSimulator
CEntity::TVector m_vecEntities
A vector of entities.
CEntity::TVector & GetRootEntityVector()
Returns a vector of all the root entities in the space.
std::function< void(CControllableEntity *)> TControllableEntityIterCBType
The callback type for iteration over controllable entities within the PreStep() and/or PostStep() par...
virtual void UpdateControllableEntitiesSenseStep()=0
virtual void RemoveControllableEntity(CControllableEntity &c_entity)
void RemoveEntity(ENTITY &c_entity)
Removes an entity of the given type.
friend class CSpaceOperationAddControllableEntity
virtual ~CSpaceOperation()
virtual ~CSpaceOperationAddEntity()
virtual ~CSpaceOperationRemoveEntity()
This class is the base of all XML-configurable ARGoS interface.