From 51955ba765e7efdcfd8c68ff174d4cc04e7dc8e5 Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Tue, 4 Feb 2020 22:50:12 -0800 Subject: [PATCH] Fixed a Function Pointer address problem created by storing a pointer to the address of an animation procedure. When code is reloaded, that pointer becomes invalid, so we just store an index, and switch on the value --- data/blumen_lumen.fold | 24 +++++++-------- gs_libs/gs_bucket.h | 27 ----------------- src/animation/foldhaus_animation.h | 2 +- src/foldhaus_app.cpp | 27 +++++++++++++++-- src/foldhaus_app.h | 30 +++++++++---------- .../foldhaus_panel_animation_timeline.h | 12 ++++---- src/win32_foldhaus.cpp | 8 ++++- todo.txt | 9 ++++++ 8 files changed, 73 insertions(+), 66 deletions(-) diff --git a/data/blumen_lumen.fold b/data/blumen_lumen.fold index 6340e2d..9ce7e8d 100644 --- a/data/blumen_lumen.fold +++ b/data/blumen_lumen.fold @@ -1,15 +1,15 @@ led_strip_count 12 -led_strip { 0, 0, 0, INTERPOLATE_POINTS, (0.000000, 1.000000, 0.000000), (0.000000, 0.050000, 1.000000), 70 } -led_strip { 0, 1, 0, INTERPOLATE_POINTS, (0.500000, 0.866025, 0.000000), (0.025000, 0.043301, 1.000000), 70 } -led_strip { 0, 2, 0, INTERPOLATE_POINTS, (0.866025, 0.499999, 0.000000), (0.043301, 0.024999, 1.000000), 70 } -led_strip { 0, 3, 0, INTERPOLATE_POINTS, (1.000000, -0.000000, 0.000000), (0.050000, -0.000000, 1.000000), 70 } -led_strip { 0, 4, 0, INTERPOLATE_POINTS, (0.866025, -0.500000, 0.000000), (0.043301, -0.025000, 1.000000), 70 } -led_strip { 0, 5, 0, INTERPOLATE_POINTS, (0.500000, -0.866025, 0.000000), (0.025000, -0.043301, 1.000000), 70 } -led_strip { 0, 6, 0, INTERPOLATE_POINTS, (-0.000000, -1.000000, 0.000000), (-0.000000, -0.050000, 1.000000), 70 } -led_strip { 0, 7, 0, INTERPOLATE_POINTS, (-0.500000, -0.866025, 0.000000), (-0.025000, -0.043301, 1.000000), 70 } -led_strip { 0, 8, 0, INTERPOLATE_POINTS, (-0.866025, -0.499999, 0.000000), (-0.043301, -0.024999, 1.000000), 70 } -led_strip { 0, 9, 0, INTERPOLATE_POINTS, (-1.000000, 0.000000, 0.000000), (-0.050000, 0.000000, 1.000000), 70 } -led_strip { 0, 10, 0, INTERPOLATE_POINTS, (-0.866025, 0.499999, 0.000000), (-0.043301, 0.024999, 1.000000), 70 } -led_strip { 0, 11, 0, INTERPOLATE_POINTS, (-0.499999, 0.866025, 0.000000), (-0.024999, 0.043301, 1.000000), 70 } +led_strip { 0, 2, 0, INTERPOLATE_POINTS, (0.000000, 1.000000, 0.000000), (0.000000, 0.050000, 1.000000), 346 } +led_strip { 0, 4, 0, INTERPOLATE_POINTS, (0.500000, 0.866025, 0.000000), (0.025000, 0.043301, 1.000000), 346 } +led_strip { 0, 6, 0, INTERPOLATE_POINTS, (0.866025, 0.499999, 0.000000), (0.043301, 0.024999, 1.000000), 346 } +led_strip { 0, 8, 0, INTERPOLATE_POINTS, (1.000000, -0.000000, 0.000000), (0.050000, -0.000000, 1.000000), 346 } +led_strip { 0, 10, 0, INTERPOLATE_POINTS, (0.866025, -0.500000, 0.000000), (0.043301, -0.025000, 1.000000), 346 } +led_strip { 0, 12, 0, INTERPOLATE_POINTS, (0.500000, -0.866025, 0.000000), (0.025000, -0.043301, 1.000000), 346 } +led_strip { 0, 14, 0, INTERPOLATE_POINTS, (-0.000000, -1.000000, 0.000000), (-0.000000, -0.050000, 1.000000), 346 } +led_strip { 0, 7, 0, INTERPOLATE_POINTS, (-0.500000, -0.866025, 0.000000), (-0.025000, -0.043301, 1.000000), 346 } +led_strip { 0, 8, 0, INTERPOLATE_POINTS, (-0.866025, -0.499999, 0.000000), (-0.043301, -0.024999, 1.000000), 346 } +led_strip { 0, 9, 0, INTERPOLATE_POINTS, (-1.000000, 0.000000, 0.000000), (-0.050000, 0.000000, 1.000000), 346 } +led_strip { 0, 10, 0, INTERPOLATE_POINTS, (-0.866025, 0.499999, 0.000000), (-0.043301, 0.024999, 1.000000), 346 } +led_strip { 0, 11, 0, INTERPOLATE_POINTS, (-0.499999, 0.866025, 0.000000), (-0.024999, 0.043301, 1.000000), 346 } END_OF_ASSEMBLY_FILE \ No newline at end of file diff --git a/gs_libs/gs_bucket.h b/gs_libs/gs_bucket.h index ffeb9c7..a9281dd 100644 --- a/gs_libs/gs_bucket.h +++ b/gs_libs/gs_bucket.h @@ -24,9 +24,6 @@ class gs_bucket { u32 Used; - gs_bucket(); - gs_bucket(u32 BucketSize); - void GrowBucket(); T* GetElementAtIndex(u32 Index); @@ -36,33 +33,9 @@ class gs_bucket { void FreeElementAtIndex(u32 Index); }; -template -gs_bucket::gs_bucket() -{ - this->BucketSize = 0; - this->BucketCount = 0; - this->Buckets = 0; - this->Used = 0; -} - -template -gs_bucket::gs_bucket(u32 BucketSize) -{ - this->BucketSize = BucketSize; - this->BucketCount = 0; - this->Buckets = 0; - this->Used = 0; -} - template void gs_bucket::GrowBucket() { - if (this->BucketCount == 0) - { - // First Grow Attempt - this->Buckets = 0; - } - if (this->BucketSize == 0) { this->BucketSize = GS_LIST_DEFAULT_BUCKET_SIZE; diff --git a/src/animation/foldhaus_animation.h b/src/animation/foldhaus_animation.h index c4de271..033ee22 100644 --- a/src/animation/foldhaus_animation.h +++ b/src/animation/foldhaus_animation.h @@ -19,7 +19,7 @@ struct animation_block // TODO(Peter): Should we change this to frames?? r32 StartTime; r32 EndTime; - animation_proc* Proc; + u32 AnimationProcHandle; u32 Layer; }; diff --git a/src/foldhaus_app.cpp b/src/foldhaus_app.cpp index f33be26..dab996b 100644 --- a/src/foldhaus_app.cpp +++ b/src/foldhaus_app.cpp @@ -174,7 +174,7 @@ INITIALIZE_APPLICATION(InitializeApplication) State->Camera.LookAt = v3{0, 0, 0}; #if 1 - char Path[] = "radialumia.fold"; + char Path[] = "blumen_lumen.fold"; LoadAssembly(State, Context, Path); #endif @@ -352,7 +352,28 @@ UPDATE_AND_RENDER(UpdateAndRender) { gs_list_handle AssemblyHandle = *State->ActiveAssemblyIndecies.GetElementAtIndex(j); assembly* Assembly = State->AssemblyList.GetElementWithHandle(AssemblyHandle); - Block.Proc(Assembly, FrameTime - Block.StartTime); + + // TODO(Peter): Temporary + switch(Block.AnimationProcHandle) + { + case 1: + { + TestPatternOne(Assembly, FrameTime - Block.StartTime); + }break; + + case 2: + { + TestPatternTwo(Assembly, FrameTime - Block.StartTime); + }break; + + case 3: + { + TestPatternThree(Assembly, FrameTime - Block.StartTime); + }break; + + // NOTE(Peter): Zero is invalid + InvalidDefaultCase; + } } } } @@ -369,7 +390,7 @@ UPDATE_AND_RENDER(UpdateAndRender) DMXBuffers = DMXBufferListAppend(DMXBuffers, NewDMXBuffers); } - DEBUG_IF(GlobalDebugServices->Interface.SendSACNData) + //DEBUG_IF(GlobalDebugServices->Interface.SendSACNData) { switch (State->NetworkProtocol) { diff --git a/src/foldhaus_app.h b/src/foldhaus_app.h index b9f2728..1cc3aaf 100644 --- a/src/foldhaus_app.h +++ b/src/foldhaus_app.h @@ -170,13 +170,13 @@ TestPatternTwo(assembly* Assembly, r32 Time) internal void TestPatternThree(assembly* Assembly, r32 Time) { - r32 GreenSize = 20.0f; - r32 BlueSize = 25.0f; - r32 RedSize = 25.0f; + v4 GreenCenter = v4{0, 0, 150, 1}; + r32 GreenRadius = GSAbs(GSSin(Time)) * 200; - r32 GreenPosition = -GreenSize + (Time * 45); - r32 BluePosition = -BlueSize + (Time * 25); - r32 RedPosition = (100 + RedSize) + (Time * -35); + v4 TealCenter = v4{0, 0, 150, 1}; + r32 TealRadius = GSAbs(GSSin(Time + 1.5)) * 200; + + r32 FadeDist = 35; for (u32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) { @@ -190,24 +190,22 @@ TestPatternThree(assembly* Assembly, r32 Time) u8 Green = 0; u8 Blue = 0; - r32 GreenDistance = GSAbs(LED.Position.z - GreenPosition); - r32 GreenBrightness = GSClamp(0.0f, GreenSize - GreenDistance, GreenSize) / GreenSize; + r32 GreenDist = GSAbs(Mag(LED.Position - GreenCenter) - GreenRadius); + r32 GreenBrightness = GSClamp(0.f, FadeDist - GSAbs(GreenDist), FadeDist); Green = (u8)(GreenBrightness * 255); - r32 BlueDistance = GSAbs(LED.Position.z - BluePosition); - r32 BlueBrightness = GSClamp(0.0f, BlueSize - BlueDistance, BlueSize) / BlueSize; - Blue = (u8)(BlueBrightness * 255); - - r32 RedDistance = GSAbs(LED.Position.z - RedPosition); - r32 RedBrightness = GSClamp(0.0f, RedSize - RedDistance, RedSize) / RedSize; - Red = (u8)(RedBrightness * 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 = Blue; + Assembly->Colors[LED.Index].B = Green; Assembly->Colors[LED.Index].G = Green; } } } + // END TEMPORARY PATTERNS #include "foldhaus_assembly.cpp" diff --git a/src/panels/foldhaus_panel_animation_timeline.h b/src/panels/foldhaus_panel_animation_timeline.h index f477128..5eb99d7 100644 --- a/src/panels/foldhaus_panel_animation_timeline.h +++ b/src/panels/foldhaus_panel_animation_timeline.h @@ -40,21 +40,21 @@ GetXPositionFromTimeInAnimationPanel (r32 Time, rect PanelBounds, s32 StartFrame } internal void -AddAnimationBlock(r32 StartTime, r32 EndTime, animation_proc* Proc, animation_system* AnimationSystem) +AddAnimationBlock(r32 StartTime, r32 EndTime, u32 AnimationProcHandle, animation_system* AnimationSystem) { animation_block NewBlock = {0}; NewBlock.StartTime = StartTime; NewBlock.EndTime = EndTime; - NewBlock.Proc = Proc; + NewBlock.AnimationProcHandle = AnimationProcHandle; AnimationSystem->Blocks.PushElementOnList(NewBlock); } #define NEW_ANIMATION_BLOCK_DURATION 3 internal void -AddAnimationBlockAtCurrentTime (animation_proc* Proc, animation_system* System) +AddAnimationBlockAtCurrentTime (u32 AnimationProcHandle, animation_system* System) { r32 CurrentTime = System->Time; - AddAnimationBlock(CurrentTime, CurrentTime + NEW_ANIMATION_BLOCK_DURATION, Proc, System); + AddAnimationBlock(CurrentTime, CurrentTime + NEW_ANIMATION_BLOCK_DURATION, AnimationProcHandle, System); } internal void @@ -202,7 +202,7 @@ FOLDHAUS_INPUT_COMMAND_PROC(AddAnimationBlockCommand) animation_block Block = {0}; Block.StartTime = NewBlockTimeStart; Block.EndTime = NewBlockTimeEnd; - Block.Proc = TestPatternThree; + Block.AnimationProcHandle = 4; gs_list_handle NewBlockHandle = State->AnimationSystem.Blocks.PushElementOnList(Block); SelectAnimationBlock(NewBlockHandle, State); @@ -418,7 +418,7 @@ DrawAnimationClipsList(rect PanelBounds, mouse_state Mouse, render_command_buffe if (MouseButtonTransitionedDown(Mouse.LeftButtonState) && PointIsInRect(Mouse.DownPos, ElementBounds)) { - AddAnimationBlockAtCurrentTime(Clip.Proc, &State->AnimationSystem); + AddAnimationBlockAtCurrentTime(i + 1, &State->AnimationSystem); } } diff --git a/src/win32_foldhaus.cpp b/src/win32_foldhaus.cpp index bbb7b1b..b9983a6 100644 --- a/src/win32_foldhaus.cpp +++ b/src/win32_foldhaus.cpp @@ -194,7 +194,13 @@ PLATFORM_SEND_TO(Win32SendTo) if (LengthSent == SOCKET_ERROR) { s32 Error = WSAGetLastError(); - InvalidCodePath; + if (Error == 10051) + { + } + else + { + InvalidCodePath; + } } return LengthSent; diff --git a/todo.txt b/todo.txt index 5a128f6..5fba1b3 100644 --- a/todo.txt +++ b/todo.txt @@ -8,6 +8,12 @@ Ground Up Reengineering - panels metaprogramming - fix memory layout (remeber to profile before and after) +- Hot Code Reloading + - Fix it + +- File Loading + - Gracefully handle File Not found +s - Buckets & Lists - Allow them to use memory arenas - Zero is initialization @@ -28,8 +34,11 @@ Ground Up Reengineering - custom sculpture update functions (for motion) - placing sculptures - editing sculpture files (change universe output) + - led groups & subgroups - defined in file - Network + - Handle Error Cases + - Handle connecting a sculpture after launch - Artnet - Universe offsets (per sculpture)