From 26d357f169a37d565c0778d8ec6b99cd40b29d19 Mon Sep 17 00:00:00 2001 From: LunarAkai Date: Sun, 27 Jul 2025 20:22:17 +0200 Subject: [PATCH] i mean, it runs again,.. thats something --- moonhare_engine/src/game.rs | 19 ++++++++++--------- moonhare_engine/src/game_plugin.rs | 1 + playground/src/main.rs | 3 +++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/moonhare_engine/src/game.rs b/moonhare_engine/src/game.rs index 5ebbc2e..28cb9eb 100644 --- a/moonhare_engine/src/game.rs +++ b/moonhare_engine/src/game.rs @@ -1,6 +1,6 @@ -use std::{ops::DerefMut, sync::Mutex}; +use std::{ops::{ControlFlow, DerefMut}, sync::Mutex}; -use glium::{glutin::surface::WindowSurface, winit::{self, event::WindowEvent, event_loop::{self, EventLoop}, window::Window}}; +use glium::{glutin::surface::WindowSurface, winit::{self, event::{self, WindowEvent}, event_loop::{self, EventLoop}, window::Window}}; use crate::{game, game_plugin::GamePlugin, winit::winit_window::WinitWindow, ENGINE_NAME}; @@ -67,7 +67,6 @@ impl Game { pub fn run(&mut self) { while self.running { self.update(); - self.handle_events( self); self.render(); } @@ -82,13 +81,17 @@ impl Game { self.window } - fn handle_events(self, game: &mut Game) { - let _ = Box::new(self.event_loop).run(move |event, window_target| { + 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 => window_target.exit(), + glium::winit::event::WindowEvent::CloseRequested => { + + }, glium::winit::event::WindowEvent::Resized(window_size) => { - game.get_display().resize(window_size.into()); + }, glium::winit::event::WindowEvent::RedrawRequested => { @@ -100,7 +103,5 @@ impl Game { }, _ => (), } - }); - } } diff --git a/moonhare_engine/src/game_plugin.rs b/moonhare_engine/src/game_plugin.rs index 09d13ab..f24e161 100644 --- a/moonhare_engine/src/game_plugin.rs +++ b/moonhare_engine/src/game_plugin.rs @@ -6,4 +6,5 @@ pub trait GamePlugin { fn update(&mut self); fn render(&mut self, target: &mut Frame); fn cleanup(&mut self); + fn handle_events(&mut self); } \ No newline at end of file diff --git a/playground/src/main.rs b/playground/src/main.rs index 4b761c4..6b7bf95 100644 --- a/playground/src/main.rs +++ b/playground/src/main.rs @@ -56,6 +56,9 @@ impl GamePlugin for PlaygroundGame { } fn cleanup(&mut self) { + } + fn handle_events(&mut self) { + } }