MCPcopy Create free account
hub / github.com/Illation/ETEngine / Process

Method Process

Projects/Demo/source/Runtime/SpawnSystem.cpp:33–72  ·  view source on GitHub ↗

------------------------------ SpawnSystem::Process Spawn upon user input

Source from the content-addressed store, hash-verified

31// Spawn upon user input
32//
33void SpawnSystem::Process(fw::ComponentRange<SpawnSystemView>& range)
34{
35 if (!(core::InputManager::GetInstance()->GetMouseButton(E_MouseButton::Right) >= E_KeyState::Down))
36 {
37 return;
38 }
39
40 // common variables
41 fw::EcsCommandBuffer& cb = GetCommandBuffer();
42 float const dt = core::ContextManager::GetInstance()->GetActiveContext()->time->DeltaTime();
43
44 for (SpawnSystemView& view : range)
45 {
46 view.spawner->cooldown -= dt;
47 if (view.spawner->cooldown <= 0.f)
48 {
49 view.spawner->cooldown = view.spawner->interval;
50
51 fw::T_EntityId const spawned = cb.AddEntity();
52
53 vec3 const& dir = view.transform->GetForward();
54
55 fw::TransformComponent tf;
56 tf.SetPosition(view.transform->GetWorldPosition() + dir * view.spawner->scale);
57 tf.SetScale(vec3(view.spawner->scale));
58
59 fw::RigidBodyComponent rb(true, view.spawner->mass, view.spawner->collisionShape);
60
61 fw::ModelComponent model(view.spawner->mesh, view.spawner->material);
62
63 cb.AddComponents(spawned, tf, model, rb);
64
65 vec3 const impulse = dir * view.spawner->impulse;
66 cb.OnMerge(spawned, fw::EcsCommandBuffer::T_OnMergeFn([impulse](fw::EcsController& ecs, fw::T_EntityId const entity)
67 {
68 ecs.GetComponent<fw::RigidBodyComponent>(entity).ApplyImpulse(impulse);
69 }));
70 }
71 }
72}
73
74
75} // namespace demo

Callers

nothing calls this directly

Calls 9

GetMouseButtonMethod · 0.80
DeltaTimeMethod · 0.80
GetActiveContextMethod · 0.80
SetPositionMethod · 0.80
SetScaleMethod · 0.80
AddComponentsMethod · 0.80
OnMergeMethod · 0.80
ApplyImpulseMethod · 0.80
AddEntityMethod · 0.45

Tested by

no test coverage detected