Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
265f2a2c70 | |||
3c516badd4 | |||
00dce54aea | |||
1c86219dbe | |||
cee5731e6c | |||
f8583702be | |||
275373d9bc | |||
48e68d76a4 | |||
66d4f100c6 | |||
86d6f7c6a7 | |||
3c78d9c94c | |||
e8da9d2a72 | |||
2f422e97dd | |||
eb004cbb21 | |||
e944e7d91a |
60
Cargo.lock
generated
60
Cargo.lock
generated
@ -67,6 +67,12 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
@ -361,6 +367,20 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.11.1"
|
||||
@ -781,6 +801,29 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icu_collections"
|
||||
version = "1.5.0"
|
||||
@ -2229,6 +2272,7 @@ name = "strafe-client"
|
||||
version = "0.10.5"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
"configparser",
|
||||
"ddsfile",
|
||||
"glam",
|
||||
@ -2240,6 +2284,9 @@ dependencies = [
|
||||
"strafesnet_deferred_loader",
|
||||
"strafesnet_rbx_loader",
|
||||
"strafesnet_snf",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
@ -2891,7 +2938,7 @@ dependencies = [
|
||||
"web-sys",
|
||||
"wgpu-types",
|
||||
"windows",
|
||||
"windows-core",
|
||||
"windows-core 0.58.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2920,7 +2967,16 @@ version = "0.58.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-core 0.58.0",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
|
@ -16,6 +16,7 @@ roblox = ["dep:strafesnet_deferred_loader", "dep:strafesnet_rbx_loader"]
|
||||
|
||||
[dependencies]
|
||||
bytemuck = { version = "1.13.1", features = ["derive"] }
|
||||
chrono = "0.4.39"
|
||||
configparser = "3.0.2"
|
||||
ddsfile = "0.5.1"
|
||||
glam = "0.29.0"
|
||||
@ -27,5 +28,8 @@ strafesnet_common = { path = "../lib/common", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { path = "../lib/deferred_loader", features = ["legacy"], registry = "strafesnet", optional = true }
|
||||
strafesnet_rbx_loader = { path = "../lib/rbx_loader", registry = "strafesnet", optional = true }
|
||||
strafesnet_snf = { path = "../lib/snf", registry = "strafesnet", optional = true }
|
||||
wasm-bindgen = "0.2.99"
|
||||
wasm-bindgen-futures = "0.4.49"
|
||||
web-sys = { version = "0.3.76", features = ["console"] }
|
||||
wgpu = "23.0.1"
|
||||
winit = "0.30.7"
|
||||
|
@ -3,11 +3,11 @@ pub type INWorker<'a,Task>=CompatNWorker<'a,Task>;
|
||||
|
||||
pub struct CompatNWorker<'a,Task>{
|
||||
data:std::marker::PhantomData<Task>,
|
||||
f:Box<dyn FnMut(Task)+Send+'a>,
|
||||
f:Box<dyn FnMut(Task)+'a>,
|
||||
}
|
||||
|
||||
impl<'a,Task> CompatNWorker<'a,Task>{
|
||||
pub fn new(f:impl FnMut(Task)+Send+'a)->CompatNWorker<'a,Task>{
|
||||
pub fn new(f:impl FnMut(Task)+'a)->CompatNWorker<'a,Task>{
|
||||
Self{
|
||||
data:std::marker::PhantomData,
|
||||
f:Box::new(f),
|
||||
|
@ -59,10 +59,13 @@ impl std::fmt::Display for LoadError{
|
||||
}
|
||||
impl std::error::Error for LoadError{}
|
||||
|
||||
pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::CompleteMap,LoadError>{
|
||||
pub fn load_file<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::CompleteMap,LoadError>{
|
||||
//blocking because it's simpler...
|
||||
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
||||
match read(file).map_err(LoadError::ReadError)?{
|
||||
load(file)
|
||||
}
|
||||
pub fn load<R:Read+std::io::Seek>(reader:R)->Result<strafesnet_common::map::CompleteMap,LoadError>{
|
||||
match read(reader).map_err(LoadError::ReadError)?{
|
||||
#[cfg(feature="snf")]
|
||||
DataStructure::StrafesNET(map)=>Ok(map),
|
||||
#[cfg(feature="roblox")]
|
||||
|
@ -14,6 +14,9 @@ WorkerDescription{
|
||||
*/
|
||||
//up to three frames in flight, dropping new frame requests when all three are busy, and dropping output frames when one renders out of order
|
||||
|
||||
fn print(message:&str){
|
||||
web_sys::console::log_1(&message.into());
|
||||
}
|
||||
pub fn new<'a>(
|
||||
mut graphics:crate::graphics::GraphicsState,
|
||||
mut config:wgpu::SurfaceConfiguration,
|
||||
@ -33,13 +36,21 @@ pub fn new<'a>(
|
||||
}
|
||||
Instruction::Render(frame_state)=>{
|
||||
if let Some((size,user_settings))=resize.take(){
|
||||
println!("Resizing to {:?}",size);
|
||||
let t0=std::time::Instant::now();
|
||||
config.width=size.width.max(1);
|
||||
config.height=size.height.max(1);
|
||||
print(format!("Resizing to {:?}",size).as_str());
|
||||
//let t0=std::time::Instant::now();
|
||||
match size{
|
||||
winit::dpi::PhysicalSize{width:2560,height:1440}=>{
|
||||
config.width=size.width.clamp(1,2560);
|
||||
config.height=size.height.clamp(1,1440);
|
||||
},
|
||||
_=>{
|
||||
config.width=size.width.clamp(1,1280);
|
||||
config.height=size.height.clamp(1,720);
|
||||
}
|
||||
}
|
||||
surface.configure(&device,&config);
|
||||
graphics.resize(&device,&config,&user_settings);
|
||||
println!("Resize took {:?}",t0.elapsed());
|
||||
//println!("Resize took {:?}",t0.elapsed());
|
||||
}
|
||||
//this has to go deeper somehow
|
||||
let frame=match surface.get_current_texture(){
|
||||
|
@ -13,5 +13,9 @@ mod physics_worker;
|
||||
mod graphics_worker;
|
||||
|
||||
fn main(){
|
||||
setup::setup_and_start(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")));
|
||||
let title=format!("Strafe Client v{}",env!("CARGO_PKG_VERSION"));
|
||||
#[cfg(target_arch="wasm32")]
|
||||
wasm_bindgen_futures::spawn_local(setup::setup_and_start(title));
|
||||
#[cfg(not(target_arch="wasm32"))]
|
||||
pollster::block_on(setup::setup_and_start(title));
|
||||
}
|
||||
|
@ -32,6 +32,16 @@ fn create_window(title:&str,event_loop:&winit::event_loop::EventLoop<()>)->Resul
|
||||
use winit::platform::windows::WindowBuilderExtWindows;
|
||||
builder=builder.with_no_redirection_bitmap(true);
|
||||
}
|
||||
#[cfg(target_arch="wasm32")]
|
||||
{
|
||||
use wasm_bindgen::JsCast;
|
||||
use winit::platform::web::WindowAttributesExtWebSys;
|
||||
let canvas=web_sys::window().unwrap()
|
||||
.document().unwrap()
|
||||
.get_element_by_id("canvas").unwrap()
|
||||
.dyn_into::<web_sys::HtmlCanvasElement>().unwrap();
|
||||
attr=attr.with_canvas(Some(canvas));
|
||||
}
|
||||
event_loop.create_window(attr)
|
||||
}
|
||||
fn create_instance()->SetupContextPartial1{
|
||||
@ -61,36 +71,18 @@ struct SetupContextPartial2<'a>{
|
||||
surface:wgpu::Surface<'a>,
|
||||
}
|
||||
impl<'a> SetupContextPartial2<'a>{
|
||||
fn pick_adapter(self)->SetupContextPartial3<'a>{
|
||||
async 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=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);
|
||||
}
|
||||
}
|
||||
let chosen_adapter=self.instance.request_adapter(&wgpu::RequestAdapterOptions{
|
||||
power_preference:wgpu::PowerPreference::HighPerformance,
|
||||
force_fallback_adapter:false,
|
||||
compatible_surface:Some(&self.surface),
|
||||
}).await;
|
||||
|
||||
if let Some(maybe_chosen_adapter)=chosen_adapter{
|
||||
adapter=maybe_chosen_adapter;
|
||||
@ -129,7 +121,7 @@ struct SetupContextPartial3<'a>{
|
||||
adapter:wgpu::Adapter,
|
||||
}
|
||||
impl<'a> SetupContextPartial3<'a>{
|
||||
fn request_device(self)->SetupContextPartial4<'a>{
|
||||
async fn request_device(self)->SetupContextPartial4<'a>{
|
||||
let optional_features=optional_features();
|
||||
let required_features=required_features();
|
||||
|
||||
@ -137,7 +129,7 @@ impl<'a> SetupContextPartial3<'a>{
|
||||
let needed_limits=required_limits().using_resolution(self.adapter.limits());
|
||||
|
||||
let trace_dir=std::env::var("WGPU_TRACE");
|
||||
let (device, queue)=pollster::block_on(self.adapter
|
||||
let (device, queue)=self.adapter
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
label: None,
|
||||
@ -146,7 +138,7 @@ impl<'a> SetupContextPartial3<'a>{
|
||||
memory_hints:wgpu::MemoryHints::Performance,
|
||||
},
|
||||
trace_dir.ok().as_ref().map(std::path::Path::new),
|
||||
))
|
||||
).await
|
||||
.expect("Unable to find a suitable GPU adapter!");
|
||||
|
||||
SetupContextPartial4{
|
||||
@ -192,7 +184,7 @@ pub struct SetupContext<'a>{
|
||||
pub config:wgpu::SurfaceConfiguration,
|
||||
}
|
||||
|
||||
pub fn setup_and_start(title:String){
|
||||
pub async fn setup_and_start(title:String){
|
||||
let event_loop=winit::event_loop::EventLoop::new().unwrap();
|
||||
|
||||
println!("Initializing the surface...");
|
||||
@ -203,9 +195,9 @@ pub fn setup_and_start(title:String){
|
||||
|
||||
let partial_2=partial_1.create_surface(&window).unwrap();
|
||||
|
||||
let partial_3=partial_2.pick_adapter();
|
||||
let partial_3=partial_2.pick_adapter().await;
|
||||
|
||||
let partial_4=partial_3.request_device();
|
||||
let partial_4=partial_3.request_device().await;
|
||||
|
||||
let size=window.inner_size();
|
||||
|
||||
@ -219,26 +211,26 @@ pub fn setup_and_start(title:String){
|
||||
setup_context,
|
||||
);
|
||||
|
||||
if let Some(arg)=std::env::args().nth(1){
|
||||
let path=std::path::PathBuf::from(arg);
|
||||
//if let Some(arg)=std::env::args().nth(1){
|
||||
//let path=std::path::PathBuf::from(arg);
|
||||
window_thread.send(TimedInstruction{
|
||||
time:integer::Time::ZERO,
|
||||
instruction:WindowInstruction::WindowEvent(winit::event::WindowEvent::DroppedFile(path)),
|
||||
instruction:WindowInstruction::WindowEvent(winit::event::WindowEvent::DroppedFile("".into())),
|
||||
}).unwrap();
|
||||
};
|
||||
//};
|
||||
|
||||
println!("Entering event loop...");
|
||||
let root_time=std::time::Instant::now();
|
||||
let root_time=chrono::Utc::now();
|
||||
run_event_loop(event_loop,window_thread,root_time).unwrap();
|
||||
}
|
||||
|
||||
fn run_event_loop(
|
||||
event_loop:winit::event_loop::EventLoop<()>,
|
||||
mut window_thread:crate::compat_worker::QNWorker<TimedInstruction<WindowInstruction>>,
|
||||
root_time:std::time::Instant
|
||||
root_time:chrono::DateTime<chrono::Utc>,
|
||||
)->Result<(),winit::error::EventLoopError>{
|
||||
event_loop.run(move |event,elwt|{
|
||||
let time=integer::Time::from_nanos(root_time.elapsed().as_nanos() as i64);
|
||||
let time=integer::Time::from_nanos((chrono::Utc::now()-root_time).num_nanoseconds().unwrap());
|
||||
// *control_flow=if cfg!(feature="metal-auto-capture"){
|
||||
// winit::event_loop::ControlFlow::Exit
|
||||
// }else{
|
||||
|
@ -25,8 +25,10 @@ impl WindowContext<'_>{
|
||||
}
|
||||
fn window_event(&mut self,time:integer::Time,event:winit::event::WindowEvent){
|
||||
match event{
|
||||
winit::event::WindowEvent::DroppedFile(path)=>{
|
||||
match crate::file::load(path.as_path()){
|
||||
winit::event::WindowEvent::DroppedFile(_path)=>{
|
||||
//match crate::file::load_file(path.as_path()){
|
||||
let data=include_bytes!("/run/media/quat/Files/Documents/map-files/verify-scripts/maps/bhop_snfm/5692152916.snfm");
|
||||
match crate::file::load(std::io::Cursor::new(data.as_slice())){
|
||||
Ok(map)=>self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ChangeMap(map)}).unwrap(),
|
||||
Err(e)=>println!("Failed to load map: {e}"),
|
||||
}
|
||||
|
1
web-client/.gitignore
vendored
Normal file
1
web-client/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/dist
|
2
web-client/Trunk.toml
Normal file
2
web-client/Trunk.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[build]
|
||||
target = "index.html"
|
25
web-client/index.html
Normal file
25
web-client/index.html
Normal file
@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1"/>
|
||||
<title>Strafe Client</title>
|
||||
|
||||
<base data-trunk-public-url />
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 0px;
|
||||
background: #fff;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.main-canvas {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas class="main-canvas" id="canvas"></canvas>
|
||||
<link data-trunk rel="rust" href="../strafe-client/Cargo.toml"/>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user