fix(engine): foundation→tableau drag hints, z-lift, and Android battery drain
Fixes #34, #35, #36 - all_hints: add Foundation as source for Tableau hints (guarded by take_from_foundation); previously H key never suggested Foundation→Tableau - end_drag / touch_end_drag: enforce take_from_foundation at input layer so a rejected-by-core MoveRequestEvent is never fired - animation_plugin: pub CARD_ANIM_Z_LIFT so card_plugin can consume it - update_card_entity: set CardAnim start.z = z + CARD_ANIM_Z_LIFT to eliminate 1-frame z artifact where animated card appeared behind resting cards - solitaire_app: use AutoVsync on Android (caps GPU at display Hz vs spinning at 200+ fps); add WinitSettings unfocused reactive_low_power so app draws ~1fps when backgrounded Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -19,6 +19,8 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::window::{MonitorSelection, PresentMode, WindowPosition};
|
||||
#[cfg(target_os = "android")]
|
||||
use bevy::winit::{UpdateMode, WinitSettings};
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use bevy::window::{Monitor, PrimaryMonitor, PrimaryWindow};
|
||||
#[cfg(not(target_os = "android"))]
|
||||
@@ -112,12 +114,22 @@ pub fn run() {
|
||||
name: Some("ferrous-solitaire".into()),
|
||||
resolution: window_resolution,
|
||||
position: window_position,
|
||||
// AutoNoVsync prefers Mailbox (triple-buffered) and
|
||||
// falls back to Immediate, eliminating the vsync stall
|
||||
// that AutoVsync produces during continuous window
|
||||
// resize on X11 / Wayland. The game's frame budget is
|
||||
// small enough that a few stray dropped frames from
|
||||
// disabling vsync are imperceptible.
|
||||
// On Android, AutoVsync caps the GPU at the display
|
||||
// refresh rate (~60-90 fps). Without it the renderer
|
||||
// spins as fast as the hardware allows, keeping the
|
||||
// GPU fully loaded and draining the battery even when
|
||||
// the game is completely idle.
|
||||
//
|
||||
// On desktop (X11 / Wayland) AutoNoVsync prefers
|
||||
// Mailbox (triple-buffered) and falls back to
|
||||
// Immediate, eliminating the vsync stall that
|
||||
// AutoVsync produces during continuous window resize.
|
||||
// The game's frame budget is small enough that a few
|
||||
// stray dropped frames from disabling vsync are
|
||||
// imperceptible on desktop.
|
||||
#[cfg(target_os = "android")]
|
||||
present_mode: PresentMode::AutoVsync,
|
||||
#[cfg(not(target_os = "android"))]
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
// Android windows always fill the screen; max_width/max_height
|
||||
// default to 0.0, which panics Bevy's clamp when min > max.
|
||||
@@ -204,6 +216,22 @@ pub fn run() {
|
||||
.add_plugins(SplashPlugin)
|
||||
.add_plugins(DiagnosticsHudPlugin);
|
||||
|
||||
// On Android the default WinitSettings use UpdateMode::Continuous for
|
||||
// the focused window, which means Bevy renders as fast as possible even
|
||||
// when the game is completely idle. Switching to reactive_low_power with
|
||||
// a 1-second ceiling when the app is backgrounded cuts wake-up frequency
|
||||
// from ~60 Hz to ≤1 Hz, dramatically reducing background battery drain.
|
||||
//
|
||||
// The focused mode stays Continuous so that card-slide animations remain
|
||||
// smooth. PresentMode::AutoVsync (set above) keeps the GPU capped at the
|
||||
// display refresh rate (~60 Hz) when foregrounded, which already prevents
|
||||
// the GPU from spinning at 200+ fps between vsync intervals.
|
||||
#[cfg(target_os = "android")]
|
||||
app.insert_resource(WinitSettings {
|
||||
focused_mode: UpdateMode::Continuous,
|
||||
unfocused_mode: UpdateMode::reactive_low_power(std::time::Duration::from_secs(1)),
|
||||
});
|
||||
|
||||
// Wire the runtime window icon. Bevy 0.18 has no first-class
|
||||
// `Window::icon` field; the icon is set through the underlying
|
||||
// `winit::window::Window` via `WinitWindows`. Android draws its
|
||||
|
||||
Reference in New Issue
Block a user