Patch Update - Fix Memory Leak From terrain genneration and use Instancing to generate big terrain - V10.1.3
This commit is contained in:
parent
00e6749d01
commit
8bcd3eed48
23
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
23
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
@ -4,7 +4,13 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="" />
|
||||
<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/assets/Texture/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/object.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/object.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/object.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/object.cpp" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@ -41,19 +47,7 @@
|
||||
<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="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="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://6" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="cidr-memory-view://3" root0="FORCE_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" />
|
||||
@ -208,6 +202,7 @@
|
||||
<workItem from="1746526901276" duration="2023000" />
|
||||
<workItem from="1746536290167" duration="1908000" />
|
||||
<workItem from="1746538260893" duration="5781000" />
|
||||
<workItem from="1746546014271" duration="1490000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
|
||||
<option name="closed" value="true" />
|
||||
|
0
enginecustom/DemoScene_V10.1.2.ker
Normal file
0
enginecustom/DemoScene_V10.1.2.ker
Normal file
@ -4,28 +4,28 @@ Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][Khaotic Engine]
|
||||
Pos=1233,27
|
||||
Size=343,826
|
||||
Pos=1697,27
|
||||
Size=343,1094
|
||||
Collapsed=0
|
||||
DockId=0x00000005,0
|
||||
|
||||
[Window][Objects]
|
||||
Pos=8,27
|
||||
Size=289,826
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
|
||||
[Window][Terrain]
|
||||
Pos=8,27
|
||||
Size=250,826
|
||||
Size=289,547
|
||||
Collapsed=0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Window][Terrain]
|
||||
Pos=8,576
|
||||
Size=289,545
|
||||
Collapsed=0
|
||||
DockId=0x00000008,0
|
||||
|
||||
[Window][Light]
|
||||
Pos=8,27
|
||||
Size=290,866
|
||||
Collapsed=0
|
||||
DockId=0x00000007,1
|
||||
DockId=0x0000000B,1
|
||||
|
||||
[Window][Shader Manager]
|
||||
Pos=8,27
|
||||
@ -37,7 +37,7 @@ DockId=0x00000001,2
|
||||
Pos=8,27
|
||||
Size=289,826
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Window][DockSpace Demo]
|
||||
Size=1584,861
|
||||
@ -47,11 +47,11 @@ Collapsed=0
|
||||
Pos=8,27
|
||||
Size=1559,974
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Window][DockSpace]
|
||||
Pos=0,0
|
||||
Size=1584,861
|
||||
Size=2048,1129
|
||||
Collapsed=0
|
||||
|
||||
[Window][Add Object]
|
||||
@ -66,24 +66,24 @@ Collapsed=0
|
||||
DockId=0x0000000C,0
|
||||
|
||||
[Window][Log Window]
|
||||
Pos=8,627
|
||||
Size=1568,226
|
||||
Pos=8,37
|
||||
Size=16,19
|
||||
Collapsed=0
|
||||
DockId=0x00000006,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0xC0DFADC4 Pos=8,27 Size=1568,826 Split=X
|
||||
DockNode ID=0x00000001 Parent=0xC0DFADC4 SizeRef=330,1094 Selected=0x393905AB
|
||||
DockNode ID=0x00000003 Parent=0xC0DFADC4 SizeRef=1700,1094 CentralNode=1
|
||||
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=1568,826 Split=Y
|
||||
DockNode ID=0x00000004 Parent=0xCCBD8CF7 SizeRef=1568,598 Split=X
|
||||
DockNode ID=0x00000009 Parent=0x00000004 SizeRef=289,974 Selected=0x031DC75C
|
||||
DockNode ID=0x0000000D Parent=0x00000004 SizeRef=1613,974 Split=X
|
||||
DockNode ID=0x00000002 Parent=0x0000000D SizeRef=1268,826 Split=Y
|
||||
DockNode ID=0x0000000B Parent=0x00000002 SizeRef=1568,637 Split=X
|
||||
DockNode ID=0x00000007 Parent=0x0000000B SizeRef=250,826 Selected=0x393905AB
|
||||
DockNode ID=0x00000008 Parent=0x0000000B SizeRef=971,826 CentralNode=1 Selected=0x031DC75C
|
||||
DockNode ID=0x0000000C Parent=0x00000002 SizeRef=1568,335 Selected=0x139FDA3F
|
||||
DockNode ID=0x00000005 Parent=0x0000000D SizeRef=343,826 Selected=0x9F035453
|
||||
DockNode ID=0x00000006 Parent=0xCCBD8CF7 SizeRef=1568,226 Selected=0xAB74BEE9
|
||||
DockSpace ID=0xC0DFADC4 Pos=8,27 Size=1568,826 Split=X
|
||||
DockNode ID=0x00000001 Parent=0xC0DFADC4 SizeRef=330,1094 Selected=0x393905AB
|
||||
DockNode ID=0x00000003 Parent=0xC0DFADC4 SizeRef=1700,1094 CentralNode=1
|
||||
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=2032,1094 Split=Y
|
||||
DockNode ID=0x00000004 Parent=0xCCBD8CF7 SizeRef=1568,598 Split=X
|
||||
DockNode ID=0x00000009 Parent=0x00000004 SizeRef=289,974 Split=Y Selected=0x031DC75C
|
||||
DockNode ID=0x00000007 Parent=0x00000009 SizeRef=289,547 Selected=0x031DC75C
|
||||
DockNode ID=0x00000008 Parent=0x00000009 SizeRef=289,545 Selected=0x393905AB
|
||||
DockNode ID=0x0000000D Parent=0x00000004 SizeRef=1613,974 Split=X
|
||||
DockNode ID=0x00000002 Parent=0x0000000D SizeRef=1268,826 Split=Y
|
||||
DockNode ID=0x0000000B Parent=0x00000002 SizeRef=1568,637 CentralNode=1
|
||||
DockNode ID=0x0000000C Parent=0x00000002 SizeRef=1568,335 Selected=0x139FDA3F
|
||||
DockNode ID=0x00000005 Parent=0x0000000D SizeRef=343,826 Selected=0x9F035453
|
||||
DockNode ID=0x00000006 Parent=0xCCBD8CF7 SizeRef=1568,226 Selected=0xAB74BEE9
|
||||
|
||||
|
@ -98,7 +98,8 @@ public:
|
||||
std::string ObjectTypeToString(ObjectType objectType);
|
||||
|
||||
void LaunchObject();
|
||||
void LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer, D3DClass* m_Direct3D);
|
||||
bool LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer,
|
||||
D3DClass* m_Direct3D);
|
||||
void SetAlpha(float alpha) { m_alpha = alpha; }
|
||||
float GetAlpha() const { return m_alpha; }
|
||||
void SetInitialStretch(float initialStretch) { m_initialStretch = initialStretch; }
|
||||
|
@ -1192,50 +1192,74 @@ int ApplicationClass::GetScreenHeight() const
|
||||
|
||||
void ApplicationClass::GenerateTerrain()
|
||||
{
|
||||
Logger::Get().Log("Generating terrain", __FILE__, __LINE__);
|
||||
Logger::Get().Log("Génération du terrain avec instanciation", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
|
||||
char modelFilename[128];
|
||||
TextureContainer TerrainTextures;
|
||||
XMMATRIX scaleMatrix;
|
||||
float scaleX, scaleY, scaleZ;
|
||||
// Nettoyer les objets terrain existants pour éviter les fuites
|
||||
for (auto* chunk : m_terrainChunk)
|
||||
{
|
||||
if (chunk)
|
||||
{
|
||||
chunk->Shutdown();
|
||||
delete chunk;
|
||||
}
|
||||
}
|
||||
m_terrainChunk.clear();
|
||||
|
||||
scaleX = 10.0f;
|
||||
scaleY = 1.0f;
|
||||
scaleZ = 10.0f;
|
||||
// Dimensions du terrain
|
||||
float scaleX = 10.0f;
|
||||
float scaleY = 1.0f;
|
||||
float scaleZ = 10.0f;
|
||||
int gridSizeX = 20;
|
||||
int gridSizeZ = 20;
|
||||
|
||||
scaleMatrix = XMMatrixScaling(scaleX, scaleY, scaleZ);
|
||||
// Créer un conteneur de textures partagé
|
||||
TextureContainer textureContainer;
|
||||
textureContainer.diffusePaths.push_back(L"assets/Texture/Bricks2K.png");
|
||||
textureContainer.normalPaths.push_back(L"assets/Texture/BricksNRM2K.png");
|
||||
textureContainer.specularPaths.push_back(L"assets/Texture/BricksGLOSS2K.png");
|
||||
|
||||
// Set the file name of the model.
|
||||
strcpy_s(modelFilename, "assets/Model/OBJ/plane.obj");
|
||||
// Précharger les textures une seule fois
|
||||
ModelClass* sharedModel = new ModelClass();
|
||||
sharedModel->PreloadTextures(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureContainer);
|
||||
|
||||
// Liste des fichiers de texture
|
||||
std::vector<std::wstring> terrainTexture = {
|
||||
L"assets/Texture/Bricks2K.png",
|
||||
L"assets/Texture/BricksNRM2K.png",
|
||||
L"assets/Texture/BricksGLOSS2K.png"
|
||||
};
|
||||
char modelFilename[128];
|
||||
strcpy_s(modelFilename, "assets/Model/OBJ/plane.obj");
|
||||
|
||||
std::filesystem::path p(modelFilename);
|
||||
std::string filenameWithoutExtension = p.stem().string();
|
||||
|
||||
// for loop to generate terrain chunks for a 10x10 grid
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
for (int j = 0; j < 20; j++)
|
||||
{
|
||||
Object* newTerrain = new Object();
|
||||
newTerrain->LoadTexturesFromPath(terrainTexture, TerrainTextures, m_Direct3D); // Load textures from the path
|
||||
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, TerrainTextures);
|
||||
newTerrain->SetScaleMatrix(scaleMatrix);
|
||||
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * scaleX , -12.0f, j * scaleZ));
|
||||
newTerrain->SetName(filenameWithoutExtension);
|
||||
newTerrain->SetType(ObjectType::Cube);
|
||||
newTerrain->SetActiveShader(ShaderType::SUNLIGHT);
|
||||
m_terrainChunk.push_back(newTerrain);
|
||||
// Générer les tuiles de terrain
|
||||
for (int i = 0; i < gridSizeX; i++)
|
||||
{
|
||||
for (int j = 0; j < gridSizeZ; j++)
|
||||
{
|
||||
// Créer un nouvel objet de terrain
|
||||
Object* terrain = new Object();
|
||||
|
||||
}
|
||||
}
|
||||
// Initialiser avec le modèle et les textures préchargées
|
||||
if (!terrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureContainer))
|
||||
{
|
||||
Logger::Get().Log("Échec de l'initialisation d'une tuile de terrain", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
delete terrain;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Définir la position dans la grille
|
||||
XMFLOAT3 position(i * scaleX, -12.0f, j * scaleZ);
|
||||
XMFLOAT3 scale(scaleX, scaleY, scaleZ);
|
||||
|
||||
terrain->SetPosition(XMLoadFloat3(&position));
|
||||
terrain->SetScale(XMLoadFloat3(&scale));
|
||||
|
||||
// Configurer les propriétés
|
||||
terrain->SetName("TerrainTile_" + std::to_string(i) + "_" + std::to_string(j));
|
||||
terrain->SetType(ObjectType::Cube);
|
||||
terrain->SetActiveShader(ShaderType::SUNLIGHT);
|
||||
terrain->SetId(m_ObjectId++);
|
||||
|
||||
// Ajouter à la liste des chunks de terrain
|
||||
m_terrainChunk.push_back(terrain);
|
||||
}
|
||||
}
|
||||
|
||||
Logger::Get().Log("Terrain généré avec " + std::to_string(m_terrainChunk.size()) + " tuiles", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
}
|
||||
|
||||
void ApplicationClass::AddKobject(std::wstring& filepath)
|
||||
|
@ -354,7 +354,8 @@ void Object::LaunchObject()
|
||||
OutputDebugStringA(buffer);
|
||||
}
|
||||
|
||||
void Object::LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer, D3DClass* m_Direct3D)
|
||||
bool Object::LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer,
|
||||
D3DClass* m_Direct3D)
|
||||
{
|
||||
|
||||
HRESULT result;
|
||||
@ -380,10 +381,12 @@ void Object::LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, Textu
|
||||
"\nError: " + std::to_string(result) +
|
||||
"\nDescription: " + str,
|
||||
__FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return ; // Assurez-vous de retourner false ou de gérer l'erreur de manière appropriée
|
||||
return false; // Assurez-vous de retourner false ou de gérer l'erreur de manière appropriée
|
||||
}
|
||||
texturesContainer.AssignTexture(texturesContainer, texture,texturePath , i);
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user