summaryrefslogtreecommitdiff
path: root/memory.cpp
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2022-11-05 11:07:29 -0400
committerFox Caminiti <fox@foxcam.net>2022-11-05 11:07:29 -0400
commit0a6e95f855afad36481baa9ed72b39ba6e297df6 (patch)
treed8668a39ce224821ee6e05242ffb3cd37fd23c96 /memory.cpp
parent7435ce70153572e9f2dec316406e6ebb53334b51 (diff)
many changes
Diffstat (limited to 'memory.cpp')
-rw-r--r--memory.cpp77
1 files changed, 75 insertions, 2 deletions
diff --git a/memory.cpp b/memory.cpp
index 3037eb0..6e70055 100644
--- a/memory.cpp
+++ b/memory.cpp
@@ -41,6 +41,58 @@ Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName)
return Memory_Block_AddressAtIndex(Memory, TableName, FileIndex);
}
+// 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)
+{
+ for (;;) {
+ if (*CurrentCount == TotalCount) {
+ return 0;
+ }
+ if (*HasIncremented) {
+ *HasIncremented = 0;
+ (*Index)++;
+ }
+ uint8 *Occupied = (uint8 *)Memory_Block_AddressAtIndex(Memory, TableName, *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 uint32
+Memory_Block_PrincipalBitmap_AllocateNew(project_data *File, project_state *State, memory *Memory)
+{
+ uint32 LastVal = 0;
+ uint32 LastBlock = 0;
+ uint32 c = 0;
+ uint32 r = 0;
+ while (r < File->Source_Count) {
+ block_source Source = *(block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, c);
+ if (Source.Occupied != 0) {
+ LastBlock = (Source.Bitmap_Index > LastBlock) ? Source.Bitmap_Index : LastBlock;
+ LastVal = r;
+ r++;
+ }
+ c++;
+ }
+
+ block_source Source = *(block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, r);
+ uint32 BlockSize = ((Source.Width * Source.Height * Source.BytesPerPixel) / BitmapBlockSize) + 1;
+
+ uint32 Blocks_Max = Memory->Slot[B_CachedBitmaps].Size / BitmapBlockSize;
+ Assert(Blocks_Max > (LastBlock + BlockSize));
+ return LastBlock + BlockSize;
+
+}
+
static uint32
Memory_Block_Bitmap_AllocateNew(project_state *State, memory *Memory, cache_entry Entry, uint64 NewSize)
{
@@ -95,17 +147,37 @@ Memory_Block_Bitmap_AllocateNew(project_state *State, memory *Memory, cache_entr
}
+static void
+Memory_Cache_Invalidate(project_state *State, memory *Memory, cache_entry_type Type, uint32 TypeInfo, uint32 TypeInfo_Sub)
+{
+ cache_entry *EntryArray = State->Render.Entry;
+ int c = 0;
+ int count = Memory->EntryCount;
+ while (count != 0) {
+ if (EntryArray[c].Type == Type &&
+ EntryArray[c].TypeInfo == TypeInfo) {
+ EntryArray[c].IsOccupied = false;
+ Memory->EntryCount--;
+ }
+ c++;
+ count--;
+ }
+}
+
static cache_entry *
-Memory_Cache_Search(project_state *State, memory *Memory, cache_entry *EntryArray, cache_entry_type Type, uint32 TypeInfo, uint32 TypeInfo_Sub)
+Memory_Cache_Search(project_state *State, memory *Memory, cache_entry_type Type, uint32 TypeInfo, uint32 TypeInfo_Sub)
{
+ cache_entry *EntryArray = State->Render.Entry;
int c = 0;
- while (EntryArray[c].IsOccupied != 0) {
+ int count = Memory->EntryCount;
+ while (count != 0) {
if (EntryArray[c].Type == Type &&
EntryArray[c].TypeInfo == TypeInfo &&
EntryArray[c].TypeInfo_Sub == TypeInfo_Sub) {
return &EntryArray[c];
}
c++;
+ count--;
}
if (c != 0)
EntryArray[c].Block_StartIndex = Memory_Block_Bitmap_AllocateNew(State, Memory, EntryArray[c], 0);
@@ -113,6 +185,7 @@ Memory_Cache_Search(project_state *State, memory *Memory, cache_entry *EntryArra
EntryArray[c].Type = Type;
EntryArray[c].TypeInfo = TypeInfo;
EntryArray[c].TypeInfo_Sub = TypeInfo_Sub;
+ Memory->EntryCount++;
return &EntryArray[c];
}