From 040d919b69e78315c40723459e6235d709d191f9 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Sun, 2 Nov 2025 01:22:50 +0100 Subject: [PATCH] =?UTF-8?q?Minor=20-=20Optimise=20l'acc=C3=A8s=20aux=20res?= =?UTF-8?q?sources=20D3D=20-=20V14.10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactorise l'accès aux interfaces Direct3D pour plus de clarté et d'efficacité, en utilisant des accesseurs `const` et en déplaçant certaines fonctions directement dans l'en-tête. Cela simplifie l'utilisation des ressources D3D et améliore la lisibilité du code. --- enginecustom/src/inc/system/d_3d_class.h | 23 +++++++--- enginecustom/src/inc/system/macro.h | 2 +- enginecustom/src/inc/system/system_class.h | 2 - enginecustom/src/src/system/d_3d_class.cpp | 48 +------------------- enginecustom/src/src/system/system_class.cpp | 31 ++++--------- x64/Debug/config.txt | 2 +- x64/Release/config.txt | 2 +- 7 files changed, 31 insertions(+), 79 deletions(-) diff --git a/enginecustom/src/inc/system/d_3d_class.h b/enginecustom/src/inc/system/d_3d_class.h index af15be5..7fc3c43 100644 --- a/enginecustom/src/inc/system/d_3d_class.h +++ b/enginecustom/src/inc/system/d_3d_class.h @@ -75,20 +75,20 @@ public: * * @return Pointer to the ID3D11Device interface. */ - ID3D11Device* get_device(); + ID3D11Device* get_device() const { return device_; }; /** * @brief Gets the Direct3D device context. * * @return Pointer to the ID3D11DeviceContext interface. */ - ID3D11DeviceContext* get_device_context(); + ID3D11DeviceContext* get_device_context() const { return device_context_; }; //XMMATRIX get_projection_matrix(XMMATRIX& projectionMatrix); IDXGISwapChain* swap_chain; /** * Get the swap chain associated with the Direct3D device. * @return Pointer to the IDXGISwapChain interface. */ - IDXGISwapChain* get_swap_chain(); + IDXGISwapChain* get_swap_chain() const { return swap_chain; }; /** * Resizes the swap chain to the specified width and height. * @param width New width of the swap chain. @@ -100,7 +100,7 @@ public: * * @param vsync True to enable vertical sync, false to disable. */ - void set_vsync(bool vsync); + void set_vsync(bool vsync) { vsync_enabled_ = vsync; }; /** * Get the projection matrix. @@ -135,7 +135,10 @@ public: /** * Resets the viewport to the default settings. */ - void reset_viewport(); + void reset_viewport() const + { + device_context_->RSSetViewports(1, &viewport_); + } /** * Release all Direct3D resources. @@ -151,11 +154,17 @@ public: /** * Turn on the Z-buffer to enable depth. */ - void turn_z_buffer_on(); + void turn_z_buffer_on()const + { + device_context_->OMSetDepthStencilState(depth_stencil_state_, 1); + } /** * Turn off the Z-buffer to disable depth. */ - void turn_z_buffer_off(); + void turn_z_buffer_off() const + { + device_context_->OMSetDepthStencilState(depth_disabled_stencil_state_, 1); + } /** * Turn on alpha blending for transparency effects. diff --git a/enginecustom/src/inc/system/macro.h b/enginecustom/src/inc/system/macro.h index d4bb6b7..012041d 100644 --- a/enginecustom/src/inc/system/macro.h +++ b/enginecustom/src/inc/system/macro.h @@ -69,7 +69,7 @@ inline int size_t_to_int(size_t x) #define LOG_SHUTDOWN(msg) ((void)0) #define LOG_INIT(msg) ((void)0) -#define R_LOG_ERROR(result,msg) ((void)0) +#define R_LOG_ERROR(result,msg) ((void)0); #endif diff --git a/enginecustom/src/inc/system/system_class.h b/enginecustom/src/inc/system/system_class.h index 43a54fd..222e03b 100644 --- a/enginecustom/src/inc/system/system_class.h +++ b/enginecustom/src/inc/system/system_class.h @@ -3,8 +3,6 @@ #define WIN32_LEAN_AND_MEAN -static bool DEBUG_MODE = true; - #include "Logger.h" #include "input_class.h" diff --git a/enginecustom/src/src/system/d_3d_class.cpp b/enginecustom/src/src/system/d_3d_class.cpp index cd8b54d..00cf824 100644 --- a/enginecustom/src/src/system/d_3d_class.cpp +++ b/enginecustom/src/src/system/d_3d_class.cpp @@ -555,21 +555,9 @@ void d_3d_class::end_scene() return; } - -ID3D11Device* d_3d_class::get_device() +void d_3d_class::get_video_card_info(char* description, int& memory) { - return device_; -} - - -ID3D11DeviceContext* d_3d_class::get_device_context() -{ - return device_context_; -} - -void d_3d_class::get_video_card_info(char* cardName, int& memory) -{ - strcpy_s(cardName, 128, video_card_description_); + strcpy_s(description, 128, video_card_description_); memory = video_card_memory_; return; } @@ -583,15 +571,6 @@ void d_3d_class::set_back_buffer_render_target() return; } - -void d_3d_class::reset_viewport() -{ - // Set the viewport. - device_context_->RSSetViewports(1, &viewport_); - - return; -} - void d_3d_class::release_resources() { LOG_SHUTDOWN("Releasing D3D resources"); @@ -689,11 +668,6 @@ void d_3d_class::reset_resources(int newWidth, int newHeight) device_context_->OMSetRenderTargets(1, &render_target_view_, depth_stencil_view_); } -IDXGISwapChain* d_3d_class::get_swap_chain() -{ - return swap_chain; -} - void d_3d_class::resize_swap_chain(int newWidth, int newHeight) { LOG_INFO("Resizing swap chain to " + std::to_string(newWidth) + "x" + std::to_string(newHeight)); @@ -721,19 +695,6 @@ void d_3d_class::resize_swap_chain(int newWidth, int newHeight) device_context_->RSSetViewports(1, &viewport_); } -void d_3d_class::turn_z_buffer_on() -{ - device_context_->OMSetDepthStencilState(depth_stencil_state_, 1); - return; -} - - -void d_3d_class::turn_z_buffer_off() -{ - device_context_->OMSetDepthStencilState(depth_disabled_stencil_state_, 1); - return; -} - void d_3d_class::enable_alpha_blending() { float blendFactor[4]; @@ -768,11 +729,6 @@ void d_3d_class::disable_alpha_blending() return; } -void d_3d_class::set_vsync(bool vsync) -{ - vsync_enabled_ = vsync; -} - bool d_3d_class::set_projection_params(int width, int height, float screenDepth, float screenNear) { float fieldOfView, screenAspect; diff --git a/enginecustom/src/src/system/system_class.cpp b/enginecustom/src/src/system/system_class.cpp index 0800404..badfcab 100644 --- a/enginecustom/src/src/system/system_class.cpp +++ b/enginecustom/src/src/system/system_class.cpp @@ -61,17 +61,16 @@ bool system_class::initialize() application_->get_direct_3d()->resize_swap_chain(initial_window_width_, initial_window_height_); } +#ifdef _DEBUG // initialize imgui - if(DEBUG_MODE) + imgui_manager_ = std::make_shared(); + imgui_manager_->SetApp(application_); + result = imgui_manager_->Initialize(hwnd_, application_->get_direct_3d()->get_device(), application_->get_direct_3d()->get_device_context()); + if (!result) { - imgui_manager_ = std::make_shared(); - imgui_manager_->SetApp(application_); - result = imgui_manager_->Initialize(hwnd_, application_->get_direct_3d()->get_device(), application_->get_direct_3d()->get_device_context()); - if (!result) - { - R_FALSE - } + R_FALSE } +#endif } catch (const std::exception& e) @@ -177,19 +176,8 @@ bool system_class::frame() R_FALSE } - if(!input_->IsKeyDown(222)) - { - //log the key press - is_debug_key_pressed_ = false; - } - else if (input_->IsKeyDown(222) && !is_debug_key_pressed_) - { - // Log the key release state - is_debug_key_pressed_ = true; - DEBUG_MODE = !DEBUG_MODE; - } - - if (DEBUG_MODE) +#ifdef _DEBUG + if (input_->IsKeyDown(DIK_F1)) { // render ImGui result = imgui_manager_->ImGuiWidgetRenderer(); @@ -199,6 +187,7 @@ bool system_class::frame() R_FALSE } } +#endif application_->get_direct_3d()->end_scene(); diff --git a/x64/Debug/config.txt b/x64/Debug/config.txt index 77c665a..d848296 100644 --- a/x64/Debug/config.txt +++ b/x64/Debug/config.txt @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:844d37e56d8020360b0ba0507c8c450508001232980e7d0792367356ec4b1f55 +oid sha256:1c2af19db109f13e771e4254af6c38566486f644df1404a0564dad6082a54ee7 size 9 diff --git a/x64/Release/config.txt b/x64/Release/config.txt index 77c665a..d848296 100644 --- a/x64/Release/config.txt +++ b/x64/Release/config.txt @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:844d37e56d8020360b0ba0507c8c450508001232980e7d0792367356ec4b1f55 +oid sha256:1c2af19db109f13e771e4254af6c38566486f644df1404a0564dad6082a54ee7 size 9