1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-28 15:39:41 +00:00

Merge branch 'seekable-membuf' into 'master'

Make in-memory buffers seekable to fix fog of war

See merge request OpenMW/openmw!129
This commit is contained in:
Alexei Dobrohotov 2019-07-01 10:08:12 +00:00
commit 4d5debafdf

View file

@ -9,11 +9,31 @@ namespace Files
struct MemBuf : std::streambuf struct MemBuf : std::streambuf
{ {
MemBuf(char const* buffer, size_t size) MemBuf(char const* buffer, size_t size)
{
// a streambuf isn't specific to istreams, so we need a non-const pointer :/ // a streambuf isn't specific to istreams, so we need a non-const pointer :/
char* nonconstBuffer = (const_cast<char*>(buffer)); : bufferStart(const_cast<char*>(buffer))
this->setg(nonconstBuffer, nonconstBuffer, nonconstBuffer + size); , bufferEnd(bufferStart + size)
{
this->setg(bufferStart, bufferStart, bufferEnd);
} }
pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which) override
{
if (dir == std::ios_base::cur)
gbump(off);
else
setg(bufferStart, (dir == std::ios_base::beg ? bufferStart : bufferEnd) + off, bufferEnd);
return gptr() - bufferStart;
}
pos_type seekpos(pos_type pos, std::ios_base::openmode which) override
{
return seekoff(pos, std::ios_base::beg, which);
}
protected:
char* bufferStart;
char* bufferEnd;
}; };
/// @brief A variant of std::istream that reads from a constant in-memory buffer. /// @brief A variant of std::istream that reads from a constant in-memory buffer.