-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
info about data access and state of resources
- Loading branch information
Showing
4 changed files
with
128 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod custom; | ||
pub mod model; | ||
pub mod sound; | ||
pub mod state; | ||
|
||
use fyrox::{ | ||
asset::manager::ResourceManager, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use fyrox::asset::Resource; | ||
use fyrox::core::futures; | ||
use fyrox::resource::texture::{ | ||
CompressionOptions, Texture, TextureImportOptions, TextureMinificationFilter, TextureResource, | ||
TextureResourceExtension, | ||
}; | ||
|
||
// ANCHOR: checked_access | ||
fn checked_access(texture_resource: &Resource<Texture>) { | ||
let mut state = texture_resource.state(); | ||
if let Some(texture) = state.data() { | ||
println!("Kind: {:?}", texture.kind()); | ||
} | ||
} | ||
// ANCHOR_END: checked_access | ||
|
||
// ANCHOR: unchecked_access | ||
fn unchecked_access(texture_resource: &Resource<Texture>) { | ||
let texture = texture_resource.data_ref(); | ||
println!("Kind: {:?}", texture.kind()); | ||
} | ||
// ANCHOR_END: unchecked_access | ||
|
||
// ANCHOR: await_resource | ||
async fn await_resource(texture_resource: Resource<Texture>) { | ||
if let Ok(result) = texture_resource.await { | ||
// `data_ref` will never panic after the above check. | ||
let texture = result.data_ref(); | ||
println!("Kind: {:?}", texture.kind()); | ||
}; | ||
} | ||
// ANCHOR_END: await_resource | ||
|
||
// ANCHOR: block_and_wait | ||
fn block_and_wait(texture_resource: Resource<Texture>) { | ||
// Block the current thread and wait until the resource is loaded. | ||
if let Ok(result) = futures::executor::block_on(texture_resource) { | ||
// `data_ref` will never panic after the above check. | ||
let texture = result.data_ref(); | ||
println!("Kind: {:?}", texture.kind()); | ||
}; | ||
} | ||
// ANCHOR_END: block_and_wait | ||
|
||
// ANCHOR: embedded_resource | ||
fn embedded_resource() -> Option<Resource<Texture>> { | ||
let data = include_bytes!("texture.png"); | ||
TextureResource::load_from_memory( | ||
Default::default(), | ||
data, | ||
TextureImportOptions::default() | ||
.with_compression(CompressionOptions::NoCompression) | ||
.with_minification_filter(TextureMinificationFilter::Linear), | ||
) | ||
.ok() | ||
} | ||
// ANCHOR_END: embedded_resource |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters