@@ -87,13 +87,15 @@ namespace RGL
87
87
88
88
AzFramework::EntityContextEventBus::Handler::BusConnect (gameEntityContextId);
89
89
LidarSystemNotificationBus::Handler::BusConnect ();
90
+ AZ::TickBus::Handler::BusConnect ();
90
91
91
92
m_rglLidarSystem.Activate ();
92
93
}
93
94
94
95
void RGLSystemComponent::Deactivate ()
95
96
{
96
97
m_rglLidarSystem.Deactivate ();
98
+ AZ::TickBus::Handler::BusDisconnect ();
97
99
LidarSystemNotificationBus::Handler::BusDisconnect ();
98
100
AzFramework::EntityContextEventBus::Handler::BusDisconnect ();
99
101
@@ -113,6 +115,18 @@ namespace RGL
113
115
void RGLSystemComponent::SetSceneConfiguration (const SceneConfiguration& config)
114
116
{
115
117
m_sceneConfig = config;
118
+
119
+ m_excludedTags.resize (config.m_excludedTagNames .size ());
120
+ AZStd::transform (
121
+ config.m_excludedTagNames .begin (),
122
+ config.m_excludedTagNames .end (),
123
+ m_excludedTags.begin (),
124
+ [](const AZStd::string& tagName) -> LmbrCentral::Tag
125
+ {
126
+ return LmbrCentral::Tag (tagName);
127
+ });
128
+ UpdateTagExcludedEntities ();
129
+
116
130
RGLNotificationBus::Broadcast (&RGLNotifications::OnSceneConfigurationSet, config);
117
131
}
118
132
@@ -121,14 +135,37 @@ namespace RGL
121
135
return m_sceneConfig;
122
136
}
123
137
138
+ static bool HasExcludedTag (AZ::EntityId entityId, const AZStd::vector<LmbrCentral::Tag>& excludedTags)
139
+ {
140
+ LmbrCentral::Tags entityTags;
141
+ LmbrCentral::TagComponentRequestBus::EventResult (entityTags, entityId, &LmbrCentral::TagComponentRequests::GetTags);
142
+
143
+ if (entityTags.empty ())
144
+ {
145
+ return false ;
146
+ }
147
+
148
+ for (const auto tag : excludedTags)
149
+ {
150
+ if (entityTags.contains (tag))
151
+ {
152
+ return true ;
153
+ }
154
+ }
155
+
156
+ return false ;
157
+ }
158
+
124
159
void RGLSystemComponent::OnEntityContextCreateEntity (AZ::Entity& entity)
125
160
{
126
- if (m_excludedEntities. contains (entity. GetId () ))
161
+ if (! HasVisuals (entity))
127
162
{
128
163
return ;
129
164
}
130
165
131
- if (m_activeLidarCount < 1U )
166
+ m_entityTagListeners.emplace_back (entity.GetId ());
167
+
168
+ if (m_activeLidarCount < 1U || ShouldEntityBeExcluded (entity.GetId ()))
132
169
{
133
170
m_unprocessedEntities.emplace (entity.GetId ());
134
171
return ;
@@ -163,6 +200,12 @@ namespace RGL
163
200
RGLNotificationBus::Broadcast (&RGLNotifications::OnAnyLidarExists);
164
201
for (auto entityIdIt = m_unprocessedEntities.begin (); entityIdIt != m_unprocessedEntities.end ();)
165
202
{
203
+ if (ShouldEntityBeExcluded (*entityIdIt))
204
+ {
205
+ ++entityIdIt;
206
+ continue ;
207
+ }
208
+
166
209
AZ::Entity* entity = nullptr ;
167
210
AZ::ComponentApplicationBus::BroadcastResult (entity, &AZ::ComponentApplicationRequests::FindEntity, *entityIdIt);
168
211
AZ_Assert (entity, " Failed to find entity with provided id!" );
@@ -189,6 +232,26 @@ namespace RGL
189
232
m_modelLibrary.Clear ();
190
233
}
191
234
235
+ void RGLSystemComponent::OnTick (float deltaTime, AZ::ScriptTimePoint time)
236
+ {
237
+ for (auto entityId : m_managersToBeRemoved)
238
+ {
239
+ m_entityManagers.erase (entityId);
240
+ m_unprocessedEntities.insert (entityId);
241
+ }
242
+ m_managersToBeRemoved.clear ();
243
+ }
244
+
245
+ bool RGLSystemComponent::HasVisuals (const AZ::Entity& entity)
246
+ {
247
+ return entity.FindComponent <EMotionFX::Integration::ActorComponent>() || entity.FindComponent (AZ::Render::MeshComponentTypeId);
248
+ }
249
+
250
+ bool RGLSystemComponent::ShouldEntityBeExcluded (AZ::EntityId entityId) const
251
+ {
252
+ return m_excludedEntities.contains (entityId) || HasExcludedTag (entityId, m_excludedTags);
253
+ }
254
+
192
255
void RGLSystemComponent::ProcessEntity (const AZ::Entity& entity)
193
256
{
194
257
AZStd::unique_ptr<EntityManager> entityManager;
@@ -209,6 +272,27 @@ namespace RGL
209
272
AZ_Error (__func__, inserted, " Object with provided entityId already exists." );
210
273
}
211
274
275
+ void RGLSystemComponent::UpdateTagExcludedEntities ()
276
+ {
277
+ if (m_excludedTags.empty ())
278
+ {
279
+ return ;
280
+ }
281
+
282
+ for (auto entityManagerIt = m_entityManagers.begin (); entityManagerIt != m_entityManagers.end ();)
283
+ {
284
+ if (HasExcludedTag (entityManagerIt->first , m_excludedTags))
285
+ {
286
+ m_unprocessedEntities.insert (entityManagerIt->first );
287
+ entityManagerIt = m_entityManagers.erase (entityManagerIt);
288
+ }
289
+ else
290
+ {
291
+ ++entityManagerIt;
292
+ }
293
+ }
294
+ }
295
+
212
296
void RGLSystemComponent::UpdateScene ()
213
297
{
214
298
AZ::ScriptTimePoint currentTime;
@@ -225,4 +309,33 @@ namespace RGL
225
309
entityManager->Update ();
226
310
}
227
311
}
312
+
313
+ void RGLSystemComponent::ReviseEntityPresence (AZ::EntityId entityId)
314
+ {
315
+ if (m_activeLidarCount < 1U )
316
+ {
317
+ return ; // No lidars exist. Every entity should stay as unprocessed until they do.
318
+ }
319
+
320
+ if (m_excludedEntities.contains (entityId))
321
+ {
322
+ return ; // Already not included.
323
+ }
324
+
325
+ if (HasExcludedTag (entityId, m_excludedTags))
326
+ {
327
+ if (m_entityManagers.contains (entityId))
328
+ {
329
+ m_managersToBeRemoved.push_back (entityId);
330
+ }
331
+ }
332
+ else if (const auto it = m_unprocessedEntities.find (entityId); it != m_unprocessedEntities.end ())
333
+ {
334
+ m_unprocessedEntities.erase (it);
335
+ AZ::Entity* entity = nullptr ;
336
+ AZ::ComponentApplicationBus::BroadcastResult (entity, &AZ::ComponentApplicationRequests::FindEntity, entityId);
337
+ AZ_Assert (entity, " Failed to find entity with provided id!" );
338
+ ProcessEntity (*entity);
339
+ }
340
+ }
228
341
} // namespace RGL
0 commit comments