diff --git a/lib/monet/src/lib.rs b/lib/monet/src/lib.rs index 36786921..269f0007 100644 --- a/lib/monet/src/lib.rs +++ b/lib/monet/src/lib.rs @@ -129,6 +129,18 @@ impl Recipient for Renderer { }} } +#[derive(Compact, Clone)] +pub struct AddSeveralInstances {pub scene_id: usize, pub batch_id: u16, pub positions: CVec} + +impl Recipient for Renderer { + fn receive(&mut self, msg: &AddSeveralInstances) -> Fate {match *msg { + AddSeveralInstances{scene_id, batch_id, ref positions} => { + self.scenes[scene_id].batches.get_mut(&batch_id).unwrap().instances.extend_from_slice(positions); + Fate::Live + } + }} +} + #[derive(Copy, Clone)] pub struct Project2dTo3d {pub scene_id: usize, pub position_2d: P2, pub requester: ID} @@ -184,6 +196,7 @@ pub fn setup(system: &mut ActorSystem, renderer: Renderer) { system.add_unclearable_inbox::(); system.add_unclearable_inbox::(); system.add_unclearable_inbox::(); + system.add_unclearable_inbox::(); system.add_unclearable_inbox::(); system.add_unclearable_inbox::(); system.add_unclearable_inbox::(); @@ -402,6 +415,7 @@ impl RenderContext { let vertices = glium::VertexBuffer::new(&self.window, &batch.prototype.vertices).unwrap(); let indices = glium::IndexBuffer::new(&self.window, index::PrimitiveType::TrianglesList, &batch.prototype.indices).unwrap(); let instances = glium::VertexBuffer::dynamic(&self.window, batch.instances.as_slice()).unwrap(); + println!("rendering batch with {} instances", instances.len()); target.draw((&vertices, instances.per_instance().unwrap()), &indices, &self.batch_program, &uniforms, ¶ms).unwrap(); } diff --git a/src/game/lanes_and_cars/lane_rendering.rs b/src/game/lanes_and_cars/lane_rendering.rs index fd78988d..1241f327 100644 --- a/src/game/lanes_and_cars/lane_rendering.rs +++ b/src/game/lanes_and_cars/lane_rendering.rs @@ -1,5 +1,5 @@ use descartes::{Band, FiniteCurve, WithUniqueOrthogonal, Norm}; -use kay::{Actor, Individual, Recipient, RecipientAsSwarm, ActorSystem, Swarm, Fate}; +use kay::{Actor, CVec, Individual, Recipient, RecipientAsSwarm, ActorSystem, Swarm, Fate}; use monet::{Instance, Thing, Vertex}; use core::geometry::band_to_thing; use super::{Lane, TransferLane, InteractionKind}; @@ -72,24 +72,27 @@ impl Recipient for Lane { use ::monet::RenderToScene; use ::monet::AddInstance; +use ::monet::AddSeveralInstances; use ::monet::UpdateThing; impl Recipient for Lane { fn receive(&mut self, msg: &RenderToScene) -> Fate {match *msg { RenderToScene{renderer_id, scene_id} => { - for car in &self.cars { + let car_instances = self.cars.iter().map(|car| { let position2d = self.path.along(*car.position); let direction = self.path.direction_along(*car.position); - renderer_id << AddInstance{ - scene_id: scene_id, - batch_id: 0, - position: Instance{ - instance_position: [position2d.x, position2d.y, 0.0], - instance_direction: [direction.x, direction.y], - instance_color: [0.5, 0.5, 0.5] - } - }; - } + Instance{ + instance_position: [position2d.x, position2d.y, 0.0], + instance_direction: [direction.x, direction.y], + instance_color: [0.5, 0.5, 0.5] + } + }).collect::>(); + + renderer_id << AddSeveralInstances{ + scene_id: scene_id, + batch_id: 0, + positions: car_instances + }; if ! self.interactions.iter().any(|inter| match inter.kind {InteractionKind::Next{..} => true, _ => false}) { renderer_id << AddInstance{scene_id: scene_id, batch_id: 1333, position: Instance{ diff --git a/src/game/lanes_and_cars/mod.rs b/src/game/lanes_and_cars/mod.rs index 89c27e07..77d56f53 100644 --- a/src/game/lanes_and_cars/mod.rs +++ b/src/game/lanes_and_cars/mod.rs @@ -113,7 +113,7 @@ const TRAFFIC_LOGIC_THROTTLING : usize = 60; impl Recipient for Lane { fn receive(&mut self, msg: &Tick) -> Fate {match *msg{ Tick{dt, current_tick} => { - self.in_construction += dt * 40.0; + self.in_construction += dt * 400.0; let do_traffic = current_tick % TRAFFIC_LOGIC_THROTTLING == self.id().instance_id as usize % TRAFFIC_LOGIC_THROTTLING;