summaryrefslogtreecommitdiff
path: root/crates/client/src
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-02-16 22:55:43 -0500
committerLLLL Colonq <llll@colonq>2025-02-16 22:55:43 -0500
commit4d0a8140130ebd0f46744b86eeb2a708657a942e (patch)
tree6b1a11e07173c769d0f3522c2f6088409b69332d /crates/client/src
parent33d69b282e082acce3c5d36cc08cd99a7ccf738d (diff)
Switch to workspace
Diffstat (limited to 'crates/client/src')
-rw-r--r--crates/client/src/common.rs8
-rw-r--r--crates/client/src/common/client.rs48
-rw-r--r--crates/client/src/common/client/assets.rs23
-rw-r--r--crates/client/src/common/client/assets/audio/test.wavbin0 -> 924 bytes
-rw-r--r--crates/client/src/common/client/assets/meshes/square.obj15
-rw-r--r--crates/client/src/common/client/assets/shaders/flat/frag.glsl11
-rw-r--r--crates/client/src/common/client/assets/shaders/flat/vert.glsl4
-rw-r--r--crates/client/src/common/client/assets/textures/test.pngbin0 -> 714 bytes
-rw-r--r--crates/client/src/helpers.js13
-rw-r--r--crates/client/src/index.css46
-rw-r--r--crates/client/src/lib.rs10
-rw-r--r--crates/client/src/main.rs42
12 files changed, 220 insertions, 0 deletions
diff --git a/crates/client/src/common.rs b/crates/client/src/common.rs
new file mode 100644
index 0000000..3599211
--- /dev/null
+++ b/crates/client/src/common.rs
@@ -0,0 +1,8 @@
+#[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
new file mode 100644
index 0000000..69ac6b3
--- /dev/null
+++ b/crates/client/src/common/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 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<String, audio::Audio> {
+ 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
new file mode 100644
index 0000000..742f9ea
--- /dev/null
+++ b/crates/client/src/common/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/common/client/assets/audio/test.wav b/crates/client/src/common/client/assets/audio/test.wav
new file mode 100644
index 0000000..0eabe85
--- /dev/null
+++ b/crates/client/src/common/client/assets/audio/test.wav
Binary files differ
diff --git a/crates/client/src/common/client/assets/meshes/square.obj b/crates/client/src/common/client/assets/meshes/square.obj
new file mode 100644
index 0000000..7328a6c
--- /dev/null
+++ b/crates/client/src/common/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/common/client/assets/shaders/flat/frag.glsl b/crates/client/src/common/client/assets/shaders/flat/frag.glsl
new file mode 100644
index 0000000..7006a2b
--- /dev/null
+++ b/crates/client/src/common/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/common/client/assets/shaders/flat/vert.glsl b/crates/client/src/common/client/assets/shaders/flat/vert.glsl
new file mode 100644
index 0000000..e324f7e
--- /dev/null
+++ b/crates/client/src/common/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/common/client/assets/textures/test.png b/crates/client/src/common/client/assets/textures/test.png
new file mode 100644
index 0000000..1f1edca
--- /dev/null
+++ b/crates/client/src/common/client/assets/textures/test.png
Binary files differ
diff --git a/crates/client/src/helpers.js b/crates/client/src/helpers.js
new file mode 100644
index 0000000..20b86f4
--- /dev/null
+++ b/crates/client/src/helpers.js
@@ -0,0 +1,13 @@
+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/index.css b/crates/client/src/index.css
new file mode 100644
index 0000000..80de9e4
--- /dev/null
+++ b/crates/client/src/index.css
@@ -0,0 +1,46 @@
+html {
+ /* Remove touch delay: */
+ touch-action: manipulation;
+}
+
+body {
+ /* Light mode background color for what is not covered by the egui canvas,
+ or where the egui canvas is translucent. */
+ background: #000000;
+}
+
+/* Allow canvas to fill entire web page: */
+html,
+body {
+ overflow: hidden;
+ margin: 0 !important;
+ padding: 0 !important;
+ height: 100%;
+ width: 100%;
+}
+
+/* Position canvas in center-top: */
+canvas {
+ margin-right: auto;
+ margin-left: auto;
+ display: block;
+ position: absolute;
+ top: 0%;
+ left: 50%;
+ transform: translate(-50%, 0%);
+ color: #000000;
+}
+
+.centered {
+ margin-right: auto;
+ margin-left: auto;
+ display: block;
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ font-size: 24px;
+ font-family: Ubuntu-Light, Helvetica, sans-serif;
+ text-align: center;
+ image-transform: pixelated;
+}
diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs
new file mode 100644
index 0000000..3298f07
--- /dev/null
+++ b/crates/client/src/lib.rs
@@ -0,0 +1,10 @@
+mod common;
+
+#[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;
+}
diff --git a/crates/client/src/main.rs b/crates/client/src/main.rs
new file mode 100644
index 0000000..af8e753
--- /dev/null
+++ b/crates/client/src/main.rs
@@ -0,0 +1,42 @@
+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"),
+ }
+}