summaryrefslogtreecommitdiff
path: root/memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'memory.cpp')
-rw-r--r--memory.cpp42
1 files changed, 17 insertions, 25 deletions
diff --git a/memory.cpp b/memory.cpp
index 53388bf..4593d49 100644
--- a/memory.cpp
+++ b/memory.cpp
@@ -26,16 +26,18 @@ Memory_Block_AllocateNew(memory *Memory, memory_table_list TableName)
}
static void *
-Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 Index)
+Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 Index, bool32 AssertExists = 1)
{
memory_table *Table = &Memory->Slot[TableName];
Assert(Table->Block_ElementSize != 0);
uint8 *Address = (uint8 *)Table->Address + (Table->Block_ElementSize * Index);
+ if (AssertExists)
+ Assert(*Address != 0);
return (void *)Address;
}
static uint16
-Memory_Block_IndexAtAddress(memory *Memory, memory_table_list TableName, void *Address)
+Memory_Block_LazyIndexAtAddress(memory *Memory, memory_table_list TableName, void *Address)
{
memory_table *Table = &Memory->Slot[TableName];
return ((uint8 *)Address - (uint8 *)Table->Address) / Table->Block_ElementSize;
@@ -45,7 +47,7 @@ static void *
Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName)
{
uint16 FileIndex = Memory_Block_AllocateNew(Memory, TableName);
- return Memory_Block_AddressAtIndex(Memory, TableName, FileIndex);
+ return Memory_Block_AddressAtIndex(Memory, TableName, FileIndex, 0);
}
// IMPORTANT(fox): All block data has to start with a uint8 Occupied variable!
@@ -60,7 +62,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 *)Memory_Block_AddressAtIndex(Memory, TableName, *Index, 0);
if (*Occupied) {
*HasIncremented = 1;
(*CurrentCount)++;
@@ -179,23 +181,6 @@ 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_type Type, uint32 TypeInfo, uint32 TypeInfo_Sub)
{
@@ -203,10 +188,17 @@ Memory_Cache_Search(project_state *State, memory *Memory, cache_entry_type Type,
int c = 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];
+ if (Type == cache_entry_type_comp) {
+ if (EntryArray[c].Type == Type &&
+ EntryArray[c].TypeInfo == TypeInfo) {
+ return &EntryArray[c];
+ }
+ } else {
+ if (EntryArray[c].Type == Type &&
+ EntryArray[c].TypeInfo == TypeInfo &&
+ EntryArray[c].TypeInfo_Sub == TypeInfo_Sub) {
+ return &EntryArray[c];
+ }
}
c++;
count--;