[Stream] Add pointer interface to the reader

This commit is contained in:
momo5502 2016-12-25 15:17:31 +01:00
parent bfe1c335af
commit b4fd5a11d1
3 changed files with 31 additions and 2 deletions

View File

@ -2948,8 +2948,8 @@ namespace Game
struct GfxPortalWritable
{
bool isQueued;
bool isAncestor;
char isQueued;
char isAncestor;
char recursionDepth;
char hullPointCount;
float(*hullPoints)[2];
@ -2959,6 +2959,7 @@ namespace Game
{
float coeffs[4];
char side[3];
char pad;
};
struct GfxPortal

View File

@ -59,6 +59,29 @@ namespace Utils
}
}
void* Stream::Reader::readPointer()
{
void* pointer = this->read<void*>();
if (!this->hasPointer(pointer))
{
this->pointerMap[pointer] = 0;
}
return pointer;
}
void Stream::Reader::mapPointer(void* oldPointer, void* newPointer)
{
if (this->hasPointer(oldPointer))
{
this->pointerMap[oldPointer] = newPointer;
}
}
bool Stream::Reader::hasPointer(void* pointer)
{
return this->pointerMap.find(pointer) != this->pointerMap.end();
}
Stream::Stream() : criticalSectionState(0)
{
memset(this->blockSize, 0, sizeof(this->blockSize));

View File

@ -49,9 +49,14 @@ namespace Utils
bool end();
void seek(unsigned int position);
void* readPointer();
void mapPointer(void* oldPointer, void* newPointer);
bool hasPointer(void* pointer);
private:
unsigned int position;
std::string buffer;
std::map<void*, void*> pointerMap;
Utils::Memory::Allocator* allocator;
};