Merge remote-tracking branch 'pr/1870' into wave-6
This commit is contained in:
@ -222,6 +222,11 @@ speed, in the picture and in simply being able to play it:
|
||||
`--set VICTORY_WATER_VOLUME_PORTALS=1` separately enables an experimental
|
||||
lowering for the volume-portals compute shader on 32-lane hosts. An explicit
|
||||
`VICTORY_WAVE_WIDE` setting takes precedence.
|
||||
- **The screen stays on with a pad in hand.** The title's pad input arrives
|
||||
through GameInput's synthetic pad, which the system's activity timer never
|
||||
counts, so Windows turned the picture off mid-session on its display
|
||||
timeout. A display and sleep request is now held for the whole run
|
||||
(`VICTORY_KEEP_AWAKE=0` leaves the power plan alone).
|
||||
- **One command to play**: the launcher builds the layer the first time and
|
||||
applies what the menu saved.
|
||||
- **`Get-NVIDIA-DLSS.cmd`**: the eight NVIDIA files that are loaded, about
|
||||
|
||||
@ -406,6 +406,26 @@ pub fn run(
|
||||
victory_hle::runtime::set_title_dll_loader(Box::new(move |file| {
|
||||
late.load(file, show).map_err(|e| format!("{e:#}"))
|
||||
}));
|
||||
// The screen stays on while the title runs: the pad's input reaches the
|
||||
// title through GameInput's synthetic pad, which the system's own activity
|
||||
// timer never counts, so the power plan's display timeout would turn the
|
||||
// picture off with the pad still in hand (`VICTORY_KEEP_AWAKE=0`: leave it
|
||||
// to the power plan). Held until the title's main thread ends.
|
||||
let _awake = if victory_hle::awake::asked() {
|
||||
match victory_hle::awake::hold() {
|
||||
Some(held) => {
|
||||
println!("display the screen stays on while the title runs");
|
||||
Some(held)
|
||||
}
|
||||
None => {
|
||||
println!("display the screen could not be held on: the power plan's timeouts apply");
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("display the power plan's own screen timeout (VICTORY_KEEP_AWAKE=0)");
|
||||
None
|
||||
};
|
||||
// SAFETY: imports are bound; from here on we run title code.
|
||||
let main = unsafe { Arc::new(image).spawn_main(dlls)? };
|
||||
let code = main
|
||||
|
||||
123
crates/victory-hle/src/awake.rs
Normal file
123
crates/victory-hle/src/awake.rs
Normal file
@ -0,0 +1,123 @@
|
||||
//! Keeps the host's screen on while the title runs.
|
||||
//!
|
||||
//! A pad is not a keyboard or a mouse: the title's input arrives through
|
||||
//! GameInput's synthetic pad, and the system's own activity timer never sees
|
||||
//! it. After the power plan's display timeout Windows turns the picture off
|
||||
//! with the pad still being worked, mid-cutscene or mid-chase, and the
|
||||
//! machine can then sleep too. On the console that does not happen: its shell
|
||||
//! holds a display deferral for the title that is running.
|
||||
//!
|
||||
//! [`hold`] takes that request on the host, and holds it for as long as its
|
||||
//! guard lives. `VICTORY_KEEP_AWAKE=0` leaves the power plan its own timeouts.
|
||||
|
||||
/// Whether the screen is held on for the run (`VICTORY_KEEP_AWAKE=0`: not).
|
||||
pub fn asked() -> bool {
|
||||
asked_for(std::env::var("VICTORY_KEEP_AWAKE").ok().as_deref())
|
||||
}
|
||||
|
||||
fn asked_for(value: Option<&str>) -> bool {
|
||||
value != Some("0")
|
||||
}
|
||||
|
||||
/// A display and sleep request, held until it is let go.
|
||||
#[cfg(windows)]
|
||||
#[must_use = "the request is let go as soon as the guard is dropped"]
|
||||
pub struct Awake {
|
||||
request: *mut std::ffi::c_void,
|
||||
}
|
||||
|
||||
/// Nothing to hold where the system has no power requests.
|
||||
#[cfg(not(windows))]
|
||||
#[must_use = "the request is let go as soon as the guard is dropped"]
|
||||
pub struct Awake;
|
||||
|
||||
/// Takes the request: the display stays on and the machine does not sleep.
|
||||
/// `None` when the system refuses it, and the run goes on without one.
|
||||
#[cfg(windows)]
|
||||
pub fn hold() -> Option<Awake> {
|
||||
use windows_sys::Win32::Foundation::CloseHandle;
|
||||
use windows_sys::Win32::System::Power::{
|
||||
PowerCreateRequest, PowerRequestDisplayRequired, PowerRequestSystemRequired,
|
||||
PowerSetRequest,
|
||||
};
|
||||
use windows_sys::Win32::System::Threading::{
|
||||
POWER_REQUEST_CONTEXT_SIMPLE_STRING, REASON_CONTEXT,
|
||||
};
|
||||
|
||||
// What `powercfg /requests` shows as the reason.
|
||||
let mut reason: Vec<u16> = "VIctory: the title is running\0".encode_utf16().collect();
|
||||
let mut context = REASON_CONTEXT {
|
||||
Flags: POWER_REQUEST_CONTEXT_SIMPLE_STRING,
|
||||
..Default::default()
|
||||
};
|
||||
context.Reason.SimpleReasonString = reason.as_mut_ptr();
|
||||
// SAFETY: a valid context; the string is copied by the call.
|
||||
let request = unsafe { PowerCreateRequest(&context) };
|
||||
if request.is_null() || request as isize == -1 {
|
||||
tracing::info!("the screen's power request was not created");
|
||||
return None;
|
||||
}
|
||||
for flag in [PowerRequestDisplayRequired, PowerRequestSystemRequired] {
|
||||
// SAFETY: the request we just created.
|
||||
if unsafe { PowerSetRequest(request, flag) } == 0 {
|
||||
tracing::info!(flag, "the screen's power request was refused");
|
||||
// SAFETY: as above, and it is not handed out.
|
||||
unsafe {
|
||||
windows_sys::Win32::System::Power::PowerClearRequest(
|
||||
request,
|
||||
PowerRequestDisplayRequired,
|
||||
);
|
||||
CloseHandle(request);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(Awake { request })
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub fn hold() -> Option<Awake> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
impl Drop for Awake {
|
||||
fn drop(&mut self) {
|
||||
use windows_sys::Win32::Foundation::CloseHandle;
|
||||
use windows_sys::Win32::System::Power::{
|
||||
PowerClearRequest, PowerRequestDisplayRequired, PowerRequestSystemRequired,
|
||||
};
|
||||
// SAFETY: a request from `hold`, which is not used again.
|
||||
unsafe {
|
||||
for flag in [PowerRequestDisplayRequired, PowerRequestSystemRequired] {
|
||||
PowerClearRequest(self.request, flag);
|
||||
}
|
||||
CloseHandle(self.request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_switch_is_on_unless_asked_off() {
|
||||
assert!(asked_for(None));
|
||||
assert!(asked_for(Some("1")));
|
||||
assert!(!asked_for(Some("0")));
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn a_request_is_taken_and_let_go() {
|
||||
// Some hosts refuse it; the guard is then `None` and the run goes on.
|
||||
if let Some(held) = hold() {
|
||||
drop(held);
|
||||
}
|
||||
// A second one after the first was cleared.
|
||||
if let Some(held) = hold() {
|
||||
drop(held);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,7 @@ mod image_watch;
|
||||
pub use victory_gpu::frame_phase;
|
||||
pub use victory_gpu::frames_begun;
|
||||
|
||||
pub mod awake;
|
||||
pub mod modules;
|
||||
mod registry;
|
||||
pub mod runtime;
|
||||
|
||||
Reference in New Issue
Block a user