From 483b1a2238edf41537681f797c4fce1212b992b4 Mon Sep 17 00:00:00 2001 From: Micha White Date: Sun, 29 Jan 2023 15:43:58 -0500 Subject: Optimize bunnymark --- alligator_render/examples/bunnymark.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'alligator_render/examples/bunnymark.rs') diff --git a/alligator_render/examples/bunnymark.rs b/alligator_render/examples/bunnymark.rs index 62371c9..4fe37d3 100644 --- a/alligator_render/examples/bunnymark.rs +++ b/alligator_render/examples/bunnymark.rs @@ -4,11 +4,26 @@ use alligator_render::{ ImageFormat, Instance, InstanceId, RenderWindowConfig, Renderer, TextureId, }; +fn xorshift_plus(seed: &mut [u64; 2]) -> u64 { + let mut t = seed[0]; + let s = seed[1]; + + t ^= t << 23; + t ^= t >> 18; + t ^= s ^ (s >> 5); + + seed[0] = s; + seed[1] = t; + + t + s +} + #[derive(Debug)] struct State { texture_id: TextureId, bunnies: Vec, previous_timestamp: Option, + seed: [u64; 2], stopped: bool, } @@ -18,6 +33,7 @@ impl State { texture_id, bunnies: Vec::with_capacity(10_000_000), previous_timestamp: None, + seed: [0x0D15EA5E8BADF00D, 0xDECAFBADDEADBEAF], stopped: false, } } @@ -78,13 +94,13 @@ impl State { let instance_id = renderer.instances_mut().push_instance(Instance { texture_coordinates: [texture_x, texture_y], texture_size: [texture_width, texture_height], - size: [0.1, 0.1], + size: [0.08, 0.08], position: [-1.5, 0.70], ..Default::default() }); - let velocity_x = fps.fract() / 24.0; - let velocity_y = 0.0; + let velocity_x = (xorshift_plus(&mut self.seed) % 1_000_000) as f32 / 25_000_000.0; + let velocity_y = (xorshift_plus(&mut self.seed) % 1_000_000) as f32 / 25_000_000.0; self.bunnies.push(Bunny { instance_id, velocity_x, -- cgit v1.2.3