Saturday @ Foldspace

This commit is contained in:
Peter Slattery 2021-01-30 19:33:44 -08:00
parent 8a51ce2f04
commit c58ef9e40a
3 changed files with 196 additions and 37 deletions

View File

@ -12,8 +12,19 @@ BlumenLumen_MicListenJob(gs_thread_context* Ctx, u8* UserData)
gs_data Msg = {}; gs_data Msg = {};
u8 WeathermanIPAddr[4] = {};
WeathermanIPAddr[0] = 127;
WeathermanIPAddr[1] = 0;
WeathermanIPAddr[2] = 0;
WeathermanIPAddr[3] = 1;
u32 WeathermanIPV4 = (u32)UpackB4(WeathermanIPAddr);
u32 WeathermanPort = 20185;
while (true) while (true)
{ {
#if 0
// TODO(pjs): Removing this block for now - nothing is wrong with it except that SocketPeek is still blocking for some reason
if (SocketPeek(Data->SocketManager, Data->ListenSocket)) if (SocketPeek(Data->SocketManager, Data->ListenSocket))
{ {
// TODO(pjs): Make this a peek operation // TODO(pjs): Make this a peek operation
@ -27,6 +38,7 @@ BlumenLumen_MicListenJob(gs_thread_context* Ctx, u8* UserData)
} }
} }
} }
#endif
while (Data->OutgoingMsgQueue->ReadHead != Data->OutgoingMsgQueue->WriteHead) while (Data->OutgoingMsgQueue->ReadHead != Data->OutgoingMsgQueue->WriteHead)
{ {
@ -37,8 +49,8 @@ BlumenLumen_MicListenJob(gs_thread_context* Ctx, u8* UserData)
} }
Msg = Data->OutgoingMsgQueue->Buffers[ReadIndex]; Msg = Data->OutgoingMsgQueue->Buffers[ReadIndex];
u32 Address = 0; u32 Address = WeathermanIPV4;
u32 Port = 0; u32 Port = WeathermanPort;
s32 Flags = 0; s32 Flags = 0;
SocketSend(Data->SocketManager, Data->ListenSocket, Address, Port, Msg, Flags); SocketSend(Data->SocketManager, Data->ListenSocket, Address, Port, Msg, Flags);
} }
@ -72,6 +84,20 @@ BlumenLumen_LoadPatterns(app_state* State)
Patterns_PushPattern(Patterns, Pattern_Green); Patterns_PushPattern(Patterns, Pattern_Green);
Patterns_PushPattern(Patterns, Pattern_FlowerColors); Patterns_PushPattern(Patterns, Pattern_FlowerColors);
Patterns_PushPattern(Patterns, Pattern_FlowerColorToWhite); Patterns_PushPattern(Patterns, Pattern_FlowerColorToWhite);
Patterns_PushPattern(Patterns, Pattern_BasicFlowers);
}
internal pixel
TEMP_Saturate(pixel P)
{
v4 CRGB = v4{ (r32)P.R / 255.f, (r32)P.G / 255.f, (r32)P.B / 255.f, 1.f };
v4 CHSV = RGBToHSV(CRGB);
if (CHSV.g > .3f)
{
CHSV.g = 1;
CRGB = HSVToRGB(CHSV);
}
return V4ToRGBPixel(CRGB);
} }
internal gs_data internal gs_data
@ -91,7 +117,7 @@ BlumenLumen_CustomInit(app_state* State, context Context)
BLState->MicListenJobData.OutgoingMsgQueue = &BLState->OutgoingMsgQueue; BLState->MicListenJobData.OutgoingMsgQueue = &BLState->OutgoingMsgQueue;
BLState->MicListenJobData.ListenSocket = CreateSocket(Context.SocketManager, "127.0.0.1", "20185"); BLState->MicListenJobData.ListenSocket = CreateSocket(Context.SocketManager, "127.0.0.1", "20185");
BLState->MicListenThread = CreateThread(Context.ThreadManager, BlumenLumen_MicListenJob, (u8*)&BLState->MicListenJobData); //BLState->MicListenThread = CreateThread(Context.ThreadManager, BlumenLumen_MicListenJob, (u8*)&BLState->MicListenJobData);
gs_const_string SculpturePath = ConstString("data/test_blumen.fold"); gs_const_string SculpturePath = ConstString("data/test_blumen.fold");
LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath, State->GlobalLog); LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath, State->GlobalLog);
@ -105,7 +131,7 @@ BlumenLumen_CustomInit(app_state* State, context Context)
Anim0.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem); Anim0.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
Animation_AddLayer(&Anim0, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem); Animation_AddLayer(&Anim0, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
Animation_AddBlock(&Anim0, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(11), 0); Animation_AddBlock(&Anim0, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(15), 0);
AnimationArray_Push(&State->AnimationSystem.Animations, Anim0); AnimationArray_Push(&State->AnimationSystem.Animations, Anim0);
@ -136,9 +162,18 @@ BlumenLumen_CustomInit(app_state* State, context Context)
State->AnimationSystem.TimelineShouldAdvance = true; State->AnimationSystem.TimelineShouldAdvance = true;
} // End Animation Playground } // End Animation Playground
for (u32 i = 0; i < FLOWER_COLORS_COUNT; i++)
{
FlowerAColors[i] = TEMP_Saturate(FlowerAColors[i]);
FlowerBColors[i] = TEMP_Saturate(FlowerBColors[i]);
FlowerCColors[i] = TEMP_Saturate(FlowerCColors[i]);
}
return Result; return Result;
} }
u8 temp = 0;
internal void internal void
BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
{ {
@ -184,9 +219,10 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
*Msg = PushSizeToData(&State->Permanent, sizeof(motor_packet)); *Msg = PushSizeToData(&State->Permanent, sizeof(motor_packet));
} }
motor_packet* Packet = (motor_packet*)Msg->Memory; motor_packet* Packet = (motor_packet*)Msg->Memory;
Packet->FlowerPositions[0] = 5; Packet->FlowerPositions[0] = temp;
Packet->FlowerPositions[0] = 4; Packet->FlowerPositions[1] = temp + 1;
Packet->FlowerPositions[0] = 9; Packet->FlowerPositions[2] = temp + 2;
temp++;
// NOTE(pjs): We increment the write head AFTER we've written so that // NOTE(pjs): We increment the write head AFTER we've written so that
// the network thread doesn't think the buffer is ready to send before // the network thread doesn't think the buffer is ready to send before

View File

@ -6,7 +6,8 @@
#ifndef BLUMEN_PATTERNS_H #ifndef BLUMEN_PATTERNS_H
#define FLOWER_COLORS_COUNT 12 #define FLOWER_COLORS_COUNT 12
pixel FlowerColors[FLOWER_COLORS_COUNT] = {
pixel FlowerAColors[FLOWER_COLORS_COUNT] = {
{ 232,219,88 }, { 232,219,88 },
{ 232,219,88 }, { 232,219,88 },
{ 232,219,88 }, { 232,219,88 },
@ -20,6 +21,34 @@ pixel FlowerColors[FLOWER_COLORS_COUNT] = {
{ 116,126,39 }, { 116,126,39 },
{ 61,62,31 } { 61,62,31 }
}; };
pixel FlowerBColors[FLOWER_COLORS_COUNT] = {
{ 62,56,139 },
{ 93,87,164 },
{ 93,87,164 },
{ 93,87,164 },
{ 155,140,184 },
{ 191,201,204 },
{ 45,31,116 },
{ 201,196,156 },
{ 191,175,109 },
{ 186,176,107 },
{ 89,77,17 },
{ 47,49,18 },
};
pixel FlowerCColors[FLOWER_COLORS_COUNT] = {
{ 220,217,210 },
{ 220,217,210 },
{ 220,217,210 },
{ 225,193,110 },
{ 225,193,110 },
{ 227,221,214 },
{ 227,221,214 },
{ 230,218,187 },
{ 230,218,187 },
{ 172,190,211 },
{ 172,190,211 },
{ 172,190,211 },
};
internal pixel internal pixel
PixelMix(r32 T, pixel A, pixel B) PixelMix(r32 T, pixel A, pixel B)
@ -80,8 +109,8 @@ Pattern_FlowerColors(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_ar
r32 CycleTime = 10; r32 CycleTime = 10;
r32 CyclePercent = ModR32(Time, CycleTime) / CycleTime; r32 CyclePercent = ModR32(Time, CycleTime) / CycleTime;
pixel CA = GetColor(FlowerColors, FLOWER_COLORS_COUNT, CyclePercent); pixel CA = GetColor(FlowerAColors, FLOWER_COLORS_COUNT, CyclePercent);
pixel CB = GetColor(FlowerColors, FLOWER_COLORS_COUNT, 1.0f - CyclePercent); pixel CB = GetColor(FlowerAColors, FLOWER_COLORS_COUNT, 1.0f - CyclePercent);
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++) for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
{ {
@ -211,6 +240,54 @@ TestPatternThree(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena*
} }
} }
v4 RGBToHSV(v4 In)
{
v4 Result = {};
r32 Min = Min(In.r, Min(In.g, In.b));
r32 Max = Max(In.r, Max(In.g, In.b));
r32 V = Max;
r32 Delta = Max - Min;
r32 S = 0;
r32 H = 0;
if( Max != 0 )
{
S = Delta / Max;
if( In.r == Max )
{
H = ( In.g - In.b ) / Delta; // between yellow & magenta
}
else if( In.g == Max )
{
H = 2 + ( In.b - In.r ) / Delta; // between cyan & yellow
}
else
{
H = 4 + ( In.r - In.g ) / Delta; // between magenta & cyan
}
H *= 60; // degrees
if( H < 0 )
H += 360;
Assert(H);
//if ( isNaN(h) )
//H = 0;
Result = v4{H, S, V, 1};
}
else
{
// r = g = b = 0
// s = 0, v is undefined
S = 0;
H = -1;
Result = v4{H, S, 1, 1};
}
return Result;
}
v4 HSVToRGB (v4 In) v4 HSVToRGB (v4 In)
{ {
float Hue = In.x; float Hue = In.x;
@ -551,6 +628,9 @@ Pattern_FlowerColorToWhite(led_buffer* Leds, assembly Assembly, r32 Time, gs_mem
{ {
v2_strip Strip = Assembly.Strips[StripIndex]; v2_strip Strip = Assembly.Strips[StripIndex];
#if 0
// All flowers same flower type
pixel* Colors = &FlowerAColors[0];
r32 FlowerSpread = .8f; r32 FlowerSpread = .8f;
r32 FlowerOffset = 0; r32 FlowerOffset = 0;
if (AssemblyStrip_HasTagValueSLOW(Strip, "flower", "center")) if (AssemblyStrip_HasTagValueSLOW(Strip, "flower", "center"))
@ -562,46 +642,86 @@ Pattern_FlowerColorToWhite(led_buffer* Leds, assembly Assembly, r32 Time, gs_mem
FlowerOffset = 2; FlowerOffset = 2;
} }
FlowerOffset *= FlowerSpread; FlowerOffset *= FlowerSpread;
#else
// Each flower different
pixel* Colors = &FlowerAColors[0];
r32 FlowerOffset = 0;
if (AssemblyStrip_HasTagValueSLOW(Strip, "flower", "center"))
{
Colors = &FlowerBColors[0];
}
else if (AssemblyStrip_HasTagValueSLOW(Strip, "flower", "right"))
{
Colors = &FlowerCColors[0];
}
#endif
r32 PercentCycle = ModR32(Time + FlowerOffset, 10) / 10; r32 PercentCycle = ModR32(Time + FlowerOffset, 10) / 10;
r32 FadeBottom = FadeBottomBase + RemapR32(SinR32((PercentCycle * 4) * TauR32), -1, 1, -50, 50); r32 FadeBottom = FadeBottomBase + RemapR32(SinR32((PercentCycle * 4) * TauR32), -1, 1, -50, 50);
v4 TopRGB = WhiteV4;
pixel TopColor = V4ToRGBPixel(TopRGB);
for (u32 i = 0; i < Strip.LedCount; i++) for (u32 i = 0; i < Strip.LedCount; i++)
{ {
u32 LedIndex = Strip.LedLUT[i]; u32 LedIndex = Strip.LedLUT[i];
v4 P = Leds->Positions[LedIndex]; v4 P = Leds->Positions[LedIndex];
pixel FinalColor = {}; pixel FinalColor = {};
if (P.y > FadeTop) r32 B = RemapR32(SinR32((P.y / 15.f) + (PercentCycle * TauR32)), -1, 1, .5f, 1.f);
{ r32 HNoise = RemapR32(SinR32((P.y / 31.f) + (PercentCycle * TauR32)), -1, 1, 0.f, 1.f);
FinalColor = TopColor;
} pixel BottomColor = GetColor(Colors, FLOWER_COLORS_COUNT, (PercentCycle + HNoise) / 2);
else
{ FinalColor = BottomColor;
r32 B = RemapR32(SinR32((P.y / 15.f) + (PercentCycle * TauR32)), -1, 1, .5f, 1.f);
r32 HNoise = RemapR32(SinR32((P.y / 31.f) + (PercentCycle * TauR32)), -1, 1, 0.f, 1.f);
pixel BottomColor = GetColor(FlowerColors, FLOWER_COLORS_COUNT, (PercentCycle + HNoise) / 2);
if (P.y < FadeBottom)
{
FinalColor = BottomColor;
}
else if (P.y >= FadeBottom && P.y <= FadeTop)
{
r32 FadePct = RemapR32(P.y, FadeBottom, FadeTop, 0, 1);
FinalColor = PixelMix(FadePct, BottomColor, TopColor);
}
}
Leds->Colors[LedIndex] = FinalColor; Leds->Colors[LedIndex] = FinalColor;
} }
} }
} }
r32 TLastFrame = 0;
pixel* FAC = &FlowerAColors[0];
pixel* FBC = &FlowerBColors[0];
pixel* FCC = &FlowerCColors[0];
internal void
Pattern_BasicFlowers(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
{
if (TLastFrame > Time)
{
pixel* Temp = FAC;
FAC = FBC;
FBC = FCC;
FCC = Temp;
}
TLastFrame = Time;
for (u32 StripIndex = 0; StripIndex < Assembly.StripCount; StripIndex++)
{
v2_strip Strip = Assembly.Strips[StripIndex];
// Each flower different
pixel* Colors = FAC;
if (AssemblyStrip_HasTagValueSLOW(Strip, "flower", "center"))
{
Colors = FBC;
}
else if (AssemblyStrip_HasTagValueSLOW(Strip, "flower", "right"))
{
Colors = FCC;
}
r32 CycleT = ModR32(Time, 10) * 20;
for (u32 i = 0; i < Strip.LedCount; i++)
{
u32 LedIndex = Strip.LedLUT[i];
v4 P = Leds->Positions[LedIndex];
r32 T = ModR32(P.y + CycleT, 200) / 200.f;
T = Clamp01(T);
Leds->Colors[LedIndex] = GetColor(Colors, FLOWER_COLORS_COUNT, T);
}
}
}
#define BLUMEN_PATTERNS_H #define BLUMEN_PATTERNS_H
#endif // BLUMEN_PATTERNS_H #endif // BLUMEN_PATTERNS_H

View File

@ -234,8 +234,6 @@ Win32SocketReceive(platform_socket* Socket, gs_memory_arena* Storage)
} }
return Result; return Result;
#else #else
gs_data Result = PushSizeToData(Storage, 1024); gs_data Result = PushSizeToData(Storage, 1024);
s32 Flags = 0; s32 Flags = 0;
SOCKET* Win32Sock = (SOCKET*)Socket->PlatformHandle; SOCKET* Win32Sock = (SOCKET*)Socket->PlatformHandle;
@ -269,6 +267,11 @@ Win32SocketSend(platform_socket* Socket, u32 Address, u32 Port, gs_data Data, s3
if (Error == 10051) if (Error == 10051)
{ {
} }
if (Error == 10053)
{
// TODO(pjs): WSAECONNABORTED
InvalidCodePath;
}
else else
{ {
// TODO(Peter): :ErrorLogging // TODO(Peter): :ErrorLogging