added log wrapper

This commit is contained in:
LunarAkai 2025-07-28 19:50:49 +02:00
commit 237dd614a2
15 changed files with 213 additions and 59 deletions

View file

@ -4,4 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
glium = "0.36.0"
glium = "0.36.0"
log = "0.4"
fern = "0.7"
winit = "0.30.12"

View file

@ -1,30 +1,28 @@
use std::{ops::{ControlFlow, DerefMut}, sync::Mutex};
use glium::{glutin::surface::WindowSurface, winit::{self, event::{self, WindowEvent}, event_loop::{self, EventLoop}, window::Window}};
use glium::{glutin::{api::egl::surface::Surface, surface::WindowSurface}, winit::{self, event::{self, WindowEvent}, event_loop::{self, EventLoop}, window::Window}, Display};
use winit::application::ApplicationHandler;
use crate::{game_plugin::GamePlugin, window::winit_window::WinitWindow, ENGINE_NAME};
use crate::{core::game, game_plugin::GamePlugin, window::winit_window::WinitWindow, ENGINE_NAME};
pub struct Game {
pub running: bool,
pub game_plugin: Option<Box<dyn GamePlugin>>,
pub window: Window,
pub display: glium::Display<WindowSurface>,
pub event_loop: EventLoop<()>
pub window: WinitWindow,
}
impl Game {
pub fn new() -> Self {
let _event_loop: EventLoop<()> = EventLoop::new().unwrap();
let _window = WinitWindow::construct_window(&_event_loop);
let mut game_window = WinitWindow::default();
_event_loop.run_app(&mut game_window);
Game {
running: true,
game_plugin: None,
window: _window.0,
display: _window.1,
event_loop: _event_loop,
window: game_window,
}
}
@ -33,8 +31,6 @@ 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 {
@ -49,13 +45,13 @@ impl Game {
}
pub fn render(&mut self) {
let mut target = self.display.draw();
//let mut target = display.draw();
if let Some(ref mut game_plugin) = self.game_plugin {
game_plugin.render(&mut target);
}
//if let Some(ref mut game_plugin) = self.game_plugin {
// game_plugin.render(&mut target);
//}
target.finish().unwrap();
//target.finish().unwrap();
}
pub fn cleanup(&mut self) {
@ -72,36 +68,4 @@ impl Game {
self.cleanup();
}
pub fn get_display(&self) -> &glium::Display<WindowSurface>{
&self.display
}
pub fn get_window(self) -> Window {
self.window
}
pub fn handle_events(&mut self, event: winit::event::Event<()>) {
if let Some(ref mut game_plugin) = self.game_plugin {
game_plugin.handle_events();
}
match event {
glium::winit::event::Event::WindowEvent { event, .. } => match event {
glium::winit::event::WindowEvent::CloseRequested => {
},
glium::winit::event::WindowEvent::Resized(window_size) => {
},
glium::winit::event::WindowEvent::RedrawRequested => {
},
_ => (),
}
glium::winit::event::Event::AboutToWait => {
},
_ => (),
}
}
}

View file

@ -1,15 +1,19 @@
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 glium::{backend::{glutin::SimpleWindowBuilder, Context}, glutin::{display::GetGlDisplay, prelude::GlContext, surface::WindowSurface}, winit::{self, dpi::LogicalSize, event_loop::{ActiveEventLoop, EventLoop}, raw_window_handle::HasDisplayHandle, window::{Window, WindowAttributes}}, Display};
use winit::application::ApplicationHandler;
use crate::window::window_config::WindowConfig;
use crate::ENGINE_NAME;
pub struct WinitWindow {}
#[derive(Default)]
pub struct WinitWindow {
pub window: Option<Window>,
}
impl WinitWindow {
/// constructs a new winit window
pub fn construct_window(event_loop: &EventLoop<()>) -> (Window, Display<WindowSurface>) {
impl ApplicationHandler for WinitWindow {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let config = WindowConfig::default();
let mut window_attributes = WindowAttributes::default();
@ -25,8 +29,18 @@ impl WinitWindow {
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)
self.window = Some(event_loop.create_window(window_attributes).unwrap());
}
fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: winit::window::WindowId,
event: winit::event::WindowEvent,
) {
todo!()
}
}