Compare commits

...

2 Commits

Author SHA1 Message Date
082fbf3e80 Clear some warnings 2024-04-22 18:42:38 -07:00
3d2d7cfea3 Generate a Rust palette 2024-04-22 18:34:32 -07:00
5 changed files with 96 additions and 11 deletions

View File

@ -11,7 +11,7 @@ pub(crate) fn integrate(linker: &mut Linker<ExecutorState>) -> VResult<()> {
Ok(()) Ok(())
} }
fn yield_frame(caller: Caller<ExecutorState>) -> Result<(), Trap> { fn yield_frame(_caller: Caller<ExecutorState>) -> Result<(), Trap> {
Err(Trap::from(YieldFrame {})) Err(Trap::from(YieldFrame {}))
} }

View File

@ -1,7 +1,7 @@
use std::{fmt::Display, mem}; use std::mem;
use viperid::VResult; use viperid::VResult;
use wasmi::{core::{HostError, Trap}, Engine, Linker, Module, Store, TypedFunc, TypedResumableCall, TypedResumableInvocation}; use wasmi::{core::Trap, Engine, Linker, Module, Store, TypedFunc, TypedResumableCall, TypedResumableInvocation};
use crate::{engine_api::{self, YieldFrame}, wasi::{self, StockWasi}}; use crate::{engine_api::{self, YieldFrame}, wasi::{self, StockWasi}};
@ -34,7 +34,7 @@ impl Executor {
let mut linker = <Linker<ExecutorState>>::new(&engine); let mut linker = <Linker<ExecutorState>>::new(&engine);
wasi::integrate(&mut linker, |hs| &mut hs.wasi)?; wasi::integrate(&mut linker, |hs| &mut hs.wasi)?;
engine_api::integrate(&mut linker); engine_api::integrate(&mut linker)?;
let instance = linker let instance = linker
.instantiate(&mut store, &module)? .instantiate(&mut store, &module)?

View File

@ -149,6 +149,11 @@ function generateColors() {
return colors; return colors;
} }
function clamp(x) {
if (x < 0.0) { return 0.0; }
if (x > 255.0) { return 255.0; }
return Math.round(x);
}
function dump(fname, colors, width, height, scalar) { function dump(fname, colors, width, height, scalar) {
if (colors.length != width * height) { if (colors.length != width * height) {
@ -156,12 +161,6 @@ function dump(fname, colors, width, height, scalar) {
} }
let pngdata = []; let pngdata = [];
let clamp = function(x) {
if (x < 0.0) { return 0.0; }
if (x > 255.0) { return 255.0; }
return Math.round(x);
}
for (var y = 0; y < height * scalar; y++) { for (var y = 0; y < height * scalar; y++) {
for (var x = 0; x < width * scalar; x++) { for (var x = 0; x < width * scalar; x++) {
let i = Math.floor(y / scalar) * width + Math.floor(x / scalar); let i = Math.floor(y / scalar) * width + Math.floor(x / scalar);
@ -181,4 +180,21 @@ function dump(fname, colors, width, height, scalar) {
png.pack().pipe(fs.createWriteStream(fname)); png.pack().pipe(fs.createWriteStream(fname));
} }
dump("palette.png", generateColors(), 8, 8, 64); function dumpRust(fname, colors) {
var paletteString = "";
paletteString += "pub const PALETTE: [[u8; 3]; " + palette.length + "] = [\n"
for (var i = 0; i < colors.length; i++) {
var c = colors[i];
paletteString += (" [" +
clamp(255 * c.srgb.r) + ", " +
clamp(255 * c.srgb.g) + ", " +
clamp(255 * c.srgb.b) +
"],\n");
}
paletteString += "];\n"
fs.writeFileSync(fname, paletteString);
}
var palette = generateColors();
dump("palette.png", palette, 8, 8, 64);
dumpRust("../../src/palette.rs", palette)

View File

@ -1 +1,4 @@
mod palette;
pub use palette::PALETTE;
pub type VResult<T> = Result<T, anyhow::Error>; pub type VResult<T> = Result<T, anyhow::Error>;

66
src/palette.rs Normal file
View File

@ -0,0 +1,66 @@
pub const PALETTE: [[u8; 3]; 64] = [
[0, 0, 0],
[0, 0, 255],
[0, 255, 0],
[0, 255, 255],
[255, 0, 0],
[255, 0, 255],
[255, 255, 0],
[255, 255, 255],
[32, 45, 44],
[41, 60, 67],
[18, 22, 32],
[40, 34, 49],
[27, 17, 29],
[54, 42, 47],
[46, 33, 23],
[66, 60, 43],
[39, 92, 148],
[55, 83, 107],
[110, 45, 90],
[79, 50, 74],
[130, 103, 52],
[100, 85, 68],
[80, 133, 85],
[88, 106, 80],
[59, 115, 206],
[76, 108, 153],
[165, 53, 114],
[124, 70, 99],
[188, 157, 22],
[154, 137, 89],
[57, 194, 137],
[109, 161, 129],
[39, 187, 255],
[123, 67, 240],
[186, 66, 177],
[239, 60, 80],
[255, 170, 48],
[186, 255, 0],
[69, 255, 115],
[2, 241, 228],
[150, 190, 255],
[185, 113, 226],
[220, 118, 175],
[249, 134, 85],
[242, 204, 114],
[194, 255, 116],
[100, 255, 173],
[105, 242, 252],
[201, 169, 248],
[221, 193, 228],
[250, 156, 143],
[240, 197, 180],
[230, 237, 137],
[233, 243, 193],
[116, 253, 234],
[182, 247, 242],
[243, 222, 238],
[237, 228, 236],
[254, 235, 224],
[245, 241, 240],
[245, 254, 225],
[250, 253, 246],
[211, 250, 250],
[230, 247, 244],
];