Physics stuff
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#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);
|
||||
m_last_tick = current_tick;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user