summaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-05 23:24:57 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-05 23:24:57 +0100
commit1c0c8f788c8125c90a097e5241b5e8fe2518d1d2 (patch)
treeb5542fe00a472b5d5a8bcdd17fb3a34b75ad1dd0 /client/src
parente15b39b2a9cf028b12cbe98f56674e58c5a6bd4c (diff)
downloadweareserver-1c0c8f788c8125c90a097e5241b5e8fe2518d1d2.tar
weareserver-1c0c8f788c8125c90a097e5241b5e8fe2518d1d2.tar.bz2
weareserver-1c0c8f788c8125c90a097e5241b5e8fe2518d1d2.tar.zst
a
Diffstat (limited to 'client/src')
-rw-r--r--client/src/download.rs9
-rw-r--r--client/src/network.rs3
-rw-r--r--client/src/part.rs11
-rw-r--r--client/src/renderer.rs22
-rw-r--r--client/src/shader.wgsl4
-rw-r--r--client/src/window.rs11
6 files changed, 48 insertions, 12 deletions
diff --git a/client/src/download.rs b/client/src/download.rs
index 256c25c..dfd7ff0 100644
--- a/client/src/download.rs
+++ b/client/src/download.rs
@@ -1,12 +1,12 @@
+use crate::network::Network;
use anyhow::Result;
+use log::debug;
use std::collections::HashSet;
use weareshared::{
packets::{Packet, Resource},
store::{ResourceStore, sha256},
};
-use crate::network::Network;
-
pub struct Downloader {
have: HashSet<Resource>,
need: HashSet<Resource>,
@@ -38,7 +38,9 @@ impl Downloader {
self.store.set(&d)?;
self.need.remove(&key);
self.pending.remove(&key);
- self.have.insert(key);
+ if self.have.insert(key) {
+ debug!("have {key}");
+ }
}
_ => (),
}
@@ -51,6 +53,7 @@ impl Downloader {
.packet_send
.send(Packet::RequestResource(*n))
.unwrap();
+ debug!("need {n}");
new_pending.push(*n);
}
self.pending.extend(new_pending);
diff --git a/client/src/network.rs b/client/src/network.rs
index 0fd5f08..e542c7e 100644
--- a/client/src/network.rs
+++ b/client/src/network.rs
@@ -1,5 +1,5 @@
use std::{
- io::{BufReader, BufWriter},
+ io::{BufReader, BufWriter, Write},
net::TcpStream,
sync::mpsc::{Receiver, Sender, channel},
thread::spawn,
@@ -50,6 +50,7 @@ fn handle_conn_write(sock: TcpStream, rx: Receiver<Packet>) -> Result<()> {
for packet in rx {
debug!("-> {packet:?}");
packet.serialize(&mut sock)?;
+ sock.flush()?;
}
Ok(())
}
diff --git a/client/src/part.rs b/client/src/part.rs
index 0ad714a..7d02f0c 100644
--- a/client/src/part.rs
+++ b/client/src/part.rs
@@ -12,13 +12,18 @@ use wgpu::{
util::{BufferInitDescriptor, DeviceExt},
};
-pub struct RenderPart {
+pub struct PartRenderer {
vertex: Buffer,
index: Buffer,
pipeline: RenderPipeline,
bind_group: BindGroup,
n_vertex: u32,
}
+
+pub struct PrefabData {
+
+}
+
pub struct PartData {
target: Part,
vertex: Vec<Option<VertexAttributes>>,
@@ -48,7 +53,7 @@ impl PartData {
}
}
-impl RenderPart {
+impl PartRenderer {
pub fn new(device: Device, data: PartData, format: TextureFormat) -> Self {
let mut vertex = Vec::new();
let mut index = Vec::new();
@@ -140,7 +145,7 @@ impl RenderPart {
n_vertex,
}
}
- pub fn draw(&self, commands: &mut CommandEncoder, target: TextureView) {
+ pub fn draw(&self, commands: &mut CommandEncoder, target: &TextureView) {
let mut rpass = commands.begin_render_pass(&RenderPassDescriptor {
label: None,
color_attachments: &[Some(RenderPassColorAttachment {
diff --git a/client/src/renderer.rs b/client/src/renderer.rs
index cc44446..35bc0ef 100644
--- a/client/src/renderer.rs
+++ b/client/src/renderer.rs
@@ -1,6 +1,9 @@
+use crate::part::{PartData, PartRenderer};
use anyhow::{Result, anyhow};
use log::info;
use pollster::FutureExt;
+use std::collections::HashMap;
+use weareshared::{packets::Resource, tree::SceneTree};
use wgpu::{
Backends, BindGroup, BindGroupDescriptor, BindGroupLayoutDescriptor, BlendState, Color,
ColorTargetState, ColorWrites, CommandEncoderDescriptor, Device, DeviceDescriptor, Features,
@@ -20,6 +23,9 @@ pub struct Renderer<'a> {
queue: Queue,
device: Device,
surface_configuration: SurfaceConfiguration,
+
+ prefabs_loading: HashMap<Resource, Vec<PartData>>,
+ prefabs: HashMap<Resource, Vec<PartRenderer>>,
}
impl<'a> Renderer<'a> {
pub fn new(window: &'a Window) -> Result<Self> {
@@ -111,6 +117,8 @@ impl<'a> Renderer<'a> {
device,
queue,
surface_configuration,
+ prefabs: HashMap::new(),
+ prefabs_loading: HashMap::new(),
})
}
@@ -121,7 +129,7 @@ impl<'a> Renderer<'a> {
.configure(&self.device, &self.surface_configuration);
}
- pub fn draw(&mut self) -> Result<()> {
+ pub fn draw(&mut self, scene: &SceneTree) -> Result<()> {
let target = self.surface.get_current_texture()?;
let target_view = target
.texture
@@ -150,9 +158,19 @@ impl<'a> Renderer<'a> {
rpass.draw(0..3, 0..1);
}
+ for data in scene.objects.values() {
+ if let Some(ob) = self.prefabs.get(&data.res) {
+ for p in ob {
+ p.draw(&mut commands, &target_view);
+ }
+ } else {
+ let loading = self.prefabs_loading.entry(data.res).or_default();
+
+ }
+ }
+
let i = self.queue.submit(Some(commands.finish()));
self.device.poll(MaintainBase::WaitForSubmissionIndex(i));
-
target.present();
Ok(())
diff --git a/client/src/shader.wgsl b/client/src/shader.wgsl
index 859ffa4..41c21d9 100644
--- a/client/src/shader.wgsl
+++ b/client/src/shader.wgsl
@@ -1,6 +1,6 @@
@vertex
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
- let x = f32(i32(in_vertex_index) - 1);
+ let x = f32(i32(in_vertex_index) % 2);
let y = f32(i32(in_vertex_index & 1u) * 2 - 1);
return vec4<f32>(x, y, 0.0, 1.0);
}
@@ -8,4 +8,4 @@ fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) ve
@fragment
fn fs_main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
-} \ No newline at end of file
+}
diff --git a/client/src/window.rs b/client/src/window.rs
index 5f2e7f8..2219bbc 100644
--- a/client/src/window.rs
+++ b/client/src/window.rs
@@ -43,7 +43,7 @@ impl ApplicationHandler for WindowState {
WindowEvent::Resized(size) => {
sta.renderer.resize(size.width, size.height);
}
- WindowEvent::RedrawRequested => sta.renderer.draw().unwrap(),
+ WindowEvent::RedrawRequested => sta.renderer.draw(&sta.tree).unwrap(),
WindowEvent::CloseRequested => {
event_loop.exit();
}
@@ -59,3 +59,12 @@ impl ApplicationHandler for WindowState {
}
}
}
+
+impl Drop for WindowState {
+ fn drop(&mut self) {
+ if let Some((win, sta)) = self.window.take() {
+ drop(sta);
+ drop(win)
+ }
+ }
+}