1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// 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");
}