2026-08-25 22:10:54 +01:00
|
|
|
#include "HydraLightSpawnerActor.h"
|
|
|
|
|
#include "../../ecs/components/HydraPositionComponent.h"
|
|
|
|
|
#include "../../ecs/components/HydraTickComponent.h"
|
|
|
|
|
#include "../../ecs/HydraECS.h"
|
|
|
|
|
#include "../../engine/HydraEngine.h"
|
|
|
|
|
#include "../../actor/HydraActorManager.h"
|
|
|
|
|
#include "HydraSpawnedLightActor.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void HydraLightSpawnerActor::FixedTick(float delta_t)
|
|
|
|
|
{
|
|
|
|
|
if(m_enabled)
|
|
|
|
|
{
|
|
|
|
|
std::chrono::time_point<std::chrono::steady_clock> current_tick = std::chrono::steady_clock::now();
|
|
|
|
|
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(current_tick - m_last_tick);
|
|
|
|
|
long elapsed_milli_seconds = elapsed.count();
|
|
|
|
|
if(elapsed_milli_seconds >= (m_interval * 1000.0f))
|
|
|
|
|
{
|
|
|
|
|
HydraEngine* engine = GetEngine();
|
|
|
|
|
|
|
|
|
|
HydraPositionComponent pos_comp =engine->ECS()->GetComponent<HydraPositionComponent>(GetID());
|
|
|
|
|
HydraActorManager* actor_manager = engine->ActorManager();
|
|
|
|
|
HydraID actor_id = actor_manager->CreateActor<HydraSpawnedLightActor>();
|
|
|
|
|
actor_manager->InitialiseActor(actor_id);
|
|
|
|
|
actor_manager->SetPosition(actor_id, pos_comp.position);
|
|
|
|
|
actor_manager->SetLinearVelocity(actor_id, m_spawn_direction * m_spawn_velocity);
|
2026-08-28 16:36:25 +01:00
|
|
|
SpawnedActor actor = {};
|
|
|
|
|
actor.actor_id = actor_id;
|
|
|
|
|
actor.spawned_time = current_tick;
|
|
|
|
|
m_spawned_actors.push(actor);
|
|
|
|
|
m_last_tick = current_tick;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(m_spawned_actors.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
SpawnedActor actor = m_spawned_actors.front();
|
|
|
|
|
long actor_spawned_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(current_tick - actor.spawned_time).count();
|
|
|
|
|
if(actor_spawned_time_ms > (m_spawn_duration * 1000.0f ))
|
|
|
|
|
{
|
|
|
|
|
GetEngine()->ActorManager()->DeleteActor(actor.actor_id);
|
|
|
|
|
m_spawned_actors.pop();
|
|
|
|
|
}
|
2026-08-25 22:10:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-08-28 16:36:25 +01:00
|
|
|
|
|
|
|
|
|
2026-08-25 22:10:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HydraLightSpawnerActor::_CreatePosition()
|
|
|
|
|
{
|
|
|
|
|
HydraECS *ecs = GetEngine()->ECS();
|
|
|
|
|
HydraPositionComponent position_component;
|
|
|
|
|
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HydraLightSpawnerActor::_CreateTick()
|
|
|
|
|
{
|
|
|
|
|
HydraECS *ecs = GetEngine()->ECS();
|
|
|
|
|
HydraTickComponent tick_component;
|
|
|
|
|
tick_component.entity_id = GetID();
|
|
|
|
|
tick_component.fixed = true;
|
|
|
|
|
ecs->AddComponent<HydraTickComponent>(GetID(), tick_component);
|
|
|
|
|
}
|
|
|
|
|
void HydraLightSpawnerActor::InitialiseComponents()
|
|
|
|
|
{
|
|
|
|
|
_CreatePosition();
|
|
|
|
|
_CreateTick();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HydraLightSpawnerActor::SetEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
m_enabled = enabled;
|
|
|
|
|
if(enabled == true)
|
|
|
|
|
{
|
|
|
|
|
m_last_tick = std::chrono::steady_clock::now();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HydraLightSpawnerActor::SpawnSettings(float spawns_per_second,
|
|
|
|
|
glm::vec3 spawn_direction,
|
|
|
|
|
glm::vec3 dir_variation,
|
|
|
|
|
float spawn_velocity,
|
|
|
|
|
float velocity_variation,
|
|
|
|
|
float spawn_duration)
|
|
|
|
|
{
|
|
|
|
|
m_spawns_per_second = spawns_per_second;
|
|
|
|
|
m_spawn_direction = spawn_direction;
|
|
|
|
|
m_dir_variation = dir_variation;
|
|
|
|
|
m_spawn_velocity = spawn_velocity;
|
|
|
|
|
m_velocity_variation = velocity_variation;
|
|
|
|
|
m_spawn_duration = spawn_duration;
|
|
|
|
|
m_interval = 1.0f / spawns_per_second;
|
|
|
|
|
}
|