sevenx_engine 0.2.11

Engine de jogos 2D/3D completa com suporte Android, física, áudio, partículas, tilemap, UI, eventos e sistema 3D avançado com PBR.
Documentation
// SevenX Engine - Android Native Demo
// Versão nativa sem winit - funciona 100% no Android!

#[cfg(target_os = "android")]
use android_activity::{
    AndroidApp, InputStatus, MainEvent, PollEvent,
};

#[cfg(target_os = "android")]
use std::time::{Duration, Instant};

#[cfg(target_os = "android")]
#[unsafe(no_mangle)]
fn android_main(app: AndroidApp) {
    android_logger::init_once(
        android_logger::Config::default()
            .with_max_level(log::LevelFilter::Info)
            .with_tag("SevenX"),
    );
    
    log::info!("🤖 SevenX Android Native - Iniciando!");
    
    // Estado do jogo
    let mut score = 0;
    let mut touches = Vec::new();
    let mut last_update = Instant::now();
    let mut running = true;
    let mut window_ready = false;
    
    // Loop principal
    while running {
        app.poll_events(Some(Duration::from_millis(16)), |event| {
            match event {
                PollEvent::Wake => {
                    log::debug!("Wake event");
                }
                
                PollEvent::Timeout => {
                    if !window_ready {
                        return;
                    }
                    
                    // Update game
                    let now = Instant::now();
                    let dt = now.duration_since(last_update).as_secs_f32();
                    last_update = now;
                    
                    // Simples update
                    if !touches.is_empty() {
                        score += 1;
                        if score % 60 == 0 {
                            log::info!("Score: {} | Touches: {}", score, touches.len());
                        }
                    }
                }
                
                PollEvent::Main(main_event) => {
                    match main_event {
                        MainEvent::InitWindow { .. } => {
                            log::info!("✅ Window initialized!");
                            window_ready = true;
                        }
                        
                        MainEvent::TerminateWindow { .. } => {
                            log::info!("❌ Window terminated");
                            window_ready = false;
                        }
                        
                        MainEvent::WindowResized { .. } => {
                            log::info!("📐 Window resized");
                        }
                        
                        MainEvent::RedrawNeeded { .. } => {
                            if window_ready {
                                // Aqui seria o render
                                log::debug!("🎨 Redraw - Score: {}", score);
                            }
                        }
                        
                        MainEvent::InputAvailable { .. } => {
                            // Process input
                            touches.clear();
                            
                            if let Ok(mut iter) = app.input_events_iter() {
                                loop {
                                    let read_input = iter.next(|event| {
                                        // android-activity 0.5 usa métodos diferentes
                                        log::info!("👆 Input event received");
                                        touches.push((100.0, 100.0)); // Placeholder
                                        InputStatus::Handled
                                    });
                                    
                                    if !read_input {
                                        break;
                                    }
                                }
                            }
                        }
                        
                        MainEvent::GainedFocus => {
                            log::info!("🎯 Gained focus");
                        }
                        
                        MainEvent::LostFocus => {
                            log::info!("😴 Lost focus");
                        }
                        
                        MainEvent::Start => {
                            log::info!("▶️  Start");
                        }
                        
                        MainEvent::Resume { .. } => {
                            log::info!("▶️  Resume");
                        }
                        
                        MainEvent::Pause => {
                            log::info!("⏸️  Pause");
                        }
                        
                        MainEvent::Stop => {
                            log::info!("⏹️  Stop");
                        }
                        
                        MainEvent::Destroy => {
                            log::info!("💥 Destroy - Final Score: {}", score);
                            running = false;
                        }
                        
                        _ => {}
                    }
                }
                
                _ => {}
            }
        });
    }
    
    log::info!("👋 Encerrando - Score final: {}", score);
}

#[cfg(not(target_os = "android"))]
fn main() {
    println!("❌ Este exemplo só funciona no Android!");
    println!("Execute: cargo apk run --example android_native");
}