2024-12-22 19:33:27 +00:00
|
|
|
// mod graphics;
|
|
|
|
// mod state;
|
|
|
|
mod map;
|
|
|
|
mod camera;
|
2024-08-29 08:52:03 +01:00
|
|
|
|
2024-09-29 16:11:41 +01:00
|
|
|
use std::{fmt::Debug, sync::Arc};
|
2024-09-08 19:03:55 +01:00
|
|
|
|
2024-09-29 16:11:41 +01:00
|
|
|
use log::debug;
|
2024-12-22 19:33:27 +00:00
|
|
|
// use state::State;
|
|
|
|
// use graphics::Graphics;
|
2024-09-08 19:03:55 +01:00
|
|
|
use winit::{application::ApplicationHandler, dpi::PhysicalSize, event::{Event, WindowEvent}, event_loop::EventLoop, window::{Window, WindowAttributes}};
|
2024-12-24 08:49:17 +00:00
|
|
|
use bevy::{prelude::*, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}};
|
2024-08-20 22:12:18 +01:00
|
|
|
|
2024-09-29 16:11:41 +01:00
|
|
|
pub fn dbg<V: Debug>(v: V) -> V {
|
|
|
|
debug!(target: "app", "{:?}", v);
|
|
|
|
v
|
|
|
|
}
|
|
|
|
|
2024-12-22 19:33:27 +00:00
|
|
|
// struct App<'a> {
|
|
|
|
// // event_loop: EventLoop<()>,
|
|
|
|
// window: Option<Arc<Window>>,
|
|
|
|
// graphics: Option<Graphics<'a>>,
|
|
|
|
// state: State
|
|
|
|
// }
|
|
|
|
// impl App<'_> {
|
|
|
|
// fn new() -> Self {
|
|
|
|
// Self {
|
|
|
|
// window: None,
|
|
|
|
// graphics: None,
|
|
|
|
// state: State::new()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2024-09-08 19:03:55 +01:00
|
|
|
|
2024-12-22 19:33:27 +00:00
|
|
|
// impl ApplicationHandler for App<'_> {
|
|
|
|
// fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
|
|
|
// #[cfg(not(any(target_family = "wasm", target_os = "android")))]
|
|
|
|
// let window = event_loop.create_window(
|
|
|
|
// WindowAttributes::default()
|
|
|
|
// .with_inner_size(PhysicalSize::new(1080*2/5, 2000*2/5))
|
|
|
|
// ).unwrap();
|
|
|
|
// #[cfg(target_os = "android")]
|
|
|
|
// let window = event_loop.create_window(
|
|
|
|
// WindowAttributes::default()
|
|
|
|
// // .with_inner_size(PhysicalSize::new(1080*2/5, 2000*2/5))
|
|
|
|
// ).unwrap();
|
|
|
|
// self.window = Some(Arc::new(window));
|
|
|
|
// self.graphics = Some(pollster::block_on(Graphics::init(&self.state, self.window.clone().unwrap())));
|
|
|
|
// }
|
|
|
|
// fn window_event(
|
|
|
|
// &mut self,
|
|
|
|
// event_loop: &winit::event_loop::ActiveEventLoop,
|
|
|
|
// window_id: winit::window::WindowId,
|
|
|
|
// event: WindowEvent,
|
|
|
|
// ) {
|
|
|
|
// match &event {
|
|
|
|
// WindowEvent::CloseRequested => event_loop.exit(),
|
|
|
|
// WindowEvent::RedrawRequested => {
|
|
|
|
// if let Some(g) = &mut self.graphics {
|
|
|
|
// self.state.update_if_needed();
|
|
|
|
// self.state.render(self.window.as_ref().unwrap().inner_size());
|
|
|
|
// g.update(&self.state);
|
|
|
|
// g.render(&self.state);
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// WindowEvent::MouseWheel { delta, .. } => {
|
|
|
|
// dbg!(delta);
|
|
|
|
// },
|
|
|
|
// _ => {}
|
|
|
|
// }
|
|
|
|
// self.graphics.as_mut().unwrap().window_event(&event, &self.window.as_ref().unwrap());
|
|
|
|
// self.state.window_event(&event, &self.window.as_ref().unwrap());
|
|
|
|
// }
|
|
|
|
// fn about_to_wait(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
|
|
|
// if let Some(window) = self.window.as_ref() {
|
|
|
|
// window.request_redraw();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2024-08-20 22:12:18 +01:00
|
|
|
|
2024-08-29 08:52:03 +01:00
|
|
|
#[cfg(not(target_os = "android"))]
|
|
|
|
pub fn main() {
|
|
|
|
// #[cfg(target_family = "wasm")]
|
|
|
|
// let (event_loop, window) = {
|
|
|
|
// use winit::platform::web::WindowExtWebSys;
|
|
|
|
// std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
|
|
|
// console_log::init().expect("could not initialize logger");
|
2024-08-20 22:12:18 +01:00
|
|
|
|
2024-08-29 08:52:03 +01:00
|
|
|
// let event_loop = winit::event_loop::EventLoop::new().unwrap();
|
|
|
|
// let window = winit::window::WindowBuilder::new().build(&event_loop).unwrap();
|
|
|
|
|
|
|
|
// web_sys::window()
|
|
|
|
// .unwrap()
|
|
|
|
// .document()
|
|
|
|
// .unwrap()
|
|
|
|
// .body()
|
|
|
|
// .unwrap()
|
|
|
|
// .append_child(&window.canvas().unwrap())
|
|
|
|
// .unwrap();
|
|
|
|
// (event_loop, window)
|
|
|
|
// };
|
|
|
|
|
2024-12-22 19:33:27 +00:00
|
|
|
App::new()
|
|
|
|
.add_plugins((
|
2024-12-24 08:49:17 +00:00
|
|
|
DefaultPlugins,
|
2024-12-22 19:33:27 +00:00
|
|
|
camera::Plugin,
|
2024-12-22 21:02:45 +00:00
|
|
|
map::Plugin,
|
|
|
|
FrameTimeDiagnosticsPlugin,
|
2024-12-24 08:49:17 +00:00
|
|
|
LogDiagnosticsPlugin {
|
|
|
|
filter: Some(vec![FrameTimeDiagnosticsPlugin::FPS]),
|
|
|
|
..Default::default()
|
|
|
|
}
|
2024-12-22 19:33:27 +00:00
|
|
|
))
|
|
|
|
.run();
|
2024-08-24 21:44:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "android")]
|
|
|
|
#[no_mangle]
|
|
|
|
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
2024-08-31 09:41:16 +01:00
|
|
|
use winit::platform::android::{EventLoopBuilderExtAndroid, activity::WindowManagerFlags};
|
2024-08-24 21:44:13 +01:00
|
|
|
|
2024-09-11 20:20:47 +01:00
|
|
|
android_logger::init_once(
|
|
|
|
android_logger::Config::default()
|
|
|
|
.with_max_level(log::LevelFilter::Debug)
|
|
|
|
.with_filter(android_logger::FilterBuilder::new().parse("app").build())
|
|
|
|
);
|
2024-08-29 08:52:03 +01:00
|
|
|
|
2024-09-29 16:11:41 +01:00
|
|
|
app.set_window_flags(WindowManagerFlags::KEEP_SCREEN_ON | WindowManagerFlags::FULLSCREEN, WindowManagerFlags::empty());
|
2024-08-31 09:41:16 +01:00
|
|
|
|
2024-08-29 08:52:03 +01:00
|
|
|
let event_loop = winit::event_loop::EventLoopBuilder::new()
|
2024-08-24 21:44:13 +01:00
|
|
|
.with_android_app(app)
|
|
|
|
.build()
|
2024-08-29 08:52:03 +01:00
|
|
|
.unwrap();
|
2024-09-11 20:20:47 +01:00
|
|
|
|
|
|
|
event_loop.run_app(&mut App::new()).unwrap();
|
2024-08-18 18:02:10 +01:00
|
|
|
}
|