Crates.io | bevy_double_res |
lib.rs | bevy_double_res |
version | 0.1.0 |
source | src |
created_at | 2022-09-03 09:29:41.143609 |
updated_at | 2022-09-03 09:29:41.143609 |
description | Straightforward double buffering implementation for bevy resources |
homepage | https://github.com/necromfox/bevy_double_res |
repository | https://github.com/necromfox/bevy_double_res |
max_upload_size | |
id | 657810 |
size | 98,886 |
Straightforward implementation of double buffering of ordinary bevy engine resources
First, create your buffer:
fn main() {
use bevy_double_res::prelude::*;
let mut tuple = (10, 20).into_double_buf();
//...
}
or
fn main() {
use bevy_double_res::prelude::*;
let mut tuple = DoubleBuffer::new((10, 20));
//...
}
Second, mutate items:
fn main() {
//...
tuple.apply(|current, next| {
next.0 = current.1;
next.1 = current.0;
});
tuple.swap();
//...
}
or
fn main() {
//...
let (current, next) = tuple.split_ordered();
next.0 = current.1;
next.1 = current.0;
tuple.swap();
//...
}
Don't forget about the swap!
Last, display contents of your buffer:
fn main() {
use bevy_double_res::prelude::*;
let mut tuple = (10, 20).into_double_buf();
tuple.apply(|current, next| {
next.0 = current.1;
next.1 = current.0;
});
tuple.swap();
println!("{:?}", tuple.current()); // outputs: (20, 10)
}
Creating resource is the same:
fn setup(mut commands: Commands) {
let tuple = (10, 20).into_double_buf();
commands.insert_resource(tuple);
}
Accessing resource in systems:
fn circular_dependent_system(mut tuple: DoubleResMut<(i32, i32)>) {
tuple.apply(|current, next| {
next.0 = current.1;
next.1 = current.0;
});
tuple.swap();
}
Also see an example of usage