use super::super::generation::{PendingDenoiseGeneration, PendingGuideGeneration};
use crate::{
bridge::{
frame_cache::guide_pass::{GuideCache, GuideKey},
remote::{
handoff::HandoffMachine,
live_lane::LiveLane,
remote_render::{RemoteConnectionHandle, RemoteRenderHandle},
},
render_thread::{RedrawGate, RenderContext},
},
settings::LiveComputeTarget,
};
use indicatrix_net::SceneState;
use std::{
sync::{Arc, Mutex, PoisonError},
time::Instant,
};
#[derive(Debug, Clone, Copy, PartialEq)]
pub(super) struct Pose {
pub(super) yaw: f32,
pub(super) pitch: f32,
pub(super) distance: f32,
pub(super) light_yaw: f32,
pub(super) light_pitch: f32,
}
pub(super) fn current_pose(ctx: &Mutex<RenderContext>) -> Pose {
let guard = ctx
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
Pose {
yaw: guard.yaw,
pitch: guard.pitch,
distance: guard.distance,
light_yaw: guard.light_yaw,
light_pitch: guard.light_pitch,
}
}
#[must_use]
pub(super) fn current_drag_held(ctx: &Mutex<RenderContext>) -> bool {
ctx.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.camera_drag_held
}
pub(super) struct Orchestrator {
pub(super) handoff: HandoffMachine,
pub(super) remote_handle: Option<RemoteRenderHandle>,
pub(super) live_lane: Option<LiveLane>,
pub(super) lane_scene: Option<SceneState>,
pub(super) current_request_id: Option<u32>,
pub(super) next_request_id: u32,
pub(super) refusal_noted: bool,
pub(super) worker_label: String,
pub(super) scene_seen: (u64, Instant),
pub(super) gave_up_for: Option<(u64, LiveComputeTarget)>,
pub(super) remote_connection: Option<RemoteConnectionHandle>,
pub(super) display_only_refused: bool,
pub(super) remote_hdr: Option<bool>,
pub(super) last_pose: Pose,
pub(super) last_change_at: Instant,
pub(super) drag_was_held: bool,
pub(super) guide_cache: GuideCache,
pub(super) pending_guide_gen: Option<PendingGuideGeneration>,
pub(super) pending_denoise_gen: Option<PendingDenoiseGeneration>,
pub(super) last_denoised: Option<(GuideKey, Vec<u8>)>,
pub(super) redraw_gate: RedrawGate<()>,
pub(super) last_redraw_at: Option<Instant>,
pub(super) live_remote_was_allowed: bool,
}
impl Orchestrator {
pub(super) const fn alloc_request_id(&mut self) -> u32 {
let id = self.next_request_id;
self.next_request_id = self.next_request_id.wrapping_add(1);
id
}
}
pub(super) fn lock(state: &Arc<Mutex<Orchestrator>>) -> std::sync::MutexGuard<'_, Orchestrator> {
state.lock().unwrap_or_else(PoisonError::into_inner)
}