summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-11 00:24:12 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-11 00:24:12 +0100
commite9e5df5ff1e09356bf2ad0bcc82bbaee6a2acc0d (patch)
treebe3ed59dc7a82ab7d973b7fa88930d7f69c76c49
parent2c8360de342872f65bdef037f3fb5d598b8f26a0 (diff)
downloadweareserver-e9e5df5ff1e09356bf2ad0bcc82bbaee6a2acc0d.tar
weareserver-e9e5df5ff1e09356bf2ad0bcc82bbaee6a2acc0d.tar.bz2
weareserver-e9e5df5ff1e09356bf2ad0bcc82bbaee6a2acc0d.tar.zst
things
-rw-r--r--client/src/camera.rs6
-rw-r--r--client/src/main.rs3
-rw-r--r--client/src/network.rs2
-rw-r--r--client/src/scene_render.rs16
-rw-r--r--client/src/state.rs35
-rw-r--r--client/src/ui.rs17
6 files changed, 60 insertions, 19 deletions
diff --git a/client/src/camera.rs b/client/src/camera.rs
index 9228482..4006c74 100644
--- a/client/src/camera.rs
+++ b/client/src/camera.rs
@@ -37,6 +37,12 @@ impl Camera {
self.rot.x += input_rot.x * -0.002;
self.rot.y += input_rot.y * -0.002;
}
+ pub fn position(&self) -> Vec3 {
+ self.pos
+ }
+ pub fn rotation(&self) -> Vec3 {
+ self.rot
+ }
pub fn rotation_mat(&self) -> Mat3 {
Mat3::from_euler(EulerRot::YXZ, self.rot.x, self.rot.y, self.rot.z)
}
diff --git a/client/src/main.rs b/client/src/main.rs
index 0ee665c..091854b 100644
--- a/client/src/main.rs
+++ b/client/src/main.rs
@@ -15,6 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#![feature(iter_array_chunks)]
+#![feature(mpmc_channel)]
pub mod camera;
pub mod download;
pub mod network;
@@ -22,8 +23,8 @@ pub mod renderer;
pub mod scene_prepare;
pub mod scene_render;
pub mod state;
-pub mod window;
pub mod ui;
+pub mod window;
use anyhow::Result;
use clap::Parser;
diff --git a/client/src/network.rs b/client/src/network.rs
index 73c4ab2..d279436 100644
--- a/client/src/network.rs
+++ b/client/src/network.rs
@@ -19,7 +19,7 @@ use log::{debug, info, warn};
use std::{
io::{BufReader, BufWriter, Write},
net::TcpStream,
- sync::mpsc::{Receiver, Sender, channel},
+ sync::mpmc::{Receiver, Sender, channel},
thread::spawn,
};
use weareshared::{helper::ReadWrite, packets::Packet};
diff --git a/client/src/scene_render.rs b/client/src/scene_render.rs
index f6f7dbb..bc9fc52 100644
--- a/client/src/scene_render.rs
+++ b/client/src/scene_render.rs
@@ -20,9 +20,9 @@ use weareshared::{packets::Resource, resources::Prefab, tree::SceneTree};
use wgpu::{
BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState,
Color, ColorTargetState, ColorWrites, CommandEncoder, CompareFunction, DepthBiasState,
- DepthStencilState, Device, FragmentState, FrontFace, IndexFormat, LoadOp, MultisampleState,
- Operations, PipelineCompilationOptions, PipelineLayoutDescriptor, PolygonMode, PrimitiveState,
- PrimitiveTopology, PushConstantRange, RenderPassColorAttachment,
+ DepthStencilState, Device, Face, FragmentState, FrontFace, IndexFormat, LoadOp,
+ MultisampleState, Operations, PipelineCompilationOptions, PipelineLayoutDescriptor,
+ PolygonMode, PrimitiveState, PrimitiveTopology, PushConstantRange, RenderPassColorAttachment,
RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPipeline,
RenderPipelineDescriptor, SamplerBindingType, ShaderStages, StencilState, StoreOp,
TextureFormat, TextureSampleType, TextureView, TextureViewDimension, VertexAttribute,
@@ -118,7 +118,7 @@ impl ScenePipeline {
primitive: PrimitiveState {
topology: PrimitiveTopology::TriangleList,
front_face: FrontFace::Ccw,
- cull_mode: None, //Some(Face::Back),
+ cull_mode: Some(Face::Back),
polygon_mode: PolygonMode::Fill,
..Default::default()
},
@@ -173,18 +173,18 @@ impl ScenePipeline {
for ob in scene.objects.values() {
let prefab_projection = projection
+ * Mat4::from_translation(ob.pos.into())
* Mat4::from_mat3(Mat3::from_euler(
EulerRot::YXZ,
ob.rot.x,
ob.rot.y,
ob.rot.z,
- ))
- * Mat4::from_translation(ob.pos.into());
+ ));
if let Some(prefab) = prefabs.try_get(ob.res.clone()) {
for (affine, part) in &prefab.0 {
let part_projection = prefab_projection
- * Mat4::from_mat3a(affine.matrix3)
- * Mat4::from_translation(affine.translation.into());
+ * Mat4::from_translation(affine.translation.into())
+ * Mat4::from_mat3a(affine.matrix3);
let projection = part_projection.to_cols_array().map(|v| v.to_le_bytes());
rpass.set_bind_group(0, &*part.texture, &[]);
diff --git a/client/src/state.rs b/client/src/state.rs
index 5176ca1..cb7316d 100644
--- a/client/src/state.rs
+++ b/client/src/state.rs
@@ -20,7 +20,7 @@ use glam::{Vec2, Vec3};
use log::{info, warn};
use std::{net::TcpStream, sync::Arc, time::Instant};
use weareshared::{
- packets::{Packet, Resource},
+ packets::{Object, Packet, Resource},
resources::PrefabIndex,
store::ResourceStore,
tree::SceneTree,
@@ -38,6 +38,7 @@ pub struct State<'a> {
pub prefab_index: Arc<PrefabIndex>,
pub prefab_index_res_loaded: Option<Resource<PrefabIndex>>,
pub prefab_index_res: Option<Resource<PrefabIndex>>,
+ pub avatar_ob: Option<Object>,
}
pub struct InputState {
@@ -67,6 +68,7 @@ impl<'a> State<'a> {
},
prefab_index_res: None,
prefab_index_res_loaded: None,
+ avatar_ob: None,
prefab_index: PrefabIndex::default().into(),
})
}
@@ -103,6 +105,7 @@ impl<'a> State<'a> {
return;
}
let pi = self.prefab_index.clone();
+ let net = self.network.clone();
self.renderer
.ui_renderer
.add_surface(self.camera.new_ui_affine(), move |ctx| {
@@ -110,10 +113,15 @@ impl<'a> State<'a> {
egui::Window::new("Prefab Index")
.open(&mut open)
.show(ctx, |ui| {
- for (key, _res) in &pi.0 {
+ for (key, res) in &pi.0 {
ui.horizontal(|ui| {
ui.label(key);
- if ui.button("Add").clicked() {}
+ if ui.button("Add").clicked() {
+ info!("spawn {res}");
+ net.packet_send
+ .send(Packet::Add(Object::new(), res.clone()))
+ .unwrap();
+ }
});
}
});
@@ -150,6 +158,27 @@ impl<'a> State<'a> {
}
}
+ if let Some(ob) = self.avatar_ob {
+ self.network
+ .packet_send
+ .send(Packet::Position(
+ ob,
+ self.camera.position().into(),
+ self.camera.rotation().into(),
+ ))
+ .unwrap();
+ } else {
+ if let Some(res) = self.prefab_index.0.get("avatar_test") {
+ info!("found avatar resource {res}");
+ let ob = Object::new();
+ self.network
+ .packet_send
+ .send(Packet::Add(ob, res.to_owned()))
+ .unwrap();
+ self.avatar_ob = Some(ob)
+ }
+ }
+
self.input_state.egui_events.clear();
Ok(())
}
diff --git a/client/src/ui.rs b/client/src/ui.rs
index 13e58d0..ffd840d 100644
--- a/client/src/ui.rs
+++ b/client/src/ui.rs
@@ -14,6 +14,7 @@
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 crate::state::InputState;
use egui::{
Context, Event, ImageData, TextureId, ViewportId, ViewportInfo,
epaint::{ImageDelta, Primitive, Vertex},
@@ -43,8 +44,6 @@ use wgpu::{
vertex_attr_array,
};
-use crate::state::InputState;
-
pub struct UiRenderer {
device: Arc<Device>,
queue: Arc<Queue>,
@@ -53,6 +52,8 @@ pub struct UiRenderer {
bind_group_layout: BindGroupLayout,
textures: RwLock<HashMap<TextureId, (BindGroup, Texture, [u32; 2])>>,
surfaces: RwLock<HashMap<ViewportId, UiSurface>>,
+
+ last_pointer: Vec2,
}
pub struct UiSurface {
@@ -144,6 +145,7 @@ impl UiRenderer {
device,
queue,
bind_group_layout,
+ last_pointer: Vec2::ZERO,
textures: HashMap::new().into(),
surfaces: HashMap::new().into(),
}
@@ -313,10 +315,13 @@ impl UiRenderer {
);
let mut raw_input = egui::RawInput::default();
- raw_input.events.push(Event::PointerMoved(egui::Pos2::new(
- input_state.cursor_pos.x,
- input_state.cursor_pos.y,
- )));
+ if input_state.cursor_pos != self.last_pointer {
+ raw_input.events.push(Event::PointerMoved(egui::Pos2::new(
+ input_state.cursor_pos.x,
+ input_state.cursor_pos.y,
+ )));
+ self.last_pointer = input_state.cursor_pos;
+ }
raw_input
.events
.extend(input_state.egui_events.iter().cloned());