-
-
Save stevenblenkinsop/58a1318777467a5a25c8 to your computer and use it in GitHub Desktop.
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 &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