aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fparkan-game/src')
-rw-r--r--apps/fparkan-game/src/mission_hints.rs63
-rw-r--r--apps/fparkan-game/src/mission_notices.rs6
2 files changed, 44 insertions, 25 deletions
diff --git a/apps/fparkan-game/src/mission_hints.rs b/apps/fparkan-game/src/mission_hints.rs
index bd643aa3..66704479 100644
--- a/apps/fparkan-game/src/mission_hints.rs
+++ b/apps/fparkan-game/src/mission_hints.rs
@@ -8,20 +8,27 @@ use fparkan_path::{normalize_relative, PathPolicy};
use fparkan_platform_winit::text::{caption, StringResources};
use fparkan_runtime::MissionScriptOutcome;
use fparkan_vfs::VfsError;
-use std::{collections::VecDeque, path::Path, sync::Arc};
+use std::{path::Path, sync::Arc};
const WIDTH: u16 = 640;
const HEIGHT: u16 = 384;
const UV: [[f32; 2]; 4] = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]];
+const PAGER_DURATION_MS: u32 = 20_000;
pub(super) struct MissionHints {
messages: Option<MessageResources>,
range: EnvironmentGpuRange,
- waiting: VecDeque<(u32, String)>,
- active: Option<(u32, u32, u32)>,
+ pending: Option<PagerMessage>,
+ active: Option<(u32, u32)>,
outcome: Option<(MissionScriptOutcome, u32)>,
}
+struct PagerMessage {
+ index: u32,
+ body: String,
+ posted_ms: u32,
+}
+
struct MessageResources {
config: Arc<[u8]>,
catalog: Arc<[u8]>,
@@ -59,13 +66,13 @@ impl MissionHints {
Ok(Self {
messages,
range,
- waiting: VecDeque::new(),
+ pending: None,
active: None,
outcome: None,
})
}
- pub(super) fn enqueue(&mut self, index: u32) -> Result<(), String> {
+ pub(super) fn post(&mut self, index: u32, clock: u32) -> Result<(), String> {
let messages = self
.messages
.as_ref()
@@ -82,7 +89,11 @@ impl MissionHints {
.get(id)
.filter(|text| !text.trim().is_empty())
.ok_or_else(|| format!("missing string {id} for {symbol}"))?;
- self.waiting.push_back((index, body));
+ self.pending = Some(PagerMessage {
+ index,
+ body,
+ posted_ms: clock,
+ });
Ok(())
}
@@ -105,7 +116,7 @@ impl MissionHints {
.map_err(|error| error.to_string())?;
self.outcome = Some((outcome, height));
self.active = None;
- self.waiting.clear();
+ self.pending = None;
eprintln!("mission_outcome_text outcome={outcome:?} queue_time_ms={clock}");
height
};
@@ -115,15 +126,11 @@ impl MissionHints {
.map_err(|error| error.to_string());
}
self.outcome = None;
- if self
- .active
- .is_some_and(|(start, duration, _)| clock.wrapping_sub(start) >= duration)
- {
+ if let Some(message) = self.pending.take() {
self.active = None;
- }
- if self.active.is_none() {
- if let Some((index, body)) = self.waiting.pop_front() {
- let (height, rgba) = match caption(&body, WIDTH, HEIGHT) {
+ if pager_visible(message.posted_ms, clock) {
+ let index = message.index;
+ let (height, rgba) = match caption(&message.body, WIDTH, HEIGHT) {
Ok(caption) => caption,
Err(error) => {
eprintln!(
@@ -137,17 +144,17 @@ impl MissionHints {
renderer
.update_material_texture(self.range.material_index, 0, &texture(rgba))
.map_err(|error| error.to_string())?;
- // shortcut: reading time from character count until pager timing is recovered.
- let duration = (body.chars().count() as u32)
- .saturating_mul(45)
- .clamp(3500, 18_000);
- self.active = Some((clock, duration, height));
+ self.active = Some((message.posted_ms, height));
+ let posted_ms = message.posted_ms;
eprintln!(
- "mission_text index={index} queue_time_ms={clock} duration_ms={duration}"
+ "mission_text index={index} queue_time_ms={posted_ms} duration_ms={PAGER_DURATION_MS}"
);
}
}
- if let Some((_, _, occupied)) = self.active {
+ self.active = self
+ .active
+ .filter(|&(posted_ms, _)| pager_visible(posted_ms, clock));
+ if let Some((_, occupied)) = self.active {
self.place_caption(mesh, viewport, occupied);
}
renderer
@@ -213,6 +220,10 @@ impl MessageResources {
}
}
+fn pager_visible(posted_ms: u32, clock: u32) -> bool {
+ clock.wrapping_sub(posted_ms) < PAGER_DURATION_MS
+}
+
fn outcome_text(outcome: MissionScriptOutcome) -> Option<&'static str> {
// shortcut: use the caption panel until the native result dialog and its controls are reproduced.
match outcome {
@@ -236,6 +247,14 @@ mod tests {
use super::*;
#[test]
+ fn pager_expires_twenty_seconds_after_posting_across_clock_wrap() {
+ let posted = u32::MAX - 500;
+ assert!(pager_visible(posted, posted));
+ assert!(pager_visible(posted, posted.wrapping_add(19_999)));
+ assert!(!pager_visible(posted, posted.wrapping_add(20_000)));
+ }
+
+ #[test]
fn outcome_captions_only_show_for_terminal_states() {
assert!(outcome_text(MissionScriptOutcome::Active).is_none());
let victory = outcome_text(MissionScriptOutcome::Completed).unwrap();
diff --git a/apps/fparkan-game/src/mission_notices.rs b/apps/fparkan-game/src/mission_notices.rs
index b3f855bf..739eb628 100644
--- a/apps/fparkan-game/src/mission_notices.rs
+++ b/apps/fparkan-game/src/mission_notices.rs
@@ -21,12 +21,12 @@ impl StaticVulkanApp {
MissionNotice::Information(index) => {
#[cfg(windows)]
{
- let queued = self
+ let posted = self
.mission_hints
.as_mut()
.ok_or_else(|| "mission text resources unavailable".to_string())
- .and_then(|hints| hints.enqueue(index));
- if let Err(error) = queued {
+ .and_then(|hints| hints.post(index, clock_ms));
+ if let Err(error) = posted {
eprintln!(
"sim_coverage mission_text_unavailable=1 index={index} reason={error}"
);