Physics working

This commit is contained in:
Confideo-IOM
2026-08-24 20:59:24 +01:00
parent 20c0794d10
commit 1253571c17
146 changed files with 4469 additions and 1273 deletions
+40 -4
View File
@@ -24,6 +24,7 @@
#include "../ecs/systems/HydraDirectionalShadowSourceSystem.h"
#include "../ecs/systems/HydraSpotShadowSourceSystem.h"
#include "../ecs/systems/HydraPointShadowSourceSystem.h"
#include "../ecs/systems/HydraPhysicsSystem.h"
#include "../ecs/components/HydraPositionComponent.h"
#include "../ecs/components/HydraMeshComponent.h"
@@ -34,6 +35,7 @@
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
#include "../ecs/components/HydraSpotShadowSourceComponent.h"
#include "../ecs/components/HydraPointShadowSourceComponent.h"
#include "../ecs/components/HydraPhysicsComponent.h"
#include "../camera/HydraCamera.h"
@@ -59,7 +61,7 @@
#include "../task/buffer/HydraInitialiseTextureManagerTask.hpp"
#include "../task/buffer/HydraInitialiseShadowBufferTask.hpp"
#include "../task/actor/HydraUpdatePlayerTask.h"
#include "../task/physics/HydraStepPhysicsTask.h"
#include "../task/renderer/HydraEndRenderTask.hpp"
#include "../mesh/HydraMeshManager.h"
@@ -197,6 +199,7 @@ void HydraEngine::_CreateManagers()
m_material_buffer_manager = new HydraMaterialBufferManager();
m_light_buffer_manager = new HydraLightBufferManager();
m_shadow_buffer_manager = new HydraShadowBufferManager();
}
void HydraEngine::_InitialiseManagers()
@@ -234,6 +237,7 @@ void HydraEngine::_InitialiseSystems()
m_ecs->RegisterComponentType<HydraDirectionalShadowSourceComponent>();
m_ecs->RegisterComponentType<HydraSpotShadowSourceComponent>();
m_ecs->RegisterComponentType<HydraPointShadowSourceComponent>();
m_ecs->RegisterComponentType<HydraPhysicsComponent>();
m_mesh_system = m_ecs->RegisterSystem<HydraMeshSystem>();
m_transform_system = m_ecs->RegisterSystem<HydraTransformSystem>();
@@ -243,7 +247,7 @@ void HydraEngine::_InitialiseSystems()
m_directional_shadow_system = m_ecs->RegisterSystem<HydraDirectionalShadowSourceSystem>();
m_spot_shadow_system = m_ecs->RegisterSystem<HydraSpotShadowSourceSystem>();
m_point_shadow_system = m_ecs->RegisterSystem<HydraPointShadowSourceSystem>();
m_physics_system = m_ecs->RegisterSystem<HydraPhysicsSystem>();
HydraSignature mesh_sig;
HydraSignature trans_sig;
@@ -253,6 +257,7 @@ void HydraEngine::_InitialiseSystems()
HydraSignature directional_shadow_sig;
HydraSignature spot_shadow_sig;
HydraSignature point_shadow_sig;
HydraSignature physics_sig;
mesh_sig.set(m_ecs->GetComponentType<HydraMeshComponent>(),true);
trans_sig.set(m_ecs->GetComponentType<HydraPositionComponent>(),true);
@@ -274,6 +279,9 @@ void HydraEngine::_InitialiseSystems()
point_shadow_sig.set(m_ecs->GetComponentType<HydraPositionComponent>(), true);
point_shadow_sig.set(m_ecs->GetComponentType<HydraPointShadowSourceComponent>(), true);
physics_sig.set(m_ecs->GetComponentType<HydraPhysicsComponent>(), true);
physics_sig.set(m_ecs->GetComponentType<HydraPositionComponent>(), true);
m_ecs->SetSystemSignature<HydraMeshSystem>(mesh_sig);
m_ecs->SetSystemSignature<HydraTransformSystem>(trans_sig);
m_ecs->SetSystemSignature<HydraRenderSystem>(render_sig);
@@ -282,11 +290,16 @@ void HydraEngine::_InitialiseSystems()
m_ecs->SetSystemSignature<HydraDirectionalShadowSourceSystem>(directional_shadow_sig);
m_ecs->SetSystemSignature<HydraSpotShadowSourceSystem>(spot_shadow_sig);
m_ecs->SetSystemSignature<HydraPointShadowSourceSystem>(point_shadow_sig);
m_ecs->SetSystemSignature<HydraPhysicsSystem>(physics_sig);
}
void HydraEngine::_UpdateSystems()
{
//Update physics system with any changes from the transform system
m_physics_system->Update(m_delta_t);
HydraID posUpdateBarrierID = m_task_scheduler->CreateBarrier();
HydraID update_trans_id = m_task_scheduler->CreateTask<HydraUpdateSystemTask>(HydraThreadAffinity::General, posUpdateBarrierID);
@@ -377,15 +390,16 @@ void HydraEngine::_GameLoop()
m_delta_t = diff.count();
float fixed_delta_t = fixed_diff.count();
if (fixed_delta_t > 0.016666666666f)
{
m_fixed_delta_t = fixed_diff.count();
last_fixed_tick = this_tick;
fixed_tick = true;
HydraID processInputID = m_task_scheduler->CreateTask<HydraProcessInputTask>(HydraThreadAffinity::Render, barrierID);
m_task_scheduler->StartTask(processInputID);
//Physics here
m_physics_system->StepPhysics(fixed_delta_t);
}
if (fpsFrameCount >= 15)
{
@@ -399,12 +413,24 @@ void HydraEngine::_GameLoop()
last_tick = this_tick;
fpsFrameCount++;
HydraID processInputID = m_task_scheduler->CreateTask<HydraProcessInputTask>(HydraThreadAffinity::Render, barrierID);
HydraProcessInputTask* m_input_task = static_cast<HydraProcessInputTask*>(m_task_scheduler->GetTask(processInputID));
m_input_task->Initialise(fixed_tick);
m_task_scheduler->StartTask(processInputID);
HydraID initialise_components_id = m_task_scheduler->CreateTask<HydraInitialiseComponentsTask>(HydraThreadAffinity::General, barrierID);
HydraID update_player_task_id = m_task_scheduler->CreateTask<HydraUpdatePlayerTask>(HydraThreadAffinity::General, barrierID);
m_task_scheduler->StartTask(initialise_components_id);
m_task_scheduler->StartTask(update_player_task_id);
m_task_scheduler->WaitForBarrier(barrierID);
if(fixed_tick)
{
m_game->FixedUpdate(m_delta_t);
}
m_game->Update(m_delta_t);
_UpdateSystems();
@@ -466,6 +492,16 @@ bool HydraEngine::KeyPressed(HYDRA_KEY_CODES key)
return m_input_manager->KeyPressed(key);
}
bool HydraEngine::KeyUp(HYDRA_KEY_CODES key)
{
return m_input_manager->KeyUp(key);
}
bool HydraEngine::KeyDown(HYDRA_KEY_CODES key)
{
return m_input_manager->KeyDown(key);
}
glm::vec2 HydraEngine::MouseChange()
{
return m_input_manager->MouseChange();