console.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //! Which console the title runs on. Titles pick settings (resolution,
  2. //! memory budgets) by it, so the user chooses; Series X unless told.
  3. use std::sync::atomic::{AtomicBool, Ordering};
  4. const GIB: usize = 1 << 30;
  5. #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
  6. pub enum Console {
  7. #[default]
  8. SeriesX,
  9. SeriesS,
  10. }
  11. impl Console {
  12. /// Title memory in bytes: (GPU-optimal, standard). Series X in the
  13. /// advanced configuration; Series S has one range, counted as standard
  14. /// (7,776 MiB, the published console-mode figure).
  15. // shortcut: later system updates gave Series S titles more (amount not
  16. // published here); the title sizes nothing from this figure
  17. // (it goes by the device type), so update it if a title does.
  18. pub const fn title_memory(self) -> (usize, usize) {
  19. match self {
  20. Console::SeriesX => (10 * GIB, 7 * GIB / 2),
  21. Console::SeriesS => (0, 7_776 << 20),
  22. }
  23. }
  24. pub const fn name(self) -> &'static str {
  25. match self {
  26. Console::SeriesX => "Xbox Series X",
  27. Console::SeriesS => "Xbox Series S",
  28. }
  29. }
  30. }
  31. static SERIES_S: AtomicBool = AtomicBool::new(false);
  32. /// Set before the title starts.
  33. pub fn set(console: Console) {
  34. SERIES_S.store(console == Console::SeriesS, Ordering::Relaxed);
  35. }
  36. pub fn current() -> Console {
  37. if SERIES_S.load(Ordering::Relaxed) {
  38. Console::SeriesS
  39. } else {
  40. Console::SeriesX
  41. }
  42. }