trying to eat the spaghetti (make it less)
This commit is contained in:
parent
3dd1a0caee
commit
4ad7d2ebd0
42 changed files with 189 additions and 668 deletions
|
|
@ -4,7 +4,5 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
glium = "0.36.0"
|
||||
log = "0.4"
|
||||
fern = "0.7"
|
||||
winit = "0.30.12"
|
||||
moonhare_internal = { path = "../crates/moonhare_internal" }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
use std::{ops::{ControlFlow, DerefMut}, sync::Mutex};
|
||||
|
||||
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::{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: WinitWindow,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
pub fn new() -> Self {
|
||||
let _event_loop: EventLoop<()> = EventLoop::new().unwrap();
|
||||
|
||||
let mut game_window = WinitWindow::default();
|
||||
_event_loop.run_app(&mut game_window);
|
||||
|
||||
Game {
|
||||
running: true,
|
||||
game_plugin: None,
|
||||
window: game_window,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_plugin(&mut self, plugin: Box<dyn GamePlugin>) {
|
||||
self.game_plugin = Some(plugin);
|
||||
}
|
||||
|
||||
pub fn init(&mut self) {
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.init();
|
||||
} else {
|
||||
panic!("Needs Game Plugin to run!");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.update();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self) {
|
||||
//let mut target = display.draw();
|
||||
|
||||
//if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
// game_plugin.render(&mut target);
|
||||
//}
|
||||
|
||||
//target.finish().unwrap();
|
||||
}
|
||||
|
||||
pub fn cleanup(&mut self) {
|
||||
if let Some(ref mut game_plugin) = self.game_plugin {
|
||||
game_plugin.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
while self.running {
|
||||
self.update();
|
||||
self.render();
|
||||
}
|
||||
|
||||
self.cleanup();
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
pub mod game;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
use glium::Frame;
|
||||
|
||||
|
||||
pub trait GamePlugin {
|
||||
fn init(&mut self);
|
||||
fn update(&mut self);
|
||||
fn render(&mut self, target: &mut Frame);
|
||||
fn cleanup(&mut self);
|
||||
fn handle_events(&mut self);
|
||||
}
|
||||
|
|
@ -1,24 +1,3 @@
|
|||
pub mod vertex;
|
||||
pub mod core;
|
||||
pub mod game_plugin;
|
||||
pub mod window;
|
||||
pub mod logger;
|
||||
|
||||
const ENGINE_NAME: &str = "Moonhare Engine";
|
||||
|
||||
|
||||
pub struct CPointer<T>(T);
|
||||
|
||||
impl<T> Drop for CPointer<T> {
|
||||
fn drop(&mut self) {
|
||||
println!("Dropping")
|
||||
}
|
||||
}
|
||||
|
||||
// rescaling: position *= factor;
|
||||
// rotating: new_position = vec2(pos.x * cos(angle) - pos.y * sin(angle), pos.x * sin(single) + pos.y * cos(angle));
|
||||
// skewing: position.x += position.y * factor;
|
||||
|
||||
|
||||
|
||||
pub use moonhare_internal::*;
|
||||
|
||||
pub const ENGINE_NAME: &str = "Moonhare Engine";
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
pub struct Logger {
|
||||
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
use glium::implement_vertex;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Vertex {
|
||||
pub position: [f32; 2],
|
||||
pub color: [f32; 3],
|
||||
}
|
||||
implement_vertex!(Vertex, position, color);
|
||||
|
||||
impl Vertex {
|
||||
pub fn define_shape(v1: Vertex, v2: Vertex, v3: Vertex) -> Vec<Vertex> {
|
||||
let shape = vec![
|
||||
v1,
|
||||
v2,
|
||||
v3
|
||||
];
|
||||
return shape;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
pub mod winit_window;
|
||||
pub mod window_config;
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
use glium::{backend::glutin::SimpleWindowBuilder, glutin::config::{ConfigTemplate, ConfigTemplateBuilder}, winit::window::WindowAttributes};
|
||||
|
||||
use crate::ENGINE_NAME;
|
||||
|
||||
/// General Config for [`WinitWindow`](crate::winit::winit_window::WinitWindow)
|
||||
pub struct WindowConfig {
|
||||
pub title: &'static str,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub visble: bool,
|
||||
pub decorations: bool,
|
||||
}
|
||||
|
||||
impl Default for WindowConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: ENGINE_NAME,
|
||||
width: 1280,
|
||||
height: 720,
|
||||
visble: default_visibility(),
|
||||
decorations: default_decorations(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_visibility() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_decorations() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
|
||||
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;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct WinitWindow {
|
||||
pub window: Option<Window>,
|
||||
}
|
||||
|
||||
|
||||
impl ApplicationHandler for WinitWindow {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let config = WindowConfig::default();
|
||||
|
||||
let mut window_attributes = WindowAttributes::default();
|
||||
|
||||
let logical_size = LogicalSize::new(config.width, config.height);
|
||||
window_attributes = window_attributes.with_inner_size(logical_size);
|
||||
window_attributes = window_attributes.with_max_inner_size(logical_size);
|
||||
|
||||
window_attributes = window_attributes.with_title(config.title)
|
||||
.with_fullscreen(None);
|
||||
|
||||
// Set Visible
|
||||
window_attributes = window_attributes.with_visible(true);
|
||||
|
||||
window_attributes = winit::platform::wayland::WindowAttributesExtWayland::with_name(window_attributes, ENGINE_NAME, "");
|
||||
|
||||
|
||||
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!()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue