diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..d8708cf --- /dev/null +++ b/run.bat @@ -0,0 +1,4 @@ +@echo off +pushd app_run_tree +start win32_msvc\debug\win32_foldhaus.exe +popd \ No newline at end of file diff --git a/src/app/engine/assembly/foldhaus_assembly.cpp b/src/app/engine/assembly/foldhaus_assembly.cpp index fd060d4..4ae1a6c 100644 --- a/src/app/engine/assembly/foldhaus_assembly.cpp +++ b/src/app/engine/assembly/foldhaus_assembly.cpp @@ -208,7 +208,8 @@ LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena assembly* NewAssembly = AssemblyArray_Take(Assemblies); NewAssembly->Arena = CreateMemoryArena(Context.ThreadContext.Allocator); - if (ParseAssemblyFile(NewAssembly, FileName, AssemblyFileText, Scratch)) + parser AssemblyParser = ParseAssemblyFile(NewAssembly, FileName, AssemblyFileText, Scratch); + if (AssemblyParser.Success) { ConstructAssemblyFromDefinition(NewAssembly, LedSystem); } @@ -217,6 +218,14 @@ LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena FreeMemoryArena(&NewAssembly->Arena); Assemblies->Count -= 1; } + + for (parser_error* ErrorAt = AssemblyParser.ErrorsRoot; + ErrorAt != 0; + ErrorAt = ErrorAt->Next) + { + OutputDebugString(ErrorAt->Message.Str); + } + } else { diff --git a/src/app/engine/assembly/foldhaus_assembly_parser.cpp b/src/app/engine/assembly/foldhaus_assembly_parser.cpp index 26e4205..5024fb6 100644 --- a/src/app/engine/assembly/foldhaus_assembly_parser.cpp +++ b/src/app/engine/assembly/foldhaus_assembly_parser.cpp @@ -258,12 +258,13 @@ AssemblyParser_ReadStripGenData(parser* Parser, assembly* Assembly) return Result; } -internal bool +internal parser ParseAssemblyFile(assembly* Assembly, gs_const_string FileName, gs_string FileText, gs_memory_arena* Transient) { Assembly->LedCountTotal = 0; parser Parser = {0}; + Parser.FileName = FileName; Parser.String = FileText; Parser.Identifiers = &AssemblyFieldIdentifiers[0]; Parser.IdentifiersCount = AssemblyField_Count; @@ -271,6 +272,7 @@ ParseAssemblyFile(assembly* Assembly, gs_const_string FileName, gs_string FileTe Parser.LineStart = Parser.At; Parser.Arena = &Assembly->Arena; Parser.Transient = Transient; + Parser.Success = true; Assembly->Name = Parser_ReadStringValue(&Parser, AssemblyField_AssemblyName); Assembly->Scale = Parser_ReadR32Value(&Parser, AssemblyField_AssemblyScale); @@ -298,6 +300,7 @@ ParseAssemblyFile(assembly* Assembly, gs_const_string FileName, gs_string FileTe else { Parser_PushErrorF(&Parser, "Invalid output mode specified for assembly."); + Parser.Success = false; } for (u32 i = 0; i < Assembly->StripCount; i++) @@ -316,16 +319,17 @@ ParseAssemblyFile(assembly* Assembly, gs_const_string FileName, gs_string FileTe if (!Parser_ReadCloseStruct(&Parser)) { Parser_PushErrorF(&Parser, "Strip struct doesn't close where expected"); + Parser.Success = false; } } else { Parser_PushErrorF(&Parser, "Expected a strip struct but none was found"); + Parser.Success = false; } } - // TODO(pjs): invalidate the file if its incorrect - return true; //Tokenizer.ParsingIsValid; + return Parser; } #define FOLDHAUS_ASSEMBLY_PARSER_CPP diff --git a/src/app/engine/foldhaus_serializer.h b/src/app/engine/foldhaus_serializer.h index 06f9d71..34ac831 100644 --- a/src/app/engine/foldhaus_serializer.h +++ b/src/app/engine/foldhaus_serializer.h @@ -135,7 +135,7 @@ struct parser_error { gs_string Message; - gs_string FileName; + gs_const_string FileName; u32 LineNumber; parser_error* Next; @@ -143,7 +143,7 @@ struct parser_error struct parser { - gs_string FileName; + gs_const_string FileName; gs_string String; @@ -160,6 +160,8 @@ struct parser parser_error* ErrorsRoot; parser_error* ErrorsHead; + + bool Success; }; internal void @@ -170,13 +172,17 @@ Parser_PushErrorF(parser* Parser, char* Format, ...) Error->LineNumber = Parser->Line; Error->Message = PushString(Parser->Transient, 1024); - PrintF(&Error->Message, "File: %S Line: %d - ", Error->FileName, Error->LineNumber); + PrintF(&Error->Message, "Error:\n"); va_list Args; va_start(Args, Format); PrintFArgsList(&Error->Message, Format, Args); va_end(Args); + AppendPrintF(&Error->Message, "\n\tFile: %S\n\tLine: %d\n", + Error->FileName, Error->LineNumber); + NullTerminate(&Error->Message); + SLLPushOrInit(Parser->ErrorsRoot, Parser->ErrorsHead, Error); } @@ -202,8 +208,27 @@ Parser_AdvanceChar(parser* P) { P->Line += 1; P->LineStart = P->At + 1; + + if ((P->At[0] == '\n' && P->At[1] == '\r') || + (P->At[0] == '\r' && P->At[1] == '\n')) + { + P->At++; + P->At++; + } + else if (P->At[0] == '\n') + { + P->At++; + } + else + { + // TODO(pjs): Not sure this is actually invalid + InvalidCodePath; + } + } + else + { + P->At++; } - P->At++; } internal void diff --git a/src/app/engine/uart/foldhaus_uart.cpp b/src/app/engine/uart/foldhaus_uart.cpp index c158412..64157fa 100644 --- a/src/app/engine/uart/foldhaus_uart.cpp +++ b/src/app/engine/uart/foldhaus_uart.cpp @@ -6,7 +6,7 @@ #ifndef FOLDHAUS_UART_CPP -internal void +internal uart_header* UART_SetChannelBuffer_Create(gs_memory_cursor* WriteCursor, uart_channel ChannelSettings, v2_strip Strip, led_buffer LedBuffer) { // NOTE(pjs): This is just here because the information is duplicated and I want to be sure @@ -27,10 +27,15 @@ UART_SetChannelBuffer_Create(gs_memory_cursor* WriteCursor, uart_channel Channel u8* OutputPixel = PushArrayOnCursor(WriteCursor, u8, 3); // TODO(pjs): Use the Output mask +#if 1 OutputPixel[0] = Color.R; OutputPixel[1] = Color.G; OutputPixel[2] = Color.B; - +#else + OutputPixel[0] = 255; + OutputPixel[1] = 255; + OutputPixel[2] = 255; +#endif if (Channel->ElementsCount == 4) { // TODO(pjs): Calculate white from the RGB components? @@ -43,6 +48,8 @@ UART_SetChannelBuffer_Create(gs_memory_cursor* WriteCursor, uart_channel Channel uart_footer* Footer = PushStructOnCursor(WriteCursor, uart_footer); UART_FillFooter(Footer, (u8*)Header); + + return Header; } internal void @@ -64,7 +71,7 @@ UART_BuildOutputData(addressed_data_buffer_list* Output, assembly_array Assembli // NOTE(pjs): This is the minimum size of every UART message. SetChannelBuffer messages will // be bigger than this, but their size is based on the number of pixels in each channel - u32 MessageBaseSize = sizeof(uart_header) + sizeof(uart_channel) + sizeof(uart_footer); + u32 MessageBaseSize = UART_MESSAGE_MIN_SIZE; for (u32 AssemblyIdx = 0; AssemblyIdx < Assemblies.Count; AssemblyIdx++) { @@ -74,15 +81,19 @@ UART_BuildOutputData(addressed_data_buffer_list* Output, assembly_array Assembli struct strips_to_data_buffer { gs_const_string ComPort; + u32* StripIndices; u32 StripIndicesCount; u32 StripIndicesCountMax; u64 LedCount; + u8** ChannelsStart; + strips_to_data_buffer* Next; }; + u32 BuffersNeededCount = 0; strips_to_data_buffer* BuffersNeededHead = 0; strips_to_data_buffer* BuffersNeededTail = 0; @@ -120,6 +131,12 @@ UART_BuildOutputData(addressed_data_buffer_list* Output, assembly_array Assembli BufferSelected->Next = 0; SLLPushOrInit(BuffersNeededHead, BuffersNeededTail, BufferSelected); + BuffersNeededCount += 1; + + gs_string Temp = PushStringF(Transient, 256, "Found Com Port: %S\n\tStrip: %d\n", StripAt.UARTAddr.ComPort.ConstString, + StripIdx); + NullTerminate(&Temp); + OutputDebugString(Temp.Str); } Assert(BufferSelected->StripIndicesCount < BufferSelected->StripIndicesCountMax); @@ -136,6 +153,8 @@ UART_BuildOutputData(addressed_data_buffer_list* Output, assembly_array Assembli TotalBufferSize += MessageBaseSize; // DrawAll message TotalBufferSize += ChannelSettings.ElementsCount * At->LedCount; // pixels * channels per pixel + At->ChannelsStart = PushArray(Transient, u8*, At->StripIndicesCount); + addressed_data_buffer* Buffer = AddressedDataBufferList_Push(Output, TotalBufferSize); gs_const_string ComPort = At->ComPort; AddressedDataBuffer_SetCOMPort(Buffer, ComPort); @@ -148,7 +167,9 @@ UART_BuildOutputData(addressed_data_buffer_list* Output, assembly_array Assembli v2_strip StripAt = Assembly.Strips[StripIdx]; ChannelSettings.PixelsCount = StripAt.LedCount; - UART_SetChannelBuffer_Create(&WriteCursor, ChannelSettings, StripAt, *LedBuffer); + uart_header* Header = UART_SetChannelBuffer_Create(&WriteCursor, ChannelSettings, StripAt, *LedBuffer); + + //At->Header[i] = Header; } UART_DrawAll_Create(&WriteCursor); diff --git a/src/app/engine/uart/foldhaus_uart.h b/src/app/engine/uart/foldhaus_uart.h index f866efc..63067ba 100644 --- a/src/app/engine/uart/foldhaus_uart.h +++ b/src/app/engine/uart/foldhaus_uart.h @@ -35,6 +35,8 @@ struct uart_footer #pragma pack(pop) +#define UART_MESSAGE_MIN_SIZE sizeof(uart_header) + sizeof(uart_channel) + sizeof(uart_footer) + global u32 UART_CRCTable[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d diff --git a/src/app/foldhaus_app.cpp b/src/app/foldhaus_app.cpp index 6277cd4..afb9fe2 100644 --- a/src/app/foldhaus_app.cpp +++ b/src/app/foldhaus_app.cpp @@ -56,6 +56,7 @@ INITIALIZE_APPLICATION(InitializeApplication) State->LedSystem = LedSystem_Create(Context.ThreadContext.Allocator, 128); State->AssemblyDebugState = AssemblyDebug_Create(&State->Permanent); + State->AssemblyDebugState.Override = ADS_Override_AllRed; GlobalDebugServices->Interface.RenderSculpture = true; @@ -99,14 +100,14 @@ UPDATE_AND_RENDER(UpdateAndRender) State->Assemblies, State->LedSystem); + Editor_Render(State, Context, RenderBuffer); + // NOTE(pjs): Building data buffers to be sent out to the sculpture // This array is used on the platform side to actually send the information assembly_array SACNAssemblies = AssemblyArray_Filter(State->Assemblies, AssemblyFilter_OutputsViaSACN, State->Transient); assembly_array UARTAssemblies = AssemblyArray_Filter(State->Assemblies, AssemblyFilter_OutputsViaUART, State->Transient); SACN_BuildOutputData(&State->SACN, OutputData, SACNAssemblies, &State->LedSystem); UART_BuildOutputData(OutputData, UARTAssemblies, &State->LedSystem, State->Transient); - - Editor_Render(State, Context, RenderBuffer); } CLEANUP_APPLICATION(CleanupApplication) diff --git a/src/app/patterns/blumen_patterns.h b/src/app/patterns/blumen_patterns.h index bd27bfc..4345524 100644 --- a/src/app/patterns/blumen_patterns.h +++ b/src/app/patterns/blumen_patterns.h @@ -380,13 +380,16 @@ Pattern_HueShift(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* r32 CycleProgress = FractR32(Time / CycleLength); r32 CycleBlend = (SinR32(Time) * .5f) + .5f; + v4 HSV = { CycleProgress * 360, 1, 1, 1 }; + v4 RGB = HSVToRGB(HSV); + for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++) { v4 Pos = Leds->Positions[LedIndex]; r32 Dist = Pos.y - Height; - v4 HSV = { (ModR32(Dist, 25) / 25) * 360, 1, 1, 1 }; - v4 RGB = HSVToRGB(HSV); + //v4 HSV = { (ModR32(Dist, 25) / 25) * 360, 1, 1, 1 }; + //v4 RGB = HSVToRGB(HSV); u8 R = (u8)(RGB.x * 255); u8 G = (u8)(RGB.y * 255); diff --git a/src/app/platform_win32/win32_foldhaus.cpp b/src/app/platform_win32/win32_foldhaus.cpp index f0974e3..c055de0 100644 --- a/src/app/platform_win32/win32_foldhaus.cpp +++ b/src/app/platform_win32/win32_foldhaus.cpp @@ -546,10 +546,8 @@ WinMain ( Context.UpdateAndRender(&Context, InputQueue, &RenderBuffer, &OutputData); - RenderCommandBuffer(RenderBuffer); - ClearRenderBuffer(&RenderBuffer); - - if (true) + bool Multithread = true; + if (Multithread) { for (addressed_data_buffer* At = OutputData.Root; At != 0; @@ -561,6 +559,21 @@ WinMain ( Win32PushWorkOnQueue(&Win32WorkQueue.WorkQueue, Win32_SendAddressedDataBuffer_Job, ProcArg, ConstString("Send UART Data")); } } + else + { + for (addressed_data_buffer* At = OutputData.Root; + At != 0; + At = At->Next) + { + gs_data ProcArg = {}; + ProcArg.Memory = (u8*)At; + ProcArg.Size = sizeof(addressed_data_buffer); + Win32_SendAddressedDataBuffer_Job(ThreadContext, ProcArg); + } + } + + RenderCommandBuffer(RenderBuffer); + ClearRenderBuffer(&RenderBuffer); Mouse_Advance(&Context); diff --git a/src/sculpture_gen/gen_blumen_lumen.cpp b/src/sculpture_gen/gen_blumen_lumen.cpp index 00333da..126ef52 100644 --- a/src/sculpture_gen/gen_blumen_lumen.cpp +++ b/src/sculpture_gen/gen_blumen_lumen.cpp @@ -99,7 +99,7 @@ typedef struct u32* BloomInnerChannels; } flower_desc; -internal void +internal u32 BuildFlower(gs_string* OutputBuffer, flower_desc Desc) { @@ -149,6 +149,11 @@ BuildFlower(gs_string* OutputBuffer, flower_desc Desc) BuildLoop(OutputBuffer, FlowerStem); #endif + u32 StripsCount = BloomStemInner.SegmentsCount; + StripsCount += BloomStemOuter.SegmentsCount; + StripsCount += FlowerStem.SegmentsCount; + + return StripsCount; } // Just for brevity, no real function provided @@ -176,9 +181,11 @@ int main(int ArgCount, char** Args) "Blumen Lumen - Silver Spring", 100, v3{0, 0, 0}, - 69, + 63, ""); + u32 StripCount = 0; + u32 StemChannels[] = { FSC(2, 1), FSC(2, 2), FSC(2, 3), FSC(2, 4), FSC(2, 5), FSC(2, 6) }; u32 BloomOuterChannels[] = { FSC(1, 0), FSC(1, 1), FSC(1, 2), FSC(1, 3), FSC(1, 4), FSC(1, 5), FSC(1, 6), FSC(1, 7), FSC(2, 0) }; u32 BloomInnerChannels[] = { FSC(0, 0), FSC(0, 1), FSC(0, 2), FSC(0, 3), FSC(0, 4), FSC(0, 5) }; @@ -189,7 +196,7 @@ int main(int ArgCount, char** Args) F0.StemChannels = StemChannels; F0.BloomOuterChannels = BloomOuterChannels; F0.BloomInnerChannels = BloomInnerChannels; - BuildFlower(&OutputBuffer, F0); + StripCount += BuildFlower(&OutputBuffer, F0); flower_desc F1 = {}; F1.Pos = v3{0, 0, 0}; @@ -198,7 +205,7 @@ int main(int ArgCount, char** Args) F1.StemChannels = StemChannels; F1.BloomInnerChannels = BloomInnerChannels; F1.BloomOuterChannels = BloomOuterChannels; - BuildFlower(&OutputBuffer, F1); + StripCount += BuildFlower(&OutputBuffer, F1); flower_desc F2 = {}; F2.Pos = v3{1, 0, 0}; @@ -207,9 +214,10 @@ int main(int ArgCount, char** Args) F2.StemChannels = StemChannels; F2.BloomInnerChannels = BloomInnerChannels; F2.BloomOuterChannels = BloomOuterChannels; - BuildFlower(&OutputBuffer, F2); + StripCount += BuildFlower(&OutputBuffer, F2); - printf("%.*s\n", (u32)OutputBuffer.Length, OutputBuffer.Str); + //printf("%.*s\n", (u32)OutputBuffer.Length, OutputBuffer.Str); + printf("%d\n", StripCount); return 0; }