From 1dcbcb3073406d84742197e43059dc1086208612 Mon Sep 17 00:00:00 2001 From: paladin Date: Wed, 19 Aug 2026 23:43:47 +0100 Subject: [PATCH] Moved Mars language to a separate repository. Partially refactored for the simple render pipeline. Incomplete refactor, does not build. --- Cargo.lock | 9 ++- Cargo.toml | 1 + src/engine.rs | 14 ++++- src/lang/src/gc.rs | 108 ---------------------------------- src/lang/src/table.rs | 48 --------------- src/lang/src/tests/script.lua | 12 ---- 6 files changed, 20 insertions(+), 172 deletions(-) delete mode 100644 src/lang/src/gc.rs delete mode 100644 src/lang/src/table.rs delete mode 100644 src/lang/src/tests/script.lua diff --git a/Cargo.lock b/Cargo.lock index 2cc386c..ce454a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -628,6 +628,7 @@ dependencies = [ "glam", "image", "log", + "mars", "pollster", "wasm-bindgen", "wasm-bindgen-futures", @@ -1003,9 +1004,13 @@ dependencies = [ [[package]] name = "log" -version = "0.4.29" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "mars" +version = "0.1.0" [[package]] name = "memchr" diff --git a/Cargo.toml b/Cargo.toml index 3eb3455..b6eda9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ glam = { version = "0.33.3", features = [ "bytemuck" ] } console_error_panic_hook = "0.1.7" bytemuck = { version = "1.25.0", features = [ "derive" ]} image = { version = "0.24", default-features = false, features = ["png", "jpeg"]} +mars = { path = "../Mars" } [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1.6" diff --git a/src/engine.rs b/src/engine.rs index de79301..a4a625a 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -5,7 +5,6 @@ use glam::camera::lh::proj::directx::perspective; use wgpu::util::DeviceExt; use glam::prelude::*; - struct Controller { buttons: HashMap, keys: HashMap, @@ -150,9 +149,20 @@ struct SimpleMaterial { specular: Option, } +struct SimpleModel { + affine: Affine3A, + material: mars::gc::Gc, + +} + struct SimpleRenderPlan { pipeline: wgpu::RenderPipeline, - clients: Kt> + // todo: clients: Kt>> + clients: Vec +} + +struct FluidRigidBody { + } pub struct State { diff --git a/src/lang/src/gc.rs b/src/lang/src/gc.rs deleted file mode 100644 index d909bd7..0000000 --- a/src/lang/src/gc.rs +++ /dev/null @@ -1,108 +0,0 @@ -use std::alloc::{alloc, dealloc, Layout}; -use std::any::Any; -use std::cell::{Ref, RefCell, RefMut}; -use std::fmt::Debug; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; - -#[derive(Debug)] -pub struct Gc { - it: *mut RefCell> -} - -impl Clone for Gc { - fn clone(&self) -> Self { - Gc { it: self.it } - } -} - -impl Traverse for Gc { - fn traverse(&self) { - self.borrow().traverse() - } -} - -impl PartialEq for Gc { - fn eq(&self, other: &Gc) -> bool { - self.it == other.it - } -} - -impl Gc { - pub(crate) fn borrow(&self) -> impl Deref { - Ref::map(unsafe { // ??? - (*self.it).borrow() - },|it| &it.data) - } - pub(crate) fn borrow_mut(&self) -> impl DerefMut { - RefMut::map(unsafe { - (*self.it).borrow_mut() - },|it| &mut it.data) - } -} - -#[derive(Clone, Debug, Copy)] -enum Color { - White, - Black, -} - -#[repr(C)] // Trying to access everything but `item: T` while not knowing what T is... -struct Header { - layout: Layout, - color: Color, // NOT for incremental tri-color right now; white == mark-free, black == mark-keep - data: T -} - -pub struct Allocator { - objects: Vec>>>, -} - -impl Allocator { - pub fn new() -> Allocator { - Allocator { - objects: Vec::new(), - } - } - pub fn alloc(&mut self, it: T) -> Gc { - let layout = Layout::new::>>(); - let pointer = unsafe { alloc(layout) as *mut RefCell> }; - let mut header = unsafe { pointer.as_mut() }.unwrap().borrow_mut(); - header.layout = layout; - header.color = Color::Black; - header.data = it; - self.objects.push(Some(pointer as *mut RefCell>)); - Gc { - it: pointer, - } - } - fn mark_white(&mut self) { - for i in 0..self.objects.len() { - if let Some(object) = self.objects[i] { - unsafe { (*object).borrow_mut().color = Color::White }; - } - } - } - fn collect(&mut self) { - self.objects.retain(|object| { - if let Some(object) = object { - let header = unsafe { (**object).borrow_mut() }; - match header.color { - Color::White => { - unsafe { dealloc(*object as *mut u8,header.layout); } - true - } - Color::Black => false - } - } else { - false - } - }); - } -} - -pub trait Traverse: Any + Debug { - fn traverse(&self) { // mark or grey - () - } -} \ No newline at end of file diff --git a/src/lang/src/table.rs b/src/lang/src/table.rs deleted file mode 100644 index 569eb2a..0000000 --- a/src/lang/src/table.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::alloc::{alloc, Layout}; -use std::collections::HashMap; -use std::ptr::null_mut; -use crate::gc::{Gc, Traverse}; -use crate::Value; - -#[derive(Debug, Clone)] -pub struct Table { - table: (*mut [(Value, Value)],usize,usize), - array: (*mut [Value],usize,usize), - meta: Option> -} - -impl Traverse for Table { - fn traverse(&self) { - unsafe { - if let Some(table) = self.table.0.as_ref() { - for (index,item) in table.iter() { - if !matches!(index,Value::Nil) { - index.traverse(); - item.traverse(); - } - } - } - if let Some(array) = self.array.0.as_ref() { - for item in array.iter() { - item.traverse(); - } - } - } - } -} - -impl Table { - pub fn set(index: Value, item: Value) { - - } - pub fn get(index: Value) { - - } - pub fn new() -> Self { - Table { - table: (null_mut::<[(Value,Value)]>().into(),0,0), - array: (null_mut().into(),0,0), - meta: None - } - } -} \ No newline at end of file diff --git a/src/lang/src/tests/script.lua b/src/lang/src/tests/script.lua deleted file mode 100644 index 73a6987..0000000 --- a/src/lang/src/tests/script.lua +++ /dev/null @@ -1,12 +0,0 @@ -local two -do - local one - if something then - local three - print(something) - end - local four - if something2 then - - end -end \ No newline at end of file