A bit more cleanup around sacn and assemblies.

This commit is contained in:
Peter Slattery 2020-06-20 17:05:58 -07:00
parent 9c432a3807
commit 23c9dabfbb
5 changed files with 22 additions and 28 deletions

View File

@ -182,7 +182,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
#if 1 #if 1
string SculpturePath = MakeStringLiteral("data/blumen_lumen_v2.fold"); string SculpturePath = MakeStringLiteral("data/blumen_lumen_v2.fold");
LoadAssembly(State, Context, SculpturePath); LoadAssembly(&State->Assemblies, &State->LedSystem, &State->Transient, Context, SculpturePath, State->GlobalLog);
#endif #endif
State->PixelsToWorldScale = .01f; State->PixelsToWorldScale = .01f;

View File

@ -5,8 +5,6 @@
// //
#ifndef FOLDHAUS_ASSEMBLY_CPP #ifndef FOLDHAUS_ASSEMBLY_CPP
// Led System
internal led_system internal led_system
LedSystemInitialize(platform_memory_handler PlatformMemory, u32 BuffersMax) LedSystemInitialize(platform_memory_handler PlatformMemory, u32 BuffersMax)
{ {
@ -78,8 +76,6 @@ LedBufferSetLed(led_buffer* Buffer, u32 Led, v4 Position)
Buffer->Positions[Led] = Position; Buffer->Positions[Led] = Position;
} }
// Assembly
internal void internal void
ConstructAssemblyFromDefinition (assembly* Assembly, string AssemblyName, v4 RootPosition, led_system* LedSystem) ConstructAssemblyFromDefinition (assembly* Assembly, string AssemblyName, v4 RootPosition, led_system* LedSystem)
{ {
@ -114,37 +110,36 @@ ConstructAssemblyFromDefinition (assembly* Assembly, string AssemblyName, v4 Roo
static v4 TempAssemblyOffsets[] = { v4{0, 0, 0, 0}, v4{250, 0, 75, 0}, v4{-250, 0, 75, 0} }; static v4 TempAssemblyOffsets[] = { v4{0, 0, 0, 0}, v4{250, 0, 75, 0}, v4{-250, 0, 75, 0} };
s32 TempAssemblyOffsetsCount = 3; s32 TempAssemblyOffsetsCount = 3;
// TODO(Peter): Don't reference State, pull back to the Led buffer and Assembly Array
internal void internal void
LoadAssembly (app_state* State, context Context, string Path) LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, memory_arena* Scratch, context Context, string Path, event_log* GlobalLog)
{ {
platform_memory_result AssemblyFile = ReadEntireFile(Context, Path); platform_memory_result AssemblyFile = ReadEntireFile(Context, Path);
if (AssemblyFile.Error == PlatformMemory_NoError && AssemblyFile.Size > 0) if (AssemblyFile.Error == PlatformMemory_NoError && AssemblyFile.Size > 0)
{ {
string AssemblyFileText = MakeString((char*)AssemblyFile.Base); string AssemblyFileText = MakeString((char*)AssemblyFile.Base);
Assert(State->Assemblies.Count < State->Assemblies.CountMax); Assert(Assemblies->Count < Assemblies->CountMax);
assembly* NewAssembly = &State->Assemblies.Values[State->Assemblies.Count++]; assembly* NewAssembly = &Assemblies->Values[Assemblies->Count++];
s32 IndexOfLastSlash = FastLastIndexOfCharInCharArray(Path.Memory, Path.Length, '\\'); s32 IndexOfLastSlash = FastLastIndexOfCharInCharArray(Path.Memory, Path.Length, '\\');
string FileName = Substring(Path, IndexOfLastSlash + 1); string FileName = Substring(Path, IndexOfLastSlash + 1);
NewAssembly->Arena.PlatformMemory = Context.PlatformMemory; NewAssembly->Arena.PlatformMemory = Context.PlatformMemory;
if (ParseAssemblyFile(NewAssembly, AssemblyFileText, &State->Transient)) if (ParseAssemblyFile(NewAssembly, AssemblyFileText, Scratch))
{ {
v4 Offset = TempAssemblyOffsets[State->Assemblies.Count % TempAssemblyOffsetsCount]; v4 Offset = TempAssemblyOffsets[Assemblies->Count % TempAssemblyOffsetsCount];
ConstructAssemblyFromDefinition(NewAssembly, FileName, Offset, &State->LedSystem); ConstructAssemblyFromDefinition(NewAssembly, FileName, Offset, LedSystem);
PlatformFree(Context.PlatformMemory, AssemblyFile.Base, AssemblyFile.Size); PlatformFree(Context.PlatformMemory, AssemblyFile.Base, AssemblyFile.Size);
} }
else else
{ {
FreeMemoryArena(&NewAssembly->Arena); FreeMemoryArena(&NewAssembly->Arena);
State->Assemblies.Count -= 1; Assemblies->Count -= 1;
} }
} }
else else
{ {
LogError(State->GlobalLog, "Unable to load assembly file"); LogError(GlobalLog, "Unable to load assembly file");
} }
} }

View File

@ -477,6 +477,5 @@ DrawAllPanels(panel_layout PanelLayout, render_command_buffer* RenderBuffer, mou
} }
} }
#define FOLDHAUS_INTERFACE_CPP #define FOLDHAUS_INTERFACE_CPP
#endif // FOLDHAUS_INTERFACE_CPP #endif // FOLDHAUS_INTERFACE_CPP

View File

@ -71,7 +71,7 @@ HierarchyView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
b32 Success = GetFilePath(Context, &FilePath, "Foldhaus Files\0*.fold\0\0"); b32 Success = GetFilePath(Context, &FilePath, "Foldhaus Files\0*.fold\0\0");
if (Success) if (Success)
{ {
LoadAssembly(State, Context, FilePath); LoadAssembly(&State->Assemblies, &State->LedSystem, &State->Transient, Context, FilePath, State->GlobalLog);
} }
} }

View File

@ -12,7 +12,7 @@
#define IP_ADDRESS_BYTES 16 #define IP_ADDRESS_BYTES 16
#define STARTCODE_DMX 0 #define STARTCODE_DMX 0
/* /*
* a description of the address space being used * a description of the address space being used
*/ */
#define PREAMBLE_SIZE_ADDR 0 #define PREAMBLE_SIZE_ADDR 0
@ -52,7 +52,7 @@
/* /*
* data definitions * data definitions
*/ */
#define ACN_IDENTIFIER "ASC-E1.17\0\0\0" #define ACN_IDENTIFIER "ASC-E1.17\0\0\0"
#define ROOT_VECTOR 4 #define ROOT_VECTOR 4
#define FRAMING_VECTOR 2 #define FRAMING_VECTOR 2
#define DMP_VECTOR 2 #define DMP_VECTOR 2
@ -159,7 +159,7 @@ VHD_PackLength_(u8* Buffer, u32 Length, b32 IncludeLength)
return Cursor; return Cursor;
} }
internal cid internal cid
StringToCID_ (const char* String) StringToCID_ (const char* String)
{ {
cid Result = {}; cid Result = {};
@ -193,11 +193,11 @@ StringToCID_ (const char* String)
Src++; Src++;
} }
return Result; return Result;
} }
internal void internal void
InitStreamHeader (u8* Buffer, s32 BufferSize, InitStreamHeader (u8* Buffer, s32 BufferSize,
u16 SlotCount, u16 SlotCount,
u8 StartCode, u8 StartCode,
u16 Universe, u16 Universe,
@ -220,8 +220,8 @@ InitStreamHeader (u8* Buffer, s32 BufferSize,
// TODO(Peter): If you never use this anywhere else, go back and remove the parameters // TODO(Peter): If you never use this anywhere else, go back and remove the parameters
VHD_PackFlags_(Cursor, false, false, false); VHD_PackFlags_(Cursor, false, false, false);
Cursor = VHD_PackLength_(Cursor, Cursor = VHD_PackLength_(Cursor,
STREAM_HEADER_SIZE - RLP_PREAMBLE_SIZE + SlotCount, STREAM_HEADER_SIZE - RLP_PREAMBLE_SIZE + SlotCount,
false); false);
// root vector // root vector
@ -234,8 +234,8 @@ InitStreamHeader (u8* Buffer, s32 BufferSize,
} }
VHD_PackFlags_(Cursor, false, false, false); VHD_PackFlags_(Cursor, false, false, false);
Cursor = VHD_PackLength_(Cursor, Cursor = VHD_PackLength_(Cursor,
STREAM_HEADER_SIZE - FRAMING_FLAGS_AND_LENGTH_ADDR + SlotCount, STREAM_HEADER_SIZE - FRAMING_FLAGS_AND_LENGTH_ADDR + SlotCount,
false); false);
// framing vector // framing vector
@ -263,7 +263,7 @@ InitStreamHeader (u8* Buffer, s32 BufferSize,
Cursor = PackB2(Cursor, Universe); Cursor = PackB2(Cursor, Universe);
VHD_PackFlags_(Cursor, false, false, false); VHD_PackFlags_(Cursor, false, false, false);
Cursor = VHD_PackLength_(Cursor, Cursor = VHD_PackLength_(Cursor,
STREAM_HEADER_SIZE - DMP_FLAGS_AND_LENGTH_ADDR + SlotCount, STREAM_HEADER_SIZE - DMP_FLAGS_AND_LENGTH_ADDR + SlotCount,
false); false);
@ -292,7 +292,7 @@ InitStreamHeader (u8* Buffer, s32 BufferSize,
// //
internal streaming_acn internal streaming_acn
InitializeSACN ( context Context) InitializeSACN (context Context)
{ {
streaming_acn SACN = {}; streaming_acn SACN = {};
@ -313,7 +313,7 @@ internal void
SACNUpdateSequence (streaming_acn* SACN) SACNUpdateSequence (streaming_acn* SACN)
{ {
// Never use 0 after the first one // Never use 0 after the first one
if (++SACN->SequenceIterator == 0) if (++SACN->SequenceIterator == 0)
{ {
++SACN->SequenceIterator; ++SACN->SequenceIterator;
} }