that's how it's done, this winit shim is pretty small so I'mma just steal it and substitute my custom events in my own local winit shim

master
mitchellhansen 4 years ago
parent 6fb6e433fb
commit 813a5c5e64

@ -15,7 +15,7 @@ typed-arena = "2.0.1"
serde = { version = "1", features = ["derive"], optional = true }
log = "0.4"
png = "0.16"
winit = "0.24.0"
#winit = { version = "0.24.0"}
rand = { version = "0.7.2", features = ["wasm-bindgen"] }
bytemuck = "1"
noise = "0.6"
@ -32,4 +32,13 @@ legion = "0.3.1"
wgpu = "0.7.0"
imgui = "0.7.0"
imgui-wgpu = "0.14.0"
imgui-winit-support = "0.7.0"
winit-19 = { version = ">= 0.16, < 0.20", package = "winit", optional = true }
winit-20 = { version = ">= 0.20, < 0.22", package = "winit", optional = true }
winit-22 = { version = "0.22", package = "winit", optional = true }
winit-23 = { version = "0.23", package = "winit", optional = true }
winit-24 = { version = "0.24", package = "winit", optional = true }
[features]
default = ["winit-24"]
debug = ["winit-24"]

@ -2,8 +2,8 @@ use std::f32::consts::{FRAC_PI_2, PI};
use std::time::{Duration, Instant};
use cgmath::{Decomposed, InnerSpace, Matrix4, Point3, Rad, Vector3};
use winit::dpi::{LogicalPosition, PhysicalPosition};
use winit::event::{ElementState, MouseScrollDelta, VirtualKeyCode};
use winit_24::dpi::{LogicalPosition, PhysicalPosition};
use winit_24::event::{ElementState, MouseScrollDelta, VirtualKeyCode};
use crate::render::OPENGL_TO_WGPU_MATRIX;

File diff suppressed because it is too large Load Diff

@ -1,8 +1,7 @@
extern crate imgui;
extern crate imgui_wgpu;
extern crate imgui_winit_support;
extern crate tobj;
extern crate winit;
extern crate winit_24;
use std::f32::consts::PI;
use std::rc::Rc;
@ -31,13 +30,13 @@ use rapier3d::na::{Isometry, Isometry3, Vector, Vector3};
use rapier3d::pipeline::PhysicsPipeline;
use wgpu::{BindGroup, Buffer, TextureView};
use wgpu_subscriber;
use winit::{
use winit_24::{
event::{self, WindowEvent},
event_loop::{ControlFlow, EventLoop},
};
use winit::event::DeviceEvent::MouseMotion;
use winit::platform::unix::x11::ffi::Time;
use winit::window::Window;
use winit_24::event::DeviceEvent::MouseMotion;
use winit_24::platform::unix::x11::ffi::Time;
use winit_24::window::Window;
use crate::camera::{Camera, CameraController};
use crate::components::{Collider, Color, LoopState, Physics, Position};
@ -47,7 +46,7 @@ use crate::render::Renderer;
use legion::systems::{UnsafeResources, SyncResources};
use std::borrow::Borrow;
use imgui::__core::convert::TryInto;
use imgui_winit_support::WinitPlatform;
use crate::extended_winit_imgui_support::WinitPlatform;
mod camera;
mod components;
@ -56,6 +55,7 @@ mod light;
mod owned_event;
mod physics;
mod render;
mod extended_winit_imgui_support;
/*
@ -107,7 +107,6 @@ fn main() {
.build();
let mut update_schedule = Schedule::builder()
.add_system(physics::test_unsafe_system())
.add_system(physics::update_camera_system())
.add_system(physics::run_physics_system())
.add_system(physics::update_models_system())
@ -119,7 +118,7 @@ fn main() {
.build();
let event_loop = EventLoop::<OwnedEventExtension>::with_user_event();
let mut builder = winit::window::WindowBuilder::new();
let mut builder = winit_24::window::WindowBuilder::new();
builder = builder.with_title("MVGE");
let window = builder.build(&event_loop).unwrap();
@ -129,11 +128,11 @@ fn main() {
// Load up all the resources
{
let mut imgui_context = imgui::Context::create();
let mut platform = imgui_winit_support::WinitPlatform::init(&mut imgui_context);
let mut platform = extended_winit_imgui_support::WinitPlatform::init(&mut imgui_context);
platform.attach_window(
imgui_context.io_mut(),
&window,
imgui_winit_support::HiDpiMode::Default,
extended_winit_imgui_support::HiDpiMode::Default,
);
// imgui rendering context

@ -3,18 +3,20 @@ use std::path::PathBuf;
use gilrs::Event as GilEvent;
use legion::world::SubWorld;
use legion::*;
use winit::dpi::{PhysicalPosition, PhysicalSize};
use winit::event::DeviceEvent::MouseMotion;
use winit::event::{
use winit_24::dpi::{PhysicalPosition, PhysicalSize};
use winit_24::event::DeviceEvent::MouseMotion;
use winit_24::event::{
AxisId, DeviceEvent, DeviceId, ElementState, Event, KeyboardInput, ModifiersState, MouseButton,
MouseScrollDelta, StartCause, Touch, TouchPhase, WindowEvent,
};
use winit::window::{Theme, WindowId, Window};
use winit_24::window::{Theme, WindowId, Window};
use crate::camera::{Camera, CameraController};
use crate::owned_event::OwnedWindowEvent::MouseWheel;
use crate::{ImguiPlatform, ImguiContext};
use std::sync::{Mutex, Arc};
use std::cmp::Ordering;
use imgui::Io;
#[derive(Clone)]
pub enum OwnedUIEvent<T> {
@ -239,6 +241,7 @@ pub enum OwnedWindowEvent {
ThemeChanged(Theme),
}
/// Because I am a glutton for punishment I am going to just do a mono-event-dispatch-magoooo
#[system]
#[write_component(Camera)]
@ -250,13 +253,13 @@ pub fn event_dispatch(
#[resource] imgui_platform: &mut Arc<Mutex<ImguiPlatform>>,
#[resource] winit_window: &mut Window,
) {
use winit::event::Event::DeviceEvent;
use winit_24::event::Event::DeviceEvent;
for event in event_stack {
match event {
OwnedEvent::DeviceEvent {
event: winit::event::DeviceEvent::MouseMotion { delta },
event: winit_24::event::DeviceEvent::MouseMotion { delta },
..
} => {
let mut query = <(&mut CameraController)>::query();
@ -265,7 +268,7 @@ pub fn event_dispatch(
}
},
OwnedEvent::DeviceEvent {
event: winit::event::DeviceEvent::Key(keyboard_input),
event: winit_24::event::DeviceEvent::Key(keyboard_input),
..
} => {
let mut query = <(&mut CameraController)>::query();
@ -297,6 +300,6 @@ pub fn event_dispatch(
let mut imgui_context = &mut imgui_context.lock().unwrap().context;
let mut imgui_platform = &mut imgui_platform.lock().unwrap().platform;
imgui_platform.handle_event(imgui_context.io_mut(), &winit_window, &event.into());
imgui_platform.handle_event(imgui_context.io_mut(), &winit_window, &event);
}
}

@ -87,17 +87,6 @@ pub fn run_physics(
);
}
#[system]
#[write_component(Camera)]
pub fn test_unsafe(world: &mut SubWorld,
#[resource] loop_state: &mut LoopState,
// #[resource] imgui_context: &mut imgui::Context,
) {
}
#[system]
#[write_component(Camera)]

@ -17,15 +17,14 @@ use wgpu::{
Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView,
VertexState,
};
use winit::dpi::PhysicalSize;
use winit::platform::unix::x11::ffi::Time;
use winit::window::Window;
use winit_24::dpi::PhysicalSize;
use winit_24::platform::unix::x11::ffi::Time;
use winit_24::window::Window;
use crate::camera::{Camera, CameraController};
use crate::components::{Color, Mesh, Position, RangeCopy};
use crate::geometry::{import_mesh, vertex, Vertex};
use crate::light::{DirectionalLight, LightRaw};
use imgui_winit_support::WinitPlatform;
use imgui::*;
use imgui_wgpu::{Renderer as ImguiRenderer, RendererConfig as ImguiRendererConfig};
use std::cell::RefCell;

Loading…
Cancel
Save