amethyst / amethyst/rfcs

Loader/Asset API Ergonomics

Offen
#15 9 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Keine Sprachdaten
Sterne
32
Forks
10
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

The current loader API is (subjectively) a little heavy.

For example, to load a GLTF file:
```rust
let loader = world.read_resource();
let progress = ();
let format = GltfSceneFormat;
let options = Default::default();
let storage = &world.read_resource();

let asset = loader.load("path/to/gltf.gltf", GltfSceneFormat, options, progress, storage);
```

And to load a GLTF file from a custom source:
```rust
let loader = world.read_resource();
let progress = ();
let format = GltfSceneFormat;
let options = Default::default();
let source = /*...*/;
let storage = &world.read_resource();

let asset = loader.load_from("path/to/gltf.gltf", GltfSceneFormat, options, source, progress, storage);
```

I think this API could be made slightly cleaner by doing (any subset of) a few things:
- Dynamically dispatch on the resource URL to determine the source and format (maybe integrating with the `vnodes` system)
- Put the storages within the Loader / give the Loader some way to get handles to the storages, so that the user doesn't have to
- Use the builder pattern

Then, a simple asset load can look like just:
```rust
let asset = loader.asset("/io/assets/path/to/texture.png").load();
```

And a complex load can look like:
```rust
let asset = loader
.asset("/io/assets/special_source/path_to_scene.gltf")
.progress(progress_counter)
.options(GltfSceneOptions { /* ... */ })
.custom_storage(custom_storage) // not sure if this would be needed
.load();
```

Since loading assets is something that you do a lot, I think it's worth it to make the API nice to use.

Downsides:
- Makes things slightly more prone to runtime errors (can have file-type mismatches)
- Gives Loader more responsibilities

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.