[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 struct GfxPortalWritable
{ {
bool isQueued; char isQueued;
bool isAncestor; char isAncestor;
char recursionDepth; char recursionDepth;
char hullPointCount; char hullPointCount;
float(*hullPoints)[2]; float(*hullPoints)[2];
@ -2959,6 +2959,7 @@ namespace Game
{ {
float coeffs[4]; float coeffs[4];
char side[3]; char side[3];
char pad;
}; };
struct GfxPortal 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) Stream::Stream() : criticalSectionState(0)
{ {
memset(this->blockSize, 0, sizeof(this->blockSize)); memset(this->blockSize, 0, sizeof(this->blockSize));

View File

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