Compare commits
34 Commits
minkowski-
...
refactor-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
ce50fcc082
|
|||
|
c830e67ab7
|
|||
|
42862ce573
|
|||
|
3690954042
|
|||
|
bfe4b491d7
|
|||
|
36f44ffd43
|
|||
|
7f16468104
|
|||
|
a870899743
|
|||
|
b5431c0732
|
|||
|
36ccbdc6b2
|
|||
|
a68f009658
|
|||
|
118a1639a7
|
|||
|
3212fb1d41
|
|||
|
424c7ce9a6
|
|||
|
3174f9caa9
|
|||
|
b8e5343464
|
|||
|
51e7703933
|
|||
|
e46f54efe0
|
|||
|
b2993995bb
|
|||
|
7963c3632b
|
|||
|
67680312dd
|
|||
|
1a0a3403f0
|
|||
|
9e65a6eb95
|
|||
|
ebc897aad8
|
|||
|
23a6655bb0
|
|||
|
0422c223cd
|
|||
|
5db2ce076d
|
|||
|
c98364b68d
|
|||
|
b7e8fb6e18
|
|||
|
d343056664
|
|||
|
534f2a2141
|
|||
|
79ea88fc74
|
|||
|
3fd507be94
|
|||
| 0fbe37e483 |
505
Cargo.lock
generated
505
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
19
Cargo.toml
19
Cargo.toml
@@ -35,3 +35,22 @@ unused_lifetimes = "warn"
|
||||
unused_qualifications = "warn"
|
||||
# variant_size_differences = "warn"
|
||||
unexpected_cfgs = "warn"
|
||||
|
||||
[workspace.dependencies]
|
||||
glam = "0.31.0"
|
||||
|
||||
# engine
|
||||
strafesnet_graphics = { path = "engine/graphics", registry = "strafesnet" }
|
||||
strafesnet_physics = { version = "0.0.1", path = "engine/physics", registry = "strafesnet" }
|
||||
strafesnet_session = { path = "engine/session", registry = "strafesnet" }
|
||||
strafesnet_settings = { path = "engine/settings", registry = "strafesnet" }
|
||||
|
||||
# lib
|
||||
fixed_wide = { version = "0.2.2", path = "lib/fixed_wide", registry = "strafesnet" }
|
||||
linear_ops = { version = "0.1.1", path = "lib/linear_ops", registry = "strafesnet" }
|
||||
ratio_ops = { version = "0.1.0", path = "lib/ratio_ops", registry = "strafesnet" }
|
||||
strafesnet_bsp_loader = { path = "lib/bsp_loader", registry = "strafesnet" }
|
||||
strafesnet_common = { version = "0.8.3", path = "lib/common", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.5.1", path = "lib/deferred_loader", registry = "strafesnet" }
|
||||
strafesnet_rbx_loader = { path = "lib/rbx_loader", registry = "strafesnet" }
|
||||
strafesnet_snf = { version = "0.3.2", path = "lib/snf", registry = "strafesnet" }
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
[package]
|
||||
name = "strafesnet_graphics"
|
||||
version = "0.1.0"
|
||||
version = "0.0.2"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bytemuck = { version = "1.13.1", features = ["derive"] }
|
||||
ddsfile = "0.5.1"
|
||||
glam = "0.30.0"
|
||||
glam.workspace = true
|
||||
id = { version = "0.1.0", registry = "strafesnet" }
|
||||
strafesnet_common = { path = "../../lib/common", registry = "strafesnet" }
|
||||
strafesnet_session = { path = "../session", registry = "strafesnet" }
|
||||
strafesnet_settings = { path = "../settings", registry = "strafesnet" }
|
||||
strafesnet_common.workspace = true
|
||||
wgpu = "28.0.0"
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
use std::collections::{HashSet,HashMap};
|
||||
use strafesnet_common::map;
|
||||
use strafesnet_settings::settings;
|
||||
use strafesnet_session::session;
|
||||
use strafesnet_common::model::{self, ColorId, NormalId, PolygonIter, PositionId, RenderConfigId, TextureCoordinateId, VertexId};
|
||||
use wgpu::{util::DeviceExt,AstcBlock,AstcChannel};
|
||||
use crate::model::{self as model_graphics,IndexedGraphicsMeshOwnedRenderConfig,IndexedGraphicsMeshOwnedRenderConfigId,GraphicsMeshOwnedRenderConfig,GraphicsModelColor4,GraphicsModelOwned,GraphicsVertex};
|
||||
@@ -54,6 +52,10 @@ struct GraphicsPipelines{
|
||||
model:wgpu::RenderPipeline,
|
||||
}
|
||||
|
||||
pub fn view_inv(pos:glam::Vec3,angles:glam::Vec2)->glam::Mat4{
|
||||
//f32 good enough for view matrix
|
||||
glam::Mat4::from_mat3_translation(glam::Mat3::from_euler(glam::EulerRot::YXZ,angles.x,angles.y,0f32),pos)
|
||||
}
|
||||
struct GraphicsCamera{
|
||||
screen_size:glam::UVec2,
|
||||
fov:glam::Vec2,//slope
|
||||
@@ -75,15 +77,10 @@ impl GraphicsCamera{
|
||||
pub fn proj(&self)->glam::Mat4{
|
||||
perspective_rh(self.fov.x,self.fov.y,0.4,4000.0)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
pub fn to_uniform_data(&self,pos:glam::Vec3,angles:glam::Vec2)->[f32;16*4]{
|
||||
pub fn to_uniform_data(&self,view_inv:glam::Mat4)->[f32;16*4]{
|
||||
let proj=self.proj();
|
||||
let proj_inv=proj.inverse();
|
||||
let view_inv=self.world(pos,angles);
|
||||
let view=view_inv.inverse();
|
||||
|
||||
let mut raw=[0f32; 16 * 4];
|
||||
@@ -162,9 +159,6 @@ impl GraphicsState{
|
||||
pub fn clear(&mut self){
|
||||
self.models.clear();
|
||||
}
|
||||
pub fn load_user_settings(&mut self,user_settings:&settings::UserSettings){
|
||||
self.camera.fov=user_settings.calculate_fov(1.0,&self.camera.screen_size).as_vec2();
|
||||
}
|
||||
pub fn generate_models(&mut self,device:&wgpu::Device,queue:&wgpu::Queue,map:&map::CompleteMap){
|
||||
//generate texture view per texture
|
||||
let texture_views:HashMap<model::TextureId,wgpu::TextureView>=map.textures.iter().enumerate().filter_map(|(texture_id,texture_data)|{
|
||||
@@ -634,7 +628,7 @@ impl GraphicsState{
|
||||
// Create the render pipeline
|
||||
let shader=device.create_shader_module(wgpu::ShaderModuleDescriptor{
|
||||
label:None,
|
||||
source:wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("../../../strafe-client/src/shader.wgsl"))),
|
||||
source:wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("../shaders/shader.wgsl"))),
|
||||
});
|
||||
|
||||
//load textures
|
||||
@@ -662,10 +656,10 @@ impl GraphicsState{
|
||||
wgpu::TextureFormat::Astc{
|
||||
block:AstcBlock::B4x4,
|
||||
channel:AstcChannel::UnormSrgb,
|
||||
}=>&include_bytes!("../../../strafe-client/images/astc.dds")[..],
|
||||
wgpu::TextureFormat::Etc2Rgb8UnormSrgb=>&include_bytes!("../../../strafe-client/images/etc2.dds")[..],
|
||||
wgpu::TextureFormat::Bc1RgbaUnormSrgb=>&include_bytes!("../../../strafe-client/images/bc1.dds")[..],
|
||||
wgpu::TextureFormat::Bgra8UnormSrgb=>&include_bytes!("../../../strafe-client/images/bgra.dds")[..],
|
||||
}=>&include_bytes!("../images/astc.dds")[..],
|
||||
wgpu::TextureFormat::Etc2Rgb8UnormSrgb=>&include_bytes!("../images/etc2.dds")[..],
|
||||
wgpu::TextureFormat::Bc1RgbaUnormSrgb=>&include_bytes!("../images/bc1.dds")[..],
|
||||
wgpu::TextureFormat::Bgra8UnormSrgb=>&include_bytes!("../images/bgra.dds")[..],
|
||||
_=>unreachable!(),
|
||||
};
|
||||
|
||||
@@ -708,7 +702,7 @@ impl GraphicsState{
|
||||
|
||||
//squid
|
||||
let squid_texture_view={
|
||||
let bytes=include_bytes!("../../../strafe-client/images/squid.dds");
|
||||
let bytes=include_bytes!("../images/squid.dds");
|
||||
|
||||
let image=ddsfile::Dds::read(&mut std::io::Cursor::new(bytes)).unwrap();
|
||||
|
||||
@@ -833,7 +827,7 @@ impl GraphicsState{
|
||||
});
|
||||
|
||||
let camera=GraphicsCamera::default();
|
||||
let camera_uniforms=camera.to_uniform_data(glam::Vec3::ZERO,glam::Vec2::ZERO);
|
||||
let camera_uniforms=camera.to_uniform_data(view_inv(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),
|
||||
@@ -890,28 +884,25 @@ impl GraphicsState{
|
||||
&mut self,
|
||||
device:&wgpu::Device,
|
||||
config:&wgpu::SurfaceConfiguration,
|
||||
user_settings:&settings::UserSettings,
|
||||
fov:glam::Vec2,
|
||||
){
|
||||
self.depth_view=Self::create_depth_texture(config,device);
|
||||
self.camera.screen_size=glam::uvec2(config.width,config.height);
|
||||
self.load_user_settings(user_settings);
|
||||
self.camera.fov=fov;
|
||||
}
|
||||
pub fn render(
|
||||
&mut self,
|
||||
view:&wgpu::TextureView,
|
||||
device:&wgpu::Device,
|
||||
queue:&wgpu::Queue,
|
||||
frame_state:session::FrameState,
|
||||
camera:glam::Mat4,
|
||||
){
|
||||
//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(
|
||||
frame_state.trajectory.extrapolated_position(frame_state.time).map(Into::<f32>::into).to_array().into(),
|
||||
frame_state.camera.simulate_move_angles(glam::IVec2::ZERO)
|
||||
);
|
||||
let camera_uniforms=self.camera.to_uniform_data(camera);
|
||||
self.staging_belt
|
||||
.write_buffer(
|
||||
&mut encoder,
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod model;
|
||||
pub mod setup;
|
||||
pub mod graphics;
|
||||
|
||||
112
engine/graphics/src/setup.rs
Normal file
112
engine/graphics/src/setup.rs
Normal file
@@ -0,0 +1,112 @@
|
||||
fn optional_features()->wgpu::Features{
|
||||
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
||||
|wgpu::Features::TEXTURE_COMPRESSION_ETC2
|
||||
}
|
||||
fn required_features()->wgpu::Features{
|
||||
wgpu::Features::TEXTURE_COMPRESSION_BC
|
||||
}
|
||||
fn required_downlevel_capabilities()->wgpu::DownlevelCapabilities{
|
||||
wgpu::DownlevelCapabilities{
|
||||
flags:wgpu::DownlevelFlags::empty(),
|
||||
shader_model:wgpu::ShaderModel::Sm5,
|
||||
..wgpu::DownlevelCapabilities::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod step1{
|
||||
pub fn create_instance()->wgpu::Instance{
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod step2{
|
||||
pub fn create_surface<'window>(instance:&wgpu::Instance,target:impl Into<wgpu::SurfaceTarget<'window>>)->Result<wgpu::Surface<'window>,wgpu::CreateSurfaceError>{
|
||||
instance.create_surface(target)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod step3{
|
||||
pub async fn pick_adapter(instance:&wgpu::Instance,surface:&wgpu::Surface<'_>)->Option<wgpu::Adapter>{
|
||||
let backends=wgpu::Backends::from_env().unwrap_or_default();
|
||||
//TODO: prefer adapter that implements optional features
|
||||
//let optional_features=optional_features();
|
||||
let required_features=super::required_features();
|
||||
let required_downlevel_capabilities=super::required_downlevel_capabilities();
|
||||
|
||||
//no helper function smh gotta write it myself
|
||||
let adapters=instance.enumerate_adapters(backends).await;
|
||||
|
||||
let adapter=adapters.into_iter()
|
||||
// reverse because we want to select adapters that appear first in ties,
|
||||
// and max_by_key selects the last equal element in the iterator.
|
||||
.rev()
|
||||
.filter(|adapter|
|
||||
adapter.is_surface_supported(surface)
|
||||
&&adapter.features().contains(required_features)
|
||||
&&{
|
||||
let downlevel_capabilities=adapter.get_downlevel_capabilities();
|
||||
downlevel_capabilities.shader_model>=required_downlevel_capabilities.shader_model
|
||||
&&downlevel_capabilities.flags.contains(required_downlevel_capabilities.flags)
|
||||
}
|
||||
)
|
||||
.max_by_key(|adapter|match adapter.get_info().device_type{
|
||||
wgpu::DeviceType::IntegratedGpu=>3,
|
||||
wgpu::DeviceType::DiscreteGpu=>4,
|
||||
wgpu::DeviceType::VirtualGpu=>2,
|
||||
wgpu::DeviceType::Other|wgpu::DeviceType::Cpu=>1,
|
||||
})?;
|
||||
|
||||
let adapter_info=adapter.get_info();
|
||||
println!("Using {} ({:?})", adapter_info.name, adapter_info.backend);
|
||||
|
||||
Some(adapter)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod step4{
|
||||
pub async fn request_device(adapter:&wgpu::Adapter)->(wgpu::Device,wgpu::Queue){
|
||||
let optional_features=super::optional_features();
|
||||
let required_features=super::required_features();
|
||||
|
||||
// Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface.
|
||||
let needed_limits=crate::graphics::required_limits().using_resolution(adapter.limits());
|
||||
|
||||
let (device, queue)=adapter
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor{
|
||||
label:None,
|
||||
required_features:(optional_features&adapter.features())|required_features,
|
||||
required_limits:needed_limits,
|
||||
memory_hints:wgpu::MemoryHints::Performance,
|
||||
trace:wgpu::Trace::Off,
|
||||
experimental_features:wgpu::ExperimentalFeatures::disabled(),
|
||||
},
|
||||
).await
|
||||
.expect("Unable to find a suitable GPU adapter!");
|
||||
|
||||
(
|
||||
device,
|
||||
queue,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod step5{
|
||||
pub fn configure_surface(
|
||||
adapter:&wgpu::Adapter,
|
||||
device:&wgpu::Device,
|
||||
surface:&wgpu::Surface<'_>,
|
||||
(width,height):(u32,u32),
|
||||
)->wgpu::SurfaceConfiguration{
|
||||
let mut config=surface
|
||||
.get_default_config(adapter, width, height)
|
||||
.expect("Surface isn't supported by the adapter.");
|
||||
|
||||
let surface_view_format=config.format.add_srgb_suffix();
|
||||
config.view_formats.push(surface_view_format);
|
||||
config.present_mode=wgpu::PresentMode::AutoNoVsync;
|
||||
surface.configure(device,&config);
|
||||
|
||||
config
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
[package]
|
||||
name = "strafesnet_physics"
|
||||
version = "0.1.0"
|
||||
version = "0.0.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
arrayvec = "0.7.6"
|
||||
glam = "0.30.0"
|
||||
glam.workspace = true
|
||||
id = { version = "0.1.0", registry = "strafesnet" }
|
||||
strafesnet_common = { path = "../../lib/common", registry = "strafesnet" }
|
||||
strafesnet_common.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
use core::ops::{Bound,RangeBounds};
|
||||
|
||||
use strafesnet_common::integer::{Planar64Vec3,Ratio,Fixed,vec3::Vector3};
|
||||
use crate::model::into_giga_time;
|
||||
use crate::model::{SubmeshVertId,SubmeshEdgeId,SubmeshDirectedEdgeId,SubmeshFaceId,TransformedMesh,GigaTime};
|
||||
use crate::mesh_query::{MeshQuery,MeshTopology,DirectedEdge,UndirectedEdge};
|
||||
use crate::physics::{Time,Trajectory};
|
||||
|
||||
struct AsRefHelper<T>(T);
|
||||
impl<T> AsRef<T> for AsRefHelper<T>{
|
||||
@@ -7,30 +13,31 @@ impl<T> AsRef<T> for AsRefHelper<T>{
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy)]
|
||||
pub struct MinkowskiVert<M0:MeshTopology,M1:MeshTopology>{
|
||||
vert0:M0::Vert,
|
||||
vert1:M1::Vert,
|
||||
//Note that a face on a minkowski mesh refers to a pair of fevs on the meshes it's summed from
|
||||
//(face,vertex)
|
||||
//(edge,edge)
|
||||
//(vertex,face)
|
||||
#[derive(Clone,Copy,Debug,Eq,PartialEq)]
|
||||
pub enum MinkowskiVert{
|
||||
VertVert(SubmeshVertId,SubmeshVertId),
|
||||
}
|
||||
#[derive(Clone,Copy)]
|
||||
pub enum MinkowskiEdge<M0:MeshTopology,M1:MeshTopology>{
|
||||
VertEdge(M0::Vert,M1::Edge),
|
||||
EdgeVert(M0::Edge,M1::Vert),
|
||||
// TODO: remove this
|
||||
impl core::ops::Neg for MinkowskiVert{
|
||||
type Output=Self;
|
||||
fn neg(self)->Self::Output{
|
||||
match self{
|
||||
MinkowskiVert::VertVert(v0,v1)=>MinkowskiVert::VertVert(v1,v0),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone,Copy)]
|
||||
pub enum MinkowskiDirectedEdge<M0:MeshTopology,M1:MeshTopology>{
|
||||
VertEdge(M0::Vert,M1::DirectedEdge),
|
||||
EdgeVert(M0::DirectedEdge,M1::Vert),
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
pub enum MinkowskiEdge{
|
||||
VertEdge(SubmeshVertId,SubmeshEdgeId),
|
||||
EdgeVert(SubmeshEdgeId,SubmeshVertId),
|
||||
//EdgeEdge when edges are parallel
|
||||
}
|
||||
#[derive(Clone,Copy)]
|
||||
pub enum MinkowskiFace<M0:MeshTopology,M1:MeshTopology>{
|
||||
VertFace(M0::Vert,M1::Face),
|
||||
EdgeEdge(M0::Edge,M1::Edge,bool),
|
||||
FaceVert(M0::Face,M1::Vert),
|
||||
}
|
||||
|
||||
impl<M0:MeshTopology,M1:MeshTopology> UndirectedEdge for MinkowskiEdge<M0,M1>{
|
||||
type DirectedEdge=MinkowskiDirectedEdge<M0,M1>;
|
||||
impl UndirectedEdge for MinkowskiEdge{
|
||||
type DirectedEdge=MinkowskiDirectedEdge;
|
||||
fn as_directed(self,parity:bool)->Self::DirectedEdge{
|
||||
match self{
|
||||
MinkowskiEdge::VertEdge(v0,e1)=>MinkowskiDirectedEdge::VertEdge(v0,e1.as_directed(parity)),
|
||||
@@ -38,8 +45,14 @@ impl<M0:MeshTopology,M1:MeshTopology> UndirectedEdge for MinkowskiEdge<M0,M1>{
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<M0:MeshTopology,M1:MeshTopology> DirectedEdge for MinkowskiDirectedEdge<M0,M1>{
|
||||
type UndirectedEdge=MinkowskiEdge<M0,M1>;
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
pub enum MinkowskiDirectedEdge{
|
||||
VertEdge(SubmeshVertId,SubmeshDirectedEdgeId),
|
||||
EdgeVert(SubmeshDirectedEdgeId,SubmeshVertId),
|
||||
//EdgeEdge when edges are parallel
|
||||
}
|
||||
impl DirectedEdge for MinkowskiDirectedEdge{
|
||||
type UndirectedEdge=MinkowskiEdge;
|
||||
fn as_undirected(self)->Self::UndirectedEdge{
|
||||
match self{
|
||||
MinkowskiDirectedEdge::VertEdge(v0,e1)=>MinkowskiEdge::VertEdge(v0,e1.as_undirected()),
|
||||
@@ -48,27 +61,156 @@ impl<M0:MeshTopology,M1:MeshTopology> DirectedEdge for MinkowskiDirectedEdge<M0,
|
||||
}
|
||||
fn parity(&self)->bool{
|
||||
match self{
|
||||
MinkowskiDirectedEdge::VertEdge(_,e)=>e.parity(),
|
||||
MinkowskiDirectedEdge::EdgeVert(e,_)=>e.parity(),
|
||||
MinkowskiDirectedEdge::VertEdge(_,e)
|
||||
|MinkowskiDirectedEdge::EdgeVert(e,_)=>e.parity(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Minkowski<M0,M1>{
|
||||
mesh0:M0,
|
||||
mesh1:M1,
|
||||
#[derive(Clone,Copy,Debug,Hash)]
|
||||
pub enum MinkowskiFace{
|
||||
VertFace(SubmeshVertId,SubmeshFaceId),
|
||||
EdgeEdge(SubmeshEdgeId,SubmeshEdgeId,bool),
|
||||
FaceVert(SubmeshFaceId,SubmeshVertId),
|
||||
//EdgeFace
|
||||
//FaceEdge
|
||||
//FaceFace
|
||||
}
|
||||
|
||||
impl<M0,M1> Minkowski<M0,M1>{
|
||||
pub fn sum(mesh0:M0,mesh1:M1)->Self{
|
||||
Self{mesh0,mesh1}
|
||||
#[derive(Debug)]
|
||||
pub struct MinkowskiMesh<'a>{
|
||||
mesh0:TransformedMesh<'a>,
|
||||
mesh1:TransformedMesh<'a>,
|
||||
}
|
||||
|
||||
// TODO: remove this
|
||||
impl<'a> core::ops::Neg for &MinkowskiMesh<'a>{
|
||||
type Output=MinkowskiMesh<'a>;
|
||||
fn neg(self)->Self::Output{
|
||||
MinkowskiMesh::minkowski_sum(self.mesh1,self.mesh0)
|
||||
}
|
||||
}
|
||||
impl<M0:MeshTopology,M1:MeshTopology> MeshTopology for Minkowski<M0,M1>{
|
||||
type Vert=MinkowskiVert<M0,M1>;
|
||||
type Edge=MinkowskiEdge<M0,M1>;
|
||||
type DirectedEdge=MinkowskiDirectedEdge<M0,M1>;
|
||||
type Face=MinkowskiFace<M0,M1>;
|
||||
|
||||
impl MinkowskiMesh<'_>{
|
||||
pub fn minkowski_sum<'a>(mesh0:TransformedMesh<'a>,mesh1:TransformedMesh<'a>)->MinkowskiMesh<'a>{
|
||||
MinkowskiMesh{
|
||||
mesh0,
|
||||
mesh1,
|
||||
}
|
||||
}
|
||||
pub fn predict_collision_in(&self,trajectory:&Trajectory,range:impl RangeBounds<Time>)->Option<(MinkowskiFace,GigaTime)>{
|
||||
let start_position=match range.start_bound(){
|
||||
Bound::Included(time)=>trajectory.extrapolated_position(*time),
|
||||
Bound::Excluded(time)=>trajectory.extrapolated_position(*time),
|
||||
Bound::Unbounded=>trajectory.position,
|
||||
};
|
||||
let fev=crate::minimum_difference::closest_fev_not_inside(self,start_position)?;
|
||||
//continue forwards along the body parabola
|
||||
fev.crawl(self,trajectory,range.start_bound(),range.end_bound()).hit()
|
||||
}
|
||||
pub fn predict_collision_out(&self,trajectory:&Trajectory,range:impl RangeBounds<Time>)->Option<(MinkowskiFace,GigaTime)>{
|
||||
let (lower_bound,upper_bound)=(range.start_bound(),range.end_bound());
|
||||
// TODO: handle unbounded collision using infinity fev
|
||||
let start_position=match upper_bound{
|
||||
Bound::Included(time)=>trajectory.extrapolated_position(*time),
|
||||
Bound::Excluded(time)=>trajectory.extrapolated_position(*time),
|
||||
Bound::Unbounded=>trajectory.position,
|
||||
};
|
||||
let fev=crate::minimum_difference::closest_fev_not_inside(self,start_position)?;
|
||||
// swap and negate bounds to do a time inversion
|
||||
let (lower_bound,upper_bound)=(upper_bound.map(|&t|-t),lower_bound.map(|&t|-t));
|
||||
let time_reversed_trajectory=-trajectory;
|
||||
//continue backwards along the body parabola
|
||||
fev.crawl(self,&time_reversed_trajectory,lower_bound.as_ref(),upper_bound.as_ref()).hit()
|
||||
//no need to test -time<time_limit because of the first step
|
||||
.map(|(face,time)|(face,-time))
|
||||
}
|
||||
pub fn predict_collision_face_out(&self,trajectory:&Trajectory,range:impl RangeBounds<Time>,contact_face_id:MinkowskiFace)->Option<(MinkowskiDirectedEdge,GigaTime)>{
|
||||
// TODO: make better
|
||||
use crate::face_crawler::{low,upp};
|
||||
//no algorithm needed, there is only one state and two cases (Edge,None)
|
||||
//determine when it passes an edge ("sliding off" case)
|
||||
let start_time=range.start_bound().map(|&t|(t-trajectory.time).to_ratio());
|
||||
let mut best_time=range.end_bound().map(|&t|into_giga_time(t,trajectory.time));
|
||||
let mut best_edge=None;
|
||||
let face_n=self.face_nd(contact_face_id).0;
|
||||
self.for_each_face_edge(contact_face_id,|directed_edge_id|{
|
||||
let edge_n=self.directed_edge_n(directed_edge_id);
|
||||
//f x e points in
|
||||
let n=face_n.cross(edge_n);
|
||||
let &[v0,v1]=self.edge_verts(directed_edge_id.as_undirected()).as_ref();
|
||||
let d=n.dot(self.vert(v0)+self.vert(v1));
|
||||
//WARNING! d outside of *2
|
||||
//WARNING: truncated precision
|
||||
//wrap for speed
|
||||
for dt in Fixed::<4,128>::zeroes2(((n.dot(trajectory.position))*2-d).wrap_4(),n.dot(trajectory.velocity).wrap_4()*2,n.dot(trajectory.acceleration).wrap_4()){
|
||||
if low(&start_time,&dt)&&upp(&dt,&best_time)&&n.dot(trajectory.extrapolated_velocity_ratio_dt(dt)).is_negative(){
|
||||
best_time=Bound::Included(dt);
|
||||
best_edge=Some((directed_edge_id,dt));
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
best_edge
|
||||
}
|
||||
pub fn contains_point(&self,point:Planar64Vec3)->bool{
|
||||
crate::minimum_difference::contains_point(self,point)
|
||||
}
|
||||
}
|
||||
impl MeshQuery for MinkowskiMesh<'_>{
|
||||
type Direction=Planar64Vec3;
|
||||
type Position=Planar64Vec3;
|
||||
type Normal=Vector3<Fixed<3,96>>;
|
||||
type Offset=Fixed<4,128>;
|
||||
// TODO: relative d
|
||||
fn face_nd(&self,face_id:MinkowskiFace)->(Self::Normal,Self::Offset){
|
||||
match face_id{
|
||||
MinkowskiFace::VertFace(v0,f1)=>{
|
||||
let (n,d)=self.mesh1.face_nd(f1);
|
||||
(-n,d-n.dot(self.mesh0.vert(v0)))
|
||||
},
|
||||
MinkowskiFace::EdgeEdge(e0,e1,parity)=>{
|
||||
let edge0_n=self.mesh0.edge_n(e0);
|
||||
let edge1_n=self.mesh1.edge_n(e1);
|
||||
let &[e0v0,e0v1]=self.mesh0.edge_verts(e0).as_ref();
|
||||
let &[e1v0,e1v1]=self.mesh1.edge_verts(e1).as_ref();
|
||||
let n=edge0_n.cross(edge1_n);
|
||||
let e0d=n.dot(self.mesh0.vert(e0v0)+self.mesh0.vert(e0v1));
|
||||
let e1d=n.dot(self.mesh1.vert(e1v0)+self.mesh1.vert(e1v1));
|
||||
((n*(parity as i64*4-2)).widen_3(),((e0d-e1d)*(parity as i64*2-1)).widen_4())
|
||||
},
|
||||
MinkowskiFace::FaceVert(f0,v1)=>{
|
||||
let (n,d)=self.mesh0.face_nd(f0);
|
||||
(n,d-n.dot(self.mesh1.vert(v1)))
|
||||
},
|
||||
}
|
||||
}
|
||||
fn vert(&self,vert_id:MinkowskiVert)->Planar64Vec3{
|
||||
match vert_id{
|
||||
MinkowskiVert::VertVert(v0,v1)=>{
|
||||
self.mesh0.vert(v0)-self.mesh1.vert(v1)
|
||||
},
|
||||
}
|
||||
}
|
||||
fn hint_point(&self)->Planar64Vec3{
|
||||
self.mesh0.hint_point()-self.mesh1.hint_point()
|
||||
}
|
||||
fn farthest_vert(&self,dir:Planar64Vec3)->MinkowskiVert{
|
||||
MinkowskiVert::VertVert(self.mesh0.farthest_vert(dir),self.mesh1.farthest_vert(-dir))
|
||||
}
|
||||
fn edge_n(&self,edge_id:Self::Edge)->Self::Direction{
|
||||
let &[v0,v1]=self.edge_verts(edge_id).as_ref();
|
||||
self.vert(v1)-self.vert(v0)
|
||||
}
|
||||
fn directed_edge_n(&self,directed_edge_id:Self::DirectedEdge)->Self::Direction{
|
||||
let &[v0,v1]=self.edge_verts(directed_edge_id.as_undirected()).as_ref();
|
||||
(self.vert(v1)-self.vert(v0))*((directed_edge_id.parity() as i64)*2-1)
|
||||
}
|
||||
}
|
||||
impl MeshTopology for MinkowskiMesh<'_>{
|
||||
type Face=MinkowskiFace;
|
||||
type Edge=MinkowskiEdge;
|
||||
type DirectedEdge=MinkowskiDirectedEdge;
|
||||
type Vert=MinkowskiVert;
|
||||
fn for_each_vert_edge(&self,vert_id:Self::Vert,mut f:impl FnMut(Self::DirectedEdge)){
|
||||
match vert_id{
|
||||
MinkowskiVert::VertVert(v0,v1)=>{
|
||||
@@ -233,67 +375,33 @@ impl<M0:MeshTopology,M1:MeshTopology> MeshTopology for Minkowski<M0,M1>{
|
||||
}
|
||||
}
|
||||
|
||||
use strafesnet_common::integer::vec3::Vector3;
|
||||
use strafesnet_common::integer::Fixed;
|
||||
impl<M0:MeshQuery,M1:MeshQuery> MeshQuery for Minkowski<M0,M1>
|
||||
where
|
||||
M0:MeshQuery<
|
||||
Direction=Vector3<Fixed<1,32>>,
|
||||
Position=Vector3<Fixed<1,32>>,
|
||||
Normal=Vector3<Fixed<3,96>>,
|
||||
Offset=Fixed<4,128>,
|
||||
>,
|
||||
M1:MeshQuery<
|
||||
Direction=Vector3<Fixed<1,32>>,
|
||||
Position=Vector3<Fixed<1,32>>,
|
||||
Normal=Vector3<Fixed<3,96>>,
|
||||
Offset=Fixed<4,128>,
|
||||
>,
|
||||
{
|
||||
type Direction=M0::Direction;
|
||||
type Position=M0::Position;
|
||||
type Normal=M0::Normal;
|
||||
type Offset=M0::Offset;
|
||||
fn vert(&self,vert_id:MinkowskiVert<M0,M1>)->Planar64Vec3{
|
||||
self.mesh0.vert(vert_id.vert0)-self.mesh1.vert(vert_id.vert1)
|
||||
}
|
||||
fn face_nd(&self,face_id:MinkowskiFace<M0,M1>)->(Self::Normal,Self::Offset){
|
||||
match face_id{
|
||||
MinkowskiFace::VertFace(v0,f1)=>{
|
||||
let (n,d)=self.mesh1.face_nd(f1);
|
||||
(-n,d-n.dot(self.mesh0.vert(v0)))
|
||||
},
|
||||
MinkowskiFace::EdgeEdge(e0,e1,parity)=>{
|
||||
let edge0_n=self.mesh0.edge_n(e0);
|
||||
let edge1_n=self.mesh1.edge_n(e1);
|
||||
let &[e0v0,e0v1]=self.mesh0.edge_verts(e0).as_ref();
|
||||
let &[e1v0,e1v1]=self.mesh1.edge_verts(e1).as_ref();
|
||||
let n=edge0_n.cross(edge1_n);
|
||||
let e0d=n.dot(self.mesh0.vert(e0v0)+self.mesh0.vert(e0v1));
|
||||
let e1d=n.dot(self.mesh1.vert(e1v0)+self.mesh1.vert(e1v1));
|
||||
((n*(parity as i64*4-2)).widen_3(),((e0d-e1d)*(parity as i64*2-1)).widen_4())
|
||||
},
|
||||
MinkowskiFace::FaceVert(f0,v1)=>{
|
||||
let (n,d)=self.mesh0.face_nd(f0);
|
||||
(n,d-n.dot(self.mesh1.vert(v1)))
|
||||
},
|
||||
fn is_empty_volume(normals:&[Vector3<Fixed<3,96>>])->bool{
|
||||
let len=normals.len();
|
||||
for i in 0..len-1{
|
||||
for j in i+1..len{
|
||||
let n=normals[i].cross(normals[j]);
|
||||
let mut d_comp=None;
|
||||
for k in 0..len{
|
||||
if k!=i&&k!=j{
|
||||
let d=n.dot(normals[k]).is_negative();
|
||||
if let &Some(comp)=&d_comp{
|
||||
// This is testing if d_comp*d < 0
|
||||
if comp^d{
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
d_comp=Some(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fn hint_point(&self)->Planar64Vec3{
|
||||
self.mesh0.hint_point()-self.mesh1.hint_point()
|
||||
}
|
||||
fn farthest_vert(&self,dir:Planar64Vec3)->MinkowskiVert{
|
||||
MinkowskiVert{
|
||||
vert0:self.mesh0.farthest_vert(dir),
|
||||
vert1:self.mesh1.farthest_vert(-dir),
|
||||
}
|
||||
}
|
||||
fn edge_n(&self,edge_id:Self::Edge)->Self::Direction{
|
||||
let &[v0,v1]=self.edge_verts(edge_id).as_ref();
|
||||
self.vert(v1)-self.vert(v0)
|
||||
}
|
||||
fn directed_edge_n(&self,directed_edge_id:Self::DirectedEdge)->Self::Direction{
|
||||
let &[v0,v1]=self.edge_verts(directed_edge_id.as_undirected()).as_ref();
|
||||
(self.vert(v1)-self.vert(v0))*((directed_edge_id.parity() as i64)*2-1)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_empty_volume(){
|
||||
use strafesnet_common::integer::vec3;
|
||||
assert!(!is_empty_volume(&[vec3::X.widen_3(),vec3::Y.widen_3(),vec3::Z.widen_3()]));
|
||||
assert!(is_empty_volume(&[vec3::X.widen_3(),vec3::Y.widen_3(),vec3::Z.widen_3(),vec3::NEG_X.widen_3()]));
|
||||
}
|
||||
|
||||
@@ -57,6 +57,9 @@ impl InputState{
|
||||
fn replace_mouse(&mut self,mouse:MouseState,next_mouse:MouseState){
|
||||
(self.next_mouse,self.mouse)=(next_mouse,mouse);
|
||||
}
|
||||
fn get_control(&self,control:Controls)->bool{
|
||||
self.controls.contains(control)
|
||||
}
|
||||
fn set_control(&mut self,control:Controls,state:bool){
|
||||
self.controls.set(control,state)
|
||||
}
|
||||
@@ -265,6 +268,12 @@ pub struct PhysicsCamera{
|
||||
impl PhysicsCamera{
|
||||
const ANGLE_PITCH_LOWER_LIMIT:Angle32=Angle32::NEG_FRAC_PI_2;
|
||||
const ANGLE_PITCH_UPPER_LIMIT:Angle32=Angle32::FRAC_PI_2;
|
||||
fn set_sensitivity(&mut self,sensitivity:Ratio64Vec2){
|
||||
// Calculate nearest mouse position in new sensitivity
|
||||
self.clamped_mouse_pos.x=(self.clamped_mouse_pos.x as i128*self.sensitivity.x.num() as i128*sensitivity.x.den() as i128/(sensitivity.x.num() as i128*self.sensitivity.x.den() as i128)) as i32;
|
||||
self.clamped_mouse_pos.y=(self.clamped_mouse_pos.y as i128*self.sensitivity.y.num() as i128*sensitivity.y.den() as i128/(sensitivity.y.num() as i128*self.sensitivity.y.den() as i128)) as i32;
|
||||
self.sensitivity=sensitivity;
|
||||
}
|
||||
pub fn move_mouse(&mut self,mouse_delta:glam::IVec2){
|
||||
let mut unclamped_mouse_pos=self.clamped_mouse_pos+mouse_delta;
|
||||
unclamped_mouse_pos.y=unclamped_mouse_pos.y.clamp(
|
||||
@@ -922,6 +931,9 @@ impl PhysicsState{
|
||||
pub fn get_finish_time(&self)->Option<run::Time>{
|
||||
self.run.get_finish_time()
|
||||
}
|
||||
fn is_no_clip_enabled(&self)->bool{
|
||||
self.input_state.get_control(Controls::Sprint)
|
||||
}
|
||||
pub fn clear(&mut self){
|
||||
self.touching.clear();
|
||||
}
|
||||
@@ -1195,6 +1207,11 @@ fn next_instruction_internal(state:&PhysicsState,data:&PhysicsData,time_limit:Ti
|
||||
let trajectory=state.body.with_acceleration(state.acceleration(data));
|
||||
//check for collision ends
|
||||
state.touching.predict_collision_end(&mut collector,&data.models,&data.hitbox_mesh,&trajectory,state.time);
|
||||
|
||||
if state.is_no_clip_enabled(){
|
||||
return collector.take();
|
||||
}
|
||||
|
||||
//check for collision starts
|
||||
let mut aabb=aabb::Aabb::default();
|
||||
trajectory.grow_aabb(&mut aabb,state.time,collector.time());
|
||||
@@ -1862,10 +1879,11 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
state.input_state.set_next_mouse(m);
|
||||
},
|
||||
Instruction::Mouse(MouseInstruction::ReplaceMouse{m0,m1})=>{
|
||||
state.camera.move_mouse(m0.pos-state.input_state.mouse.pos);
|
||||
state.camera.move_mouse(state.input_state.mouse_delta());
|
||||
state.camera.move_mouse(m0.pos-state.input_state.next_mouse.pos);
|
||||
state.input_state.replace_mouse(m0,m1);
|
||||
},
|
||||
Instruction::Misc(MiscInstruction::SetSensitivity(sensitivity))=>state.camera.sensitivity=sensitivity,
|
||||
Instruction::Misc(MiscInstruction::SetSensitivity(sensitivity))=>state.camera.set_sensitivity(sensitivity),
|
||||
Instruction::SetControl(SetControlInstruction::SetMoveForward(s))=>state.input_state.set_control(Controls::MoveForward,s),
|
||||
Instruction::SetControl(SetControlInstruction::SetMoveLeft(s))=>state.input_state.set_control(Controls::MoveLeft,s),
|
||||
Instruction::SetControl(SetControlInstruction::SetMoveBack(s))=>state.input_state.set_control(Controls::MoveBackward,s),
|
||||
|
||||
@@ -4,12 +4,12 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
glam = "0.30.0"
|
||||
glam.workspace = true
|
||||
replace_with = "0.1.7"
|
||||
strafesnet_common = { path = "../../lib/common", registry = "strafesnet" }
|
||||
strafesnet_physics = { path = "../physics", registry = "strafesnet" }
|
||||
strafesnet_settings = { path = "../settings", registry = "strafesnet" }
|
||||
strafesnet_snf = { path = "../../lib/snf", registry = "strafesnet" }
|
||||
strafesnet_common.workspace = true
|
||||
strafesnet_physics.workspace = true
|
||||
strafesnet_settings.workspace = true
|
||||
strafesnet_snf.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -61,6 +61,14 @@ pub struct FrameState{
|
||||
pub camera:physics::PhysicsCamera,
|
||||
pub time:PhysicsTime,
|
||||
}
|
||||
impl FrameState{
|
||||
pub fn pos(&self)->glam::Vec3{
|
||||
self.trajectory.extrapolated_position(self.time).map(Into::<f32>::into).to_array().into()
|
||||
}
|
||||
pub fn angles(&self)->glam::Vec2{
|
||||
self.camera.simulate_move_angles(glam::IVec2::ZERO)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Simulation{
|
||||
timer:Timer<Scaled<SessionTimeInner,PhysicsTimeInner>>,
|
||||
|
||||
@@ -6,8 +6,8 @@ edition = "2024"
|
||||
[dependencies]
|
||||
configparser = "3.0.2"
|
||||
directories = "6.0.0"
|
||||
glam = "0.30.0"
|
||||
strafesnet_common = { path = "../../lib/common", registry = "strafesnet" }
|
||||
glam.workspace = true
|
||||
strafesnet_common.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -4,12 +4,12 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
glam = "0.30.0"
|
||||
strafesnet_common = { path = "../lib/common", registry = "strafesnet" }
|
||||
strafesnet_physics = { path = "../engine/physics", registry = "strafesnet" }
|
||||
strafesnet_snf = { path = "../lib/snf", registry = "strafesnet" }
|
||||
glam.workspace = true
|
||||
strafesnet_common.workspace = true
|
||||
strafesnet_physics.workspace = true
|
||||
strafesnet_snf.workspace = true
|
||||
# this is just for the primitive constructor
|
||||
strafesnet_rbx_loader = { path = "../lib/rbx_loader", registry = "strafesnet" }
|
||||
strafesnet_rbx_loader.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -10,9 +10,9 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
glam = "0.30.0"
|
||||
strafesnet_common = { version = "0.7.0", path = "../common", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.5.1", path = "../deferred_loader", registry = "strafesnet" }
|
||||
glam.workspace = true
|
||||
strafesnet_common.workspace = true
|
||||
strafesnet_deferred_loader.workspace = true
|
||||
vbsp = "0.9.1"
|
||||
vbsp-entities-css = "0.6.0"
|
||||
vmdl = "0.2.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafesnet_common"
|
||||
version = "0.7.0"
|
||||
version = "0.8.3"
|
||||
edition = "2024"
|
||||
repository = "https://git.itzana.me/StrafesNET/strafe-project"
|
||||
license = "MIT OR Apache-2.0"
|
||||
@@ -12,10 +12,10 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
[dependencies]
|
||||
arrayvec = "0.7.4"
|
||||
bitflags = "2.6.0"
|
||||
fixed_wide = { version = "0.2.0", path = "../fixed_wide", registry = "strafesnet", features = ["deferred-division","zeroes","wide-mul"] }
|
||||
linear_ops = { version = "0.1.1", path = "../linear_ops", registry = "strafesnet", features = ["deferred-division","named-fields"] }
|
||||
ratio_ops = { version = "0.1.0", path = "../ratio_ops", registry = "strafesnet" }
|
||||
glam = "0.30.0"
|
||||
fixed_wide = { workspace = true, features = ["deferred-division","zeroes","wide-mul"] }
|
||||
linear_ops = { workspace = true, features = ["deferred-division","named-fields"] }
|
||||
ratio_ops = { workspace = true }
|
||||
glam.workspace = true
|
||||
id = { version = "0.1.0", registry = "strafesnet" }
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -149,10 +149,23 @@ impl_time_i64_rhs_operator!(Shr,shr);
|
||||
impl_time_i64_rhs_operator!(Shl,shl);
|
||||
impl<T> core::ops::Mul<Time<T>> for Planar64{
|
||||
type Output=Ratio<Fixed<2,64>,Planar64>;
|
||||
#[inline]
|
||||
fn mul(self,rhs:Time<T>)->Self::Output{
|
||||
Ratio::new(self*Fixed::raw(rhs.0),Planar64::raw(1_000_000_000))
|
||||
}
|
||||
}
|
||||
impl<T> From<Time<T>> for f32{
|
||||
#[inline]
|
||||
fn from(value:Time<T>)->Self{
|
||||
value.get() as f32/Time::<T>::ONE_SECOND.get() as f32
|
||||
}
|
||||
}
|
||||
impl<T> From<Time<T>> for f64{
|
||||
#[inline]
|
||||
fn from(value:Time<T>)->Self{
|
||||
value.get() as f64/Time::<T>::ONE_SECOND.get() as f64
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod test_time{
|
||||
use super::*;
|
||||
@@ -214,11 +227,11 @@ impl Ratio64{
|
||||
}
|
||||
#[inline]
|
||||
pub const fn mul_int(&self,rhs:i64)->i64{
|
||||
rhs*self.num/(self.den as i64)
|
||||
(rhs as i128*self.num as i128/self.den as i128) as i64
|
||||
}
|
||||
#[inline]
|
||||
pub const fn rhs_div_int(&self,rhs:i64)->i64{
|
||||
rhs*(self.den as i64)/self.num
|
||||
(rhs as i128*self.den as i128/self.num as i128) as i64
|
||||
}
|
||||
#[inline]
|
||||
pub const fn mul_ref(&self,rhs:&Ratio64)->Ratio64{
|
||||
@@ -263,7 +276,6 @@ fn integer_decode_f64(f: f64) -> (u64, i16, i8) {
|
||||
pub enum Ratio64TryFromFloatError{
|
||||
Nan,
|
||||
Infinite,
|
||||
Subnormal,
|
||||
HighlyNegativeExponent(i16),
|
||||
HighlyPositiveExponent(i16),
|
||||
}
|
||||
@@ -298,8 +310,10 @@ fn ratio64_from_mes((m,e,s):(u64,i16,i8))->Result<Ratio64,Ratio64TryFromFloatErr
|
||||
|
||||
Ok(Ratio64::new(num as i64,den as u64).unwrap())
|
||||
}else if e<0{
|
||||
// simple exact representation
|
||||
Ok(Ratio64::new((m as i64)*(s as i64),1<<-e).unwrap())
|
||||
}else if (64-m.leading_zeros() as i16)+e<64{
|
||||
// integer
|
||||
Ok(Ratio64::new((m as i64)*(s as i64)*(1<<e),1).unwrap())
|
||||
}else{
|
||||
Err(Ratio64TryFromFloatError::HighlyPositiveExponent(e))
|
||||
@@ -331,6 +345,29 @@ impl TryFrom<f64> for Ratio64{
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
fn req(r0:Ratio64,r1:Ratio64){
|
||||
println!("r0={r0:?} r1={r1:?}");
|
||||
assert_eq!(r0.num(),r1.num(),"Nums not eq");
|
||||
assert_eq!(r0.den(),r1.den(),"Dens not eq");
|
||||
}
|
||||
#[test]
|
||||
fn test_ratio64_from_float(){
|
||||
req(2.0.try_into().unwrap(),Ratio64::new(2,1).unwrap());
|
||||
req(1.0.try_into().unwrap(),Ratio64::new(1,1).unwrap());
|
||||
req(0.5.try_into().unwrap(),Ratio64::new(1,2).unwrap());
|
||||
req(1.1.try_into().unwrap(),Ratio64::new(2476979795053773,2251799813685248).unwrap());
|
||||
req(0.8.try_into().unwrap(),Ratio64::new(3602879701896397,4503599627370496).unwrap());
|
||||
req(0.61.try_into().unwrap(),Ratio64::new(5494391545392005,9007199254740992).unwrap());
|
||||
req(0.01.try_into().unwrap(),Ratio64::new(5764607523034235,576460752303423488).unwrap());
|
||||
req(0.001.try_into().unwrap(),Ratio64::new(1152921504606847,1152921504606846976).unwrap());
|
||||
req(0.00001.try_into().unwrap(),Ratio64::new(89605456633725,8960545663372499267).unwrap());
|
||||
req(0.00000000001.try_into().unwrap(),Ratio64::new(35204848,3520484800000000213).unwrap());
|
||||
req(0.000000000000000001.try_into().unwrap(),Ratio64::new(11,10999999999999999213).unwrap());
|
||||
req(2222222222222.0.try_into().unwrap(),Ratio64::new(2222222222222,1).unwrap());
|
||||
req(core::f64::consts::PI.try_into().unwrap(),Ratio64::new(884279719003555,281474976710656).unwrap());
|
||||
}
|
||||
|
||||
impl std::ops::Mul<Ratio64> for Ratio64{
|
||||
type Output=Ratio64;
|
||||
#[inline]
|
||||
|
||||
@@ -53,36 +53,23 @@ impl std::fmt::Display for Error{
|
||||
impl std::error::Error for Error{}
|
||||
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
enum RunState{
|
||||
pub enum RunState{
|
||||
Created,
|
||||
Started{timer:TimerFixed<Realtime<PhysicsTimeInner,TimeInner>,Unpaused>},
|
||||
Finished{timer:TimerFixed<Realtime<PhysicsTimeInner,TimeInner>,Paused>},
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
pub struct Run{
|
||||
state:RunState,
|
||||
flagged:Option<FlagReason>,
|
||||
}
|
||||
|
||||
impl Run{
|
||||
pub fn new()->Self{
|
||||
Self{
|
||||
state:RunState::Created,
|
||||
flagged:None,
|
||||
}
|
||||
}
|
||||
impl RunState{
|
||||
pub fn time(&self,time:PhysicsTime)->Time{
|
||||
match &self.state{
|
||||
match &self{
|
||||
RunState::Created=>Time::ZERO,
|
||||
RunState::Started{timer}=>timer.time(time),
|
||||
RunState::Finished{timer}=>timer.time(),
|
||||
}
|
||||
}
|
||||
pub fn start(&mut self,time:PhysicsTime)->Result<(),Error>{
|
||||
match &self.state{
|
||||
match &self{
|
||||
RunState::Created=>{
|
||||
self.state=RunState::Started{
|
||||
*self=RunState::Started{
|
||||
timer:TimerFixed::new(time,Time::ZERO),
|
||||
};
|
||||
Ok(())
|
||||
@@ -93,10 +80,10 @@ impl Run{
|
||||
}
|
||||
pub fn finish(&mut self,time:PhysicsTime)->Result<(),Error>{
|
||||
//this uses Copy
|
||||
match &self.state{
|
||||
match &self{
|
||||
RunState::Created=>Err(Error::NotStarted),
|
||||
RunState::Started{timer}=>{
|
||||
self.state=RunState::Finished{
|
||||
*self=RunState::Finished{
|
||||
timer:timer.into_paused(time),
|
||||
};
|
||||
Ok(())
|
||||
@@ -104,12 +91,39 @@ impl Run{
|
||||
RunState::Finished{..}=>Err(Error::AlreadyFinished),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
pub struct Run{
|
||||
state:RunState,
|
||||
flag_reason:Option<FlagReason>,
|
||||
}
|
||||
|
||||
impl Run{
|
||||
pub fn new()->Self{
|
||||
Self{
|
||||
state:RunState::Created,
|
||||
flag_reason:None,
|
||||
}
|
||||
}
|
||||
pub fn time(&self,time:PhysicsTime)->Time{
|
||||
self.state.time(time)
|
||||
}
|
||||
pub fn start(&mut self,time:PhysicsTime)->Result<(),Error>{
|
||||
self.state.start(time)
|
||||
}
|
||||
pub fn finish(&mut self,time:PhysicsTime)->Result<(),Error>{
|
||||
self.state.finish(time)
|
||||
}
|
||||
pub fn flag(&mut self,flag_reason:FlagReason){
|
||||
//don't replace the first reason the run was flagged
|
||||
if self.flagged.is_none(){
|
||||
self.flagged=Some(flag_reason);
|
||||
if self.flag_reason.is_none(){
|
||||
self.flag_reason=Some(flag_reason);
|
||||
}
|
||||
}
|
||||
pub fn flag_reason(&self)->Option<FlagReason>{
|
||||
self.flag_reason
|
||||
}
|
||||
pub fn get_finish_time(&self)->Option<Time>{
|
||||
match &self.state{
|
||||
RunState::Finished{timer}=>Some(timer.time()),
|
||||
|
||||
@@ -10,7 +10,7 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
strafesnet_common = { version = "0.7.0", path = "../common", registry = "strafesnet" }
|
||||
strafesnet_common.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fixed_wide"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2024"
|
||||
repository = "https://git.itzana.me/StrafesNET/strafe-project"
|
||||
license = "MIT OR Apache-2.0"
|
||||
@@ -17,7 +17,7 @@ zeroes=["dep:arrayvec"]
|
||||
bnum = "0.13.0"
|
||||
arrayvec = { version = "0.7.6", optional = true }
|
||||
paste = "1.0.15"
|
||||
ratio_ops = { version = "0.1.0", path = "../ratio_ops", registry = "strafesnet", optional = true }
|
||||
ratio_ops = { workspace = true, optional = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -7,7 +7,7 @@ const BNUM_DIGIT_WIDTH:usize=64;
|
||||
/// N is the number of u64s to use
|
||||
/// F is the number of fractional bits (always N*32 lol)
|
||||
pub struct Fixed<const N:usize,const F:usize>{
|
||||
pub(crate)bits:BInt<{N}>,
|
||||
bits:BInt<{N}>,
|
||||
}
|
||||
|
||||
impl<const N:usize,const F:usize> Fixed<N,F>{
|
||||
@@ -545,7 +545,7 @@ impl_shift_operator!( Fixed, Shr, shr, Self );
|
||||
|
||||
// wide operators. The result width is the sum of the input widths, i.e. none of the multiplication
|
||||
|
||||
#[expect(unused_macros)]
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! impl_wide_operators{
|
||||
($lhs:expr,$rhs:expr)=>{
|
||||
impl core::ops::Mul<Fixed<$rhs,{$rhs*32}>> for Fixed<$lhs,{$lhs*32}>{
|
||||
|
||||
@@ -14,12 +14,12 @@ fixed-wide=["dep:fixed_wide","dep:paste"]
|
||||
deferred-division=["dep:ratio_ops"]
|
||||
|
||||
[dependencies]
|
||||
ratio_ops = { version = "0.1.0", path = "../ratio_ops", registry = "strafesnet", optional = true }
|
||||
fixed_wide = { version = "0.2.0", path = "../fixed_wide", registry = "strafesnet", optional = true }
|
||||
ratio_ops = { workspace = true, optional = true }
|
||||
fixed_wide = { workspace = true, optional = true }
|
||||
paste = { version = "1.0.15", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
fixed_wide = { path = "../fixed_wide", registry = "strafesnet", features = ["wide-mul"] }
|
||||
fixed_wide = { workspace = true, features = ["wide-mul"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -11,13 +11,13 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
bytemuck = "1.14.3"
|
||||
glam = "0.30.0"
|
||||
glam.workspace = true
|
||||
regex = { version = "1.11.3", default-features = false, features = ["unicode-perl"] }
|
||||
rbx_mesh = "0.5.0"
|
||||
rbxassetid = { version = "0.1.0", path = "../rbxassetid", registry = "strafesnet" }
|
||||
roblox_emulator = { version = "0.5.1", path = "../roblox_emulator", default-features = false, registry = "strafesnet" }
|
||||
strafesnet_common = { version = "0.7.0", path = "../common", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.5.1", path = "../deferred_loader", registry = "strafesnet" }
|
||||
strafesnet_common.workspace = true
|
||||
strafesnet_deferred_loader.workspace = true
|
||||
rbx_binary = "2.0.1"
|
||||
rbx_dom_weak = "4.1.0"
|
||||
rbx_reflection = "6.1.0"
|
||||
|
||||
@@ -867,6 +867,11 @@ impl PartialMap1<'_>{
|
||||
deferred_model_deferred_attributes.model.mesh,
|
||||
deferred_model_deferred_attributes.render
|
||||
)?;
|
||||
// If the mesh size is zero we can't auto-scale it, throw it out.
|
||||
if mesh_size.x==integer::Fixed::ZERO||mesh_size.y==integer::Fixed::ZERO||mesh_size.z==integer::Fixed::ZERO{
|
||||
print!("[rbx_loader] Mesh with zero size!");
|
||||
return None;
|
||||
}
|
||||
Some(ModelDeferredAttributes{
|
||||
mesh,
|
||||
deferred_attributes:deferred_model_deferred_attributes.model.deferred_attributes,
|
||||
|
||||
@@ -104,7 +104,7 @@ fn build_mesh2(
|
||||
if let Some(normal_id)=normal_agreement_checker.into_agreed_normal(){
|
||||
polygon_groups_normal_id[normal_id as usize-1].push(face);
|
||||
}else{
|
||||
panic!("Empty face!");
|
||||
print!("[union] Empty face!");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -158,7 +158,7 @@ fn build_mesh5(
|
||||
if let Some(normal_id)=normal_agreement_checker.into_agreed_normal(){
|
||||
polygon_groups_normal_id[normal_id as usize-1].push(face);
|
||||
}else{
|
||||
panic!("Empty face!");
|
||||
print!("[union] Empty face!");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -12,7 +12,7 @@ default=["run-service"]
|
||||
run-service=[]
|
||||
|
||||
[dependencies]
|
||||
glam = "0.30.0"
|
||||
glam.workspace = true
|
||||
mlua = { version = "0.11.3", features = ["luau"] }
|
||||
phf = { version = "0.13.1", features = ["macros"] }
|
||||
rbx_dom_weak = "4.1.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafesnet_snf"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
edition = "2024"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@@ -8,7 +8,7 @@ edition = "2024"
|
||||
[dependencies]
|
||||
binrw = "0.15.0"
|
||||
id = { version = "0.1.0", registry = "strafesnet" }
|
||||
strafesnet_common = { version = "0.7.0", path = "../common", registry = "strafesnet" }
|
||||
strafesnet_common.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -81,6 +81,15 @@ pub struct SegmentId(u32);
|
||||
pub struct Segment{
|
||||
pub instructions:Vec<TimedPhysicsInstruction>
|
||||
}
|
||||
impl Segment{
|
||||
fn append<R:BinReaderExt>(&mut self,segment_info:&SegmentInfo,mut data:R)->Result<(),Error>{
|
||||
for _ in 0..segment_info.instruction_count{
|
||||
let instruction:newtypes::physics::TimedInstruction=data.read_le().map_err(Error::InvalidSegment)?;
|
||||
self.instructions.push(instruction.try_into().map_err(Error::SegmentConvert)?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
pub struct SegmentInfo{
|
||||
@@ -94,14 +103,13 @@ pub struct SegmentInfo{
|
||||
block_id:BlockId,
|
||||
}
|
||||
|
||||
pub struct StreamableBot<R:BinReaderExt>{
|
||||
file:crate::file::File<R>,
|
||||
pub struct StreamableBot{
|
||||
segment_map:Vec<SegmentInfo>,
|
||||
}
|
||||
impl<R:BinReaderExt> StreamableBot<R>{
|
||||
pub(crate) fn new(mut file:crate::file::File<R>)->Result<Self,Error>{
|
||||
impl StreamableBot{
|
||||
pub(crate) fn new<R:BinReaderExt>(mut data:R)->Result<Self,Error>{
|
||||
//assume the file seek is in the right place to start reading header
|
||||
let header:Header=file.data_mut().read_le().map_err(Error::InvalidHeader)?;
|
||||
let header:Header=data.read_le().map_err(Error::InvalidHeader)?;
|
||||
let mut instructions_subtotal=0;
|
||||
let segment_map=header.segments.into_iter().map(|SegmentHeader{time,instruction_count,block_id}|{
|
||||
instructions_subtotal+=instruction_count as u64;
|
||||
@@ -113,13 +121,12 @@ impl<R:BinReaderExt> StreamableBot<R>{
|
||||
}
|
||||
}).collect();
|
||||
Ok(Self{
|
||||
file,
|
||||
segment_map,
|
||||
})
|
||||
}
|
||||
#[expect(dead_code)]
|
||||
fn get_segment_info(&self,segment_id:SegmentId)->Result<SegmentInfo,Error>{
|
||||
Ok(*self.segment_map.get(segment_id.get() as usize).ok_or(Error::InvalidSegmentId(segment_id))?)
|
||||
fn get_segment_info(&self,segment_id:SegmentId)->Result<&SegmentInfo,Error>{
|
||||
self.segment_map.get(segment_id.get() as usize).ok_or(Error::InvalidSegmentId(segment_id))
|
||||
}
|
||||
pub fn find_segments_instruction_range(&self,start_instruction:u64,end_instruction:u64)->&[SegmentInfo]{
|
||||
let start=self.segment_map.partition_point(|segment_info|segment_info.instructions_subtotal<start_instruction);
|
||||
@@ -132,28 +139,21 @@ impl<R:BinReaderExt> StreamableBot<R>{
|
||||
// let end=self.segment_map.partition_point(|segment_info|segment_info.time<end_time);
|
||||
// &self.segment_map[start..=end]
|
||||
// }
|
||||
fn append_to_segment(&mut self,segment_info:SegmentInfo,segment:&mut Segment)->Result<(),Error>{
|
||||
let mut block=self.file.block_reader(segment_info.block_id).map_err(Error::File)?;
|
||||
for _ in 0..segment_info.instruction_count{
|
||||
let instruction:newtypes::physics::TimedInstruction=block.read_le().map_err(Error::InvalidSegment)?;
|
||||
segment.instructions.push(instruction.try_into().map_err(Error::SegmentConvert)?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn load_segment(&mut self,segment_info:SegmentInfo)->Result<Segment,Error>{
|
||||
pub fn load_segment<R:BinReaderExt>(&self,segment_info:&SegmentInfo,mut data:R)->Result<Segment,Error>{
|
||||
let mut segment=Segment{
|
||||
instructions:Vec::with_capacity(segment_info.instruction_count as usize),
|
||||
};
|
||||
self.append_to_segment(segment_info,&mut segment)?;
|
||||
segment.append(segment_info,data)?;
|
||||
Ok(segment)
|
||||
}
|
||||
pub fn read_all(&mut self)->Result<Segment,Error>{
|
||||
pub fn read_all<R:BinReaderExt>(self,header:&crate::file::Header,mut data:R)->Result<Segment,Error>{
|
||||
let mut segment=Segment{
|
||||
instructions:Vec::new(),
|
||||
};
|
||||
for i in 0..self.segment_map.len(){
|
||||
let segment_info=self.segment_map[i];
|
||||
self.append_to_segment(segment_info,&mut segment)?;
|
||||
for segment_info in &self.segment_map{
|
||||
let block_info=header.block_info(segment_info.block_id).map_err(Error::File)?;
|
||||
let block=block_info.take_seek(&mut data).map_err(Error::IO)?;
|
||||
segment.append(segment_info,block)?;
|
||||
}
|
||||
Ok(segment)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//file format "sniff"
|
||||
|
||||
use binrw::{binrw,BinReaderExt,io::TakeSeekExt};
|
||||
use std::io::{SeekFrom,Error as IoError};
|
||||
use binrw::binrw;
|
||||
use binrw::BinReaderExt;
|
||||
use binrw::io::{TakeSeek,TakeSeekExt};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
@@ -54,65 +56,69 @@ pub(crate) enum FourCC{
|
||||
#[brw(magic=b"SNFB")]
|
||||
Bot,
|
||||
}
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Clone,Copy,Debug,Hash,id::Id,Eq,Ord,PartialEq,PartialOrd)]
|
||||
pub struct BlockId(u32);
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Debug,Clone)]
|
||||
struct BlockPosition(u64);
|
||||
|
||||
/// The range of data for a specific Block, relative to the start of the file.
|
||||
#[derive(Debug,Clone)]
|
||||
pub struct BlockInfo(core::ops::Range<u64>);
|
||||
impl BlockInfo{
|
||||
/// Create an adapter which seeks to the block start and reads at most the block length.
|
||||
pub fn take_seek<R:BinReaderExt>(&self,mut data:R)->Result<TakeSeek<R>,IoError>{
|
||||
data.seek(SeekFrom::Start(self.start))?;
|
||||
Ok(data.take_seek(self.end-self.start))
|
||||
}
|
||||
}
|
||||
impl core::ops::Deref for BlockInfo{
|
||||
type Target=core::ops::Range<u64>;
|
||||
fn deref(&self)->&Self::Target{
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Debug)]
|
||||
pub struct Header{
|
||||
/// Type of file
|
||||
pub fourcc:FourCC,
|
||||
fourcc:FourCC,
|
||||
/// File format version
|
||||
pub version:u32,
|
||||
version:u32,
|
||||
/// Minimum data required to know the location of all streamable resources for this specific file
|
||||
pub priming:u64,
|
||||
priming:u64,
|
||||
/// uuid for this file
|
||||
pub resource:u128,
|
||||
resource:u128,
|
||||
//don't need try_calc: the struct will force field initialization anyways and it can be calculated there
|
||||
pub block_count:u32,
|
||||
block_count:u32,
|
||||
#[br(count=block_count+1)]
|
||||
pub block_location:Vec<u64>,
|
||||
block_positions:Vec<BlockPosition>,
|
||||
}
|
||||
impl Header{
|
||||
pub const fn fourcc(&self)->FourCC{
|
||||
self.fourcc
|
||||
}
|
||||
pub const fn calculate_size(block_count:u32)->usize{
|
||||
4 // fourcc
|
||||
+4 // version
|
||||
+8 // priming
|
||||
+16 // resource
|
||||
+4 // block_count
|
||||
+(block_count as usize+1)*8 // block_location
|
||||
+(block_count as usize+1)*8 // block_positions
|
||||
}
|
||||
}
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Clone,Copy,Debug,Hash,id::Id,Eq,Ord,PartialEq,PartialOrd)]
|
||||
pub struct BlockId(u32);
|
||||
|
||||
pub(crate) struct File<R:BinReaderExt>{
|
||||
header:Header,
|
||||
//reference to the data
|
||||
data:R,
|
||||
}
|
||||
|
||||
impl<R:BinReaderExt> File<R>{
|
||||
pub(crate) fn new(mut input:R)->Result<File<R>,Error>{
|
||||
Ok(File{
|
||||
header:input.read_le().map_err(Error::InvalidHeader)?,
|
||||
data:input,
|
||||
})
|
||||
}
|
||||
pub(crate) fn data_mut(&mut self)->&mut R{
|
||||
&mut self.data
|
||||
}
|
||||
pub(crate) fn block_reader(&mut self,block_id:BlockId)->Result<binrw::io::TakeSeek<&mut R>,Error>{
|
||||
if self.header.block_location.len() as u32<=block_id.get(){
|
||||
pub fn block_info(&self,block_id:BlockId)->Result<BlockInfo,Error>{
|
||||
let BlockId(id)=block_id;
|
||||
if self.block_positions.len() as u32<=id{
|
||||
return Err(Error::InvalidBlockId(block_id))
|
||||
}
|
||||
let block_start=self.header.block_location[block_id.get() as usize];
|
||||
let block_end=self.header.block_location[block_id.get() as usize+1];
|
||||
self.data.seek(std::io::SeekFrom::Start(block_start)).map_err(Error::Seek)?;
|
||||
Ok(self.data_mut().take_seek(block_end-block_start))
|
||||
}
|
||||
pub(crate) fn fourcc(&self)->FourCC{
|
||||
self.header.fourcc
|
||||
let BlockPosition(start)=self.block_positions[id as usize];
|
||||
let BlockPosition(end)=self.block_positions[id as usize+1];
|
||||
Ok(BlockInfo(start..end))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,31 +20,34 @@ impl std::fmt::Display for Error{
|
||||
}
|
||||
impl std::error::Error for Error{}
|
||||
|
||||
pub enum SNF<R:BinReaderExt>{
|
||||
Map(map::StreamableMap<R>),
|
||||
Bot(bot::StreamableBot<R>),
|
||||
pub enum SNF{
|
||||
Map(map::StreamableMap),
|
||||
Bot(bot::StreamableBot),
|
||||
}
|
||||
|
||||
pub fn read_snf<R:BinReaderExt>(input:R)->Result<SNF<R>,Error>{
|
||||
let file=file::File::new(input).map_err(Error::Header)?;
|
||||
Ok(match file.fourcc(){
|
||||
file::FourCC::Map=>SNF::Map(map::StreamableMap::new(file).map_err(Error::Map)?),
|
||||
file::FourCC::Bot=>SNF::Bot(bot::StreamableBot::new(file).map_err(Error::Bot)?),
|
||||
})
|
||||
pub fn read_snf<R:BinReaderExt>(mut input:R)->Result<(file::Header,SNF),Error>{
|
||||
let file:file::Header=input.read_le().map_err(|e|Error::Header(file::Error::InvalidHeader(e)))?;
|
||||
let snf=match file.fourcc(){
|
||||
file::FourCC::Map=>SNF::Map(map::StreamableMap::new(input).map_err(Error::Map)?),
|
||||
file::FourCC::Bot=>SNF::Bot(bot::StreamableBot::new(input).map_err(Error::Bot)?),
|
||||
};
|
||||
Ok((file,snf))
|
||||
}
|
||||
pub fn read_map<R:BinReaderExt>(input:R)->Result<map::StreamableMap<R>,Error>{
|
||||
let file=file::File::new(input).map_err(Error::Header)?;
|
||||
match file.fourcc(){
|
||||
file::FourCC::Map=>Ok(map::StreamableMap::new(file).map_err(Error::Map)?),
|
||||
_=>Err(Error::UnexpectedFourCC)
|
||||
}
|
||||
pub fn read_map<R:BinReaderExt>(mut input:R)->Result<(file::Header,map::StreamableMap),Error>{
|
||||
let file:file::Header=input.read_le().map_err(|e|Error::Header(file::Error::InvalidHeader(e)))?;
|
||||
let map=match file.fourcc(){
|
||||
file::FourCC::Map=>map::StreamableMap::new(input).map_err(Error::Map)?,
|
||||
_=>return Err(Error::UnexpectedFourCC)
|
||||
};
|
||||
Ok((file,map))
|
||||
}
|
||||
pub fn read_bot<R:BinReaderExt>(input:R)->Result<bot::StreamableBot<R>,Error>{
|
||||
let file=file::File::new(input).map_err(Error::Header)?;
|
||||
match file.fourcc(){
|
||||
file::FourCC::Bot=>Ok(bot::StreamableBot::new(file).map_err(Error::Bot)?),
|
||||
_=>Err(Error::UnexpectedFourCC)
|
||||
}
|
||||
pub fn read_bot<R:BinReaderExt>(mut input:R)->Result<(file::Header,bot::StreamableBot),Error>{
|
||||
let file:file::Header=input.read_le().map_err(|e|Error::Header(file::Error::InvalidHeader(e)))?;
|
||||
let bot=match file.fourcc(){
|
||||
file::FourCC::Bot=>bot::StreamableBot::new(input).map_err(Error::Bot)?,
|
||||
_=>return Err(Error::UnexpectedFourCC)
|
||||
};
|
||||
Ok((file,bot))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -155,31 +155,27 @@ struct Region{
|
||||
}
|
||||
|
||||
//code deduplication reused in into_complete_map
|
||||
fn read_region<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<Vec<(model::ModelId,model::Model)>,Error>{
|
||||
pub fn read_region<R:BinReaderExt>(mut data:R)->Result<Vec<(model::ModelId,model::Model)>,Error>{
|
||||
//load region from disk
|
||||
//parse the models and determine what resources need to be loaded
|
||||
//load resources into self.resources
|
||||
//return Region
|
||||
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
||||
let region:Region=block.read_le().map_err(Error::InvalidData)?;
|
||||
let region:Region=data.read_le().map_err(Error::InvalidData)?;
|
||||
Ok(region.models.into_iter().map(|(model_id,model)|
|
||||
(model::ModelId::new(model_id),model.into())
|
||||
).collect())
|
||||
}
|
||||
fn read_mesh<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<model::Mesh,Error>{
|
||||
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
||||
let mesh:newtypes::model::Mesh=block.read_le().map_err(Error::InvalidData)?;
|
||||
pub fn read_mesh<R:BinReaderExt>(mut data:R)->Result<model::Mesh,Error>{
|
||||
let mesh:newtypes::model::Mesh=data.read_le().map_err(Error::InvalidData)?;
|
||||
Ok(mesh.into())
|
||||
}
|
||||
fn read_texture<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<Vec<u8>,Error>{
|
||||
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
||||
pub fn read_texture<R:BinReaderExt>(mut data:R)->Result<Vec<u8>,Error>{
|
||||
let mut texture=Vec::new();
|
||||
block.read_to_end(&mut texture).map_err(Error::IO)?;
|
||||
data.read_to_end(&mut texture).map_err(Error::IO)?;
|
||||
Ok(texture)
|
||||
}
|
||||
|
||||
pub struct StreamableMap<R:BinReaderExt>{
|
||||
file:crate::file::File<R>,
|
||||
pub struct StreamableMap{
|
||||
//this includes every platform... move the unconstrained datas to their appropriate data block?
|
||||
modes:gameplay_modes::NormalizedModes,
|
||||
//this is every possible attribute... need some sort of streaming system
|
||||
@@ -192,10 +188,10 @@ pub struct StreamableMap<R:BinReaderExt>{
|
||||
resource_blocks:ResourceMap<BlockId>,
|
||||
//resource_external:ResourceMap<ResourceId>,
|
||||
}
|
||||
impl<R:BinReaderExt> StreamableMap<R>{
|
||||
pub(crate) fn new(mut file:crate::file::File<R>)->Result<Self,Error>{
|
||||
impl StreamableMap{
|
||||
pub(crate) fn new<R:BinReaderExt>(mut data:R)->Result<Self,Error>{
|
||||
//assume the file seek is in the right place to start reading a map header
|
||||
let header:MapHeader=file.data_mut().read_le().map_err(Error::InvalidHeader)?;
|
||||
let header:MapHeader=data.read_le().map_err(Error::InvalidHeader)?;
|
||||
let modes=header.modes.into_iter().map(TryInto::try_into).collect::<Result<_,_>>().map_err(Error::InvalidMode)?;
|
||||
let attributes=header.attributes.into_iter().map(Into::into).collect();
|
||||
let render_configs=header.render_configs.into_iter().map(Into::into).collect();
|
||||
@@ -222,7 +218,6 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
||||
}
|
||||
}
|
||||
Ok(Self{
|
||||
file,
|
||||
modes:gameplay_modes::NormalizedModes::new(modes),
|
||||
attributes,
|
||||
render_configs,
|
||||
@@ -236,18 +231,13 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
||||
self.bvh.sample_aabb(aabb,&mut |&block_id|block_ids.push(block_id));
|
||||
block_ids
|
||||
}
|
||||
pub fn load_region(&mut self,block_id:BlockId)->Result<Vec<(model::ModelId,model::Model)>,Error>{
|
||||
read_region(&mut self.file,block_id)
|
||||
pub fn get_mesh_block_id<R:BinReaderExt>(&self,mesh_id:model::MeshId)->Result<&BlockId,Error>{
|
||||
self.resource_blocks.meshes.get(&mesh_id).ok_or(Error::InvalidMeshId(mesh_id))
|
||||
}
|
||||
pub fn load_mesh(&mut self,mesh_id:model::MeshId)->Result<model::Mesh,Error>{
|
||||
let block_id=*self.resource_blocks.meshes.get(&mesh_id).ok_or(Error::InvalidMeshId(mesh_id))?;
|
||||
read_mesh(&mut self.file,block_id)
|
||||
pub fn get_texture_block_id<R:BinReaderExt>(&self,texture_id:model::TextureId)->Result<&BlockId,Error>{
|
||||
self.resource_blocks.textures.get(&texture_id).ok_or(Error::InvalidTextureId(texture_id))
|
||||
}
|
||||
pub fn load_texture(&mut self,texture_id:model::TextureId)->Result<Vec<u8>,Error>{
|
||||
let block_id=*self.resource_blocks.textures.get(&texture_id).ok_or(Error::InvalidTextureId(texture_id))?;
|
||||
read_texture(&mut self.file,block_id)
|
||||
}
|
||||
pub fn into_complete_map(mut self)->Result<strafesnet_common::map::CompleteMap,Error>{
|
||||
pub fn into_complete_map<R:BinReaderExt>(self,header:&crate::file::Header,mut data:R)->Result<strafesnet_common::map::CompleteMap,Error>{
|
||||
let mut block_ids=Vec::new();
|
||||
self.bvh.into_visitor(&mut |block_id|block_ids.push(block_id));
|
||||
//count on reading the file in sequential order being fastest
|
||||
@@ -255,7 +245,9 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
||||
//load all regions
|
||||
let mut model_pairs=HashMap::new();
|
||||
for block_id in block_ids{
|
||||
model_pairs.extend(read_region(&mut self.file,block_id)?);
|
||||
let block_info=header.block_info(block_id).map_err(Error::File)?;
|
||||
let block=block_info.take_seek(&mut data).map_err(Error::IO)?;
|
||||
model_pairs.extend(read_region(block)?);
|
||||
}
|
||||
let mut models=Vec::with_capacity(model_pairs.len());
|
||||
for model_id in 0..model_pairs.len() as u32{
|
||||
@@ -267,14 +259,18 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
||||
for mesh_id in 0..self.resource_blocks.meshes.len() as u32{
|
||||
let mesh_id=model::MeshId::new(mesh_id);
|
||||
let block_id=self.resource_blocks.meshes[&mesh_id];
|
||||
meshes.push(read_mesh(&mut self.file,block_id)?);
|
||||
let block_info=header.block_info(block_id).map_err(Error::File)?;
|
||||
let block=block_info.take_seek(&mut data).map_err(Error::IO)?;
|
||||
meshes.push(read_mesh(block)?);
|
||||
};
|
||||
//load all textures
|
||||
let mut textures=Vec::with_capacity(self.resource_blocks.textures.len());
|
||||
for texture_id in 0..self.resource_blocks.textures.len() as u32{
|
||||
let texture_id=model::TextureId::new(texture_id);
|
||||
let block_id=self.resource_blocks.textures[&texture_id];
|
||||
textures.push(read_texture(&mut self.file,block_id)?);
|
||||
let block_info=header.block_info(block_id).map_err(Error::File)?;
|
||||
let block=block_info.take_seek(&mut data).map_err(Error::IO)?;
|
||||
textures.push(read_texture(block)?);
|
||||
}
|
||||
Ok(strafesnet_common::map::CompleteMap{
|
||||
modes:self.modes,
|
||||
|
||||
@@ -18,10 +18,10 @@ rbx_dom_weak = "4.1.0"
|
||||
rbx_reflection_database = "2.0.2"
|
||||
rbx_xml = "2.0.1"
|
||||
rbxassetid = { version = "0.1.0", registry = "strafesnet" }
|
||||
strafesnet_bsp_loader = { version = "0.3.1", path = "../lib/bsp_loader", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.5.1", path = "../lib/deferred_loader", registry = "strafesnet" }
|
||||
strafesnet_rbx_loader = { version = "0.7.0", path = "../lib/rbx_loader", registry = "strafesnet" }
|
||||
strafesnet_snf = { version = "0.3.1", path = "../lib/snf", registry = "strafesnet" }
|
||||
strafesnet_bsp_loader.workspace = true
|
||||
strafesnet_deferred_loader.workspace = true
|
||||
strafesnet_rbx_loader.workspace = true
|
||||
strafesnet_snf.workspace = true
|
||||
thiserror = "2.0.11"
|
||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread", "fs"] }
|
||||
vbsp = "0.9.1"
|
||||
|
||||
@@ -16,18 +16,18 @@ source = ["dep:strafesnet_deferred_loader", "dep:strafesnet_bsp_loader"]
|
||||
roblox = ["dep:strafesnet_deferred_loader", "dep:strafesnet_rbx_loader"]
|
||||
|
||||
[dependencies]
|
||||
glam = "0.30.0"
|
||||
glam.workspace = true
|
||||
parking_lot = "0.12.1"
|
||||
pollster = "0.4.0"
|
||||
strafesnet_bsp_loader = { path = "../lib/bsp_loader", registry = "strafesnet", optional = true }
|
||||
strafesnet_common = { path = "../lib/common", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { path = "../lib/deferred_loader", registry = "strafesnet", optional = true }
|
||||
strafesnet_graphics = { path = "../engine/graphics", registry = "strafesnet" }
|
||||
strafesnet_physics = { path = "../engine/physics", registry = "strafesnet" }
|
||||
strafesnet_rbx_loader = { path = "../lib/rbx_loader", registry = "strafesnet", optional = true }
|
||||
strafesnet_session = { path = "../engine/session", registry = "strafesnet" }
|
||||
strafesnet_settings = { path = "../engine/settings", registry = "strafesnet" }
|
||||
strafesnet_snf = { path = "../lib/snf", registry = "strafesnet", optional = true }
|
||||
strafesnet_bsp_loader = { workspace = true, optional = true }
|
||||
strafesnet_common.workspace = true
|
||||
strafesnet_deferred_loader = { workspace = true, optional = true }
|
||||
strafesnet_graphics.workspace = true
|
||||
strafesnet_physics.workspace = true
|
||||
strafesnet_rbx_loader = { workspace = true, optional = true }
|
||||
strafesnet_session.workspace = true
|
||||
strafesnet_settings.workspace = true
|
||||
strafesnet_snf = { workspace = true, optional = true }
|
||||
wgpu = "28.0.0"
|
||||
winit = "0.30.7"
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ pub fn new(
|
||||
config.width=size.width.max(1);
|
||||
config.height=size.height.max(1);
|
||||
surface.configure(&device,&config);
|
||||
graphics.resize(&device,&config,&user_settings);
|
||||
let fov=user_settings.calculate_fov(1.0,&glam::uvec2(config.width,config.height)).as_vec2();
|
||||
graphics.resize(&device,&config,fov);
|
||||
println!("Resize took {:?}",t0.elapsed());
|
||||
}
|
||||
Instruction::Render(frame_state)=>{
|
||||
@@ -56,7 +57,7 @@ pub fn new(
|
||||
..wgpu::TextureViewDescriptor::default()
|
||||
});
|
||||
|
||||
graphics.render(&view,&device,&queue,frame_state);
|
||||
graphics.render(&view,&device,&queue,graphics::view_inv(frame_state.pos(),frame_state.angles()));
|
||||
|
||||
frame.present();
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ mod graphics_worker;
|
||||
const TITLE:&'static str=concat!("Strafe Client v",env!("CARGO_PKG_VERSION"));
|
||||
|
||||
fn main(){
|
||||
setup::setup_and_start(TITLE);
|
||||
pollster::block_on(setup::setup_and_start(TITLE));
|
||||
}
|
||||
|
||||
@@ -1,199 +1,38 @@
|
||||
fn optional_features()->wgpu::Features{
|
||||
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
||||
|wgpu::Features::TEXTURE_COMPRESSION_ETC2
|
||||
}
|
||||
fn required_features()->wgpu::Features{
|
||||
wgpu::Features::TEXTURE_COMPRESSION_BC
|
||||
}
|
||||
fn required_downlevel_capabilities()->wgpu::DownlevelCapabilities{
|
||||
wgpu::DownlevelCapabilities{
|
||||
flags:wgpu::DownlevelFlags::empty(),
|
||||
shader_model:wgpu::ShaderModel::Sm5,
|
||||
..wgpu::DownlevelCapabilities::default()
|
||||
}
|
||||
}
|
||||
use strafesnet_graphics::setup;
|
||||
|
||||
struct SetupContextPartial1{
|
||||
backends:wgpu::Backends,
|
||||
instance:wgpu::Instance,
|
||||
}
|
||||
fn create_window(title:&str,event_loop:&winit::event_loop::EventLoop<()>)->Result<winit::window::Window,winit::error::OsError>{
|
||||
let mut attr=winit::window::WindowAttributes::default();
|
||||
attr=attr.with_title(title);
|
||||
event_loop.create_window(attr)
|
||||
}
|
||||
fn create_instance()->SetupContextPartial1{
|
||||
let backends=wgpu::Backends::from_env().unwrap_or_default();
|
||||
SetupContextPartial1{
|
||||
backends,
|
||||
instance:Default::default(),
|
||||
}
|
||||
}
|
||||
impl SetupContextPartial1{
|
||||
fn create_surface<'a>(self,window:&'a winit::window::Window)->Result<SetupContextPartial2<'a>,wgpu::CreateSurfaceError>{
|
||||
Ok(SetupContextPartial2{
|
||||
backends:self.backends,
|
||||
surface:self.instance.create_surface(window)?,
|
||||
instance:self.instance,
|
||||
})
|
||||
}
|
||||
}
|
||||
struct SetupContextPartial2<'a>{
|
||||
backends:wgpu::Backends,
|
||||
instance:wgpu::Instance,
|
||||
surface:wgpu::Surface<'a>,
|
||||
}
|
||||
impl<'a> SetupContextPartial2<'a>{
|
||||
fn pick_adapter(self)->SetupContextPartial3<'a>{
|
||||
let adapter;
|
||||
|
||||
//TODO: prefer adapter that implements optional features
|
||||
//let optional_features=optional_features();
|
||||
let required_features=required_features();
|
||||
|
||||
//no helper function smh gotta write it myself
|
||||
let adapters=pollster::block_on(self.instance.enumerate_adapters(self.backends));
|
||||
|
||||
let mut chosen_adapter=None;
|
||||
let mut chosen_adapter_score=0;
|
||||
for adapter in adapters {
|
||||
if !adapter.is_surface_supported(&self.surface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let score=match adapter.get_info().device_type{
|
||||
wgpu::DeviceType::IntegratedGpu=>3,
|
||||
wgpu::DeviceType::DiscreteGpu=>4,
|
||||
wgpu::DeviceType::VirtualGpu=>2,
|
||||
wgpu::DeviceType::Other|wgpu::DeviceType::Cpu=>1,
|
||||
};
|
||||
|
||||
let adapter_features=adapter.features();
|
||||
if chosen_adapter_score<score&&adapter_features.contains(required_features) {
|
||||
chosen_adapter_score=score;
|
||||
chosen_adapter=Some(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(maybe_chosen_adapter)=chosen_adapter{
|
||||
adapter=maybe_chosen_adapter;
|
||||
}else{
|
||||
panic!("No suitable GPU adapters found on the system!");
|
||||
}
|
||||
|
||||
|
||||
let adapter_info=adapter.get_info();
|
||||
println!("Using {} ({:?})", adapter_info.name, adapter_info.backend);
|
||||
|
||||
let required_downlevel_capabilities=required_downlevel_capabilities();
|
||||
let downlevel_capabilities=adapter.get_downlevel_capabilities();
|
||||
assert!(
|
||||
downlevel_capabilities.shader_model >= required_downlevel_capabilities.shader_model,
|
||||
"Adapter does not support the minimum shader model required to run this example: {:?}",
|
||||
required_downlevel_capabilities.shader_model
|
||||
);
|
||||
assert!(
|
||||
downlevel_capabilities
|
||||
.flags
|
||||
.contains(required_downlevel_capabilities.flags),
|
||||
"Adapter does not support the downlevel capabilities required to run this example: {:?}",
|
||||
required_downlevel_capabilities.flags - downlevel_capabilities.flags
|
||||
);
|
||||
SetupContextPartial3{
|
||||
surface:self.surface,
|
||||
adapter,
|
||||
}
|
||||
}
|
||||
}
|
||||
struct SetupContextPartial3<'a>{
|
||||
surface:wgpu::Surface<'a>,
|
||||
adapter:wgpu::Adapter,
|
||||
}
|
||||
impl<'a> SetupContextPartial3<'a>{
|
||||
fn request_device(self)->SetupContextPartial4<'a>{
|
||||
let optional_features=optional_features();
|
||||
let required_features=required_features();
|
||||
|
||||
// Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface.
|
||||
let needed_limits=strafesnet_graphics::graphics::required_limits().using_resolution(self.adapter.limits());
|
||||
|
||||
let (device, queue)=pollster::block_on(self.adapter
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor{
|
||||
label:None,
|
||||
required_features:(optional_features&self.adapter.features())|required_features,
|
||||
required_limits:needed_limits,
|
||||
memory_hints:wgpu::MemoryHints::Performance,
|
||||
trace:wgpu::Trace::Off,
|
||||
experimental_features:wgpu::ExperimentalFeatures::disabled(),
|
||||
},
|
||||
))
|
||||
.expect("Unable to find a suitable GPU adapter!");
|
||||
|
||||
SetupContextPartial4{
|
||||
surface:self.surface,
|
||||
adapter:self.adapter,
|
||||
device,
|
||||
queue,
|
||||
}
|
||||
}
|
||||
}
|
||||
struct SetupContextPartial4<'a>{
|
||||
surface:wgpu::Surface<'a>,
|
||||
adapter:wgpu::Adapter,
|
||||
device:wgpu::Device,
|
||||
queue:wgpu::Queue,
|
||||
}
|
||||
impl<'a> SetupContextPartial4<'a>{
|
||||
fn configure_surface(self,size:&'a winit::dpi::PhysicalSize<u32>)->SetupContext<'a>{
|
||||
let mut config=self.surface
|
||||
.get_default_config(&self.adapter, size.width, size.height)
|
||||
.expect("Surface isn't supported by the adapter.");
|
||||
let surface_view_format=config.format.add_srgb_suffix();
|
||||
config.view_formats.push(surface_view_format);
|
||||
config.present_mode=wgpu::PresentMode::AutoNoVsync;
|
||||
self.surface.configure(&self.device, &config);
|
||||
|
||||
SetupContext{
|
||||
surface:self.surface,
|
||||
device:self.device,
|
||||
queue:self.queue,
|
||||
config,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct SetupContext<'a>{
|
||||
pub surface:wgpu::Surface<'a>,
|
||||
pub device:wgpu::Device,
|
||||
pub queue:wgpu::Queue,
|
||||
pub config:wgpu::SurfaceConfiguration,
|
||||
}
|
||||
|
||||
pub fn setup_and_start(title:&str){
|
||||
pub async fn setup_and_start(title:&str){
|
||||
let event_loop=winit::event_loop::EventLoop::new().unwrap();
|
||||
|
||||
println!("Initializing the surface...");
|
||||
|
||||
let partial_1=create_instance();
|
||||
|
||||
let window=create_window(title,&event_loop).unwrap();
|
||||
|
||||
let partial_2=partial_1.create_surface(&window).unwrap();
|
||||
println!("Initializing the surface...");
|
||||
|
||||
let partial_3=partial_2.pick_adapter();
|
||||
let instance=setup::step1::create_instance();
|
||||
|
||||
let partial_4=partial_3.request_device();
|
||||
let surface=setup::step2::create_surface(&instance,&window).unwrap();
|
||||
|
||||
let adapter=setup::step3::pick_adapter(&instance,&surface).await.expect("No suitable GPU adapters found on the system!");
|
||||
|
||||
let (device,queue)=setup::step4::request_device(&adapter).await;
|
||||
|
||||
let size=window.inner_size();
|
||||
|
||||
let setup_context=partial_4.configure_surface(&size);
|
||||
let config=setup::step5::configure_surface(&adapter,&device,&surface,(size.width,size.height));
|
||||
|
||||
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
|
||||
|
||||
//the thread that spawns the physics thread
|
||||
let mut window_thread=crate::window::worker(
|
||||
&window,
|
||||
setup_context,
|
||||
device,
|
||||
queue,
|
||||
surface,
|
||||
config,
|
||||
);
|
||||
|
||||
for arg in std::env::args().skip(1){
|
||||
|
||||
@@ -239,7 +239,10 @@ impl WindowContext<'_>{
|
||||
}
|
||||
pub fn worker<'a>(
|
||||
window:&'a winit::window::Window,
|
||||
setup_context:crate::setup::SetupContext<'a>,
|
||||
device:wgpu::Device,
|
||||
queue:wgpu::Queue,
|
||||
surface:wgpu::Surface<'a>,
|
||||
config:wgpu::SurfaceConfiguration,
|
||||
)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTime>>{
|
||||
// WindowContextSetup::new
|
||||
#[cfg(feature="user-install")]
|
||||
@@ -249,12 +252,13 @@ pub fn worker<'a>(
|
||||
|
||||
let user_settings=directories.settings();
|
||||
|
||||
let mut graphics=strafesnet_graphics::graphics::GraphicsState::new(&setup_context.device,&setup_context.queue,&setup_context.config);
|
||||
graphics.load_user_settings(&user_settings);
|
||||
let mut graphics=strafesnet_graphics::graphics::GraphicsState::new(&device,&queue,&config);
|
||||
|
||||
//WindowContextSetup::into_context
|
||||
let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height);
|
||||
let graphics_thread=crate::graphics_worker::new(graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
|
||||
let screen_size=glam::uvec2(config.width,config.height);
|
||||
let fov=user_settings.calculate_fov(1.0,&screen_size).as_vec2();
|
||||
graphics.resize(&device,&config,fov);
|
||||
let graphics_thread=crate::graphics_worker::new(graphics,config,surface,device,queue);
|
||||
let mut window_context=WindowContext{
|
||||
manual_mouse_lock:false,
|
||||
mouse_pos:glam::DVec2::ZERO,
|
||||
|
||||
Reference in New Issue
Block a user