mirror of
https://github.com/jpd002/Play-.git
synced 2025-04-28 13:47:57 +03:00

Instead of loading the whole disc image in memory, use the Browser's File API to fetch needed parts of the file. Has to go through some odd proxying hoops since the File object is owned by the main browser thread.
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
#include "Js_DiscImageDeviceStream.h"
|
|
#include <stdexcept>
|
|
#include <cassert>
|
|
#include <emscripten.h>
|
|
#include <unistd.h>
|
|
|
|
void CJsDiscImageDeviceStream::Seek(int64 position, Framework::STREAM_SEEK_DIRECTION whence)
|
|
{
|
|
switch(whence)
|
|
{
|
|
case Framework::STREAM_SEEK_SET:
|
|
m_position = position;
|
|
break;
|
|
case Framework::STREAM_SEEK_CUR:
|
|
m_position += position;
|
|
break;
|
|
case Framework::STREAM_SEEK_END:
|
|
m_position = MAIN_THREAD_EM_ASM_INT({return Module.discImageDevice.getFileSize()});
|
|
break;
|
|
}
|
|
}
|
|
|
|
uint64 CJsDiscImageDeviceStream::Tell()
|
|
{
|
|
return m_position;
|
|
}
|
|
|
|
uint64 CJsDiscImageDeviceStream::Read(void* buffer, uint64 size)
|
|
{
|
|
if(size == 0) return 0;
|
|
|
|
assert(size <= std::numeric_limits<uint32>::max());
|
|
|
|
uint32 positionLow = static_cast<uint32>(m_position);
|
|
uint32 positionHigh = static_cast<uint32>(m_position >> 32);
|
|
|
|
MAIN_THREAD_EM_ASM({
|
|
let position = ($1) | ($2 << 32);
|
|
Module.discImageDevice.read($0, position, $3);
|
|
}, buffer, positionLow, positionHigh, static_cast<uint32>(size));
|
|
while(!MAIN_THREAD_EM_ASM_INT({return Module.discImageDevice.isDone()}))
|
|
{
|
|
usleep(100);
|
|
}
|
|
m_position += size;
|
|
return size;
|
|
}
|
|
|
|
uint64 CJsDiscImageDeviceStream::Write(const void*, uint64)
|
|
{
|
|
throw std::runtime_error("Not supported.");
|
|
}
|
|
|
|
bool CJsDiscImageDeviceStream::IsEOF()
|
|
{
|
|
throw std::runtime_error("Not supported.");
|
|
}
|
|
|
|
void CJsDiscImageDeviceStream::Flush()
|
|
{
|
|
}
|