From 4d0a8140130ebd0f46744b86eeb2a708657a942e Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Sun, 16 Feb 2025 22:55:43 -0500 Subject: Switch to workspace --- crates/throwshade/src/lib.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 crates/throwshade/src/lib.rs (limited to 'crates/throwshade/src/lib.rs') diff --git a/crates/throwshade/src/lib.rs b/crates/throwshade/src/lib.rs new file mode 100644 index 0000000..976f2ae --- /dev/null +++ b/crates/throwshade/src/lib.rs @@ -0,0 +1,57 @@ +use teleia::*; + +const VERT: &'static str = include_str!("assets/shaders/throwshade/vert.glsl"); +const FRAG: &'static str = include_str!("assets/shaders/throwshade/frag.glsl"); + +pub struct ThrowShade { + pub tickset: u64, + pub timeset: f64, + pub shader: Option, +} +impl ThrowShade { + pub fn new() -> Self { + Self { + tickset: 0, + timeset: 0.0, + shader: None, + } + } + pub fn set(&mut self, ctx: &context::Context, st: &state::State, src: &str) -> Result<(), String> { + let fsrc = format!("{}\n{}\n", FRAG, src); + self.tickset = st.tick; + if let Ok(dur) = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) { + self.timeset = dur.as_secs_f64(); + log::info!("the time: {}", self.timeset); + } + if let Some(s) = &mut self.shader { + s.replace(ctx, VERT, &fsrc)?; + } else { + self.shader = Some(shader::Shader::new_helper(ctx, VERT, &fsrc)?); + } + Ok(()) + } +} + +cfg_if::cfg_if! { + if #[cfg(target_arch = "wasm32")] { + struct Game {} + impl Game { + pub async fn new(_ctx: &context::Context) -> Self { + Self {} + } + } + impl state::Game for Game { + fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> { + ctx.clear_color(glam::Vec4::new(1.0, 0.0, 0.0, 1.0)); + ctx.clear(); + Some(()) + } + } + + use wasm_bindgen::prelude::*; + #[wasm_bindgen] + pub async fn main_js() { + teleia::run(480, 270, Game::new).await; + } + } +} -- cgit v1.2.3