Minor - Smart pointer and switch from composition to aggregation for object relation with modelclass - V11.3.0

This commit is contained in:
CatChow0 2025-06-19 17:15:27 +02:00
parent ae3fc21ffc
commit f5331444cb
14 changed files with 175 additions and 407 deletions

View File

@ -6,8 +6,19 @@
<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/enginecustom.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/assets/imgui.ini" beforeDir="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/application_class.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/application_class.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/object.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/object.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/system_class.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/system_class.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.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/object.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/object.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/scene_manager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/scene_manager.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/stats.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/stats.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/system_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/system_class.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -53,26 +64,26 @@
<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.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"
<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.KhaoticDemo.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.pluginManager&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">
@ -213,6 +224,11 @@
<workItem from="1748869642637" duration="3049000" />
<workItem from="1748954607174" duration="14202000" />
<workItem from="1748969487337" duration="402000" />
<workItem from="1750187491423" duration="4397000" />
<workItem from="1750191969842" duration="162000" />
<workItem from="1750248915365" duration="442000" />
<workItem from="1750335650897" duration="2051000" />
<workItem from="1750344288223" duration="1751000" />
</task>
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
<option name="closed" value="true" />

View File

@ -1,106 +0,0 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Khaotic Engine]
Pos=1281,19
Size=303,842
Collapsed=0
DockId=0x0000000F,0
[Window][Objects]
Pos=0,19
Size=281,842
Collapsed=0
DockId=0x00000011,0
[Window][Terrain]
Pos=0,19
Size=280,842
Collapsed=0
DockId=0x00000007,0
[Window][Light]
Pos=0,19
Size=281,842
Collapsed=0
DockId=0x00000012,0
[Window][Shader Manager]
Pos=8,27
Size=330,487
Collapsed=0
DockId=0x00000001,2
[Window][Engine Settings]
Pos=1281,527
Size=303,334
Collapsed=0
DockId=0x00000010,0
[Window][DockSpace Demo]
Size=1584,861
Collapsed=0
[Window][Render Window]
Pos=8,27
Size=1559,974
Collapsed=0
DockId=0x00000011,0
[Window][DockSpace]
Pos=0,0
Size=1584,861
Collapsed=0
[Window][Add Object]
Pos=1188,0
Size=396,430
Collapsed=0
[Window][Log]
Pos=8,518
Size=1568,335
Collapsed=0
DockId=0x0000000C,0
[Window][Log Window]
Pos=0,636
Size=1279,225
Collapsed=0
DockId=0x00000006,0
[Window][Render Stats]
Pos=0,636
Size=1279,225
Collapsed=0
DockId=0x00000004,0
[Window][render Window]
Pos=16,718
Size=997,758
Collapsed=1
[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=0,19 Size=1584,842 Split=X
DockNode ID=0x00000002 Parent=0xCCBD8CF7 SizeRef=1743,826 Split=Y
DockNode ID=0x0000000A Parent=0x00000002 SizeRef=1568,599 Split=X
DockNode ID=0x00000009 Parent=0x0000000A SizeRef=281,974 Split=Y Selected=0x031DC75C
DockNode ID=0x00000011 Parent=0x00000009 SizeRef=281,441 Selected=0x031DC75C
DockNode ID=0x00000012 Parent=0x00000009 SizeRef=281,440 Selected=0x321620B2
DockNode ID=0x0000000D Parent=0x0000000A SizeRef=1460,974 Split=Y
DockNode ID=0x0000000B Parent=0x0000000D SizeRef=1568,637 Split=X Selected=0x321620B2
DockNode ID=0x00000007 Parent=0x0000000B SizeRef=280,883 Selected=0x393905AB
DockNode ID=0x00000008 Parent=0x0000000B SizeRef=1178,883 CentralNode=1 Selected=0x4FC83240
DockNode ID=0x0000000C Parent=0x0000000D SizeRef=1568,335 Selected=0x139FDA3F
DockNode ID=0x0000000E Parent=0x00000002 SizeRef=1568,225 Split=X Selected=0xD99DEA49
DockNode ID=0x00000004 Parent=0x0000000E SizeRef=871,225 Selected=0xD99DEA49
DockNode ID=0x00000006 Parent=0x0000000E SizeRef=870,225 Selected=0xAB74BEE9
DockNode ID=0x00000005 Parent=0xCCBD8CF7 SizeRef=303,826 Split=Y Selected=0x9F035453
DockNode ID=0x0000000F Parent=0x00000005 SizeRef=303,667 Selected=0x9F035453
DockNode ID=0x00000010 Parent=0x00000005 SizeRef=303,441 Selected=0x0B098C4B

View File

@ -1,89 +0,0 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Khaotic Engine]
Pos=1233,27
Size=343,826
Collapsed=0
DockId=0x00000005,0
[Window][Objects]
Pos=8,27
Size=289,413
Collapsed=0
DockId=0x00000007,0
[Window][Terrain]
Pos=8,442
Size=289,411
Collapsed=0
DockId=0x00000008,0
[Window][Light]
Pos=8,27
Size=290,866
Collapsed=0
DockId=0x00000004,1
[Window][Shader Manager]
Pos=8,27
Size=330,487
Collapsed=0
DockId=0x00000001,2
[Window][Engine Settings]
Pos=1233,27
Size=343,826
Collapsed=0
DockId=0x00000005,1
[Window][DockSpace Demo]
Size=1584,861
Collapsed=0
[Window][Render Window]
Pos=8,27
Size=1559,974
Collapsed=0
DockId=0x00000007,0
[Window][DockSpace]
Pos=0,0
Size=1584,861
Collapsed=0
[Window][Add Object]
Pos=1188,0
Size=396,430
Collapsed=0
[Window][Log]
Pos=8,518
Size=1568,335
Collapsed=0
DockId=0x0000000C,0
[Window][Log Window]
Pos=299,627
Size=932,226
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=X
DockNode ID=0x00000009 Parent=0xCCBD8CF7 SizeRef=289,974 Split=Y Selected=0x031DC75C
DockNode ID=0x00000007 Parent=0x00000009 SizeRef=289,299 Selected=0x031DC75C
DockNode ID=0x00000008 Parent=0x00000009 SizeRef=289,297 Selected=0x393905AB
DockNode ID=0x0000000D Parent=0xCCBD8CF7 SizeRef=1613,974 Split=X
DockNode ID=0x00000002 Parent=0x0000000D SizeRef=1268,826 Split=Y
DockNode ID=0x0000000B Parent=0x00000002 SizeRef=1568,637 Split=Y
DockNode ID=0x00000004 Parent=0x0000000B SizeRef=932,598 CentralNode=1
DockNode ID=0x00000006 Parent=0x0000000B SizeRef=932,226 Selected=0xAB74BEE9
DockNode ID=0x0000000C Parent=0x00000002 SizeRef=1568,335 Selected=0x139FDA3F
DockNode ID=0x00000005 Parent=0x0000000D SizeRef=343,826 Selected=0x0B098C4B

View File

@ -15,23 +15,45 @@ Collapsed=0
DockId=0x00000002,0
[Window][render Stats]
Pos=275,630
Size=1309,231
Pos=0,630
Size=792,231
Collapsed=0
DockId=0x00000004,0
DockId=0x00000009,0
[Window][Objects]
Pos=0,19
Size=273,842
Size=238,609
Collapsed=0
DockId=0x00000005,0
DockId=0x0000000B,0
[Window][Terrain]
Pos=0,19
Size=266,842
Collapsed=0
DockId=0x00000007,0
[Window][Log Window]
Pos=794,630
Size=790,231
Collapsed=0
DockId=0x0000000A,0
[Window][Light]
Pos=0,19
Size=238,609
Collapsed=0
DockId=0x0000000B,1
[Docking][Data]
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1584,842 Split=X
DockNode ID=0x00000005 Parent=0xCCBD8CF7 SizeRef=273,842 Selected=0x031DC75C
DockNode ID=0x00000006 Parent=0xCCBD8CF7 SizeRef=1309,842 Split=Y
DockNode ID=0x00000003 Parent=0x00000006 SizeRef=1584,609 Split=X
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=990,842 CentralNode=1
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=317,842 Selected=0x9F035453
DockNode ID=0x00000004 Parent=0x00000006 SizeRef=1584,231 Selected=0xF5D1BB37
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1584,842 Split=Y
DockNode ID=0x00000003 Parent=0xCCBD8CF7 SizeRef=1584,609 Split=X
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=238,842 Selected=0x031DC75C
DockNode ID=0x0000000C Parent=0x00000003 SizeRef=1344,842 Split=X
DockNode ID=0x00000007 Parent=0x0000000C SizeRef=266,842 Selected=0x393905AB
DockNode ID=0x00000008 Parent=0x0000000C SizeRef=1316,842 Split=X
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1025,842 CentralNode=1
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=317,842 Selected=0x9F035453
DockNode ID=0x00000004 Parent=0xCCBD8CF7 SizeRef=1584,231 Split=X Selected=0xF5D1BB37
DockNode ID=0x00000009 Parent=0x00000004 SizeRef=792,231 Selected=0xF5D1BB37
DockNode ID=0x0000000A Parent=0x00000004 SizeRef=790,231 Selected=0xAB74BEE9

View File

@ -42,6 +42,7 @@
#include <algorithm>
#include <DirectXMath.h>
#include <mutex>
#include <memory>
#include "shadow_map.h"
#include "stats.h"

View File

@ -57,7 +57,7 @@ public:
ImVec2 GetWindowSize() const { return windowSize; }
// Getters
void SetApp(application_class* app) { app_ = app; }
void SetApp(std::shared_ptr<application_class> app) { app_ = app; }
// Shader toggles
@ -75,7 +75,7 @@ private:
std::vector<widget_entry> widgets_;
application_class* app_;
std::shared_ptr<application_class> app_;
scene_manager* scene_manager_;
stats* stats_;

View File

@ -26,7 +26,7 @@ enum class ShaderType
ALPHA_MAPPING
};
class object : public model_class
class object
{
public:
object();
@ -35,6 +35,13 @@ public:
object(const object&) = delete;
object& operator=(const object&) = delete;
bool Initialize(
ID3D11Device* device,
ID3D11DeviceContext* deviceContext,
char* modelFilename,
TextureContainer& texturesContainer
);
void SetScaleMatrix(XMMATRIX scaleMatrix);
void SetRotateMatrix(XMMATRIX rotateMatrix);
void SetTranslateMatrix(XMMATRIX translateMatrix);
@ -119,6 +126,9 @@ public:
bool IsGravityEnabled() const { return m_gravityEnabled; }
void SetGravityEnabled(bool state) { m_gravityEnabled = state; }
std::shared_ptr<model_class> get_model() const { return m_model_; }
void SetModel(std::shared_ptr<model_class> model) { m_model_ = model; }
public :
bool m_demoSpinning = false;
XMVECTOR m_previousPosition;
@ -149,5 +159,7 @@ private:
float m_alpha = 0.0f;
float m_initialStretch = 0.0f;
float m_springConstant = 10.0f;
std::shared_ptr<model_class> m_model_;
};

View File

@ -32,20 +32,12 @@ public:
void send_path(wchar_t* path, std::filesystem::path w_folder);
application_class* get_application_class() const { return application_; }
void set_application_class(application_class* application) {
if (application_) {
delete application_;
}
application_ = application;
}
input_class* get_input_class() const { return input_; }
void set_input(input_class* input) {
if (input_) {
delete input_;
}
input_ = input;
}
std::shared_ptr<application_class> get_application_class() const { return application_; }
void set_application_class(std::shared_ptr<application_class> application) { application_ = std::move(application); }
std::shared_ptr<input_class> get_input_class() const { return input_; }
void set_input(std::shared_ptr<input_class> input) { input_ = std::move(input); }
HWND get_hwnd() const { return hwnd_; }
void set_d_3D_mock(d_3d_class* mock) {application_->set_direct_3d(mock);}
@ -61,9 +53,9 @@ private:
HINSTANCE hinstance_;
HWND hwnd_;
input_class* input_;
application_class* application_;
imguiManager* imgui_manager_;
std::shared_ptr<input_class> input_;
std::shared_ptr<application_class> application_;
std::shared_ptr<imguiManager> imgui_manager_;
int initial_window_width_;
int initial_window_height_;

View File

@ -1133,10 +1133,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,17 +1145,17 @@ 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;
}
// Update the render count text.
@ -1300,16 +1300,7 @@ int application_class::get_screen_height() const
void application_class::generate_terrain()
{
Logger::Get().Log("Génération du terrain avec instanciation", __FILE__, __LINE__, Logger::LogLevel::Info);
// Nettoyer les objets terrain existants pour éviter les fuites
for (auto* chunk : terrain_chunk_)
{
if (chunk)
{
chunk->Shutdown();
delete chunk;
}
}
terrain_chunk_.clear();
// Dimensions du terrain
@ -1405,7 +1396,7 @@ void application_class::add_kobject(std::wstring& filepath)
object_.push_back(newObject);
// Vérifiez que l'objet a bien reçu les textures_
if (newObject->GetTexture(TextureType::Diffuse,0) == nullptr)
if (newObject->get_model()->GetTexture(TextureType::Diffuse,0) == nullptr)
{
Logger::Get().Log("object texture is null after initialization", __FILE__, __LINE__, Logger::LogLevel::Error);
}
@ -1442,8 +1433,6 @@ void application_class::delete_kobject(int index)
if (index < object_.size())
{
object_[index]->Shutdown();
delete object_[index];
object_.erase(object_.begin() + index);
}
}
@ -1451,12 +1440,6 @@ void application_class::delete_kobject(int index)
void application_class::delete_terrain()
{
Logger::Get().Log("Deleting terrain", __FILE__, __LINE__);
for (auto cube : terrain_chunk_)
{
cube->Shutdown();
delete cube;
}
terrain_chunk_.clear();
}
@ -1819,17 +1802,17 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
translateMatrix
);
object->Render(direct_3d_->get_device_context());
object->get_model()->Render(direct_3d_->get_device_context());
if (active_camera_ == sun_camera_)
{
result = shader_manager_->render_depth_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0)
object->get_model()->GetTexture(TextureType::Diffuse,0)
);
}
@ -1844,13 +1827,13 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
result = shader_manager_->render_alpha_map_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0),
object->GetTexture(TextureType::Diffuse,1),
object->GetTexture(TextureType::Alpha,0)
object->get_model()->GetTexture(TextureType::Diffuse,0),
object->get_model()->GetTexture(TextureType::Diffuse,1),
object->get_model()->GetTexture(TextureType::Alpha,0)
);
if (!result)
{
@ -1864,11 +1847,11 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
case ShaderType::CEL_SHADING:
result = shader_manager_->render_cel_shading_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0),
object->get_model()->GetTexture(TextureType::Diffuse,0),
sun_light_->GetDiffuseColor(),
sun_light_->GetAmbientColor(),
sun_light_->GetDirection(),
@ -1884,12 +1867,12 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
case ShaderType::NORMAL_MAPPING:
result = shader_manager_->render_normal_map_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0),
object->GetTexture(TextureType::Normal,0),
object->get_model()->GetTexture(TextureType::Diffuse,0),
object->get_model()->GetTexture(TextureType::Normal,0),
lights_[0]->GetDirection(),
lights_[0]->GetDiffuseColor()
);
@ -1903,13 +1886,13 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
case ShaderType::SPECULAR_MAPPING:
result = shader_manager_->render_spec_map_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0),
object->GetTexture(TextureType::Normal,0),
object->GetTexture(TextureType::Specular,0),
object->get_model()->GetTexture(TextureType::Diffuse,0),
object->get_model()->GetTexture(TextureType::Normal,0),
object->get_model()->GetTexture(TextureType::Specular,0),
lights_[0]->GetDirection(),
lights_[0]->GetDiffuseColor(),
camera_->get_position(),
@ -1926,11 +1909,11 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
case ShaderType::TEXTURE:
result = shader_manager_->render_texture_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0)
object->get_model()->GetTexture(TextureType::Diffuse,0)
);
if (!result)
{
@ -1942,11 +1925,11 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
case ShaderType::LIGHTING:
result = shader_manager_->renderlight_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0),
object->get_model()->GetTexture(TextureType::Diffuse,0),
diffuse,
position,
ambient
@ -1961,11 +1944,11 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
case ShaderType::SKYBOX:
result = shader_manager_->render_skybox_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0),
object->get_model()->GetTexture(TextureType::Diffuse,0),
sun_light_->GetDiffuseColor(),
sun_light_->GetAmbientColor(),
sun_light_->GetDirection(),
@ -1981,11 +1964,11 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
case ShaderType::SUNLIGHT:
result = shader_manager_->render_sunlight_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0),
object->get_model()->GetTexture(TextureType::Diffuse,0),
sun_light_->GetDiffuseColor(),
sun_light_->GetAmbientColor(),
sun_light_->GetDirection(),
@ -2001,11 +1984,11 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
default:
result = shader_manager_->renderlight_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->get_model()->GetIndexCount(),
worldMatrix,
view,
projection,
object->GetTexture(TextureType::Diffuse,0),
object->get_model()->GetTexture(TextureType::Diffuse,0),
diffuse,
position,
ambient
@ -2242,15 +2225,7 @@ void application_class::process_terrain_generation()
}
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 : terrain_chunk_)
{
if (chunk) {
chunk->Shutdown();
delete chunk;
}
}
terrain_chunk_.clear();
// Créer un conteneur de textures_ partagé

View File

@ -165,7 +165,7 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
// initialize the scene manager
scene_manager_ = new scene_manager;
if (!scene_manager_->initialize(app_)) {
if (!scene_manager_->initialize(app_.get())) {
Logger::Get().Log("Failed to initialize scene manager", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
@ -441,7 +441,7 @@ void imguiManager::WidgetObjectWindow()
// Compter combien de textures_ de ce type existent
int textureCount = 0;
while (object->GetTexture(type, textureCount) != nullptr)
while (object->get_model()->GetTexture(type, textureCount) != nullptr)
{
textureCount++;
}
@ -450,7 +450,7 @@ void imguiManager::WidgetObjectWindow()
ImGui::BeginGroup();
for (int texIndex = 0; texIndex < textureCount; texIndex++)
{
ID3D11ShaderResourceView* texture = object->GetTexture(type, texIndex);
ID3D11ShaderResourceView* texture = object->get_model()->GetTexture(type, texIndex);
if (texture)
{
// ID unique pour chaque bouton de texture
@ -477,7 +477,7 @@ void imguiManager::WidgetObjectWindow()
if (GetOpenFileName(&ofn))
{
// Changer la texture existante
object->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, type, texIndex);
object->get_model()->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, type, texIndex);
}
}
@ -515,7 +515,7 @@ void imguiManager::WidgetObjectWindow()
if (GetOpenFileName(&ofn))
{
// Ajouter une nouvelle texture
object->AddTexture(m_device, m_deviceContext, ofn.lpstrFile, type);
object->get_model()->AddTexture(m_device, m_deviceContext, ofn.lpstrFile, type);
}
}

View File

@ -24,6 +24,17 @@ object::~object()
{
}
bool object::Initialize(
ID3D11Device* device,
ID3D11DeviceContext* deviceContext,
char* modelFilename,
TextureContainer& texturesContainer
)
{
m_model_ = std::make_shared<model_class>();
return m_model_->Initialize(device, deviceContext, modelFilename, texturesContainer);
}
void object::SetScaleMatrix(XMMATRIX scaleMatrix)
{
m_scaleMatrix = scaleMatrix;

View File

@ -84,14 +84,7 @@ bool scene_manager::load_scene() {
Logger::Get().Log("Failed to open file for loading scene: ", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Nettoyer les objets existants
for (auto& obj : object_vec_) {
if (obj) {
obj->Shutdown();
delete obj;
}
}
object_vec_.clear();
object_id_ = 0;
@ -192,7 +185,7 @@ bool scene_manager::load_scene() {
}
// preload texture
if (!newObject->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), objectTextures))
if (!newObject->get_model()->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), objectTextures))
{
// Gérer l'erreur
return false;
@ -281,28 +274,28 @@ bool scene_manager::save_scene() {
// Même chose pour les autres types de textures_
// Textures diffuses
const auto& diffusePaths = object->GetTextureContainer().GetPaths(TextureType::Diffuse);
const auto& diffusePaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Diffuse);
outFile << " " << diffusePaths.size();
for (const auto& path : diffusePaths) {
outFile << " " << convert_w_string_to_string(path);
}
// Textures normales
const auto& normalPaths = object->GetTextureContainer().GetPaths(TextureType::Normal);
const auto& normalPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Normal);
outFile << " " << normalPaths.size();
for (const auto& path : normalPaths) {
outFile << " " << convert_w_string_to_string(path);
}
// Textures spéculaires
const auto& specularPaths = object->GetTextureContainer().GetPaths(TextureType::Specular);
const auto& specularPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Specular);
outFile << " " << specularPaths.size();
for (const auto& path : specularPaths) {
outFile << " " << convert_w_string_to_string(path);
}
// Textures alpha
const auto& alphaPaths = object->GetTextureContainer().GetPaths(TextureType::Alpha);
const auto& alphaPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Alpha);
outFile << " " << alphaPaths.size();
for (const auto& path : alphaPaths) {
outFile << " " << convert_w_string_to_string(path);

View File

@ -71,7 +71,7 @@ int stats::get_total_vertex_count() const
{
if (obj)
{
totalVertices += obj->GetVertexCount();
totalVertices += obj->get_model()->GetVertexCount();
}
}
// Ajoutez le nombre de sommets pour les cubes
@ -79,7 +79,7 @@ int stats::get_total_vertex_count() const
{
if (cube)
{
totalVertices += cube->GetVertexCount();
totalVertices += cube->get_model()->GetVertexCount();
}
}
// Ajoutez le nombre de sommets pour le terrain
@ -87,7 +87,7 @@ int stats::get_total_vertex_count() const
{
if (chunk)
{
totalVertices += chunk->GetVertexCount();
totalVertices += chunk->get_model()->GetVertexCount();
}
}
return totalVertices;
@ -101,7 +101,7 @@ int stats::get_total_triangle_count() const
if (obj)
{
// Dans une topologie de liste de triangles, chaque triangle utilise 3 indices
totalTriangles += obj->GetIndexCount() / 3;
totalTriangles += obj->get_model()->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles pour les cubes
@ -109,7 +109,7 @@ int stats::get_total_triangle_count() const
{
if (cube)
{
totalTriangles += cube->GetIndexCount() / 3;
totalTriangles += cube->get_model()->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles pour le terrain
@ -117,7 +117,7 @@ int stats::get_total_triangle_count() const
{
if (chunk)
{
totalTriangles += chunk->GetIndexCount() / 3;
totalTriangles += chunk->get_model()->GetIndexCount() / 3;
}
}
return totalTriangles;
@ -130,7 +130,7 @@ int stats::get_visible_triangle_count() const
{
if (obj && obj->IsVisible())
{
visibleTriangles += obj->GetIndexCount() / 3;
visibleTriangles += obj->get_model()->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles visibles pour les cubes
@ -138,7 +138,7 @@ int stats::get_visible_triangle_count() const
{
if (cube && cube->IsVisible())
{
visibleTriangles += cube->GetIndexCount() / 3;
visibleTriangles += cube->get_model()->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles visibles pour le terrain
@ -146,7 +146,7 @@ int stats::get_visible_triangle_count() const
{
if (chunk && chunk->IsVisible())
{
visibleTriangles += chunk->GetIndexCount() / 3;
visibleTriangles += chunk->get_model()->GetIndexCount() / 3;
}
}
return visibleTriangles;

View File

@ -20,27 +20,6 @@ system_class::system_class()
system_class::~system_class()
{
if (application_handle)
{
delete application_handle;
application_handle = 0;
}
if (input_)
{
delete input_;
input_ = 0;
}
if (imgui_manager_)
{
delete imgui_manager_;
imgui_manager_ = 0;
}
}
bool system_class::initialize()
@ -56,7 +35,7 @@ bool system_class::initialize()
initialize_windows(screenWidth, screenHeight);
// Create and initialize the input object. This object will be used to handle reading the keyboard input from the user.
input_ = new input_class;
input_ = std::make_shared<input_class>();
result = input_->Initialize(hinstance_, hwnd_, screenWidth, screenHeight);
if (!result)
@ -66,7 +45,7 @@ bool system_class::initialize()
}
// Create and initialize the application class object. This object will handle rendering all the graphics for this application.
application_ = new application_class;
application_ = std::make_shared<application_class>();
result = application_->initialize(screenWidth, screenHeight, hwnd_, false);
if (!result)
@ -85,7 +64,7 @@ bool system_class::initialize()
// initialize imgui
if(DEBUG_MODE)
{
imgui_manager_ = new imguiManager;
imgui_manager_ = std::make_shared<imguiManager>();
imgui_manager_->SetApp(application_);
result = imgui_manager_->Initialize(hwnd_, application_->get_direct_3d()->get_device(), application_->get_direct_3d()->get_device_context());
if (!result)
@ -112,49 +91,11 @@ void system_class::shutdown()
std::lock_guard<std::mutex> guard(render_mutex_);
// shutdown imgui
if (imgui_manager_)
{
Logger::Get().Log("Shutting down imgui manager", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
imgui_manager_->Shutdown();
delete imgui_manager_;
imgui_manager_ = 0;
Logger::Get().Log("Imgui manager shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the application class object.
if (application_)
{
Logger::Get().Log("Shutting down application", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
application_->shutdown();
delete application_;
application_ = 0;
Logger::Get().Log("Application shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the input object.
if (input_)
{
Logger::Get().Log("Shutting down input", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
delete input_;
input_ = 0;
Logger::Get().Log("Input shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// shutdown the window.
shutdown_windows();
Logger::Get().Log("System class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
return;
}
void system_class::run()
@ -224,7 +165,7 @@ bool system_class::frame()
}
// Do the frame processing for the application class object.
result = application_->frame(input_);
result = application_->frame(input_.get());
if (!result)
{
Logger::Get().Log("Failed to process application frame", __FILE__, __LINE__, Logger::LogLevel::Error);