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

This commit is contained in:
Peter Slattery 2020-02-04 22:50:12 -08:00
parent 33338daab7
commit 51955ba765
8 changed files with 73 additions and 66 deletions

View File

@ -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

View File

@ -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 <typename T>
gs_bucket<T>::gs_bucket()
{
this->BucketSize = 0;
this->BucketCount = 0;
this->Buckets = 0;
this->Used = 0;
}
template <typename T>
gs_bucket<T>::gs_bucket(u32 BucketSize)
{
this->BucketSize = BucketSize;
this->BucketCount = 0;
this->Buckets = 0;
this->Used = 0;
}
template <typename T>
void gs_bucket<T>::GrowBucket()
{
if (this->BucketCount == 0)
{
// First Grow Attempt
this->Buckets = 0;
}
if (this->BucketSize == 0)
{
this->BucketSize = GS_LIST_DEFAULT_BUCKET_SIZE;

View File

@ -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;
};

View File

@ -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)
{

View File

@ -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"

View File

@ -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);
}
}

View File

@ -194,8 +194,14 @@ PLATFORM_SEND_TO(Win32SendTo)
if (LengthSent == SOCKET_ERROR)
{
s32 Error = WSAGetLastError();
if (Error == 10051)
{
}
else
{
InvalidCodePath;
}
}
return LengthSent;
}

View File

@ -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)