------------------------------ SpawnSystem::Process Spawn upon user input
| 31 | // Spawn upon user input |
| 32 | // |
| 33 | void 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 |
nothing calls this directly
no test coverage detected