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.
This commit is contained in:
parent
c4b06256d9
commit
da5672b1e9
2
TODO.md
2
TODO.md
@ -1,6 +1,4 @@
|
||||
## TODO NEXT
|
||||
- TCreature::Damage
|
||||
- MAP.CC FileNumber: uint32 -> uintptr
|
||||
- MAGIC.CC
|
||||
- TCreature
|
||||
- TPlayer
|
||||
|
||||
23
src/map.cc
23
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];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user