diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ab45927..7d85494 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,14 +23,14 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly + toolchain: stable targets: wasm32-unknown-unknown - uses: jetli/wasm-pack-action@v0.4.0 with: version: 'latest' - name: Build run: | - wasm-pack build --debug --target web + wasm-pack build --target web npm i npx vite build - name: Setup Pages diff --git a/src/lib.rs b/src/lib.rs index e934cd1..9968cbd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,3 @@ -#![feature( - const_fn_floating_point_arithmetic, - const_refs_to_static, - generic_const_exprs, - let_chains -)] -#![allow(incomplete_features)] pub mod permutation; pub mod puzzle; pub mod webgl; diff --git a/src/webgl.rs b/src/webgl.rs index 87d2851..7c2724e 100644 --- a/src/webgl.rs +++ b/src/webgl.rs @@ -1,6 +1,6 @@ use gl_matrix::common::{Mat4, Vec3, PI}; use gl_matrix::{mat4, vec3}; -use std::borrow::{Borrow, BorrowMut}; +use std::borrow::BorrowMut; use std::cell::RefCell; use std::collections::HashMap; use wasm_bindgen::prelude::*; @@ -97,7 +97,7 @@ impl Command { const ANIMATION_DURATION: f32 = 400.0; // it takes 1.6 seconds to rotate the camera 120 degrees -const CAMERA_SPEED: f32 = (2.0 * PI) / (3.0 * 1600.0); +const CAMERA_SPEED: f32 = (2.0 * std::f32::consts::PI) / (3.0 * 1600.0); #[wasm_bindgen] pub fn render(ms: f32) -> Result<()> { @@ -388,7 +388,6 @@ impl Piece { } } -#[allow(dead_code)] #[derive(Debug)] struct State { pieces: Vec, @@ -595,10 +594,10 @@ impl State { let mut array = Vec::with_capacity(4 * self.get_vertex_count() as usize); for facet in self.facets() { for _ in 0..facet.get_vertex_count() { - array.push(facet.color.0[0]); - array.push(facet.color.0[1]); - array.push(facet.color.0[2]); - array.push(facet.color.0[3]); + array.push(facet.color.red()); + array.push(facet.color.green()); + array.push(facet.color.blue()); + array.push(facet.color.alpha()); } } @@ -612,9 +611,7 @@ impl State { let mut offset = 0; // slow path - if let Some(twist) = self.active_twist - && matches!(twist, Twist::Center { .. }) - { + if let Some(twist) = self.active_twist { let normal = twist.to_normal(); for piece in self.pieces.iter() { for facet in piece.facets.iter() { @@ -685,24 +682,45 @@ impl Facet { } #[derive(Debug, Clone)] -struct Color([f32; 4]); +struct Color { + red: u8, + green: u8, + blue: u8, + alpha: f32, +} -#[allow(dead_code)] impl Color { const fn rgb(red: u8, green: u8, blue: u8) -> Self { - Color([ - red as f32 / 255.0, - green as f32 / 255.0, - blue as f32 / 255.0, - 1.0, - ]) + Color { + red, + green, + blue, + alpha: 1., + } + } + const fn rgba(red: u8, green: u8, blue: u8, alpha: f32) -> Self { + Color { + red, + green, + blue, + alpha, + } + } + + fn red(&self) -> f32 { + f32::from(self.red) / 255. + } + + fn green(&self) -> f32 { + f32::from(self.green) / 255. + } + + fn blue(&self) -> f32 { + f32::from(self.blue) / 255. } - fn write_to(&self, array: &Float32Array, start: u32) { - Float32Array::set_index(array, start, self.0[0]); - Float32Array::set_index(array, start + 1, self.0[1]); - Float32Array::set_index(array, start + 2, self.0[2]); - Float32Array::set_index(array, start + 3, self.0[3]); + fn alpha(&self) -> f32 { + self.alpha } const MAGENTA: Self = Self::rgb(210, 75, 208);