[oden] Start messing with the script

This commit is contained in:
John Doty 2023-06-19 08:31:13 -07:00
parent 9f808cea31
commit 156b6d6691
4 changed files with 206 additions and 54 deletions

122
Cargo.lock generated
View file

@ -134,6 +134,28 @@ dependencies = [
"rustc-demangle",
]
[[package]]
name = "bindgen"
version = "0.63.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885"
dependencies = [
"bitflags 1.3.2",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"log",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn 1.0.109",
"which",
]
[[package]]
name = "bit-set"
version = "0.5.3"
@ -240,6 +262,15 @@ dependencies = [
"jobserver",
]
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -252,6 +283,17 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "clang-sys"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
dependencies = [
"glob",
"libc",
"libloading 0.7.4",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
@ -356,6 +398,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "either"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "env_logger"
version = "0.10.0"
@ -441,6 +489,12 @@ version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "glow"
version = "0.12.2"
@ -647,6 +701,12 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.144"
@ -977,11 +1037,31 @@ dependencies = [
"env_logger",
"image",
"log",
"oden-js",
"pollster",
"wgpu",
"winit",
]
[[package]]
name = "oden-js"
version = "0.1.0"
dependencies = [
"anyhow",
"bitflags 1.3.2",
"oden-js-sys",
"thiserror",
]
[[package]]
name = "oden-js-sys"
version = "0.1.0"
dependencies = [
"bindgen",
"cc",
"walkdir",
]
[[package]]
name = "once_cell"
version = "1.17.2"
@ -1029,6 +1109,12 @@ dependencies = [
"windows-sys 0.45.0",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "percent-encoding"
version = "2.2.0"
@ -1173,6 +1259,15 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scoped-tls"
version = "1.0.1"
@ -1198,6 +1293,12 @@ dependencies = [
"tiny-skia",
]
[[package]]
name = "shlex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
[[package]]
name = "simd-adler32"
version = "0.3.5"
@ -1389,6 +1490,16 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@ -1644,6 +1755,17 @@ dependencies = [
"web-sys",
]
[[package]]
name = "which"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
dependencies = [
"either",
"libc",
"once_cell",
]
[[package]]
name = "widestring"
version = "1.0.2"

View file

@ -11,6 +11,7 @@ bytemuck = { version = "1.13", features = ["derive"] }
env_logger = "0.10"
image = { version = "0.24", default-features = false, features = ["png"] }
log = "0.4"
oden-js = { path = "oden-js" }
pollster = "0.3"
wgpu = "0.16"
winit = "0.28"
winit = "0.28"

View file

@ -7,6 +7,9 @@ use winit::{
window::WindowBuilder,
};
mod script;
// use script::ScriptContext;
mod texture;
#[repr(C)]
@ -352,67 +355,71 @@ pub async fn run() {
let mut state = State::new(window).await;
// NOTE: There's some well-understood way here of doing constant
// rendering rather than being driven by events but I removed it
// for now. I will have to find it again at some point.
let context = script::ScriptContext::new();
event_loop.run(move |event, _, control_flow| {
control_flow.set_poll();
event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
ref event,
window_id,
} if window_id == state.window().id() => {
if !state.input(event) {
match event {
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
..
},
..
} => *control_flow = ControlFlow::Exit,
match event {
Event::WindowEvent {
ref event,
window_id,
} if window_id == state.window().id() => {
if !state.input(event) {
match event {
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
..
},
..
} => *control_flow = ControlFlow::Exit,
WindowEvent::CursorMoved { position, .. } => {
state.mouse_x = position.x;
state.mouse_y = position.y;
state.window().request_redraw();
WindowEvent::CursorMoved { position, .. } => {
state.mouse_x = position.x;
state.mouse_y = position.y;
state.window().request_redraw();
}
WindowEvent::Resized(physical_size) => {
state.resize(*physical_size);
}
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
// new_inner_size is &&mut so we have to dereference it twice
state.resize(**new_inner_size);
}
_ => {}
}
WindowEvent::Resized(physical_size) => {
state.resize(*physical_size);
}
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
// new_inner_size is &&mut so we have to dereference it twice
state.resize(**new_inner_size);
}
_ => {}
}
}
}
Event::RedrawRequested(window_id) if window_id == state.window().id() => {
state.update();
match state.render() {
Ok(_) => {}
// Reconfigure the surface if lost
Err(wgpu::SurfaceError::Lost) => state.resize(state.size),
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// All other errors (Outdated, Timeout) should be resolved by the next frame
Err(e) => eprintln!("{:?}", e),
Event::RedrawRequested(window_id) if window_id == state.window().id() => {
context.update();
state.update();
context.render();
match state.render() {
Ok(_) => {}
// Reconfigure the surface if lost
Err(wgpu::SurfaceError::Lost) => state.resize(state.size),
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// All other errors (Outdated, Timeout) should be resolved by the next frame
Err(e) => eprintln!("{:?}", e),
}
}
}
Event::MainEventsCleared => {
// RedrawRequested will only trigger once, unless we manually
// request it.
state.window().request_redraw();
}
Event::MainEventsCleared => {
// RedrawRequested will only trigger once, unless we manually
// request it.
state.window().request_redraw();
}
_ => {}
_ => {}
}
});
}

22
src/script.rs Normal file
View file

@ -0,0 +1,22 @@
use oden_js as js;
pub struct ScriptContext {
_context: js::Context,
}
impl ScriptContext {
pub fn new() -> Self {
let runtime = js::Runtime::new();
let mut context = js::Context::new(runtime);
context.add_intrinsic_bigfloat();
context.add_intrinsic_bigdecimal();
context.add_intrinsic_operators();
ScriptContext { _context: context }
}
pub fn update(&self) {}
pub fn render(&self) {}
}