RapyutaSimulationPlugins
SimulationState.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 
18 
19 // UE
20 
21 #include "CoreMinimal.h"
22 
23 #include "GameFramework/Actor.h"
24 
25 
26 
27 // rclUE
28 
29 #include "Srvs/ROS2Attach.h"
30 
31 #include "Srvs/ROS2DeleteEntity.h"
32 
33 #include "Srvs/ROS2GetEntityState.h"
34 
35 #include "Srvs/ROS2SetEntityState.h"
36 
37 #include "Srvs/ROS2SpawnEntities.h"
38 
39 #include "Srvs/ROS2SpawnEntity.h"
40 
41 
42 
43 // RapyutaSimulationPlugins
44 
45 #include "Core/RRConversionUtils.h"
46 
47 #include "Core/RRGeneralUtils.h"
48 
49 
50 
51 #include "SimulationState.generated.h"
52 
53 
54 
68 struct RAPYUTASIMULATIONPLUGINS_API FRREntityInfo
69 
70 {
71 
72 
73 
74 
79  FString EntityTypeName;
80 
81 
82 
83 
88  TSubclassOf<AActor> EntityClass;
89 
90 
91 
93 
94  {
95 
96  }
97 
98  FRREntityInfo(const TPair<FString, TSubclassOf<AActor>>& InEntityInfo)
99 
100  : EntityTypeName(InEntityInfo.Key), EntityClass(InEntityInfo.Value)
101 
102  {
103 
104  }
105 
106 };
107 
108 
109 
125 struct RAPYUTASIMULATIONPLUGINS_API FRREntities
126 
127 {
128 
129 
130 
131 
136  TArray<AActor*> Actors;
137 
138 };
139 
140 
141 
142 // (NOTE) To be renamed ARRROS2SimulationState, due to its inherent attachment to ROS 2 Node
143 
144 // & thus house [Entities] spawned by ROS services, and with ROS relevance.
145 
146 // However, check for its usage in BP and refactor if there is accordingly!
147 
173 class RAPYUTASIMULATIONPLUGINS_API ASimulationState : public AActor
174 
175 {
176 
177 
178 
179 public:
180 
190 
191 
192 
193 public:
194 
206  void RegisterSpawnableBPEntities(const TArray<FString>& InBPSpawnableClassNames);
207 
208 
209 
221  virtual void InitEntities();
222 
223 
224 
226 
228 
229 
234  FROSGetEntityStateReq PrevGetEntityStateRequest;
235 
236 
237 
251  bool ServerCheckSetEntityStateRequest(const FROSSetEntityStateReq& InRequest);
252 
253 
254 
268  void ServerSetEntityState(const FROSSetEntityStateReq& InRequest);
269 
270 
271 
273 
275 
276 
281  FROSSetEntityStateReq PrevSetEntityStateRequest;
282 
283 
284 
300  bool ServerCheckAttachRequest(const FROSAttachReq& InRequest);
301 
302 
303 
317  void ServerAttach(const FROSAttachReq& InRequest);
318 
319 
320 
322 
324 
325 
330  FROSAttachReq PrevAttachEntityRequest;
331 
332 
333 
349  bool ServerCheckSpawnRequest(const FROSSpawnEntityReq& InRequest);
350 
351 
352 
366  AActor* ServerSpawnEntity(const FROSSpawnEntityReq& InRequest, const int32 NetworkPlayerId);
367 
368 
369 
371 
373 
374 
379  FROSSpawnEntityReq PrevSpawnEntityRequest;
380 
381 
382 
398  bool ServerCheckDeleteRequest(const FROSDeleteEntityReq& InRequest);
399 
400 
401 
417  void ServerDeleteEntity(const FROSDeleteEntityReq& InRequest);
418 
419 
420 
422 
424 
425 
430  FROSDeleteEntityReq PrevDeleteEntityRequest;
431 
432 
433 
449  void ServerAddEntity(AActor* InEntity);
450 
451 
452 
464  void AddTaggedEntity(AActor* InEntity, const FName& InTag);
465 
466 
467 
483  void AddSpawnableEntityTypes(TMap<FString, TSubclassOf<AActor>> InSpawnableEntityTypes);
484 
485 
486 
488 
490 
491 
496  TMap<FString, AActor*> Entities;
497 
498 
499 
500 #if WITH_EDITOR
501 
502  TMap<FString, AActor*> EntitiesWithDisplayName;
503 
504 #endif
505 
506 
507 
509 
511 
512 
517  TMap<FName, FRREntities> EntitiesWithTag;
518 
519 
520 
522 
523 
528  TArray<AActor*> EntityList;
529 
530 
531 
543  void OnRep_EntityList();
544 
545 
546 
548 
550 
551 
556  TMap<FString, TSubclassOf<AActor>> SpawnableEntityTypes;
557 
558 
559 
561 
562 
567  TArray<FRREntityInfo> SpawnableEntityInfoList;
568 
569 
570 
582  void GetSpawnableEntityInfoList();
583 
584 
585 
597  void OnRep_SpawnableEntityInfoList();
598 
599 
600 
602 
603 
609 
610 
611 
620  TMap<FString, std::string> EncodedStrings;
621 
622 
623 
624 private:
625 
632  bool VerifyIsServerCall(const FString& InFunctionName);
633 
634 
635 
652  AActor* ServerSpawnEntity(const FROSSpawnEntityReq& InROSSpawnRequest,
653 
654  const TSubclassOf<AActor>& InEntityClass,
655 
656  const FTransform& InEntityTransform,
657 
658  const int32& InNetworkPlayerId);
659 
660 };
661 
ASimulationState::SpawnableEntityInfoList
TArray< FRREntityInfo > SpawnableEntityInfoList
Replicatable Copy of SpawnableEntityTypes.
Definition: SimulationState.h:567
ASimulationState::PrevGetEntityStateRequest
FROSGetEntityStateReq PrevGetEntityStateRequest
Cached the previous [GetEntityState] request for duplicated incoming request filtering.
Definition: SimulationState.h:234
ASimulationState
Provide ROS 2 interface implementations to interact with UE4.
Definition: SimulationState.h:173
ASimulationState::EncodedStrings
TMap< FString, std::string > EncodedStrings
Matches UE strings to original char buffers, for ros messages.
Definition: SimulationState.h:620
ASimulationState::FetchEntityListTimerHandle
FTimerHandle FetchEntityListTimerHandle
Timer handle to fetch SpawnableEntityInfoList.
Definition: SimulationState.h:608
FRREntityInfo::EntityTypeName
FString EntityTypeName
Definition: SimulationState.h:79
FRREntityInfo::FRREntityInfo
FRREntityInfo(const TPair< FString, TSubclassOf< AActor >> &InEntityInfo)
Definition: SimulationState.h:98
ASimulationState::PrevAttachEntityRequest
FROSAttachReq PrevAttachEntityRequest
Cached the previous [Attach] request for duplicated incoming request filtering.
Definition: SimulationState.h:330
ASimulationState::PrevSpawnEntityRequest
FROSSpawnEntityReq PrevSpawnEntityRequest
Cached the previous [SpawnEntity] request for duplicated incoming request filtering.
Definition: SimulationState.h:379
FRREntities::Actors
TArray< AActor * > Actors
Definition: SimulationState.h:136
FRREntityInfo
FRREntityInfo.
Definition: SimulationState.h:68
ASimulationState::SpawnableEntityTypes
TMap< FString, TSubclassOf< AActor > > SpawnableEntityTypes
Spawnable entity types for SpawnEntity ROS 2 service.
Definition: SimulationState.h:556
ASimulationState::EntitiesWithTag
TMap< FName, FRREntities > EntitiesWithTag
All existing entities with tags which can be manipulated by this class via ROS 2 services.
Definition: SimulationState.h:517
FRREntities
FRREntities has only TArray<AActor*> Actors.
Definition: SimulationState.h:125
ASimulationState::PrevDeleteEntityRequest
FROSDeleteEntityReq PrevDeleteEntityRequest
Cached the previous [DeleteEntity] request for duplicated incoming request filtering.
Definition: SimulationState.h:430
ASimulationState::EntityList
TArray< AActor * > EntityList
Replicatable copy of Entities.
Definition: SimulationState.h:528
ASimulationState::PrevSetEntityStateRequest
FROSSetEntityStateReq PrevSetEntityStateRequest
Cached the previous [SetEntityState] request for duplicated incoming request filtering.
Definition: SimulationState.h:281
RRGeneralUtils.h
General utils.
FRREntityInfo::FRREntityInfo
FRREntityInfo()
Definition: SimulationState.h:92
RRConversionUtils.h
Convertions between ROS and UE, i.e.
FRREntityInfo::EntityClass
TSubclassOf< AActor > EntityClass
Definition: SimulationState.h:88
ASimulationState::Entities
TMap< FString, AActor * > Entities
All existing entities which can be manipulated by this class via ROS 2 services.
Definition: SimulationState.h:496