aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-05-31 22:58:43 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-05-31 22:58:43 -0300
commitda5672b1e903cce47b9d76b2ffd19b0c42bd80f3 (patch)
tree5fba4490c0d5c9b415fd64758fcc9df0e73a500b
parentc4b06256d92408c4e99bd37b58d66f2024ec0a70 (diff)
downloadgame-da5672b1e903cce47b9d76b2ffd19b0c42bd80f3.tar.gz
game-da5672b1e903cce47b9d76b2ffd19b0c42bd80f3.zip
changed swap file numbers in `map.cc` to uintptr
We know swap file numbers are limited to the [1, 99999999] range which fits a uint32, but using anything but uintptr requires us to do extra casts to avoid compiler warnings so we only convert back to uint32 when building the swap file name which should work the same.
-rw-r--r--TODO.md2
-rw-r--r--src/map.cc23
2 files changed, 12 insertions, 13 deletions
diff --git a/TODO.md b/TODO.md
index 6102538..52a4acf 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,6 +1,4 @@
## TODO NEXT
-- TCreature::Damage
-- MAP.CC FileNumber: uint32 -> uintptr
- MAGIC.CC
- TCreature
- TPlayer
diff --git a/src/map.cc b/src/map.cc
index 34c1998..d3336c3 100644
--- a/src/map.cc
+++ b/src/map.cc
@@ -52,7 +52,7 @@ bool Object::exists(void){
uint32 EntryIndex = this->ObjectID & HashTableMask;
if(HashTableType[EntryIndex] == STATUS_SWAPPED){
- UnswapSector((uint32)((uintptr)HashTableData[EntryIndex]));
+ UnswapSector((uintptr)HashTableData[EntryIndex]);
}
return HashTableType[EntryIndex] == STATUS_LOADED
@@ -545,7 +545,7 @@ static void ResizeHashTable(void){
for(uint32 i = 1; i < NewSize; i += 1){
if(HashTableType[i] != STATUS_FREE){
if(HashTableType[i] == STATUS_SWAPPED){
- UnswapSector((uint32)((uintptr)HashTableData[i]));
+ UnswapSector((uintptr)HashTableData[i]);
}
if(HashTableType[i] == STATUS_LOADED){
@@ -603,7 +603,7 @@ static void PutFreeObjectSlot(TObject *Entry){
FirstFreeObject = Entry;
}
-void SwapObject(TWriteBinaryFile *File, Object Obj, uint32 FileNumber){
+void SwapObject(TWriteBinaryFile *File, Object Obj, uintptr FileNumber){
ASSERT(Obj != NONE);
// NOTE(fusion): Does it make sense to swap an object that isn't loaded? We
@@ -611,7 +611,7 @@ void SwapObject(TWriteBinaryFile *File, Object Obj, uint32 FileNumber){
// sector if it was swapped out. We should probably have an assertion here.
uint32 EntryIndex = Obj.ObjectID & HashTableMask;
if(HashTableType[EntryIndex] != STATUS_LOADED){
- error("SwapObject: Object doesn't exists or is not currently loaded.\n");
+ error("SwapObject: Object doesn't exist or is not currently loaded.\n");
return;
}
@@ -633,11 +633,11 @@ void SwapObject(TWriteBinaryFile *File, Object Obj, uint32 FileNumber){
PutFreeObjectSlot(Entry);
HashTableType[EntryIndex] = STATUS_SWAPPED;
- HashTableData[EntryIndex] = (TObject*)((uintptr)FileNumber);
+ HashTableData[EntryIndex] = (TObject*)FileNumber;
}
void SwapSector(void){
- static uint32 FileNumber = 0;
+ static uintptr FileNumber = 0;
TSector *Oldest = NULL;
int OldestSectorX = 0;
@@ -672,7 +672,7 @@ void SwapSector(void){
if(FileNumber > 99999999){
FileNumber = 1;
}
- snprintf(FileName, sizeof(FileName), "%s/%08u.swp", SAVEPATH, FileNumber);
+ snprintf(FileName, sizeof(FileName), "%s/%08u.swp", SAVEPATH, (uint32)FileNumber);
}while(FileExists(FileName));
TWriteBinaryFile File;
@@ -698,9 +698,9 @@ void SwapSector(void){
}
}
-void UnswapSector(uint32 FileNumber){
+void UnswapSector(uintptr FileNumber){
char FileName[4096];
- snprintf(FileName, sizeof(FileName), "%s/%08u.swp", SAVEPATH, FileNumber);
+ snprintf(FileName, sizeof(FileName), "%s/%08u.swp", SAVEPATH, (uint32)FileNumber);
TReadBinaryFile File;
try{
@@ -1787,10 +1787,11 @@ TObject *AccessObject(Object Obj){
uint32 EntryIndex = Obj.ObjectID & HashTableMask;
if(HashTableType[EntryIndex] == STATUS_SWAPPED){
- UnswapSector((uint32)((uintptr)HashTableData[EntryIndex]));
+ UnswapSector((uintptr)HashTableData[EntryIndex]);
}
- if(HashTableType[EntryIndex] == STATUS_LOADED && HashTableData[EntryIndex]->ObjectID == Obj.ObjectID){
+ if(HashTableType[EntryIndex] == STATUS_LOADED
+ && HashTableData[EntryIndex]->ObjectID == Obj.ObjectID){
return HashTableData[EntryIndex];
}else{
return HashTableData[0];