engine/renderer: expose resolution, return correct cursor coords

master
q3k 2021-04-04 16:10:14 +00:00
parent 6d4088a173
commit 814d01533f
3 changed files with 19 additions and 4 deletions

View File

@ -167,7 +167,7 @@ impl<'a> ecs::System <'a> for Main {
type SystemData = MainData<'a>;
fn run(&mut self, sd: Self::SystemData) {
let position: f32 = match sd.input.get().mouse_cursor() {
Some(cursor) => cursor.x,
Some(cursor) => cursor.x * 3.14 * 2.0,
_ => (sd.time.get().instant() / 10.0) * 3.14 * 2.0,
};

View File

@ -64,6 +64,7 @@ pub struct Renderer {
pub struct Status {
pub closed: bool,
pub input_device_id: u64,
pub resolution: [u32; 2],
}
impl ecs::Global for Status {}
@ -114,10 +115,16 @@ impl<'a> ecs::System<'a> for Renderer {
let view = &scene.get().view;
self.instance.flip(camera, view, &rd, &self.rm);
match self.instance.swapchain_dimensions() {
Some(res) => {
status.resolution = res.clone()
},
None => (),
}
if status.input_device_id == 0 {
status.input_device_id = input.allocate_device();
}
let (close, events) = self.poll_close();
if close {
status.closed = true;
@ -129,8 +136,11 @@ impl<'a> ecs::System<'a> for Renderer {
InternalEvent::MousePressed(button) => cursor.set_mouse_pressed(button),
InternalEvent::MouseReleased(button) => cursor.set_mouse_released(button),
InternalEvent::MouseMoved(x, y) => {
cursor.x = x as f32;
cursor.y = y as f32;
let (rx, ry) = (status.resolution[0], status.resolution[1]);
if rx != 0 && ry != 0 {
cursor.x = (x as f32) / (rx as f32);
cursor.y = (y as f32) / (ry as f32);
}
},
}
}
@ -155,6 +165,7 @@ impl Renderer {
world.set_global(Status {
closed: false,
input_device_id: 0,
resolution: [0u32; 2],
});
let mut instance = vulkan::Instance::new("abrasion".to_string());

View File

@ -168,6 +168,10 @@ impl<WT: 'static + Send + Sync> Instance<WT> {
self.armed = true;
}
pub fn swapchain_dimensions(&self) -> Option<[u32; 2]> {
Some(self.swapchain_binding.as_ref()?.chain.dimensions())
}
fn make_graphics_commands(
&mut self,
profiler: &mut Profiler,