Moved Mars language to a separate repository. Partially refactored for the simple render pipeline. Incomplete refactor, does not build.
This commit is contained in:
parent
35cf269781
commit
1dcbcb3073
6 changed files with 20 additions and 172 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use glam::camera::lh::proj::directx::perspective;
|
|||
use wgpu::util::DeviceExt;
|
||||
use glam::prelude::*;
|
||||
|
||||
|
||||
struct Controller {
|
||||
buttons: HashMap<MouseButton,bool>,
|
||||
keys: HashMap<KeyCode,bool>,
|
||||
|
|
@ -150,9 +149,20 @@ struct SimpleMaterial {
|
|||
specular: Option<TexturePlan>,
|
||||
}
|
||||
|
||||
struct SimpleModel {
|
||||
affine: Affine3A,
|
||||
material: mars::gc::Gc<SimpleMaterial>,
|
||||
|
||||
}
|
||||
|
||||
struct SimpleRenderPlan {
|
||||
pipeline: wgpu::RenderPipeline,
|
||||
clients: Kt<SimpleMesh,Kt<SimpleMaterial,Affine3A>>
|
||||
// todo: clients: Kt<SimpleMesh,Kt<SimpleMaterial,Vec<Affine3A>>>
|
||||
clients: Vec<SimpleModel>
|
||||
}
|
||||
|
||||
struct FluidRigidBody {
|
||||
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
|
|
|
|||
|
|
@ -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<T: ?Sized + Traverse> {
|
||||
it: *mut RefCell<Header<T>>
|
||||
}
|
||||
|
||||
impl<T: ?Sized + Traverse> Clone for Gc<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Gc { it: self.it }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized + Traverse> Traverse for Gc<T> {
|
||||
fn traverse(&self) {
|
||||
self.borrow().traverse()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized + Traverse> PartialEq for Gc<T> {
|
||||
fn eq(&self, other: &Gc<T>) -> bool {
|
||||
self.it == other.it
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized + Traverse> Gc<T> {
|
||||
pub(crate) fn borrow(&self) -> impl Deref<Target=T> {
|
||||
Ref::map(unsafe { // ???
|
||||
(*self.it).borrow()
|
||||
},|it| &it.data)
|
||||
}
|
||||
pub(crate) fn borrow_mut(&self) -> impl DerefMut<Target=T> {
|
||||
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<T: ?Sized + Traverse> {
|
||||
layout: Layout,
|
||||
color: Color, // NOT for incremental tri-color right now; white == mark-free, black == mark-keep
|
||||
data: T
|
||||
}
|
||||
|
||||
pub struct Allocator {
|
||||
objects: Vec<Option<*mut RefCell<Header<dyn Traverse>>>>,
|
||||
}
|
||||
|
||||
impl Allocator {
|
||||
pub fn new() -> Allocator {
|
||||
Allocator {
|
||||
objects: Vec::new(),
|
||||
}
|
||||
}
|
||||
pub fn alloc<T: Traverse + 'static>(&mut self, it: T) -> Gc<T> {
|
||||
let layout = Layout::new::<RefCell<Header<T>>>();
|
||||
let pointer = unsafe { alloc(layout) as *mut RefCell<Header<T>> };
|
||||
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<Header<dyn Traverse>>));
|
||||
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
|
||||
()
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Gc<Table>>
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
local two
|
||||
do
|
||||
local one
|
||||
if something then
|
||||
local three
|
||||
print(something)
|
||||
end
|
||||
local four
|
||||
if something2 then
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue