Create an early scripting engine #2

Merged
SeanOMik merged 42 commits from feature/early-scripting into main 2024-03-03 03:28:57 +00:00
6 changed files with 129 additions and 15 deletions
Showing only changes of commit a9705b3f81 - Show all commits

116
Cargo.lock generated
View File

@ -590,6 +590,19 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.10"
@ -622,6 +635,15 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-queue"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.18"
@ -814,6 +836,18 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "filetime"
version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.4.1",
"windows-sys 0.52.0",
]
[[package]]
name = "flate2"
version = "1.0.28"
@ -854,6 +888,15 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3aaba7ff514ee9d802b562927f80b1e94e93d8e74c31b134c9c3762dabf1a36b"
[[package]]
name = "fsevent-sys"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
dependencies = [
"libc",
]
[[package]]
name = "futures-channel"
version = "0.3.30"
@ -940,7 +983,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0af1827b7dd2f36d740ae804c1b3ea0d64c12533fb61ff91883005143a0e8c5a"
dependencies = [
"core-foundation",
"inotify",
"inotify 0.10.2",
"io-kit-sys",
"js-sys",
"libc",
@ -1196,6 +1239,17 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a257582fdcde896fd96463bf2d40eefea0580021c0712a0e2b028b60b47a837a"
[[package]]
name = "inotify"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
dependencies = [
"bitflags 1.3.2",
"inotify-sys",
"libc",
]
[[package]]
name = "inotify"
version = "0.10.2"
@ -1317,6 +1371,26 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "kqueue"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c"
dependencies = [
"kqueue-sys",
"libc",
]
[[package]]
name = "kqueue-sys"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b"
dependencies = [
"bitflags 1.3.2",
"libc",
]
[[package]]
name = "kv-log-macro"
version = "1.0.7"
@ -1505,12 +1579,14 @@ version = "0.0.1"
dependencies = [
"anyhow",
"base64 0.21.5",
"crossbeam",
"edict",
"glam",
"gltf",
"image",
"infer",
"mime",
"notify",
"percent-encoding",
"thiserror",
"tracing",
@ -1736,6 +1812,25 @@ dependencies = [
"libc",
]
[[package]]
name = "notify"
version = "6.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
dependencies = [
"bitflags 2.4.1",
"crossbeam-channel",
"filetime",
"fsevent-sys",
"inotify 0.9.6",
"kqueue",
"libc",
"log",
"mio",
"walkdir",
"windows-sys 0.48.0",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
@ -2206,6 +2301,15 @@ version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[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"
@ -2680,6 +2784,16 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690"
[[package]]
name = "walkdir"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"

View File

@ -11,11 +11,11 @@ pub struct MaterialSpecular {
impl MaterialSpecular {
pub fn from_resource(device: &wgpu::Device, queue: &wgpu::Queue, bg_layout: Arc<wgpu::BindGroupLayout>, value: &lyra_resource::Specular) -> Self {
let tex = value.texture.as_ref().map(|t| &t.data.as_ref().unwrap().image)
.map(|i| RenderTexture::from_image(device, queue, bg_layout.clone(), i, None).unwrap());
let tex = value.texture.as_ref().map(|t| t.data_ref())
.map(|i| RenderTexture::from_image(device, queue, bg_layout.clone(), &i.image, None).unwrap());
let color_tex = value.color_texture.as_ref().map(|t| &t.data.as_ref().unwrap().image)
.map(|i| RenderTexture::from_image(device, queue, bg_layout, i, None).unwrap());
let color_tex = value.color_texture.as_ref().map(|t| t.data_ref())
.map(|i| RenderTexture::from_image(device, queue, bg_layout, &i.image, None).unwrap());
Self {
factor: value.factor,
@ -39,8 +39,8 @@ pub struct Material {
impl Material {
pub fn from_resource(device: &wgpu::Device, queue: &wgpu::Queue, bg_layout: Arc<wgpu::BindGroupLayout>, value: &lyra_resource::Material) -> Self {
let diffuse_texture = value.base_color_texture.as_ref().map(|t| &t.data.as_ref().unwrap().image)
.map(|i| RenderTexture::from_image(device, queue, bg_layout.clone(), i, None).unwrap());
let diffuse_texture = value.base_color_texture.as_ref().map(|t| t.data_ref())
.map(|i| RenderTexture::from_image(device, queue, bg_layout.clone(), &i.image, None).unwrap());
let specular = value.specular.as_ref().map(|s| MaterialSpecular::from_resource(device, queue, bg_layout.clone(), s));

View File

@ -430,7 +430,7 @@ impl Renderer for BasicRenderer {
let transform_val = cached.from_transform.lerp(cached.to_transform, alpha);
let model = model.data.as_ref().unwrap().as_ref();
let model = model.data_ref();
for mesh in model.meshes.iter() {
if !self.process_mesh(entity, transform_val, mesh) && model_epoch == last_epoch {
self.update_mesh_buffers(entity, mesh);

View File

@ -1,7 +1,7 @@
use std::sync::Arc;
use image::GenericImageView;
use lyra_resource::{Resource, Texture};
use lyra_resource::{ResHandle, Texture};
use super::render_buffer::BindGroupPair;
@ -153,8 +153,8 @@ impl RenderTexture {
})
}
pub fn update_texture(&mut self, _device: &wgpu::Device, queue: &wgpu::Queue, texture: &Arc<Resource<Texture>>) {
let texture = &texture.data.as_ref().unwrap().image;
pub fn update_texture(&mut self, _device: &wgpu::Device, queue: &wgpu::Queue, texture: &Arc<ResHandle<Texture>>) {
let texture = &texture.data_ref().image;
let rgba = texture.to_rgba8();
let dimensions = texture.dimensions();
let size = wgpu::Extent3d {

View File

@ -1,6 +1,6 @@
use std::sync::Arc;
use lyra_resource::{ResourceLoader, Resource};
use lyra_resource::{ResourceLoader, ResHandle};
#[derive(Debug, Clone)]
pub struct LuaScript {
@ -23,7 +23,7 @@ impl ResourceLoader for LuaLoader {
fn load(&self, _resource_manager: &mut lyra_resource::ResourceManager, path: &str) -> Result<std::sync::Arc<dyn lyra_resource::ResourceStorage>, lyra_resource::LoaderError> {
let bytes = std::fs::read(path)?;
let s = Resource::with_data(path, LuaScript {
let s = ResHandle::with_data(path, LuaScript {
bytes
});
@ -34,7 +34,7 @@ impl ResourceLoader for LuaLoader {
let end = offset + length;
let bytes = bytes[offset..end].to_vec();
let s = Resource::with_data("from bytes", LuaScript {
let s = ResHandle::with_data("from bytes", LuaScript {
bytes
});

View File

@ -175,7 +175,7 @@ pub fn lua_scripts_create_contexts(mut host: ResMut<LuaHost>,
};
if !contexts.has_context(script.id()) {
if let Some(script_res) = &script.res_handle().data {
if let Some(script_res) = &script.res_handle().try_data_ref() {
debug!("Loading script '{}'...", script.name());
let mut script_ctx = host.load_script(&script_res.bytes, &script_data, &mut providers).unwrap();
debug!("Finished loading script '{}'", script.name());