Commit 95971f14 authored by Dan Sheppard's avatar Dan Sheppard
Browse files

Remove unnecessary, non-performant, awkward cache layer.

parent a90be57f
......@@ -5,26 +5,20 @@ const MAX_PENDING : i32 = 0;
const CACHE_SIZE : usize = 10;
use composit::{
ActiveSource, Leaf, Carriage, SourceSched
ActiveSource, Leaf, Carriage
};
pub struct ComponentManager {
components: HashMap<String,ActiveSource>,
source_factory: SourceSched
components: HashMap<String,ActiveSource>
}
impl ComponentManager {
pub fn new() -> ComponentManager {
ComponentManager {
components: HashMap::<String,ActiveSource>::new(),
source_factory: SourceSched::new(MAX_PENDING,CACHE_SIZE)
components: HashMap::<String,ActiveSource>::new()
}
}
pub fn tick(&mut self, t: f64) {
self.source_factory.tick(t);
}
pub fn add(&mut self, c: ActiveSource) {
let name = c.get_name().to_string();
if let Entry::Vacant(e) = self.components.entry(name) {
......@@ -38,10 +32,10 @@ impl ComponentManager {
pub fn make_comp_carriages(&mut self, c: &ActiveSource, leaf: &Leaf) -> Vec<Carriage> {
let mut lcomps = Vec::<Carriage>::new();
lcomps.push(c.make_carriage(&mut self.source_factory,&None,&leaf));
lcomps.push(c.make_carriage(&None,&leaf));
for part in c.list_parts() {
debug!("redraw","make_carriages {:?} for {}",leaf,part);
lcomps.push(c.make_carriage(&mut self.source_factory,&Some(part),&leaf));
lcomps.push(c.make_carriage(&Some(part),&leaf));
}
lcomps
}
......
......@@ -72,8 +72,6 @@ impl Compositor {
self.current_componentset = self.wanted_componentset.clone();
/* Warm up xfercache */
self.prime_cache(t);
/* Kick off requests */
self.components.tick(t);
/* Move into future */
self.train_manager.tick(t,&mut self.components);
/* Manage useful leafs */
......
......@@ -16,7 +16,7 @@ mod position;
mod wrapping;
pub use self::source::{
CombinedSource, Source, SourceResponse, SourceSched, ActiveSource,
CombinedSource, Source, SourceResponse, ActiveSource,
DrawnResponse, SourceManager, SourceManagerList, CombinedSourceManager
};
pub use self::combinedstickmanager::CombinedStickManager;
......
......@@ -7,7 +7,7 @@ use std::rc::Rc;
use composit::state::StateExpr;
use composit::{
AllLandscapes, Landscape, Source,
Carriage, Leaf, SourceSched, SourceResponse, StateManager,
Carriage, Leaf, SourceResponse, StateManager,
StateValue
};
......@@ -41,10 +41,13 @@ impl ActiveSource {
self.parts.keys().filter(|x| x.is_some()).map(|x| x.as_ref().unwrap().clone()).collect()
}
pub fn make_carriage(&self, sf: &mut SourceSched, part: &Option<String>, leaf: &Leaf) -> Carriage {
let mut out = Carriage::new(self.clone(),part,leaf);
sf.populate_carriage(&mut out);
out
pub fn make_carriage(&self, part: &Option<String>, leaf: &Leaf) -> Carriage {
let mut c = Carriage::new(self.clone(),part,leaf);
let mut source = c.get_source().clone();
let mut resp = SourceResponse::new(source.get_name(),&source.list_parts());
source.populate(&mut resp,c.get_leaf());
c.set_response(resp);
c
}
pub fn populate(&mut self, resp: &mut SourceResponse, leaf: &Leaf) {
......
......@@ -7,7 +7,6 @@ use print::Programs;
use shape::{ ShapeSpec, Shape };
pub struct DrawnResponse {
shapes: Option<Vec<ShapeSpec>>,
drawings: Vec<Option<Drawing>>,
sr: SourceResponse,
part: Option<String>
......@@ -17,29 +16,24 @@ impl DrawnResponse {
pub fn new(sr: SourceResponse, part: &Option<String>) -> DrawnResponse {
DrawnResponse {
sr,
shapes: None,
drawings: Vec::<Option<Drawing>>::new(),
part: part.clone()
}
}
fn populate(&mut self) {
let specs = self.sr.get_shapes(&self.part);
self.shapes = Some(specs);
fn shapes(&self) -> Vec<ShapeSpec> {
self.sr.get_shapes(&self.part)
}
#[allow(unused)]
pub fn size(&self) -> usize { self.shapes.as_ref().unwrap().len() }
pub fn size(&self) -> usize { self.shapes().len() }
pub fn is_done(&self) -> bool { self.sr.is_done() }
pub fn redraw(&mut self, ds: &mut DrawingSession) {
if self.sr.is_done() {
if self.shapes.is_none() {
self.populate();
}
self.drawings.clear();
for mut s in self.shapes.as_mut().unwrap().iter_mut() {
for mut s in self.shapes() {
if let Some(a) = s.get_artist() {
let ocm = a.select_canvas(ds);
self.drawings.push(Some(ocm.add_request(a)));
......@@ -53,11 +47,8 @@ impl DrawnResponse {
pub fn into_objects(&mut self, progs: &mut Programs,
ds: &mut DrawingSession, e: &mut PrintEdition) {
if self.sr.is_done() {
if self.shapes.is_none() {
self.populate();
}
let mut di = self.drawings.iter();
for mut s in self.shapes.as_mut().unwrap().iter_mut() {
for mut s in self.shapes().iter() {
let d = di.next();
let geom_name = s.get_geometry();
if let Some(geom) = progs.map.get_mut(&geom_name) {
......
......@@ -6,14 +6,12 @@ mod source;
mod sourcemanager;
mod sourcemanagerlist;
mod sourcepart;
mod sourcesched;
mod sourceresponse;
pub use self::activesource::ActiveSource;
pub use self::combinedsource::{ CombinedSource, build_combined_source };
pub use self::combinedsourcemanager::CombinedSourceManager;
pub use self::source::Source;
pub use self::sourcesched::SourceSched;
pub use self::sourcemanager::SourceManager;
pub use self::sourcemanagerlist::SourceManagerList;
pub use self::sourcepart::SourcePart;
......
use std::collections::HashMap;
use composit::{ Carriage, SourceResponse, ActiveSource, Leaf };
use util::Cache;
pub struct SourceSched {
max_pending: i32,
cache: Cache<(ActiveSource,Leaf),SourceResponse>,
queued: Vec<(ActiveSource,Leaf,SourceResponse)>,
pending: HashMap<(ActiveSource,Leaf),SourceResponse>
}
impl SourceSched {
pub fn new(max_pending: i32, cache_size: usize) -> SourceSched {
SourceSched {
max_pending,
cache: Cache::<(ActiveSource,Leaf),SourceResponse>::new(cache_size),
queued: Vec::<(ActiveSource,Leaf,SourceResponse)>::new(),
pending: HashMap::<(ActiveSource,Leaf),SourceResponse>::new()
}
}
fn run_queue(&mut self) {
while self.queued.len() > 0 && (self.pending.len() < self.max_pending as usize || self.max_pending == 0) {
let (mut source,leaf,mut resp) = self.queued.remove(0);
debug!("sources","start {:?}:{:?}",source,leaf);
self.pending.insert((source.clone(),leaf.clone()),resp.clone());
source.populate(&mut resp,&leaf);
}
}
fn remove_finished(&mut self) {
let mut togo = Vec::<(ActiveSource,Leaf)>::new();
for (k,r) in &self.pending {
if r.is_done() {
debug!("sources","end {:?}",k,);
togo.push(k.clone());
}
}
for k in togo {
self.pending.remove(&k);
}
self.run_queue();
}
pub fn tick(&mut self, _t: f64) {
self.remove_finished();
}
pub fn populate_carriage(&mut self, c: &mut Carriage) {
let resp = {
let source = c.get_source();
let key = (source.clone(),c.get_leaf().clone());
if let Some(resp) = self.cache.get(&key) {
debug!("sources","cache {:?} [{}]",c,resp.size());
resp
} else {
let mut resp = SourceResponse::new(source.get_name(),&source.list_parts());
debug!("sources","queue {:?}",c);
self.queued.push((source.clone(),c.get_leaf().clone(),resp.clone()));
self.run_queue();
self.cache.put(&key,resp.clone());
resp
}
};
c.set_response(resp.clone());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment