amethyst / amethyst/rfcs

Loader/Asset API Ergonomics

Aperta
#15 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
32
Fork
10
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.