[oden] Garbage assets, need to rewrite to IO
This commit is contained in:
parent
75fcc427ac
commit
17805fa4a6
17 changed files with 240 additions and 94 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use oden_js::{module, ContextRef, Value, ValueResult};
|
||||
use oden_js::{module, ContextRef};
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -24,11 +24,20 @@ pub struct SpriteCommand {
|
|||
pub sh: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CreateTextureCommand {
|
||||
pub id: u32,
|
||||
pub image: image::DynamicImage,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum GraphicsCommand {
|
||||
Clear(ClearCommand),
|
||||
Print(PrintCommand),
|
||||
Sprite(SpriteCommand),
|
||||
CreateTexture(CreateTextureCommand),
|
||||
UseTexture(u32),
|
||||
EndFrame,
|
||||
}
|
||||
|
||||
|
|
@ -41,33 +50,19 @@ impl GraphicsImpl {
|
|||
GraphicsImpl { sender }
|
||||
}
|
||||
|
||||
fn print_fn(&self, ctx: &ContextRef, text: String) -> ValueResult {
|
||||
fn print(&self, text: String) -> () {
|
||||
let _ = self
|
||||
.sender
|
||||
.send(GraphicsCommand::Print(PrintCommand { text }));
|
||||
|
||||
Ok(Value::undefined(ctx))
|
||||
}
|
||||
|
||||
fn cls_fn(&self, ctx: &ContextRef, r: f64, g: f64, b: f64) -> ValueResult {
|
||||
fn cls(&self, r: f64, g: f64, b: f64) -> () {
|
||||
let _ = self.sender.send(GraphicsCommand::Clear(ClearCommand {
|
||||
color: [r, g, b, 1.0],
|
||||
}));
|
||||
Ok(Value::undefined(ctx))
|
||||
}
|
||||
|
||||
fn spr_fn(
|
||||
&self,
|
||||
ctx: &ContextRef,
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
h: f32,
|
||||
u: f32,
|
||||
v: f32,
|
||||
sw: f32,
|
||||
sh: f32,
|
||||
) -> ValueResult {
|
||||
fn spr(&self, x: f32, y: f32, w: f32, h: f32, u: f32, v: f32, sw: f32, sh: f32) {
|
||||
let _ = self.sender.send(GraphicsCommand::Sprite(SpriteCommand {
|
||||
x,
|
||||
y,
|
||||
|
|
@ -78,7 +73,10 @@ impl GraphicsImpl {
|
|||
sw,
|
||||
sh,
|
||||
}));
|
||||
Ok(Value::undefined(ctx))
|
||||
}
|
||||
|
||||
fn use_texture(&self, id: u32) {
|
||||
let _ = self.sender.send(GraphicsCommand::UseTexture(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,16 +92,14 @@ impl GraphicsAPI {
|
|||
let gfx = gfx.clone();
|
||||
builder.export(
|
||||
"print",
|
||||
ctx.new_fn(move |ctx: &ContextRef, t: String| gfx.print_fn(ctx, t))?,
|
||||
ctx.new_fn(move |_: &ContextRef, t: String| gfx.print(t))?,
|
||||
)?;
|
||||
}
|
||||
{
|
||||
let gfx = gfx.clone();
|
||||
builder.export(
|
||||
"cls",
|
||||
ctx.new_fn(move |ctx: &ContextRef, r: f64, g: f64, b: f64| {
|
||||
gfx.cls_fn(ctx, r, g, b)
|
||||
})?,
|
||||
ctx.new_fn(move |_: &ContextRef, r: f64, g: f64, b: f64| gfx.cls(r, g, b))?,
|
||||
)?;
|
||||
}
|
||||
{
|
||||
|
|
@ -111,7 +107,7 @@ impl GraphicsAPI {
|
|||
builder.export(
|
||||
"spr",
|
||||
ctx.new_fn(
|
||||
move |ctx: &ContextRef,
|
||||
move |_: &ContextRef,
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
|
|
@ -119,12 +115,17 @@ impl GraphicsAPI {
|
|||
u: f32,
|
||||
v: f32,
|
||||
sw: f32,
|
||||
sh: f32| {
|
||||
gfx.spr_fn(ctx, x, y, w, h, u, v, sw, sh)
|
||||
},
|
||||
sh: f32| gfx.spr(x, y, w, h, u, v, sw, sh),
|
||||
)?,
|
||||
)?;
|
||||
}
|
||||
{
|
||||
let gfx = gfx.clone();
|
||||
builder.export(
|
||||
"use_texture",
|
||||
ctx.new_fn(move |_: &ContextRef, id: u32| gfx.use_texture(id))?,
|
||||
)?;
|
||||
}
|
||||
builder.build("graphics-core")?;
|
||||
Ok(GraphicsAPI { gfx })
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue