diff options
Diffstat (limited to 'core/src/runtime.rs')
-rw-r--r-- | core/src/runtime.rs | 107 |
1 files changed, 24 insertions, 83 deletions
diff --git a/core/src/runtime.rs b/core/src/runtime.rs index 6b1b5d1..5fd17e9 100644 --- a/core/src/runtime.rs +++ b/core/src/runtime.rs | |||
@@ -1,11 +1,11 @@ | |||
1 | use crate::core_shapes::CoreDrawable; | 1 | use crate::{ |
2 | use crate::rendering::Render; | 2 | core_shapes::CoreDrawable, |
3 | use crate::types::Bounds; | 3 | rendering::{Render, Renderer}, |
4 | 4 | solving::{Constrainable, SolverContext}, | |
5 | // use super::complex_shapes::{ComplexShape, Drawable}; | 5 | types::Bounds, |
6 | use super::rendering::Renderer; | 6 | }; |
7 | use super::solving::{Constrainable, SolverContext}; | ||
8 | 7 | ||
8 | // TODO: | ||
9 | // const RECURSION_LIMIT: u64 = 10_000; | 9 | // const RECURSION_LIMIT: u64 = 10_000; |
10 | 10 | ||
11 | pub struct Runtime<'a> { | 11 | pub struct Runtime<'a> { |
@@ -20,15 +20,10 @@ impl<'a> Runtime<'a> { | |||
20 | Self { | 20 | Self { |
21 | solver_ctx, | 21 | solver_ctx, |
22 | renderer, | 22 | renderer, |
23 | // drawables: Vec::new(), | ||
24 | drawables: Vec::new(), | 23 | drawables: Vec::new(), |
25 | } | 24 | } |
26 | } | 25 | } |
27 | 26 | ||
28 | // pub fn add_drawable<T: ComplexShape + 'static>(&mut self, drawable: Drawable<T>) { | ||
29 | // self.drawables.push(drawable.into()) | ||
30 | // } | ||
31 | |||
32 | pub fn add_drawable(&mut self, drawable: CoreDrawable) { | 27 | pub fn add_drawable(&mut self, drawable: CoreDrawable) { |
33 | self.drawables.push(drawable) | 28 | self.drawables.push(drawable) |
34 | } | 29 | } |
@@ -41,88 +36,34 @@ impl<'a> Runtime<'a> { | |||
41 | &mut *self.renderer | 36 | &mut *self.renderer |
42 | } | 37 | } |
43 | 38 | ||
44 | pub fn render(mut self, bounds: Bounds) { | 39 | pub fn render(self, bounds: Bounds) { |
45 | let model = self.solver_ctx.solve(); | 40 | // Separate self into several variables, so we can get mutable references to each at the |
41 | // same time | ||
42 | let Runtime { | ||
43 | mut solver_ctx, | ||
44 | mut renderer, | ||
45 | drawables, | ||
46 | } = self; | ||
47 | |||
48 | for drawable in &drawables { | ||
49 | drawable.inherent_constraints(&mut *solver_ctx, &mut *renderer); | ||
50 | } | ||
51 | |||
52 | let model = solver_ctx.solve(); | ||
46 | 53 | ||
47 | let bounds = bounds | 54 | let bounds = bounds |
48 | .fixate(&*model) | 55 | .fixate(&*model) |
49 | .expect("Could not fixate figure bounds"); | 56 | .expect("Could not fixate figure bounds"); |
50 | 57 | ||
51 | self.renderer.set_size(bounds.width, bounds.height); | 58 | renderer.set_size(bounds.width, bounds.height); |
52 | 59 | ||
53 | for drawable in &self.drawables { | 60 | for drawable in &drawables { |
54 | let defined_drawable = drawable | 61 | let defined_drawable = drawable |
55 | .fixate(&*model) | 62 | .fixate(&*model) |
56 | .expect("Could not fixate core shape"); | 63 | .expect("Could not fixate core shape"); |
57 | defined_drawable | 64 | defined_drawable |
58 | .shape | 65 | .shape |
59 | .render(defined_drawable.context, &mut *self.renderer); | 66 | .render(defined_drawable.context, &mut *renderer); |
60 | } | 67 | } |
61 | } | 68 | } |
62 | |||
63 | // TODO: preserve ordering of shapes | ||
64 | // pub fn render(mut self) { | ||
65 | // let mut drawables = self.drawables; | ||
66 | // let mut waited_on_variables = Vec::new(); | ||
67 | // let mut core_shapes = Vec::new(); | ||
68 | // | ||
69 | // /* | ||
70 | // for drawable in &self.shapes { | ||
71 | // let bounds = &drawable.bounds; | ||
72 | // let shape = &drawable.shape; | ||
73 | // | ||
74 | // if let Some(core_shape) = shape.to_render() { | ||
75 | // drawables.push((*drawable).clone()); | ||
76 | // continue; | ||
77 | // } | ||
78 | // | ||
79 | // let mut result = shape.draw(bounds); | ||
80 | // drawables.append(&mut result.subshapes); | ||
81 | // waited_on_variables.append(&mut result.waiting_on); | ||
82 | // } | ||
83 | // */ | ||
84 | // | ||
85 | // let mut recursion_count = 0; | ||
86 | // | ||
87 | // while !drawables.is_empty() { | ||
88 | // recursion_count += 1; | ||
89 | // | ||
90 | // if recursion_count > RECURSION_LIMIT { | ||
91 | // panic!("Recursion limit reached"); | ||
92 | // } | ||
93 | // | ||
94 | // let mut tmp_drawables = Vec::new(); | ||
95 | // | ||
96 | // for drawable in drawables.drain(..) { | ||
97 | // let shape_ctx = &drawable.context; | ||
98 | // let shape = &drawable.shape; | ||
99 | // | ||
100 | // if let Some(core_shape) = shape.as_core_shape() { | ||
101 | // core_shape.constrain(shape_ctx, &mut *self.solver_ctx, &*self.renderer); | ||
102 | // core_shapes.push((shape.dyn_clone(), shape_ctx.clone())); // Better to Arc? Cow? | ||
103 | // continue; | ||
104 | // } | ||
105 | // | ||
106 | // let mut result = shape.draw(shape_ctx, &mut *self.solver_ctx); | ||
107 | // tmp_drawables.append(&mut result.subshapes); | ||
108 | // waited_on_variables.append(&mut result.waiting_on); | ||
109 | // } | ||
110 | // | ||
111 | // drawables = tmp_drawables; | ||
112 | // } | ||
113 | // | ||
114 | // let model = self.solver_ctx.solve(); | ||
115 | // | ||
116 | // // Delay rendering core shapes until later to have all the constraints | ||
117 | // for (core_shape, shape_ctx) in core_shapes { | ||
118 | // let core_shape = core_shape.as_core_shape().unwrap(); | ||
119 | // | ||
120 | // match (core_shape.to_render(&*model), shape_ctx.fixate(&*model)) { | ||
121 | // (Some(defined_shape), Some(shape_ctx)) => { | ||
122 | // defined_shape.render(shape_ctx, &mut *self.renderer) | ||
123 | // } | ||
124 | // _ => panic!("Failed to fixate core shape"), | ||
125 | // } | ||
126 | // } | ||
127 | // } | ||
128 | } | 69 | } |