Patch Update - WIP Async Cube Generation - V10.2.1
This commit is contained in:
parent
94fd900ce8
commit
f8bfb62e98
12
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
12
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
@ -6,18 +6,10 @@
|
||||
<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/assets/Texture/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" 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/inc/system/fpsclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/fpsclass.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/modelclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/modelclass.h" 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/fpsclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/fpsclass.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.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" />
|
||||
<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" />
|
||||
@ -58,7 +50,7 @@
|
||||
"keyToString": {
|
||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"C++ Project.enginecustom.executor": "Run",
|
||||
"C/C++ Project.enginecustom.executor": "Run",
|
||||
"C/C++ Project.enginecustom.executor": "dotTrace Profiler",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
@ -193,7 +185,7 @@
|
||||
<workItem from="1746536290167" duration="1908000" />
|
||||
<workItem from="1746538260893" duration="5781000" />
|
||||
<workItem from="1746546014271" duration="1814000" />
|
||||
<workItem from="1746619988287" duration="10779000" />
|
||||
<workItem from="1746619988287" duration="12282000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
|
||||
<option name="closed" value="true" />
|
||||
|
@ -5,7 +5,7 @@ Collapsed=0
|
||||
|
||||
[Window][Khaotic Engine]
|
||||
Pos=1233,27
|
||||
Size=343,826
|
||||
Size=343,599
|
||||
Collapsed=0
|
||||
DockId=0x00000005,0
|
||||
|
||||
@ -17,7 +17,7 @@ DockId=0x00000007,0
|
||||
|
||||
[Window][Terrain]
|
||||
Pos=8,27
|
||||
Size=281,826
|
||||
Size=281,599
|
||||
Collapsed=0
|
||||
DockId=0x00000008,0
|
||||
|
||||
|
@ -79,6 +79,7 @@ public:
|
||||
int GetVisibleTriangleCount() const;
|
||||
|
||||
void CreateBigCube(int sideCount);
|
||||
void ProcessTerrainGeneration();
|
||||
bool Initialize(int, int, HWND, bool IsVulkan);
|
||||
void Shutdown();
|
||||
bool Frame(InputClass*);
|
||||
@ -195,6 +196,12 @@ public :
|
||||
|
||||
private :
|
||||
|
||||
|
||||
std::mutex m_TerrainMutex;
|
||||
std::vector<std::tuple<float, float, float, std::string, int>> m_TerrainGenerationData;
|
||||
bool m_TerrainGenerationReady;
|
||||
int m_NextTerrainObjectId;
|
||||
|
||||
// ------------------------------------- //
|
||||
// ------------- DIRECT3D -------------- //
|
||||
// ------------------------------------- //
|
||||
|
@ -710,6 +710,7 @@ void ApplicationClass::Shutdown()
|
||||
bool ApplicationClass::Frame(InputClass* Input)
|
||||
{
|
||||
|
||||
ProcessTerrainGeneration();
|
||||
ResetDrawCallCount();
|
||||
|
||||
int mouseX, mouseY, currentMouseX, currentMouseY;
|
||||
@ -2389,74 +2390,132 @@ void ApplicationClass::ResetDrawCallCount()
|
||||
|
||||
void ApplicationClass::CreateBigCube(int sideCount)
|
||||
{
|
||||
Logger::Get().Log("Génération du terrain avec instanciation", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
Logger::Get().Log("Lancement de la génération du terrain dans un thread séparé", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
|
||||
// Créer un thread qui exécutera la génération du terrain
|
||||
std::thread generationThread([this, sideCount]() {
|
||||
Logger::Get().Log("Thread de génération de terrain démarré", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
|
||||
// Stockage temporaire pour les nouveaux objets
|
||||
std::vector<Object*> newTerrainChunks;
|
||||
|
||||
// Nettoyer les objets terrain existants pour éviter les fuites
|
||||
// Dimensions du terrain
|
||||
float scaleX = 1.0f;
|
||||
float scaleY = 1.0f;
|
||||
float scaleZ = 1.0f;
|
||||
|
||||
// Préparer les données pour la création des cubes
|
||||
std::vector<std::tuple<float, float, float, std::string, int>> cubeData;
|
||||
int objectId = m_ObjectId;
|
||||
|
||||
// Générer les données des cubes
|
||||
for (int i = 0; i < sideCount; i++) {
|
||||
for (int j = 0; j < sideCount; j++) {
|
||||
for (int k = 0; k < sideCount; k++) {
|
||||
// Vérifier si nous devons arrêter le thread
|
||||
if (m_ShouldQuit) {
|
||||
Logger::Get().Log("Génération de terrain annulée", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
return;
|
||||
}
|
||||
|
||||
// Position et nom du cube
|
||||
float posX = i * scaleX;
|
||||
float posY = k * scaleY;
|
||||
float posZ = j * scaleZ;
|
||||
std::string name = "TerrainTile_" + std::to_string(i) + "_" + std::to_string(j) + "_" + std::to_string(k);
|
||||
|
||||
// Stocker les données du cube
|
||||
cubeData.push_back(std::make_tuple(posX, posY, posZ, name, objectId++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Synchroniser avec le thread principal pour créer les objets
|
||||
// Cette partie doit être exécutée dans le thread principal (via une file d'attente ou autre mécanisme)
|
||||
std::lock_guard<std::mutex> lock(m_TerrainMutex);
|
||||
m_TerrainGenerationData = std::move(cubeData);
|
||||
m_TerrainGenerationReady = true;
|
||||
m_NextTerrainObjectId = objectId;
|
||||
|
||||
Logger::Get().Log("Données de génération de terrain préparées (" + std::to_string(m_TerrainGenerationData.size()) + " cubes)", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
});
|
||||
|
||||
// Détacher le thread pour qu'il s'exécute en arrière-plan
|
||||
generationThread.detach();
|
||||
}
|
||||
|
||||
void ApplicationClass::ProcessTerrainGeneration()
|
||||
{
|
||||
// Vérifier si des données de terrain sont prêtes à être traitées
|
||||
if (!m_TerrainGenerationReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Acquérir les données générées
|
||||
std::vector<std::tuple<float, float, float, std::string, int>> cubeData;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_TerrainMutex);
|
||||
cubeData = std::move(m_TerrainGenerationData);
|
||||
m_TerrainGenerationData.clear();
|
||||
m_TerrainGenerationReady = false;
|
||||
m_ObjectId = m_NextTerrainObjectId;
|
||||
}
|
||||
|
||||
Logger::Get().Log("Création des objets terrain à partir des données préparées", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
|
||||
// Nettoyer les objets terrain existants
|
||||
for (auto* chunk : m_terrainChunk)
|
||||
{
|
||||
if (chunk)
|
||||
{
|
||||
if (chunk) {
|
||||
chunk->Shutdown();
|
||||
delete chunk;
|
||||
}
|
||||
}
|
||||
m_terrainChunk.clear();
|
||||
|
||||
// Dimensions du terrain
|
||||
float scaleX = 1.0f;
|
||||
float scaleY = 1.0f;
|
||||
float scaleZ = 1.0f;
|
||||
|
||||
|
||||
// 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");
|
||||
|
||||
|
||||
// Précharger les textures une seule fois
|
||||
ModelClass* sharedModel = new ModelClass();
|
||||
sharedModel->PreloadTextures(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureContainer);
|
||||
|
||||
|
||||
char modelFilename[128];
|
||||
strcpy_s(modelFilename, "assets/Model/TXT/cube.txt");
|
||||
|
||||
// Générer les tuiles de terrain
|
||||
for (int i = 0; i < sideCount; i++)
|
||||
|
||||
// Créer les objets à partir des données
|
||||
for (const auto& [posX, posY, posZ, name, id] : cubeData)
|
||||
{
|
||||
for (int j = 0; j < sideCount; j++)
|
||||
// Créer un nouvel objet de terrain
|
||||
Object* terrain = new Object();
|
||||
|
||||
// Initialiser avec le modèle et les textures
|
||||
if (!terrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureContainer))
|
||||
{
|
||||
|
||||
for (int k = 0; k < sideCount; k++)
|
||||
{
|
||||
// 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, k * scaleY, 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::TEXTURE);
|
||||
terrain->SetId(m_ObjectId++);
|
||||
|
||||
// Ajouter à la liste des chunks de terrain
|
||||
m_terrainChunk.push_back(terrain);
|
||||
}
|
||||
Logger::Get().Log("Échec de l'initialisation d'une tuile de terrain", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
delete terrain;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Configurer l'objet
|
||||
XMFLOAT3 position(posX, posY, posZ);
|
||||
XMFLOAT3 scale(1.0f, 1.0f, 1.0f);
|
||||
|
||||
terrain->SetPosition(XMLoadFloat3(&position));
|
||||
terrain->SetScale(XMLoadFloat3(&scale));
|
||||
terrain->SetName(name);
|
||||
terrain->SetType(ObjectType::Cube);
|
||||
terrain->SetActiveShader(ShaderType::TEXTURE);
|
||||
terrain->SetId(id);
|
||||
|
||||
// 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);
|
||||
|
||||
delete sharedModel;
|
||||
|
||||
Logger::Get().Log("Génération du terrain terminée avec " + std::to_string(m_terrainChunk.size()) + " cubes", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||
}
|
@ -18,24 +18,7 @@ ModelClass::~ModelClass()
|
||||
{
|
||||
}
|
||||
|
||||
// bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, std::vector<ID3D11ShaderResourceView*> textures) {
|
||||
// Logger::Get().Log("Initializing model class with preloaded textures (vector)", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
//
|
||||
// bool result = Initialize(device, deviceContext, modelFilename);
|
||||
// if (!result) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // Ajouter toutes les textures au container comme textures diffuses
|
||||
// for (auto& tex : textures) {
|
||||
// m_Textures.diffuse.push_back(tex);
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, const TextureContainer& textures) {
|
||||
Logger::Get().Log("Initializing model class with preloaded texture container", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
bool result = Initialize(device, deviceContext, modelFilename);
|
||||
if (!result) {
|
||||
@ -48,7 +31,6 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
|
||||
}
|
||||
|
||||
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename) {
|
||||
Logger::Get().Log("Initializing model class without textures", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
bool result;
|
||||
|
||||
@ -68,9 +50,7 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
|
||||
Logger::Get().Log("Failed to initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger::Get().Log("Model class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -103,18 +83,12 @@ int ModelClass::GetIndexCount()
|
||||
return m_indexCount;
|
||||
}
|
||||
|
||||
// ID3D11ShaderResourceView* ModelClass::GetTexture(int index) const {
|
||||
// // Pour compatibilité, utilise la texture diffuse par défaut
|
||||
// return m_Textures.GetTexture(TextureType::Diffuse, index);
|
||||
// }
|
||||
|
||||
ID3D11ShaderResourceView* ModelClass::GetTexture(TextureType type, int index) const {
|
||||
return m_Textures.GetTexture(type, index);
|
||||
}
|
||||
|
||||
bool ModelClass::InitializeBuffers(ID3D11Device* device)
|
||||
{
|
||||
Logger::Get().Log("Initializing buffers", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
VertexType* vertices;
|
||||
unsigned long* indices;
|
||||
@ -189,16 +163,12 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device)
|
||||
|
||||
delete[] indices;
|
||||
indices = 0;
|
||||
|
||||
Logger::Get().Log("Buffers initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ModelClass::ShutdownBuffers()
|
||||
{
|
||||
Logger::Get().Log("Shutting down buffers", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
// Release the index buffer.
|
||||
if (m_indexBuffer)
|
||||
{
|
||||
@ -212,10 +182,7 @@ void ModelClass::ShutdownBuffers()
|
||||
m_vertexBuffer->Release();
|
||||
m_vertexBuffer = 0;
|
||||
}
|
||||
|
||||
Logger::Get().Log("Buffers shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -243,17 +210,13 @@ void ModelClass::RenderBuffers(ID3D11DeviceContext* deviceContext)
|
||||
|
||||
void ModelClass::ReleaseTextures()
|
||||
{
|
||||
Logger::Get().Log("Releasing textures", __FILE__, __LINE__);
|
||||
|
||||
// Utilise la méthode ReleaseAll de TextureContainer
|
||||
m_Textures.ReleaseAll();
|
||||
|
||||
Logger::Get().Log("Textures released", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
bool ModelClass::LoadModel(char* filename)
|
||||
{
|
||||
Logger::Get().Log("Loading model: " + std::string(filename), __FILE__, __LINE__);
|
||||
|
||||
std::string fileStr(filename);
|
||||
std::string extension = fileStr.substr(fileStr.find_last_of(".") + 1);
|
||||
@ -277,8 +240,7 @@ bool ModelClass::LoadModel(char* filename)
|
||||
|
||||
bool ModelClass::LoadObjModel(char* filename)
|
||||
{
|
||||
Logger::Get().Log("Loading model", __FILE__, __LINE__);
|
||||
|
||||
|
||||
std::string line;
|
||||
std::ifstream fin(filename);
|
||||
|
||||
@ -362,16 +324,12 @@ bool ModelClass::LoadObjModel(char* filename)
|
||||
|
||||
fin.close();
|
||||
|
||||
Logger::Get().Log("Model loaded", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ModelClass::LoadTxtModel(char* filename)
|
||||
{
|
||||
Logger::Get().Log("Loading model", __FILE__, __LINE__);
|
||||
|
||||
ifstream fin;
|
||||
char input;
|
||||
int i;
|
||||
@ -422,16 +380,12 @@ bool ModelClass::LoadTxtModel(char* filename)
|
||||
|
||||
// Close the model file.
|
||||
fin.close();
|
||||
|
||||
Logger::Get().Log("Model loaded "+ std::string(filename), __FILE__, __LINE__);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModelClass::CalculateModelVectors()
|
||||
{
|
||||
Logger::Get().Log("Calculating model vectors", __FILE__, __LINE__);
|
||||
|
||||
int faceCount, i, index;
|
||||
TempVertexType vertex1, vertex2, vertex3;
|
||||
VectorType tangent, binormal;
|
||||
@ -493,10 +447,6 @@ void ModelClass::CalculateModelVectors()
|
||||
m_model[index - 3].by = binormal.y;
|
||||
m_model[index - 3].bz = binormal.z;
|
||||
}
|
||||
|
||||
Logger::Get().Log("Model vectors calculated", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void ModelClass::CalculateTangentBinormal(TempVertexType vertex1, TempVertexType vertex2, TempVertexType vertex3, VectorType& tangent, VectorType& binormal)
|
||||
@ -551,23 +501,16 @@ void ModelClass::CalculateTangentBinormal(TempVertexType vertex1, TempVertexType
|
||||
binormal.x = binormal.x / length;
|
||||
binormal.y = binormal.y / length;
|
||||
binormal.z = binormal.z / length;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void ModelClass::ReleaseModel()
|
||||
{
|
||||
Logger::Get().Log("Releasing model", __FILE__, __LINE__);
|
||||
|
||||
if (m_model)
|
||||
{
|
||||
delete[] m_model;
|
||||
m_model = 0;
|
||||
}
|
||||
|
||||
Logger::Get().Log("Model released", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool ModelClass::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, TextureContainer& textureContainer)
|
||||
|
Loading…
x
Reference in New Issue
Block a user