NoJobEngine 2.0.7
Loading...
Searching...
No Matches
Scene.cpp
Go to the documentation of this file.
1#include <cstdio>
2#include <exception>
6
9
12
13#include <algorithm>
14#include <cmath>
15#include <random>
16#include <utility>
17
18#include <glm/gtc/constants.hpp>
19#include <glm/gtc/matrix_inverse.hpp>
20#include <glm/gtc/matrix_transform.hpp>
21
22#define GLM_ENABLE_EXPERIMENTAL
23#include <glm/gtx/matrix_decompose.hpp>
24#include <glm/gtx/quaternion.hpp>
25
26namespace NoJob
27{
28 namespace
29 {
30 TransformComponent TransformFromMatrix(
31 const glm::mat4& matrix)
32 {
33 glm::vec3 scale;
34 glm::quat orientation;
35 glm::vec3 translation;
36 glm::vec3 skew;
37 glm::vec4 perspective;
38
39 TransformComponent result;
40
41 if (glm::decompose(
42 matrix,
43 scale,
44 orientation,
45 translation,
46 skew,
47 perspective))
48 {
49 result.Position = translation;
50
51 result.Rotation =
52 glm::eulerAngles(
53 orientation);
54
55 result.Scale = scale;
56 }
57
58 return result;
59 }
60
61 bool NearlyEqualPosition(
62 const glm::vec3& a,
63 const glm::vec3& b)
64 {
65 constexpr float epsilon =
66 0.0001f;
67
68 const glm::vec3 difference =
69 a - b;
70
71 return
72 glm::dot(
73 difference,
74 difference) <=
75 epsilon * epsilon;
76 }
77 }
78
79 Scene::Scene() = default;
80
81 Scene::Scene(const Scene& other)
82 : m_Entities(other.m_Entities),
83 m_NextHandle(other.m_NextHandle),
84 m_NextID(other.m_NextID),
85 m_DeltaTime(other.m_DeltaTime)
86 {
87 // Runtime state and NavigationSystem are intentionally
88 // not copied. The runtime owner reconnects navigation
89 // explicitly before OnRuntimeStart().
90 }
91
93 {
95 }
96
97 std::unique_ptr<Scene>
99 {
100 return
101 std::make_unique<Scene>(
102 *this);
103 }
104
106 const Scene& other)
107 {
109
110 m_Entities =
111 other.m_Entities;
112
113 m_NextHandle =
114 other.m_NextHandle;
115
116 m_NextID =
117 other.m_NextID;
118
119 m_DeltaTime =
120 other.m_DeltaTime;
121
122 m_RuntimeRunning = false;
123
124 m_ScriptInstances.clear();
125 m_NavAgentStates.clear();
126
127 // External runtime services are not restored
128 // from serialized or copied scene data.
129 m_NavigationSystem = nullptr;
130 m_SpatialQuery = nullptr;
131 }
132
134 const std::string& name)
135 {
136 const std::uint32_t handle =
137 m_NextHandle++;
138
139 auto [iterator, inserted] =
140 m_Entities.try_emplace(
141 handle);
142
143 (void)inserted;
144
145 EntityData& data =
146 iterator->second;
147
148 data.ID.ID =
149 m_NextID++;
150
151 data.Tag.Tag =
152 name.empty()
153 ? "Entity"
154 : name;
155
156 return Entity(
157 handle,
158 this);
159 }
160
162 Entity entity)
163 {
164 if (!entity ||
165 entity.m_Scene != this)
166 {
167 return;
168 }
169
170 const auto relationship =
171 entity.GetComponent<
173
174 // Children become roots while preserving
175 // their world transforms.
176 const auto children =
177 relationship.Children;
178
179 for (const auto childHandle :
180 children)
181 {
182 if (IsValid(childHandle))
183 {
184 Unparent(
185 Entity(
186 childHandle,
187 this),
188 true);
189 }
190 }
191
192 if (relationship.Parent != 0 &&
193 IsValid(
194 relationship.Parent))
195 {
196 auto& siblings =
197 m_Entities
198 .at(
199 relationship.Parent)
200 .Relationship
201 .Children;
202
203 std::erase(
204 siblings,
205 entity.m_Handle);
206 }
207
208 DestroyScriptInstance(
209 entity.m_Handle);
210
211 m_NavAgentStates.erase(
212 entity.m_Handle);
213
214 m_ParticleStates.erase(
215 entity.m_Handle);
216
217 m_Entities.erase(
218 entity.m_Handle);
219 }
220
222 std::uint32_t handle) const
223 {
224 return
225 handle != 0 &&
226 m_Entities.contains(
227 handle);
228 }
229
230 std::vector<Entity>
232 {
233 std::vector<Entity> result;
234
235 result.reserve(
236 m_Entities.size());
237
238 for (const auto& [handle, data] :
239 m_Entities)
240 {
241 (void)data;
242
243 result.emplace_back(
244 handle,
245 this);
246 }
247
248 return result;
249 }
250
251 std::optional<Scene::AIDebugStateInfo> Scene::GetAIDebugState(std::uint32_t handle) const
252 {
253 const auto it = m_ScriptInstances.find(handle);
254 if (it == m_ScriptInstances.end()) return std::nullopt;
255 for (const auto& ptr : it->second)
256 {
257 if (!ptr || ptr->GetAIDebugState().empty()) continue;
258 AIDebugStateInfo result;
259 result.Current = ptr->GetAIDebugState();
260 result.Previous = ptr->GetAIDebugPreviousState();
261 result.TimeInState = ptr->GetAIDebugTimeInState();
262 result.RuntimeSeconds = ptr->GetAIDebugRuntimeSeconds();
263 for (const auto& e : ptr->GetAIDebugTransitions())
264 result.History.push_back({e.From, e.To, e.RuntimeSeconds});
265 return result;
266 }
267 return std::nullopt;
268 }
269
270 void Scene::CreateScriptInstance(std::uint32_t handle)
271 {
272 if (!IsValid(handle) || m_ScriptInstances.contains(handle)) return;
275 auto& data = m_Entities.at(handle);
276 auto& instances = m_ScriptInstances[handle];
277 auto create = [&](NativeScriptComponent& component)
278 {
279 std::fprintf(stderr, "[BT DIAG] Entity %u configured script '%s', enabled=%d\n",
280 handle, component.ScriptName.c_str(), component.Enabled ? 1 : 0);
281 if (!component.Enabled) return;
283 const auto* definition = ScriptRegistry::Find(component.ScriptName);
284 if (!definition || !definition->Factory) {
285 std::fprintf(stderr, "[BT DIAG] Entity %u script '%s' MISSING FACTORY in runtime ScriptRegistry (DLL not loaded/registered?)\n",
286 handle, component.ScriptName.c_str());
287 return;
288 }
289 std::fprintf(stderr, "[BT DIAG] Entity %u script '%s' factory FOUND\n", handle, component.ScriptName.c_str());
290 auto instance = definition->Factory();
291 instance->m_Entity = Entity(handle, this);
292 instance->m_BoundScript = &component;
293 ScriptRegistry::ApplyFieldsToInstance(component, *instance);
294 // Store before OnCreate, so shutdown can clean up even if OnCreate throws.
295 instances.push_back(std::move(instance));
296 };
297 if (data.NativeScript) create(*data.NativeScript);
298 for (auto& script : data.AdditionalNativeScripts) create(script);
299 // Two-phase initialization: all scripts must exist before a BT agent
300 // resolves actions exposed by its sibling scripts.
301 // Initialize non-BT scripts first, even if the BTAssetAgent was listed first.
302 // Every instance is already constructed before either pass.
303 for (int pass = 0; pass < 2; ++pass)
304 for (auto& instance : instances) if (instance && instance->m_BoundScript &&
305 ((instance->m_BoundScript->ScriptName == "BTAssetAgent") == (pass == 1))) {
306 std::fprintf(stderr, "[BT DIAG] Entity %u OnCreate '%s' (pass %d)\n",
307 handle, instance->m_BoundScript->ScriptName.c_str(), pass);
308 try { instance->OnCreate(); }
309 catch (const std::exception& ex) {
310 std::fprintf(stderr, "[Native Script] Entity %u, script %s: %s\n",
311 handle, instance->m_BoundScript ? instance->m_BoundScript->ScriptName.c_str() : "unknown", ex.what());
312 // A failed BT initialization must not terminate the whole editor.
313 }
314 }
315 }
316
317 ScriptableEntity* Scene::FindRuntimeScript(std::uint32_t handle, const std::string& scriptName) const
318 {
319 const auto it = m_ScriptInstances.find(handle);
320 if (it == m_ScriptInstances.end()) return nullptr;
321 for (const auto& script : it->second)
322 if (script && script->m_BoundScript && script->m_BoundScript->ScriptName == scriptName)
323 return script.get();
324 return nullptr;
325 }
326
327 void Scene::RegisterEntityBehaviorTreeBindings(std::uint32_t handle, BTNativeRegistry& registry) const
328 {
329 std::fprintf(stderr, "[BT TRACE] ENTER Scene::RegisterEntityBehaviorTreeBindings entity=%u\n", handle);
330 std::fflush(stderr);
331 const auto it = m_ScriptInstances.find(handle);
332 if (it == m_ScriptInstances.end()) {
333 std::fprintf(stderr, "[BT DIAG] Entity %u has NO runtime script instances\n", handle);
334 return;
335 }
336 std::fprintf(stderr, "[BT DIAG] Entity %u has %zu runtime script instance(s)\n",
337 handle, it->second.size());
338 for (const auto& script : it->second) {
339 if (!script) continue;
340 const char* name = script->m_BoundScript ? script->m_BoundScript->ScriptName.c_str() : "<unbound>";
341 std::fprintf(stderr, "[BT DIAG] Entity %u registering BT callbacks from '%s'\n", handle, name);
342 std::fprintf(stderr, "[BT TRACE] BEFORE virtual binding script='%s' ptr=%p\n", name, static_cast<const void*>(script.get()));
343 std::fflush(stderr);
344 script->RegisterBehaviorTreeBindings(registry);
345 std::fprintf(stderr, "[BT TRACE] AFTER virtual binding script='%s' action=%d condition=%d\n",
346 name, registry.HasAction("Guard.Attack") ? 1 : 0,
347 registry.HasCondition("Guard.HasTarget") ? 1 : 0);
348 std::fflush(stderr);
349 std::fprintf(stderr, "[BT DIAG] Entity %u after '%s': Guard.Attack=%d, Guard.HasTarget=%d\n",
350 handle, name, registry.HasAction("Guard.Attack") ? 1 : 0,
351 registry.HasCondition("Guard.HasTarget") ? 1 : 0);
352 }
353 }
354
355 std::optional<Scene::BTDebugInfo> Scene::GetBehaviorTreeDebug(std::uint32_t handle) const
356 {
357 const auto it = m_ScriptInstances.find(handle);
358 if (it == m_ScriptInstances.end()) return std::nullopt;
359 for (const auto& ptr : it->second)
360 {
361 const auto* controller = ptr ? dynamic_cast<const BTScriptController*>(ptr.get()) : nullptr;
362 if (!controller || !controller->GetBehaviorTreeInstance()) continue;
363 const auto& snapshot = controller->GetDebugSnapshot();
364 BTDebugInfo result;
365 result.LastResult = snapshot.LastResult;
366 for (const auto& n : snapshot.Nodes)
367 result.Nodes.push_back({n.ID, n.Status, n.Ticks, n.Label, n.Depth, n.Active});
368 for (const auto& e : snapshot.Events)
369 result.Events.push_back({e.Tick, e.Node, e.Kind, e.Detail});
370 result.BlackboardEntries = snapshot.BlackboardEntries;
371 result.BlackboardRevision = snapshot.BlackboardRevision;
372 result.TargetHandle = snapshot.TargetHandle;
373 result.TargetPosition = snapshot.TargetPosition;
374 return result;
375 }
376 return std::nullopt;
377 }
378
379 void Scene::DestroyScriptInstance(std::uint32_t handle)
380 {
381 auto it = m_ScriptInstances.find(handle);
382 if (it == m_ScriptInstances.end()) return;
383 auto instances = std::move(it->second);
384 m_ScriptInstances.erase(it);
385 for (auto rit = instances.rbegin(); rit != instances.rend(); ++rit)
386 if (*rit) (*rit)->OnDestroy();
387 }
388
389 const std::vector<
390 Scene::RuntimeParticle>&
392 std::uint32_t handle) const
393 {
394 static const std::vector<
396 empty;
397
398 const auto it =
399 m_ParticleStates.find(
400 handle);
401
402 return
403 it ==
404 m_ParticleStates.end()
405 ? empty
406 : it->second.Particles;
407 }
408
410 {
411 if (m_RuntimeRunning)
412 return;
413
414 m_RuntimeRunning = true;
415
416 m_ParticleStates.clear();
417 m_NavAgentStates.clear();
418 m_PerceptionStates.clear();
419
421
422 std::vector<std::uint32_t> startupHandles;
423 startupHandles.reserve(m_Entities.size());
424 for (const auto& [handle, data] : m_Entities)
425 startupHandles.push_back(handle);
426
427 for (const auto handle : startupHandles)
428 {
429 if (!IsValid(handle))
430 continue;
431
432 CreateScriptInstance(handle);
433
434 if (!IsValid(handle))
435 continue;
436
437 const auto& data = m_Entities.at(handle);
438
439 if (data.AudioSource &&
440 data.AudioSource
441 ->PlayOnAwake)
442 {
443 const glm::mat4 world =
445 Entity(
446 handle,
447 this));
448
450 handle,
451 *data.AudioSource,
452 glm::vec3(
453 world[3]));
454 }
455
456 if (data.NavAgent)
457 {
458 NavAgentRuntimeState state;
459
460 state.Agent.Speed() =
461 std::max(
462 data.NavAgent->Speed,
463 0.0f);
464
465 state.Agent
467 std::max(
468 data.NavAgent
469 ->StoppingDistance,
470 0.0f);
471
472 m_NavAgentStates.emplace(
473 handle,
474 std::move(state));
475 }
476 if (data.Perception)
477 {
478 m_PerceptionStates.try_emplace(handle);
479 }
480 }
481 }
482
484 {
485 m_RuntimeRunning = false;
486
487 m_SpatialQuery = nullptr;
488
489 m_ParticleStates.clear();
490 m_NavAgentStates.clear();
491 m_PerceptionStates.clear();
492
494
495 while (
496 !m_ScriptInstances.empty())
497 {
498 DestroyScriptInstance(
499 m_ScriptInstances
500 .begin()
501 ->first);
502 }
503 }
504
505 std::vector<Scene::PerceptionTargetInfo>
506 Scene::GetPerceivedTargets(std::uint32_t observerHandle) const
507 {
508 std::vector<PerceptionTargetInfo> results;
509
510 // Comprobamos que el observador tiene estado de percepción.
511 const auto stateIt = m_PerceptionStates.find(observerHandle);
512
513 if (stateIt == m_PerceptionStates.end())
514 return results;
515
516 const auto& state = stateIt->second;
517
518 // Reservamos memoria para evitar realojamientos.
519 results.reserve(state.Targets.size());
520
521 for (const auto& [targetHandle, target] : state.Targets)
522 {
523 if (!IsValid(targetHandle))
524 continue;
525
527
528 info.EntityHandle = target.EntityHandle;
529 info.LastKnownPosition = target.LastKnownPosition;
530 info.TimeSinceLastSeen = target.TimeSinceLastSeen;
531 info.VisibleDuration = target.VisibleDuration;
532 info.TrackedDuration = target.TrackedDuration;
533 info.IsVisible = target.IsVisible;
534
535 results.push_back(info);
536 }
537
538 return results;
539 }
540
541 std::optional<Scene::LastSeenTargetInfo> Scene::GetLastSeenTarget(std::uint32_t observerHandle) const
542 {
543 const auto it = m_PerceptionStates.find(observerHandle);
544 if (it == m_PerceptionStates.end() || !it->second.LastSeenHandle ||
545 !IsValid(it->second.LastSeenHandle))
546 return std::nullopt;
547 const auto& state = it->second;
548 bool visible = false;
549 if (auto target = state.Targets.find(state.LastSeenHandle); target != state.Targets.end())
550 visible = target->second.IsVisible;
551 return LastSeenTargetInfo{ state.LastSeenHandle, state.LastSeenPosition,
552 state.LastSeenElapsed, visible };
553 }
554
555 void Scene::UpdatePerception(float deltaTime)
556 {
557 const float dt = std::max(deltaTime, 0.0f);
558
559 for (auto& [handle, data] : m_Entities)
560 {
561 if (!data.Perception)
562 {
563 m_PerceptionStates.erase(handle);
564 continue;
565 }
566
567 const auto& perception = *data.Perception;
568
569 if (!perception.Enabled)
570 {
571 m_PerceptionStates.erase(handle);
572 continue;
573 }
574
575 auto& state = m_PerceptionStates[handle];
576
577 if (state.LastSeenHandle)
578 state.LastSeenElapsed += dt;
579
580 for (auto it = state.Targets.begin();
581 it != state.Targets.end();)
582 {
583 auto& target = it->second;
584 target.TrackedDuration += dt;
585 if (target.IsVisible) target.VisibleDuration += dt;
586
587 if (!IsValid(target.EntityHandle))
588 {
589 it = state.Targets.erase(it);
590 continue;
591 }
592
593 if (!target.IsVisible)
594 {
595 target.TimeSinceLastSeen += dt;
596
597 if (target.TimeSinceLastSeen >=
598 std::max(perception.MemoryDuration, 0.0f))
599 {
600 it = state.Targets.erase(it);
601 continue;
602 }
603 }
604
605 ++it;
606 }
607 state.UpdateTimer += dt;
608
609 const float interval =
610 std::max(perception.UpdateInterval, 0.01f);
611
612 if (state.UpdateTimer < interval)
613 continue;
614
615 state.UpdateTimer = 0.0f;
616
617 for (auto& [targetHandle, target] : state.Targets)
618 {
619 target.IsVisible = false;
620 }
621
622 const glm::mat4 observerWorld =
623 GetWorldTransform(Entity(handle, this));
624
625 const glm::vec3 observerPosition(observerWorld[3]);
626
627 // Forward local motor: -Z.
628 // Transform dir global space.
629 glm::vec3 forward = -glm::vec3(observerWorld[2]);
630
631 // Perception horizontal plane XZ.
632 forward.y = 0.0f;
633
634 const float forwardLengthSquared =
635 glm::dot(forward, forward);
636
637 if (forwardLengthSquared < 0.000001f)
638 forward = glm::vec3(0.0f, 0.0f, -1.0f);
639 else
640 forward /= std::sqrt(forwardLengthSquared);
641
642 const float fov =
643 std::clamp(perception.FieldOfView, 0.0f, 360.0f);
644
645 const float halfFovRadians =
646 glm::radians(fov * 0.5f);
647
648 const float minimumDot =
649 std::cos(halfFovRadians);
650
651 const float radius =
652 std::max(perception.DetectionRadius, 0.0f);
653
654 const float radiusSquared = radius * radius;
655
656 for (const auto& [targetHandle, targetData] : m_Entities)
657 {
658 if (targetHandle == handle)
659 continue;
660
661 const LayerMask targetMask =
662 EntityLayers::Bit(targetData.Layer.Layer);
663
664 if ((targetMask & perception.DetectionMask) == 0)
665 continue;
666
667 const glm::mat4 targetWorld =
668 GetWorldTransform(Entity(targetHandle, this));
669
670 const glm::vec3 targetPosition(targetWorld[3]);
671
672 const glm::vec3 offset =
673 targetPosition - observerPosition;
674
675 const float distanceSquared =
676 glm::dot(offset, offset);
677
678 if (distanceSquared > radiusSquared)
679 continue;
680 // Prove the Horizontal angle to frontal direction agent
681 glm::vec3 horizontalOffset = offset;
682 horizontalOffset.y = 0.0f;
683
684 const float horizontalDistanceSquared =
685 glm::dot(horizontalOffset, horizontalOffset);
686
687 if (horizontalDistanceSquared > 0.000001f &&
688 fov < 360.0f)
689 {
690 const glm::vec3 directionToTarget =
691 horizontalOffset /
692 std::sqrt(horizontalDistanceSquared);
693
694 const float dot =
695 glm::dot(forward, directionToTarget);
696
697 if (dot < minimumDot)
698 continue;
699 }
700
701 // -----------------------------------------------------
702 // Line of Sight (LOS)
703 // -----------------------------------------------------
704
705 if (m_SpatialQuery)
706 {
707 const std::uint64_t observerID = data.ID.ID;
708 const std::uint64_t targetID = targetData.ID.ID;
709 // Eye position in world space.
710 // EyeHeight is a vertical offset from the entity origin.
711 const float eyeHeight =
712 std::max(perception.EyeHeight, 0.0f);
713
714 const glm::vec3 eyePosition =
715 observerPosition + glm::vec3(0.0f, eyeHeight, 0.0f);
716
717 const glm::vec3 targetAimPosition =
718 targetPosition + glm::vec3(0.0f, eyeHeight, 0.0f);
719
720 const bool blocked = m_SpatialQuery->HasObstacleBetween(
721 eyePosition,
722 targetAimPosition,
723 observerID,
724 targetID
725 );
726
727 if (blocked)
728 continue;
729 }
730
731 auto& targetState = state.Targets[targetHandle];
732
733 targetState.EntityHandle = targetHandle;
734 targetState.LastKnownPosition = targetPosition;
735 state.LastSeenHandle = targetHandle;
736 state.LastSeenPosition = targetPosition;
737 state.LastSeenElapsed = 0.0f;
738 targetState.TimeSinceLastSeen = 0.0f;
739 targetState.IsVisible = true;
740
741 }
742 }
743 }
745 float deltaTime)
746 {
747 m_DeltaTime =
748 deltaTime;
749
750 if (!m_RuntimeRunning)
751 return;
752
753 // -----------------------------------------------------
754 // Animator
755 // -----------------------------------------------------
756
757 for (auto& [handle, data] :
758 m_Entities)
759 {
760 (void)handle;
761
762 if (!data.Animator ||
763 !data.Animator->Playing ||
764 !data.Animator->Animation)
765 {
766 continue;
767 }
768
769 const auto& clips =
770 data.Animator
771 ->Animation
772 ->Clips();
773
774 if (clips.empty())
775 continue;
776
777 data.Animator->ClipIndex =
778 std::clamp(
779 data.Animator->ClipIndex,
780 0,
781 static_cast<int>(
782 clips.size()) -
783 1);
784
785 auto& animator =
786 *data.Animator;
787
788 const float duration =
789 static_cast<float>(
790 clips[
791 animator.ClipIndex]
792 .DurationSeconds());
793
794 animator.TimeSeconds +=
795 deltaTime *
796 animator.Speed;
797
798 if (duration > 0.0f &&
799 animator.TimeSeconds >
800 duration)
801 {
802 animator.TimeSeconds =
803 animator.Loop
804 ? std::fmod(
805 animator.TimeSeconds,
806 duration)
807 : duration;
808 }
809 }
810
811 // -----------------------------------------------------
812 // V1.8 Native NavAgents
813 // -----------------------------------------------------
814
815 // -----------------------------------------------------
816// V1.8 Native NavAgents - Dynamic Repath
817// -----------------------------------------------------
818
819 if (m_NavigationSystem)
820 {
821
822
823 const bool hasNavMesh =
824 m_NavigationSystem->HasNavMesh();
825
826 const std::uint64_t navMeshVersion =
827 m_NavigationSystem->GetNavMeshVersion();
828
829 for (auto& [handle, data] : m_Entities)
830 {
831 if (!data.NavAgent)
832 continue;
833
834 auto& component = *data.NavAgent;
835 auto& state = m_NavAgentStates[handle];
836
837 state.Agent.Speed() =
838 std::max(component.Speed, 0.0f);
839
840 state.Agent.StoppingDistance() =
841 std::max(component.StoppingDistance, 0.0f);
842
843 if (!component.Enabled ||
844 !component.HasDestination)
845 {
846 state.Agent.Stop();
847 state.HasRequestedDestination = false;
848 state.PathQueryFailed = false;
849 state.RepathTimer = 0.0f;
850 state.StuckTimer = 0.0f;
851 state.ProgressInitialized = false;
852 continue;
853 }
854
855 Entity entity(handle, this);
856
857 const glm::mat4 worldTransform =
858 GetWorldTransform(entity);
859
860 const glm::vec3 currentPosition(
861 worldTransform[3]);
862
863 // Check actual world-space progress, not the requested
864 // movement vector (physics can prevent the movement).
865 if (!state.ProgressInitialized)
866 {
867 state.LastProgressPosition = currentPosition;
868 state.ProgressInitialized = true;
869 state.StuckTimer = 0.0f;
870 }
871 else
872 {
873 glm::vec3 progress = currentPosition - state.LastProgressPosition;
874 progress.y = 0.0f;
875 if (glm::dot(progress, progress) >= 0.15f * 0.15f)
876 {
877 state.LastProgressPosition = currentPosition;
878 state.StuckTimer = 0.0f;
879 }
880 else
881 {
882 state.StuckTimer += std::max(deltaTime, 0.0f);
883 }
884 }
885
886 // Release an unreachable destination. AI scripts can then
887 // select a new patrol/flee destination instead of pushing
888 // against the same corner indefinitely.
889 if (state.StuckTimer >= 2.5f && component.Speed > 0.01f)
890 {
891 state.Agent.Stop();
892 component.HasDestination = false;
893 state.HasRequestedDestination = false;
894 state.PathQueryFailed = false;
895 state.StuckTimer = 0.0f;
896 state.ProgressInitialized = false;
897 continue;
898 }
899
900 const bool destinationChanged =
901 !state.HasRequestedDestination ||
902 !NearlyEqualPosition(
903 state.RequestedDestination,
904 component.Destination);
905
906 const bool navMeshChanged =
907 state.PathNavMeshVersion != navMeshVersion;
908
909 // No path can remain valid without a NavMesh.
910 if (!hasNavMesh)
911 {
912 state.Agent.Stop();
913 state.PathQueryFailed = true;
914 state.RepathTimer = 0.0f;
915 continue;
916 }
917
918 // New destination or changed navigation geometry:
919 // calculate immediately.
920 if (destinationChanged || navMeshChanged)
921 {
922 const bool found =
923 state.Agent.SetDestination(
924 *m_NavigationSystem,
925 currentPosition,
926 component.Destination);
927
928 state.RequestedDestination =
929 component.Destination;
930
931 state.HasRequestedDestination = true;
932 state.PathNavMeshVersion = navMeshVersion;
933 state.PathQueryFailed = !found;
934 state.RepathTimer = 0.0f;
935 state.LastProgressPosition = currentPosition;
936 state.StuckTimer = 0.0f;
937 state.ProgressInitialized = true;
938
939 if (!found)
940 continue;
941 }
942 else
943 {
944 // Retry failed paths periodically.
945 // Also refresh active routes at a controlled rate.
946 state.RepathTimer +=
947 std::max(deltaTime, 0.0f);
948
949 if (state.RepathTimer >= std::max(component.RepathInterval, 0.05f))
950 {
951 state.RepathTimer = 0.0f;
952
953 if (state.PathQueryFailed)
954 {
955 const bool found =
956 state.Agent.SetDestination(
957 *m_NavigationSystem,
958 currentPosition,
959 component.Destination);
960
961 state.PathQueryFailed = !found;
962
963 if (!found)
964 continue;
965 }
966 else if (!state.Agent.HasReachedDestination())
967 {
968 const bool found =
969 state.Agent.RecalculatePath(
970 *m_NavigationSystem,
971 currentPosition);
972
973 // The previous path is retained by
974 // RecalculatePath() on failure.
975 // Do not follow it blindly.
976 if (!found)
977 {
978 state.Agent.Stop();
979 state.PathQueryFailed = true;
980 continue;
981 }
982 }
983 }
984 }
985
986 if (state.PathQueryFailed)
987 continue;
988
989 if (state.Agent.HasReachedDestination())
990 {
991 component.HasDestination = false;
992 state.HasRequestedDestination = false;
993 continue;
994 }
995
996 const glm::vec3 movement =
997 state.Agent.Update(
998 currentPosition,
999 deltaTime);
1000
1001 if (glm::dot(movement, movement) > 0.0000001f)
1002 {
1003 glm::mat4 movedWorld = worldTransform;
1004
1005 glm::vec3 moveDirection = movement;
1006 moveDirection.y = 0.0f;
1007
1008 const float moveLength = glm::length(moveDirection);
1009 if (moveLength > 0.0001f)
1010 {
1011 moveDirection /= moveLength;
1012
1013 // Perception considers -Z the forward axis.
1014 glm::vec3 forward = -glm::vec3(worldTransform[2]);
1015 forward.y = 0.0f;
1016
1017 const float forwardLength = glm::length(forward);
1018 if (forwardLength > 0.0001f)
1019 {
1020 forward /= forwardLength;
1021
1022 const float dotValue = glm::clamp(
1023 glm::dot(forward, moveDirection),
1024 -1.0f, 1.0f);
1025
1026 const float crossY =
1027 glm::cross(forward, moveDirection).y;
1028
1029 const float angle = std::atan2(crossY, dotValue);
1030 const float maxRotation =
1031 glm::radians(360.0f) * std::max(deltaTime, 0.0f);
1032
1033 const float rotationStep = glm::clamp(
1034 angle, -maxRotation, maxRotation);
1035
1036 const glm::mat4 rotationDelta = glm::rotate(
1037 glm::mat4(1.0f),
1038 rotationStep,
1039 glm::vec3(0.0f, 1.0f, 0.0f));
1040
1041 movedWorld = rotationDelta * worldTransform;
1042 }
1043 }
1044
1045 // Rotate around the agent, not around the world origin.
1046 movedWorld[3] =
1047 worldTransform[3] + glm::vec4(movement, 0.0f);
1048
1049 SetWorldTransform(entity, movedWorld);
1050 }
1051
1052 if (state.Agent.HasReachedDestination())
1053 {
1054 component.HasDestination = false;
1055 state.HasRequestedDestination = false;
1056 }
1057 }
1058 }
1059 // -----------------------------------------------------
1060 // V1.8 AI Perception
1061 // -----------------------------------------------------
1062
1063 UpdatePerception(deltaTime);
1064
1065 // -----------------------------------------------------
1066 // V1.6 CPU Particle Simulation
1067 // -----------------------------------------------------
1068
1069 for (auto& [handle, data] :
1070 m_Entities)
1071 {
1072 if (!data.ParticleSystem)
1073 continue;
1074
1075 auto& settings =
1076 *data.ParticleSystem;
1077
1078 auto& state =
1079 m_ParticleStates[
1080 handle];
1081
1082 for (auto& p :
1083 state.Particles)
1084 {
1085 p.Age +=
1086 deltaTime;
1087
1088 p.Velocity +=
1089 settings.Gravity *
1090 deltaTime;
1091
1092 p.Position +=
1093 p.Velocity *
1094 deltaTime;
1095
1096 const float t =
1097 glm::clamp(
1098 p.Age /
1099 std::max(
1100 p.Lifetime,
1101 0.01f),
1102 0.0f,
1103 1.0f);
1104
1105 p.Color =
1106 glm::mix(
1107 p.StartColor,
1108 p.EndColor,
1109 t);
1110
1111 p.Size =
1112 glm::mix(
1113 p.StartSize,
1114 p.StartSize *
1115 std::max(
1116 settings
1117 .EndSizeMultiplier,
1118 0.0f),
1119 t);
1120 }
1121
1122 std::erase_if(
1123 state.Particles,
1124 [](const RuntimeParticle& p)
1125 {
1126 return
1127 p.Age >=
1128 p.Lifetime;
1129 });
1130
1131 if (!settings.Playing)
1132 continue;
1133
1134 state.Elapsed +=
1135 deltaTime;
1136
1137 const bool emitting =
1138 settings.Loop ||
1139 state.Elapsed <=
1140 std::max(
1141 settings.Duration,
1142 0.0f);
1143
1144 if (!emitting)
1145 continue;
1146
1147 const float rate =
1148 std::max(
1149 settings.EmissionRate,
1150 0.0f);
1151
1152 state.SpawnAccumulator +=
1153 rate *
1154 deltaTime;
1155
1156 std::uint32_t spawnCount =
1157 static_cast<
1158 std::uint32_t>(
1159 state.SpawnAccumulator);
1160
1161 state.SpawnAccumulator -=
1162 static_cast<float>(
1163 spawnCount);
1164
1165 const glm::mat4 world =
1167 Entity(
1168 handle,
1169 this));
1170
1171 const glm::vec3 origin(
1172 world[3]);
1173
1174 glm::vec3 direction =
1175 settings.Direction;
1176
1177 if (glm::length(
1178 direction) <
1179 0.0001f)
1180 {
1181 direction =
1182 {
1183 0.0f,
1184 1.0f,
1185 0.0f
1186 };
1187 }
1188
1189 direction =
1190 glm::normalize(
1191 glm::mat3(world) *
1192 glm::normalize(
1193 direction));
1194
1195 while (
1196 spawnCount-- > 0 &&
1197 state.Particles.size() <
1198 settings.MaxParticles)
1199 {
1200 auto random01 =
1201 [&state]()
1202 {
1203 state.Seed =
1204 state.Seed *
1205 1664525u +
1206 1013904223u;
1207
1208 return
1209 static_cast<float>(
1210 (state.Seed >>
1211 8) &
1212 0x00FFFFFFu) /
1213 static_cast<float>(
1214 0x01000000u);
1215 };
1216
1217 auto signedRandom =
1218 [&]()
1219 {
1220 return
1221 random01() *
1222 2.0f -
1223 1.0f;
1224 };
1225
1227
1228 glm::vec3 spawnOffset{
1229 0.0f
1230 };
1231
1232 glm::vec3 spawnDirection =
1233 direction;
1234
1235 if (settings.Shape ==
1237 {
1238 glm::vec3 r{
1239 signedRandom(),
1240 signedRandom(),
1241 signedRandom()
1242 };
1243
1244 if (glm::length(r) <
1245 0.0001f)
1246 {
1247 r =
1248 {
1249 0.0f,
1250 1.0f,
1251 0.0f
1252 };
1253 }
1254
1255 r =
1256 glm::normalize(r);
1257
1258 const float radius =
1259 std::max(
1260 settings
1261 .ShapeRadius,
1262 0.0f) *
1263 std::cbrt(
1264 random01());
1265
1266 spawnOffset =
1267 r *
1268 radius;
1269
1270 spawnDirection =
1271 r;
1272 }
1273 else if (
1274 settings.Shape ==
1276 {
1277 glm::vec3 tangent =
1278 std::abs(
1279 direction.y) <
1280 0.99f
1281 ? glm::normalize(
1282 glm::cross(
1283 direction,
1284 glm::vec3(
1285 0,
1286 1,
1287 0)))
1288 : glm::vec3(
1289 1,
1290 0,
1291 0);
1292
1293 const glm::vec3
1294 bitangent =
1295 glm::normalize(
1296 glm::cross(
1297 direction,
1298 tangent));
1299
1300 const float angle =
1301 glm::radians(
1302 glm::clamp(
1303 settings.ConeAngle,
1304 0.0f,
1305 89.0f));
1306
1307 const float radial =
1308 std::tan(angle) *
1309 std::sqrt(
1310 random01());
1311
1312 const float phi =
1313 random01() *
1314 glm::two_pi<
1315 float>();
1316
1317 spawnDirection =
1318 glm::normalize(
1319 direction +
1320 tangent *
1321 (std::cos(
1322 phi) *
1323 radial) +
1324 bitangent *
1325 (std::sin(
1326 phi) *
1327 radial));
1328 }
1329
1330 const float lifetimeScale =
1331 1.0f +
1332 signedRandom() *
1333 glm::clamp(
1334 settings
1335 .LifetimeRandom,
1336 0.0f,
1337 1.0f);
1338
1339 const float speedScale =
1340 1.0f +
1341 signedRandom() *
1342 glm::clamp(
1343 settings
1344 .SpeedRandom,
1345 0.0f,
1346 1.0f);
1347
1348 const float sizeScale =
1349 1.0f +
1350 signedRandom() *
1351 glm::clamp(
1352 settings
1353 .SizeRandom,
1354 0.0f,
1355 1.0f);
1356
1357 p.Position =
1358 origin +
1359 spawnOffset;
1360
1361 p.Velocity =
1362 spawnDirection *
1363 settings.StartSpeed *
1364 speedScale;
1365
1366 p.Lifetime =
1367 std::max(
1368 settings
1369 .StartLifetime *
1370 lifetimeScale,
1371 0.01f);
1372
1373 p.StartSize =
1374 std::max(
1375 settings
1376 .StartSize *
1377 sizeScale,
1378 0.001f);
1379
1380 p.Size =
1381 p.StartSize;
1382
1383 p.StartColor =
1384 settings.StartColor;
1385
1386 p.EndColor =
1387 settings.EndColor;
1388
1389 p.Color =
1390 p.StartColor;
1391
1392 state.Particles
1393 .push_back(p);
1394 }
1395 }
1396
1397 // -----------------------------------------------------
1398 // Spatial Audio
1399 // -----------------------------------------------------
1400
1401 // First enabled AudioListener is authoritative.
1402 for (auto& [handle, data] :
1403 m_Entities)
1404 {
1405 if (!data.AudioListener ||
1406 !data.AudioListener
1407 ->Enabled)
1408 {
1409 continue;
1410 }
1411
1412 const glm::mat4 world =
1414 Entity(
1415 handle,
1416 this));
1417
1418 const glm::vec3 position(
1419 world[3]);
1420
1421 const glm::vec3 forward =
1422 glm::normalize(
1423 -glm::vec3(
1424 world[2]));
1425
1426 const glm::vec3 up =
1427 glm::normalize(
1428 glm::vec3(
1429 world[1]));
1430
1432 position,
1433 forward,
1434 up);
1435
1436 break;
1437 }
1438
1439 for (auto& [handle, data] :
1440 m_Entities)
1441 {
1442 if (!data.AudioSource)
1443 continue;
1444
1445 const glm::mat4 world =
1447 Entity(
1448 handle,
1449 this));
1450
1452 handle,
1453 *data.AudioSource,
1454 glm::vec3(
1455 world[3]));
1456 }
1457
1458 // -----------------------------------------------------
1459 // Native Scripts
1460 // -----------------------------------------------------
1461
1462 // Snapshot handles because scripts can create/destroy
1463 // entities during update.
1464 std::vector<std::uint32_t>
1465 handles;
1466
1467 handles.reserve(
1468 m_Entities.size());
1469
1470 for (const auto& [handle, data] :
1471 m_Entities)
1472 {
1473 (void)data;
1474
1475 handles.push_back(
1476 handle);
1477 }
1478
1479 for (const auto handle : handles)
1480 {
1481 if (!IsValid(handle)) continue;
1482 // Recreate on component changes to keep script pointers valid.
1483 // Editor normally changes script configuration outside Play.
1484 CreateScriptInstance(handle);
1485 auto it = m_ScriptInstances.find(handle);
1486 if (it == m_ScriptInstances.end()) continue;
1487 auto& data = m_Entities.at(handle);
1488 std::vector<NativeScriptComponent*> components;
1489 if (data.NativeScript && data.NativeScript->Enabled)
1490 components.push_back(&*data.NativeScript);
1491 for (auto& script : data.AdditionalNativeScripts)
1492 if (script.Enabled) components.push_back(&script);
1493 bool bindingsChanged = components.size() != it->second.size();
1494 if (!bindingsChanged)
1495 for (std::size_t i = 0; i < components.size(); ++i)
1496 if (it->second[i]->m_BoundScript != components[i])
1497 { bindingsChanged = true; break; }
1498 if (bindingsChanged)
1499 {
1500 DestroyScriptInstance(handle);
1501 CreateScriptInstance(handle);
1502 it = m_ScriptInstances.find(handle);
1503 if (it == m_ScriptInstances.end()) continue;
1504 }
1505 // Iterate over a stable index; scripts can remove their own entity.
1506 for (std::size_t i = 0; i < components.size(); ++i)
1507 {
1508 if (!IsValid(handle)) break;
1509 auto current = m_ScriptInstances.find(handle);
1510 if (current == m_ScriptInstances.end() || i >= current->second.size()) break;
1511 auto* instance = current->second[i].get();
1512 auto* component = components[i];
1513 if (!instance || !component) continue;
1514 ScriptRegistry::ApplyFieldsToInstance(*component, *instance);
1515 instance->OnUpdate(deltaTime);
1516 if (IsValid(handle) && m_ScriptInstances.contains(handle))
1517 ScriptRegistry::ReadFieldsFromInstance(*component, *instance);
1518 }
1519 }
1520 }
1521
1523 Entity entity)
1524 {
1525 if (!entity ||
1526 entity.m_Scene != this)
1527 {
1528 return {};
1529 }
1530
1531 const auto parent =
1532 entity.GetComponent<
1534 .Parent;
1535
1536 return
1537 IsValid(parent)
1538 ? Entity(
1539 parent,
1540 this)
1541 : Entity{};
1542 }
1543
1544 std::vector<Entity>
1546 Entity entity)
1547 {
1548 std::vector<Entity> result;
1549
1550 if (!entity ||
1551 entity.m_Scene != this)
1552 {
1553 return result;
1554 }
1555
1556 for (const auto handle :
1557 entity.GetComponent<
1559 .Children)
1560 {
1561 if (IsValid(handle))
1562 {
1563 result.emplace_back(
1564 handle,
1565 this);
1566 }
1567 }
1568
1569 return result;
1570 }
1571
1573 Entity possibleDescendant,
1574 Entity ancestor) const
1575 {
1576 if (!possibleDescendant ||
1577 !ancestor)
1578 {
1579 return false;
1580 }
1581
1582 std::uint32_t current =
1583 possibleDescendant
1584 .m_Handle;
1585
1586 while (IsValid(current))
1587 {
1588 const auto parent =
1589 m_Entities
1590 .at(current)
1591 .Relationship
1592 .Parent;
1593
1594 if (parent ==
1595 ancestor.m_Handle)
1596 {
1597 return true;
1598 }
1599
1600 if (parent == 0)
1601 break;
1602
1603 current =
1604 parent;
1605 }
1606
1607 return false;
1608 }
1609
1611 Entity child,
1612 Entity parent,
1613 bool keepWorldTransform)
1614 {
1615 if (!child ||
1616 !parent ||
1617 child.m_Scene != this ||
1618 parent.m_Scene != this ||
1619 child == parent ||
1621 parent,
1622 child))
1623 {
1624 return false;
1625 }
1626
1627 const glm::mat4 oldWorld =
1628 keepWorldTransform
1630 child)
1631 : glm::mat4(
1632 1.0f);
1633
1634 auto& childRelationship =
1635 child.GetComponent<
1637
1638 if (childRelationship.Parent !=
1639 0 &&
1640 IsValid(
1641 childRelationship
1642 .Parent))
1643 {
1644 auto& oldChildren =
1645 m_Entities
1646 .at(
1647 childRelationship
1648 .Parent)
1649 .Relationship
1650 .Children;
1651
1652 std::erase(
1653 oldChildren,
1654 child.m_Handle);
1655 }
1656
1657 childRelationship.Parent =
1658 parent.m_Handle;
1659
1660 auto& children =
1661 parent.GetComponent<
1663 .Children;
1664
1665 if (std::find(
1666 children.begin(),
1667 children.end(),
1668 child.m_Handle) ==
1669 children.end())
1670 {
1671 children.push_back(
1672 child.m_Handle);
1673 }
1674
1675 if (keepWorldTransform)
1676 {
1678 child,
1679 oldWorld);
1680 }
1681
1682 return true;
1683 }
1684
1686 Entity child,
1687 bool keepWorldTransform)
1688 {
1689 if (!child ||
1690 child.m_Scene != this)
1691 {
1692 return;
1693 }
1694
1695 auto& relationship =
1696 child.GetComponent<
1698
1699 if (relationship.Parent == 0)
1700 return;
1701
1702 const glm::mat4 oldWorld =
1703 keepWorldTransform
1705 child)
1706 : glm::mat4(
1707 1.0f);
1708
1709 if (IsValid(
1710 relationship.Parent))
1711 {
1712 auto& siblings =
1713 m_Entities
1714 .at(
1715 relationship
1716 .Parent)
1717 .Relationship
1718 .Children;
1719
1720 std::erase(
1721 siblings,
1722 child.m_Handle);
1723 }
1724
1725 relationship.Parent = 0;
1726
1727 if (keepWorldTransform)
1728 {
1729 child.GetComponent<
1731 TransformFromMatrix(
1732 oldWorld);
1733 }
1734 }
1735
1737 Entity entity) const
1738 {
1739 if (!entity ||
1740 entity.m_Scene != this)
1741 {
1742 return glm::mat4(
1743 1.0f);
1744 }
1745
1746 const auto& data =
1747 m_Entities.at(
1748 entity.m_Handle);
1749
1750 const glm::mat4 local =
1751 data.Transform
1752 .GetTransform();
1753
1754 const auto parent =
1755 data.Relationship.Parent;
1756
1757 if (parent == 0 ||
1758 !IsValid(parent))
1759 {
1760 return local;
1761 }
1762
1763 return
1765 Entity(
1766 parent,
1767 const_cast<
1768 Scene*>(this))) *
1769 local;
1770 }
1771
1773 Entity entity,
1774 const glm::mat4& worldTransform)
1775 {
1776 if (!entity ||
1777 entity.m_Scene != this)
1778 {
1779 return;
1780 }
1781
1782 const auto parent =
1783 entity.GetComponent<
1785 .Parent;
1786
1787 glm::mat4 local =
1788 worldTransform;
1789
1790 if (parent != 0 &&
1791 IsValid(parent))
1792 {
1793 const glm::mat4 parentWorld =
1795 Entity(
1796 parent,
1797 this));
1798
1799 local =
1800 glm::inverse(
1801 parentWorld) *
1802 worldTransform;
1803 }
1804
1805 entity.GetComponent<
1807 TransformFromMatrix(
1808 local);
1809 }
1810}
Animation declarations for the Animation subsystem.
AudioEngine declarations for the Audio subsystem.
BTGameplay declarations for the Behavior Trees subsystem.
IspatialQuery declarations for the Perception subsystem.
Built-in gameplay scripts and neural agent examples.
NavigationSystem declarations for the Navigation subsystem.
Scene declarations for the Scenes and Native Scripting subsystem.
static bool Init()
static bool Play(std::uint32_t entityHandle, const AudioSourceComponent &source, const glm::vec3 &position=glm::vec3(0.0f))
static void StopAll()
static void SetListener(const glm::vec3 &position, const glm::vec3 &forward, const glm::vec3 &up, const glm::vec3 &velocity=glm::vec3(0.0f))
static void Update(std::uint32_t entityHandle, const AudioSourceComponent &source, const glm::vec3 &position=glm::vec3(0.0f), const glm::vec3 &velocity=glm::vec3(0.0f))
bool HasCondition(std::string_view name) const
bool HasAction(std::string_view name) const
Entity()=default
T & GetComponent()
Definition Scene.h:851
float & Speed()
Definition NavAgent.h:63
float & StoppingDistance()
Definition NavAgent.h:73
std::optional< LastSeenTargetInfo > GetLastSeenTarget(std::uint32_t observerHandle) const
Definition Scene.cpp:541
ScriptableEntity * FindRuntimeScript(std::uint32_t entityHandle, const std::string &scriptName) const
Definition Scene.cpp:317
std::unique_ptr< Scene > Copy() const
Definition Scene.cpp:98
std::vector< Entity > GetEntities()
Definition Scene.cpp:231
bool SetParent(Entity child, Entity parent, bool keepWorldTransform=true)
Definition Scene.cpp:1610
glm::mat4 GetWorldTransform(Entity entity) const
Definition Scene.cpp:1736
bool IsDescendant(Entity possibleDescendant, Entity ancestor) const
Definition Scene.cpp:1572
void Unparent(Entity child, bool keepWorldTransform=true)
Definition Scene.cpp:1685
std::optional< AIDebugStateInfo > GetAIDebugState(std::uint32_t entityHandle) const
Definition Scene.cpp:251
friend class Entity
Definition Scene.h:824
Entity GetParent(Entity entity)
Definition Scene.cpp:1522
void SetWorldTransform(Entity entity, const glm::mat4 &worldTransform)
Definition Scene.cpp:1772
const std::vector< RuntimeParticle > & GetParticles(std::uint32_t handle) const
Definition Scene.cpp:391
std::vector< Entity > GetChildren(Entity entity)
Definition Scene.cpp:1545
Entity CreateEntity(const std::string &name="Entity")
Definition Scene.cpp:133
void RegisterEntityBehaviorTreeBindings(std::uint32_t entityHandle, BTNativeRegistry &registry) const
Definition Scene.cpp:327
void OnUpdate(float deltaTime)
Definition Scene.cpp:744
void DestroyEntity(Entity entity)
Definition Scene.cpp:161
std::optional< BTDebugInfo > GetBehaviorTreeDebug(std::uint32_t entityHandle) const
Definition Scene.cpp:355
bool IsValid(std::uint32_t handle) const
Definition Scene.cpp:221
void OnRuntimeStop()
Definition Scene.cpp:483
void OnRuntimeStart()
Definition Scene.cpp:409
void RestoreFrom(const Scene &other)
Definition Scene.cpp:105
std::vector< PerceptionTargetInfo > GetPerceivedTargets(std::uint32_t observerHandle) const
Definition Scene.cpp:506
static void ApplyDefaults(NativeScriptComponent &component)
static const ScriptDefinition * Find(const std::string &name)
static void ReadFieldsFromInstance(NativeScriptComponent &component, const Script &instance)
static void ApplyFieldsToInstance(const NativeScriptComponent &component, Script &instance)
Base class for native gameplay scripts instantiated while a scene runs.
constexpr LayerMask Bit(std::uint32_t layer)
Definition Components.h:54
void RegisterBuiltinScripts()
std::uint32_t LayerMask
Definition Components.h:37
void RegisterBTAssetAgent()
Definition BTGameplay.h:281
std::uint64_t ID
Definition Components.h:25
std::vector< std::uint32_t > Children
Definition Components.h:101
std::vector< Transition > History
Definition Scene.h:60
std::vector< Event > Events
Definition Scene.h:68
std::optional< glm::vec3 > TargetPosition
Definition Scene.h:72
std::uint64_t BlackboardRevision
Definition Scene.h:70
std::vector< BTBlackboard::DebugEntry > BlackboardEntries
Definition Scene.h:69
std::optional< std::uint32_t > TargetHandle
Definition Scene.h:71
std::vector< Node > Nodes
Definition Scene.h:66
std::string Tag
Definition Components.h:30