Files
airdef/airdef-mod/src/capabilities.rs
T
chexit 9217f9a5cc Report camera readiness in /airdef capabilities
Pin the engine at 6a53a626c (API 30) and show render.camera-status: the
calling run's set-views cameras, whether the last noted frame was a world
frame, the request's world generation, each camera's reason and the run's
own main-view selection. As the other lines, this is a host milestone:
availability, request, preparation and why, not a GPU frame or a visible
picture. A unit test pins the line: readiness stays per camera and apart
from the run's main-view selection.

docs/ENGINE.md, the 4 November continuation and the status table now say
what prepared means (a picture encoded into the camera's target, or a
world frame drawn from it as this run's screen view, only for the run
whose selection the screen used), the per-run/per-world resets, and what
remains: GPU acceptance.

Verified: python3 tools/airdef.py check (gitlink, packer, mod needs 30,
fork 30, game 30); test-wasm 27 steps; airdef-mod 65 unit, 1 boundary and
5 scenarios; python3 -m unittest discover -s tools 28 tests.

Co-Authored-By: Kimi Code <noreply@moonshot.cn>
2026-11-04 21:08:23 +03:00

241 lines
7.8 KiB
Rust

//! Host milestones, not promises of audible output or completed GPU/file work.
use horizon_mod_sdk::render::{self, CapabilityReason, CapabilityState};
pub fn ready(s: &CapabilityState) -> bool {
s.generation != 0
&& s.available
&& s.enabled
&& s.request_accepted
&& s.prepared
&& s.reason == CapabilityReason::Ready
}
pub fn capture_problem(s: &CapabilityState) -> Option<&'static str> {
if !s.available {
Some("Движок не поддерживает подтверждение захвата")
} else if !s.enabled || s.generation == 0 {
Some("Захват недоступен без текущего мира")
} else if !s.request_accepted {
Some("Захват больше не принадлежит этой сессии мода")
} else if s.reason == CapabilityReason::Failed {
Some("Ошибка пути захвата движка")
} else {
None
}
}
/// Adopt the existing global preference once in this world, without switching it.
/// A configured request and actual backend preparation are still separate milestones.
pub fn acoustics() -> CapabilityState {
let s = render::acoustics_status();
if s.available && s.generation != 0 && !s.request_accepted {
render::set_acoustics(s.enabled);
render::acoustics_status()
} else {
s
}
}
fn reason(r: CapabilityReason) -> &'static str {
match r {
CapabilityReason::AwaitingWorld => "awaiting-world",
CapabilityReason::Disabled => "disabled",
CapabilityReason::NotRequested => "not-requested",
CapabilityReason::AwaitingBackend => "awaiting-backend",
CapabilityReason::Failed => "failed",
CapabilityReason::Ready => "ready",
}
}
fn line(
name: &str,
generation: u64,
available: bool,
enabled: bool,
accepted: bool,
prepared: bool,
why: &str,
) -> String {
format!("{name}: API={available}, включено={enabled}, запрос={accepted}, подготовлено={prepared}, поколение={generation}, {why}")
}
fn camera_line(s: &render::CameraState) -> String {
let cameras: Vec<String> = s
.cameras
.iter()
.map(|c| {
let why = match c.reason {
render::CameraReason::AwaitingFrame => "awaiting-frame",
render::CameraReason::Ready => "ready",
};
format!("{}:{}", c.id, why)
})
.collect();
let main = match s.main_view {
Some(id) => id.to_string(),
None => "нет".into(),
};
format!(
"Камеры: API={}, включено={}, запрос={}, подготовлено={}, поколение={}, {}, main={}, [{}]",
s.available,
s.enabled,
s.request_accepted,
s.prepared,
s.generation,
reason(s.reason),
main,
cameras.join("; ")
)
}
pub fn diagnostics() -> String {
let smoke = render::smoke_status();
let acoustic = acoustics();
let capture = render::capture_owner_status();
let lights = render::point_lights_status();
let sources = render::sound_sources_status();
let cameras = render::camera_status();
let smoke_reason = match smoke.reason {
render::SmokeReason::AwaitingFrame => "awaiting-frame",
render::SmokeReason::Disabled => "disabled",
render::SmokeReason::PathUnavailable => "path-unavailable",
render::SmokeReason::Ready => "ready",
};
[
"Возможности движка (API 30; подготовка не означает готовый GPU-кадр, слышимый звук или файл):".into(),
line(
"Дым",
smoke.generation,
smoke.available,
smoke.enabled,
smoke.request_accepted,
smoke.backend_ready,
smoke_reason,
),
line(
"Акустика",
acoustic.generation,
acoustic.available,
acoustic.enabled,
acoustic.request_accepted,
acoustic.prepared,
reason(acoustic.reason),
),
line(
"Точечный свет",
lights.generation,
lights.available,
lights.enabled,
lights.request_accepted,
lights.prepared,
reason(lights.reason),
),
line(
"Постоянные звуки",
sources.generation,
sources.available,
sources.enabled,
sources.request_accepted,
sources.prepared,
reason(sources.reason),
),
camera_line(&cameras),
line(
"Захват этого мода",
capture.generation,
capture.available,
capture.enabled,
capture.request_accepted,
capture.prepared,
reason(capture.reason),
),
]
.join("\n")
}
#[cfg(test)]
mod tests {
use super::*;
fn state() -> CapabilityState {
CapabilityState {
generation: 5,
available: true,
enabled: true,
request_accepted: true,
prepared: true,
reason: CapabilityReason::Ready,
}
}
#[test]
fn acceptance_alone_never_disables_the_working_fallback() {
assert!(ready(&state()));
for missing in 0..6 {
let mut s = state();
match missing {
0 => s.generation = 0,
1 => s.available = false,
2 => s.enabled = false,
3 => s.request_accepted = false,
4 => s.prepared = false,
_ => s.reason = CapabilityReason::AwaitingBackend,
}
assert!(!ready(&s));
}
}
#[test]
fn a_foreign_capture_is_not_success_and_preparing_is_not_failure() {
let mut s = state();
s.request_accepted = false;
assert!(capture_problem(&s).is_some());
s = state();
s.prepared = false;
s.reason = CapabilityReason::AwaitingBackend;
assert!(capture_problem(&s).is_none());
assert!(!ready(&s));
s.reason = CapabilityReason::Failed;
assert!(capture_problem(&s).is_some());
}
fn camera(id: u32, prepared: bool) -> render::CameraReadiness {
render::CameraReadiness {
id,
request_accepted: true,
prepared,
reason: if prepared {
render::CameraReason::Ready
} else {
render::CameraReason::AwaitingFrame
},
}
}
#[test]
fn the_camera_line_separates_readiness_from_the_screens_selection() {
let line = camera_line(&render::CameraState {
generation: 5,
available: true,
enabled: true,
request_accepted: true,
prepared: true,
reason: CapabilityReason::Ready,
cameras: vec![camera(7, true), camera(8, false)],
main_view: Some(7),
});
assert_eq!(
line,
"Камеры: API=true, включено=true, запрос=true, подготовлено=true, поколение=5, \
ready, main=7, [7:ready; 8:awaiting-frame]"
);
// No accepted submission: no cameras, no main view, and the reason says so.
let line = camera_line(&render::CameraState {
generation: 5,
available: true,
enabled: false,
request_accepted: false,
prepared: false,
reason: CapabilityReason::NotRequested,
cameras: Vec::new(),
main_view: None,
});
assert!(line.ends_with("not-requested, main=нет, []"), "{line}");
}
}