From 75bb2ae86d7de28a09bfbbbc05fe980fb3fd8885 Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Wed, 5 Feb 2020 12:20:03 -0800 Subject: [PATCH] Added some notes to various parts of the code base. Also simplified test patterns to ensure that we don't need to use leds_in_universe_range anywhere except in DMX buffer preparation --- gs_libs/gs_win32.cpp | 1 - meta/gs_meta.cpp | 4 ++ src/assembly_parser.cpp | 15 ++--- src/foldhaus_app.h | 109 +++++++++++++++--------------------- src/foldhaus_assembly.cpp | 9 --- src/foldhaus_assembly.h | 4 ++ src/win32_foldhaus.cpp | 3 +- src/win32_foldhaus_memory.h | 2 + src/win32_foldhaus_timing.h | 4 ++ todo.txt | 5 +- 10 files changed, 69 insertions(+), 87 deletions(-) diff --git a/gs_libs/gs_win32.cpp b/gs_libs/gs_win32.cpp index 1a3fa09..dd55973 100644 --- a/gs_libs/gs_win32.cpp +++ b/gs_libs/gs_win32.cpp @@ -503,7 +503,6 @@ HandleWindowsMessage ( else { printf("Translated Char Not Recognized: %c\n", TranslatedChar); - //InvalidCodePath; } */ }break; diff --git a/meta/gs_meta.cpp b/meta/gs_meta.cpp index afca8ba..b4a4e41 100644 --- a/meta/gs_meta.cpp +++ b/meta/gs_meta.cpp @@ -113,6 +113,8 @@ GetWallClock () if (!QueryPerformanceCounter(&Time)) { s32 Error = GetLastError(); + // TODO(Peter): I'm waiting to see an error actually occur here + // to know what it could possibly be. InvalidCodePath; } return (s64)Time.QuadPart; @@ -125,6 +127,8 @@ GetPerformanceFrequency () if (!QueryPerformanceFrequency(&Frequency)) { s32 Error = GetLastError(); + // TODO(Peter): I'm waiting to see an error actually occur here + // to know what it could possibly be. InvalidCodePath; } return (s64)Frequency.QuadPart; diff --git a/src/assembly_parser.cpp b/src/assembly_parser.cpp index 4555707..91d37e3 100644 --- a/src/assembly_parser.cpp +++ b/src/assembly_parser.cpp @@ -83,9 +83,10 @@ ParseAssemblyVector (char* String) return Result; } -internal void +internal b32 ParseAssemblyFileHeader (assembly_definition* Assembly, tokenizer* Tokenizer) { + b32 HeaderIsValid = false; if (CharArraysEqualUpToLength(Tokenizer->At, LED_STRIP_COUNT_IDENTIFIER, CharArrayLength(LED_STRIP_COUNT_IDENTIFIER))) { @@ -95,19 +96,11 @@ ParseAssemblyFileHeader (assembly_definition* Assembly, tokenizer* Tokenizer) if (CountToken.Type == AssemblyToken_Number) { Assembly->LEDStripSize = ParseSignedIntUnsafe(CountToken.Token).SignedIntValue; - } - else - { - InvalidCodePath; + HeaderIsValid = true; } EatWhitespace(Tokenizer); } - else - { - // TODO(Peter): Handle corrupted files, try to recover? - InvalidCodePath; - } - + return HeaderIsValid; } internal led_strip_definition diff --git a/src/foldhaus_app.h b/src/foldhaus_app.h index 1cc3aaf..b088cea 100644 --- a/src/foldhaus_app.h +++ b/src/foldhaus_app.h @@ -92,18 +92,12 @@ internal void OpenColorPicker(app_state* State, v4* Address); internal void TestPatternOne(assembly* Assembly, r32 Time) { - for (u32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) + for (u32 LEDIdx = 0; LEDIdx < Assembly->LEDCount; LEDIdx++) { - leds_in_universe_range LEDUniverseRange = Assembly->LEDUniverseMap[Range]; - for (s32 LEDIdx = LEDUniverseRange.RangeStart; - LEDIdx < LEDUniverseRange.RangeOnePastLast; - LEDIdx++) - { - led LED = Assembly->LEDs[LEDIdx]; - Assembly->Colors[LED.Index].R = 255; - Assembly->Colors[LED.Index].B = 255; - Assembly->Colors[LED.Index].G = 255; - } + led LED = Assembly->LEDs[LEDIdx]; + Assembly->Colors[LED.Index].R = 255; + Assembly->Colors[LED.Index].B = 255; + Assembly->Colors[LED.Index].G = 255; } } @@ -127,43 +121,37 @@ TestPatternTwo(assembly* Assembly, r32 Time) r32 OuterRadiusSquared = 1000000; r32 InnerRadiusSquared = 0; - for (u32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) + for (u32 LEDIdx = 0; LEDIdx < Assembly->LEDCount; LEDIdx++) { - leds_in_universe_range LEDUniverseRange = Assembly->LEDUniverseMap[Range]; - for (s32 LEDIdx = LEDUniverseRange.RangeStart; - LEDIdx < LEDUniverseRange.RangeOnePastLast; - LEDIdx++) + led LED = Assembly->LEDs[LEDIdx]; + + v4 Position = LED.Position; + + v4 ToFront = Position + FrontCenter; + v4 ToBack = Position + BackCenter; + + r32 ToFrontDotNormal = Dot(ToFront, Normal); + r32 ToBackDotNormal = Dot(ToBack, Normal); + + ToFrontDotNormal = GSClamp01(ToFrontDotNormal * 1000); + ToBackDotNormal = GSClamp01(ToBackDotNormal * 1000); + + r32 SqDistToCenter = MagSqr(Position); + if (SqDistToCenter < OuterRadiusSquared && SqDistToCenter > InnerRadiusSquared) { - led LED = Assembly->LEDs[LEDIdx]; - - v4 Position = LED.Position; - - v4 ToFront = Position + FrontCenter; - v4 ToBack = Position + BackCenter; - - r32 ToFrontDotNormal = Dot(ToFront, Normal); - r32 ToBackDotNormal = Dot(ToBack, Normal); - - ToFrontDotNormal = GSClamp01(ToFrontDotNormal * 1000); - ToBackDotNormal = GSClamp01(ToBackDotNormal * 1000); - - r32 SqDistToCenter = MagSqr(Position); - if (SqDistToCenter < OuterRadiusSquared && SqDistToCenter > InnerRadiusSquared) + if (XOR(ToFrontDotNormal > 0, ToBackDotNormal > 0)) { - if (XOR(ToFrontDotNormal > 0, ToBackDotNormal > 0)) - { - Assembly->Colors[LED.Index] = Color; - } - else - { - Assembly->Colors[LED.Index] = {}; - } + Assembly->Colors[LED.Index] = Color; } else { Assembly->Colors[LED.Index] = {}; } } + else + { + Assembly->Colors[LED.Index] = {}; + } } } @@ -178,31 +166,26 @@ TestPatternThree(assembly* Assembly, r32 Time) r32 FadeDist = 35; - for (u32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) + + for (u32 LEDIdx = 0; LEDIdx < Assembly->LEDCount; LEDIdx++) { - leds_in_universe_range LEDUniverseRange = Assembly->LEDUniverseMap[Range]; - for (s32 LEDIdx = LEDUniverseRange.RangeStart; - LEDIdx < LEDUniverseRange.RangeOnePastLast; - LEDIdx++) - { - led LED = Assembly->LEDs[LEDIdx]; - u8 Red = 0; - u8 Green = 0; - u8 Blue = 0; - - r32 GreenDist = GSAbs(Mag(LED.Position - GreenCenter) - GreenRadius); - r32 GreenBrightness = GSClamp(0.f, FadeDist - GSAbs(GreenDist), FadeDist); - Green = (u8)(GreenBrightness * 255); - - r32 TealDist = GSAbs(Mag(LED.Position - TealCenter) - TealRadius); - r32 TealBrightness = GSClamp(0.f, FadeDist - GSAbs(TealDist), FadeDist); - Red = (u8)(TealBrightness * 255); - Blue = (u8)(TealBrightness * 255); - - Assembly->Colors[LED.Index].R = Red; - Assembly->Colors[LED.Index].B = Green; - Assembly->Colors[LED.Index].G = Green; - } + led LED = Assembly->LEDs[LEDIdx]; + u8 Red = 0; + u8 Green = 0; + u8 Blue = 0; + + r32 GreenDist = GSAbs(Mag(LED.Position - GreenCenter) - GreenRadius); + r32 GreenBrightness = GSClamp(0.f, FadeDist - GSAbs(GreenDist), FadeDist); + Green = (u8)(GreenBrightness * 255); + + r32 TealDist = GSAbs(Mag(LED.Position - TealCenter) - TealRadius); + r32 TealBrightness = GSClamp(0.f, FadeDist - GSAbs(TealDist), FadeDist); + Red = (u8)(TealBrightness * 255); + Blue = (u8)(TealBrightness * 255); + + Assembly->Colors[LED.Index].R = Red; + Assembly->Colors[LED.Index].B = Green; + Assembly->Colors[LED.Index].G = Green; } } diff --git a/src/foldhaus_assembly.cpp b/src/foldhaus_assembly.cpp index 7d2d0fe..38db7fc 100644 --- a/src/foldhaus_assembly.cpp +++ b/src/foldhaus_assembly.cpp @@ -5,15 +5,6 @@ // #ifndef FOLDHAUS_ASSEMBLY_CPP -internal s32 -GetAssemblyMemorySizeFromDefinition(assembly_definition Definition, string Name) -{ - s32 Result = (sizeof(led) + sizeof(pixel)) * Definition.TotalLEDCount; - Result += sizeof(leds_in_universe_range) * Definition.LEDStripCount; - Result += Name.Length; - return Result; -} - internal assembly ConstructAssemblyFromDefinition (assembly_definition Definition, string AssemblyName, diff --git a/src/foldhaus_assembly.h b/src/foldhaus_assembly.h index 29f5bde..f53084b 100644 --- a/src/foldhaus_assembly.h +++ b/src/foldhaus_assembly.h @@ -22,6 +22,10 @@ union pixel u8 Channels[3]; }; +// NOTE(Peter): This structure is so we can keep track of +// what LEDs output to which DMX universe. You don't need +// to use it anywhere else, as all the data for patterns, +// colors, and groups is/will be stored elsewhere. struct leds_in_universe_range { s32 RangeStart; diff --git a/src/win32_foldhaus.cpp b/src/win32_foldhaus.cpp index db441e6..13e959b 100644 --- a/src/win32_foldhaus.cpp +++ b/src/win32_foldhaus.cpp @@ -639,7 +639,8 @@ WinMain ( } else { - InvalidCodePath; + MessageBox(MainWindow.Handle, "Unable to load application DLL at startup.\nAborting\n", "Set Up Error", MB_OK); + return -1; } WSADATA WSAData; diff --git a/src/win32_foldhaus_memory.h b/src/win32_foldhaus_memory.h index 3afedcc..e786c44 100644 --- a/src/win32_foldhaus_memory.h +++ b/src/win32_foldhaus_memory.h @@ -22,6 +22,8 @@ PLATFORM_FREE(Win32Free) if (!Result) { s32 Error = WSAGetLastError(); + // TODO(Peter): I'm waiting to see an error actually occur here + // to know what it could possibly be. InvalidCodePath; } return Result; diff --git a/src/win32_foldhaus_timing.h b/src/win32_foldhaus_timing.h index ed5d041..6d04a31 100644 --- a/src/win32_foldhaus_timing.h +++ b/src/win32_foldhaus_timing.h @@ -15,6 +15,8 @@ GetPerformanceFrequency () if (!QueryPerformanceFrequency(&Frequency)) { s32 Error = GetLastError(); + // TODO(Peter): I'm waiting to see an error actually occur here + // to know what it could possibly be. InvalidCodePath; } return (s64)Frequency.QuadPart; @@ -31,6 +33,8 @@ GetWallClock () if (!QueryPerformanceCounter(&Time)) { s32 Error = GetLastError(); + // TODO(Peter): I'm waiting to see an error actually occur here + // to know what it could possibly be. InvalidCodePath; } return (s64)Time.QuadPart; diff --git a/todo.txt b/todo.txt index 7ac07e9..21157d7 100644 --- a/todo.txt +++ b/todo.txt @@ -21,8 +21,8 @@ x Hot Code Reloading - Enumerate Directory Contents (you started this in win32_foldhaus_fileio.h) - -- File Loading - - Gracefully handle File Not found +x File Loading + x Gracefully handle File Not found - Buckets & Lists - Allow them to use memory arenas @@ -57,6 +57,7 @@ x Hot Code Reloading - styling - text input - lister with icon options + - panel system: destroy panel by extending it beyond its max, not just its min - Sculpture View - mouse spatial interaction - handles, and hover for info