From 3335ac4cfda08325bc59a2b9cb73c6b861ab6dfc Mon Sep 17 00:00:00 2001 From: Musa Date: Thu, 18 Dec 2025 21:04:19 -0500 Subject: [PATCH] Fix build in release mode. --- CMakeLists.txt | 5 +-- README.md | 38 +++++++++++++++-- exe_main.cpp | 5 ++- lib/Base/Arena.cpp | 6 +++ lib/Base/Base.h | 4 ++ lib/Base/General_Purpose_Allocator.cpp | 1 + lib/Base/Timing.h | 4 ++ lib/OS/OS_Win32.cpp | 9 +++- src/Base_Entry_Point.cpp | 1 + src/Ex1.cpp | 59 +++++++++----------------- src/explorer_main.cpp | 2 +- 11 files changed, 83 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f2e906..72c4c42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,9 +46,6 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release") ) endif() -SET (SYSTEM_LIBRARIES -) - add_executable(${EXE_NAME} ${SRC_FILES}) target_include_directories(${EXE_NAME} PRIVATE ${INCLUDE_DIRS}) -target_link_libraries(${EXE_NAME} PRIVATE ${LINK_LIBS_DIRS} ${SYSTEM_LIBRARIES}) +target_link_libraries(${EXE_NAME} PRIVATE ${LINK_LIBS_DIRS}) diff --git a/README.md b/README.md index 998067d..ca51549 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +# Build Overview + +- #TODO: Explain build configuration: library, exe +- Why do we use CMake (even though I hate it)? (because it's industry standard?) +- Plans to use a metaprogram to modify code for certain reasons (e.g. getting stack traces) + ## Configuration This project uses CMake to configure and build. Currently only Win32 is supported. ``` @@ -7,8 +13,32 @@ cmake -S . -B build ``` cmake --build build --config Debug ``` - +## Roadmap for Supporting Other platforms + +- Linux +- MacOS +- Android +- iOS + +# APIs + +## Base Layer + +### Thread-local Context + +## OS Platform Layer + +## Debug Tooling + + + +# Explorer Application Notes + +## File Enumeration + +## Sorting + +## Searching Algorithms + +## Multithreading \ No newline at end of file diff --git a/exe_main.cpp b/exe_main.cpp index f265224..968d70a 100644 --- a/exe_main.cpp +++ b/exe_main.cpp @@ -1,7 +1,7 @@ -// Treat library files as a single-file (single translation unit) header +// Treat library files as a single-file header (single translation unit) #include "lib_main.cpp" -#define BASE_RUN_TESTS BUILD_DEBUG +#define BASE_RUN_TESTS 0 #define BUILD_EXPLORER_APP_WIN32 1 #define BUILD_CUSTOM_GUI 0 @@ -17,6 +17,7 @@ #pragma comment(lib, "d3d11.lib") #pragma comment(lib, "dxgi.lib") + #pragma comment(lib, "msvcrt.lib") #include "lib/third_party/dear-imgui/imgui.h" #include "lib/third_party/dear-imgui/imgui_impl_win32.h" diff --git a/lib/Base/Arena.cpp b/lib/Base/Arena.cpp index 508d40f..80b4c6a 100644 --- a/lib/Base/Arena.cpp +++ b/lib/Base/Arena.cpp @@ -325,20 +325,26 @@ void* fixed_arena_allocator_proc (Allocator_Mode mode, s64 requested_size, s64 o } force_inline void initialize_arenas_in_use_list () { +#if BUILD_DEBUG if (arenas_in_use.allocated > 0) return; mutex_init(&arenas_in_use_mutex); arenas_in_use.allocator = default_allocator(); array_reserve(arenas_in_use, 256); +#endif } force_inline void add_arena_to_in_use_list (Arena* arena) { +#if BUILD_DEBUG Assert(arenas_in_use.allocated > 0); // check we initialized! lock_guard(&arenas_in_use_mutex); array_add(arenas_in_use, arena); +#endif } force_inline void remove_arena_from_in_use_list (Arena* arena) { +#if BUILD_DEBUG Assert(arenas_in_use.allocated > 0); // check we initialized! lock_guard(&arenas_in_use_mutex); array_unordered_remove_by_value(arenas_in_use, arena, 1); +#endif } diff --git a/lib/Base/Base.h b/lib/Base/Base.h index f95c7af..dadda52 100644 --- a/lib/Base/Base.h +++ b/lib/Base/Base.h @@ -139,10 +139,14 @@ static const int __arch_endian_check_num = 1; #if defined(_MSC_VER) #ifdef _DEBUG #define BUILD_DEBUG 1 + #else + #define BUILD_DEBUG 0 #endif #elif defined(__GNUC__) || defined(__clang__) #ifndef NDEBUG #define BUILD_DEBUG 1 + #else + #define BUILD_DEBUG 0 #endif #endif diff --git a/lib/Base/General_Purpose_Allocator.cpp b/lib/Base/General_Purpose_Allocator.cpp index c5f9d9c..f2b985c 100644 --- a/lib/Base/General_Purpose_Allocator.cpp +++ b/lib/Base/General_Purpose_Allocator.cpp @@ -1,6 +1,7 @@ #if GP_ALLOCATOR_TRACK_ALLOCATIONS global General_Allocator gAllocator; // @Shared global Mutex allocator_mutex; + global bool default_allocator_show_small_allocations = true; #endif #if !COMPILER_MSVC diff --git a/lib/Base/Timing.h b/lib/Base/Timing.h index 43d44a6..209d2ce 100644 --- a/lib/Base/Timing.h +++ b/lib/Base/Timing.h @@ -79,6 +79,10 @@ string format_bytes (s64 bytes, s32 trailing_width = 3) { unit_index += 1; } + // This makes the trailing width param kinda pointless... idk. + if (unit_index == 0) trailing_width = 0; + // if (unit_index == 1) trailing_width = 2; + switch (trailing_width) { case 0: return format_string("%.0f %s", count_f64, units[unit_index].data); case 1: return format_string("%.1f %s", count_f64, units[unit_index].data); diff --git a/lib/OS/OS_Win32.cpp b/lib/OS/OS_Win32.cpp index a5d2754..702243b 100644 --- a/lib/OS/OS_Win32.cpp +++ b/lib/OS/OS_Win32.cpp @@ -1088,8 +1088,13 @@ bool Win32_Discover_Drives () { Win32_Max_Path_Length, &serial_number, &max_comp_len, &file_system_flags, (LPWSTR)file_system_name, Win32_Max_Path_Length)) { drive->label = drive_label; - drive->volume_name = wide_to_utf8(volume_name); - if (drive->volume_name == "") { drive->volume_name = copy_string("Local Disk"); } + if (volume_name[0] == 0) { + drive->volume_name = copy_string("Local Disk"); + } else { + drive->volume_name = wide_to_utf8(volume_name); + } + if (drive->volume_name == "") { drive->volume_name = copy_string("Local Disk"); } // Probably redundant?? + drive->type = (Win32_Drive_Type)drive_type; { push_allocator(temp()); drive->file_system = Win32_filesystem_from_string(wide_to_utf8(file_system_name)); diff --git a/src/Base_Entry_Point.cpp b/src/Base_Entry_Point.cpp index 6e8fc13..cd3b845 100644 --- a/src/Base_Entry_Point.cpp +++ b/src/Base_Entry_Point.cpp @@ -7,6 +7,7 @@ internal void Main_Entry_Point (int argc, WCHAR **argv); return 0; } #else + #pragma comment(linker, "/SUBSYSTEM:WINDOWS") #include // globals __argc, __wargv int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { diff --git a/src/Ex1.cpp b/src/Ex1.cpp index 0919965..349c09a 100644 --- a/src/Ex1.cpp +++ b/src/Ex1.cpp @@ -50,6 +50,9 @@ bool Ex1_Register_Global_Hotkeys () { global Key_Combination program_exit_hotkey { ImGuiKey_W, USE_CTRL, USE_SHIFT, KEY_UNUSED, TRIGGER_ONCE }; global Key_Combination program_minimize_hotkey { ImGuiKey_W, USE_CTRL, KEY_UNUSED, KEY_UNUSED, TRIGGER_ONCE }; +global Key_Combination decrease_font_size_hotkey { ImGuiKey_Minus, USE_CTRL, KEY_UNUSED, KEY_UNUSED, TRIGGER_ONCE }; +global Key_Combination increase_font_size_hotkey { ImGuiKey_Equal, USE_CTRL, KEY_UNUSED, KEY_UNUSED, TRIGGER_ONCE }; + bool Ex1_check_key_combinations() { update_global_keyboard_state(); // #program_hotkeys @@ -59,6 +62,12 @@ bool Ex1_check_key_combinations() { if (check_key_combination(&program_minimize_hotkey)) { Win32_Minimize_Window_To_Tray(get_main_window_pointer()); } + if (check_key_combination(&decrease_font_size_hotkey)) { // see ImGui_Show_Font_Info. + imgui_default_font.current_size = clamp(imgui_default_font.current_size - 1, 0, 5); + } + if (check_key_combination(&increase_font_size_hotkey)) { + imgui_default_font.current_size = clamp(imgui_default_font.current_size + 1, 0, 5); + } // #Ex1_hotkeys return false; } @@ -224,12 +233,12 @@ void Ex1_Control_Panel () { using namespace ImGui; // bool all_drives_enumerated = !ex1_ntfs.threads_in_flight.count // && (drives_enumerated == drives.count); - // string file_path = format_string_temp("%s_DriveData.bin", os_get_machine_name().data); - string file_path = "D:/TempSync/Filesystem_Data/MUSA-PC3_DriveData.bin"; + string file_path = format_string_temp("D:/TempSync/Filesystem_Data/%s_DriveData.bin", os_get_machine_name().data); + // string file_path = "D:/TempSync/Filesystem_Data/MUSA-PC3_DriveData.bin"; Text("fixed file_path: %s", file_path.data); - // if (!all_drives_enumerated && file_exists(file_path)) { // #autoload - // Deserialize_ST_File_Enumeration(file_path); - // } + if (!all_drives_enumerated && file_exists(file_path)) { // #autoload + Deserialize_ST_File_Enumeration(file_path); + } if (drives.count > 0 && !all_drives_enumerated && file_exists(file_path) && Button("Load from file (this machine)")) { Deserialize_ST_File_Enumeration(file_path); // Deserialize_Win32_Drives(file_path); @@ -303,47 +312,21 @@ void ImGui_Debug_Panel () { using namespace ImGui; Begin("Debug Panel"); // #cpuid Text("[cpus] physical: %d, logical: %d, primary: %d, secondary: %d", os_cpu_physical_core_count(), os_cpu_logical_core_count(), os_cpu_primary_core_count(), os_cpu_secondary_core_count()); - /*{ SeparatorText("Arena In-Use List"); - lock_guard(&arena_free_list->mutex); - for (u8 i = 0; i < Arena_Reserve_Count; i += 1) { - #if ARENA_DEBUG - auto t = format_cstring( - " [%s] in_use: %d, committed_bytes: %s", - format_bytes(Arena_Sizes[i], 0).data, - arena_free_list->in_flight_count[i], - format_bytes(committed_bytes(arena_free_list->in_flight[i])).data - ); - #else - auto t = format_cstring( - " [%s] in_use: %d, committed_bytes: %s", - format_bytes(Arena_Sizes[i], 0).data, - arena_free_list->in_flight_count[i], - "disabled in release mode" - ); - #endif - Text(t); - } - SeparatorText("Arena Free List"); - for (u8 i = 0; i < Arena_Reserve_Count; i += 1) { - auto t = format_cstring( - " [%s] free: %d, committed_bytes: %s", - format_bytes(Arena_Sizes[i], 0).data, - (s32)arena_free_list->free_table[i].count, - format_bytes(committed_bytes(arena_free_list->free_table[i])).data - ); - Text(t); - } - }*/ #if BUILD_DEBUG SeparatorText("Default Allocator Allocations"); { lock_guard(&allocator_mutex); + // Replace this with two sliders min and max to filter allocations? + Checkbox("Show small allocations (<1kB)", &default_allocator_show_small_allocations); auto allocations = to_view(get_general_allocator_data()->allocations); Text("%s in %lld allocations", format_bytes(get_general_allocator_data()->total_bytes_allocated).data, allocations.count); for_each(a, allocations) { - Text(" [%lld] ptr: %p (size: %lld, alignment: %d)", - a, allocations[a].memory, allocations[a].size, allocations[a].alignment); + if (!default_allocator_show_small_allocations && allocations[a].size < 1024) { + continue; + } + Text(" [%lld] ptr: %p (size: %s, alignment: %d)", + a, allocations[a].memory, format_bytes(allocations[a].size).data, allocations[a].alignment); } } SeparatorText("Arenas in Use"); diff --git a/src/explorer_main.cpp b/src/explorer_main.cpp index 349421c..757bf8b 100644 --- a/src/explorer_main.cpp +++ b/src/explorer_main.cpp @@ -151,7 +151,7 @@ void Explorer_ImGui_Application_Win32 () { ImGui_Debug_Panel(); Ex1_Control_Panel(); - ImGui_Show_Font_Info(); + // ImGui_Show_Font_Info(); ImGui_Pop_Default_Font();