Get watermark working in first stage

This commit is contained in:
hodasemi 2023-12-04 19:34:51 +01:00
parent b0b2b3e847
commit 171cedf181
4 changed files with 52 additions and 58 deletions

View file

@ -28,7 +28,7 @@ impl UiOverlay for Watermark {}
impl DataReceiver for Watermark { impl DataReceiver for Watermark {
fn game_phase_change(&mut self, phase: GamePhase) -> Result<()> { fn game_phase_change(&mut self, phase: GamePhase) -> Result<()> {
match phase { match phase {
GamePhase::None => self.gui.enable()?, GamePhase::None | GamePhase::TestDay => self.gui.enable()?,
_ => self.gui.disable()?, _ => self.gui.disable()?,
} }

View file

@ -378,7 +378,7 @@ impl Overlay {
write_log!("created RFactorData"); write_log!("created RFactorData");
for receiver in self.ui_elements.iter() { for receiver in self.ui_elements.iter() {
data.add_receiver(receiver.clone()); data.add_receiver(receiver.clone())?;
} }
} }
} }

View file

@ -12,6 +12,7 @@ pub struct Rendering {
queue: Arc<Mutex<Queue>>, queue: Arc<Mutex<Queue>>,
signal_semaphore: Arc<Semaphore>, signal_semaphore: Arc<Semaphore>,
fence: Arc<Fence>,
render_callbacks: Vec<Box<dyn Fn(u32) -> Result<Arc<CommandBuffer>> + Send + Sync>>, render_callbacks: Vec<Box<dyn Fn(u32) -> Result<Arc<CommandBuffer>> + Send + Sync>>,
} }
@ -45,6 +46,7 @@ impl Rendering {
Ok(Self { Ok(Self {
signal_semaphore: Semaphore::new(swapchain.device().clone())?, signal_semaphore: Semaphore::new(swapchain.device().clone())?,
fence: Fence::builder().build(swapchain.device().clone())?,
swapchain, swapchain,
images, images,
@ -95,7 +97,10 @@ impl Rendering {
wait_semaphores.len() wait_semaphores.len()
)); ));
self.queue.lock().unwrap().submit(None, &[submit])?; self.queue
.lock()
.unwrap()
.submit(Some(&self.fence), &[submit])?;
write_log!("submitted layer queue"); write_log!("submitted layer queue");

View file

@ -88,8 +88,15 @@ impl RFactorData {
}) })
} }
pub fn add_receiver(&mut self, receiver: Arc<Mutex<dyn UiOverlay>>) { pub fn add_receiver(&mut self, receiver: Arc<Mutex<dyn UiOverlay>>) -> Result<()> {
receiver
.lock()
.unwrap()
.game_phase_change(self.previous_game_phase)?;
self.receivers.push(receiver); self.receivers.push(receiver);
Ok(())
} }
fn now(&self) -> f32 { fn now(&self) -> f32 {
@ -100,8 +107,9 @@ impl RFactorData {
write_log!(" =================== update RFactorData ==================="); write_log!(" =================== update RFactorData ===================");
// get scoring info // get scoring info
match self.scoring_reader.vehicle_scoring(self.now()) { if let Some((scoring_info, vehicle_scorings)) =
Some((scoring_info, vehicle_scorings)) => { self.scoring_reader.vehicle_scoring(self.now())
{
self.last_scoring_read = self.start_time.elapsed(); self.last_scoring_read = self.start_time.elapsed();
write_log!(format!( write_log!(format!(
@ -122,7 +130,6 @@ impl RFactorData {
} }
} }
{
let phase = GamePhase::try_from(scoring_info.mSession)?; let phase = GamePhase::try_from(scoring_info.mSession)?;
if self.previous_game_phase != phase { if self.previous_game_phase != phase {
@ -137,7 +144,6 @@ impl RFactorData {
} }
write_log!(format!("GamePhase: {:?}", self.previous_game_phase)); write_log!(format!("GamePhase: {:?}", self.previous_game_phase));
}
for receiver in self.receivers.iter() { for receiver in self.receivers.iter() {
let mut rec_mut = receiver.lock().unwrap(); let mut rec_mut = receiver.lock().unwrap();
@ -147,23 +153,6 @@ impl RFactorData {
} }
} }
} }
None => {
let now = self.start_time.elapsed();
if now > (self.last_scoring_read + GAME_PHASE_TIME_OUT) {
if self.previous_game_phase != GamePhase::None {
self.previous_game_phase = GamePhase::None;
for receiver in self.receivers.iter() {
receiver
.lock()
.unwrap()
.game_phase_change(self.previous_game_phase)?;
}
}
}
}
}
// check telemetry data // check telemetry data
write_log!("before telemetry update"); write_log!("before telemetry update");