Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unifying the filesystem interface (eg. no more check) #706

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

FalseIlyu
Copy link
Contributor

@FalseIlyu FalseIlyu commented Apr 5, 2024

The purpose of this PR is to remove the need of checking what type of filesystem to use before reading a file either at compile type (as we have currently to handle android) or at runtime (as proposed in #673).

It divides responsibility as follows :

  • Parsers get data from a stream and build game asset from it.
  • The filesystem look for the data and organise it as a istream.
  • The stream handles direct access to the data.

As a first draft i moved void ReadFile(std::istream& stream) in all parsers from a private to a public method.
Added a std::unique_ptr<std::istream> GetData(const std::filesystem::path& path) as the method to ask access to data from the filesystem.
Replaced place where we had to choose between Open(Locator::filesystem::value().ReadAll(path)); and Open(path) with ReadFile(*Locator::filesystem::value().GetData(path));
Copied the membuf from the component into android and made it own a copy of the file data (mostly a lazy way to ensure the data was there while being read by the buffer) i also allowed it to be initialized by a vector of byte.

I propose this as draft as i wish to have comment about change that would be necessary or better to implement this (and if such a change is agreeable). Once/while implementation detail are discussed apps and parsers still need to be changed before this gets ready for merge (removing the possibility to read file from parsers and the implied changes it will need on apps).

This would replace #673 if merged before. I didn't look if it would be a pain to modify #674 to make it work with the changes brought here if it is merging #674 should take priority and this PR should be responsible to make it work (tbc i presume it means i will do it).

This PR has been tested by launching the game on an android emulator and windows (both x86_64).

src/FileSystem/AndroidFileSystem.cpp Outdated Show resolved Hide resolved
src/FileSystem/AndroidFileSystem.cpp Outdated Show resolved Hide resolved
@FalseIlyu FalseIlyu force-pushed the unified-filesystem branch 3 times, most recently from 1b28ea7 to 496fa82 Compare April 5, 2024 20:03
@bwrsandman
Copy link
Member

I'm not sure why the Files in components are virtual. They should not be.
Another thing I'm worried about is language binding. The original intent of splitting off file loading code was they they would be easier to call from C code and to make language bindings. We shouldn't lose sight of this.

@FalseIlyu
Copy link
Contributor Author

FalseIlyu commented Apr 6, 2024

Another thing I'm worried about is language binding. The original intent of splitting off file loading code was they they would be easier to call from C code and to make language bindings. We shouldn't lose sight of this.

This mostly concerns components, no ? Because in this case nothing really force us to remove the void Open method and use this in engine to make thing more straightforward for use (with the idea that with the actual file reading decoupled from the filesystem it is going to make it easier to test thing when we actually go forth with looking performance issue). Even in the case of the filesystem we can keep the readAll method accessible as something easier to work with from C (as for the moment we use it to build the stream in Android and i don't see it being not usefull to us in any case, it would just mean keeping it public).

Copy link
Contributor

github-actions bot commented Apr 23, 2024

Uploaded images

Map Debug Release Vanilla
Land1.txt Land1 Debug Land1 Release Land1 Vanilla
Land2.txt Land2 Debug Land2 Release Land2 Vanilla
Land3.txt Land3 Debug Land3 Release Land3 Vanilla
Land4.txt Land4 Debug Land4 Release Land4 Vanilla
Land5.txt Land5 Debug Land5 Release Land5 Vanilla
LandT.txt LandT Debug LandT Release LandT Vanilla
TwoGods.txt TwoGods Debug TwoGods Release TwoGods Vanilla
ThreeGods.txt ThreeGods Debug ThreeGods Release ThreeGods Vanilla
FourGods.txt FourGods Debug FourGods Release FourGods Vanilla
construct.txt Construct Debug Construct Release construct Vanilla

@bwrsandman
Copy link
Member

If you rebase, the tests will pass

@github-actions github-actions bot added the merge-conflicts PR cannot be merged until it is rebased label May 21, 2024
@github-actions github-actions bot removed the merge-conflicts PR cannot be merged until it is rebased label May 23, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

components/anm/include/ANMFile.h Show resolved Hide resolved
components/l3d/include/L3DFile.h Show resolved Hide resolved
components/lnd/include/LNDFile.h Show resolved Hide resolved
src/3D/L3DAnim.cpp Show resolved Hide resolved
src/3D/L3DAnim.cpp Show resolved Hide resolved
src/FileSystem/DefaultFileSystem.cpp Show resolved Hide resolved
src/FileSystem/DefaultFileSystem.cpp Show resolved Hide resolved
src/FileSystem/DefaultFileSystem.h Show resolved Hide resolved
src/FileSystem/FileSystemInterface.h Show resolved Hide resolved
src/FileSystem/FileSystemInterface.h Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants