From 4fb92d6fa3ce2d93c2ce720429f46aa104972674 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Mon, 28 Jul 2025 01:41:31 -0400 Subject: Update --- crates/client/src/client.rs | 48 +++++++++++++++++++++ crates/client/src/client/assets.rs | 23 ++++++++++ crates/client/src/client/assets/audio/test.wav | Bin 0 -> 924 bytes crates/client/src/client/assets/meshes/square.obj | 15 +++++++ .../src/client/assets/shaders/flat/frag.glsl | 11 +++++ .../src/client/assets/shaders/flat/vert.glsl | 4 ++ crates/client/src/client/assets/textures/test.png | Bin 0 -> 714 bytes crates/client/src/common.rs | 8 ---- crates/client/src/common/client.rs | 48 --------------------- crates/client/src/common/client/assets.rs | 23 ---------- .../client/src/common/client/assets/audio/test.wav | Bin 924 -> 0 bytes .../src/common/client/assets/meshes/square.obj | 15 ------- .../common/client/assets/shaders/flat/frag.glsl | 11 ----- .../common/client/assets/shaders/flat/vert.glsl | 4 -- .../src/common/client/assets/textures/test.png | Bin 714 -> 0 bytes crates/client/src/helpers.js | 13 ------ crates/client/src/lib.rs | 6 +-- crates/client/src/main.rs | 42 ------------------ 18 files changed, 104 insertions(+), 167 deletions(-) create mode 100644 crates/client/src/client.rs create mode 100644 crates/client/src/client/assets.rs create mode 100644 crates/client/src/client/assets/audio/test.wav create mode 100644 crates/client/src/client/assets/meshes/square.obj create mode 100644 crates/client/src/client/assets/shaders/flat/frag.glsl create mode 100644 crates/client/src/client/assets/shaders/flat/vert.glsl create mode 100644 crates/client/src/client/assets/textures/test.png delete mode 100644 crates/client/src/common.rs delete mode 100644 crates/client/src/common/client.rs delete mode 100644 crates/client/src/common/client/assets.rs delete mode 100644 crates/client/src/common/client/assets/audio/test.wav delete mode 100644 crates/client/src/common/client/assets/meshes/square.obj delete mode 100644 crates/client/src/common/client/assets/shaders/flat/frag.glsl delete mode 100644 crates/client/src/common/client/assets/shaders/flat/vert.glsl delete mode 100644 crates/client/src/common/client/assets/textures/test.png delete mode 100644 crates/client/src/helpers.js delete mode 100644 crates/client/src/main.rs (limited to 'crates/client/src') diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs new file mode 100644 index 0000000..713d022 --- /dev/null +++ b/crates/client/src/client.rs @@ -0,0 +1,48 @@ +#![allow(dead_code, unused_variables)] +mod assets; + +use std::collections::HashMap; +use teleia::*; + +pub struct Game { + assets: assets::Assets, +} + +impl Game { + pub fn new(ctx: &context::Context) -> Self { + Self { + assets: assets::Assets::new(ctx), + } + } +} + +impl teleia::state::Game for Game { + fn initialize_audio(&self, ctx: &context::Context, st: &state::State, actx: &audio::Context) -> HashMap { + HashMap::from_iter(vec![ + ("test".to_owned(), audio::Audio::new(&actx, include_bytes!("client/assets/audio/test.wav"))), + ]) + } + fn finish_title(&mut self, _st: &mut state::State) {} + fn mouse_press(&mut self, _ctx: &context::Context, _st: &mut state::State) {} + fn mouse_move(&mut self, _ctx: &context::Context, _st: &mut state::State, _x: i32, _y: i32) {} + fn update(&mut self, ctx: &context::Context, _st: &mut state::State) -> Erm<()> { + Ok(()) + } + fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Erm<()> { + ctx.clear(); + self.assets.font.render_text( + ctx, + &glam::Vec2::new(0.0, 0.0), + "hello computer", + ); + st.bind_2d(ctx, &self.assets.shader_flat); + self.assets.texture_test.bind(ctx); + self.assets.shader_flat.set_position_2d( + ctx, + &glam::Vec2::new(40.0, 40.0), + &glam::Vec2::new(16.0, 16.0), + ); + self.assets.mesh_square.render(ctx); + Ok(()) + } +} diff --git a/crates/client/src/client/assets.rs b/crates/client/src/client/assets.rs new file mode 100644 index 0000000..742f9ea --- /dev/null +++ b/crates/client/src/client/assets.rs @@ -0,0 +1,23 @@ +use teleia::*; + +pub struct Assets { + pub font: font::Bitmap, + pub shader_flat: shader::Shader, + pub mesh_square: mesh::Mesh, + pub texture_test: texture::Texture, +} + +impl Assets { + pub fn new(ctx: &context::Context) -> Self { + Self { + font: font::Bitmap::new(ctx), + shader_flat: shader::Shader::new( + ctx, + include_str!("assets/shaders/flat/vert.glsl"), + include_str!("assets/shaders/flat/frag.glsl"), + ), + mesh_square: mesh::Mesh::from_obj(ctx, include_bytes!("assets/meshes/square.obj")), + texture_test: texture::Texture::new(ctx, include_bytes!("assets/textures/test.png")), + } + } +} diff --git a/crates/client/src/client/assets/audio/test.wav b/crates/client/src/client/assets/audio/test.wav new file mode 100644 index 0000000..0eabe85 Binary files /dev/null and b/crates/client/src/client/assets/audio/test.wav differ diff --git a/crates/client/src/client/assets/meshes/square.obj b/crates/client/src/client/assets/meshes/square.obj new file mode 100644 index 0000000..7328a6c --- /dev/null +++ b/crates/client/src/client/assets/meshes/square.obj @@ -0,0 +1,15 @@ +# Blender 3.6.2 +# www.blender.org +o Cube +v -1.000000 -1.000000 0.000000 +v 1.000000 -1.000000 0.000000 +v -1.000000 1.000000 0.000000 +v 1.000000 1.000000 0.000000 +vn -0.0000 -0.0000 -1.0000 +vt 0.0 1.0 +vt 1.0 0.0 +vt 0.0 0.0 +vt 1.0 1.0 +s 0 +f 3/1/1 2/2/1 1/3/1 +f 3/1/1 4/4/1 2/2/1 diff --git a/crates/client/src/client/assets/shaders/flat/frag.glsl b/crates/client/src/client/assets/shaders/flat/frag.glsl new file mode 100644 index 0000000..7006a2b --- /dev/null +++ b/crates/client/src/client/assets/shaders/flat/frag.glsl @@ -0,0 +1,11 @@ +uniform sampler2D texture_data; + +void main() +{ + vec2 tcfull = vec2(vertex_texcoord.x, 1.0 - vertex_texcoord.y); + vec4 texel = texture(texture_data, tcfull); + if (texel.a != 1.0) { + discard; + } + frag_color = texel; +} diff --git a/crates/client/src/client/assets/shaders/flat/vert.glsl b/crates/client/src/client/assets/shaders/flat/vert.glsl new file mode 100644 index 0000000..e324f7e --- /dev/null +++ b/crates/client/src/client/assets/shaders/flat/vert.glsl @@ -0,0 +1,4 @@ +void main() +{ + default_main(); +} \ No newline at end of file diff --git a/crates/client/src/client/assets/textures/test.png b/crates/client/src/client/assets/textures/test.png new file mode 100644 index 0000000..1f1edca Binary files /dev/null and b/crates/client/src/client/assets/textures/test.png differ diff --git a/crates/client/src/common.rs b/crates/client/src/common.rs deleted file mode 100644 index 3599211..0000000 --- a/crates/client/src/common.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[cfg(target_arch = "wasm32")] -pub mod client; - -#[cfg(not(target_arch = "wasm32"))] -pub mod overlay; - -#[cfg(not(target_arch = "wasm32"))] -pub mod server; diff --git a/crates/client/src/common/client.rs b/crates/client/src/common/client.rs deleted file mode 100644 index 69ac6b3..0000000 --- a/crates/client/src/common/client.rs +++ /dev/null @@ -1,48 +0,0 @@ -#![allow(dead_code, unused_variables)] -mod assets; - -use std::collections::HashMap; -use teleia::*; - -pub struct Game { - assets: assets::Assets, -} - -impl Game { - pub async fn new(ctx: &context::Context) -> Self { - Self { - assets: assets::Assets::new(ctx), - } - } -} - -impl teleia::state::Game for Game { - fn initialize_audio(&self, ctx: &context::Context, st: &state::State, actx: &audio::Context) -> HashMap { - HashMap::from_iter(vec![ - ("test".to_owned(), audio::Audio::new(&actx, include_bytes!("client/assets/audio/test.wav"))), - ]) - } - fn finish_title(&mut self, _st: &mut state::State) {} - fn mouse_press(&mut self, _ctx: &context::Context, _st: &mut state::State) {} - fn mouse_move(&mut self, _ctx: &context::Context, _st: &mut state::State, _x: i32, _y: i32) {} - fn update(&mut self, ctx: &context::Context, _st: &mut state::State) -> Option<()> { - Some(()) - } - fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> { - ctx.clear(); - self.assets.font.render_text( - ctx, - &glam::Vec2::new(0.0, 0.0), - "hello computer", - ); - st.bind_2d(ctx, &self.assets.shader_flat); - self.assets.texture_test.bind(ctx); - self.assets.shader_flat.set_position_2d( - ctx, - &glam::Vec2::new(40.0, 40.0), - &glam::Vec2::new(16.0, 16.0), - ); - self.assets.mesh_square.render(ctx); - Some(()) - } -} diff --git a/crates/client/src/common/client/assets.rs b/crates/client/src/common/client/assets.rs deleted file mode 100644 index 742f9ea..0000000 --- a/crates/client/src/common/client/assets.rs +++ /dev/null @@ -1,23 +0,0 @@ -use teleia::*; - -pub struct Assets { - pub font: font::Bitmap, - pub shader_flat: shader::Shader, - pub mesh_square: mesh::Mesh, - pub texture_test: texture::Texture, -} - -impl Assets { - pub fn new(ctx: &context::Context) -> Self { - Self { - font: font::Bitmap::new(ctx), - shader_flat: shader::Shader::new( - ctx, - include_str!("assets/shaders/flat/vert.glsl"), - include_str!("assets/shaders/flat/frag.glsl"), - ), - mesh_square: mesh::Mesh::from_obj(ctx, include_bytes!("assets/meshes/square.obj")), - texture_test: texture::Texture::new(ctx, include_bytes!("assets/textures/test.png")), - } - } -} diff --git a/crates/client/src/common/client/assets/audio/test.wav b/crates/client/src/common/client/assets/audio/test.wav deleted file mode 100644 index 0eabe85..0000000 Binary files a/crates/client/src/common/client/assets/audio/test.wav and /dev/null differ diff --git a/crates/client/src/common/client/assets/meshes/square.obj b/crates/client/src/common/client/assets/meshes/square.obj deleted file mode 100644 index 7328a6c..0000000 --- a/crates/client/src/common/client/assets/meshes/square.obj +++ /dev/null @@ -1,15 +0,0 @@ -# Blender 3.6.2 -# www.blender.org -o Cube -v -1.000000 -1.000000 0.000000 -v 1.000000 -1.000000 0.000000 -v -1.000000 1.000000 0.000000 -v 1.000000 1.000000 0.000000 -vn -0.0000 -0.0000 -1.0000 -vt 0.0 1.0 -vt 1.0 0.0 -vt 0.0 0.0 -vt 1.0 1.0 -s 0 -f 3/1/1 2/2/1 1/3/1 -f 3/1/1 4/4/1 2/2/1 diff --git a/crates/client/src/common/client/assets/shaders/flat/frag.glsl b/crates/client/src/common/client/assets/shaders/flat/frag.glsl deleted file mode 100644 index 7006a2b..0000000 --- a/crates/client/src/common/client/assets/shaders/flat/frag.glsl +++ /dev/null @@ -1,11 +0,0 @@ -uniform sampler2D texture_data; - -void main() -{ - vec2 tcfull = vec2(vertex_texcoord.x, 1.0 - vertex_texcoord.y); - vec4 texel = texture(texture_data, tcfull); - if (texel.a != 1.0) { - discard; - } - frag_color = texel; -} diff --git a/crates/client/src/common/client/assets/shaders/flat/vert.glsl b/crates/client/src/common/client/assets/shaders/flat/vert.glsl deleted file mode 100644 index e324f7e..0000000 --- a/crates/client/src/common/client/assets/shaders/flat/vert.glsl +++ /dev/null @@ -1,4 +0,0 @@ -void main() -{ - default_main(); -} \ No newline at end of file diff --git a/crates/client/src/common/client/assets/textures/test.png b/crates/client/src/common/client/assets/textures/test.png deleted file mode 100644 index 1f1edca..0000000 Binary files a/crates/client/src/common/client/assets/textures/test.png and /dev/null differ diff --git a/crates/client/src/helpers.js b/crates/client/src/helpers.js deleted file mode 100644 index 20b86f4..0000000 --- a/crates/client/src/helpers.js +++ /dev/null @@ -1,13 +0,0 @@ -let resized = false; - -export async function js_track_resized_setup() { - window.addEventListener("resize", () => { - resized = true; - }); -}; - -export function js_poll_resized() { - let ret = resized; - resized = false; - return ret; -} diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 3298f07..d928d0e 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -1,10 +1,10 @@ -mod common; +mod client; #[cfg(target_arch = "wasm32")] use wasm_bindgen::prelude::*; #[cfg(target_arch = "wasm32")] #[wasm_bindgen] -pub async fn main_js() { - teleia::run(240, 160, common::client::Game::new).await; +pub fn main_js() { + teleia::run(240, 160, teleia::Options::empty(), client::Game::new); } diff --git a/crates/client/src/main.rs b/crates/client/src/main.rs deleted file mode 100644 index af8e753..0000000 --- a/crates/client/src/main.rs +++ /dev/null @@ -1,42 +0,0 @@ -mod common; - -#[cfg(not(target_arch = "wasm32"))] -use clap::{command, Command}; - -#[cfg(target_arch = "wasm32")] -pub fn main() {} // dummy main, real wasm32 main is lib::main_js - -#[cfg(not(target_arch = "wasm32"))] -#[tokio::main] -pub async fn main() { - let matches = command!() - .propagate_version(true) - .subcommand_required(true) - .arg_required_else_help(true) - .subcommand( - Command::new("overlay") - .about("Run the LCOLONQ model renderer in a full-screen transparent overlay") - ) - .subcommand( - Command::new("terminal") - .about("Run the LCOLONQ model renderer in a terminal") - ) - .subcommand( - Command::new("server") - .about("Run the LCOLONQ online websocket server") - ) - .get_matches(); - match matches.subcommand() { - Some(("overlay", _cm)) => { - teleia::run("LCOLONQ", 1920, 1080, teleia::Options::OVERLAY, common::overlay::Overlay::overlay).await; - }, - Some(("terminal", _cm)) => { - teleia::run("LCOLONQ", 1920, 1080, teleia::Options::HIDDEN, common::overlay::Overlay::terminal).await; - }, - Some(("server", _cm)) => { - env_logger::Builder::new().filter(None, log::LevelFilter::Info).init(); - log::info!("starting LCOLONQ server..."); - }, - _ => unreachable!("no subcommand"), - } -} -- cgit v1.2.3