diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
index b5166e4..616a8ba 100644
--- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
+++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
@@ -6,19 +6,15 @@
-
-
+
-
-
+
+
-
-
-
@@ -38,9 +34,83 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -64,26 +134,26 @@
- {
- "keyToString": {
- "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "C++ Project.enginecustom.executor": "Run",
- "C/C++ Project.KhaoticDemo.executor": "Run",
- "C/C++ Project.enginecustom.executor": "Run",
- "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.pluginManager",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -229,6 +299,7 @@
+
diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini
index 674f428..bb12ee8 100644
--- a/enginecustom/imgui.ini
+++ b/enginecustom/imgui.ini
@@ -10,13 +10,13 @@ Collapsed=0
[Window][Khaotic Engine]
Pos=1267,19
-Size=317,842
+Size=317,609
Collapsed=0
DockId=0x00000002,0
[Window][render Stats]
Pos=0,630
-Size=792,231
+Size=1584,231
Collapsed=0
DockId=0x00000009,0
@@ -28,7 +28,7 @@ DockId=0x0000000B,0
[Window][Terrain]
Pos=0,19
-Size=266,842
+Size=266,609
Collapsed=0
DockId=0x00000007,0
diff --git a/enginecustom/src/inc/system/Skybox.h b/enginecustom/src/inc/system/Skybox.h
index 30c70ac..6783c92 100644
--- a/enginecustom/src/inc/system/Skybox.h
+++ b/enginecustom/src/inc/system/Skybox.h
@@ -13,7 +13,7 @@ public:
void Initialize(d_3d_class* d3dClassRef); // Get all the required references
- object* ConstructSkybox();
+ object* ConstructSkybox(application_class* app);
// Variables
diff --git a/enginecustom/src/inc/system/application_class.h b/enginecustom/src/inc/system/application_class.h
index 0106e62..de25173 100644
--- a/enginecustom/src/inc/system/application_class.h
+++ b/enginecustom/src/inc/system/application_class.h
@@ -55,6 +55,8 @@ constexpr bool full_screen = false;
constexpr float screen_depth = 1000.0f;
constexpr float screen_near = 0.3f;
+static std::map> g_model_cache;
+
struct input
{
bool key_left = false;
@@ -79,8 +81,7 @@ public:
render_texture_class* get_refraction_texture() const { return refraction_texture_; };
render_texture_class* get_reflection_texture() const { return reflection_texture_; };
- void create_big_cube(int side_count);
- void process_terrain_generation();
+ bool create_big_cube(int side_count);
virtual bool initialize(int, int, HWND, bool is_vulkan);
void shutdown();
virtual bool frame(input_class*);
diff --git a/enginecustom/src/inc/system/object.h b/enginecustom/src/inc/system/object.h
index 9e3a006..024cc80 100644
--- a/enginecustom/src/inc/system/object.h
+++ b/enginecustom/src/inc/system/object.h
@@ -29,6 +29,7 @@ enum class ShaderType
class object
{
public:
+ object(application_class& app);
object();
~object();
@@ -137,6 +138,9 @@ public :
bool m_gravityEnabled = true;
private:
+
+ application_class& m_Application;
+
XMMATRIX m_scaleMatrix;
XMMATRIX m_rotateMatrix;
XMMATRIX m_translateMatrix;
diff --git a/enginecustom/src/inc/system/stats.h b/enginecustom/src/inc/system/stats.h
index 5b7d9de..e60d1ee 100644
--- a/enginecustom/src/inc/system/stats.h
+++ b/enginecustom/src/inc/system/stats.h
@@ -6,6 +6,7 @@
#include "object.h"
#include // Pour __cpuid
#include // Pour DXGI
+#include
#pragma comment(lib, "dxgi.lib")
class stats
@@ -36,7 +37,6 @@ public:
std::string get_gpu_driver_version(ID3D11Device* device);
private:
- std::thread update_geometric_thread_;
std::thread update_display_thread_;
fps_class* fps_;
diff --git a/enginecustom/src/src/system/Skybox.cpp b/enginecustom/src/src/system/Skybox.cpp
index 74f3e8f..1f4fc9a 100644
--- a/enginecustom/src/src/system/Skybox.cpp
+++ b/enginecustom/src/src/system/Skybox.cpp
@@ -23,7 +23,7 @@ void Skybox::Initialize(d_3d_class* d3dClassRef)
m_d3dClassRef = d3dClassRef;
}
-object* Skybox::ConstructSkybox()
+object* Skybox::ConstructSkybox(application_class* app)
{
Logger::Get().Log("Construct skybox", __FILE__, __LINE__, Logger::LogLevel::Initialize);
@@ -51,7 +51,7 @@ object* Skybox::ConstructSkybox()
}
// Create the model object
- m_Skybox = new object();
+ m_Skybox = new object(*app);
HRESULT result = m_Skybox->Initialize(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), modelFilename, SkyboxTextures);
if (!result)
{
diff --git a/enginecustom/src/src/system/application_class.cpp b/enginecustom/src/src/system/application_class.cpp
index fe69205..e0cf554 100644
--- a/enginecustom/src/src/system/application_class.cpp
+++ b/enginecustom/src/src/system/application_class.cpp
@@ -505,7 +505,7 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
//ConstructSkyboxWithPlanes();
Skybox* skybox = new Skybox;
skybox->Initialize(direct_3d_);
- skybox_.push_back(skybox->ConstructSkybox());
+ skybox_.push_back(skybox->ConstructSkybox(this));
culling_active_ = true;
culling_thread_ = std::thread(&application_class::culling_thread_function, this);
@@ -765,8 +765,6 @@ void application_class::shutdown()
bool application_class::frame(input_class* Input)
{
-
- process_terrain_generation();
stats_->reset_draw_call_count();
int mouseX, mouseY, currentMouseX, currentMouseY;
@@ -1133,10 +1131,10 @@ bool application_class::render(float rotation, float x, float y, float z, float
// -------------------------------------------------------- //
// set the active camera to the sun camera for rendering the shadow map.
- active_camera_ = sun_camera_;
- active_camera_->render();
- // Render the objects in the render queues. with depth only pass.
- active_camera_->get_view_matrix(viewMatrix);
+ // active_camera_ = sun_camera_;
+ // active_camera_->render();
+ // // Render the objects in the render queues. with depth only pass.
+ // active_camera_->get_view_matrix(viewMatrix);
result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
if (!result)
{
@@ -1145,18 +1143,19 @@ bool application_class::render(float rotation, float x, float y, float z, float
}
// Reset the active camera to the main camera.
- active_camera_ = camera_;
- active_camera_->render();
- active_camera_->get_view_matrix(viewMatrix);
-
- // render the objects in the render queues. with standard pass.
- result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
- if (!result)
- {
- Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
- return false;
- }
+ // active_camera_ = camera_;
+ // active_camera_->render();
+ // active_camera_->get_view_matrix(viewMatrix);
+ //
+ // // render the objects in the render queues. with standard pass.
+ // result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
+ // if (!result)
+ // {
+ // Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
+ // return false;
+ // }
+ stats_->update_geometric_stats();
// Update the render count text.
result = update_render_count_string(get_render_count());
@@ -1329,7 +1328,7 @@ void application_class::generate_terrain()
for (int j = 0; j < gridSizeZ; j++)
{
// Créer un nouvel objet de terrain
- object* terrain = new object();
+ object* terrain = new object(*this);
// Initialiser avec le modèle et les textures_ préchargées
if (!terrain->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, textureContainer))
@@ -1362,6 +1361,7 @@ void application_class::generate_terrain()
void application_class::add_kobject(std::wstring& filepath)
{
+ std::lock_guard lock(objects_mutex_);
Logger::Get().Log("Adding object", __FILE__, __LINE__);
char modelFilename[128];
@@ -1382,7 +1382,7 @@ void application_class::add_kobject(std::wstring& filepath)
L"assets/Texture/BricksGLOSS2K.png"
};
- object* newObject = new object();
+ object* newObject = new object(*this);
newObject->LoadTexturesFromPath(kobjTexture,KobjectsTextures, direct_3d_); // Load textures_ from the path
newObject->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, KobjectsTextures);
newObject->SetMass(1.0f);
@@ -1404,6 +1404,7 @@ void application_class::add_kobject(std::wstring& filepath)
void application_class::add_cube()
{
+ std::lock_guard lock(objects_mutex_);
Logger::Get().Log("Adding cube", __FILE__, __LINE__);
char modelFilename[128];
@@ -1418,7 +1419,7 @@ void application_class::add_cube()
static int cubeCount = 0;
float position = cubeCount * 2.0f;
- object* newCube = new object();
+ object* newCube = new object(*this);
newCube->LoadTexturesFromPath(cubeTexture, CubeTexture, direct_3d_); // Load textures_ from the path
newCube->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, CubeTexture);
newCube->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f));
@@ -1429,6 +1430,7 @@ void application_class::add_cube()
void application_class::delete_kobject(int index)
{
+ std::lock_guard lock(objects_mutex_);
Logger::Get().Log("Deleting object", __FILE__, __LINE__);
if (index < object_.size())
@@ -1439,6 +1441,7 @@ void application_class::delete_kobject(int index)
void application_class::delete_terrain()
{
+ std::lock_guard lock(objects_mutex_);
Logger::Get().Log("Deleting terrain", __FILE__, __LINE__);
terrain_chunk_.clear();
}
@@ -2151,126 +2154,56 @@ void application_class::physics_thread_function()
}
}
-void application_class::create_big_cube(int side_count)
+bool application_class::create_big_cube(int side_count)
{
- 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, side_count]() {
- Logger::Get().Log("Thread de génération de terrain démarré", __FILE__, __LINE__, Logger::LogLevel::Info);
+ std::string modelName = "assets/Model/TXT/cube.txt";
+ std::shared_ptr sharedModel;
+
+ // Vérifier si le modèle existe déjà
+ auto it = g_model_cache.find(modelName);
+ if (it != g_model_cache.end()) {
+ sharedModel = it->second;
+ } else {
+ // copy le string en char*
+ char model_file[128];
+ size_t convertedChars = 0;
+ (void)wcstombs_s(&convertedChars, model_file, sizeof(model_file), std::wstring(modelName.begin(), modelName.end()).c_str(), _TRUNCATE);
- // Stockage temporaire pour les nouveaux objets
- std::vector