feat: implement multithreading for collision resolution and ball updates

This commit is contained in:
Florian Sylvain
2025-05-11 06:35:47 +02:00
parent d1c4f36963
commit c58a2cead2
8 changed files with 182 additions and 29 deletions
+4 -1
View File
@@ -125,6 +125,9 @@ void Ball::handleWallCollision(const sf::Vector2f& windowSize) {
}
void Ball::resolveCollision(Ball& other) {
std::lock_guard<std::mutex> lockA(m_mutex);
std::lock_guard<std::mutex> lockB(other.m_mutex);
sf::Vector2f posA = getPosition();
sf::Vector2f posB = other.getPosition();
sf::Vector2f delta = posB - posA;
@@ -143,7 +146,7 @@ void Ball::resolveCollision(Ball& other) {
float vA_n = vA.x * normal.x + vA.y * normal.y;
float vB_n = vB.x * normal.x + vB.y * normal.y;
float restitution = Constants::RESTITUTION;
float restitution = 0.95f;
float vA_n_new = vB_n * restitution;
float vB_n_new = vA_n * restitution;