diff options
author | Fox Caminiti <fox@foxcam.net> | 2022-11-10 22:34:17 -0500 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2022-11-10 22:34:17 -0500 |
commit | 38bf0102300c97335d8e78b4683cb9b9476dcde0 (patch) | |
tree | b92d8225ba860cde7f23be96c7da3a3563272e8c /memory.cpp | |
parent | 0a6e95f855afad36481baa9ed72b39ba6e297df6 (diff) |
graph implementation
Diffstat (limited to 'memory.cpp')
-rw-r--r-- | memory.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
@@ -34,6 +34,13 @@ Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 return (void *)Address; } +static uint16 +Memory_Block_IndexAtAddress(memory *Memory, memory_table_list TableName, void *Address) +{ + memory_table *Table = &Memory->Slot[TableName]; + return ((uint8 *)Address - (uint8 *)Table->Address) / Table->Block_ElementSize; +} + static void * Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName) { @@ -43,7 +50,37 @@ Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName) // IMPORTANT(fox): All block data has to start with a uint8 Occupied variable! static bool32 -Block_Loop(memory *Memory, memory_table_list TableName, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index) +Block_Loop(memory *Memory, memory_table_list TableName, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index, void *Extra = NULL) +{ + for (;;) { + if (*CurrentCount == TotalCount) { + return 0; + } + if (*HasIncremented) { + *HasIncremented = 0; + (*Index)++; + } + uint8 *Occupied; + if (!Extra) { + Occupied = (uint8 *)Memory_Block_AddressAtIndex(Memory, TableName, *Index); + } else { + Occupied = (uint8 *)Bezier_Lookup(Memory, (property_channel *)Extra, *Index); + } + if (*Occupied) { + *HasIncremented = 1; + (*CurrentCount)++; + return 1; + } + (*Index)++; + Assert(*CurrentCount <= TotalCount); + Assert(*Index <= TotalCount*100); // This can get triggered normally if 100+ items are added and the first 99 in memory are deleted. + } + Assert(0); + return 0; +} + +static bool32 +Block_Loop(memory *Memory, property_channel *Property, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index) { for (;;) { if (*CurrentCount == TotalCount) { @@ -53,7 +90,7 @@ Block_Loop(memory *Memory, memory_table_list TableName, uint32 TotalCount, int * *HasIncremented = 0; (*Index)++; } - uint8 *Occupied = (uint8 *)Memory_Block_AddressAtIndex(Memory, TableName, *Index); + uint8 *Occupied = (uint8 *)Bezier_Lookup(Memory, Property, *Index); if (*Occupied) { *HasIncremented = 1; (*CurrentCount)++; |