summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2024-10-07 20:45:14 -0400
committerMica White <botahamec@outlook.com>2024-10-07 20:45:14 -0400
commitea5db5846bc700f0da912225ddcb4be372359044 (patch)
treef478f7a1e9e3fbb6ca162ea51c5c626ceb3898c2 /src
parent509e5ce1e17417a70b9bcce8bc6e33c05106811d (diff)
Finish basic windowing stuff
Diffstat (limited to 'src')
-rw-r--r--src/main.rs82
1 files changed, 60 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs
index c8d4618..100cfea 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,6 +10,7 @@ use alligator_scripts::ScriptManager;
use alligator_sprites::SpriteManager;
use alligator_sys::{Renderer, RendererConfig, Window, WindowConfig, WindowEvent};
+use clap::Parser;
use pollster::FutureExt;
use serde::Deserialize;
use sha3::{Digest, Sha3_256};
@@ -67,6 +68,19 @@ pub struct Config {
vsync: bool,
}
+#[derive(Debug, Clone, Parser)]
+#[command(version, about, long_about = None)]
+pub struct CommandLineArguments {
+ /// The configuration, represented as a JSON object. If not specified,
+ /// this is retrieved from the game.json in the executable's directory.
+ #[arg(short, long)]
+ config: Option<Box<str>>,
+
+ /// Send and receive console commands through the stdio
+ #[arg(short, long)]
+ debug: bool,
+}
+
fn sprite_manager(config: &Config) -> SpriteManager {
SpriteManager::with_capacity(config.sprite_manager_capacity as usize)
}
@@ -98,10 +112,11 @@ fn script_manager(config: &Config) -> ScriptManager {
fn window(config: &Config) -> Window {
let config = WindowConfig {
title: config.window_title.clone(),
- default_width: config.default_window_width.get(),
- default_height: config.default_window_height.get(),
- default_x: 100,
- default_y: 100,
+ // TODO set window size properly
+ default_width: config.default_window_width.unwrap().get(),
+ default_height: config.default_window_height.unwrap().get(),
+ default_x: 200,
+ default_y: 200,
borderless_fullscreen: config.default_window_mode == ConfigWindowMode::BorderlessFullscreen,
visible: false,
};
@@ -111,8 +126,9 @@ fn window(config: &Config) -> Window {
fn renderer(config: &Config, window: &Window) -> Renderer {
let config = RendererConfig {
- width: config.default_window_width.get(),
- height: config.default_window_height.get(),
+ // TODO set window size properly
+ width: config.default_window_width.unwrap().get(),
+ height: config.default_window_height.unwrap().get(),
instance_capacity: config.sprite_manager_capacity,
fullscreen: false,
vsync: config.vsync,
@@ -122,14 +138,30 @@ fn renderer(config: &Config, window: &Window) -> Renderer {
}
fn main() {
- let console = Console::new(26009)
- .block_on()
- .expect("The console should not fail to start");
- profile::set_profiler(console.logger());
+ let args = CommandLineArguments::parse();
+
+ let console = if args.debug {
+ let console = Console::new(26009)
+ .block_on()
+ .expect("The console should not fail to start");
+ log::set_logger(Box::leak(Box::new(console.logger())))
+ .expect("this should be the only logger");
+ profile::set_profiler(console.logger());
+
+ Some(console)
+ } else {
+ None
+ };
- std::env::set_current_dir(std::env::current_exe().unwrap().parent().unwrap()).unwrap();
- let config = File::open("game.json").unwrap();
- let config: Config = serde_json::from_reader(config).unwrap();
+ //std::env::set_current_dir(std::env::current_exe().unwrap().parent().unwrap()).unwrap();
+
+ let config = match args.config {
+ Some(config) => serde_json::from_str(&config).unwrap(),
+ None => {
+ let config = File::open("game.json").unwrap();
+ serde_json::from_reader(config).unwrap()
+ }
+ };
let sprites = sprite_manager(&config);
let scripts = script_manager(&config);
@@ -140,15 +172,21 @@ fn main() {
let mut renderer = renderer(&config, &window);
window.set_visible(true);
- window.run(move |window, event| match event {
- Some(WindowEvent::RedrawRequest) => {
- renderer.render_frame();
- profile::finish_frame();
- }
- Some(WindowEvent::CloseRequest) => {
- std::process::exit(0);
+ window.run(move |window, event| {
+ match event {
+ Some(WindowEvent::RedrawRequest) => {
+ renderer.render_frame();
+ profile::finish_frame();
+ }
+ Some(WindowEvent::CloseRequest) => {
+ std::process::exit(0);
+ }
+ Some(_) => (),
+ None => window.request_redraw(),
+ };
+
+ if let Some(c) = &console {
+ c.flush().expect("why would this error?");
}
- Some(_) => (),
- None => window.request_redraw(),
})
}