cleanup, but window border still missing
This commit is contained in:
parent
fb49d28498
commit
d93d7f10b4
4 changed files with 63 additions and 74 deletions
|
|
@ -1,25 +1,26 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use glium::{glutin::surface::WindowSurface, winit::{application::ApplicationHandler, event::{Event, WindowEvent}, event_loop::{self, EventLoop, EventLoopBuilder}, window::{self, Window, WindowAttributes}}, Display};
|
||||
use glium::{backend::glutin::SimpleWindowBuilder, glutin::surface::WindowSurface, winit::{event_loop::EventLoop, window::Window}, Surface};
|
||||
|
||||
use crate::{game_plugin::GamePlugin, ENGINE_NAME};
|
||||
|
||||
pub struct Game {
|
||||
pub running: bool,
|
||||
pub game_plugin: Option<Box<dyn GamePlugin>>,
|
||||
pub window: Option<Window>,
|
||||
pub display: Option<glium::Display<WindowSurface>>,
|
||||
pub event_loop: Option<EventLoop<()>>
|
||||
pub window: Window,
|
||||
pub display: glium::Display<WindowSurface>,
|
||||
pub event_loop: EventLoop<()>
|
||||
}
|
||||
|
||||
impl Game {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
running: true,
|
||||
game_plugin: None,
|
||||
window: None,
|
||||
display: None,
|
||||
event_loop: None,
|
||||
let _event_loop = EventLoop::new().unwrap();
|
||||
let _window = SimpleWindowBuilder::new().with_title(ENGINE_NAME).build(&_event_loop);
|
||||
|
||||
Game {
|
||||
running: true,
|
||||
game_plugin: None,
|
||||
window: _window.0,
|
||||
display: _window.1,
|
||||
event_loop: _event_loop,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,42 +32,29 @@ impl Game {
|
|||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.init();
|
||||
} else {
|
||||
//todo!("Default Impl init")
|
||||
panic!("Needs Game Plugin to run!");
|
||||
}
|
||||
self.event_loop = Some(EventLoop::builder().build().expect("event loop building"));
|
||||
|
||||
let (_window, _display) = return_window(&self.event_loop.as_ref().unwrap());
|
||||
self.window = Some(_window);
|
||||
self.display = Some(_display);
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.update();
|
||||
} else {
|
||||
//todo!("Default Impl update")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self) {
|
||||
if let Some(ref display) = self.display{
|
||||
let mut target = display.draw();
|
||||
let mut target = self.display.draw();
|
||||
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.render(&mut target);
|
||||
} else {
|
||||
//todo!("Default Impl render")
|
||||
}
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.render(&mut target);
|
||||
}
|
||||
|
||||
let _ = &target.finish().unwrap();
|
||||
}
|
||||
target.finish().unwrap();
|
||||
}
|
||||
|
||||
pub fn cleanup(&mut self) {
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.cleanup();
|
||||
} else {
|
||||
//todo!("Default Impl cleanup")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,18 +68,18 @@ impl Game {
|
|||
}
|
||||
|
||||
pub fn get_display(&self) -> &glium::Display<WindowSurface>{
|
||||
self.display.as_ref().unwrap()
|
||||
&self.display
|
||||
}
|
||||
|
||||
pub fn get_window(self) -> Option<Window> {
|
||||
return self.window;
|
||||
pub fn get_window(self) -> Window {
|
||||
self.window
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl ApplicationHandler for Game {
|
||||
/* impl ApplicationHandler for Game {
|
||||
fn resumed(&mut self, event_loop: &event_loop::ActiveEventLoop) {
|
||||
self.window = Some(event_loop.create_window(Window::default_attributes()).unwrap())
|
||||
|
||||
}
|
||||
|
||||
fn window_event(
|
||||
|
|
@ -102,30 +90,34 @@ impl ApplicationHandler for Game {
|
|||
) {
|
||||
let _ = window_id;
|
||||
|
||||
|
||||
|
||||
match event {
|
||||
|
||||
WindowEvent::CloseRequested => {
|
||||
event_loop.exit();
|
||||
},
|
||||
WindowEvent::Resized(window_size) => {
|
||||
self.display.as_ref().unwrap().resize(window_size.into());
|
||||
if let Some(window) = &self.window {
|
||||
if let Some(display) = &self.display {
|
||||
display.resize(window_size.into());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
WindowEvent::RedrawRequested => {
|
||||
self.window.as_ref().unwrap().request_redraw();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fn return_window(event_loop: &EventLoop<()>) -> (Window, Display<WindowSurface>) {
|
||||
let (_window, display) = glium::backend::glutin::SimpleWindowBuilder::new()
|
||||
.with_title(crate::ENGINE_NAME)
|
||||
.build(event_loop);
|
||||
|
||||
return (_window, display);
|
||||
}
|
||||
} */
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
pub mod vertex;
|
||||
pub mod game;
|
||||
pub mod game_plugin;
|
||||
|
||||
use glium::{glutin::surface::WindowSurface, uniform, uniforms, winit::{event::{self, StartCause}, event_loop::{self, EventLoop, EventLoopBuilder}, window::{self, Window}}, Display, Surface};
|
||||
|
||||
|
||||
pub mod window;
|
||||
|
||||
const ENGINE_NAME: &str = "Moonhare Engine";
|
||||
|
||||
|
|
|
|||
5
moonhare_engine/src/window.rs
Normal file
5
moonhare_engine/src/window.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
pub struct WindowConfig {
|
||||
pub title: &'static str,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue