From cd04f994f137ebf9f0244dc51f19a38dae64bbcf Mon Sep 17 00:00:00 2001 From: korenkonder Date: Sun, 18 Aug 2024 00:54:01 +0300 Subject: [PATCH] Removed `lock_cs` --- src/CRE/lock.cpp | 6 --- src/CRE/lock.hpp | 41 ------------------- src/CRE/ogg_vorbis.hpp | 1 - src/ReDIVA/app.cpp | 35 +--------------- src/ReDIVA/classes.hpp | 1 - .../classes/graphics/render_settings.cpp | 1 - src/ReDIVA/input.cpp | 3 -- src/ReDIVA/task_window.hpp | 1 - 8 files changed, 1 insertion(+), 88 deletions(-) delete mode 100644 src/CRE/lock.cpp delete mode 100644 src/CRE/lock.hpp diff --git a/src/CRE/lock.cpp b/src/CRE/lock.cpp deleted file mode 100644 index 1422d62f..00000000 --- a/src/CRE/lock.cpp +++ /dev/null @@ -1,6 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#include "lock.hpp" diff --git a/src/CRE/lock.hpp b/src/CRE/lock.hpp deleted file mode 100644 index e0dc5ffe..00000000 --- a/src/CRE/lock.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#pragma once - -#include "../KKdLib/default.hpp" - -struct lock_cs { - CRITICAL_SECTION cs; - bool init; - - inline lock_cs() : cs() { - init = InitializeCriticalSectionAndSpinCount(&cs, 0); - } - - inline ~lock_cs() { - if (init) - DeleteCriticalSection(&cs); - cs = {}; - init = false; - } - - inline bool check_init() { - if (!this) - return false; - return init; - } -}; - -#define lock_lock(val) \ -if ((val) && (val)->init) { \ -EnterCriticalSection(&(val)->cs) - -#define lock_trylock(val) \ -if ((val) && (val)->init && TryEnterCriticalSection(&(val)->cs)) { - -#define lock_unlock(val) \ -LeaveCriticalSection(&(val)->cs); \ -} diff --git a/src/CRE/ogg_vorbis.hpp b/src/CRE/ogg_vorbis.hpp index fed64794..5c384e14 100644 --- a/src/CRE/ogg_vorbis.hpp +++ b/src/CRE/ogg_vorbis.hpp @@ -7,7 +7,6 @@ #include "../KKdLib/default.hpp" #include "../KKdLib/waitable_timer.hpp" -#include "lock.hpp" #include "sound.hpp" #include #include diff --git a/src/ReDIVA/app.cpp b/src/ReDIVA/app.cpp index cfb4f420..5959bfea 100644 --- a/src/ReDIVA/app.cpp +++ b/src/ReDIVA/app.cpp @@ -25,7 +25,6 @@ #include "../CRE/gl_state.hpp" #include "../CRE/hand_item.hpp" #include "../CRE/light_param.hpp" -#include "../CRE/lock.hpp" #include "../CRE/mdata_manager.hpp" #include "../CRE/module_table.hpp" #include "../CRE/object.hpp" @@ -226,11 +225,9 @@ static void APIENTRY render_debug_output(GLenum source, GLenum type, uint32_t id bool close; bool reload_render; -lock_cs* render_lock; HWND window_handle; GLFWwindow* window; ImGuiContext* imgui_context; -lock_cs* imgui_context_lock; bool global_context_menu; render_context* rctx_ptr; bool task_stage_is_modern; @@ -242,10 +239,6 @@ HANDLE d3d_gl_handle; #endif int32_t app_main(const app_init_struct& ais) { - render_lock = new lock_cs; - if (!render_lock) - return 0; - #if BAKE_FAST render_timer = new timer(600.0); #else @@ -303,10 +296,7 @@ int32_t app_main(const app_init_struct& ais) { close = false; reload_render = false; - render_context* rctx = 0; - lock_lock(render_lock); - rctx = render_context_load(); - lock_unlock(render_lock); + render_context* rctx = render_context_load(); #if !(BAKE_PNG || BAKE_VIDEO) glfwGetFramebufferSize(window, &width, &height); @@ -322,17 +312,13 @@ int32_t app_main(const app_init_struct& ais) { app_main_loop(rctx); - lock_lock(render_lock); render_context_dispose(rctx); - lock_unlock(render_lock); } while (reload_render); } app_free(); glfwTerminate(); - delete render_lock; - render_lock = 0; delete render_timer; render_timer = 0; return 0; @@ -541,9 +527,7 @@ static void app_main_loop(render_context* rctx) { Input::NewFrame(); - lock_lock(render_lock); render_context_ctrl(rctx); - lock_unlock(render_lock); render_context_disp(rctx); close |= !!glfwWindowShouldClose(window); @@ -1077,13 +1061,11 @@ static render_context* render_context_load() { render_timer->reset(); for (int32_t i = 0; i < 30; i++) { render_timer->start_of_cycle(); - lock_lock(render_lock); game_state_ctrl(); app::TaskWork::ctrl(); sound_ctrl(); file_handler_storage_ctrl(); app::TaskWork::basic(); - lock_unlock(render_lock); render_timer->end_of_cycle(); } @@ -1101,8 +1083,6 @@ static render_context* render_context_load() { uniform_value[U16] = 1; - imgui_context_lock = new lock_cs; - lock_lock(imgui_context_lock); imgui_context = ImGui::CreateContext(); ImGui::SetCurrentContext(imgui_context); ImGuiIO& io = ImGui::GetIO(); @@ -1130,7 +1110,6 @@ static render_context* render_context_load() { ImGui::StyleColorsDark(); ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init("#version 430"); - lock_unlock(imgui_context_lock); clear_color = 0xFF000000; set_clear_color = true; @@ -1164,11 +1143,9 @@ static void render_context_ctrl(render_context* rctx) { } global_context_menu = true; - lock_lock(imgui_context_lock); ImGui::SetCurrentContext(imgui_context); app::TaskWork_window(); classes_process_imgui(classes, classes_count); - lock_unlock(imgui_context_lock); if (old_width != width || old_height != height || old_scale_index != scale_index) app_resize_fb(rctx, true); @@ -1176,7 +1153,6 @@ static void render_context_ctrl(render_context* rctx) { old_height = height; old_scale_index = scale_index; - lock_lock(imgui_context_lock); ImGui::SetCurrentContext(imgui_context); if (global_context_menu && ImGui::IsMouseReleased(ImGuiMouseButton_Right) && !ImGui::IsItemHovered(0) && imgui_context->OpenPopupStack.Size < 1) @@ -1186,7 +1162,6 @@ static void render_context_ctrl(render_context* rctx) { render_imgui_context_menu(classes, classes_count, rctx); ImGui::EndPopup(); } - lock_unlock(imgui_context_lock); if (window_handle == GetForegroundWindow()) { if (input_reset) { @@ -1354,10 +1329,8 @@ static void render_context_disp(render_context* rctx) { } static void render_context_imgui(render_context* rctx) { - lock_lock(imgui_context_lock); ImGui::SetCurrentContext(imgui_context); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - lock_unlock(imgui_context_lock); } static void render_context_dispose(render_context* rctx) { @@ -1365,11 +1338,7 @@ static void render_context_dispose(render_context* rctx) { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); - lock_lock(imgui_context_lock); ImGui::DestroyContext(imgui_context); - lock_unlock(imgui_context_lock); - delete imgui_context_lock; - imgui_context_lock = 0; Glitter::glt_particle_manager_del_task(); @@ -1415,13 +1384,11 @@ static void render_context_dispose(render_context* rctx) { render_timer->reset(); while (app::task_work->tasks.size()) { render_timer->start_of_cycle(); - lock_lock(render_lock); game_state_ctrl(); app::TaskWork::ctrl(); sound_ctrl(); file_handler_storage_ctrl(); app::TaskWork::basic(); - lock_unlock(render_lock); render_timer->end_of_cycle(); } diff --git a/src/ReDIVA/classes.hpp b/src/ReDIVA/classes.hpp index eebca177..a7410516 100644 --- a/src/ReDIVA/classes.hpp +++ b/src/ReDIVA/classes.hpp @@ -6,7 +6,6 @@ #pragma once #include "../KKdLib/default.hpp" -#include "../CRE/lock.hpp" #include "../CRE/render_context.hpp" #define CLASS_DATA_NO_DATA (0) diff --git a/src/ReDIVA/classes/graphics/render_settings.cpp b/src/ReDIVA/classes/graphics/render_settings.cpp index 64e7e118..ff0578ac 100644 --- a/src/ReDIVA/classes/graphics/render_settings.cpp +++ b/src/ReDIVA/classes/graphics/render_settings.cpp @@ -4,7 +4,6 @@ */ #include "render_settings.hpp" -#include "../../../CRE/lock.hpp" #include "../../../KKdLib/timer.hpp" #include "../../app.hpp" #include "../../imgui_helper.hpp" diff --git a/src/ReDIVA/input.cpp b/src/ReDIVA/input.cpp index 651a29ea..8f8b9787 100644 --- a/src/ReDIVA/input.cpp +++ b/src/ReDIVA/input.cpp @@ -8,7 +8,6 @@ #include "input.hpp" #include "../KKdLib/timer.hpp" #include "../KKdLib/vec.hpp" -#include "../CRE/lock.hpp" #include #include #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS @@ -28,11 +27,9 @@ bool input_reset_mouse_position; bool input_locked; extern bool close; -extern lock_cs render_lock; extern timer* render_timer; extern HWND window_handle; extern ImGuiContext* imgui_context; -extern lock_cs imgui_context_lock; extern uint8_t disable_input_state_update; extern bool disable_cursor; diff --git a/src/ReDIVA/task_window.hpp b/src/ReDIVA/task_window.hpp index 4f200374..f0f23724 100644 --- a/src/ReDIVA/task_window.hpp +++ b/src/ReDIVA/task_window.hpp @@ -6,7 +6,6 @@ #pragma once #include "../KKdLib/default.hpp" -#include "../CRE/lock.hpp" #include "../CRE/render_context.hpp" #include "../CRE/task.hpp"