Add resized/moved events, minor cleanup

This commit is contained in:
Phillip Stephens 2022-02-06 14:53:42 -08:00
parent c53ee12578
commit 710b9ae6b3
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
5 changed files with 43 additions and 24 deletions

View File

@ -3,6 +3,7 @@
#include <array> #include <array>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
#include <cinttypes>
namespace aurora { namespace aurora {
struct WindowSize; struct WindowSize;
@ -20,6 +21,8 @@ struct AppDelegate {
virtual bool onAppIdle(float dt) noexcept = 0; virtual bool onAppIdle(float dt) noexcept = 0;
virtual void onAppDraw() noexcept = 0; virtual void onAppDraw() noexcept = 0;
virtual void onAppPostDraw() noexcept = 0; virtual void onAppPostDraw() noexcept = 0;
virtual void onAppWindowResized(const WindowSize& size) noexcept = 0;
virtual void onAppWindowMoved(std::int32_t x, std::int32_t y) noexcept = 0;
virtual void onAppExiting() noexcept = 0; virtual void onAppExiting() noexcept = 0;
// virtual void resized([[maybe_unused]] const WindowSize& rect, [[maybe_unused]] bool sync) noexcept {} // virtual void resized([[maybe_unused]] const WindowSize& rect, [[maybe_unused]] bool sync) noexcept {}

View File

@ -1,9 +1,12 @@
#include "aurora.hpp" #include "aurora.hpp"
#include <cinttypes>
namespace aurora { namespace aurora {
void App_onAppLaunched(AppDelegate& cb) noexcept; void App_onAppLaunched(AppDelegate& cb) noexcept;
bool App_onAppIdle(AppDelegate& cb, float dt) noexcept; bool App_onAppIdle(AppDelegate& cb, float dt) noexcept;
void App_onAppDraw(AppDelegate& cb) noexcept; void App_onAppDraw(AppDelegate& cb) noexcept;
void App_onAppPostDraw(AppDelegate& cb) noexcept; void App_onAppPostDraw(AppDelegate& cb) noexcept;
void App_onAppWindowResized(AppDelegate& cb, const WindowSize& size) noexcept;
void App_onAppWindowMoved(AppDelegate& cb, std::int32_t x, std::int32_t y) noexcept;
void App_onAppExiting(AppDelegate& cb) noexcept; void App_onAppExiting(AppDelegate& cb) noexcept;
} // namespace aurora } // namespace aurora

View File

@ -5,5 +5,11 @@ void App_onAppLaunched(AppDelegate& cb) noexcept { return cb.onAppLaunched(); }
bool App_onAppIdle(AppDelegate& cb, float dt) noexcept { return cb.onAppIdle(dt); } bool App_onAppIdle(AppDelegate& cb, float dt) noexcept { return cb.onAppIdle(dt); }
void App_onAppDraw(AppDelegate& cb) noexcept { cb.onAppDraw(); } void App_onAppDraw(AppDelegate& cb) noexcept { cb.onAppDraw(); }
void App_onAppPostDraw(AppDelegate& cb) noexcept { cb.onAppPostDraw(); } void App_onAppPostDraw(AppDelegate& cb) noexcept { cb.onAppPostDraw(); }
void App_onAppWindowResized(AppDelegate& cb, const WindowSize& size) noexcept {
cb.onAppWindowResized(size);
}
void App_onAppWindowMoved(AppDelegate& cb, std::int32_t x, std::int32_t y) noexcept {
cb.onAppWindowMoved(x, y);
}
void App_onAppExiting(AppDelegate& cb) noexcept { cb.onAppExiting(); } void App_onAppExiting(AppDelegate& cb) noexcept { cb.onAppExiting(); }
} // namespace aurora } // namespace aurora

View File

@ -7,14 +7,16 @@ use std::{num::NonZeroU8, time::Instant};
use wgpu::Backend; use wgpu::Backend;
use winit::{ use winit::{
event::{Event, WindowEvent}, event::{Event, WindowEvent, KeyboardInput},
event_loop::ControlFlow, event_loop::ControlFlow,
}; };
use crate::{ use crate::{
gpu::{create_depth_texture, create_render_texture, initialize_gpu, DeviceHolder}, gpu::{create_depth_texture, create_render_texture, initialize_gpu, DeviceHolder},
imgui::{initialize_imgui, ImGuiState}, imgui::{initialize_imgui, ImGuiState},
shaders::render_into_pass, shaders::render_into_pass,
ffi::{WindowSize},
}; };
mod gpu; mod gpu;
@ -37,16 +39,20 @@ mod ffi {
pub(crate) fn App_onAppIdle(cb: Pin<&mut AppDelegate>, dt: f32) -> bool; pub(crate) fn App_onAppIdle(cb: Pin<&mut AppDelegate>, dt: f32) -> bool;
pub(crate) fn App_onAppDraw(cb: Pin<&mut AppDelegate>); pub(crate) fn App_onAppDraw(cb: Pin<&mut AppDelegate>);
pub(crate) fn App_onAppPostDraw(cb: Pin<&mut AppDelegate>); pub(crate) fn App_onAppPostDraw(cb: Pin<&mut AppDelegate>);
pub(crate) fn App_onAppWindowResized(cb: Pin<&mut AppDelegate>, size: &WindowSize);
pub(crate) fn App_onAppWindowMoved(cb: Pin<&mut AppDelegate>, x: i32, y: i32);
pub(crate) fn App_onAppExiting(cb: Pin<&mut AppDelegate>); pub(crate) fn App_onAppExiting(cb: Pin<&mut AppDelegate>);
} }
pub struct Window { pub struct Window {
pub(crate) inner: Box<WindowContext>, pub(crate) inner: Box<WindowContext>,
} }
pub struct WindowSize { pub struct WindowSize {
pub width: u32, pub width: u32,
pub height: u32, pub height: u32,
} }
#[derive(Debug)] #[derive(Debug)]
pub enum Backend { pub enum Backend {
Invalid, Invalid,
@ -62,12 +68,14 @@ mod ffi {
Pressed, Pressed,
Released, Released,
} }
pub enum MouseButton { pub enum MouseButton {
Left, Left,
Right, Right,
Middle, Middle,
Other, Other,
} }
pub enum SpecialKey { pub enum SpecialKey {
None = 0, None = 0,
F1 = 1, F1 = 1,
@ -97,6 +105,7 @@ mod ffi {
Down = 25, Down = 25,
Tab = 26, Tab = 26,
} }
pub struct KeyboardInput { pub struct KeyboardInput {
pub scancode: u32, pub scancode: u32,
pub state: ElementState, pub state: ElementState,
@ -177,9 +186,21 @@ fn app_run(mut delegate: cxx::UniquePtr<ffi::AppDelegate>) {
&app.gpu.surface_config, &app.gpu.surface_config,
&app.gpu.config, &app.gpu.config,
); );
// TODO resize callback unsafe {
let window_size = WindowSize{width: app.gpu.surface_config.width, height: app.gpu.surface_config.height};
ffi::App_onAppWindowResized(delegate.as_mut().unwrap(), &window_size);
}
}
Event::WindowEvent { event: WindowEvent::Moved(loc), ..} => {
unsafe {
ffi::App_onAppWindowMoved(delegate.as_mut().unwrap(), loc.x, loc.y);
}
}
Event::WindowEvent { event: WindowEvent::KeyboardInput {
input: KeyboardInput, .. }, .. } => {
} }
Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => {}
Event::WindowEvent { .. } => {} Event::WindowEvent { .. } => {}
Event::DeviceEvent { .. } => {} Event::DeviceEvent { .. } => {}
Event::UserEvent(_) => {} Event::UserEvent(_) => {}

View File

@ -365,20 +365,6 @@ public:
} }
OPTICK_FRAME("MainThread"); OPTICK_FRAME("MainThread");
// CGraphics::SetCommitResourcesAsLazy(m_cvarCommons.m_lazyCommitResources->toBoolean());
// TODO
// boo::SWindowRect rect = m_windowCallback.m_lastRect;
// rect.location = {0, 0};
// boo::IGraphicsCommandQueue* gfxQ = m_window->getCommandQueue();
// if (m_windowCallback.m_rectDirty) {
// gfxQ->resizeRenderTexture(m_renderTex, rect.size[0], rect.size[1]);
// CGraphics::SetViewportResolution({rect.size[0], rect.size[1]});
// m_windowCallback.m_rectDirty = false;
// } else if (m_firstFrame) {
auto rect = aurora::get_window_size();
CGraphics::SetViewportResolution({static_cast<int32_t>(rect.width), static_cast<int32_t>(rect.height)});
// }
// Check if fullscreen has been toggled, if so set the fullscreen cvar accordingly // Check if fullscreen has been toggled, if so set the fullscreen cvar accordingly
if (m_windowCallback.m_fullscreenToggleRequested) { if (m_windowCallback.m_fullscreenToggleRequested) {
@ -394,9 +380,6 @@ public:
// Let CVarManager inform all CVar listeners of the CVar's state and clear all mdoified flags if necessary // Let CVarManager inform all CVar listeners of the CVar's state and clear all mdoified flags if necessary
m_cvarManager.proc(); m_cvarManager.proc();
// TODO
// boo::IGraphicsDataFactory* gfxF = m_window->getMainContextDataFactory();
// float scale = std::floor(m_window->getVirtualPixelFactor() * 4.f) / 4.f;
if (!g_mainMP1 && m_projectInitialized) { if (!g_mainMP1 && m_projectInitialized) {
g_mainMP1.emplace(nullptr, nullptr); g_mainMP1.emplace(nullptr, nullptr);
g_mainMP1->Init(m_fileMgr, &m_cvarManager, m_voiceEngine.get(), *m_amuseAllocWrapper); g_mainMP1->Init(m_fileMgr, &m_cvarManager, m_voiceEngine.get(), *m_amuseAllocWrapper);
@ -404,10 +387,6 @@ public:
g_mainMP1->WarmupShaders(); g_mainMP1->WarmupShaders();
} }
} }
// if (!m_imGuiInitialized) {
// ImGuiEngine::Initialize(gfxF, m_window.get(), scale, m_fileMgr.getStoreRoot());
// m_imGuiInitialized = true;
// }
float dt = 1 / 60.f; float dt = 1 / 60.f;
if (m_cvarCommons.m_variableDt->toBoolean()) { if (m_cvarCommons.m_variableDt->toBoolean()) {
@ -453,6 +432,13 @@ public:
++logvisor::FrameIndex; ++logvisor::FrameIndex;
} }
void onAppWindowResized(const aurora::WindowSize& size) noexcept override {
CGraphics::SetViewportResolution({static_cast<s32>(size.width), static_cast<s32>(size.height)});
}
void onAppWindowMoved(std::int32_t x, std::int32_t y) noexcept override {
// TODO: implement this
}
void onAppExiting() noexcept override { void onAppExiting() noexcept override {
m_imGuiConsole.Shutdown(); m_imGuiConsole.Shutdown();
if (g_mainMP1) { if (g_mainMP1) {