summaryrefslogtreecommitdiff
path: root/memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'memory.cpp')
-rw-r--r--memory.cpp93
1 files changed, 83 insertions, 10 deletions
diff --git a/memory.cpp b/memory.cpp
index f502eb2..1dd7ae6 100644
--- a/memory.cpp
+++ b/memory.cpp
@@ -8,15 +8,6 @@ Memory_InitTable(global_memory *GlobalMemory, memory *Memory, uint64 Size, memor
GlobalMemory->CurrentPosition += Size;
}
-void Memory_Zero(uint8 *Address_Write, uint64 Size)
-{
- uint64 i = 0;
- while (i < Size) {
- *(Address_Write + i) = 0;
- i++;
- }
-}
-
static uint32
Memory_Block_AllocateNew(memory *Memory, memory_table_list TableName)
{
@@ -29,7 +20,7 @@ Memory_Block_AllocateNew(memory *Memory, memory_table_list TableName)
Address_Playhead += Table->Block_ElementSize;
Index++;
}
- Memory_Zero(Address_Playhead, Table->Block_ElementSize);
+ Arbitrary_Zero(Address_Playhead, Table->Block_ElementSize);
return Index;
}
@@ -50,6 +41,88 @@ Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName)
return Memory_Block_AddressAtIndex(Memory, TableName, FileIndex);
}
+static uint32
+Memory_Block_Bitmap_AllocateNew(project_state *State, memory *Memory, cache_entry Entry, uint64 NewSize)
+{
+ uint32 LastVal = 0;
+ uint32 LastBlock = 0;
+ uint32 c = 0;
+ cache_entry *EntryArray = State->Render.Entry;
+ while (EntryArray[c].IsOccupied != 0) {
+ if (EntryArray[c].Block_StartIndex > LastBlock) {
+ LastBlock = EntryArray[c].Block_StartIndex;
+ LastVal = c;
+ }
+ c++;
+ }
+ cache_entry LastEntry = EntryArray[LastVal];
+ uint32 LastEntry_BlockCount = 0;
+ switch (EntryArray[LastVal].Type) {
+ case cache_entry_type_comp:
+ {
+ block_composition Comp = *(block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, LastEntry.TypeInfo);
+ uint64 Size = Comp.Width * Comp.Height * Comp.BytesPerPixel;
+ LastEntry_BlockCount = (Size / BitmapBlockSize) + 1;
+ } break;
+ case cache_entry_type_source:
+ {
+ block_source Source = *(block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, LastEntry.TypeInfo);
+ uint64 Size = Source.Width * Source.Height * Source.BytesPerPixel;
+ LastEntry_BlockCount = (Size / BitmapBlockSize) + 1;
+ } break;
+ case cache_entry_type_layer:
+ {
+ Assert(0);
+ } break;
+ case cache_entry_type_assert:
+ {
+ Assert(0);
+ } break;
+ default:
+ {
+ Assert(0);
+ } break;
+ }
+
+ return LastBlock + LastEntry_BlockCount;
+
+ /*
+ uint32 Blocks_Needed = (NewSize / BitmapBlockSize) + 1;
+ uint32 Blocks_Max = Memory->Slot[B_CachedBitmaps].Size / BitmapBlockSize;
+ uint32 Block_Index_Available = 0;
+ */
+
+}
+
+static cache_entry *
+Memory_Cache_Search(project_state *State, memory *Memory, cache_entry *EntryArray, cache_entry_type Type, uint32 TypeInfo, uint32 TypeInfo_Sub)
+{
+ int c = 0;
+ while (EntryArray[c].IsOccupied != 0) {
+ if (EntryArray[c].Type == Type &&
+ EntryArray[c].TypeInfo == TypeInfo &&
+ EntryArray[c].TypeInfo_Sub == TypeInfo_Sub) {
+ return &EntryArray[c];
+ }
+ c++;
+ }
+ if (c != 0)
+ EntryArray[c].Block_StartIndex = Memory_Block_Bitmap_AllocateNew(State, Memory, EntryArray[c], 0);
+ EntryArray[c].IsOccupied = true;
+ EntryArray[c].Type = Type;
+ EntryArray[c].TypeInfo = TypeInfo;
+ EntryArray[c].TypeInfo_Sub = TypeInfo_Sub;
+ return &EntryArray[c];
+}
+
+static void *
+Memory_Block_Bitmap_AddressAtIndex(memory *Memory, uint32 Index)
+{
+ memory_table *Table = &Memory->Slot[B_CachedBitmaps];
+ uint8 *Address = (uint8 *)Table->Address + Index*BitmapBlockSize;
+ return (void *)Address;
+}
+
static void *
Memory_PushScratch(memory *Memory, uint64 Size) {
memory_table *Table = &Memory->Slot[B_ScratchSpace];