MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / _read

Method _read

Engine/source/core/stream/fileStream.cpp:243–341  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

241
242//-----------------------------------------------------------------------------
243bool FileStream::_read(const U32 i_numBytes, void *o_pBuffer)
244{
245 AssertFatal(0 != mStreamCaps, "FileStream::_read: the stream isn't open");
246 AssertFatal(NULL != o_pBuffer || i_numBytes == 0, "FileStream::_read: NULL destination pointer with non-zero read request");
247
248 if (!hasCapability(Stream::StreamRead))
249 {
250 AssertFatal(false, "FileStream::_read: file stream lacks capability");
251 Stream::setStatus(IllegalCall);
252 return(false);
253 }
254
255 // exit on pre-existing errors
256 if (Ok != getStatus())
257 return(false);
258
259 // if a request of non-zero length was made
260 if (0 != i_numBytes)
261 {
262 U8 *pDst = (U8 *)o_pBuffer;
263 U32 readSize;
264 U32 remaining = i_numBytes;
265 U32 bytesRead;
266 U32 blockHead;
267 U32 blockTail;
268
269 // check if the buffer has some data in it
270 if (BUFFER_INVALID != mBuffHead)
271 {
272 // copy as much as possible from the buffer into the destination
273 readSize = ((mBuffTail + 1) >= mBuffPos) ? (mBuffTail + 1 - mBuffPos) : 0;
274 readSize = getMin(readSize, remaining);
275 calcBlockHead(mBuffPos, &blockHead);
276 dMemcpy(pDst, mBuffer + (mBuffPos - blockHead), readSize);
277 // reduce the remaining amount to read
278 remaining -= readSize;
279 // advance the buffer pointers
280 mBuffPos += readSize;
281 pDst += readSize;
282
283 if (mBuffPos > mBuffTail && remaining != 0)
284 {
285 flush();
286 mBuffHead = BUFFER_INVALID;
287 if (mEOF == true)
288 Stream::setStatus(EOS);
289 }
290 }
291
292 // if the request wasn't satisfied by the buffer and the file has more data
293 if (false == mEOF && 0 < remaining)
294 {
295 // flush the buffer if its dirty, since we now need to go to disk
296 if (true == mDirty)
297 flush();
298
299 // make sure we know the current read location in the underlying file
300 mBuffPos = mFile->getPosition();

Callers

nothing calls this directly

Calls 3

dMemcpyFunction · 0.50
getPositionMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected