hmm
This commit is contained in:
parent
2f78b4c810
commit
33440da8f7
10 changed files with 135 additions and 21 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
|
@ -509,6 +509,10 @@ version = "0.1.0"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "moonhare_game"
|
name = "moonhare_game"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"moonhare_log",
|
||||||
|
"moonhare_window",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "moonhare_graphics"
|
name = "moonhare_graphics"
|
||||||
|
|
@ -538,6 +542,7 @@ dependencies = [
|
||||||
name = "moonhare_window"
|
name = "moonhare_window"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"moonhare_log",
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,5 @@ version.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
moonhare_log = { path = "../moonhare_log" }
|
||||||
|
moonhare_window = { path = "../moonhare_window" }
|
||||||
69
crates/moonhare_game/src/basic/game_window.rs
Normal file
69
crates/moonhare_game/src/basic/game_window.rs
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
use moonhare_window::{window_config, winit_window::{self, WinitWindow}};
|
||||||
|
|
||||||
|
use crate::{basic::node::Node, Game};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct GameWindow {
|
||||||
|
pub title: &'static str,
|
||||||
|
pub width: u32,
|
||||||
|
pub height: u32,
|
||||||
|
pub visble: bool,
|
||||||
|
pub decorations: bool,
|
||||||
|
pub winit_window: Option<WinitWindow>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Node for GameWindow {
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for GameWindow {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
title: "window",
|
||||||
|
width: default_game_window_width(),
|
||||||
|
height: default_game_window_height(),
|
||||||
|
visble: default_game_window_visibility(),
|
||||||
|
decorations: default_game_window_decorations(),
|
||||||
|
winit_window: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GameWindow {
|
||||||
|
pub fn create() -> Self {
|
||||||
|
let mut window_config = window_config::WindowConfig::default();
|
||||||
|
moonhare_log::info(format!("creating window with config {:?}", window_config));
|
||||||
|
let mut window = Self::default();
|
||||||
|
window_config.title = window.title.to_owned();
|
||||||
|
window_config.width = window.width;
|
||||||
|
window_config.height = window.height;
|
||||||
|
window_config.visble = window.visble;
|
||||||
|
window_config.decorations = window.decorations;
|
||||||
|
|
||||||
|
let winit = winit_window::WinitWindow::new(window_config);
|
||||||
|
|
||||||
|
window.winit_window = Some(winit);
|
||||||
|
// todo: tell winit to create a window for us
|
||||||
|
moonhare_log::info(format!("created window {:?}", window));
|
||||||
|
window
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_game_window_title() -> String {
|
||||||
|
"Moonhare Engine".to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_game_window_width() -> u32 {
|
||||||
|
1280
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_game_window_height() -> u32 {
|
||||||
|
720
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_game_window_visibility() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_game_window_decorations() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
pub mod node;
|
pub mod node;
|
||||||
pub mod window;
|
pub mod game_window;
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
use crate::basic::{node::Node};
|
|
||||||
|
|
||||||
pub struct GameWindow {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Node for GameWindow {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +1,43 @@
|
||||||
//! Base functionality for a Moonhare Game Engine Project
|
//! Base functionality for a Moonhare Game Engine Project
|
||||||
|
|
||||||
|
use moonhare_log::*;
|
||||||
|
|
||||||
|
use crate::basic::game_window::GameWindow;
|
||||||
pub mod basic;
|
pub mod basic;
|
||||||
|
|
||||||
/// Only one Game may exist per project
|
/// Only one Game may exist per project
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
pub name: String
|
pub name: String,
|
||||||
|
pub primary_window: Option<GameWindow>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Game {
|
impl Default for Game {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: default_game_name()
|
name: default_game_name(),
|
||||||
|
primary_window: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Game {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Game::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(&self) {
|
||||||
|
info("Running Game...");
|
||||||
|
loop {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_window(&mut self) {
|
||||||
|
moonhare_log::info(format!("Adding window to {:?}", self));
|
||||||
|
if self.primary_window.is_none() {
|
||||||
|
moonhare_log::trace("Primary Window is none");
|
||||||
|
self.primary_window = Some(GameWindow::create());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@ authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
winit = "0.30.12"
|
winit = "0.30.12"
|
||||||
|
moonhare_log = { path = "../moonhare_log" }
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
/// General Config for [`WinitWindow`](crate::winit::winit_window::WinitWindow)
|
/// General Config for [`WinitWindow`](crate::winit::winit_window::WinitWindow)
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct WindowConfig {
|
pub struct WindowConfig {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
use winit::{application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent, event_loop::ActiveEventLoop, window::{Window, WindowAttributes}};
|
use winit::{application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent, event_loop::{self, ActiveEventLoop, EventLoop}, window::{Window, WindowAttributes}};
|
||||||
|
|
||||||
use crate::window_config::WindowConfig;
|
use crate::window_config::WindowConfig;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Debug)]
|
||||||
pub struct WinitWindow {
|
pub struct WinitWindow {
|
||||||
pub window: Option<Window>,
|
pub window: Window,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WinitWindow {
|
impl WinitWindow {
|
||||||
pub fn create_window(&mut self, event_loop: &ActiveEventLoop, config: WindowConfig) -> WinitWindow {
|
pub fn new(config: WindowConfig) -> Self {
|
||||||
|
moonhare_log::trace("Im inside the create window function in winit");
|
||||||
|
let event_loop = EventLoop::new().unwrap();
|
||||||
let mut window_attributes = WindowAttributes::default()
|
let mut window_attributes = WindowAttributes::default()
|
||||||
.with_title(config.title);
|
.with_title(config.title);
|
||||||
|
|
||||||
|
|
@ -20,9 +22,17 @@ impl WinitWindow {
|
||||||
window_attributes = window_attributes.with_visible(config.visble);
|
window_attributes = window_attributes.with_visible(config.visble);
|
||||||
window_attributes = window_attributes.with_decorations(config.decorations);
|
window_attributes = window_attributes.with_decorations(config.decorations);
|
||||||
|
|
||||||
let window = event_loop.create_window(window_attributes).unwrap();
|
let window = match event_loop.create_window(window_attributes) {
|
||||||
|
Ok(window) => window,
|
||||||
|
Err(err) => {
|
||||||
|
moonhare_log::error("Error creating window: {err}");
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
Self { window: Some(window) }
|
moonhare_log::info(format!("Winit WIndow: {:?}", window));
|
||||||
|
|
||||||
|
Self { window: window }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
use moonhare_engine::log::{self};
|
use moonhare_engine::{game::Game, log};
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = log::configere_logger();
|
let _ = log::configere_logger();
|
||||||
log::info("test");
|
log::info("test");
|
||||||
|
|
||||||
|
let mut game = Game::new();
|
||||||
|
game.add_window();
|
||||||
|
|
||||||
|
log::info(format!("Game: {:?}", game));
|
||||||
|
|
||||||
|
// Enters Loop
|
||||||
|
game.run();
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue