Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix 241028 #140

Merged
merged 9 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions crates/av/src/audio_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn update_audio(
continue;
};

error!("clip {:?}", audio_source.0);
new_state = Some(AudioSourceState {
handle,
clip_url: audio_source.0.audio_clip_url.clone(),
Expand Down Expand Up @@ -160,8 +161,15 @@ fn update_audio(
);
playing_instance.set_playback_rate(playback_rate, AudioTween::default());
if let Some(time) = audio_source.0.current_time {
if let Some(err) = playing_instance.seek_to(time as f64) {
warn!("seek error: {}", err);
if time < 1e6 {
if let Some(err) = playing_instance.seek_to(time as f64) {
warn!("seek error: {}", err);
}
} else {
warn!(
"ignoring ridiculous time offset {} for audio clip `{}`",
time, audio_source.0.audio_clip_url
);
}
}
}
Expand All @@ -176,7 +184,14 @@ fn update_audio(
new_instance.with_playback_rate(audio_source.0.pitch.unwrap_or(1.0) as f64);

if let Some(time) = audio_source.0.current_time {
new_instance.start_from(time as f64);
if time < 1e6 {
new_instance.start_from(time as f64);
} else {
warn!(
"ignoring ridiculous start time {} for audio clip `{}`",
time, audio_source.0.audio_clip_url
);
}
}

commands.entity(ent).try_insert(AudioEmitter {
Expand Down
35 changes: 13 additions & 22 deletions crates/comms/src/livekit_room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
use std::sync::Arc;

use async_tungstenite::tungstenite::http::Uri;
use bevy::{
prelude::*,
tasks::{IoTaskPool, Task},
utils::HashMap,
};
use bevy::{prelude::*, utils::HashMap};
use futures_lite::StreamExt;
use livekit::{
id::TrackSid,
Expand Down Expand Up @@ -62,7 +58,7 @@ pub struct LivekitTransport {
}

#[derive(Component)]
pub struct LivekitConnection(pub Task<()>);
pub struct LivekitConnection;

pub fn start_livekit(
mut commands: Commands,
Expand Down Expand Up @@ -116,20 +112,17 @@ fn connect_livekit(
let receiver = new_transport.receiver.take().unwrap();
let sender = player_state.get_sender();

let task = IoTaskPool::get().spawn(livekit_handler(
transport_id,
remote_address,
receiver,
sender,
mic.subscribe(),
));
commands
.entity(transport_id)
.try_insert(LivekitConnection(task));
let subscription = mic.subscribe();

std::thread::spawn(move || {
livekit_handler(transport_id, remote_address, receiver, sender, subscription)
});

commands.entity(transport_id).try_insert(LivekitConnection);
}
}

async fn livekit_handler(
fn livekit_handler(
transport_id: Entity,
remote_address: String,
receiver: Receiver<NetworkMessage>,
Expand All @@ -145,20 +138,18 @@ async fn livekit_handler(
receiver.clone(),
sender.clone(),
mic.resubscribe(),
)
.await
{
) {
warn!("livekit error: {e}");
}
if receiver.lock().await.is_closed() {
if receiver.blocking_lock().is_closed() {
// caller closed the channel
return;
}
warn!("livekit connection dropped, reconnecting");
}
}

async fn livekit_handler_inner(
fn livekit_handler_inner(
transport_id: Entity,
remote_address: &str,
app_rx: Arc<Mutex<Receiver<NetworkMessage>>>,
Expand Down
4 changes: 2 additions & 2 deletions crates/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn load_frame(
commands
.entity(ent)
.remove::<FrameLoading>()
.insert(FrameProcess(instance))
.try_insert(FrameProcess(instance))
.try_push_children(&[child]);
}
}
Expand Down Expand Up @@ -195,7 +195,7 @@ fn process_frame(
commands
.entity(spawned_ent)
.remove::<Handle<StandardMaterial>>()
.insert(new_mats.add(SceneMaterial {
.try_insert(new_mats.add(SceneMaterial {
base: mat.clone(),
extension: SceneBound::new(bounds.clone(), config.graphics.oob),
}));
Expand Down
8 changes: 3 additions & 5 deletions crates/scene_runner/src/bounds_calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ pub fn scene_regions(parcels: impl Iterator<Item = IVec2>) -> Vec<Region> {

// gather horizontal
loop {
let next_col = (0..=extent.y)
.map(|y| rect_base + IVec2::new(extent.x + 1, y))
.collect::<Vec<_>>();
if next_col.iter().all(|p| region.contains(p)) {
for p in next_col {
let next_col = || (0..=extent.y).map(|y| rect_base + IVec2::new(extent.x + 1, y));
if next_col().all(|p| region.contains(&p)) {
for p in next_col() {
region.remove(&p);
}
extent.x += 1;
Expand Down
4 changes: 2 additions & 2 deletions crates/scene_runner/src/update_world/gltf_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ fn update_ready_gltfs(
// process collider
let mut collider_base_name = maybe_name
.map(Name::as_str)
.filter(|name| name.contains("_collider"));
.filter(|name| name.to_ascii_lowercase().contains("_collider"));

if collider_base_name.is_none() {
// check parent name also
Expand All @@ -658,7 +658,7 @@ fn update_ready_gltfs(
.ok()
.and_then(|(name, ..)| name)
.map(|name| name.as_str())
.filter(|name| name.contains("_collider"))
.filter(|name| name.to_ascii_lowercase().contains("_collider"))
}
let is_collider = collider_base_name.is_some();

Expand Down
24 changes: 20 additions & 4 deletions crates/scene_runner/src/update_world/scene_ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,20 @@ macro_rules! val {
match $pb.$u() {
YgUnit::YguUndefined => $d,
YgUnit::YguAuto => Val::Auto,
YgUnit::YguPoint => Val::Px($pb.$v),
YgUnit::YguPercent => Val::Percent($pb.$v),
YgUnit::YguPoint => {
if $pb.$v.is_nan() {
$d
} else {
Val::Px($pb.$v)
}
}
YgUnit::YguPercent => {
if $pb.$v.is_nan() {
$d
} else {
Val::Percent($pb.$v)
}
}
}
};
}
Expand All @@ -87,8 +99,12 @@ macro_rules! maybe_val {
match $pb.$u() {
YgUnit::YguUndefined => None,
YgUnit::YguAuto => Some(Val::Auto),
YgUnit::YguPoint => Some(Val::Px($pb.$v)),
YgUnit::YguPercent => Some(Val::Percent($pb.$v)),
YgUnit::YguPoint => Some(if $pb.$v.is_nan() { $d } else { Val::Px($pb.$v) }),
YgUnit::YguPercent => Some(if $pb.$v.is_nan() {
$d
} else {
Val::Percent($pb.$v)
}),
}
};
}
Expand Down
4 changes: 3 additions & 1 deletion crates/scene_runner/src/update_world/text_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ pub fn make_text_section(
_ => warn!("unrecognised text tag `{tag}`"),
}
section_start = section_start + close + 1;
} else {
break;
}
}

Expand All @@ -713,7 +715,7 @@ pub fn make_text_section(
let section_end = text[section_start..]
.char_indices()
.find(|(_, c)| *c == '<')
.map(|(ix, _)| section_start + ix)
.map(|(ix, _)| section_start + ix.max(1))
.unwrap_or(usize::MAX);

let style = TextStyle {
Expand Down
8 changes: 3 additions & 5 deletions crates/social/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::anyhow;
use bevy::{
log::{debug, warn},
tasks::IoTaskPool,
utils::{HashMap, HashSet},
};
use common::util::AsH160;
Expand Down Expand Up @@ -128,9 +127,8 @@ impl SocialClientHandler {
let (event_sx, event_rx) = mpsc::unbounded_channel();
let (response_sx, response_rx) = mpsc::unbounded_channel();

IoTaskPool::get()
.spawn(social_socket_handler(wallet, event_rx, response_sx))
.detach();
std::thread::spawn(move || social_socket_handler(wallet, event_rx, response_sx));

Some(Self {
is_initialized: false,
sender: event_sx,
Expand Down Expand Up @@ -336,7 +334,7 @@ impl SocialClientHandler {
}
}

async fn social_socket_handler(
fn social_socket_handler(
wallet: wallet::Wallet,
event_rx: UnboundedReceiver<FriendshipOutbound>,
response_sx: UnboundedSender<FriendData>,
Expand Down
4 changes: 3 additions & 1 deletion crates/ui_core/src/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ fn update_comboboxen(
On::<Defocus>::new(close_ui_silent),
On::<Click>::new(move |mut commands: Commands| {
debug!("selected {ix:?}");
commands.entity(popup.root).despawn_recursive();
if let Some(commands) = commands.get_entity(popup.root) {
commands.despawn_recursive();
}
let Some(mut commands) = commands.get_entity(ent) else {
warn!("no combo");
return;
Expand Down
Loading