forked from StrafesNET/strafe-client
wip
This commit is contained in:
parent
1de3501e89
commit
990199b4c7
108
src/body.rs
108
src/body.rs
@ -4,11 +4,9 @@ use crate::{instruction::{InstructionEmitter, InstructionConsumer, TimedInstruct
|
|||||||
pub enum PhysicsInstruction {
|
pub enum PhysicsInstruction {
|
||||||
CollisionStart(RelativeCollision),
|
CollisionStart(RelativeCollision),
|
||||||
CollisionEnd(RelativeCollision),
|
CollisionEnd(RelativeCollision),
|
||||||
SetControlDir(glam::Vec3),
|
|
||||||
StrafeTick,
|
StrafeTick,
|
||||||
Jump,
|
Jump,
|
||||||
SetWalkTargetVelocity(glam::Vec3),
|
RefreshWalkTarget,//this could be a helper function instead of an instruction
|
||||||
RefreshWalkTarget,
|
|
||||||
ReachWalkTargetVelocity,
|
ReachWalkTargetVelocity,
|
||||||
// Water,
|
// Water,
|
||||||
// Spawn(
|
// Spawn(
|
||||||
@ -16,6 +14,9 @@ pub enum PhysicsInstruction {
|
|||||||
// bool,//true = Trigger; false = teleport
|
// bool,//true = Trigger; false = teleport
|
||||||
// bool,//true = Force
|
// bool,//true = Force
|
||||||
// )
|
// )
|
||||||
|
//Both of these conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it)
|
||||||
|
MoveMouse(glam::IVec2),
|
||||||
|
SetControls(u32,u32),//can activate Jump
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Body {
|
pub struct Body {
|
||||||
@ -51,34 +52,35 @@ pub enum MoveRestriction {
|
|||||||
Ladder,//multiple ladders how
|
Ladder,//multiple ladders how
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MouseInterpolation {
|
/*
|
||||||
First,//just checks the last value
|
|
||||||
Lerp,//lerps between
|
|
||||||
}
|
|
||||||
|
|
||||||
enum InputInstruction {
|
enum InputInstruction {
|
||||||
MoveMouse(glam::IVec2),
|
|
||||||
Jump(bool),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InputState {
|
struct InputState {
|
||||||
controls: u32,
|
|
||||||
mouse_interpolation: MouseInterpolation,
|
|
||||||
time: TIME,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputState {
|
impl InputState {
|
||||||
pub fn get_control(&self,control:u32) -> bool {
|
pub fn get_control(&self,control:u32) -> bool {
|
||||||
self.controls&control!=0
|
self.controls&control!=0
|
||||||
}
|
}
|
||||||
pub fn process_instruction(&mut self,ins:InputInstruction){
|
}
|
||||||
match ins {
|
impl crate::instruction::InstructionEmitter<InputInstruction> for InputState{
|
||||||
InputInstruction::MoveMouse(m) => todo!("set mouse_interpolation"),
|
fn next_instruction(&self, time_limit:crate::body::TIME) -> Option<TimedInstruction<InputInstruction>> {
|
||||||
InputInstruction::Jump(b) => todo!("how does info about style modifiers get here"),
|
//this is polled by PhysicsState for actions like Jump
|
||||||
}
|
//no, it has to be the other way around. physics is run up until the jump instruction, and then the jump instruction is pushed.
|
||||||
|
self.queue.get(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl crate::instruction::InstructionConsumer<InputInstruction> for InputState{
|
||||||
|
fn process_instruction(&mut self,ins:TimedInstruction<InputInstruction>){
|
||||||
|
//add to queue
|
||||||
|
self.queue.push(ins);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum MouseInterpolation {
|
||||||
|
First,//just checks the last value
|
||||||
|
Lerp,//lerps between
|
||||||
|
}
|
||||||
pub struct MouseInterpolationState {
|
pub struct MouseInterpolationState {
|
||||||
interpolation: MouseInterpolation,
|
interpolation: MouseInterpolation,
|
||||||
time0: TIME,
|
time0: TIME,
|
||||||
@ -130,6 +132,64 @@ impl WalkState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: we use the Y=up coordinate space in this example.
|
||||||
|
pub struct Camera {
|
||||||
|
offset: glam::Vec3,
|
||||||
|
angles: glam::Vec3,
|
||||||
|
//punch: glam::Vec3,
|
||||||
|
//punch_velocity: glam::Vec3,
|
||||||
|
fov: glam::Vec2,//slope
|
||||||
|
sensitivity: glam::Vec2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Camera {
|
||||||
|
fn from_offset(offset:glam::Vec3,aspect:f32) -> Self {
|
||||||
|
Self{
|
||||||
|
offset,
|
||||||
|
angles: glam::Vec3::ZERO,
|
||||||
|
fov: glam::vec2(aspect,1.0),
|
||||||
|
sensitivity: glam::vec2(1.0/2048.0,1.0/2048.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const CONTROL_MOVEFORWARD:u32 = 0b00000001;
|
||||||
|
const CONTROL_MOVEBACK:u32 = 0b00000010;
|
||||||
|
const CONTROL_MOVERIGHT:u32 = 0b00000100;
|
||||||
|
const CONTROL_MOVELEFT:u32 = 0b00001000;
|
||||||
|
const CONTROL_MOVEUP:u32 = 0b00010000;
|
||||||
|
const CONTROL_MOVEDOWN:u32 = 0b00100000;
|
||||||
|
const CONTROL_JUMP:u32 = 0b01000000;
|
||||||
|
const CONTROL_ZOOM:u32 = 0b10000000;
|
||||||
|
|
||||||
|
const FORWARD_DIR:glam::Vec3 = glam::Vec3::new(0.0,0.0,-1.0);
|
||||||
|
const RIGHT_DIR:glam::Vec3 = glam::Vec3::new(1.0,0.0,0.0);
|
||||||
|
const UP_DIR:glam::Vec3 = glam::Vec3::new(0.0,1.0,0.0);
|
||||||
|
|
||||||
|
fn get_control_dir(controls: u32) -> glam::Vec3{
|
||||||
|
//don't get fancy just do it
|
||||||
|
let mut control_dir:glam::Vec3 = glam::Vec3::new(0.0,0.0,0.0);
|
||||||
|
if controls & CONTROL_MOVEFORWARD == CONTROL_MOVEFORWARD {
|
||||||
|
control_dir+=FORWARD_DIR;
|
||||||
|
}
|
||||||
|
if controls & CONTROL_MOVEBACK == CONTROL_MOVEBACK {
|
||||||
|
control_dir+=-FORWARD_DIR;
|
||||||
|
}
|
||||||
|
if controls & CONTROL_MOVELEFT == CONTROL_MOVELEFT {
|
||||||
|
control_dir+=-RIGHT_DIR;
|
||||||
|
}
|
||||||
|
if controls & CONTROL_MOVERIGHT == CONTROL_MOVERIGHT {
|
||||||
|
control_dir+=RIGHT_DIR;
|
||||||
|
}
|
||||||
|
if controls & CONTROL_MOVEUP == CONTROL_MOVEUP {
|
||||||
|
control_dir+=UP_DIR;
|
||||||
|
}
|
||||||
|
if controls & CONTROL_MOVEDOWN == CONTROL_MOVEDOWN {
|
||||||
|
control_dir+=-UP_DIR;
|
||||||
|
}
|
||||||
|
return control_dir
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PhysicsState {
|
pub struct PhysicsState {
|
||||||
pub body: Body,
|
pub body: Body,
|
||||||
pub hitbox_halfsize: glam::Vec3,
|
pub hitbox_halfsize: glam::Vec3,
|
||||||
@ -137,10 +197,10 @@ pub struct PhysicsState {
|
|||||||
//pub intersections: Vec<ModelId>,
|
//pub intersections: Vec<ModelId>,
|
||||||
//temp
|
//temp
|
||||||
pub models_cringe_clone: Vec<Model>,
|
pub models_cringe_clone: Vec<Model>,
|
||||||
pub temp_control_dir: glam::Vec3,
|
|
||||||
//camera must exist in state because wormholes modify the camera, also camera punch
|
//camera must exist in state because wormholes modify the camera, also camera punch
|
||||||
//pub camera: Camera,
|
pub camera: Camera,
|
||||||
//pub mouse_interpolation: MouseInterpolationState,
|
pub mouse_interpolation: MouseInterpolationState,
|
||||||
|
pub controls: u32,
|
||||||
pub time: TIME,
|
pub time: TIME,
|
||||||
pub strafe_tick_num: TIME,
|
pub strafe_tick_num: TIME,
|
||||||
pub strafe_tick_den: TIME,
|
pub strafe_tick_den: TIME,
|
||||||
@ -353,8 +413,6 @@ impl PhysicsState {
|
|||||||
pub fn run(&mut self, time_limit:TIME){
|
pub fn run(&mut self, time_limit:TIME){
|
||||||
//prepare is ommitted - everything is done via instructions.
|
//prepare is ommitted - everything is done via instructions.
|
||||||
while let Some(instruction) = self.next_instruction(time_limit) {//collect
|
while let Some(instruction) = self.next_instruction(time_limit) {//collect
|
||||||
//advance
|
|
||||||
//self.advance_time(instruction.time);
|
|
||||||
//process
|
//process
|
||||||
self.process_instruction(instruction);
|
self.process_instruction(instruction);
|
||||||
//write hash lol
|
//write hash lol
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use std::time::Instant;
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas};
|
use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas};
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{self, WindowEvent},
|
event::{self, WindowEvent, DeviceEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,7 +52,7 @@ pub trait Example: 'static + Sized {
|
|||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
);
|
);
|
||||||
fn update(&mut self, event: WindowEvent);
|
fn update(&mut self, event: WindowEvent);
|
||||||
fn move_mouse(&mut self, delta: (f64,f64));
|
fn device_event(&mut self, event: DeviceEvent);
|
||||||
fn render(
|
fn render(
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &wgpu::TextureView,
|
view: &wgpu::TextureView,
|
||||||
@ -350,13 +348,10 @@ fn start<E: Example>(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
event::Event::DeviceEvent {
|
event::Event::DeviceEvent {
|
||||||
event:
|
event,
|
||||||
winit::event::DeviceEvent::MouseMotion {
|
|
||||||
delta,
|
|
||||||
},
|
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
example.move_mouse(delta);
|
example.device_event(event);
|
||||||
},
|
},
|
||||||
event::Event::RedrawRequested(_) => {
|
event::Event::RedrawRequested(_) => {
|
||||||
|
|
||||||
|
247
src/main.rs
247
src/main.rs
@ -1,4 +1,5 @@
|
|||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
use strafe_client::{instruction::{TimedInstruction, self}, body::MouseInterpolationState};
|
||||||
use std::{borrow::Cow, time::Instant};
|
use std::{borrow::Cow, time::Instant};
|
||||||
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
|
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
|
||||||
|
|
||||||
@ -30,88 +31,6 @@ struct ModelGraphics {
|
|||||||
bind_group: wgpu::BindGroup,
|
bind_group: wgpu::BindGroup,
|
||||||
model_buf: wgpu::Buffer,
|
model_buf: wgpu::Buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: we use the Y=up coordinate space in this example.
|
|
||||||
struct Camera {
|
|
||||||
screen_size: (u32, u32),
|
|
||||||
offset: glam::Vec3,
|
|
||||||
fov: f32,
|
|
||||||
yaw: f32,
|
|
||||||
pitch: f32,
|
|
||||||
controls: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
const CONTROL_MOVEFORWARD:u32 = 0b00000001;
|
|
||||||
const CONTROL_MOVEBACK:u32 = 0b00000010;
|
|
||||||
const CONTROL_MOVERIGHT:u32 = 0b00000100;
|
|
||||||
const CONTROL_MOVELEFT:u32 = 0b00001000;
|
|
||||||
const CONTROL_MOVEUP:u32 = 0b00010000;
|
|
||||||
const CONTROL_MOVEDOWN:u32 = 0b00100000;
|
|
||||||
const CONTROL_JUMP:u32 = 0b01000000;
|
|
||||||
const CONTROL_ZOOM:u32 = 0b10000000;
|
|
||||||
|
|
||||||
const FORWARD_DIR:glam::Vec3 = glam::Vec3::new(0.0,0.0,-1.0);
|
|
||||||
const RIGHT_DIR:glam::Vec3 = glam::Vec3::new(1.0,0.0,0.0);
|
|
||||||
const UP_DIR:glam::Vec3 = glam::Vec3::new(0.0,1.0,0.0);
|
|
||||||
|
|
||||||
fn get_control_dir(controls: u32) -> glam::Vec3{
|
|
||||||
//don't get fancy just do it
|
|
||||||
let mut control_dir:glam::Vec3 = glam::Vec3::new(0.0,0.0,0.0);
|
|
||||||
if controls & CONTROL_MOVEFORWARD == CONTROL_MOVEFORWARD {
|
|
||||||
control_dir+=FORWARD_DIR;
|
|
||||||
}
|
|
||||||
if controls & CONTROL_MOVEBACK == CONTROL_MOVEBACK {
|
|
||||||
control_dir+=-FORWARD_DIR;
|
|
||||||
}
|
|
||||||
if controls & CONTROL_MOVELEFT == CONTROL_MOVELEFT {
|
|
||||||
control_dir+=-RIGHT_DIR;
|
|
||||||
}
|
|
||||||
if controls & CONTROL_MOVERIGHT == CONTROL_MOVERIGHT {
|
|
||||||
control_dir+=RIGHT_DIR;
|
|
||||||
}
|
|
||||||
if controls & CONTROL_MOVEUP == CONTROL_MOVEUP {
|
|
||||||
control_dir+=UP_DIR;
|
|
||||||
}
|
|
||||||
if controls & CONTROL_MOVEDOWN == CONTROL_MOVEDOWN {
|
|
||||||
control_dir+=-UP_DIR;
|
|
||||||
}
|
|
||||||
return control_dir
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn perspective_rh(fov_y_slope: f32, aspect_ratio: 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);
|
|
||||||
glam::Mat4::from_cols(
|
|
||||||
glam::Vec4::new(1.0/(fov_y_slope * aspect_ratio), 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),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Camera {
|
|
||||||
fn to_uniform_data(&self, pos: glam::Vec3) -> [f32; 16 * 3 + 4] {
|
|
||||||
let aspect = self.screen_size.0 as f32 / self.screen_size.1 as f32;
|
|
||||||
let fov = if self.controls&CONTROL_ZOOM==0 {
|
|
||||||
self.fov
|
|
||||||
}else{
|
|
||||||
self.fov/5.0
|
|
||||||
};
|
|
||||||
let proj = perspective_rh(fov, aspect, 0.5, 1000.0);
|
|
||||||
let proj_inv = proj.inverse();
|
|
||||||
let view = glam::Mat4::from_translation(pos+self.offset) * glam::Mat4::from_euler(glam::EulerRot::YXZ, self.yaw, self.pitch, 0f32);
|
|
||||||
let view_inv = view.inverse();
|
|
||||||
|
|
||||||
let mut raw = [0f32; 16 * 3 + 4];
|
|
||||||
raw[..16].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&proj)[..]);
|
|
||||||
raw[16..32].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&proj_inv)[..]);
|
|
||||||
raw[32..48].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&view_inv)[..]);
|
|
||||||
raw[48..52].copy_from_slice(AsRef::<[f32; 4]>::as_ref(&view.col(3)));
|
|
||||||
raw
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GraphicsBindGroups {
|
pub struct GraphicsBindGroups {
|
||||||
camera: wgpu::BindGroup,
|
camera: wgpu::BindGroup,
|
||||||
skybox_texture: wgpu::BindGroup,
|
skybox_texture: wgpu::BindGroup,
|
||||||
@ -124,7 +43,7 @@ pub struct GraphicsPipelines {
|
|||||||
|
|
||||||
pub struct GraphicsData {
|
pub struct GraphicsData {
|
||||||
start_time: std::time::Instant,
|
start_time: std::time::Instant,
|
||||||
camera: Camera,
|
screen_size: (u32, u32),
|
||||||
physics: strafe_client::body::PhysicsState,
|
physics: strafe_client::body::PhysicsState,
|
||||||
pipelines: GraphicsPipelines,
|
pipelines: GraphicsPipelines,
|
||||||
bind_groups: GraphicsBindGroups,
|
bind_groups: GraphicsBindGroups,
|
||||||
@ -210,6 +129,32 @@ fn generate_modeldatas(data:obj::ObjData) -> Vec<ModelData>{
|
|||||||
modeldatas
|
modeldatas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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);
|
||||||
|
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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_uniform_data(camera: &Camera, pos: glam::Vec3) -> [f32; 16 * 3 + 4] {
|
||||||
|
let proj = perspective_rh(self.fov_x, self.fov_y, 0.5, 1000.0);
|
||||||
|
let proj_inv = proj.inverse();
|
||||||
|
let view = glam::Mat4::from_translation(pos+self.offset) * glam::Mat4::from_euler(glam::EulerRot::YXZ, self.angles.y, self.angles.x, self.angles.z);
|
||||||
|
let view_inv = view.inverse();
|
||||||
|
|
||||||
|
let mut raw = [0f32; 16 * 3 + 4];
|
||||||
|
raw[..16].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&proj)[..]);
|
||||||
|
raw[16..32].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&proj_inv)[..]);
|
||||||
|
raw[32..48].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&view_inv)[..]);
|
||||||
|
raw[48..52].copy_from_slice(AsRef::<[f32; 4]>::as_ref(&view.col(3)));
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
|
||||||
impl strafe_client::framework::Example for GraphicsData {
|
impl strafe_client::framework::Example for GraphicsData {
|
||||||
fn optional_features() -> wgpu::Features {
|
fn optional_features() -> wgpu::Features {
|
||||||
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
||||||
@ -352,14 +297,6 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
|
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
|
||||||
});
|
});
|
||||||
|
|
||||||
let camera = Camera {
|
|
||||||
screen_size: (config.width, config.height),
|
|
||||||
offset: glam::Vec3::new(0.0,4.5-2.5,0.0),
|
|
||||||
fov: 1.0, //fov_slope = tan(fov_y/2)
|
|
||||||
pitch: 0.0,
|
|
||||||
yaw: 0.0,
|
|
||||||
controls:0,
|
|
||||||
};
|
|
||||||
let physics = strafe_client::body::PhysicsState {
|
let physics = strafe_client::body::PhysicsState {
|
||||||
body: strafe_client::body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
|
body: strafe_client::body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
|
||||||
time: 0,
|
time: 0,
|
||||||
@ -372,12 +309,14 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
mv: 2.7,
|
mv: 2.7,
|
||||||
grounded: false,
|
grounded: false,
|
||||||
jump_trying: false,
|
jump_trying: false,
|
||||||
temp_control_dir: glam::Vec3::ZERO,
|
|
||||||
walkspeed: 18.0,
|
walkspeed: 18.0,
|
||||||
contacts: std::collections::HashSet::new(),
|
contacts: std::collections::HashSet::new(),
|
||||||
models_cringe_clone: modeldatas.iter().map(|m|m.transforms.iter().map(|t|strafe_client::body::Model::new(*t))).flatten().collect(),
|
models_cringe_clone: modeldatas.iter().map(|m|m.transforms.iter().map(|t|strafe_client::body::Model::new(*t))).flatten().collect(),
|
||||||
walk: strafe_client::body::WalkState::new(),
|
walk: strafe_client::body::WalkState::new(),
|
||||||
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
||||||
|
camera: Camera::from_offset(glam::vec3(0.0,4.5-2.5,0.0),(config.width as f32)/(config.height as f32)),
|
||||||
|
mouse_interpolation: strafe_client::body::MouseInterpolationState::new(),
|
||||||
|
controls: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
//load textures
|
//load textures
|
||||||
@ -653,7 +592,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
|
|
||||||
GraphicsData {
|
GraphicsData {
|
||||||
start_time: Instant::now(),
|
start_time: Instant::now(),
|
||||||
camera,
|
screen_size,
|
||||||
physics,
|
physics,
|
||||||
pipelines:GraphicsPipelines{
|
pipelines:GraphicsPipelines{
|
||||||
skybox:sky_pipeline,
|
skybox:sky_pipeline,
|
||||||
@ -672,59 +611,64 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
|
|
||||||
#[allow(clippy::single_match)]
|
#[allow(clippy::single_match)]
|
||||||
fn update(&mut self, event: winit::event::WindowEvent) {
|
fn update(&mut self, event: winit::event::WindowEvent) {
|
||||||
|
//nothing atm
|
||||||
|
}
|
||||||
|
|
||||||
|
fn device_event(&mut self, event: winit::event::DeviceEvent) {
|
||||||
|
//there's no way this is the best way get a timestamp.
|
||||||
|
let time=self.start_time.elapsed().as_nanos() as i64;
|
||||||
match event {
|
match event {
|
||||||
winit::event::WindowEvent::KeyboardInput {
|
winit::event::DeviceEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
winit::event::KeyboardInput {
|
winit::event::KeyboardInput {
|
||||||
state,
|
state,
|
||||||
virtual_keycode: Some(keycode),
|
scancode: keycode,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
match (state,keycode) {
|
let s=match state {
|
||||||
(k,winit::event::VirtualKeyCode::W) => match k {
|
winit::event::ElementState::Pressed => true,
|
||||||
winit::event::ElementState::Pressed => self.camera.controls|=CONTROL_MOVEFORWARD,
|
winit::event::ElementState::Released => false,
|
||||||
winit::event::ElementState::Released => self.camera.controls&=!CONTROL_MOVEFORWARD,
|
};
|
||||||
|
if let Some(instruction)=match keycode {
|
||||||
|
119 => Some(InputInstruction::MoveForward(s)),//W
|
||||||
|
97 => Some(InputInstruction::MoveLeft(s)),//A
|
||||||
|
115 => Some(InputInstruction::MoveBack(s)),//S
|
||||||
|
100 => Some(InputInstruction::MoveRight(s)),//D
|
||||||
|
101 => Some(InputInstruction::MoveUp(s)),//E
|
||||||
|
113 => Some(InputInstruction::MoveDown(s)),//Q
|
||||||
|
32 => Some(InputInstruction::Jump(s)),//Space
|
||||||
|
122 => Some(InputInstruction::Zoom(s)),//Z
|
||||||
|
114 => if s{Some(InputInstruction::Reset)}else{None},//R
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
(k,winit::event::VirtualKeyCode::A) => match k {
|
{
|
||||||
winit::event::ElementState::Pressed => self.camera.controls|=CONTROL_MOVELEFT,
|
self.physics.queue_input_instruction(TimedInstruction{
|
||||||
winit::event::ElementState::Released => self.camera.controls&=!CONTROL_MOVELEFT,
|
time,
|
||||||
|
instruction,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
(k,winit::event::VirtualKeyCode::S) => match k {
|
},
|
||||||
winit::event::ElementState::Pressed => self.camera.controls|=CONTROL_MOVEBACK,
|
winit::event::DeviceEvent::MouseMotion {
|
||||||
winit::event::ElementState::Released => self.camera.controls&=!CONTROL_MOVEBACK,
|
delta,//these (f64,f64) are integers on my machine
|
||||||
}
|
} => {
|
||||||
(k,winit::event::VirtualKeyCode::D) => match k {
|
self.physics.queue_input_instruction(TimedInstruction{
|
||||||
winit::event::ElementState::Pressed => self.camera.controls|=CONTROL_MOVERIGHT,
|
time,
|
||||||
winit::event::ElementState::Released => self.camera.controls&=!CONTROL_MOVERIGHT,
|
instruction:InputInstruction::MoveMouse(glam::ivec2(delta.0 as i32,delta.1 as i32))
|
||||||
}
|
})
|
||||||
(k,winit::event::VirtualKeyCode::E) => match k {
|
},
|
||||||
winit::event::ElementState::Pressed => self.camera.controls|=CONTROL_MOVEUP,
|
winit::event::DeviceEvent::MouseWheel {
|
||||||
winit::event::ElementState::Released => self.camera.controls&=!CONTROL_MOVEUP,
|
delta,//these (f64,f64) are integers on my machine
|
||||||
}
|
} => {
|
||||||
(k,winit::event::VirtualKeyCode::Q) => match k {
|
if self.physics.use_scroll{
|
||||||
winit::event::ElementState::Pressed => self.camera.controls|=CONTROL_MOVEDOWN,
|
self.physics.queue_input_instruction(TimedInstruction{
|
||||||
winit::event::ElementState::Released => self.camera.controls&=!CONTROL_MOVEDOWN,
|
time,
|
||||||
}
|
instruction:InputInstruction::Jump(true)//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump
|
||||||
(k,winit::event::VirtualKeyCode::Space) => match k {
|
})
|
||||||
winit::event::ElementState::Pressed => self.camera.controls|=CONTROL_JUMP,
|
|
||||||
winit::event::ElementState::Released => self.camera.controls&=!CONTROL_JUMP,
|
|
||||||
}
|
|
||||||
(k,winit::event::VirtualKeyCode::Z) => match k {
|
|
||||||
winit::event::ElementState::Pressed => self.camera.controls|=CONTROL_ZOOM,
|
|
||||||
winit::event::ElementState::Released => self.camera.controls&=!CONTROL_ZOOM,
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
self.physics.queue_input_instruction()
|
||||||
|
|
||||||
fn move_mouse(&mut self, delta: (f64,f64)) {
|
|
||||||
self.camera.pitch=(self.camera.pitch as f64+delta.1/-2048.) as f32;
|
|
||||||
self.camera.yaw=(self.camera.yaw as f64+delta.0/-2048.) as f32;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resize(
|
fn resize(
|
||||||
@ -734,7 +678,8 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
_queue: &wgpu::Queue,
|
_queue: &wgpu::Queue,
|
||||||
) {
|
) {
|
||||||
self.depth_view = Self::create_depth_texture(config, device);
|
self.depth_view = Self::create_depth_texture(config, device);
|
||||||
self.camera.screen_size = (config.width, config.height);
|
self.screen_size = (config.width, config.height);
|
||||||
|
self.physics.camera.fov_x=self.physics.camera.fov_y*(config.width as f32)/(config.height as f32);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(
|
fn render(
|
||||||
@ -744,45 +689,15 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
_spawner: &strafe_client::framework::Spawner,
|
_spawner: &strafe_client::framework::Spawner,
|
||||||
) {
|
) {
|
||||||
let camera_mat=glam::Mat3::from_rotation_y(self.camera.yaw);
|
|
||||||
let control_dir=camera_mat*get_control_dir(self.camera.controls&(CONTROL_MOVELEFT|CONTROL_MOVERIGHT|CONTROL_MOVEFORWARD|CONTROL_MOVEBACK)).normalize_or_zero();
|
|
||||||
|
|
||||||
let time=self.start_time.elapsed().as_nanos() as i64;
|
let time=self.start_time.elapsed().as_nanos() as i64;
|
||||||
|
|
||||||
self.physics.run(time);
|
self.physics.run(time);
|
||||||
|
|
||||||
//ALL OF THIS IS TOTALLY WRONG!!!
|
|
||||||
let walk_target_velocity=self.physics.walkspeed*control_dir;
|
|
||||||
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
|
|
||||||
if self.physics.grounded&&walk_target_velocity!=self.physics.walk.target_velocity {
|
|
||||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
|
||||||
time,
|
|
||||||
instruction:strafe_client::body::PhysicsInstruction::SetWalkTargetVelocity(walk_target_velocity)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if control_dir!=self.physics.temp_control_dir {
|
|
||||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
|
||||||
time,
|
|
||||||
instruction:strafe_client::body::PhysicsInstruction::SetControlDir(control_dir)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
self.physics.jump_trying=self.camera.controls&CONTROL_JUMP!=0;
|
|
||||||
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
|
|
||||||
if self.physics.grounded&&self.physics.jump_trying {
|
|
||||||
//scroll will be implemented with InputInstruction::Jump(true) but it blocks setting self.jump_trying=true
|
|
||||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
|
||||||
time,
|
|
||||||
instruction:strafe_client::body::PhysicsInstruction::Jump
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut encoder =
|
let mut encoder =
|
||||||
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||||
|
|
||||||
// update rotation
|
// update rotation
|
||||||
let camera_uniforms = self.camera.to_uniform_data(self.physics.body.extrapolated_position(time));
|
let camera_uniforms = to_uniform_data(self.camera,self.physics.body.extrapolated_position(time));
|
||||||
self.staging_belt
|
self.staging_belt
|
||||||
.write_buffer(
|
.write_buffer(
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
|
Loading…
Reference in New Issue
Block a user