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