diff --git a/data/test_meta.cpp b/data/test_meta.cpp new file mode 100644 index 0000000..fd98109 --- /dev/null +++ b/data/test_meta.cpp @@ -0,0 +1,23 @@ +struct hello_struct_t +{ + const int x; + float* y; + char hello; +}; + +union Vector +{ + struct { + int X; + int Y; + int Z; + }; + int E[3]; +}; + +struct test_def; + +int main (int ArgCount, char* Args[]) +{ + return 0; +} \ No newline at end of file diff --git a/msdev.bat b/msdev.bat index 544328c..5d06e5e 100644 --- a/msdev.bat +++ b/msdev.bat @@ -1,3 +1,3 @@ @echo off -remedybg build\remedy_win32_foldhaus.rdbg \ No newline at end of file +remedybg build\debug_lumenarium.rdbg \ No newline at end of file diff --git a/project.4coder b/project.4coder index 1711a2d..ef8c1ac 100644 --- a/project.4coder +++ b/project.4coder @@ -15,6 +15,7 @@ blacklist_patterns = { load_paths_base = { { "src", .relative = true, .recursive = true, }, { "meta", .relative = true, .recursive = true, }, + { "C:\programs-dev\gs_libs\src", .relative = false, .recursive = true, } }; load_paths = { { load_paths_base, .os = "win", }, @@ -39,5 +40,5 @@ command_list = { { "build/main.exe" , .os = "linux" }, { "build/main.exe" , .os = "mac" }, }, }, }; -fkey_command[1] = "build"; -fkey_command[2] = "run"; +fkey_command[1] = "build_application"; +fkey_command[2] = "build_meta"; diff --git a/src/assembly_parser.cpp b/src/assembly_parser.cpp index b59a737..18789d7 100644 --- a/src/assembly_parser.cpp +++ b/src/assembly_parser.cpp @@ -86,6 +86,7 @@ ParseAssemblyVector (char* String) internal void ParseAssemblyFileHeader (assembly_definition* Assembly, tokenizer* Tokenizer) { + if (CharArraysEqualUpToLength(Tokenizer->At, LED_STRIP_COUNT_IDENTIFIER, CharArrayLength(LED_STRIP_COUNT_IDENTIFIER))) { Tokenizer->At += CharArrayLength(LED_STRIP_COUNT_IDENTIFIER); @@ -213,21 +214,237 @@ ParseAssemblyFileBody (assembly_definition* Assembly, tokenizer* Tokenizer) Assert(Assembly->LEDStripCount == Assembly->LEDStripSize); } +inline b32 +ParseTokenEquals (tokenizer* T, char* Validate) +{ + b32 Result = true; + + char* TAt = T->At; + char* VAt = Validate; + while (((TAt - T->Memory) < T->MemoryLength) && *VAt) + { + if (*VAt != *TAt) + { + Result = false; + break; + } + TAt++; + *VAt++; + } + + if (Result) + { + T->At = TAt; + EatWhitespace(T); + } + + return Result; +} + +internal b32 +ParseComma(tokenizer* T) +{ + b32 Result = ParseTokenEquals(T, ","); + return Result; +} + +internal b32 +ParseOpenCurlyBrace(tokenizer* T) +{ + b32 Result = ParseTokenEquals(T, "{"); + return Result; +} + +internal b32 +ParseCloseCurlyBrace(tokenizer* T) +{ + b32 Result = ParseTokenEquals(T, "}"); + return Result; +} + +internal b32 +ParseOpenParen(tokenizer* T) +{ + b32 Result = ParseTokenEquals(T, "("); + return Result; +} + +internal b32 +ParseCloseParen(tokenizer* T) +{ + b32 Result = ParseTokenEquals(T, ")"); + return Result; +} + +internal b32 +ParseUnsignedInteger(tokenizer* T, u32* Value) +{ + parse_result Result = ParseUnsignedIntUnsafe(T->At); + *Value = Result.UnsignedIntValue; + T->At = Result.OnePastLast; + + // TODO(Peter): Parse functions in gs_string don't actually check for errors or + // whether or not they actually parsed an int. + // :GSStringParseErrors + return true; +} + +internal b32 +ParseFloat(tokenizer* T, r32* Value) +{ + parse_result ParseResult = ParseFloatUnsafe(T->At); + *Value = ParseResult.FloatValue; + T->At = ParseResult.OnePastLast; + + // TODO(Peter): + // :GSStringParseErrors + return true; +} + +internal b32 +ParseVector(tokenizer* T, v3* Value) +{ + b32 Result = true; + + if (ParseOpenParen(T)) + { + for (u32 i = 0; i < 3; i++) + { + b32 ValueSuccess = ParseFloat(T, &(Value->E[i])); + if (!ValueSuccess) + { + Result = false; + break; + } + + b32 CommaSuccess = ParseComma(T); + if (!CommaSuccess) + { + break; + } + } + + if (!ParseCloseParen(T)) + { + Result = false; + } + } + else + { + Result = false; + } + + return Result; +} + +// TODO(Peter): Error reporting +#define ParseLEDStripToken(tokenizer, parse_expr, error_msg) \ +(parse_expr) && (ParseComma(tokenizer)) + +internal b32 +ParseLEDStripCount (tokenizer* T, u32* Value) +{ + b32 Result = false; + + if (ParseTokenEquals(T, LED_STRIP_COUNT_IDENTIFIER)) + { + EatWhitespace(T); + if (ParseUnsignedInteger(T, Value)) + { + Result = true; + } + } + + return Result; +} + +internal b32 +ParseLEDStrip (led_strip_definition* Strip, tokenizer* T, memory_arena* Arena) +{ + b32 Result = false; + + if (ParseTokenEquals(T, LED_STRIP_IDENTIFIER) && + ParseOpenCurlyBrace(T)) + { + Result = true; + + u32 ControlBoxIndex, StartUniverse, StartChannel; + ParseLEDStripToken(T, ParseUnsignedInteger(T, &Strip->ControlBoxID), "Control Box Error"); + ParseLEDStripToken(T, ParseUnsignedInteger(T, &Strip->StartUniverse), "Start Universe Error"); + ParseLEDStripToken(T, ParseUnsignedInteger(T, &Strip->StartChannel), "Start Channel Error"); + + if (ParseTokenEquals(T, INTERPOLATE_POINTS_IDENTIFIER) && + ParseComma(T)) + { + Strip->InterpolationType = StripInterpolate_Points; + + ParseLEDStripToken(T, ParseVector(T, &Strip->InterpolatePositionStart), "Position Start Error"); + ParseLEDStripToken(T, ParseVector(T, &Strip->InterpolatePositionEnd), "Position End Error"); + } + + ParseLEDStripToken(T, ParseUnsignedInteger(T, &Strip->LEDsPerStrip), "LEDs Per Strip Error"); + + EatWhitespace(T); + if (!ParseCloseCurlyBrace(T)) + { + Result = false; + } + } + + return Result; +} + internal assembly_definition ParseAssemblyFile (u8* FileBase, s32 FileSize, memory_arena* Arena) { - assembly_definition AssemblyDefinition = {}; + assembly_definition Assembly = {}; - tokenizer AssemblyFileTokenizer = {}; - AssemblyFileTokenizer.At = (char*)FileBase; - AssemblyFileTokenizer.Memory = (char*)FileBase; - AssemblyFileTokenizer.MemoryLength = FileSize; + tokenizer Tokenizer = {}; + Tokenizer.At = (char*)FileBase; + Tokenizer.Memory = (char*)FileBase; + Tokenizer.MemoryLength = FileSize; - ParseAssemblyFileHeader(&AssemblyDefinition, &AssemblyFileTokenizer); - AssemblyDefinition.LEDStrips = PushArray(Arena, led_strip_definition, AssemblyDefinition.LEDStripSize); - ParseAssemblyFileBody(&AssemblyDefinition, &AssemblyFileTokenizer); + if (ParseLEDStripCount(&Tokenizer, &Assembly.LEDStripSize)) + { + Assembly.LEDStrips = PushArray(Arena, led_strip_definition, Assembly.LEDStripSize); + + while (AtValidPosition(Tokenizer)) + { + EatWhitespace(&Tokenizer); + + if (Assembly.LEDStripCount < Assembly.LEDStripSize) + { + led_strip_definition* LEDStrip = Assembly.LEDStrips + Assembly.LEDStripCount++; + + if (ParseLEDStrip(LEDStrip, &Tokenizer, Arena)) + { + Assembly.TotalLEDCount += LEDStrip->LEDsPerStrip; + } + else + { + InvalidCodePath; + } + } + else + { + if (ParseTokenEquals(&Tokenizer, END_ASSEMBLY_FILE_IDENTIFIER)) + { + break; + } + else + { + InvalidCodePath; + } + } + } + } + else + { + // TODO(Peter): Error reporting + InvalidCodePath; + } - return AssemblyDefinition; + return Assembly; } #define ASSEMBLY_PARSER_CPP diff --git a/src/assembly_parser.h b/src/assembly_parser.h index aa2f1ac..eee4c9d 100644 --- a/src/assembly_parser.h +++ b/src/assembly_parser.h @@ -47,23 +47,28 @@ enum strip_interpolation_type struct led_strip_definition { - s32 ControlBoxID; - s32 StartUniverse, StartChannel; + u32 ControlBoxID; + u32 StartUniverse; + u32 StartChannel; strip_interpolation_type InterpolationType; // Interpolate Boxes - s32 StartBoxIndex, EndBoxIndex; + u32 StartBoxIndex; + u32 EndBoxIndex; + // Interpolate Positions - v3 InterpolatePositionStart, InterpolatePositionEnd; + v3 InterpolatePositionStart; + v3 InterpolatePositionEnd; + // Universal Interpolation - s32 LEDsPerStrip; + u32 LEDsPerStrip; }; struct assembly_definition { - s32 LEDStripSize; - s32 LEDStripCount; - s32 TotalLEDCount; + u32 LEDStripSize; + u32 LEDStripCount; + u32 TotalLEDCount; led_strip_definition* LEDStrips; }; diff --git a/src/foldhaus_app.cpp b/src/foldhaus_app.cpp index dd50e47..7012bb2 100644 --- a/src/foldhaus_app.cpp +++ b/src/foldhaus_app.cpp @@ -269,7 +269,7 @@ CreateDMXBuffers(assembly Assembly, s32 BufferHeaderSize, memory_arena* Arena) s32 BufferSize = BufferHeaderSize + 512; - for (s32 Range = 0; Range < Assembly.LEDUniverseMapCount; Range++) + for (u32 Range = 0; Range < Assembly.LEDUniverseMapCount; Range++) { leds_in_universe_range LEDUniverseRange = Assembly.LEDUniverseMap[Range]; diff --git a/src/foldhaus_app.h b/src/foldhaus_app.h index 2aec647..2701089 100644 --- a/src/foldhaus_app.h +++ b/src/foldhaus_app.h @@ -87,7 +87,7 @@ internal void OpenColorPicker(app_state* State, v4* Address); internal void TestPatternOne(assembly* Assembly, r32 Time) { - for (s32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) + for (u32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) { leds_in_universe_range LEDUniverseRange = Assembly->LEDUniverseMap[Range]; for (s32 LEDIdx = LEDUniverseRange.RangeStart; @@ -122,7 +122,7 @@ TestPatternTwo(assembly* Assembly, r32 Time) r32 OuterRadiusSquared = 1000000; r32 InnerRadiusSquared = 0; - for (s32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) + for (u32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) { leds_in_universe_range LEDUniverseRange = Assembly->LEDUniverseMap[Range]; for (s32 LEDIdx = LEDUniverseRange.RangeStart; @@ -173,7 +173,7 @@ TestPatternThree(assembly* Assembly, r32 Time) r32 BluePosition = -BlueSize + (Time * 25); r32 RedPosition = (100 + RedSize) + (Time * -35); - for (s32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) + for (u32 Range = 0; Range < Assembly->LEDUniverseMapCount; Range++) { leds_in_universe_range LEDUniverseRange = Assembly->LEDUniverseMap[Range]; for (s32 LEDIdx = LEDUniverseRange.RangeStart; diff --git a/src/foldhaus_assembly.cpp b/src/foldhaus_assembly.cpp index 9c8a8e3..b3ee8ad 100644 --- a/src/foldhaus_assembly.cpp +++ b/src/foldhaus_assembly.cpp @@ -37,7 +37,7 @@ ConstructAssemblyFromDefinition (assembly_definition Definition, Assembly.LEDUniverseMap = PushArray(&Assembly.Arena, leds_in_universe_range, Definition.LEDStripCount); // Add LEDs - for (s32 StripIdx = 0; StripIdx < Definition.LEDStripCount; StripIdx++) + for (u32 StripIdx = 0; StripIdx < Definition.LEDStripCount; StripIdx++) { led_strip_definition StripDef = Definition.LEDStrips[StripIdx]; diff --git a/src/foldhaus_assembly.h b/src/foldhaus_assembly.h index 6fbacd0..29f5bde 100644 --- a/src/foldhaus_assembly.h +++ b/src/foldhaus_assembly.h @@ -36,11 +36,11 @@ struct assembly string Name; string FilePath; - s32 LEDCount; + u32 LEDCount; pixel* Colors; led* LEDs; - s32 LEDUniverseMapCount; + u32 LEDUniverseMapCount; leds_in_universe_range* LEDUniverseMap; }; diff --git a/src/panels/foldhaus_panel_hierarchy.h b/src/panels/foldhaus_panel_hierarchy.h index 459feec..c1b53b3 100644 --- a/src/panels/foldhaus_panel_hierarchy.h +++ b/src/panels/foldhaus_panel_hierarchy.h @@ -36,7 +36,7 @@ PANEL_RENDER_PROC(HierarchyView_Render) }; v2 TextOffset = v2{10, 4}; - string TempString = MakeString(PushArray(&State->Transient, char, 256), 256); + string TempString = MakeString(PushArray(&State->Transient, char, 256), 0, 256); u32 LineCount = (u32)(PanelHeight / List.ListElementDimensions.y) + 1; for (u32 i = 0; i < LineCount; i++) diff --git a/src/panels/foldhaus_panel_sculpture_view.h b/src/panels/foldhaus_panel_sculpture_view.h index 0f04851..420208f 100644 --- a/src/panels/foldhaus_panel_sculpture_view.h +++ b/src/panels/foldhaus_panel_sculpture_view.h @@ -141,16 +141,16 @@ PANEL_RENDER_PROC(SculptureView_Render) m44 FaceCameraMatrix = GetLookAtMatrix(v4{0, 0, 0, 1}, V4(State->Camera.Position, 1)); FaceCameraMatrix = FaceCameraMatrix; - s32 MaxLEDsPerJob = 2048; + u32 MaxLEDsPerJob = 2048; render_quad_batch_constructor RenderLEDsBatch = PushRenderQuad3DBatch(RenderBuffer, State->TotalLEDsCount); for (u32 i = 0; i < State->ActiveAssemblyIndecies.Used; i++) { gs_list_handle AssemblyHandle = *State->ActiveAssemblyIndecies.GetElementAtIndex(i); assembly Assembly = *State->AssemblyList.GetElementWithHandle(AssemblyHandle); - s32 JobsNeeded = IntegerDivideRoundUp(Assembly.LEDCount, MaxLEDsPerJob); + u32 JobsNeeded = IntegerDivideRoundUp(Assembly.LEDCount, MaxLEDsPerJob); - for (s32 Job = 0; Job < JobsNeeded; Job++) + for (u32 Job = 0; Job < JobsNeeded; Job++) { draw_leds_job_data* JobData = PushStruct(&State->Transient, draw_leds_job_data); JobData->LEDs = Assembly.LEDs;