summaryrefslogtreecommitdiff
path: root/memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'memory.cpp')
-rw-r--r--memory.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/memory.cpp b/memory.cpp
index 6aebdc3..fcd7627 100644
--- a/memory.cpp
+++ b/memory.cpp
@@ -2,7 +2,7 @@ static void
InitMemoryTable(global_memory *GlobalMemory, memory *Memory, uint64 Size, memory_table_list TableName, char *Name) {
memory_table *Table = &Memory->Slot[TableName];
Table->Name = Name;
- Table->Address = (uint64 *)GlobalMemory->Address + GlobalMemory->CurrentPosition;
+ Table->Address = (uint64 *)((uint8 *)GlobalMemory->Address + GlobalMemory->CurrentPosition);
Table->Size = Size;
GlobalMemory->CurrentPosition += Size;
}
@@ -11,8 +11,21 @@ static void*
AllocateMemory(memory *Memory, uint64 Size, memory_table_list TableName) {
void *Address;
memory_table *Table = &Memory->Slot[TableName];
- Assert(Table->CurrentPosition + Size < Table->Size);
- Address = (uint64 *)Table->Address + Table->CurrentPosition;
+ if (Table->CurrentPosition + Size > Table->Size) {
+ return NULL;
+ }
+ Address = (uint64 *)((uint8 *)Table->Address + Table->CurrentPosition);
Table->CurrentPosition += Size;
return Address;
}
+
+// Returns 0-1 range wherever Pointer is in relation to StartingPointer to Size*Amount.
+static real32
+Memory_NormalizedPosition(void *StartingPointer, uint32 Amount, uint32 Size, void *Pointer)
+{
+ real32 Result = 0;
+ uint64 TotalSize = Amount*Size;
+ uint64 PointerLocationSize = (uint8 *)Pointer - (uint8 *)StartingPointer;
+ Result = (real32)PointerLocationSize / (real32)TotalSize;
+ return Result;
+}