created a mapping from leds to universes in assemly structures that doesn't rely on SACN
This commit is contained in:
parent
70c9c74796
commit
a5e774c8d1
|
@ -149,11 +149,15 @@ LoadAssembly (app_state* State, context Context, char* Path)
|
|||
|
||||
r32 Scale = 100;
|
||||
Assert(State->AssembliesCount < ASSEMBLY_LIST_LENGTH);
|
||||
s32 AssemblyMemorySize = GetAssemblyMemorySizeFromDefinition(AssemblyDefinition, FileName);
|
||||
u8* AssemblyMemory = Context.PlatformAlloc(AssemblyMemorySize);
|
||||
|
||||
assembly NewAssembly = ConstructAssemblyFromDefinition(AssemblyDefinition,
|
||||
FileName,
|
||||
v3{0, 0, 0},
|
||||
Scale,
|
||||
Context);
|
||||
AssemblyMemory,
|
||||
AssemblyMemorySize);
|
||||
State->AssemblyList[State->AssembliesCount++] = NewAssembly;
|
||||
State->TotalLEDsCount += NewAssembly.LEDCount;
|
||||
|
||||
|
@ -376,36 +380,33 @@ CreateDMXBuffers(assembly Assembly, s32 BufferHeaderSize, memory_arena* Arena)
|
|||
|
||||
s32 BufferSize = BufferHeaderSize + 512;
|
||||
|
||||
s32 Universe = 1;
|
||||
s32 ChannelsUsed = 0;
|
||||
for (s32 l = 0; l < Assembly.LEDCount; l++)
|
||||
for (s32 Range = 0; Range < Assembly.LEDUniverseMapCount; Range++)
|
||||
{
|
||||
if(ChannelsUsed == 0)
|
||||
{
|
||||
dmx_buffer_list* NewBuffer = PushStruct(Arena, dmx_buffer_list);
|
||||
NewBuffer->Buffer.Universe = Universe;
|
||||
NewBuffer->Buffer.Base = PushArray(Arena, u8, BufferSize);
|
||||
NewBuffer->Buffer.TotalSize = BufferSize;
|
||||
NewBuffer->Buffer.HeaderSize = BufferHeaderSize;
|
||||
leds_in_universe_range LEDUniverseRange = Assembly.LEDUniverseMap[Range];
|
||||
|
||||
// Append
|
||||
if (!Result) {
|
||||
Result = NewBuffer;
|
||||
Head = Result;
|
||||
}
|
||||
Head->Next = NewBuffer;
|
||||
Head = NewBuffer;
|
||||
dmx_buffer_list* NewBuffer = PushStruct(Arena, dmx_buffer_list);
|
||||
NewBuffer->Buffer.Universe = LEDUniverseRange.Universe;
|
||||
NewBuffer->Buffer.Base = PushArray(Arena, u8, BufferSize);
|
||||
NewBuffer->Buffer.TotalSize = BufferSize;
|
||||
NewBuffer->Buffer.HeaderSize = BufferHeaderSize;
|
||||
|
||||
// Append
|
||||
if (!Result) {
|
||||
Result = NewBuffer;
|
||||
Head = Result;
|
||||
}
|
||||
Head->Next = NewBuffer;
|
||||
Head = NewBuffer;
|
||||
|
||||
led LED = Assembly.LEDs[l];
|
||||
pixel Color = Assembly.Colors[LED.Index];
|
||||
*((pixel*)(Head->Buffer.Base + ChannelsUsed)) = Color;
|
||||
ChannelsUsed += 3;
|
||||
|
||||
if (ChannelsUsed + 3 >= 512)
|
||||
for (s32 LEDIdx = LEDUniverseRange.RangeStart;
|
||||
LEDIdx < LEDUniverseRange.RangeOnePastLast;
|
||||
LEDIdx++)
|
||||
{
|
||||
Universe++;
|
||||
ChannelsUsed= 0;
|
||||
led LED = Assembly.LEDs[LEDIdx];
|
||||
pixel Color = Assembly.Colors[LED.Index];
|
||||
|
||||
s32 DestinationStartChannel = LEDIdx * 3;
|
||||
*((pixel*)(Head->Buffer.Base + DestinationStartChannel)) = Color;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +1,45 @@
|
|||
internal s32
|
||||
GetAssemblyMemorySizeFromDefinition(assembly_definition Definition, string Name)
|
||||
{
|
||||
s32 Result = (sizeof(led) + sizeof(pixel)) * Definition.TotalLEDCount;
|
||||
Result += sizeof(leds_in_universe_range) * Definition.LEDStripCount;
|
||||
Result += Name.Length;
|
||||
return Result;
|
||||
}
|
||||
|
||||
internal assembly
|
||||
ConstructAssemblyFromDefinition (assembly_definition Definition,
|
||||
string AssemblyName,
|
||||
v3 RootPosition,
|
||||
r32 Scale,
|
||||
context Context)
|
||||
u8* MemoryBase,
|
||||
s32 MemorySize)
|
||||
{
|
||||
assembly Assembly = {};
|
||||
Assembly.Arena = CreateMemoryArena(MemoryBase, MemorySize);
|
||||
|
||||
s32 MemorySize = AssemblySize(Definition.TotalLEDCount, AssemblyName.Length);
|
||||
Assembly.Memory = AllocateNonGrowableArenaWithSpace(Context.PlatformAlloc, MemorySize);
|
||||
|
||||
Assembly.Name = MakeString(PushArray(&Assembly.Memory, char, AssemblyName.Length),
|
||||
AssemblyName.Length);
|
||||
Assembly.Name = MakeString(PushArray(&Assembly.Arena, char, AssemblyName.Length), AssemblyName.Length);
|
||||
CopyStringTo(AssemblyName, &Assembly.Name);
|
||||
|
||||
// NOTE(Peter): Setting this to zero so we can check at the end of the loop that creates leds
|
||||
// and make sure we created to correct number. By the time this function returns it should be
|
||||
// the case that: (Assembly.LEDCount == Definition.TotalLEDCount)
|
||||
Assembly.LEDCount = 0;
|
||||
Assembly.Colors = PushArray(&Assembly.Memory, pixel, Definition.TotalLEDCount);
|
||||
Assembly.LEDs = PushArray(&Assembly.Memory, led, Definition.TotalLEDCount);
|
||||
Assembly.Colors = PushArray(&Assembly.Arena, pixel, Definition.TotalLEDCount);
|
||||
Assembly.LEDs = PushArray(&Assembly.Arena, led, Definition.TotalLEDCount);
|
||||
Assembly.LEDUniverseMapCount = Definition.LEDStripCount;
|
||||
Assembly.LEDUniverseMap = PushArray(&Assembly.Arena, leds_in_universe_range, Definition.LEDStripCount);
|
||||
|
||||
// Add LEDs
|
||||
for (s32 StripIdx = 0; StripIdx < Definition.LEDStripCount; StripIdx++)
|
||||
{
|
||||
led_strip_definition StripDef = Definition.LEDStrips[StripIdx];
|
||||
|
||||
leds_in_universe_range* LEDUniverseRange = Assembly.LEDUniverseMap + StripIdx;
|
||||
LEDUniverseRange->Universe = StripDef.StartUniverse;
|
||||
LEDUniverseRange->RangeStart = Assembly.LEDCount;
|
||||
LEDUniverseRange->RangeOnePastLast = Assembly.LEDCount + StripDef.LEDsPerStrip;
|
||||
|
||||
// NOTE(Peter): this should be a switch on the type, but we only have one for
|
||||
// now. The assert is to remind you to create more cases when necessary
|
||||
Assert(StripDef.InterpolationType == StripInterpolate_Points);
|
||||
|
|
|
@ -15,12 +15,16 @@ union pixel
|
|||
u8 Channels[3];
|
||||
};
|
||||
|
||||
#define AssemblySize(leds, name_length) ((sizeof(led) + sizeof(pixel)) * (leds)) + name_length;
|
||||
struct leds_in_universe_range
|
||||
{
|
||||
s32 RangeStart;
|
||||
s32 RangeOnePastLast;
|
||||
s32 Universe;
|
||||
};
|
||||
|
||||
struct assembly
|
||||
{
|
||||
memory_arena Memory;
|
||||
s32 MemorySize;
|
||||
u8* MemoryBase;
|
||||
static_memory_arena Arena;
|
||||
|
||||
string Name;
|
||||
string FilePath;
|
||||
|
@ -28,4 +32,7 @@ struct assembly
|
|||
s32 LEDCount;
|
||||
pixel* Colors;
|
||||
led* LEDs;
|
||||
|
||||
s32 LEDUniverseMapCount;
|
||||
leds_in_universe_range* LEDUniverseMap;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue