WIP: cross-platform
This commit is contained in:
+18
-17
@@ -34,7 +34,7 @@ struct RowRequest {
|
||||
#[wasm_bindgen]
|
||||
pub struct Core {
|
||||
data: Rc<RefCell<RenderData>>,
|
||||
gpu: Rc<RefCell<Option<Wgpu>>>,
|
||||
gpu: Wgpu,
|
||||
store: Rc<RefCell<Store>>,
|
||||
render: Rc<RenderLoop>,
|
||||
}
|
||||
@@ -42,25 +42,26 @@ pub struct Core {
|
||||
#[wasm_bindgen]
|
||||
impl Core {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(arena_bytes: u32) -> Result<Self, JsError> {
|
||||
Ok(Self {
|
||||
data: Rc::new(RefCell::new(
|
||||
RenderData::new(arena_bytes).map_err(JsError::new)?,
|
||||
)),
|
||||
gpu: Rc::new(RefCell::new(None)),
|
||||
store: Rc::new(RefCell::new(Store::default())),
|
||||
render: Rc::new(RenderLoop::new()),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn initialize(&self, canvas: web_sys::OffscreenCanvas) -> Result<(), JsError> {
|
||||
pub async fn new(arena_bytes: u32, canvas: web_sys::OffscreenCanvas) -> Result<Self, JsError> {
|
||||
let gpu = Wgpu::new(canvas)
|
||||
.await
|
||||
.map_err(|error| JsError::new(&error))?;
|
||||
*self.gpu.borrow_mut() = Some(gpu);
|
||||
self.render
|
||||
.start(self.gpu.clone(), self.store.clone(), self.data.clone());
|
||||
Ok(())
|
||||
|
||||
let render = Rc::new(RenderLoop::new());
|
||||
|
||||
let data = Rc::new(RefCell::new(
|
||||
RenderData::new(arena_bytes).map_err(JsError::new)?,
|
||||
));
|
||||
|
||||
// what does clone mean here
|
||||
render.start(&gpu, data.clone());
|
||||
|
||||
Ok(Self {
|
||||
data,
|
||||
gpu,
|
||||
store: Rc::new(RefCell::new(Store::default())),
|
||||
render,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn rows(&self) -> String {
|
||||
|
||||
Reference in New Issue
Block a user