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

Method fillBuffer

Engine/source/core/stream/fileStream.cpp:437–493  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

435
436//-----------------------------------------------------------------------------
437bool FileStream::fillBuffer(const U32 i_startPosition)
438{
439 AssertFatal(0 != mStreamCaps, "FileStream::fillBuffer: the stream isn't open");
440 AssertFatal(false == mDirty, "FileStream::fillBuffer: buffer must be clean to fill");
441
442 // make sure start position and file pointer jive
443 if (i_startPosition != mFile->getPosition())
444 {
445 mFile->setPosition(i_startPosition, Torque::FS::File::Begin);
446 if (mFile->getStatus() != Torque::FS::FileNode::Open && mFile->getStatus() != Torque::FS::FileNode::EndOfFile)
447 {
448 setStatus();
449 return(false);
450 }
451 else
452 // update buffer pointer
453 mBuffPos = i_startPosition;
454 }
455
456 // check if file pointer is at end-of-file
457 if (EOS == getStatus())
458 {
459 // invalidate the buffer
460 mBuffHead = BUFFER_INVALID;
461 // set the status to end-of-stream
462 mEOF = true;
463 }
464 // otherwise
465 else
466 {
467 U32 blockHead;
468 // locate bounds of buffer containing current position
469 calcBlockHead(mBuffPos, &blockHead);
470 // read as much as possible from input file
471 U32 bytesRead = mFile->read((char *)mBuffer + (i_startPosition - blockHead), BUFFER_SIZE - (i_startPosition - blockHead));
472 setStatus();
473 if (Ok == getStatus() || EOS == getStatus())
474 {
475 // update buffer pointers
476 mBuffHead = i_startPosition;
477 mBuffPos = i_startPosition;
478 mBuffTail = i_startPosition + bytesRead - 1;
479 // update end-of-file status
480 if (0 != bytesRead && EOS == getStatus())
481 {
482 Stream::setStatus(Ok);
483 mEOF = true;
484 }
485 }
486 else
487 {
488 mBuffHead = BUFFER_INVALID;
489 return(false);
490 }
491 }
492 return(true);
493}
494

Callers

nothing calls this directly

Calls 4

getPositionMethod · 0.45
setPositionMethod · 0.45
getStatusMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected