revert: bring back task abstraction
This commit is contained in:
@@ -34,7 +34,7 @@ wayland = [
|
|||||||
"dep:wgpu-hal",
|
"dep:wgpu-hal",
|
||||||
"dep:ash",
|
"dep:ash",
|
||||||
]
|
]
|
||||||
profile_tokio = ["dep:console-subscriber"]
|
profile_tokio = ["dep:console-subscriber", "tokio/tracing"]
|
||||||
profile_app = [
|
profile_app = [
|
||||||
"dep:tracing-tracy",
|
"dep:tracing-tracy",
|
||||||
"bevy/trace_tracy",
|
"bevy/trace_tracy",
|
||||||
@@ -101,7 +101,7 @@ toml = "0.9.7"
|
|||||||
# mathy stuffs
|
# mathy stuffs
|
||||||
glam = { version = "0.29.0", features = ["mint", "serde"] }
|
glam = { version = "0.29.0", features = ["mint", "serde"] }
|
||||||
mint = "0.5.9"
|
mint = "0.5.9"
|
||||||
tokio = { version = "1.39.2", features = ["rt-multi-thread", "signal", "time", "tracing"] }
|
tokio = { version = "1.39.2", features = ["rt-multi-thread", "signal", "time"] }
|
||||||
|
|
||||||
# bevy
|
# bevy
|
||||||
bevy = { version = "0.16", default-features = false, features = [
|
bevy = { version = "0.16", default-features = false, features = [
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use super::{
|
|||||||
scenegraph::Scenegraph,
|
scenegraph::Scenegraph,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
core::registry::OwnedRegistry,
|
core::{registry::OwnedRegistry, task},
|
||||||
nodes::{
|
nodes::{
|
||||||
Node, audio, drawable, fields, input, items,
|
Node, audio, drawable, fields, input, items,
|
||||||
root::{ClientState, Root},
|
root::{ClientState, Root},
|
||||||
@@ -143,11 +143,9 @@ impl Client {
|
|||||||
})
|
})
|
||||||
.unwrap_or_else(|| "??".to_string());
|
.unwrap_or_else(|| "??".to_string());
|
||||||
let _ = client.dispatch_join_handle.get_or_init(|| {
|
let _ = client.dispatch_join_handle.get_or_init(|| {
|
||||||
tokio::task::Builder::new()
|
task::new(
|
||||||
.name(&format!(
|
|| format!("Stardust client \"{exe_printable}\" dispatch, pid={pid_printable}"),
|
||||||
"Stardust client \"{exe_printable}\" dispatch, pid={pid_printable}",
|
{
|
||||||
))
|
|
||||||
.spawn({
|
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
@@ -157,15 +155,14 @@ impl Client {
|
|||||||
let _ = message_time_tx.send(Instant::now());
|
let _ = message_time_tx.send(Instant::now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
.unwrap()
|
)
|
||||||
|
.unwrap()
|
||||||
});
|
});
|
||||||
let _ = client.flush_join_handle.get_or_init(|| {
|
let _ = client.flush_join_handle.get_or_init(|| {
|
||||||
tokio::task::Builder::new()
|
task::new(
|
||||||
.name(&format!(
|
|| format!("Stardust client \"{exe_printable}\" flush, pid={pid_printable}"),
|
||||||
"Stardust client \"{exe_printable}\" flush, pid={pid_printable}",
|
{
|
||||||
))
|
|
||||||
.spawn({
|
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
@@ -174,8 +171,9 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
.unwrap()
|
)
|
||||||
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(client)
|
Ok(client)
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ pub mod error;
|
|||||||
pub mod registry;
|
pub mod registry;
|
||||||
pub mod resource;
|
pub mod resource;
|
||||||
pub mod scenegraph;
|
pub mod scenegraph;
|
||||||
|
pub mod task;
|
||||||
|
|||||||
21
src/core/task.rs
Normal file
21
src/core/task.rs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
use std::future::Future;
|
||||||
|
use tokio::task::JoinHandle;
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
pub fn new<
|
||||||
|
F: FnOnce() -> S,
|
||||||
|
S: AsRef<str>,
|
||||||
|
A: Future<Output = O> + Send + 'static,
|
||||||
|
O: Send + 'static,
|
||||||
|
>(
|
||||||
|
name_fn: F,
|
||||||
|
async_future: A,
|
||||||
|
) -> std::io::Result<JoinHandle<O>> {
|
||||||
|
#[cfg(not(feature = "profile_tokio"))]
|
||||||
|
let result = Ok(tokio::task::spawn(async_future));
|
||||||
|
#[cfg(feature = "profile_tokio")]
|
||||||
|
let result = tokio::task::Builder::new()
|
||||||
|
.name(name_fn().as_ref())
|
||||||
|
.spawn(async_future);
|
||||||
|
result
|
||||||
|
}
|
||||||
23
src/main.rs
23
src/main.rs
@@ -51,6 +51,7 @@ use bevy_mod_xr::session::{XrFirst, XrHandleEvents, XrSessionPlugin};
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use core::client::{Client, tick_internal_client};
|
use core::client::{Client, tick_internal_client};
|
||||||
use core::entity_handle::EntityHandlePlugin;
|
use core::entity_handle::EntityHandlePlugin;
|
||||||
|
use core::task;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use nodes::audio::AudioNodePlugin;
|
use nodes::audio::AudioNodePlugin;
|
||||||
use nodes::drawable::lines::LinesNodePlugin;
|
use nodes::drawable::lines::LinesNodePlugin;
|
||||||
@@ -167,19 +168,17 @@ async fn main() -> Result<AppExit, JoinError> {
|
|||||||
);
|
);
|
||||||
let socket = UnixListener::bind(locked_socket.socket_path)
|
let socket = UnixListener::bind(locked_socket.socket_path)
|
||||||
.expect("Couldn't spawn stardust server at {socket_path}");
|
.expect("Couldn't spawn stardust server at {socket_path}");
|
||||||
tokio::task::Builder::new()
|
task::new(|| "Stardust socket accept loop", async move {
|
||||||
.name("Stardust client accept loop")
|
loop {
|
||||||
.spawn(async move {
|
let Ok((stream, _)) = socket.accept().await else {
|
||||||
loop {
|
continue;
|
||||||
let Ok((stream, _)) = socket.accept().await else {
|
};
|
||||||
continue;
|
if let Err(e) = Client::from_connection(stream) {
|
||||||
};
|
error!(?e, "Unable to create client from connection");
|
||||||
if let Err(e) = Client::from_connection(stream) {
|
|
||||||
error!(?e, "Unable to create client from connection");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.unwrap();
|
})
|
||||||
|
.unwrap();
|
||||||
info!("Init client join loop");
|
info!("Init client join loop");
|
||||||
|
|
||||||
let project_dirs = ProjectDirs::from("", "", "stardust");
|
let project_dirs = ProjectDirs::from("", "", "stardust");
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ mod viewporter;
|
|||||||
mod vulkano_data;
|
mod vulkano_data;
|
||||||
mod xdg;
|
mod xdg;
|
||||||
|
|
||||||
use crate::BevyMaterial;
|
|
||||||
use crate::core::error::ServerError;
|
use crate::core::error::ServerError;
|
||||||
use crate::core::registry::OwnedRegistry;
|
use crate::core::registry::OwnedRegistry;
|
||||||
use crate::nodes::drawable::model::ModelNodeSystemSet;
|
use crate::nodes::drawable::model::ModelNodeSystemSet;
|
||||||
@@ -17,6 +16,7 @@ use crate::wayland::core::seat::SeatMessage;
|
|||||||
use crate::wayland::core::surface::Surface;
|
use crate::wayland::core::surface::Surface;
|
||||||
use crate::wayland::presentation::MonotonicTimestamp;
|
use crate::wayland::presentation::MonotonicTimestamp;
|
||||||
use crate::wayland::util::ClientExt;
|
use crate::wayland::util::ClientExt;
|
||||||
|
use crate::{BevyMaterial, core::task};
|
||||||
use bevy::app::{App, Plugin, Update};
|
use bevy::app::{App, Plugin, Update};
|
||||||
use bevy::ecs::schedule::IntoScheduleConfigs;
|
use bevy::ecs::schedule::IntoScheduleConfigs;
|
||||||
use bevy::ecs::system::{Local, Res, ResMut};
|
use bevy::ecs::system::{Local, Res, ResMut};
|
||||||
@@ -257,12 +257,11 @@ impl WaylandClient {
|
|||||||
.map(|exe| exe.to_string())
|
.map(|exe| exe.to_string())
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| "??".to_string());
|
.unwrap_or_else(|| "??".to_string());
|
||||||
let abort_handle = tokio::task::Builder::new()
|
let abort_handle = task::new(
|
||||||
.name(&format!(
|
|| format!("Wayland client \"{exe_printable}\" dispatch, pid={pid_printable}"),
|
||||||
"Wayland client \"{exe_printable}\" dispatch, pid={pid_printable}",
|
Self::dispatch_loop(client, message_source),
|
||||||
))
|
)?
|
||||||
.spawn(Self::dispatch_loop(client, message_source))?
|
.abort_handle();
|
||||||
.abort_handle();
|
|
||||||
|
|
||||||
Ok(WaylandClient { abort_handle })
|
Ok(WaylandClient { abort_handle })
|
||||||
}
|
}
|
||||||
@@ -383,10 +382,11 @@ impl Wayland {
|
|||||||
let listener = waynest_server::Listener::new_with_path(&socket_path)?;
|
let listener = waynest_server::Listener::new_with_path(&socket_path)?;
|
||||||
let _ = WAYLAND_DISPLAY.set(listener.socket_path().to_path_buf());
|
let _ = WAYLAND_DISPLAY.set(listener.socket_path().to_path_buf());
|
||||||
|
|
||||||
let abort_handle = tokio::task::Builder::new()
|
let abort_handle = task::new(
|
||||||
.name("Wayland client accept loop")
|
|| "Wayland socket accept loop",
|
||||||
.spawn(Self::handle_wayland_loop(listener))?
|
Self::handle_wayland_loop(listener),
|
||||||
.abort_handle();
|
)?
|
||||||
|
.abort_handle();
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
_lockfile,
|
_lockfile,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use super::toplevel::Toplevel;
|
use super::toplevel::Toplevel;
|
||||||
use crate::{
|
use crate::{
|
||||||
core::error::Result,
|
core::{error::Result, task},
|
||||||
nodes::{
|
nodes::{
|
||||||
drawable::model::ModelPart,
|
drawable::model::ModelPart,
|
||||||
items::panel::{
|
items::panel::{
|
||||||
@@ -137,14 +137,12 @@ impl Backend for XdgBackend {
|
|||||||
let Some(seat) = self.seat.upgrade() else {
|
let Some(seat) = self.seat.upgrade() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let _ = tokio::task::Builder::new()
|
let _ = task::new(|| "Apply cursor material", async move {
|
||||||
.name("Apply cursor material")
|
let Some(cursor) = seat.cursor_surface().await else {
|
||||||
.spawn(async move {
|
return;
|
||||||
let Some(cursor) = seat.cursor_surface().await else {
|
};
|
||||||
return;
|
cursor.apply_material(&model_part);
|
||||||
};
|
});
|
||||||
cursor.apply_material(&model_part);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
fn apply_surface_material(&self, surface: SurfaceId, model_part: &Arc<ModelPart>) {
|
fn apply_surface_material(&self, surface: SurfaceId, model_part: &Arc<ModelPart>) {
|
||||||
if let Some(surface) = self.surface_from_id(&surface) {
|
if let Some(surface) = self.surface_from_id(&surface) {
|
||||||
|
|||||||
Reference in New Issue
Block a user