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,67 +107,49 @@ 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!(
"new scoring info: vehicles: {}", "new scoring info: vehicles: {}",
scoring_info.mNumVehicles scoring_info.mNumVehicles
)); ));
// check for player id // check for player id
if scoring_info.mNumVehicles == 0 { if scoring_info.mNumVehicles == 0 {
self.player_id = None; self.player_id = None;
} else if self.player_id.is_none() { } else if self.player_id.is_none() {
for vehicle_scoring in vehicle_scorings.iter() { for vehicle_scoring in vehicle_scorings.iter() {
if vehicle_scoring.mIsPlayer != 0 { if vehicle_scoring.mIsPlayer != 0 {
write_log!(format!("player found: {}", vehicle_scoring.mID)); write_log!(format!("player found: {}", vehicle_scoring.mID));
self.player_id = Some(vehicle_scoring.mID); self.player_id = Some(vehicle_scoring.mID);
break; break;
}
}
}
{
let phase = GamePhase::try_from(scoring_info.mSession)?;
if self.previous_game_phase != phase {
self.previous_game_phase = phase;
for receiver in self.receivers.iter() {
receiver
.lock()
.unwrap()
.game_phase_change(self.previous_game_phase)?;
}
}
write_log!(format!("GamePhase: {:?}", self.previous_game_phase));
}
for receiver in self.receivers.iter() {
let mut rec_mut = receiver.lock().unwrap();
if rec_mut.update_for_phase(self.previous_game_phase) {
rec_mut.scoring_update(self.previous_game_phase, &vehicle_scorings)?;
} }
} }
} }
None => {
let now = self.start_time.elapsed();
if now > (self.last_scoring_read + GAME_PHASE_TIME_OUT) { let phase = GamePhase::try_from(scoring_info.mSession)?;
if self.previous_game_phase != GamePhase::None {
self.previous_game_phase = GamePhase::None;
for receiver in self.receivers.iter() { if self.previous_game_phase != phase {
receiver self.previous_game_phase = phase;
.lock()
.unwrap() for receiver in self.receivers.iter() {
.game_phase_change(self.previous_game_phase)?; receiver
} .lock()
} .unwrap()
.game_phase_change(self.previous_game_phase)?;
}
}
write_log!(format!("GamePhase: {:?}", self.previous_game_phase));
for receiver in self.receivers.iter() {
let mut rec_mut = receiver.lock().unwrap();
if rec_mut.update_for_phase(self.previous_game_phase) {
rec_mut.scoring_update(self.previous_game_phase, &vehicle_scorings)?;
} }
} }
} }