Skip to content

Commit

Permalink
Merge pull request #204 from HiGuyMB/vfs-mem
Browse files Browse the repository at this point in the history
Memory-backed files in VFS
  • Loading branch information
HumanGamer authored Mar 5, 2024
2 parents 150a5ad + 42e0e27 commit dd7fbb9
Show file tree
Hide file tree
Showing 30 changed files with 564 additions and 211 deletions.
26 changes: 13 additions & 13 deletions engine/source/atlas/atlasGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ S8 AtlasActivationHeightfield::checkPropagation(Point2I c, S8 level)

bool AtlasActivationHeightfield::dumpActivationLevels(const char* filename)
{
FileStream fs;
Stream* fs;

if (!ResourceManager->openFileForWrite(fs, filename, File::ReadWrite))
{
Expand All @@ -311,16 +311,16 @@ bool AtlasActivationHeightfield::dumpActivationLevels(const char* filename)

for (S32 i = 0; i < size(); i++)
for (S32 j = 0; j < size(); j++)
fs.write(getLevel(Point2I(i, j)));
fs->write(getLevel(Point2I(i, j)));

fs.close();
delete fs;

return true;
}

bool AtlasActivationHeightfield::dumpHeightAtLOD(S8 level, const char* filename)
{
FileStream fs;
Stream* fs;

if (!ResourceManager->openFileForWrite(fs, filename, File::ReadWrite))
{
Expand All @@ -336,11 +336,11 @@ bool AtlasActivationHeightfield::dumpHeightAtLOD(S8 level, const char* filename)
const Point2I pos(i, j);

HeightType h = getHeightAtLOD(pos, level);
fs.write(h);
fs->write(h);
}
}

fs.close();
delete fs;

return true;
}
Expand Down Expand Up @@ -938,7 +938,7 @@ ConsoleFunction(generateChunkFileFromRaw16, void, 8, 8, "(srcFile, size, squareS
ResourceManager->closeStream(s);

// Cool, it's loaded, try generating something.
FileStream fs;
Stream* fs;

// Wipe it first.
if (!ResourceManager->openFileForWrite(fs, destFile, File::Write))
Expand All @@ -947,7 +947,7 @@ ConsoleFunction(generateChunkFileFromRaw16, void, 8, 8, "(srcFile, size, squareS
return;
}

fs.close();
delete fs;

// Now do it for reals.
if (!ResourceManager->openFileForWrite(fs, destFile, File::ReadWrite))
Expand All @@ -956,9 +956,9 @@ ConsoleFunction(generateChunkFileFromRaw16, void, 8, 8, "(srcFile, size, squareS
return;
}

cahf.generateChunkFile(&fs, treeDepth, error);
cahf.generateChunkFile(fs, treeDepth, error);

fs.close();
delete fs;
}

ConsoleFunction(doChunkGen, void, 1, 1, "Test chunk generation.")
Expand All @@ -977,7 +977,7 @@ ConsoleFunction(doChunkGen, void, 1, 1, "Test chunk generation.")
ResourceManager->closeStream(s);

// Cool, it's loaded, try generating something.
FileStream fs;
Stream* fs;

dFileDelete("demo/data/terrains/small.chu");

Expand All @@ -987,7 +987,7 @@ ConsoleFunction(doChunkGen, void, 1, 1, "Test chunk generation.")
return;
}

cahf.generateChunkFile(&fs, 5, 0.5f);
cahf.generateChunkFile(fs, 5, 0.5f);

fs.close();
delete fs;
}
6 changes: 3 additions & 3 deletions engine/source/atlas/atlasHeightfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ bool AtlasHeightfield::saveJpeg(const char* filename)
}
}

FileStream fs;
Stream* fs;

if (!ResourceManager->openFileForWrite(fs, filename, File::Write))
{
Con::errorf("AtlasHeightfield::saveJpeg - failed to open output file!");
return false;
}

tmp.writeJPEG(fs);
fs.close();
tmp.writeJPEG(*fs);
delete fs;

return true;
}
Expand Down
40 changes: 20 additions & 20 deletions engine/source/atlas/atlasTQTFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,22 +441,22 @@ void AtlasTQTFile::merge(AtlasTQTFile* tqt00, AtlasTQTFile* tqt01, AtlasTQTFile*
dMemset(mOffsets.address(), 0, sizeof(mOffsets[0]) * mOffsets.size());

// Open the file for output.
FileStream s;
Stream* s;
if (!ResourceManager->openFileForWrite(s, outFile, File::ReadWrite))
{
Con::errorf("AtlasTQTFile::merge - could not open '%s' for generation (read AND write).", outFile);
return;
}

// Write a header. Some parts of this will get rewritten later (ie, the TOC)
s.write(4, "tqt\0");
s.write(mVersion);
s.write(mTreeDepth);
s.write(mTileSize);
s->write(4, "tqt\0");
s->write(mVersion);
s->write(mTreeDepth);
s->write(mTileSize);

U32 tocOffset = s.getPosition();
U32 tocOffset = s->getPosition();

s.write(sizeof(mOffsets[0]) * mOffsets.size(), mOffsets.address());
s->write(sizeof(mOffsets[0]) * mOffsets.size(), mOffsets.address());

// Ok, copy everything from the children.
copy(tqt00, s, 0, Point2I(0, 0), 1, Point2I(0, 0));
Expand All @@ -469,12 +469,12 @@ void AtlasTQTFile::merge(AtlasTQTFile* tqt00, AtlasTQTFile* tqt01, AtlasTQTFile*
generateInnerTiles(s);

// Update the TOC.
s.setPosition(tocOffset);
s->setPosition(tocOffset);
for (S32 i = 0; i < mOffsets.size(); i++)
s.write(mOffsets[i]);
s->write(mOffsets[i]);

// Finally, close up.
s.close();
delete s;
}

void AtlasTQTFile::createTQT(const char* sourceImage, const char* outputTQT, U32 treeDepth, U32 tileSize)
Expand Down Expand Up @@ -511,22 +511,22 @@ void AtlasTQTFile::createTQT(const char* sourceImage, const char* outputTQT, U32
dMemset(mOffsets.address(), 0, sizeof(mOffsets[0]) * mOffsets.size());

// Open the file for output.
FileStream s;
Stream* s;
if (!ResourceManager->openFileForWrite(s, outputTQT, File::ReadWrite))
{
Con::errorf("AtlasTQTFile::createTQT - could not open '%s' for generation (read AND write).", outputTQT);
return;
}

// Write a header. Some parts of this will get rewritten later (ie, the TOC)
s.write(4, "tqt\0");
s.write(mVersion);
s.write(mTreeDepth);
s.write(mTileSize);
s->write(4, "tqt\0");
s->write(mVersion);
s->write(mTreeDepth);
s->write(mTileSize);

U32 tocOffset = s.getPosition();
U32 tocOffset = s->getPosition();

s.write(sizeof(mOffsets[0]) * mOffsets.size(), mOffsets.address());
s->write(sizeof(mOffsets[0]) * mOffsets.size(), mOffsets.address());

// Allocate space for the row working area which is equal to the height of
// a tile, and also load in the first chunk's worth of data.
Expand Down Expand Up @@ -592,14 +592,14 @@ void AtlasTQTFile::createTQT(const char* sourceImage, const char* outputTQT, U32
delete[] tileWorkspace;

// Update the TOC.
s.setPosition(tocOffset);
s->setPosition(tocOffset);
for (S32 i = 0; i < mOffsets.size(); i++)
s.write(mOffsets[i]);
s->write(mOffsets[i]);

// Finally, close the reader and the TQT file.

reader.close();
s.close();
delete s;
}


Expand Down
4 changes: 2 additions & 2 deletions engine/source/atlas/core/atlasFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool AtlasFile::createNew(const char* filename)
{
// Blank the file if it exists.
{
FileStream fs;
Stream* fs;

// Wipe it first.
if (!ResourceManager->openFileForWrite(fs, filename, File::Write))
Expand All @@ -92,7 +92,7 @@ bool AtlasFile::createNew(const char* filename)
return false;
}

fs.close();
delete fs;
}

// Initialize our stream.
Expand Down
Loading

0 comments on commit dd7fbb9

Please sign in to comment.