Files
RP412/MUNGA/FILESTRM.cpp
T
CydandClaude Opus 4.8 4abbf8879f Initial import of Red Planet v4.10 Win32 source
Imports the current Win32 source for the pod-racing game 'Red Planet',
built on the MUNGA engine and its L4 (Win32/DirectX) platform layer:

- MUNGA / MUNGA_L4: cross-platform engine core and Win32 backend
- RP / RP_L4: Red Planet game logic and Win32 application
- DivLoader, Setup1: asset loader and installer project
- lib, MUNGA_L4/openal, MUNGA_L4/sos: third-party audio dependencies

Removed stale Subversion metadata and added .gitignore/.gitattributes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 07:59:51 -05:00

123 lines
2.9 KiB
C++

#include "munga.h"
#pragma hdrstop
#include "filestrm.h"
//#############################################################################
//########################### FileStream ################################
//#############################################################################
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
FileStream::FileStream(const char* file_name, Logical writable) : MemoryStream(NULL, 0)
{
Open(file_name, writable);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void FileStream::Open(const char* file_name, Logical writable)
{
readOnly = !writable;
fileHandle = -1;
currentPosition = streamStart = NULL;
streamSize = 0;
if (file_name)
{
Check_Pointer(file_name);
fileHandle = OpenImplementation(file_name, readOnly);
}
if (fileHandle != -1)
{
if (readOnly)
{
streamSize = SeekImplementation(fileHandle, 0, True);
SeekImplementation(fileHandle, 0);
}
else
streamSize = 0xFFFFFFFFU;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void FileStream::Close()
{
Check(this);
if (fileHandle != -1)
{
if (!readOnly)
FlushImplementation(fileHandle);
CloseImplementation(fileHandle);
}
fileHandle = -1;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void FileStream::SetPointer(size_t index)
{
Check(this);
Verify(fileHandle != -1);
currentPosition = (char*)SeekImplementation(fileHandle, index);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MemoryStream& FileStream::AdvancePointer(size_t index)
{
Check(this);
Verify(fileHandle != -1);
currentPosition = (char*)SeekImplementation(fileHandle, (size_t)currentPosition + index);
return *this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MemoryStream& FileStream::RewindPointer(size_t index)
{
Check(this);
Verify(fileHandle != -1);
currentPosition = (char*)SeekImplementation(fileHandle, (size_t)currentPosition + index);
return *this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MemoryStream& FileStream::ReadBytes(void *ptr, size_t number_of_bytes)
{
Check(this);
Verify(fileHandle != -1);
Verify(readOnly);
size_t read = ReadImplementation(fileHandle, ptr, number_of_bytes);
Verify(read == number_of_bytes);
currentPosition += read;
return *this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MemoryStream& FileStream::WriteBytes(const void *ptr, size_t number_of_bytes)
{
Check(this);
Verify(fileHandle != -1);
Verify(!readOnly);
size_t written = WriteImplementation(fileHandle, ptr, number_of_bytes);
Verify(written == number_of_bytes);
currentPosition += written;
return *this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Logical FileStream::TestInstance() const
{
return true;
}