Patch Update - Frustum Culling Thread Independant - V10.2.2

This commit is contained in:
CatChow0 2025-05-08 16:28:27 +02:00
parent f8bfb62e98
commit 644fc57762
3 changed files with 115 additions and 35 deletions

View File

@ -6,10 +6,8 @@
<component name="ChangeListManager">
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/modelclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/modelclass.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -23,13 +21,8 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="cidr-memory-view://4" root0="FORCE_HIGHLIGHTING" />
<setting file="file://C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/d3d11.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/include/Inc/VertexTypes.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/include/Vulkan/Include/vulkan/vulkan_core.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/src/src/shader/CelShadingShader.cpp" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../../IDE_VS/VC/Tools/MSVC/14.38.33130/include/type_traits" root0="SKIP_HIGHLIGHTING" />
@ -46,25 +39,25 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
"C++ Project.enginecustom.executor": "Run",
"C/C++ Project.enginecustom.executor": "dotTrace Profiler",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "main",
"ignore.virus.scanning.warn.message": "true",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "preferences.build.unityPlugin",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;C++ Project.enginecustom.executor&quot;: &quot;Run&quot;,
&quot;C/C++ Project.enginecustom.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.build.unityPlugin&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RunManager" selected="C/C++ Project.enginecustom">
<configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project">
<configuration_1 setup="1">
@ -186,6 +179,7 @@
<workItem from="1746538260893" duration="5781000" />
<workItem from="1746546014271" duration="1814000" />
<workItem from="1746619988287" duration="12282000" />
<workItem from="1746711806997" duration="2620000" />
</task>
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
<option name="closed" value="true" />

View File

@ -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;

View File

@ -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é", __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é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 éviter de surcharger le CPU
std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 Hz
}
Logger::Get().Log("Thread de culling terminé", __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());