Implemented tag based filtering of led strips
This commit is contained in:
parent
1db836890f
commit
337b4ac271
|
@ -5,7 +5,7 @@
|
||||||
//
|
//
|
||||||
#ifndef FOLDHAUS_ANIMATION
|
#ifndef FOLDHAUS_ANIMATION
|
||||||
|
|
||||||
#define ANIMATION_PROC(name) void name(led_buffer* Assembly, r32 Time)
|
#define ANIMATION_PROC(name) void name(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient)
|
||||||
typedef ANIMATION_PROC(animation_proc);
|
typedef ANIMATION_PROC(animation_proc);
|
||||||
|
|
||||||
struct frame_range
|
struct frame_range
|
||||||
|
|
|
@ -154,6 +154,45 @@ UnloadAssembly (u32 AssemblyIndex, app_state* State, context Context)
|
||||||
State->Assemblies.Values[AssemblyIndex] = State->Assemblies.Values[LastAssemblyIndex];
|
State->Assemblies.Values[AssemblyIndex] = State->Assemblies.Values[LastAssemblyIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Querying Assemblies
|
||||||
|
|
||||||
|
internal led_strip_list
|
||||||
|
AssemblyStripsGetWithTagValue(assembly Assembly, gs_const_string TagName, gs_const_string TagValue, gs_memory_arena* Storage)
|
||||||
|
{
|
||||||
|
led_strip_list Result = {0};
|
||||||
|
// TODO(pjs): @Optimization
|
||||||
|
// We can probably come back here and do this allocation procedurally, or in buckets, or with
|
||||||
|
// a linked list. But for now, I just want to get this up and running
|
||||||
|
Result.CountMax = Assembly.StripCount;
|
||||||
|
Result.StripIndices = PushArray(Storage, u32, Result.CountMax);
|
||||||
|
|
||||||
|
u64 NameHash = HashDJB2ToU32(StringExpand(TagName));
|
||||||
|
u64 ValueHash = 0;
|
||||||
|
if (TagValue.Length > 0)
|
||||||
|
{
|
||||||
|
ValueHash = HashDJB2ToU32(StringExpand(TagValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (u32 StripIndex = 0; StripIndex < Assembly.StripCount; StripIndex++)
|
||||||
|
{
|
||||||
|
v2_strip StripAt = Assembly.Strips[StripIndex];
|
||||||
|
for (u32 j = 0; j < StripAt.TagsCount; j++)
|
||||||
|
{
|
||||||
|
v2_tag TagAt = StripAt.Tags[j];
|
||||||
|
if (TagAt.NameHash == NameHash)
|
||||||
|
{
|
||||||
|
// NOTE(pjs): We can pass an empty string to the Value parameter,
|
||||||
|
// and it will match all values of Tag
|
||||||
|
if (ValueHash == 0 || ValueHash == TagAt.ValueHash)
|
||||||
|
{
|
||||||
|
Result.StripIndices[Result.Count++] = StripIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
#define FOLDHAUS_ASSEMBLY_CPP
|
#define FOLDHAUS_ASSEMBLY_CPP
|
||||||
#endif // FOLDHAUS_ASSEMBLY_CPP
|
#endif // FOLDHAUS_ASSEMBLY_CPP
|
|
@ -60,6 +60,13 @@ struct v2_strip
|
||||||
v2_tag* Tags;
|
v2_tag* Tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct led_strip_list
|
||||||
|
{
|
||||||
|
u32 Count;
|
||||||
|
u32 CountMax;
|
||||||
|
u32* StripIndices;
|
||||||
|
};
|
||||||
|
|
||||||
struct assembly
|
struct assembly
|
||||||
{
|
{
|
||||||
gs_memory_arena Arena;
|
gs_memory_arena Arena;
|
||||||
|
|
|
@ -153,7 +153,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
|
||||||
State->LedSystem = LedSystemInitialize(Context.ThreadContext.Allocator, 128);
|
State->LedSystem = LedSystemInitialize(Context.ThreadContext.Allocator, 128);
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
gs_const_string SculpturePath = ConstString("data/radialumia_v2.fold");
|
gs_const_string SculpturePath = ConstString("data/blumen_lumen_v2.fold");
|
||||||
LoadAssembly(&State->Assemblies, &State->LedSystem, &State->Transient, Context, SculpturePath, State->GlobalLog);
|
LoadAssembly(&State->Assemblies, &State->LedSystem, &State->Transient, Context, SculpturePath, State->GlobalLog);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -364,17 +364,17 @@ UPDATE_AND_RENDER(UpdateAndRender)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
TestPatternOne(&LayerLEDBuffers[Layer], SecondsIntoBlock);
|
TestPatternOne(&LayerLEDBuffers[Layer], *Assembly, SecondsIntoBlock, &State->Transient);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
TestPatternTwo(&LayerLEDBuffers[Layer], SecondsIntoBlock);
|
TestPatternTwo(&LayerLEDBuffers[Layer], *Assembly, SecondsIntoBlock, &State->Transient);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
TestPatternThree(&LayerLEDBuffers[Layer], SecondsIntoBlock);
|
TestPatternThree(&LayerLEDBuffers[Layer], *Assembly, SecondsIntoBlock, &State->Transient);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
// NOTE(Peter): Zero is invalid
|
// NOTE(Peter): Zero is invalid
|
||||||
|
|
|
@ -73,22 +73,45 @@ struct app_state
|
||||||
|
|
||||||
internal void OpenColorPicker(app_state* State, v4* Address);
|
internal void OpenColorPicker(app_state* State, v4* Address);
|
||||||
|
|
||||||
|
#include "engine/foldhaus_assembly.cpp"
|
||||||
|
|
||||||
// BEGIN TEMPORARY PATTERNS
|
// BEGIN TEMPORARY PATTERNS
|
||||||
internal void
|
internal void
|
||||||
TestPatternOne(led_buffer* Assembly, r32 Time)
|
TestPatternOne(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient)
|
||||||
{
|
{
|
||||||
for (u32 LedIndex = 0; LedIndex < Assembly->LedCount; LedIndex++)
|
led_strip_list StemStrips = AssemblyStripsGetWithTagValue(Assembly, ConstString("section"), ConstString("stem"), Transient);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < StemStrips.Count; i++)
|
||||||
{
|
{
|
||||||
v4 LedPosition = Assembly->Positions[LedIndex];
|
u32 StripIndex = StemStrips.StripIndices[i];
|
||||||
|
v2_strip StripAt = Assembly.Strips[StripIndex];
|
||||||
|
|
||||||
|
for (u32 j = 0; j < StripAt.LedCount; j++)
|
||||||
|
{
|
||||||
|
u32 LedIndex = StripAt.LedLUT[j];
|
||||||
|
v4 LedPosition = Leds->Positions[LedIndex];
|
||||||
|
float PercentX = RemapClampedR32(LedPosition.x, -150.0f, 150.0f, 0.0f, 1.0f);
|
||||||
|
float PercentY = RemapClampedR32(LedPosition.y, -150.0f, 150.0f, 0.0f, 1.0f);
|
||||||
|
Leds->Colors[LedIndex].R = (u8)(PercentX * 255);
|
||||||
|
Leds->Colors[LedIndex].G = (u8)(PercentY * 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
|
||||||
|
{
|
||||||
|
v4 LedPosition = Leds->Positions[LedIndex];
|
||||||
float PercentX = RemapClampedR32(LedPosition.x, -150.0f, 150.0f, 0.0f, 1.0f);
|
float PercentX = RemapClampedR32(LedPosition.x, -150.0f, 150.0f, 0.0f, 1.0f);
|
||||||
float PercentY = RemapClampedR32(LedPosition.y, -150.0f, 150.0f, 0.0f, 1.0f);
|
float PercentY = RemapClampedR32(LedPosition.y, -150.0f, 150.0f, 0.0f, 1.0f);
|
||||||
Assembly->Colors[LedIndex].R = (u8)(PercentX * 255);
|
Leds->Colors[LedIndex].R = (u8)(PercentX * 255);
|
||||||
Assembly->Colors[LedIndex].G = (u8)(PercentY * 255);
|
Leds->Colors[LedIndex].G = (u8)(PercentY * 255);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
TestPatternTwo(led_buffer* Assembly, r32 Time)
|
TestPatternTwo(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient)
|
||||||
{
|
{
|
||||||
r32 PeriodicTime = (Time / PiR32) * 2;
|
r32 PeriodicTime = (Time / PiR32) * 2;
|
||||||
|
|
||||||
|
@ -107,9 +130,9 @@ TestPatternTwo(led_buffer* Assembly, r32 Time)
|
||||||
r32 OuterRadiusSquared = 1000000;
|
r32 OuterRadiusSquared = 1000000;
|
||||||
r32 InnerRadiusSquared = 0;
|
r32 InnerRadiusSquared = 0;
|
||||||
|
|
||||||
for (u32 LedIndex = 0; LedIndex < Assembly->LedCount; LedIndex++)
|
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
|
||||||
{
|
{
|
||||||
v4 Position = Assembly->Positions[LedIndex];
|
v4 Position = Leds->Positions[LedIndex];
|
||||||
|
|
||||||
v4 ToFront = Position + FrontCenter;
|
v4 ToFront = Position + FrontCenter;
|
||||||
v4 ToBack = Position + BackCenter;
|
v4 ToBack = Position + BackCenter;
|
||||||
|
@ -125,22 +148,22 @@ TestPatternTwo(led_buffer* Assembly, r32 Time)
|
||||||
{
|
{
|
||||||
if (XOR(ToFrontDotNormal > 0, ToBackDotNormal > 0))
|
if (XOR(ToFrontDotNormal > 0, ToBackDotNormal > 0))
|
||||||
{
|
{
|
||||||
Assembly->Colors[LedIndex] = Color;
|
Leds->Colors[LedIndex] = Color;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Assembly->Colors[LedIndex] = {};
|
//Leds->Colors[LedIndex] = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Assembly->Colors[LedIndex] = {};
|
//Leds->Colors[LedIndex] = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
TestPatternThree(led_buffer* Assembly, r32 Time)
|
TestPatternThree(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient)
|
||||||
{
|
{
|
||||||
v4 GreenCenter = v4{0, 0, 150, 1};
|
v4 GreenCenter = v4{0, 0, 150, 1};
|
||||||
r32 GreenRadius = Abs(SinR32(Time)) * 200;
|
r32 GreenRadius = Abs(SinR32(Time)) * 200;
|
||||||
|
@ -151,9 +174,9 @@ TestPatternThree(led_buffer* Assembly, r32 Time)
|
||||||
r32 FadeDist = 35;
|
r32 FadeDist = 35;
|
||||||
|
|
||||||
|
|
||||||
for (u32 LedIndex = 0; LedIndex < Assembly->LedCount; LedIndex++)
|
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
|
||||||
{
|
{
|
||||||
v4 LedPosition = Assembly->Positions[LedIndex];
|
v4 LedPosition = Leds->Positions[LedIndex];
|
||||||
u8 Red = 0;
|
u8 Red = 0;
|
||||||
u8 Green = 0;
|
u8 Green = 0;
|
||||||
u8 Blue = 0;
|
u8 Blue = 0;
|
||||||
|
@ -167,16 +190,14 @@ TestPatternThree(led_buffer* Assembly, r32 Time)
|
||||||
Red = (u8)(TealBrightness * 255);
|
Red = (u8)(TealBrightness * 255);
|
||||||
Blue = (u8)(TealBrightness * 255);
|
Blue = (u8)(TealBrightness * 255);
|
||||||
|
|
||||||
Assembly->Colors[LedIndex].R = Red;
|
Leds->Colors[LedIndex].R = Red;
|
||||||
Assembly->Colors[LedIndex].B = Green;
|
Leds->Colors[LedIndex].B = Green;
|
||||||
Assembly->Colors[LedIndex].G = Green;
|
Leds->Colors[LedIndex].G = Green;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// END TEMPORARY PATTERNS
|
// END TEMPORARY PATTERNS
|
||||||
|
|
||||||
#include "engine/foldhaus_assembly.cpp"
|
|
||||||
|
|
||||||
FOLDHAUS_INPUT_COMMAND_PROC(EndCurrentOperationMode)
|
FOLDHAUS_INPUT_COMMAND_PROC(EndCurrentOperationMode)
|
||||||
{
|
{
|
||||||
DeactivateCurrentOperationMode(&State->Modes);
|
DeactivateCurrentOperationMode(&State->Modes);
|
||||||
|
|
Loading…
Reference in New Issue