-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Consistent AssetPath Format #10511
Comments
Windows supports both paths separators since Windows 7 IIRC. For instance, even on MS-DOS, I can navigate fine using forward slash: The problem is the returned path from Win32 API, which due to naming conventions, uses backslash There are exceptions to this, mostly UNC, like:
All of these can be solved on user side, by having a mounting letter on Windows. Let's say, for some reason, I want an asset from inside my WSL, which is located at With all that being said, we probably still have to do something if we want to support paths returned from Win32 API, like when reading all files from a folder, WinAPI will use So as long Bevy new |
Internally, The approach I was contemplating was to replace both Here's how I would proceed on this:
|
@cart It's still not clear to me whether the internal representation of a path should be
Implementation-wise, |
What problem does this solve or what need does it fill?
Currently AssetPath is backed by
Path
, which is great if the goal is to support arbitrary filesystem paths across operating systems:\foo\bar
,C:\foo\bar
/foo/bar
,/mnt/c/foo/bar
However that is not the goal of AssetPath. AssetPath exists to be an opinionated "cross platform virtual asset filesystem with support for multiple arbitrary asset sources and asset labels, which serves as a unique canonical asset identifier". Ideally, you can compare two "absolute AssetPaths", and if they are not equal, they are not the same asset.
This mismatch in goals can create problems. For example, when we create AssetPaths from hot-reload events on Windows, they come in the form
\foo\bar.png
. However users tend to use/foo/bar.png
(and we encourage this pattern everywhere), which can create problems when considering paths as strings (like it did here #10500). As a cross-platform canonical path format, AssetPath has no business supporting windows-only drive letter syntax, as that location is not directly expressible on other operating systems. AssetPath already has a cross platform way to express other mounted filesystem locations (some_asset_source://
).What solution would you like?
We should build a new, consistent path abstraction for AssetPath and replace the current Path usage with that. It should support only
/
and be designed with the explicit goal of providing consistent canonical identifiers.Like the current AssetPath impl, it should avoid allocating when a
&static str
is used to construct it, and it should have true copy on write behavior (#9729).This will create a new problem: users that want to support absolute paths (ex:
C:\path\to\image.png
) can no longer directly use the default AssetSource (which is rooted at the local asset folder)). We need a way to support this, in the interest of building apps like "file editors" or loading scenes from arbitrary locations on disk.I believe this should be accomplished via a combination of two approachs:
/
on every other platform), enabling absolute paths to work by default (without the windows drive syntax).A://some/path.png
would map to the windows pathA:\some\path.png
). We could then build AssetPath::from(Path) in a way that explicitly handles windows drive syntax and converts it to the equivalent AssetPath. We could also consider building "automount" functionality that will mount windows drives when they are requested.One issue with (2) is that Bevy Asset V2 does not currently support mounting new asset sources at runtime. We'd almost certainly want to support that, as new drives can be connected at arbitrary times when an app is running.
The text was updated successfully, but these errors were encountered: