Created
July 10, 2015 06:07
-
-
Save anonymous/a69fa5b4ae36fdcac405 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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
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 entity_manager.render_data.get_mut(i) { // render_data is Option<RenderData>, where RenderData is a struct containing my data... | |
Some(&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; | |
}, | |
_ => (), | |
} | |
println!("{:?}", &entity_manager.render_data[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment