SACN strips now wrap around to the next universe

This commit is contained in:
PS 2021-09-25 17:08:01 -05:00
parent d6eabfe3ac
commit f0f0a48acb
2 changed files with 239 additions and 223 deletions

View File

@ -344,11 +344,14 @@ SACN_GetUniverseSendAddress(s32 Universe)
return V4Address; return V4Address;
} }
internal void internal u64
SACN_FillBufferWithLeds(u8* BufferStart, u32 BufferSize, v2_strip Strip, led_buffer LedBuffer) SACN_FillBufferWithLeds(u8* BufferStart, u32 BufferSize, v2_strip Strip, u64 LedsPlaced, led_buffer LedBuffer)
{ {
u8* DestChannel = BufferStart; u8* DestChannel = BufferStart;
for (u32 i = 0; i < Strip.LedCount; i++) u64 FirstLed = LedsPlaced;
u64 LedsToAdd = Min(Strip.LedCount - LedsPlaced, STREAM_BODY_SIZE / 3);
u64 OnePastLastLed = FirstLed + LedsToAdd;
for (u32 i = FirstLed; i < OnePastLastLed; i++)
{ {
u32 LedIndex = Strip.LedLUT[i]; u32 LedIndex = Strip.LedLUT[i];
pixel Color = LedBuffer.Colors[LedIndex]; pixel Color = LedBuffer.Colors[LedIndex];
@ -358,6 +361,7 @@ SACN_FillBufferWithLeds(u8* BufferStart, u32 BufferSize, v2_strip Strip, led_buf
DestChannel[2] = Color.B; DestChannel[2] = Color.B;
DestChannel += 3; DestChannel += 3;
} }
return LedsToAdd;
} }
internal void internal void
@ -367,7 +371,7 @@ SACN_BuildOutputData(streaming_acn* SACN, addressed_data_buffer_list* Output, as
// TODO(pjs): 512 is a magic number - make it a constant? // TODO(pjs): 512 is a magic number - make it a constant?
s32 BufferHeaderSize = STREAM_HEADER_SIZE; s32 BufferHeaderSize = STREAM_HEADER_SIZE;
s32 BufferBodySize = 512; s32 BufferBodySize = STREAM_BODY_SIZE;
s32 BufferSize = BufferHeaderSize + BufferBodySize; s32 BufferSize = BufferHeaderSize + BufferBodySize;
for (u32 AssemblyIdx = 0; AssemblyIdx < Assemblies.Count; AssemblyIdx++) for (u32 AssemblyIdx = 0; AssemblyIdx < Assemblies.Count; AssemblyIdx++)
@ -379,14 +383,26 @@ SACN_BuildOutputData(streaming_acn* SACN, addressed_data_buffer_list* Output, as
{ {
v2_strip StripAt = Assembly.Strips[StripIdx]; v2_strip StripAt = Assembly.Strips[StripIdx];
u32 V4SendAddress = SACN_GetUniverseSendAddress(StripAt.SACNAddr.StartUniverse); // NOTE(PS): This isn't actually invalid, we just haven't needed to implement
// something more complex than only allowing strips to start at the first
// channel of a universe
Assert(StripAt.SACNAddr.StartChannel == 1);
u32 UniverseAt = StripAt.SACNAddr.StartUniverse;
u64 LedsPlaced = 0;
while (LedsPlaced < StripAt.LedCount)
{
u32 V4SendAddress = SACN_GetUniverseSendAddress(UniverseAt);
u32 SendPort = DEFAULT_STREAMING_ACN_PORT; u32 SendPort = DEFAULT_STREAMING_ACN_PORT;
addressed_data_buffer* Data = AddressedDataBufferList_Push(Output, BufferSize); addressed_data_buffer* Data = AddressedDataBufferList_Push(Output, BufferSize);
AddressedDataBuffer_SetNetworkAddress(Data, SACN->SendSocket, V4SendAddress, SendPort); AddressedDataBuffer_SetNetworkAddress(Data, SACN->SendSocket, V4SendAddress, SendPort);
SACN_PrepareBufferHeader(StripAt.SACNAddr.StartUniverse, Data->Memory, Data->MemorySize, BufferHeaderSize, *SACN); SACN_PrepareBufferHeader(UniverseAt, Data->Memory, Data->MemorySize, BufferHeaderSize, *SACN);
SACN_FillBufferWithLeds(Data->Memory + BufferHeaderSize, BufferBodySize, StripAt, *LedBuffer); LedsPlaced += SACN_FillBufferWithLeds(Data->Memory + BufferHeaderSize, BufferBodySize, StripAt, LedsPlaced, *LedBuffer);
UniverseAt += 1;
}
} }
} }
} }