considering to become a goose farmer /s
This commit is contained in:
parent
d93d7f10b4
commit
b5fd2a7bd8
7 changed files with 100 additions and 50 deletions
|
|
@ -1,6 +1,9 @@
|
|||
use glium::{backend::glutin::SimpleWindowBuilder, glutin::surface::WindowSurface, winit::{event_loop::EventLoop, window::Window}, Surface};
|
||||
use std::{ops::DerefMut, sync::Mutex};
|
||||
|
||||
use glium::{glutin::surface::WindowSurface, winit::{self, event::WindowEvent, event_loop::{self, EventLoop}, window::Window}};
|
||||
|
||||
use crate::{game, game_plugin::GamePlugin, winit::winit_window::WinitWindow, ENGINE_NAME};
|
||||
|
||||
use crate::{game_plugin::GamePlugin, ENGINE_NAME};
|
||||
|
||||
pub struct Game {
|
||||
pub running: bool,
|
||||
|
|
@ -12,8 +15,9 @@ pub struct Game {
|
|||
|
||||
impl Game {
|
||||
pub fn new() -> Self {
|
||||
let _event_loop = EventLoop::new().unwrap();
|
||||
let _window = SimpleWindowBuilder::new().with_title(ENGINE_NAME).build(&_event_loop);
|
||||
let _event_loop: EventLoop<()> = EventLoop::new().unwrap();
|
||||
|
||||
let _window = WinitWindow::construct_window(&_event_loop);
|
||||
|
||||
Game {
|
||||
running: true,
|
||||
|
|
@ -29,6 +33,8 @@ impl Game {
|
|||
}
|
||||
|
||||
pub fn init(&mut self) {
|
||||
self.window.set_fullscreen(None);
|
||||
self.window.set_decorations(true);
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.init();
|
||||
} else {
|
||||
|
|
@ -61,6 +67,7 @@ impl Game {
|
|||
pub fn run(&mut self) {
|
||||
while self.running {
|
||||
self.update();
|
||||
self.handle_events( self);
|
||||
self.render();
|
||||
}
|
||||
|
||||
|
|
@ -74,50 +81,26 @@ impl Game {
|
|||
pub fn get_window(self) -> Window {
|
||||
self.window
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* impl ApplicationHandler for Game {
|
||||
fn resumed(&mut self, event_loop: &event_loop::ActiveEventLoop) {
|
||||
|
||||
}
|
||||
|
||||
fn window_event(
|
||||
&mut self,
|
||||
event_loop: &event_loop::ActiveEventLoop,
|
||||
window_id: window::WindowId,
|
||||
event: WindowEvent,
|
||||
) {
|
||||
let _ = window_id;
|
||||
|
||||
|
||||
|
||||
fn handle_events(self, game: &mut Game) {
|
||||
let _ = Box::new(self.event_loop).run(move |event, window_target| {
|
||||
match event {
|
||||
glium::winit::event::Event::WindowEvent { event, .. } => match event {
|
||||
glium::winit::event::WindowEvent::CloseRequested => window_target.exit(),
|
||||
glium::winit::event::WindowEvent::Resized(window_size) => {
|
||||
game.get_display().resize(window_size.into());
|
||||
},
|
||||
glium::winit::event::WindowEvent::RedrawRequested => {
|
||||
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
glium::winit::event::Event::AboutToWait => {
|
||||
|
||||
WindowEvent::CloseRequested => {
|
||||
event_loop.exit();
|
||||
},
|
||||
WindowEvent::Resized(window_size) => {
|
||||
if let Some(window) = &self.window {
|
||||
if let Some(display) = &self.display {
|
||||
display.resize(window_size.into());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
WindowEvent::RedrawRequested => {
|
||||
if let Some(window) = &self.window {
|
||||
window.request_redraw();
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
fn about_to_wait(&mut self, _: &event_loop::ActiveEventLoop) {
|
||||
if let Some(window) = &self.window {
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
pub mod vertex;
|
||||
pub mod game;
|
||||
pub mod game_plugin;
|
||||
pub mod window;
|
||||
pub mod winit;
|
||||
pub mod logger;
|
||||
|
||||
const ENGINE_NAME: &str = "Moonhare Engine";
|
||||
|
||||
|
|
|
|||
3
moonhare_engine/src/logger/mod.rs
Normal file
3
moonhare_engine/src/logger/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub struct Logger {
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
pub struct WindowConfig {
|
||||
pub title: &'static str,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
}
|
||||
2
moonhare_engine/src/winit/mod.rs
Normal file
2
moonhare_engine/src/winit/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod winit_window;
|
||||
pub mod window_config;
|
||||
32
moonhare_engine/src/winit/window_config.rs
Normal file
32
moonhare_engine/src/winit/window_config.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use glium::{backend::glutin::SimpleWindowBuilder, glutin::config::{ConfigTemplate, ConfigTemplateBuilder}, winit::window::WindowAttributes};
|
||||
|
||||
use crate::ENGINE_NAME;
|
||||
|
||||
/// General Config for [`WinitWindow`](crate::winit::winit_window::WinitWindow)
|
||||
pub struct WindowConfig {
|
||||
pub title: &'static str,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub visble: bool,
|
||||
pub decorations: bool,
|
||||
}
|
||||
|
||||
impl Default for WindowConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: ENGINE_NAME,
|
||||
width: 1280,
|
||||
height: 720,
|
||||
visble: default_visibility(),
|
||||
decorations: default_decorations(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_visibility() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_decorations() -> bool {
|
||||
true
|
||||
}
|
||||
34
moonhare_engine/src/winit/winit_window.rs
Normal file
34
moonhare_engine/src/winit/winit_window.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
use glium::{backend::glutin::SimpleWindowBuilder, glutin::{display::GetGlDisplay, surface::WindowSurface}, winit::{self, dpi::LogicalSize, event_loop::{ActiveEventLoop, EventLoop}, raw_window_handle::HasDisplayHandle, window::{Window, WindowAttributes}}, Display};
|
||||
|
||||
use crate::winit::window_config::WindowConfig;
|
||||
|
||||
use crate::ENGINE_NAME;
|
||||
|
||||
pub struct WinitWindow {}
|
||||
|
||||
impl WinitWindow {
|
||||
/// constructs a new winit window
|
||||
pub fn construct_window(event_loop: &EventLoop<()>) -> (Window, Display<WindowSurface>) {
|
||||
let config = WindowConfig::default();
|
||||
|
||||
let mut window_attributes = WindowAttributes::default();
|
||||
|
||||
let logical_size = LogicalSize::new(config.width, config.height);
|
||||
window_attributes = window_attributes.with_inner_size(logical_size);
|
||||
window_attributes = window_attributes.with_max_inner_size(logical_size);
|
||||
|
||||
window_attributes = window_attributes.with_title(config.title)
|
||||
.with_fullscreen(None);
|
||||
|
||||
// Set Visible
|
||||
window_attributes = window_attributes.with_visible(true);
|
||||
|
||||
window_attributes = winit::platform::wayland::WindowAttributesExtWayland::with_name(window_attributes, ENGINE_NAME, "");
|
||||
|
||||
SimpleWindowBuilder::new().set_window_builder(window_attributes).build(event_loop)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue