i'm blue dabededabeday

This commit is contained in:
LunarAkai 2025-08-03 19:00:45 +02:00
commit 5a88e1c4c2
6 changed files with 66 additions and 19 deletions

View file

@ -5,5 +5,6 @@ version.workspace = true
authors.workspace = true
[dependencies]
moonhare_graphics = { path = "../moonhare_graphics" }
moonhare_log = { path = "../moonhare_log" }
moonhare_window = { path = "../moonhare_window" }
moonhare_window = { path = "../moonhare_window" }

View file

@ -1,10 +1,10 @@
//! Base functionality for a Moonhare Game Engine Project
use std::sync::Arc;
use std::rc::Rc;
use moonhare_graphics::glium::{backend::Context, glutin::api::egl::context};
use moonhare_log::*;
use moonhare_window::{glfw::{self, PWindow}, platforms::glfw_window::GLFWWindow, Window, WindowRenderContext};
use moonhare_window::{glfw::PWindow, platforms::glfw_window::GLFWWindow};
pub mod basic;
/// Only one Game may exist per project
@ -12,8 +12,8 @@ pub mod basic;
pub struct Game {
pub is_running: bool,
pub name: String,
pub context: WindowRenderContext,
pub glfw_window: Option<GLFWWindow>
pub context: moonhare_window::WindowRenderContext,
pub glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>
}
impl Default for Game {
@ -21,7 +21,7 @@ impl Default for Game {
Self {
is_running: true,
name: default_game_name(),
context: WindowRenderContext::OPENGLGLFW,
context: moonhare_window::WindowRenderContext::OPENGLGLFW,
glfw_window: None,
}
}
@ -34,18 +34,28 @@ impl Game {
pub fn run(self) {
info("Running Game...");
let mut glfw_window_unwrapped: GLFWWindow = self.glfw_window.unwrap();
let mut glfw_window_unwrapped: moonhare_window::platforms::glfw_window::GLFWWindow = self.glfw_window.unwrap();
let mut context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
context = moonhare_graphics::build_context(glfw_window_unwrapped.glfw_window);
while self.is_running {
handle_window_event(&mut glfw_window_unwrapped);
while self.is_running {
let _ = move |mut window: GLFWWindow| {
handle_window_event(&mut window);
};
// update();
// render();
render(context.clone());
}
}
pub fn add_window(&mut self) {
moonhare_log::info(format!("Adding window to {:?}", self));
self.glfw_window =Some(Window::create(self.context).into());
self.glfw_window =Some(moonhare_window::Window::create(self.context).into());
}
}
@ -54,9 +64,15 @@ fn default_game_name() -> String {
}
/// Deals with GLFW Window Events (in `monhare_window`)
fn handle_window_event(glfw_window: &mut GLFWWindow) {
fn handle_window_event(glfw_window: &mut moonhare_window::platforms::glfw_window::GLFWWindow) {
glfw_window.glfw_window.glfw.poll_events();
for (_, event) in glfw::flush_messages(&glfw_window.events) {
GLFWWindow::handle_window_event(&mut glfw_window.glfw_window, event);
for (_, event) in moonhare_window::glfw::flush_messages(&glfw_window.events) {
moonhare_window::platforms::glfw_window::GLFWWindow::handle_window_event(&mut glfw_window.glfw_window, event);
}
}
fn render(context: Rc<Context>) {
let mut target = moonhare_graphics::glium::Frame::new(context.clone(), context.get_framebuffer_dimensions());
moonhare_graphics::glium::Surface::clear_color(&mut target, 0.0, 0.0, 1.0, 1.0);
target.finish().unwrap();
}