diff --git a/gs_libs/gs_win32.cpp b/gs_libs/gs_win32.cpp index dd55973..e2df025 100644 --- a/gs_libs/gs_win32.cpp +++ b/gs_libs/gs_win32.cpp @@ -83,20 +83,26 @@ Win32StringLength(char* String) } internal s32 -Win32ConcatStrings(s32 ALen, char* A, s32 BLen, char* B, s32 DestLen, char* Dest) +Win32ConcatStrings(s32 ALength, char* A, s32 BLength, char* B, s32 DestLength, char* Dest) { char* Dst = Dest; char* AAt = A; - for (s32 a = 0; a < ALen; a++) + int ALengthToCopy = ALength < DestLength ? ALength : DestLength; + for (s32 a = 0; a < ALength; a++) { *Dst++ = *AAt++; } char* BAt = B; - for (s32 b = 0; b < BLen; b++) + int DestLengthRemaining = DestLength - (Dst - Dest); + int BLengthToCopy = BLength < DestLengthRemaining ? BLength : DestLength; + for (s32 b = 0; b < BLengthToCopy; b++) { *Dst++ = *BAt++; } - return Dst - Dest; + int DestLengthOut = Dst - Dest; + int NullTermIndex = DestLengthOut < DestLength ? DestLengthOut : DestLength; + Dest[NullTermIndex] = 0; + return DestLengthOut; } /// diff --git a/src/foldhaus_app.cpp b/src/foldhaus_app.cpp index e3c996f..a62d462 100644 --- a/src/foldhaus_app.cpp +++ b/src/foldhaus_app.cpp @@ -341,13 +341,25 @@ UPDATE_AND_RENDER(UpdateAndRender) State->AnimationSystem.LastUpdatedFrame = CurrentFrame; r32 FrameTime = CurrentFrame * State->AnimationSystem.SecondsPerFrame; + u32 CurrentBlocksMax = State->AnimationSystem.LayersCount; + b8* CurrentBlocksFilled = PushArray(&State->Transient, b8, CurrentBlocksMax); + GSZeroArray(CurrentBlocksFilled, b8, CurrentBlocksMax); + animation_block* CurrentBlocks = PushArray(&State->Transient, animation_block, CurrentBlocksMax); + for (u32 i = 0; i < State->AnimationSystem.Blocks.Used; i++) { gs_list_entry* BlockEntry = State->AnimationSystem.Blocks.GetEntryAtIndex(i); if (EntryIsFree(BlockEntry)) { continue; } animation_block Block = BlockEntry->Value; if (CurrentFrame < Block.Range.Min || CurrentFrame > Block.Range.Max) { continue; } - + CurrentBlocksFilled[Block.Layer] = true; + CurrentBlocks[Block.Layer] = Block; + } + + for (s32 Layer = CurrentBlocksMax - 1; Layer >= 0; Layer--) + { + if (!CurrentBlocksFilled[Layer]) { continue; } + animation_block Block = CurrentBlocks[Layer]; for (u32 j = 0; j < State->ActiveAssemblyIndecies.Used; j++) { gs_list_handle AssemblyHandle = *State->ActiveAssemblyIndecies.GetElementAtIndex(j); diff --git a/src/foldhaus_app.h b/src/foldhaus_app.h index 822573c..840af74 100644 --- a/src/foldhaus_app.h +++ b/src/foldhaus_app.h @@ -151,12 +151,12 @@ TestPatternTwo(assembly* Assembly, r32 Time) } else { - Assembly->Colors[LED.Index] = {}; + //Assembly->Colors[LED.Index] = {}; } } else { - Assembly->Colors[LED.Index] = {}; + //Assembly->Colors[LED.Index] = {}; } } } diff --git a/src/win32_foldhaus_dll.h b/src/win32_foldhaus_dll.h index 13c78cb..01b6bea 100644 --- a/src/win32_foldhaus_dll.h +++ b/src/win32_foldhaus_dll.h @@ -14,13 +14,44 @@ struct win32_dll_refresh FILETIME LastWriteTime; HMODULE DLL; - b32 IsValid; + bool IsValid; char SourceDLLPath[MAX_PATH]; char WorkingDLLPath[MAX_PATH]; char LockFilePath[MAX_PATH]; }; +internal int +Win32DLLStringLength(char* String) +{ + char* At = String; + while (*At) { At++; }; + return At - String; +} + +internal int +Win32DLLConcatStrings(int ALength, char* A, int BLength, char* B, int DestLength, char* Dest) +{ + char* Dst = Dest; + char* AAt = A; + int ALengthToCopy = ALength < DestLength ? ALength : DestLength; + for (s32 a = 0; a < ALength; a++) + { + *Dst++ = *AAt++; + } + char* BAt = B; + int DestLengthRemaining = DestLength - (Dst - Dest); + int BLengthToCopy = BLength < DestLengthRemaining ? BLength : DestLength; + for (s32 b = 0; b < BLengthToCopy; b++) + { + *Dst++ = *BAt++; + } + int DestLengthOut = Dst - Dest; + int NullTermIndex = DestLengthOut < DestLength ? DestLengthOut : DestLength; + Dest[NullTermIndex] = 0; + return DestLengthOut; +} + internal void GetApplicationPath(system_path* Result) { @@ -81,15 +112,15 @@ InitializeDLLHotReloading(char* SourceDLLName, ExePath.Path = (char*)VirtualAlloc(NULL, ExePath.PathLength, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); GetApplicationPath(&ExePath); - Win32ConcatStrings(ExePath.IndexOfLastSlash, ExePath.Path, - Win32StringLength(SourceDLLName), SourceDLLName, - MAX_PATH, Result.SourceDLLPath); - Win32ConcatStrings(ExePath.IndexOfLastSlash, ExePath.Path, - Win32StringLength(WorkingDLLFileName), WorkingDLLFileName, - MAX_PATH, Result.WorkingDLLPath); - Win32ConcatStrings(ExePath.IndexOfLastSlash, ExePath.Path, - Win32StringLength(LockFileName), LockFileName, - MAX_PATH, Result.LockFilePath); + Win32DLLConcatStrings(ExePath.IndexOfLastSlash, ExePath.Path, + Win32DLLStringLength(SourceDLLName), SourceDLLName, + MAX_PATH, Result.SourceDLLPath); + Win32DLLConcatStrings(ExePath.IndexOfLastSlash, ExePath.Path, + Win32DLLStringLength(WorkingDLLFileName), WorkingDLLFileName, + MAX_PATH, Result.WorkingDLLPath); + Win32DLLConcatStrings(ExePath.IndexOfLastSlash, ExePath.Path, + Win32DLLStringLength(LockFileName), LockFileName, + MAX_PATH, Result.LockFilePath); Win32Free((u8*)ExePath.Path, ExePath.PathLength); return Result; diff --git a/todo.txt b/todo.txt index aaf9384..06de4c0 100644 --- a/todo.txt +++ b/todo.txt @@ -75,10 +75,15 @@ Ground Up Reengineering x zoom in and out - blending between animation - layers - - display more than one layer - - add/remove layers + x display more than one layer + x add/remove layers - layer masks by sculpture - - blend modes + - blend modes - create a copy of the led's per layer, handle blending outside of patterns + - interface for animation system + - add/remove layers + - select blend modes + - change which layer an animation is on + - - setting start and end of timeline (how long is a loop) - clips can have parameters that drive them?