Commit 8083146d authored by MrMartinIden's avatar MrMartinIden
Browse files

Merge branch 'feature' into 'master'

Feature

See merge request !103
parents 187c571b 703f3d9f
......@@ -9,5 +9,6 @@ target_link_libraries(client PUBLIC
WFL::MovementSystem
WFL::PhysicsSystem
WFL::UpdateAabbSystem
WFL::CheckCapsuleOnPlatform
enet_static)
add_library(WFL::Client ALIAS client)
......@@ -31,31 +31,32 @@
namespace WFL
{
using tuple = std::tuple<MovementSystem,
UpdateAabbSystemMt,
CheckCapsuleOnPlatform,
PhysicsSystem>;
struct Client {
Client(entt::registry& reg)
: m_systems({ MovementSystem {},
UpdateAabbSystemMt {},
CheckCapsuleOnPlatform {},
PhysicsSystem { reg } })
{
}
void update(entt::registry& reg)
{
std::apply([&](auto&&... args) { (args.update(reg, fixed_dt), ...); }, m_systems);
}
using tuple = std::tuple<MovementSystem,
UpdateAabbSystemMt,
CheckCapsuleOnPlatformMt,
PhysicsSystem>;
PhysicsSystem& get_physics_system()
struct Client
{
return std::get<PhysicsSystem>(m_systems);
}
tuple m_systems;
};
Client(entt::registry &reg) :
m_systems({ MovementSystem{},
UpdateAabbSystemMt{},
CheckCapsuleOnPlatformMt{},
PhysicsSystem{ reg } })
{
}
void update(entt::registry &reg)
{
std::apply([&](auto &&...args) { (args.update(reg, fixed_dt), ...); }, m_systems);
}
PhysicsSystem &get_physics_system()
{
return std::get<PhysicsSystem>(m_systems);
}
tuple m_systems;
};
} // namespace WFL
......@@ -22,6 +22,13 @@ target_include_directories(Printer INTERFACE Printer)
target_link_libraries(Printer INTERFACE glm::glm)
add_library(WFL::Printer ALIAS Printer)
add_library(CheckCapsuleOnPlatform
systems/CheckCapsuleOnPlatform.cpp
systems/CheckCapsuleOnPlatform.hpp)
target_link_libraries(CheckCapsuleOnPlatform PUBLIC Components glm::glm)
add_library(WFL::CheckCapsuleOnPlatform ALIAS CheckCapsuleOnPlatform)
add_library(UpdateAabbSystem INTERFACE)
target_include_directories(UpdateAabbSystem INTERFACE
"systems/UpdateAabbSystem/")
......
......@@ -296,9 +296,10 @@ namespace WFL
const AABB &aabb = m_character_group.get<AABB>(entity);
MortonPrimitive &primCode = m_character_group.get<MortonPrimitive>(entity);
std::cout << glm::to_string(aabb.position()) << '\n';
#ifdef DEBUG_BROADPHASE
std::cout << "compute_codes_character: " << glm::to_string(aabb.position()) << '\n';
#endif
primCode = compute_global_code::generate(offset.m_value, aabb.position());
});
};
......
#include "CheckCapsuleOnPlatform.hpp"
namespace WFL
{
std::mutex s_mutex{};
} // namespace WFL
#pragma once
#include <systems/system.hpp>
#include "system.hpp"
#include <components.hpp>
#include <constraint.hpp>
......@@ -9,22 +9,51 @@
namespace WFL
{
struct CheckCapsuleOnPlatform : BaseSystem<CheckCapsuleOnPlatform>
extern std::mutex s_mutex;
template <bool is_multithreaded>
struct CheckCapsuleOnPlatform : BaseSystem<CheckCapsuleOnPlatform<is_multithreaded>>
{
void update(entt::registry &registry, [[maybe_unused]] float dt = 0)
{
auto view = registry.view<AABB, ConstraintComponent>();
view.each([&](const auto entity, const AABB &capsuleAABB, const ConstraintComponent &constraint) {
auto ent = constraint.m_value;
auto view_aabb = registry.view<AABB>();
auto constraint_view = registry.view<AABB, ConstraintComponent>();
auto func = [&](const entt::entity entity) {
const AABB &capsuleAABB = constraint_view.get<AABB>(entity);
const ConstraintComponent &constraint = constraint_view.get<ConstraintComponent>(entity);
const auto &constraint_entity = constraint.m_value;
auto &aabb = registry.get<AABB>(ent);
auto &aabb = view_aabb.get<AABB>(constraint_entity);
if (!aabb.overlaps(capsuleAABB))
{
registry.remove<ConstraintComponent>(entity);
if constexpr (is_multithreaded)
{
std::lock_guard<std::mutex> guard{ s_mutex };
registry.remove<ConstraintComponent>(entity);
}
else
{
registry.remove<ConstraintComponent>(entity);
}
}
});
};
if constexpr (is_multithreaded)
{
std::for_each(std::execution::par, constraint_view.begin(), constraint_view.end(), func);
}
else
{
std::for_each(std::execution::seq, constraint_view.begin(), constraint_view.end(), func);
}
}
};
using CheckCapsuleOnPlatformMt = CheckCapsuleOnPlatform<true>;
using CheckCapsuleOnPlatformSt = CheckCapsuleOnPlatform<false>;
} // namespace WFL
......@@ -21,7 +21,7 @@ namespace WFL
{
using tuple = std::tuple<MovementSystem,
UpdateAabbSystemMt,
CheckCapsuleOnPlatform,
CheckCapsuleOnPlatformMt,
PhysicsSystem>;
struct Server
......@@ -33,7 +33,7 @@ namespace WFL
m_network_system({}),
m_systems({ MovementSystem{},
UpdateAabbSystemMt{},
CheckCapsuleOnPlatform{},
CheckCapsuleOnPlatformMt{},
PhysicsSystem{ registry } })
{
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment