First
This commit is contained in:
47
src/lib.rs
47
src/lib.rs
@ -2,8 +2,10 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
pub mod egui_renderer;
|
||||
pub mod hm_renderer;
|
||||
pub mod state;
|
||||
pub mod voxel;
|
||||
pub mod voxel_renderer;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -15,7 +17,8 @@ use winit::window::Window;
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
pub fn run() -> anyhow::Result<()> {
|
||||
pub fn run() -> anyhow::Result<()>
|
||||
{
|
||||
env_logger::init();
|
||||
|
||||
let event_loop = EventLoop::with_user_event().build()?;
|
||||
@ -27,12 +30,15 @@ pub fn run() -> anyhow::Result<()> {
|
||||
|
||||
// App struct
|
||||
#[derive(Default)]
|
||||
pub struct App {
|
||||
pub struct App
|
||||
{
|
||||
state: Option<State>,
|
||||
}
|
||||
|
||||
impl ApplicationHandler for App {
|
||||
fn resumed(&mut self, event_loop: &event_loop::ActiveEventLoop) {
|
||||
impl ApplicationHandler for App
|
||||
{
|
||||
fn resumed(&mut self, event_loop: &event_loop::ActiveEventLoop)
|
||||
{
|
||||
// Create window
|
||||
let window = Arc::new(
|
||||
event_loop
|
||||
@ -59,28 +65,35 @@ impl ApplicationHandler for App {
|
||||
event_loop: &event_loop::ActiveEventLoop,
|
||||
_window_id: winit::window::WindowId,
|
||||
event: winit::event::WindowEvent,
|
||||
) {
|
||||
)
|
||||
{
|
||||
let state = self.state.as_mut().unwrap();
|
||||
state.handle_event(&event);
|
||||
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
match event
|
||||
{
|
||||
WindowEvent::CloseRequested =>
|
||||
{
|
||||
event_loop.exit();
|
||||
}
|
||||
WindowEvent::RedrawRequested => {
|
||||
WindowEvent::RedrawRequested =>
|
||||
{
|
||||
state.render();
|
||||
state.get_window().request_redraw();
|
||||
}
|
||||
|
||||
WindowEvent::Resized(size) => {
|
||||
WindowEvent::Resized(size) =>
|
||||
{
|
||||
state.resize(size);
|
||||
}
|
||||
|
||||
WindowEvent::MouseWheel { delta, .. } => {
|
||||
WindowEvent::MouseWheel { delta, .. } =>
|
||||
{
|
||||
state.mouse_wheel(delta);
|
||||
}
|
||||
|
||||
_ => {}
|
||||
_ =>
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,16 +102,20 @@ impl ApplicationHandler for App {
|
||||
_event_loop: &event_loop::ActiveEventLoop,
|
||||
_device_id: winit::event::DeviceId,
|
||||
event: winit::event::DeviceEvent,
|
||||
) {
|
||||
)
|
||||
{
|
||||
let state = self.state.as_mut().unwrap();
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
match event {
|
||||
winit::event::DeviceEvent::MouseMotion { delta } => {
|
||||
match event
|
||||
{
|
||||
winit::event::DeviceEvent::MouseMotion { delta } =>
|
||||
{
|
||||
state.cursor_moved(delta.0 as f32, delta.1 as f32);
|
||||
}
|
||||
|
||||
_ => {}
|
||||
_ =>
|
||||
{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user