use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Platform {
Windows,
Linux,
MacOS,
Android,
IOS,
Web,
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Architecture {
X86_64,
ARM64,
ARMv7,
X86,
Unknown,
}
pub struct PlatformInfo {
pub platform: Platform,
pub architecture: Architecture,
pub is_mobile: bool,
pub is_desktop: bool,
pub supports_keyboard: bool,
pub supports_mouse: bool,
pub supports_touch: bool,
pub supports_gamepad: bool,
pub supports_accelerometer: bool,
}
impl Platform {
pub fn current() -> Self {
#[cfg(target_os = "android")]
{
return Platform::Android;
}
#[cfg(all(target_os = "linux", not(target_os = "android")))]
{
return Platform::Linux;
}
#[cfg(target_os = "windows")]
{
return Platform::Windows;
}
#[cfg(target_os = "macos")]
{
return Platform::MacOS;
}
#[cfg(target_os = "ios")]
{
return Platform::IOS;
}
#[cfg(target_arch = "wasm32")]
{
return Platform::Web;
}
#[cfg(not(any(
target_os = "windows",
target_os = "linux",
target_os = "macos",
target_os = "ios",
target_os = "android",
target_arch = "wasm32"
)))]
{
return Platform::Unknown;
}
return Platform::Unknown;
}
pub fn name(&self) -> &'static str {
match self {
Platform::Windows => "Windows",
Platform::Linux => "Linux",
Platform::MacOS => "macOS",
Platform::Android => "Android",
Platform::IOS => "iOS",
Platform::Web => "Web",
Platform::Unknown => "Unknown",
}
}
pub fn is_mobile(&self) -> bool {
matches!(self, Platform::Android | Platform::IOS)
}
pub fn is_desktop(&self) -> bool {
matches!(self, Platform::Windows | Platform::Linux | Platform::MacOS)
}
}
impl Architecture {
pub fn current() -> Self {
#[cfg(target_arch = "x86_64")]
return Architecture::X86_64;
#[cfg(target_arch = "aarch64")]
return Architecture::ARM64;
#[cfg(target_arch = "arm")]
return Architecture::ARMv7;
#[cfg(target_arch = "x86")]
return Architecture::X86;
#[cfg(not(any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "arm",
target_arch = "x86"
)))]
return Architecture::Unknown;
}
pub fn name(&self) -> &'static str {
match self {
Architecture::X86_64 => "x86_64",
Architecture::ARM64 => "ARM64",
Architecture::ARMv7 => "ARMv7",
Architecture::X86 => "x86",
Architecture::Unknown => "Unknown",
}
}
}
impl PlatformInfo {
pub fn detect() -> Self {
let platform = Platform::current();
let architecture = Architecture::current();
let is_mobile = platform.is_mobile();
let is_desktop = platform.is_desktop();
Self {
platform,
architecture,
is_mobile,
is_desktop,
supports_keyboard: is_desktop,
supports_mouse: is_desktop,
supports_touch: is_mobile,
supports_gamepad: true, supports_accelerometer: is_mobile,
}
}
pub fn print_info(&self) {
println!("=== Platform Info ===");
println!("Platform: {}", self.platform.name());
println!("Architecture: {}", self.architecture.name());
println!("Type: {}", if self.is_mobile { "Mobile" } else { "Desktop" });
println!("\n=== Input Support ===");
println!("Keyboard: {}", if self.supports_keyboard { "✅" } else { "❌" });
println!("Mouse: {}", if self.supports_mouse { "✅" } else { "❌" });
println!("Touch: {}", if self.supports_touch { "✅" } else { "❌" });
println!("Gamepad: {}", if self.supports_gamepad { "✅" } else { "❌" });
println!("Accelerometer: {}", if self.supports_accelerometer { "✅" } else { "❌" });
}
pub fn recommended_graphics_quality(&self) -> &'static str {
match (self.platform, self.architecture) {
(Platform::Windows | Platform::Linux | Platform::MacOS, Architecture::X86_64 | Architecture::ARM64) => "High",
(Platform::Android | Platform::IOS, Architecture::ARM64) => "Medium",
(Platform::Android | Platform::IOS, Architecture::ARMv7) => "Low",
_ => "VeryLow",
}
}
pub fn recommended_resolution(&self) -> (u32, u32) {
match self.platform {
Platform::Windows | Platform::Linux | Platform::MacOS => (1280, 720),
Platform::Android | Platform::IOS => (854, 480),
Platform::Web => (800, 600),
Platform::Unknown => (640, 480),
}
}
pub fn supports_feature(&self, feature: &str) -> bool {
match feature {
"3d" => !self.is_mobile, "shaders" => !self.is_mobile,
"post_processing" => !self.is_mobile,
"multiplayer" => true,
"audio" => true,
"particles" => true,
"physics" => true,
_ => false,
}
}
}
pub fn auto_configure() -> crate::config::EngineConfig {
let info = PlatformInfo::detect();
let (width, height) = info.recommended_resolution();
crate::config::EngineConfig {
window_title: format!("SevenX Game - {}", info.platform.name()),
window_width: width,
window_height: height,
target_fps: 60,
clear_color: [20, 25, 35, 255],
gravity: 9.81,
}
}