Patch Update - Frustum Culling Thread Independant - V10.2.2
This commit is contained in:
@@ -196,6 +196,12 @@ public :
|
||||
|
||||
private :
|
||||
|
||||
// Thread de culling
|
||||
std::thread m_CullingThread;
|
||||
std::atomic<bool> m_CullingActive;
|
||||
std::mutex m_ObjectsMutex;
|
||||
void CullingThreadFunction();
|
||||
|
||||
|
||||
std::mutex m_TerrainMutex;
|
||||
std::vector<std::tuple<float, float, float, std::string, int>> m_TerrainGenerationData;
|
||||
|
@@ -54,12 +54,18 @@ ApplicationClass::ApplicationClass() : m_ShouldQuit(false)
|
||||
ApplicationClass::~ApplicationClass()
|
||||
{
|
||||
m_ShouldQuit = true;
|
||||
m_CullingActive = false;
|
||||
|
||||
// Joindre le thread pour s'assurer qu'il se termine correctement
|
||||
// Joindre les threads pour s'assurer qu'ils se terminent correctement
|
||||
if (m_PhysicsThread.joinable())
|
||||
{
|
||||
m_PhysicsThread.join();
|
||||
}
|
||||
|
||||
if (m_CullingThread.joinable())
|
||||
{
|
||||
m_CullingThread.join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -468,6 +474,9 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
|
||||
skybox->Initialize(m_Direct3D);
|
||||
m_Skybox.push_back(skybox->ConstructSkybox());
|
||||
|
||||
m_CullingActive = true;
|
||||
m_CullingThread = std::thread(&ApplicationClass::CullingThreadFunction, this);
|
||||
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
@@ -1593,9 +1602,72 @@ void ApplicationClass::SetScreenWidth(int width)
|
||||
m_screenWidth = width;
|
||||
}
|
||||
|
||||
void ApplicationClass::CullingThreadFunction()
|
||||
{
|
||||
Logger::Get().Log("Thread de culling d<>marr<72>", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
|
||||
while (m_CullingActive)
|
||||
{
|
||||
// Construction du frustum une fois par cycle de culling
|
||||
ConstructFrustum();
|
||||
|
||||
// S'assurer que la skybox est toujours visible
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_ObjectsMutex);
|
||||
for (auto* skyboxObject : m_Skybox)
|
||||
{
|
||||
if (skyboxObject)
|
||||
{
|
||||
skyboxObject->SetVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Traitement des files d'objets normaux (sans la skybox)
|
||||
std::vector<std::reference_wrapper<std::vector<Object*>>> queues = {
|
||||
std::ref(m_object), std::ref(m_cubes), std::ref(m_terrainChunk)
|
||||
};
|
||||
|
||||
for (auto& queueRef : queues)
|
||||
{
|
||||
std::vector<Object*>& queue = queueRef.get();
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_ObjectsMutex);
|
||||
|
||||
for (auto* object : queue)
|
||||
{
|
||||
if (!object) continue;
|
||||
|
||||
// Extraction des donn<6E>es de position
|
||||
XMVECTOR position = object->GetPosition();
|
||||
float x = XMVectorGetX(position);
|
||||
float y = XMVectorGetY(position);
|
||||
float z = XMVectorGetZ(position);
|
||||
|
||||
// Calcul du rayon approximatif
|
||||
XMVECTOR scale = object->GetScale();
|
||||
float radius = max(max(XMVectorGetX(scale), XMVectorGetY(scale)), XMVectorGetZ(scale));
|
||||
|
||||
// V<>rification du frustum
|
||||
bool visible = m_FrustumCulling.CheckCube(x, y, z, radius, GetFrustumTolerance());
|
||||
object->SetVisible(visible);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Pause pour <20>viter de surcharger le CPU
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 Hz
|
||||
}
|
||||
|
||||
Logger::Get().Log("Thread de culling termin<69>", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::vector<Object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection)
|
||||
{
|
||||
XMMATRIX worldMatrix, scaleMatrix, rotateMatrix, translateMatrix, srMatrix;
|
||||
std::lock_guard<std::mutex> lock(m_ObjectsMutex);
|
||||
XMMATRIX scaleMatrix, rotateMatrix, translateMatrix ;
|
||||
bool result;
|
||||
|
||||
int renderCount = 0;
|
||||
@@ -1631,21 +1703,29 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
||||
object->UpdatePosition(m_Timer->GetTime());
|
||||
}
|
||||
|
||||
// V<>rifie si l'objet est dans le frustum
|
||||
if (!m_FrustumCulling.CheckCube(x, y, z, radius, GetFrustumTolerance()))
|
||||
|
||||
if (!object->IsVisible())
|
||||
{
|
||||
object->SetVisible(false);
|
||||
continue;
|
||||
}
|
||||
object->SetVisible(true); // L'objet est visible
|
||||
|
||||
// // V<>rifie si l'objet est dans le frustum
|
||||
// if (!m_FrustumCulling.CheckCube(x, y, z, radius, GetFrustumTolerance()))
|
||||
// {
|
||||
// object->SetVisible(false);
|
||||
// continue;
|
||||
// }
|
||||
// object->SetVisible(true); // L'objet est visible
|
||||
renderCount++;
|
||||
|
||||
scaleMatrix = object->GetScaleMatrix();
|
||||
rotateMatrix = object->GetRotateMatrix();
|
||||
translateMatrix = object->GetTranslateMatrix();
|
||||
|
||||
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
||||
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
||||
XMMATRIX worldMatrix = XMMatrixMultiply(
|
||||
XMMatrixMultiply(scaleMatrix, rotateMatrix),
|
||||
translateMatrix
|
||||
);
|
||||
|
||||
object->Render(m_Direct3D->GetDeviceContext());
|
||||
|
||||
|
Reference in New Issue
Block a user