[oden] Remove native assets module
What's the point?
This commit is contained in:
parent
f3f9988314
commit
96e95e22ce
3 changed files with 1 additions and 66 deletions
|
|
@ -1,56 +0,0 @@
|
|||
use crate::script::graphics::{CreateTextureCommand, GraphicsCommand};
|
||||
use oden_js::{module::native::NativeModuleBuilder, ContextRef, Error, Result};
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
|
||||
struct AssetsImpl {
|
||||
next_texture_id: AtomicU32,
|
||||
gfx_sender: Sender<GraphicsCommand>,
|
||||
}
|
||||
|
||||
impl AssetsImpl {
|
||||
fn new(sender: Sender<GraphicsCommand>) -> Self {
|
||||
AssetsImpl {
|
||||
gfx_sender: sender,
|
||||
next_texture_id: AtomicU32::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
fn load_texture(&self, path: &str) -> Result<u32> {
|
||||
let bytes = std::fs::read(path)?;
|
||||
let image = match image::load_from_memory(&bytes) {
|
||||
Ok(i) => i,
|
||||
Err(e) => return Err(Error::RustFunctionError(format!("{e}"))),
|
||||
};
|
||||
|
||||
let id = self.next_texture_id.fetch_add(1, Ordering::SeqCst);
|
||||
let _ = self
|
||||
.gfx_sender
|
||||
.send(GraphicsCommand::CreateTexture(CreateTextureCommand {
|
||||
id,
|
||||
image,
|
||||
label: Some(path.into()),
|
||||
}));
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AssetsAPI {}
|
||||
|
||||
impl AssetsAPI {
|
||||
pub fn define(ctx: &ContextRef, sender: Sender<GraphicsCommand>) -> oden_js::Result<Self> {
|
||||
let assets = Arc::new(AssetsImpl::new(sender));
|
||||
let mut builder = NativeModuleBuilder::new(ctx);
|
||||
{
|
||||
let assets = assets.clone();
|
||||
builder.export(
|
||||
"load_texture",
|
||||
ctx.new_fn(move |_ctx: &ContextRef, p: String| assets.load_texture(&p))?,
|
||||
)?;
|
||||
}
|
||||
builder.build("asset-core")?;
|
||||
Ok(AssetsAPI {})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue