aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-15 00:45:45 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-15 00:45:45 +0200
commit052e28628eceb112aaadd5e703709c80183d290f (patch)
tree665d3a17fa5c16c3561f530c4a22eb4e0e4f8828
parent804f05e5e556fb950292f323d32e5e4fc35d310b (diff)
downloadhurrycurry-052e28628eceb112aaadd5e703709c80183d290f.tar
hurrycurry-052e28628eceb112aaadd5e703709c80183d290f.tar.bz2
hurrycurry-052e28628eceb112aaadd5e703709c80183d290f.tar.zst
create light client crate
-rw-r--r--Cargo.lock52
-rw-r--r--Cargo.toml2
-rw-r--r--light-client/Cargo.toml9
-rw-r--r--light-client/src/bin/bunnymark.rs104
-rw-r--r--light-client/src/main.rs77
-rw-r--r--light-client/src/network.rs7
6 files changed, 246 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 896d13dc..732d4f03 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -174,7 +174,7 @@ version = "0.69.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
dependencies = [
- "bitflags",
+ "bitflags 2.6.0",
"cexpr",
"clang-sys",
"itertools",
@@ -193,6 +193,12 @@ dependencies = [
[[package]]
name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
+name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
@@ -695,6 +701,15 @@ dependencies = [
]
[[package]]
+name = "light-client"
+version = "0.1.0"
+dependencies = [
+ "hurrycurry-protocol",
+ "sdl2",
+ "tungstenite",
+]
+
+[[package]]
name = "linux-raw-sys"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -949,7 +964,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
dependencies = [
- "bitflags",
+ "bitflags 2.6.0",
]
[[package]]
@@ -1014,7 +1029,7 @@ version = "0.38.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
dependencies = [
- "bitflags",
+ "bitflags 2.6.0",
"errno",
"libc",
"linux-raw-sys",
@@ -1100,12 +1115,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
+name = "sdl2"
+version = "0.37.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3b498da7d14d1ad6c839729bd4ad6fc11d90a57583605f3b4df2cd709a9cd380"
+dependencies = [
+ "bitflags 1.3.2",
+ "lazy_static",
+ "libc",
+ "sdl2-sys",
+]
+
+[[package]]
+name = "sdl2-sys"
+version = "0.37.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "951deab27af08ed9c6068b7b0d05a93c91f0a8eb16b6b816a5e73452a43521d3"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "version-compare",
+]
+
+[[package]]
name = "security-framework"
version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0"
dependencies = [
- "bitflags",
+ "bitflags 2.6.0",
"core-foundation",
"core-foundation-sys",
"libc",
@@ -1380,6 +1418,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
+name = "version-compare"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
+
+[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index c3c2d759..ea1db4ef 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,3 +1,3 @@
[workspace]
-members = ["server/replaytool", "server", "server/protocol"]
+members = ["server/replaytool", "server", "server/protocol", "light-client"]
resolver = "2"
diff --git a/light-client/Cargo.toml b/light-client/Cargo.toml
new file mode 100644
index 00000000..a7cb5199
--- /dev/null
+++ b/light-client/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "light-client"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+sdl2 = { version = "0.37.0", features = ["image", "ttf"] }
+hurrycurry-protocol = { path = "../server/protocol" }
+tungstenite = "0.23.0"
diff --git a/light-client/src/bin/bunnymark.rs b/light-client/src/bin/bunnymark.rs
new file mode 100644
index 00000000..12c18d66
--- /dev/null
+++ b/light-client/src/bin/bunnymark.rs
@@ -0,0 +1,104 @@
+/*
+ Hurry Curry! - a game about cooking
+ Copyright 2024 metamuffin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+use hurrycurry_protocol::glam::IVec2;
+use sdl2::{
+ event::Event,
+ image::{InitFlag, LoadTexture},
+ keyboard::Keycode,
+ pixels::Color,
+ rect::Rect,
+};
+use std::time::Instant;
+
+const WIDTH: i32 = 1920;
+const HEIGHT: i32 = 1080;
+
+pub fn main() {
+ let amount = std::env::args().skip(1).next().unwrap().parse().unwrap();
+
+ let sdl_context = sdl2::init().unwrap();
+ let video_subsystem = sdl_context.video().unwrap();
+ let _image_context = sdl2::image::init(InitFlag::WEBP | InitFlag::PNG).unwrap();
+ let window = video_subsystem
+ .window("Hurry Curry! Light Client", WIDTH as u32, HEIGHT as u32)
+ .position_centered()
+ .build()
+ .map_err(|e| e.to_string())
+ .unwrap();
+
+ let mut canvas = window
+ .into_canvas()
+ .accelerated()
+ .build()
+ .map_err(|e| e.to_string())
+ .unwrap();
+ let texture_creator = canvas.texture_creator();
+ let texture = texture_creator.load_texture("client/icon.png").unwrap();
+
+ let mut bunnies = vec![(IVec2::ZERO, IVec2::ONE); amount];
+
+ for (i, (pos, vel)) in bunnies.iter_mut().enumerate() {
+ let mut r = xorshift(i as i32);
+ pos.x = r % WIDTH;
+ r = xorshift(r);
+ pos.y = r % HEIGHT;
+ r = xorshift(r);
+ vel.x = r % 7 - 3;
+ r = xorshift(r);
+ vel.y = r % 7 - 3;
+ }
+
+ let mut last = Instant::now();
+ 'mainloop: loop {
+ canvas.set_draw_color(Color::BLACK);
+ canvas.clear();
+ for (pos, vel) in &mut bunnies {
+ *pos += *vel;
+ if pos.x < 0 || pos.x > WIDTH {
+ vel.x *= -1
+ }
+ if pos.y < 0 || pos.y > HEIGHT {
+ vel.y *= -1
+ }
+ canvas
+ .copy(&texture, None, Some(Rect::new(pos.x, pos.y, 30, 30)))
+ .unwrap();
+ }
+ canvas.present();
+
+ for event in sdl_context.event_pump().unwrap().poll_iter() {
+ match event {
+ Event::Quit { .. }
+ | Event::KeyDown {
+ keycode: Option::Some(Keycode::Escape),
+ ..
+ } => break 'mainloop,
+ _ => {}
+ }
+ }
+ println!("frame time: {:?}", last.elapsed());
+ last = Instant::now();
+ }
+}
+
+fn xorshift(mut x: i32) -> i32 {
+ x ^= x << 13;
+ x ^= x >> 17;
+ x ^= x << 5;
+ x
+}
diff --git a/light-client/src/main.rs b/light-client/src/main.rs
new file mode 100644
index 00000000..03c2fd76
--- /dev/null
+++ b/light-client/src/main.rs
@@ -0,0 +1,77 @@
+/*
+ Hurry Curry! - a game about cooking
+ Copyright 2024 metamuffin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+use sdl2::{
+ event::Event,
+ image::InitFlag,
+ keyboard::Keycode,
+ pixels::{Color, PixelFormatEnum},
+ render::TextureAccess,
+};
+
+pub mod network;
+
+fn main() {
+ let sdl_context = sdl2::init().unwrap();
+ let video_subsystem = sdl_context.video().unwrap();
+ let _image_context = sdl2::image::init(InitFlag::WEBP).unwrap();
+ let window = video_subsystem
+ .window("Hurry Curry! Light Client", 1280, 720)
+ .position_centered()
+ .resizable()
+ .build()
+ .map_err(|e| e.to_string())
+ .unwrap();
+
+ let mut canvas = window
+ .into_canvas()
+ .accelerated()
+ .build()
+ .map_err(|e| e.to_string())
+ .unwrap();
+ let texture_creator = canvas.texture_creator();
+ let mut texture = texture_creator
+ .create_texture(
+ Some(PixelFormatEnum::RGBA8888),
+ TextureAccess::Streaming,
+ 1024,
+ 1024,
+ )
+ .unwrap();
+
+ texture.update(None, &vec![128; 1024 * 1024], 1024).unwrap();
+
+ 'mainloop: loop {
+ canvas.set_draw_color(Color::BLACK);
+ canvas.clear();
+
+ canvas.copy(&texture, None, None).unwrap();
+
+ canvas.present();
+
+ for event in sdl_context.event_pump().unwrap().poll_iter() {
+ match event {
+ Event::Quit { .. }
+ | Event::KeyDown {
+ keycode: Option::Some(Keycode::Escape),
+ ..
+ } => break 'mainloop,
+ _ => {}
+ }
+ }
+ }
+}
diff --git a/light-client/src/network.rs b/light-client/src/network.rs
new file mode 100644
index 00000000..2a185b73
--- /dev/null
+++ b/light-client/src/network.rs
@@ -0,0 +1,7 @@
+pub struct Network {}
+
+impl Network {
+ pub fn connect(addr: &str) {
+ let (sock, resp) = tungstenite::connect(addr).unwrap();
+ }
+}