AbstractMeasurement: remove the DynClone requirement

This commit is contained in:
2022-07-28 21:49:28 -07:00
parent 3722512554
commit 2d1a15eabc
2 changed files with 7 additions and 11 deletions

View File

@@ -28,7 +28,7 @@ pub struct Driver<S> {
time_spent_prepping_render: Duration, time_spent_prepping_render: Duration,
time_spent_blocked_on_render: Duration, time_spent_blocked_on_render: Duration,
time_spent_rendering: Arc<Mutex<Duration>>, time_spent_rendering: Arc<Mutex<Duration>>,
measurements: Vec<Box<dyn AbstractMeasurement>>, measurements: Vec<Arc<dyn AbstractMeasurement>>,
stimuli: StimuliAdapter, stimuli: StimuliAdapter,
start_time: Instant, start_time: Instant,
last_diag_time: Instant, last_diag_time: Instant,
@@ -49,10 +49,10 @@ impl<S> Driver<S> {
time_spent_blocked_on_render: Default::default(), time_spent_blocked_on_render: Default::default(),
time_spent_rendering: Default::default(), time_spent_rendering: Default::default(),
measurements: vec![ measurements: vec![
Box::new(meas::Time), Arc::new(meas::Time),
Box::new(meas::Meta), Arc::new(meas::Meta),
Box::new(meas::Energy::world()), Arc::new(meas::Energy::world()),
Box::new(meas::Power::world()), Arc::new(meas::Power::world()),
], ],
stimuli: StimuliAdapter::new(), stimuli: StimuliAdapter::new(),
start_time: Instant::now(), start_time: Instant::now(),
@@ -66,7 +66,7 @@ impl<S> Driver<S> {
} }
pub fn add_measurement<Meas: AbstractMeasurement + 'static>(&mut self, m: Meas) { pub fn add_measurement<Meas: AbstractMeasurement + 'static>(&mut self, m: Meas) {
self.measurements.push(Box::new(m)); self.measurements.push(Arc::new(m));
} }
pub fn set_steps_per_stim(&mut self, steps_per_stim: u64) { pub fn set_steps_per_stim(&mut self, steps_per_stim: u64) {

View File

@@ -2,17 +2,13 @@ use crate::geom::{Meters, Region, Torus, WorldRegion};
use crate::real::{Real as _, ToFloat as _}; use crate::real::{Real as _, ToFloat as _};
use crate::cross::vec::Vec3; use crate::cross::vec::Vec3;
use crate::sim::GenericSim; use crate::sim::GenericSim;
use dyn_clone::{self, DynClone};
use indexmap::IndexMap; use indexmap::IndexMap;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
// TODO: remove this Clone and Send requirement? Have Measurements be shared by-reference across pub trait AbstractMeasurement: Send + Sync {
// threads? i.e. Sync, and no Clone
pub trait AbstractMeasurement: Send + Sync + DynClone {
fn eval(&self, state: &dyn GenericSim) -> String; fn eval(&self, state: &dyn GenericSim) -> String;
fn key_value(&self, state: &dyn GenericSim) -> IndexMap<String, String>; fn key_value(&self, state: &dyn GenericSim) -> IndexMap<String, String>;
} }
dyn_clone::clone_trait_object!(AbstractMeasurement);
/// create one IndexMap out of several measurements /// create one IndexMap out of several measurements
pub fn eval_multiple_kv(state: &dyn GenericSim, meas: &[&dyn AbstractMeasurement]) -> IndexMap<String, String> { pub fn eval_multiple_kv(state: &dyn GenericSim, meas: &[&dyn AbstractMeasurement]) -> IndexMap<String, String> {