damn, rust borrow checker got tamed >:3

This commit is contained in:
LunarAkai 2025-08-03 20:53:44 +02:00
commit 78b5348b92
2 changed files with 18 additions and 12 deletions

View file

@ -34,16 +34,16 @@ impl Game {
pub fn run(self) {
info("Running Game...");
let mut glfw_window_unwrapped: moonhare_window::platforms::glfw_window::GLFWWindow = self.glfw_window.unwrap();
let mut glfw_window_unwrapped = self.glfw_window;
let mut context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
context = moonhare_graphics::build_context(Rc::new(RefCell::new(glfw_window_unwrapped.glfw_window)));
context = moonhare_graphics::build_context(glfw_window_unwrapped.clone().unwrap().glfw_window);
let value = glfw_window_unwrapped;
let mut value = glfw_window_unwrapped;
while self.is_running {
// can't move glfwwindow cause i can't implement clone, or idk
handle_window_event(value);
handle_window_event(value.as_mut().unwrap());
render(context.clone());
// update();
@ -61,9 +61,9 @@ fn default_game_name() -> String {
}
/// Deals with GLFW Window Events (in `monhare_window`)
fn handle_window_event(mut glfw_window: GLFWWindow) {
glfw_window.glfw_window.glfw.poll_events();
for (_, event) in moonhare_window::glfw::flush_messages(&glfw_window.events) {
fn handle_window_event(mut glfw_window: &GLFWWindow) {
glfw_window.glfw_window.borrow_mut().glfw.poll_events();
for (_, event) in moonhare_window::glfw::flush_messages(&glfw_window.events.borrow()) {
moonhare_window::platforms::glfw_window::GLFWWindow::handle_window_event(&glfw_window, event);
}
}

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{cell::RefCell, rc::Rc, sync::Arc};
use glfw::{Context, Glfw, GlfwReceiver, PWindow, Window, WindowEvent};
use moonhare_event::{event::Event, events::window_events::window_close_event::WindowCloseEvent};
@ -7,14 +7,20 @@ use crate::{window_config, MoonhareWindow};
#[derive(Debug)]
pub struct GLFWWindow {
pub glfw_window: PWindow,
pub events: GlfwReceiver<(f64, WindowEvent)>,
pub glfw_window: Rc<RefCell<PWindow>>,
pub events: Rc<RefCell<GlfwReceiver<(f64, WindowEvent)>>>,
pub glfw: Glfw,
pub is_running: bool,
}
const APP_ID: &str = "de.lunarakai.moonhare_engine";
impl Clone for GLFWWindow {
fn clone(&self) -> Self {
Self { glfw_window: self.glfw_window.clone(), events: self.events.clone(), glfw: self.glfw.clone(), is_running: self.is_running.clone() }
}
}
impl GLFWWindow {
fn new() -> Self {
let mut glfw = glfw::init(glfw::fail_on_errors).unwrap();
@ -30,8 +36,8 @@ impl GLFWWindow {
window.make_current();
Self {
glfw_window: window.try_into().unwrap(),
events: events,
glfw_window: Rc::new(RefCell::new(window)),
events: Rc::new(RefCell::new(events)),
glfw: glfw,
is_running: true
}