Compare commits
13 Commits
recalculat
...
run-timer-
| Author | SHA1 | Date | |
|---|---|---|---|
| ed69cf2297 | |||
| b2a84e3be1 | |||
| 0468484788 | |||
| b9dc97053f | |||
| 40ed173b60 | |||
| fd5a813357 | |||
| 50726199b9 | |||
| 0676007430 | |||
| 97c49c9351 | |||
| 10689784be | |||
| 2eff5dda9e | |||
| 93b04f4f1f | |||
| c616e82c47 |
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1912,9 +1912,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_common"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||
checksum = "ea4126f6fbf9aecf89c9e319290f0221d177dcaa8659b4b9e3d82acc37829f12"
|
||||
checksum = "9a2621612e675a8f804abbbbe3b60caeafe58a2422cccbe453268d6f457df4f3"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags 2.6.0",
|
||||
|
||||
@@ -6,12 +6,6 @@ use strafesnet_common::model::{self, ColorId, NormalId, PolygonIter, PositionId,
|
||||
use wgpu::{util::DeviceExt,AstcBlock,AstcChannel};
|
||||
use crate::model_graphics::{self,IndexedGraphicsMeshOwnedRenderConfig,IndexedGraphicsMeshOwnedRenderConfigId,GraphicsMeshOwnedRenderConfig,GraphicsModelColor4,GraphicsModelOwned,GraphicsVertex};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GraphicsModelUpdate{
|
||||
transform:Option<glam::Mat4>,
|
||||
color:Option<glam::Vec4>,
|
||||
}
|
||||
|
||||
struct Indices{
|
||||
count:u32,
|
||||
buf:wgpu::Buffer,
|
||||
@@ -32,7 +26,6 @@ impl Indices{
|
||||
}
|
||||
struct GraphicsModel{
|
||||
indices:Indices,
|
||||
model_buf:wgpu::Buffer,
|
||||
vertex_buf:wgpu::Buffer,
|
||||
bind_group:wgpu::BindGroup,
|
||||
instance_count:u32,
|
||||
@@ -65,12 +58,12 @@ struct GraphicsCamera{
|
||||
#[inline]
|
||||
fn perspective_rh(fov_x_slope:f32,fov_y_slope:f32,z_near:f32,z_far:f32)->glam::Mat4{
|
||||
//glam_assert!(z_near > 0.0 && z_far > 0.0);
|
||||
let r=z_far / (z_near-z_far);
|
||||
let r=z_far/(z_near-z_far);
|
||||
glam::Mat4::from_cols(
|
||||
glam::Vec4::new(1.0/fov_x_slope,0.0,0.0,0.0),
|
||||
glam::Vec4::new(0.0,1.0/fov_y_slope,0.0,0.0),
|
||||
glam::Vec4::new(0.0,0.0,r,-1.0),
|
||||
glam::Vec4::new(0.0,0.0,r * z_near,0.0),
|
||||
glam::Vec4::new(0.0,0.0,r*z_near,0.0),
|
||||
)
|
||||
}
|
||||
impl GraphicsCamera{
|
||||
@@ -79,10 +72,10 @@ impl GraphicsCamera{
|
||||
}
|
||||
pub fn world(&self,pos:glam::Vec3,angles:glam::Vec2)->glam::Mat4{
|
||||
//f32 good enough for view matrix
|
||||
glam::Mat4::from_translation(pos) * glam::Mat4::from_euler(glam::EulerRot::YXZ,angles.x,angles.y,0f32)
|
||||
glam::Mat4::from_translation(pos)*glam::Mat4::from_euler(glam::EulerRot::YXZ,angles.x,angles.y,0f32)
|
||||
}
|
||||
|
||||
pub fn to_uniform_data(&self,(pos,angles):(glam::Vec3,glam::Vec2))->[f32; 16 * 4]{
|
||||
pub fn to_uniform_data(&self,pos:glam::Vec3,angles:glam::Vec2)->[f32;16*4]{
|
||||
let proj=self.proj();
|
||||
let proj_inv=proj.inverse();
|
||||
let view_inv=self.world(pos,angles);
|
||||
@@ -105,6 +98,13 @@ impl std::default::Default for GraphicsCamera{
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FrameState{
|
||||
pub body:crate::physics::Body,
|
||||
pub camera:crate::physics::PhysicsCamera,
|
||||
pub time:integer::Time,
|
||||
pub run:strafesnet_common::run::Run,
|
||||
}
|
||||
|
||||
pub struct GraphicsState{
|
||||
pipelines:GraphicsPipelines,
|
||||
bind_groups:GraphicsBindGroups,
|
||||
@@ -507,7 +507,6 @@ impl GraphicsState{
|
||||
model_graphics::Indices::U16(indices)=>Indices::new(device,indices,wgpu::IndexFormat::Uint16),
|
||||
},
|
||||
bind_group,
|
||||
model_buf,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -816,7 +815,7 @@ impl GraphicsState{
|
||||
});
|
||||
|
||||
let camera=GraphicsCamera::default();
|
||||
let camera_uniforms=camera.to_uniform_data(crate::physics::PhysicsOutputState::default().extrapolate(strafesnet_common::mouse::MouseState::default()));
|
||||
let camera_uniforms=camera.to_uniform_data(glam::Vec3::ZERO,glam::Vec2::ZERO);
|
||||
let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
||||
label:Some("Camera"),
|
||||
contents:bytemuck::cast_slice(&camera_uniforms),
|
||||
@@ -884,16 +883,17 @@ impl GraphicsState{
|
||||
view:&wgpu::TextureView,
|
||||
device:&wgpu::Device,
|
||||
queue:&wgpu::Queue,
|
||||
physics_output:crate::physics::PhysicsOutputState,
|
||||
predicted_time:integer::Time,
|
||||
mouse_pos:glam::IVec2,
|
||||
frame_state:FrameState,
|
||||
){
|
||||
//TODO:use scheduled frame times to create beautiful smoothing simulation physics extrapolation assuming no input
|
||||
|
||||
let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
|
||||
|
||||
// update rotation
|
||||
let camera_uniforms=self.camera.to_uniform_data(physics_output.extrapolate(strafesnet_common::mouse::MouseState{pos:mouse_pos,time:predicted_time}));
|
||||
let camera_uniforms=self.camera.to_uniform_data(
|
||||
frame_state.body.extrapolated_position(frame_state.time).into(),
|
||||
frame_state.camera.simulate_move_angles(glam::IVec2::ZERO)
|
||||
);
|
||||
self.staging_belt
|
||||
.write_buffer(
|
||||
&mut encoder,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use strafesnet_common::integer;
|
||||
|
||||
pub enum Instruction{
|
||||
Render(crate::physics::PhysicsOutputState,integer::Time,glam::IVec2),
|
||||
Render(crate::graphics::FrameState),
|
||||
//UpdateModel(crate::graphics::GraphicsModelUpdate),
|
||||
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
||||
ChangeMap(strafesnet_common::map::CompleteMap),
|
||||
@@ -17,12 +15,12 @@ WorkerDescription{
|
||||
//up to three frames in flight, dropping new frame requests when all three are busy, and dropping output frames when one renders out of order
|
||||
|
||||
pub fn new<'a>(
|
||||
mut graphics:crate::graphics::GraphicsState,
|
||||
mut config:wgpu::SurfaceConfiguration,
|
||||
surface:wgpu::Surface<'a>,
|
||||
device:wgpu::Device,
|
||||
queue:wgpu::Queue,
|
||||
)->crate::compat_worker::INWorker<'a,Instruction>{
|
||||
mut graphics:crate::graphics::GraphicsState,
|
||||
mut config:wgpu::SurfaceConfiguration,
|
||||
surface:wgpu::Surface<'a>,
|
||||
device:wgpu::Device,
|
||||
queue:wgpu::Queue,
|
||||
)->crate::compat_worker::INWorker<'a,Instruction>{
|
||||
let mut resize=None;
|
||||
crate::compat_worker::INWorker::new(move |ins:Instruction|{
|
||||
match ins{
|
||||
@@ -33,18 +31,16 @@ pub fn new<'a>(
|
||||
Instruction::Resize(size,user_settings)=>{
|
||||
resize=Some((size,user_settings));
|
||||
}
|
||||
Instruction::Render(physics_output,predicted_time,mouse_pos)=>{
|
||||
if let Some((size,user_settings))=&resize{
|
||||
Instruction::Render(frame_state)=>{
|
||||
if let Some((size,user_settings))=resize.take(){
|
||||
println!("Resizing to {:?}",size);
|
||||
let t0=std::time::Instant::now();
|
||||
config.width=size.width.max(1);
|
||||
config.height=size.height.max(1);
|
||||
surface.configure(&device,&config);
|
||||
graphics.resize(&device,&config,user_settings);
|
||||
graphics.resize(&device,&config,&user_settings);
|
||||
println!("Resize took {:?}",t0.elapsed());
|
||||
}
|
||||
//clear every time w/e
|
||||
resize=None;
|
||||
//this has to go deeper somehow
|
||||
let frame=match surface.get_current_texture(){
|
||||
Ok(frame)=>frame,
|
||||
@@ -60,7 +56,7 @@ pub fn new<'a>(
|
||||
..wgpu::TextureViewDescriptor::default()
|
||||
});
|
||||
|
||||
graphics.render(&view,&device,&queue,physics_output,predicted_time,mouse_pos);
|
||||
graphics.render(&view,&device,&queue,frame_state);
|
||||
|
||||
frame.present();
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ pub struct TransformedMesh<'a>{
|
||||
transform:&'a PhysicsMeshTransform,
|
||||
}
|
||||
impl TransformedMesh<'_>{
|
||||
pub fn new<'a>(
|
||||
pub const fn new<'a>(
|
||||
view:PhysicsMeshView<'a>,
|
||||
transform:&'a PhysicsMeshTransform,
|
||||
)->TransformedMesh<'a>{
|
||||
|
||||
@@ -419,7 +419,7 @@ impl HitboxMesh{
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn transformed_mesh(&self)->TransformedMesh{
|
||||
const fn transformed_mesh(&self)->TransformedMesh{
|
||||
TransformedMesh::new(self.mesh.complete_mesh_view(),&self.transform)
|
||||
}
|
||||
}
|
||||
@@ -613,19 +613,6 @@ impl MoveState{
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone,Default)]
|
||||
pub struct PhysicsOutputState{
|
||||
body:Body,
|
||||
camera:PhysicsCamera,
|
||||
camera_offset:Planar64Vec3,
|
||||
mouse_pos:glam::IVec2,
|
||||
}
|
||||
impl PhysicsOutputState{
|
||||
pub fn extrapolate(&self,mouse:MouseState)->(glam::Vec3,glam::Vec2){
|
||||
((self.body.extrapolated_position(mouse.time)+self.camera_offset).into(),self.camera.simulate_move_angles(mouse.pos-self.mouse_pos))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||
enum PhysicsCollisionAttributes{
|
||||
Contact(gameplay_attributes::ContactAttributes),
|
||||
@@ -922,7 +909,7 @@ impl VirtualBody<'_>{
|
||||
pub struct PhysicsState{
|
||||
time:Time,
|
||||
body:Body,
|
||||
world:WorldState,//currently there is only one state the world can be in
|
||||
_world:WorldState,//currently there is only one state the world can be in
|
||||
touching:TouchingState,
|
||||
//camera must exist in state because wormholes modify the camera, also camera punch
|
||||
camera:PhysicsCamera,
|
||||
@@ -959,7 +946,7 @@ impl Default for PhysicsState{
|
||||
move_state:MoveState::Air,
|
||||
camera:PhysicsCamera::default(),
|
||||
input_state:InputState::default(),
|
||||
world:WorldState{},
|
||||
_world:WorldState{},
|
||||
mode_state:ModeState::default(),
|
||||
run:run::Run::new(),
|
||||
}
|
||||
@@ -1047,17 +1034,21 @@ impl instruction::InstructionEmitter<PhysicsInternalInstruction> for PhysicsCont
|
||||
}
|
||||
}
|
||||
impl PhysicsContext{
|
||||
pub const fn output(&self)->PhysicsOutputState{
|
||||
PhysicsOutputState{
|
||||
body:self.state.body,
|
||||
camera:self.state.camera,
|
||||
camera_offset:self.state.style.camera_offset,
|
||||
mouse_pos:self.state.input_state.mouse.pos,
|
||||
pub fn camera_body(&self)->Body{
|
||||
Body{
|
||||
position:self.state.body.position+self.state.style.camera_offset,
|
||||
..self.state.body
|
||||
}
|
||||
}
|
||||
pub const fn camera(&self)->PhysicsCamera{
|
||||
self.state.camera
|
||||
}
|
||||
pub const fn get_next_mouse(&self)->&MouseState{
|
||||
self.state.input_state.get_next_mouse()
|
||||
}
|
||||
pub const fn run(&self)->run::Run{
|
||||
self.state.run
|
||||
}
|
||||
/// use with caution, this is the only non-instruction way to mess with physics
|
||||
pub fn generate_models(&mut self,map:&map::CompleteMap){
|
||||
self.state.clear();
|
||||
@@ -1484,9 +1475,9 @@ fn run_teleport_behaviour(
|
||||
match stage_element.behaviour(){
|
||||
gameplay_modes::StageElementBehaviour::SpawnAt=>(),
|
||||
gameplay_modes::StageElementBehaviour::Trigger
|
||||
|gameplay_modes::StageElementBehaviour::Teleport=>{
|
||||
|gameplay_modes::StageElementBehaviour::Teleport=>if let Some(mode_state_stage)=mode.get_stage(mode_state.get_stage_id()){
|
||||
//I guess this is correct behaviour when trying to teleport to a non-existent spawn but it's still weird
|
||||
let _=teleport_to_spawn(stage,move_state,body,touching,run,mode_state,mode,models,hitbox_mesh,bvh,style,camera,input_state,time);
|
||||
let _=teleport_to_spawn(mode_state_stage,move_state,body,touching,run,mode_state,mode,models,hitbox_mesh,bvh,style,camera,input_state,time);
|
||||
return;
|
||||
},
|
||||
gameplay_modes::StageElementBehaviour::Platform=>(),
|
||||
@@ -1896,6 +1887,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
if b_refresh_walk_target{
|
||||
state.apply_input_and_body(data);
|
||||
state.cull_velocity(data,state.body.velocity);
|
||||
//also check if accelerating away from surface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,8 +180,13 @@ impl MouseInterpolator{
|
||||
self.empty_queue();
|
||||
}
|
||||
}
|
||||
pub fn get_render_stuff(&self,time:Time)->(crate::physics::PhysicsOutputState,Time,glam::IVec2){
|
||||
(self.physics.output(),self.timer.time(time),self.physics.get_next_mouse().pos)
|
||||
pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{
|
||||
crate::graphics::FrameState{
|
||||
body:self.physics.camera_body(),
|
||||
camera:self.physics.camera(),
|
||||
run:self.physics.run(),
|
||||
time:self.timer.time(time),
|
||||
}
|
||||
}
|
||||
pub fn change_map(&mut self,time:Time,map:&strafesnet_common::map::CompleteMap){
|
||||
//dump any pending interpolation state
|
||||
@@ -221,8 +226,8 @@ pub fn new<'a>(
|
||||
interpolator.handle_instruction(&ins);
|
||||
match ins.instruction{
|
||||
Instruction::Render=>{
|
||||
let (physics_output,time,mouse_pos)=interpolator.get_render_stuff(ins.time);
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics_output,time,mouse_pos)).unwrap();
|
||||
let frame_state=interpolator.get_frame_state(ins.time);
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::Render(frame_state)).unwrap();
|
||||
},
|
||||
Instruction::Resize(size)=>{
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,interpolator.user_settings().clone())).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user