diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f2e906..22f1bb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,9 +46,15 @@ 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}) + +message(STATUS "Build type: $") + +add_custom_command(TARGET ${EXE_NAME} POST_BUILD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -E echo "Running post-build script..." + COMMAND cmd.exe /c "${CMAKE_SOURCE_DIR}/copy_files.cmd" $ + COMMENT "Running custom post-build script." +) diff --git a/README.md b/README.md index 998067d..ebd8fc8 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,49 @@ +# 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. ``` cmake -S . -B build ``` ## Build +To build in debug mode: ``` 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/copy_files.cmd b/copy_files.cmd new file mode 100644 index 0000000..5e2da59 --- /dev/null +++ b/copy_files.cmd @@ -0,0 +1,17 @@ +@echo off +set CONFIG=%1 +echo Build configuration is: %CONFIG% + +if /i "%CONFIG%"=="Debug" ( + echo Copying files to debug directory + copy /Y "extras\fonts\RobotoMono-Regular.ttf" "build\Debug\RobotoMono-Regular.ttf" + copy /Y "extras\icons\tmp.ico" "build\Debug\tmp.ico" + copy /Y "extras\icons\tmp_min.ico" "build\Debug\tmp_min.ico" + :: #TODO: Copy DLLs: Varjo + rem copy /Y "third_party\bin\some_dll.dll" "build/Debug\some_dll.dll" +) else if /i "%CONFIG%"=="Release" ( + echo Copying files to release directory + copy /Y "extras\fonts\RobotoMono-Regular.ttf" "build\Release\RobotoMono-Regular.ttf" + copy /Y "extras\icons\tmp.ico" "build\Release\tmp.ico" + copy /Y "extras\icons\tmp_min.ico" "build\Release\tmp_min.ico" +) 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/extras/imgui.ini b/extras/imgui.ini index d0a73d8..6e4d097 100644 --- a/extras/imgui.ini +++ b/extras/imgui.ini @@ -26,12 +26,12 @@ Collapsed=0 [Window][WindowOverViewport_11111111] Pos=0,0 -Size=4533,1681 +Size=3391,1672 Collapsed=0 [Window][Font Settings] -Pos=0,1565 -Size=3372,116 +Pos=0,1556 +Size=1371,116 Collapsed=0 DockId=0x00000001,0 @@ -41,30 +41,30 @@ Size=691,540 Collapsed=0 [Window][Debug Panel] -Pos=3374,0 -Size=1159,816 +Pos=1374,0 +Size=2017,1269 Collapsed=0 DockId=0x00000005,0 [Window][Control Panel] -Pos=3374,818 -Size=1159,863 +Pos=1374,1272 +Size=2017,400 Collapsed=0 DockId=0x00000006,0 [Window][Enumerated Data Workspace] Pos=0,0 -Size=3372,1563 +Size=1371,1672 Collapsed=0 DockId=0x00000002,0 [Docking][Data] -DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=294,254 Size=4533,1681 Split=X Selected=0x1FC7AC8C - DockNode ID=0x00000003 Parent=0x08BD597D SizeRef=3372,1672 Split=Y +DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=225,261 Size=3391,1672 Split=X Selected=0x1FC7AC8C + DockNode ID=0x00000003 Parent=0x08BD597D SizeRef=1371,1672 Split=Y DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1582,1553 CentralNode=1 Selected=0x671FC263 DockNode ID=0x00000001 Parent=0x00000003 SizeRef=1582,116 Selected=0x355F9D19 - DockNode ID=0x00000004 Parent=0x08BD597D SizeRef=1159,1672 Split=Y Selected=0xD2C573A7 - DockNode ID=0x00000005 Parent=0x00000004 SizeRef=1351,536 Selected=0xD2C573A7 - DockNode ID=0x00000006 Parent=0x00000004 SizeRef=1351,567 Selected=0xF930105C + DockNode ID=0x00000004 Parent=0x08BD597D SizeRef=2017,1672 Split=Y Selected=0xD2C573A7 + DockNode ID=0x00000005 Parent=0x00000004 SizeRef=1351,1269 Selected=0xD2C573A7 + DockNode ID=0x00000006 Parent=0x00000004 SizeRef=1351,400 Selected=0xF930105C DockSpace ID=0xC0DFADC4 Pos=0,51 Size=2560,1511 CentralNode=1 Selected=0x5E5F7166 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..2d0c05c 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; } @@ -73,7 +82,8 @@ struct Ex1_Workspace { RadixSort dir_modtime_radix; bool sort_completed; - // Reordered strings: + // Reordered strings: #note: these are NOT required to save in memory, better to search and + // sort the filtered strings using the solved radices ArrayView files_sorted_by_size; ArrayView files_sorted_by_modtime; }; @@ -224,12 +234,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 +313,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();