Skip to content

Instantly share code, notes, and snippets.

@stevenblenkinsop
Forked from anonymous/playground.rs
Last active August 29, 2015 14:24
Show Gist options
  • Save stevenblenkinsop/58a1318777467a5a25c8 to your computer and use it in GitHub Desktop.
Save stevenblenkinsop/58a1318777467a5a25c8 to your computer and use it in GitHub Desktop.
type RenderData = u32;
struct Manager {
num_entities: usize,
render_data: Vec<Option<RenderData>>
}
pub fn main() {
let mut entity_manager = Manager {
num_entities: 3,
render_data: vec![Some(5), Some(2), None]
};
// Inside my game loop...
for i in 0..entity_manager.num_entities {
match &mut entity_manager.render_data[i] { // render_data is Option<RenderData>, where RenderData is a struct containing my data...
&mut Some(ref mut data) => { // I really don't want to copy this data everywhere.
// Render the entity using my data. The data kind of needs to be modified a bit. (Make sure the Uniforms are up to date, for those interested in why)
*data += 1;
},
&mut None => (),
}
println!("{:?}", &entity_manager.render_data[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment