Cleaned up some extraneous variables in the assembly structure

This commit is contained in:
Peter Slattery 2020-06-19 18:53:23 -07:00
parent 69db4b436c
commit 9c432a3807
10 changed files with 86 additions and 111 deletions

View File

@ -314,8 +314,7 @@ CreateDMXBuffers(assembly Assembly, led_system* LedSystem, s32 BufferHeaderSize,
for (u32 i = 0; i < Strip.LedCount; i++)
{
u32 LedIndex = Strip.LedLUT[i];
led LED = LedBuffer->Leds[LedIndex];
pixel Color = LedBuffer->Colors[LED.Index];
pixel Color = LedBuffer->Colors[LedIndex];
DestChannel[0] = Color.R;
DestChannel[1] = Color.G;
@ -529,6 +528,7 @@ UPDATE_AND_RENDER(UpdateAndRender)
Context->GeneralWorkQueue->ResetWorkQueue(Context->GeneralWorkQueue);
// Checking for overflows
#if 0
{
DEBUG_TRACK_SCOPE(OverflowChecks);
AssertAllocationsNoOverflow(State->Permanent);
@ -538,6 +538,7 @@ UPDATE_AND_RENDER(UpdateAndRender)
AssertAllocationsNoOverflow(Assembly->Arena);
}
}
#endif
}
CLEANUP_APPLICATION(CleanupApplication)

View File

@ -94,18 +94,18 @@ TestPatternOne(led_buffer* Assembly, r32 Time)
{
for (u32 LedIndex = 0; LedIndex < Assembly->LedCount; LedIndex++)
{
led Led = Assembly->Leds[LedIndex];
if (Led.Position.x < 0)
v4 LedPosition = Assembly->Positions[LedIndex];
if (LedPosition.x < 0)
{
Assembly->Colors[Led.Index].R = 255;
Assembly->Colors[Led.Index].B = 255;
Assembly->Colors[Led.Index].G = 255;
Assembly->Colors[LedIndex].R = 255;
Assembly->Colors[LedIndex].B = 255;
Assembly->Colors[LedIndex].G = 255;
}
else
{
Assembly->Colors[Led.Index].R = 0;
Assembly->Colors[Led.Index].B = 0;
Assembly->Colors[Led.Index].G = 0;
Assembly->Colors[LedIndex].R = 0;
Assembly->Colors[LedIndex].B = 0;
Assembly->Colors[LedIndex].G = 0;
}
}
}
@ -132,9 +132,7 @@ TestPatternTwo(led_buffer* Assembly, r32 Time)
for (u32 LedIndex = 0; LedIndex < Assembly->LedCount; LedIndex++)
{
led Led = Assembly->Leds[LedIndex];
v4 Position = Led.Position;
v4 Position = Assembly->Positions[LedIndex];
v4 ToFront = Position + FrontCenter;
v4 ToBack = Position + BackCenter;
@ -150,16 +148,16 @@ TestPatternTwo(led_buffer* Assembly, r32 Time)
{
if (XOR(ToFrontDotNormal > 0, ToBackDotNormal > 0))
{
Assembly->Colors[Led.Index] = Color;
Assembly->Colors[LedIndex] = Color;
}
else
{
//Assembly->Colors[Led.Index] = {};
//Assembly->Colors[LedIndex] = {};
}
}
else
{
//Assembly->Colors[Led.Index] = {};
//Assembly->Colors[LedIndex] = {};
}
}
}
@ -178,23 +176,23 @@ TestPatternThree(led_buffer* Assembly, r32 Time)
for (u32 LedIndex = 0; LedIndex < Assembly->LedCount; LedIndex++)
{
led Led = Assembly->Leds[LedIndex];
v4 LedPosition = Assembly->Positions[LedIndex];
u8 Red = 0;
u8 Green = 0;
u8 Blue = 0;
r32 GreenDist = GSAbs(Mag(Led.Position - GreenCenter) - GreenRadius);
r32 GreenDist = GSAbs(Mag(LedPosition - GreenCenter) - GreenRadius);
r32 GreenBrightness = GSClamp(0.f, FadeDist - GSAbs(GreenDist), FadeDist);
Green = (u8)(GreenBrightness * 255);
r32 TealDist = GSAbs(Mag(Led.Position - TealCenter) - TealRadius);
r32 TealDist = GSAbs(Mag(LedPosition - 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;
Assembly->Colors[LedIndex].R = Red;
Assembly->Colors[LedIndex].B = Green;
Assembly->Colors[LedIndex].G = Green;
}
}

View File

@ -34,7 +34,7 @@ LedSystemTakeFreeBuffer(led_system* System, u32 LedCount)
{
if (System->Buffers[i].LedCount == 0
&& System->Buffers[i].Colors == 0
&& System->Buffers[i].Leds == 0)
&& System->Buffers[i].Positions == 0)
{
Result = i;
break;
@ -46,7 +46,7 @@ LedSystemTakeFreeBuffer(led_system* System, u32 LedCount)
led_buffer* Buffer = &System->Buffers[Result];
Buffer->LedCount = LedCount;
Buffer->Colors = PlatformAllocArray(System->PlatformMemory, pixel, Buffer->LedCount);
Buffer->Leds = PlatformAllocArray(System->PlatformMemory, led, Buffer->LedCount);
Buffer->Positions = PlatformAllocArray(System->PlatformMemory, v4, Buffer->LedCount);
System->LedsCountTotal += LedCount;
@ -59,7 +59,7 @@ LedSystemFreeBuffer(led_system* System, u32 BufferIndex)
Assert(BufferIndex < System->BuffersCountMax);
led_buffer* Buffer = &System->Buffers[BufferIndex];
PlatformFreeArray(System->PlatformMemory, Buffer->Colors, pixel, Buffer->LedCount);
PlatformFreeArray(System->PlatformMemory, Buffer->Leds, led, Buffer->LedCount);
PlatformFreeArray(System->PlatformMemory, Buffer->Positions, v4, Buffer->LedCount);
System->LedsCountTotal -= Buffer->LedCount;
*Buffer = {};
}
@ -75,8 +75,7 @@ internal void
LedBufferSetLed(led_buffer* Buffer, u32 Led, v4 Position)
{
Assert(Led < Buffer->LedCount);
Buffer->Leds[Led].Position = Position;
Buffer->Leds[Led].Index = Led;
Buffer->Positions[Led] = Position;
}
// Assembly

View File

@ -5,13 +5,6 @@
//
#ifndef FOLDHAUS_ASSEMBLY_H
struct led
{
// TODO(Peter): Pretty sure we don't need this. led and pixel are always parallel arrays
s32 Index;
v4 Position;
};
union pixel
{
struct
@ -27,7 +20,7 @@ struct led_buffer
{
u32 LedCount;
pixel* Colors;
led* Leds;
v4* Positions;
};
struct led_system
@ -50,6 +43,7 @@ struct v2_tag
struct v2_strip
{
s32 ControlBoxID; // TODO(Peter): I don't think we need this anymore
// TODO(Peter): Add in info for Serial, ArtNet, etc.
s32 StartUniverse;
s32 StartChannel;

View File

@ -132,28 +132,25 @@ struct multiply_patterns_data
NODE_PROC(MultiplyPatterns, multiply_patterns_data)
{
led* LED = Data->Result.LEDs;
for (s32 l = 0; l < Data->Result.LEDCount; l++)
for (s32 LedIndex = 0; LedIndex < Data->Result.LEDCount; LedIndex++)
{
Assert(LED->Index >= 0 && LED->Index < Data->Result.LEDCount);
Assert(LedIndex >= 0 && LedIndex < Data->Result.LEDCount);
s32 AR = Data->A.Colors[LED->Index].R;
s32 AG = Data->A.Colors[LED->Index].G;
s32 AB = Data->A.Colors[LED->Index].B;
s32 AR = Data->A.Colors[LedIndex].R;
s32 AG = Data->A.Colors[LedIndex].G;
s32 AB = Data->A.Colors[LedIndex].B;
s32 BR = Data->B.Colors[LED->Index].R;
s32 BG = Data->B.Colors[LED->Index].G;
s32 BB = Data->B.Colors[LED->Index].B;
s32 BR = Data->B.Colors[LedIndex].R;
s32 BG = Data->B.Colors[LedIndex].G;
s32 BB = Data->B.Colors[LedIndex].B;
s32 RCombined = (AR * BR) / 255;
s32 GCombined = (AG * BG) / 255;
s32 BCombined = (AB * BB) / 255;
Data->Result.Colors[LED->Index].R = (u8)RCombined;
Data->Result.Colors[LED->Index].G = (u8)GCombined;
Data->Result.Colors[LED->Index].B = (u8)BCombined;
LED++;
Data->Result.Colors[LedIndex].R = (u8)RCombined;
Data->Result.Colors[LedIndex].G = (u8)GCombined;
Data->Result.Colors[LedIndex].B = (u8)BCombined;
}
}

View File

@ -14,7 +14,7 @@ typedef enum node_type node_type;
struct color_buffer
{
led* LEDs;
v4* LedPositions;
pixel* Colors;
s32 LEDCount;
};

View File

@ -39,10 +39,9 @@ enum gsm_struct_type
gsm_StructType_v4,
gsm_StructType_float,
gsm_StructType_color_buffer,
gsm_StructType_led,
gsm_StructType_s32,
gsm_StructType_pixel,
gsm_StructType_u8,
gsm_StructType_s32,
gsm_StructType_sin_wave_data,
gsm_StructType_r32,
gsm_StructType_revolving_discs_data,
@ -62,10 +61,6 @@ static gsm_struct_member_type_info StructMembers_v4[] = {
{ "a", 1, (u64)&((v4*)0)->a, {}, 0},
{ "E", 1, (u64)&((v4*)0)->E, {}, 0},
};
static gsm_struct_member_type_info StructMembers_led[] = {
{ "Index", 5, (u64)&((led*)0)->Index, {}, 0},
{ "Position", 8, (u64)&((led*)0)->Position, {}, 0},
};
static gsm_struct_member_type_info StructMembers_pixel[] = {
{ "R", 1, (u64)&((pixel*)0)->R, {}, 0},
{ "G", 1, (u64)&((pixel*)0)->G, {}, 0},
@ -73,7 +68,7 @@ static gsm_struct_member_type_info StructMembers_pixel[] = {
{ "Channels", 8, (u64)&((pixel*)0)->Channels, {}, 0},
};
static gsm_struct_member_type_info StructMembers_color_buffer[] = {
{ "LEDs", 4, (u64)&((color_buffer*)0)->LEDs, {}, 0},
{ "LedPositions", 12, (u64)&((color_buffer*)0)->LedPositions, {}, 0},
{ "Colors", 6, (u64)&((color_buffer*)0)->Colors, {}, 0},
{ "LEDCount", 8, (u64)&((color_buffer*)0)->LEDCount, {}, 0},
};
@ -115,14 +110,13 @@ static gsm_struct_type_info StructTypes[] = {
{ gsm_StructType_v4, "v4", 2, 16, 0, 0, StructMembers_v4, 3 },
{ gsm_StructType_float, "float", 5, 4, 0, 0, 0, 0 },
{ gsm_StructType_color_buffer, "color_buffer", 12, 20, 0, 0, StructMembers_color_buffer, 3 },
{ gsm_StructType_led, "led", 3, 20, 0, 0, StructMembers_led, 2 },
{ gsm_StructType_s32, "s32", 3, 4, 0, 0, 0, 0 },
{ gsm_StructType_pixel, "pixel", 5, 3, 0, 0, StructMembers_pixel, 2 },
{ gsm_StructType_u8, "u8", 2, 1, 0, 0, 0, 0 },
{ gsm_StructType_s32, "s32", 3, 4, 0, 0, 0, 0 },
{ gsm_StructType_sin_wave_data, "sin_wave_data", 13, 20, 0, 0, StructMembers_sin_wave_data, 5 },
{ gsm_StructType_r32, "r32", 3, 4, 0, 0, 0, 0 },
{ gsm_StructType_revolving_discs_data, "revolving_discs_data", 20, 60, 0, 0, StructMembers_revolving_discs_data, 8 },
{ gsm_StructType_vertical_color_fade_data, "vertical_color_fade_data", 24, 44, 0, 0, StructMembers_vertical_color_fade_data, 4 },
{ gsm_StructType_multiply_patterns_data, "multiply_patterns_data", 22, 60, 0, 0, StructMembers_multiply_patterns_data, 3 },
};
static gsm_u32 StructTypesCount = 13;
static gsm_u32 StructTypesCount = 12;

View File

@ -71,7 +71,7 @@ SculptureView_Cleanup(panel* Panel, app_state* State)
struct draw_leds_job_data
{
led* LEDs;
v4* Positions;
pixel* Colors;
s32 StartIndex;
s32 OnePastLastIndex;
@ -107,15 +107,13 @@ DrawLEDsInBufferRangeJob (s32 ThreadID, void* JobData)
v2 UV2 = v2{1, 1};
v2 UV3 = v2{0, 1};
led* LED = Data->LEDs + Data->StartIndex;
for (s32 LEDIdx = 0;
LEDIdx < LEDCount;
LEDIdx++)
for (s32 LedIndex = 0; LedIndex < LEDCount; LedIndex++)
{
pixel PixelColor = Data->Colors[LED->Index];
pixel PixelColor = Data->Colors[LedIndex];
v4 Color = v4{PixelColor.R / 255.f, PixelColor.G / 255.f, PixelColor.B / 255.f, 1.0f};
v4 V4Position = LED->Position;
v4 V4Position = Data->Positions[Data->StartIndex + LedIndex];
V4Position.w = 0;
v4 P0 = P0_In + V4Position;
v4 P1 = P1_In + V4Position;
@ -126,8 +124,6 @@ DrawLEDsInBufferRangeJob (s32 ThreadID, void* JobData)
P0, P1, P2, UV0, UV1, UV2, Color, Color, Color);
SetTri3DInBatch(Data->Batch, BatchReservedRange.Start + TrisUsed++,
P0, P2, P3, UV0, UV2, UV3, Color, Color, Color);
LED++;
}
}
@ -165,7 +161,7 @@ SculptureView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
for (u32 Job = 0; Job < JobsNeeded; Job++)
{
draw_leds_job_data* JobData = PushStruct(&State->Transient, draw_leds_job_data);
JobData->LEDs = LedBuffer->Leds;
JobData->Positions = LedBuffer->Positions;
JobData->Colors = LedBuffer->Colors;
JobData->StartIndex = Job * MaxLEDsPerJob;
JobData->OnePastLastIndex = GSMin(JobData->StartIndex + MaxLEDsPerJob, LedBuffer->LedCount);

View File

@ -22,15 +22,13 @@ void SolidColorProc(solid_color_data* Data)
u8 G = (u8)GSClamp(0.f, (Data->Color.g * 255), 255.f);
u8 B = (u8)GSClamp(0.f, (Data->Color.b * 255), 255.f);
led* LED = Data->Result.LEDs;
for (s32 l = 0; l < Data->Result.LEDCount; l++)
for (s32 LedIndex = 0; LedIndex < Data->Result.LEDCount; LedIndex++)
{
Assert(LED->Index >= 0 && LED->Index < Data->Result.LEDCount);
Assert(LedIndex >= 0 && LedIndex < Data->Result.LEDCount);
Data->Result.Colors[LED->Index].R = R;
Data->Result.Colors[LED->Index].G = G;
Data->Result.Colors[LED->Index].B = B;
LED++;
Data->Result.Colors[LedIndex].R = R;
Data->Result.Colors[LedIndex].G = G;
Data->Result.Colors[LedIndex].B = B;
}
}
@ -59,18 +57,18 @@ void VerticalColorFadeProc(vertical_color_fade_data* Data)
r32 Range = Data->Max - Data->Min;
led* LED = Data->Result.LEDs;
for (s32 l = 0; l < Data->Result.LEDCount; l++)
{
Assert(LED->Index >= 0 && LED->Index < Data->Result.LEDCount);
r32 Amount = (LED->Position.y - Data->Min) / Range;
for (s32 LedIndex = 0; LedIndex < Data->Result.LEDCount; LedIndex++)
{
Assert(LedIndex >= 0 && LedIndex < Data->Result.LEDCount);
v4 LedPosition = Data->Result.LedPositions[LedIndex];
r32 Amount = (LedPosition.y - Data->Min) / Range;
Amount = GSClamp01(1.0f - Amount);
Data->Result.Colors[LED->Index].R = (u8)(R * Amount);
Data->Result.Colors[LED->Index].G = (u8)(G * Amount);
Data->Result.Colors[LED->Index].B = (u8)(B * Amount);
LED++;
Data->Result.Colors[LedIndex].R = (u8)(R * Amount);
Data->Result.Colors[LedIndex].G = (u8)(G * Amount);
Data->Result.Colors[LedIndex].B = (u8)(B * Amount);
}
}
@ -124,10 +122,9 @@ void RevolvingDiscs(revolving_discs_data* Data)
r32 OuterRadiusSquared = Data->OuterRadius * Data->OuterRadius;
r32 InnerRadiusSquared = Data->InnerRadius * Data->InnerRadius;
led* LED = Data->Result.LEDs;
for (s32 l = 0; l < Data->Result.LEDCount; l++)
for (s32 LedIndex = 0; LedIndex < Data->Result.LEDCount; LedIndex++)
{
v4 Position = LED->Position;
v4 Position = Data->Result.LedPositions[LedIndex];
v4 ToFront = Position + FrontCenter;
v4 ToBack = Position + BackCenter;
@ -143,10 +140,9 @@ void RevolvingDiscs(revolving_discs_data* Data)
{
if (XOR(ToFrontDotNormal > 0, ToBackDotNormal > 0))
{
Data->Result.Colors[LED->Index] = Color;
Data->Result.Colors[LedIndex] = Color;
}
}
LED++;
}
}

View File

@ -21,7 +21,7 @@ PLATFORM_FREE(Win32Free)
b32 Result = VirtualFree(Base, 0, MEM_RELEASE);
if (!Result)
{
s32 Error = WSAGetLastError();
s32 Error = GetLastError();
// TODO(Peter): I'm waiting to see an error actually occur here
// to know what it could possibly be.
InvalidCodePath;