diff --git a/.gitignore b/.gitignore index 5831047..9cb11ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ process/ reference/ -working_data/ \ No newline at end of file +working_data/ +build_clang diff --git a/build_clang.bat b/build_clang.bat new file mode 100644 index 0000000..30c5b8b --- /dev/null +++ b/build_clang.bat @@ -0,0 +1,32 @@ +@echo off + +set ProjectDevFolder=%~dp0 +set ProjectDevPath=%ProjectDevFolder:~0,-1% + +pushd %ProjectDevPath% + +IF NOT EXIST .\build_clang\ mkdir .\build_clang + +C:\programs\ctime\ctime.exe -begin %ProjectDevPath%\build\win32_foldhaus_clang_build_time.ctm + +set CommonCompilerFlags=-std=c++11 -Wno-writable-strings -Wno-unused-value -Wno-varargs -Wno-switch -Wno-microsoft-enum-forward-reference -DDEBUG=1 + +pushd .\build_clang\ + +REM Run the Preprocessor +foldhaus_meta.exe ..\src\foldhaus_app.cpp + +echo WAITING FOR PDB TO WRITE > lock.tmp + +clang %CommonCompilerFlags% ..\src\foldhaus_app.cpp -shared + +set LastError=%ERRORLEVEL% + +del lock.tmp + +clang %CommonCompilerFlags% ..\src\win32_foldhaus.cpp -o win32_foldhaus.exe user32.lib winmm.lib gdi32.lib opengl32.lib dsound.lib Ws2_32.lib Comdlg32.lib + +C:\programs\ctime\ctime.exe -end %ProjectDevPath%\build\win32_foldhaus_clang_build_time.ctm %LastError% +REM C:\programs\ctime\ctime.exe -stats %ProjectDevPath%\build\win32_foldhaus_clang_build_time.ctm +popd + diff --git a/gs_libs/gs_font.h b/gs_libs/gs_font.h index e6265dd..7570039 100644 --- a/gs_libs/gs_font.h +++ b/gs_libs/gs_font.h @@ -47,6 +47,8 @@ InitializeTextFont (s32 CodepointCount, u8* CodepointMemory, s32 CodepointMemory Assert(CodepointMemorySize >= (sizeof(char) + sizeof(codepoint_bitmap)) * CodepointCount); Result.CodepointKeys = (char*)CodepointMemory; Result.CodepointValues = (codepoint_bitmap*)(CodepointMemory + (sizeof(char) * CodepointCount)); + + return Result; } #define GLYPH_SKIRT 1 diff --git a/gs_libs/gs_language.h b/gs_libs/gs_language.h index 9240fcf..84964d9 100644 --- a/gs_libs/gs_language.h +++ b/gs_libs/gs_language.h @@ -88,7 +88,13 @@ static void DebugPrint(char* Format, ...); #if !defined(Assert) // NOTE(peter): this writes to address 0 which is always illegal and will cause a crash -#define Assert(expression) if(!(expression)){ *((int *)0) = 5; } +#define Assert(expression) \ +if((expression)) \ +{ \ +}else{ \ +volatile int* p = 0; \ +*p = 5; \ +} #endif #define DEBUG_IF(condition) if (condition) @@ -310,9 +316,9 @@ GSIntDivideRoundUpDef(s64); #define GSRemapDef(type) \ static type GSRemap(type Value, type OldMin, type OldMax, type NewMin, type NewMax) { \ -type Result = (Value - OldMin) / (OldMax - OldMin); \ -Result = (Result * (NewMax - NewMin)) + NewMin; \ -return Result; \ + type Result = (Value - OldMin) / (OldMax - OldMin); \ + Result = (Result * (NewMax - NewMin)) + NewMin; \ + return Result; \ } GSRemapDef(u8); GSRemapDef(u16); diff --git a/gs_libs/gs_memory_arena.h b/gs_libs/gs_memory_arena.h index b8b0a8e..772d9e3 100644 --- a/gs_libs/gs_memory_arena.h +++ b/gs_libs/gs_memory_arena.h @@ -156,8 +156,10 @@ typedef unsigned long long int gs_mem_u64; #ifdef DEBUG #if !defined(GSMem_Assert) #define GSMem_Assert(expression) \ -if(!(expression)) { \ -*((int *)0) = 5; \ +if((expression)) { \ +}else{ \ + volatile int* p = 0; \ + *p = 5; \ } #endif @@ -567,7 +569,7 @@ ClearArena(memory_arena* Arena) static arena_snapshot TakeSnapshotOfArena(memory_arena* Arena) { - Assert(Arena->FindAddressRule == FindAddress_InLastBufferOnly); + GSMem_Assert(Arena->FindAddressRule == FindAddress_InLastBufferOnly); arena_snapshot Result = {}; Result.Arena = Arena; @@ -593,7 +595,7 @@ TakeSnapshotOfArena(memory_arena* Arena) static void ClearArenaToSnapshot(memory_arena* Arena, arena_snapshot Snapshot) { - Assert(Arena == Snapshot.Arena); + GSMem_Assert(Arena == Snapshot.Arena); memory_buffer* HeadBufferAtSnapshot = Arena->Buffers + Snapshot.HeadBufferAtSnapshot; if (HeadBufferAtSnapshot) diff --git a/gs_libs/gs_vector_matrix.h b/gs_libs/gs_vector_matrix.h index 67f4d5a..fb1a3b3 100644 --- a/gs_libs/gs_vector_matrix.h +++ b/gs_libs/gs_vector_matrix.h @@ -189,9 +189,9 @@ v4 operator- (v4 A) return Result; } -#define V2OpV2Def(op) v2 operator##op (v2 A, v2 B) { return v2{ A.x op B.x, A.y op B.y };} -#define V3OpV3Def(op) v3 operator##op (v3 A, v3 B) { return v3{ A.x op B.x, A.y op B.y, A.z op B.z };} -#define V4OpV4Def(op) v4 operator##op (v4 A, v4 B) { return v4{ A.x op B.x, A.y op B.y, A.z op B.z, A.w op B.w };} +#define V2OpV2Def(op) v2 operator op (v2 A, v2 B) { return v2{ A.x op B.x, A.y op B.y };} +#define V3OpV3Def(op) v3 operator op (v3 A, v3 B) { return v3{ A.x op B.x, A.y op B.y, A.z op B.z };} +#define V4OpV4Def(op) v4 operator op (v4 A, v4 B) { return v4{ A.x op B.x, A.y op B.y, A.z op B.z, A.w op B.w };} V2OpV2Def(+) V2OpV2Def(-) V2OpV2Def(/) @@ -208,9 +208,9 @@ V4OpV4Def(*) #undef V3OpV3Def #undef V4OpV4Def -#define V2RefOpV2Def(op) v2 operator##op (v2& A, v2 B) { return v2{ A.x op B.x, A.y op B.y };} -#define V3RefOpV3Def(op) v3 operator##op (v3& A, v3 B) { return v3{ A.x op B.x, A.y op B.y, A.z op B.z };} -#define V4RefOpScalarDef(op) v4 operator##op (v4& A, v4 B) { return v4{ A.x op B.x, A.y op B.y, A.z op B.z, A.w op B.w };} +#define V2RefOpV2Def(op) v2 operator op (v2& A, v2 B) { return v2{ A.x op B.x, A.y op B.y };} +#define V3RefOpV3Def(op) v3 operator op (v3& A, v3 B) { return v3{ A.x op B.x, A.y op B.y, A.z op B.z };} +#define V4RefOpScalarDef(op) v4 operator op (v4& A, v4 B) { return v4{ A.x op B.x, A.y op B.y, A.z op B.z, A.w op B.w };} V2RefOpV2Def(+=) V2RefOpV2Def(-=) V3RefOpV3Def(+=) @@ -221,9 +221,9 @@ V4RefOpScalarDef(-=) #undef V3RefOpV3Def #undef V4RefOpV4Def -#define V2OpScalarDef(op) v2 operator##op (v2 A, float B) { return v2{ A.x op B, A.y op B };} -#define V3OpScalarDef(op) v3 operator##op (v3 A, float B) { return v3{ A.x op B, A.y op B, A.z op B };} -#define V4OpScalarDef(op) v4 operator##op (v4 A, float B) { return v4{ A.x op B, A.y op B, A.z op B, A.w op B };} +#define V2OpScalarDef(op) v2 operator op (v2 A, float B) { return v2{ A.x op B, A.y op B };} +#define V3OpScalarDef(op) v3 operator op (v3 A, float B) { return v3{ A.x op B, A.y op B, A.z op B };} +#define V4OpScalarDef(op) v4 operator op (v4 A, float B) { return v4{ A.x op B, A.y op B, A.z op B, A.w op B };} V2OpScalarDef(*) V2OpScalarDef(/) V3OpScalarDef(*) @@ -235,9 +235,9 @@ V4OpScalarDef(/) #undef V4POpScalarDef -#define V2POpScalarDef(op) v2 operator##op (v2& A, float B) { return v2{ A->x op B, A->y op B };} -#define V3POpScalarDef(op) v3 operator##op (v3& A, float B) { return v3{ A->x op B, A->y op B, A->z op B };} -#define V4POpScalarDef(op) v4 operator##op (v4& A, float B) { return v4{ A->x op B, A->y op B, A->z op B, A->w op B };} +#define V2POpScalarDef(op) v2 operator op (v2& A, float B) { return v2{ A->x op B, A->y op B };} +#define V3POpScalarDef(op) v3 operator op (v3& A, float B) { return v3{ A->x op B, A->y op B, A->z op B };} +#define V4POpScalarDef(op) v4 operator op (v4& A, float B) { return v4{ A->x op B, A->y op B, A->z op B, A->w op B };} V2OpScalarDef(*=) V2OpScalarDef(/=) V3OpScalarDef(*=) diff --git a/src/foldhaus_debug.h b/src/foldhaus_debug.h index 7641db6..c987469 100644 --- a/src/foldhaus_debug.h +++ b/src/foldhaus_debug.h @@ -225,7 +225,7 @@ GetIndexForNameHash(debug_frame* Frame, u32 NameHash) for (s32 Offset = 0; Offset < Frame->ScopeNamesMax; Offset++) { u32 Index = (NameHash + Offset) % Frame->ScopeNamesMax; - if ((Frame->ScopeNamesHash[Index].Hash == NameHash)) + if (Frame->ScopeNamesHash[Index].Hash == NameHash) { Result = Index; break; @@ -399,7 +399,7 @@ internal r32 DEBUGGetSecondsElapsed (s64 Start, s64 End, r32 PerformanceCountFre } #ifdef DEBUG -#define DEBUG_TRACK_FUNCTION scope_tracker ScopeTracker (__FUNCTION__, GlobalDebugServices) +#define DEBUG_TRACK_FUNCTION scope_tracker ScopeTracker ((char*)__func__, GlobalDebugServices) #define DEBUG_TRACK_SCOPE(name) scope_tracker ScopeTracker_##name (#name, GlobalDebugServices) #else #define DEBUG_TRACK_FUNCTION diff --git a/src/interface.h b/src/interface.h index a1b0fcb..2288183 100644 --- a/src/interface.h +++ b/src/interface.h @@ -271,7 +271,7 @@ struct multi_option_label_result internal multi_option_label_result EvaluateMultiOptionLabel (render_command_buffer* RenderBuffer, - v2 Min, v2 Max, string Label, string Options[], + v2 Min, v2 Max, string Label, string Options[], s32 OptionsCount, interface_config Config, mouse_state Mouse) { multi_option_label_result Result = {}; @@ -283,7 +283,7 @@ EvaluateMultiOptionLabel (render_command_buffer* RenderBuffer, v2 ButtonDim = v2{ButtonSide, ButtonSide}; v2 ButtonPos = Max - (ButtonDim + Config.Margin); - for (s32 b = 0; b < sizeof(Options) / sizeof(Options[0]); b++) + for (s32 b = 0; b < OptionsCount; b++) { button_result Button = EvaluateButton(RenderBuffer, ButtonPos, ButtonPos + ButtonDim, Options[b], Config, Mouse); @@ -301,13 +301,12 @@ EvaluateMultiOptionLabel (render_command_buffer* RenderBuffer, // NOTE(Peter): returns IndexPressed = -1 if the button itself is pressed, as opposed // to one of its options internal multi_option_label_result -EvaluateMultiOptionButton (render_command_buffer* RenderBuffer, v2 Min, v2 Max, string Text, string Options[], b32 Selected, +EvaluateMultiOptionButton (render_command_buffer* RenderBuffer, v2 Min, v2 Max, string Text, string Options[], s32 OptionsCount, b32 Selected, interface_config Config, mouse_state Mouse) { multi_option_label_result Result = {}; Result.Pressed = false; - s32 OptionsCount = sizeof(Options) / sizeof(Options[0]); r32 ButtonSide = (Max.y - Min.y) - (2 * Config.Margin.y); v2 ButtonDim = v2{ButtonSide, ButtonSide}; @@ -386,31 +385,29 @@ EvaluateSlider (render_command_buffer* RenderBuffer, v2 Min, v2 Max, string Labe struct panel_result { - s32 Depth; v2 NextPanelMin; v2 ChildMin, ChildMax; }; internal panel_result -EvaluatePanel (render_command_buffer* RenderBuffer, v2 Min, v2 Max, s32 Depth, interface_config Config) +EvaluatePanel (render_command_buffer* RenderBuffer, v2 Min, v2 Max, interface_config Config) { panel_result Result = {}; - Result.Depth = Depth; Result.ChildMin = Min + Config.Margin; Result.ChildMax = Max - Config.Margin; Result.NextPanelMin = v2{Max.x, Min.y}; - v4 BG = Config.PanelBGColors[Depth]; + v4 BG = Config.PanelBGColors[0]; PushRenderQuad2D(RenderBuffer, Min, Max, BG); return Result; } internal panel_result -EvaluatePanel (render_command_buffer* RenderBuffer, v2 Min, v2 Max, string Label, s32 Depth, interface_config Config) +EvaluatePanel (render_command_buffer* RenderBuffer, v2 Min, v2 Max, string Label, interface_config Config) { - panel_result Result = EvaluatePanel(RenderBuffer, Min, Max, Depth, Config); + panel_result Result = EvaluatePanel(RenderBuffer, Min, Max, Config); v2 TextPos = v2{ Min.x + Config.Margin.x, @@ -427,7 +424,7 @@ EvaluatePanel(render_command_buffer* RenderBuffer, panel_result* ParentPanel, r3 { v2 Min = v2{ParentPanel->ChildMin.x, ParentPanel->ChildMax.y - Height}; v2 Max = ParentPanel->ChildMax; - panel_result Result = EvaluatePanel(RenderBuffer, Min, Max, Title, ParentPanel->Depth + 1, Config); + panel_result Result = EvaluatePanel(RenderBuffer, Min, Max, Title, Config); ParentPanel->ChildMax.y = Min.y - Config.Margin.y; diff --git a/src/panels/foldhaus_panel_animation_timeline.h b/src/panels/foldhaus_panel_animation_timeline.h index 5eb99d7..f95a747 100644 --- a/src/panels/foldhaus_panel_animation_timeline.h +++ b/src/panels/foldhaus_panel_animation_timeline.h @@ -454,8 +454,7 @@ AnimationTimeline_Render(panel Panel, rect PanelBounds, render_command_buffer* R v2 OptionsRowMin = v2{ PanelBounds.Min.x, TimelineBounds.Max.y }; v2 OptionsRowMax = PanelBounds.Max; - panel_result AnimationPanel = EvaluatePanel(RenderBuffer, OptionsRowMin, OptionsRowMax, - 0, State->Interface); + panel_result AnimationPanel = EvaluatePanel(RenderBuffer, OptionsRowMin, OptionsRowMax, State->Interface); r32 ButtonWidth = 35; v2 ButtonMin = v2{0, 0}; diff --git a/src/panels/foldhaus_panel_dmx_view.h b/src/panels/foldhaus_panel_dmx_view.h index e8f3caf..37d6645 100644 --- a/src/panels/foldhaus_panel_dmx_view.h +++ b/src/panels/foldhaus_panel_dmx_view.h @@ -26,6 +26,11 @@ DMXView_Cleanup(panel* Panel, app_state* State) } +#if 0 + +// NOTE(Peter): Here to illustrate what old SACN Universe drawing looked like +// This won't actually function +// :NoLongerFunctionalSACNCodeButThatsOk internal void DrawSACNUniversePixels (render_command_buffer* RenderBuffer, sacn_universe* ToDraw, v2 TopLeft, v2 Dimension) @@ -59,12 +64,14 @@ DrawSACNUniversePixels (render_command_buffer* RenderBuffer, sacn_universe* ToDr ++PixelsDrawn; } } +#endif GSMetaTag(panel_render); internal void DMXView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse) { #if 0 + // :NoLongerFunctionalSACNCodeButThatsOk DEBUG_TRACK_SCOPE(DrawUniverseOutputDisplay); universe_view_operation_state* OpState = (universe_view_operation_state*)Operation.OpStateMemory; diff --git a/src/panels/foldhaus_panel_node_graph.h b/src/panels/foldhaus_panel_node_graph.h index 1e478e6..b954cc2 100644 --- a/src/panels/foldhaus_panel_node_graph.h +++ b/src/panels/foldhaus_panel_node_graph.h @@ -169,7 +169,7 @@ BeginConnectNodesOperation(visual_port VisualPort, u32 VisualPortIndex, mouse_st // input_command NodeGraph_Commands[] = { - { 0 } + {} }; GSMetaTag(panel_init); diff --git a/todo.txt b/todo.txt index 25edd90..080fbf7 100644 --- a/todo.txt +++ b/todo.txt @@ -2,31 +2,18 @@ TODO FOLDHAUS Ground Up Reengineering - Metaprogramming - x refactor for speed - x use #include statements to crawl through the codebase - x generalize the system - panels metaprogramming - fix memory layout (remeber to profile before and after) -x Hot Code Reloading - x Fix it - - Make the DLL truly platform agnostic - math.h: present for trig functions - windows.h: only thing left is InterlockedIncrement and InterlockedAdd - Win32 Platform Layer - x Capture Mouse Events that start on the window but end outside - x Mouse up when mouse down was in the window - Enumerate Directory Contents (you started this in win32_foldhaus_fileio.h) - - - -x File Loading - x Gracefully handle File Not found - Internal Log File NOTE: This should not be a part of the debug system - x Basic logging - Save output log to a file continuously - Have a window where we can view the log within the app - Create a bar that displays the most recent error message @@ -45,10 +32,6 @@ x File Loading - Lighting - Clipping (with error checking) -- Asset Loading - - images - - icon system - - Sculptures - store scale in the assembly definition file - cache led vertex buffers @@ -70,6 +53,11 @@ x File Loading - lister with icon options - panel system: destroy panel by extending it beyond its max, not just its min +- Asset Loading + - images + - icon system - integrate with interface + + - Sculpture View - mouse spatial interaction - handles, and hover for info - debug capabilities (toggle strip/led/universe colors)