stuff oder so

This commit is contained in:
LunarAkai 2025-08-03 23:27:32 +02:00
commit 0eeb4b2563
8 changed files with 286 additions and 18 deletions

View file

@ -1,10 +1,10 @@
//! Base functionality for a Moonhare Game Engine Project
use std::{cell::{RefCell, RefMut}, rc::Rc, sync::Arc};
use std::rc::Rc;
use moonhare_graphics::glium::{backend::Context, glutin::api::egl::context, winit::event_loop};
use moonhare_graphics::{color::Color, glium::{backend::Context, glutin::api::egl::context}};
use moonhare_log::*;
use moonhare_window::{glfw::PWindow, platforms::glfw_window::GLFWWindow};
use moonhare_window::{platforms::glfw_window::GLFWWindow};
pub mod basic;
/// Only one Game may exist per project
@ -13,7 +13,7 @@ pub struct Game {
pub is_running: bool,
pub name: String,
pub context: moonhare_window::WindowRenderContext,
pub glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>
pub glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>,
}
impl Default for Game {
@ -27,6 +27,16 @@ impl Default for Game {
}
}
pub struct GraphicsHandler {
pub context: Option<Rc<Context>>
}
impl Default for GraphicsHandler {
fn default() -> Self {
Self { context: None }
}
}
impl Game {
pub fn new() -> Self {
Game::default()
@ -34,15 +44,15 @@ impl Game {
pub fn run(self) {
info("Running Game...");
let mut glfw_window_unwrapped = self.glfw_window;
let mut context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
let glfw_window_unwrapped = self.glfw_window;
let mut graphics_handler: GraphicsHandler = GraphicsHandler { ..Default::default() };
let context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
context = moonhare_graphics::build_context(glfw_window_unwrapped.clone().unwrap().glfw_window);
graphics_handler.context = Some(context.clone());
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.as_mut().unwrap());
render(context.clone());
@ -61,7 +71,7 @@ fn default_game_name() -> String {
}
/// Deals with GLFW Window Events (in `monhare_window`)
fn handle_window_event(mut glfw_window: &GLFWWindow) {
fn handle_window_event(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);
@ -69,8 +79,6 @@ fn handle_window_event(mut glfw_window: &GLFWWindow) {
}
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();
let target = moonhare_graphics::glium::Frame::new(context.clone(), context.get_framebuffer_dimensions());
moonhare_graphics::draw_background_color(Color::color_from_rgb(255, 255, 255), target);
}