mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
stuff
This commit is contained in:
parent
517838e2ae
commit
7dc33c2dce
|
@ -68,6 +68,14 @@ target_sdk_version = 30
|
|||
required = true
|
||||
glEsVersion = 0x00030000
|
||||
|
||||
[[package.metadata.android.uses_feature]]
|
||||
name = "android.hardware.touchscreen.multitouch"
|
||||
required = true
|
||||
|
||||
[[package.metadata.android.uses_feature]]
|
||||
name = "android.hardware.touchscreen.multitouch.distinct"
|
||||
required = true
|
||||
|
||||
[package.metadata.android.application.activity]
|
||||
config_changes = "orientation|keyboardHidden|screenLayout|screenSize"
|
||||
exported = true
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use glam::UVec2;
|
||||
use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView};
|
||||
use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch};
|
||||
use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch, RawKeyEvent, TouchPhase};
|
||||
use crate::rendering::Renderer;
|
||||
|
||||
pub mod player_actions;
|
||||
|
@ -36,17 +36,25 @@ pub fn process_glutin_events(world: &mut World, event: &Event<()>) {
|
|||
},
|
||||
|
||||
#[cfg(not(feature = "raw-evt"))]
|
||||
WindowEvent::KeyboardInput { device_id, input, is_synthetic } => {
|
||||
WindowEvent::KeyboardInput { device_id, event, .. } => {
|
||||
world.add_entity((
|
||||
EventComponent,
|
||||
InputDeviceEvent {
|
||||
device_id: *device_id,
|
||||
event: DeviceEvent::Key(*input)
|
||||
event: DeviceEvent::Key(RawKeyEvent {
|
||||
physical_key: event.physical_key,
|
||||
state: event.state,
|
||||
})
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
WindowEvent::Touch(touch) => {
|
||||
// if matches!(touch.phase, TouchPhase::Started | TouchPhase::Cancelled | TouchPhase::Ended) {
|
||||
// println!("TOUCH ==================== {:#?}", touch);
|
||||
// } else {
|
||||
// println!("TOUCH MOVED {:?} {}", touch.phase, touch.id);
|
||||
// }
|
||||
world.add_entity((
|
||||
EventComponent,
|
||||
TouchEvent(*touch)
|
||||
|
@ -73,7 +81,7 @@ pub fn process_glutin_events(world: &mut World, event: &Event<()>) {
|
|||
OnBeforeExitEvent
|
||||
));
|
||||
},
|
||||
|
||||
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,6 +130,7 @@ fn process_touch_events(
|
|||
let position = dvec2(event.0.location.x, event.0.location.y);
|
||||
match event.0.phase {
|
||||
TouchPhase::Started => {
|
||||
//println!("touch started: finger {}", event.0.id);
|
||||
touch_state.fingers.insert(event.0.id, Finger {
|
||||
id: event.0.id,
|
||||
device_id: event.0.device_id,
|
||||
|
@ -146,6 +147,7 @@ fn process_touch_events(
|
|||
}
|
||||
},
|
||||
TouchPhase::Ended | TouchPhase::Cancelled => {
|
||||
//println!("touch ended: finger {}", event.0.id);
|
||||
touch_state.fingers.remove(&event.0.id);
|
||||
},
|
||||
}
|
||||
|
|
|
@ -172,6 +172,8 @@ fn attach_console() {
|
|||
#[no_mangle]
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn android_main(app: android_activity::AndroidApp) {
|
||||
use android_activity::WindowManagerFlags;
|
||||
app.set_window_flags(WindowManagerFlags::FULLSCREEN, WindowManagerFlags::empty());
|
||||
kubi_main(app)
|
||||
}
|
||||
|
||||
|
@ -202,6 +204,13 @@ pub fn kubi_main(#[cfg(target_os = "android")] app: android_activity::AndroidApp
|
|||
world.add_workload(render);
|
||||
world.add_workload(after_frame_end);
|
||||
|
||||
//Save _visualizer.json
|
||||
#[cfg(feature = "generate_visualizer_data")]
|
||||
std::fs::write(
|
||||
"_visualizer.json",
|
||||
serde_json::to_string(&world.workloads_info()).unwrap(),
|
||||
).unwrap();
|
||||
|
||||
//Run pre-startup procedure
|
||||
world.run_workload(pre_startup).unwrap();
|
||||
|
||||
|
@ -217,31 +226,41 @@ pub fn kubi_main(#[cfg(target_os = "android")] app: android_activity::AndroidApp
|
|||
}
|
||||
};
|
||||
|
||||
//Initialize renderer
|
||||
{
|
||||
let settings = world.borrow::<UniqueView<GameSettings>>().unwrap();
|
||||
world.add_unique_non_send_sync(Renderer::init(&event_loop, &settings));
|
||||
}
|
||||
world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.)));
|
||||
|
||||
//Save _visualizer.json
|
||||
#[cfg(feature = "generate_visualizer_data")]
|
||||
std::fs::write(
|
||||
"_visualizer.json",
|
||||
serde_json::to_string(&world.workloads_info()).unwrap(),
|
||||
).unwrap();
|
||||
|
||||
//Run startup systems
|
||||
world.run_workload(startup).unwrap();
|
||||
|
||||
//Run the event loop
|
||||
let mut last_update = Instant::now();
|
||||
let mut ready = false;
|
||||
event_loop.run(move |event, window_target| {
|
||||
//Wait for the window to become active (required for android)
|
||||
if !ready {
|
||||
if Event::Resumed != event {
|
||||
window_target.set_control_flow(ControlFlow::Wait);
|
||||
return
|
||||
}
|
||||
|
||||
//Initialize renderer
|
||||
{
|
||||
let settings = world.borrow::<UniqueView<GameSettings>>().unwrap();
|
||||
world.add_unique_non_send_sync(Renderer::init(window_target, &settings));
|
||||
}
|
||||
world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.)));
|
||||
|
||||
//Run startup systems
|
||||
world.run_workload(startup).unwrap();
|
||||
|
||||
ready = true;
|
||||
}
|
||||
|
||||
window_target.set_control_flow(ControlFlow::Poll);
|
||||
|
||||
process_glutin_events(&mut world, &event);
|
||||
|
||||
#[allow(clippy::collapsible_match, clippy::single_match)]
|
||||
match event {
|
||||
#[cfg(target_os = "android")]
|
||||
Event::Suspended => {
|
||||
window_target.exit();
|
||||
}
|
||||
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
log::info!("exit requested");
|
||||
|
@ -249,6 +268,7 @@ pub fn kubi_main(#[cfg(target_os = "android")] app: android_activity::AndroidApp
|
|||
},
|
||||
_ => (),
|
||||
},
|
||||
|
||||
Event::AboutToWait => {
|
||||
//Update delta time (maybe move this into a system?)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue