2024-04-21 16:23:40 +00:00
|
|
|
// ▄████████▄ + ███ + ▄█████████ ███ +
|
|
|
|
// ███▀ ▀███ + + ███ ███▀ + ███ + +
|
|
|
|
// ███ + ███ ███ ███ █████████ ███ ███ ███ ███
|
2024-04-21 17:34:00 +00:00
|
|
|
// ███ +███ ███ ███ ███ ███▐██████ ███ ███ ███
|
2024-04-21 16:23:40 +00:00
|
|
|
// ███ + ███ ███+ ███ +███ ███ + ███ ███ + ███
|
|
|
|
// ███▄ ▄███ ███▄ ███ ███ + ███ + ███ ███▄ ███
|
|
|
|
// ▀████████▀ + ▀███████ ███▄ ███▄ ▀████ ▀███████
|
|
|
|
// + + + ███
|
|
|
|
// + ▀████████████████████████████████████████████████████▀
|
2024-04-23 15:33:36 +00:00
|
|
|
//
|
|
|
|
// This module initializes the game, handles command-line arguments,
|
|
|
|
// and manages window-related key bindings.
|
2024-04-21 16:23:40 +00:00
|
|
|
|
2024-05-12 21:42:56 +00:00
|
|
|
pub mod actor;
|
|
|
|
pub mod audio;
|
|
|
|
pub mod camera;
|
|
|
|
pub mod chat;
|
|
|
|
pub mod cmd;
|
2024-05-12 21:57:21 +00:00
|
|
|
pub mod game;
|
2024-05-12 21:42:56 +00:00
|
|
|
pub mod hud;
|
|
|
|
pub mod load;
|
|
|
|
pub mod menu;
|
2024-05-12 21:44:10 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
pub mod nature;
|
2024-05-12 21:42:56 +00:00
|
|
|
pub mod var;
|
|
|
|
pub mod visual;
|
|
|
|
pub mod world;
|
2024-03-16 19:53:57 +00:00
|
|
|
|
2024-05-12 19:06:38 +00:00
|
|
|
pub mod prelude {
|
2024-05-12 21:57:21 +00:00
|
|
|
pub use crate::{actor, audio, camera, chat, cmd, game, hud, load, menu, nature, var, visual, world};
|
2024-05-12 20:17:17 +00:00
|
|
|
pub use crate::var::{FONT, Settings};
|
2024-05-12 19:06:38 +00:00
|
|
|
pub use crate::load::load_asset;
|
2024-05-12 20:17:17 +00:00
|
|
|
pub fn bool2vis(boolean: bool) -> bevy::prelude::Visibility {
|
|
|
|
if boolean {
|
|
|
|
bevy::prelude::Visibility::Inherited
|
|
|
|
} else {
|
|
|
|
bevy::prelude::Visibility::Hidden
|
|
|
|
}
|
|
|
|
}
|
2024-05-12 19:06:38 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 23:04:23 +00:00
|
|
|
use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode};
|
2024-03-18 03:41:52 +00:00
|
|
|
use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
|
2024-03-16 20:44:51 +00:00
|
|
|
use bevy::prelude::*;
|
2024-04-16 16:28:15 +00:00
|
|
|
use bevy::pbr::ExtendedMaterial;
|
2024-03-28 21:34:16 +00:00
|
|
|
use std::env;
|
2024-03-16 14:00:31 +00:00
|
|
|
|
2024-04-25 01:23:30 +00:00
|
|
|
const HELP: &str = "./outfly [options]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--version, -v show this program's version number and exit
|
|
|
|
--help, -h show this help message and exit
|
|
|
|
--gl use GL rendering instead of Vulkan
|
|
|
|
--fs-legacy use 'legacy' (non-borderless) fullscreen mode
|
|
|
|
--fs-sized use 'sized' (non-borderless) fullscreen mode
|
|
|
|
--windowed start in non-fullscreen mode
|
|
|
|
|
|
|
|
Note: borderless fullscreen is the default, but it crashes on some systems.";
|
|
|
|
|
2024-03-16 13:27:22 +00:00
|
|
|
fn main() {
|
2024-04-30 21:41:37 +00:00
|
|
|
let prefs = var::load_prefs();
|
2024-04-25 01:23:30 +00:00
|
|
|
let mut opt = CommandLineOptions {
|
2024-04-30 21:41:37 +00:00
|
|
|
window_mode_fullscreen: prefs.get_fullscreen_mode(),
|
|
|
|
window_mode_initial: prefs.get_window_mode(),
|
|
|
|
use_gl: prefs.render_mode_is_gl(),
|
2024-04-25 01:23:30 +00:00
|
|
|
};
|
|
|
|
|
2024-03-28 21:34:16 +00:00
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
if args.len() > 1 {
|
2024-04-25 00:37:45 +00:00
|
|
|
for arg in &args[1..] {
|
2024-04-25 01:23:30 +00:00
|
|
|
if arg == "--help" || arg == "-h" {
|
|
|
|
println!("{}", HELP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if arg == "--version" || arg == "-v" {
|
2024-04-25 00:37:45 +00:00
|
|
|
let version = option_env!("CARGO_PKG_VERSION").unwrap();
|
|
|
|
let name = option_env!("CARGO_PKG_NAME").unwrap();
|
|
|
|
let homepage = option_env!("CARGO_PKG_HOMEPAGE").unwrap();
|
|
|
|
println!("{name} {version}");
|
|
|
|
println!("License: GNU GPL version 3: https://gnu.org/licenses/gpl.html");
|
|
|
|
println!("{homepage}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if arg == "--gl" {
|
2024-04-30 21:41:37 +00:00
|
|
|
opt.use_gl = true;
|
2024-04-25 00:37:45 +00:00
|
|
|
}
|
2024-04-25 01:23:30 +00:00
|
|
|
else if arg == "--windowed" {
|
|
|
|
opt.window_mode_initial = WindowMode::Windowed;
|
|
|
|
}
|
|
|
|
else if arg == "--fs-legacy" {
|
|
|
|
let mode = WindowMode::Fullscreen;
|
|
|
|
if opt.window_mode_initial == opt.window_mode_fullscreen {
|
|
|
|
opt.window_mode_initial = mode;
|
|
|
|
}
|
|
|
|
opt.window_mode_fullscreen = mode;
|
|
|
|
}
|
|
|
|
else if arg == "--fs-sized" {
|
|
|
|
let mode = WindowMode::SizedFullscreen;
|
|
|
|
if opt.window_mode_initial == opt.window_mode_fullscreen {
|
|
|
|
opt.window_mode_initial = mode;
|
|
|
|
}
|
|
|
|
opt.window_mode_fullscreen = mode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("{}", HELP);
|
|
|
|
println!("\nERROR: no such option: `{}`", arg);
|
|
|
|
return;
|
|
|
|
}
|
2024-03-28 21:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-30 21:41:37 +00:00
|
|
|
if opt.use_gl {
|
|
|
|
env::set_var("WGPU_BACKEND", "gl");
|
|
|
|
}
|
|
|
|
|
2024-04-23 13:39:46 +00:00
|
|
|
let mut app = App::new();
|
2024-04-25 01:23:30 +00:00
|
|
|
app.insert_resource(opt);
|
|
|
|
|
2024-04-23 13:39:46 +00:00
|
|
|
#[cfg(feature = "embed_assets")]
|
|
|
|
app.add_plugins(bevy_embedded_assets::EmbeddedAssetPlugin {
|
|
|
|
mode: bevy_embedded_assets::PluginMode::ReplaceDefault
|
|
|
|
});
|
2024-04-25 01:23:30 +00:00
|
|
|
|
2024-04-30 21:41:37 +00:00
|
|
|
app.add_plugins(OutFlyPlugin);
|
|
|
|
app.insert_resource(prefs);
|
|
|
|
app.run();
|
2024-03-17 23:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct OutFlyPlugin;
|
|
|
|
impl Plugin for OutFlyPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_systems(Startup, setup);
|
|
|
|
app.add_systems(Update, handle_input);
|
2024-04-16 14:28:04 +00:00
|
|
|
app.add_systems(Update, debug);
|
2024-04-14 12:55:00 +00:00
|
|
|
app.insert_resource(var::Settings::default());
|
2024-04-14 14:20:51 +00:00
|
|
|
app.insert_resource(var::GameVars::default());
|
2024-03-17 23:04:23 +00:00
|
|
|
app.add_plugins((
|
2024-03-18 19:58:16 +00:00
|
|
|
DefaultPlugins,//.set(ImagePlugin::default_nearest()),
|
2024-03-17 23:04:23 +00:00
|
|
|
FrameTimeDiagnosticsPlugin,
|
|
|
|
|
2024-03-17 22:49:50 +00:00
|
|
|
actor::ActorPlugin,
|
2024-03-17 23:04:23 +00:00
|
|
|
audio::AudioPlugin,
|
2024-04-04 11:33:54 +00:00
|
|
|
camera::CameraPlugin,
|
|
|
|
chat::ChatPlugin,
|
2024-05-12 21:37:03 +00:00
|
|
|
cmd::CmdPlugin,
|
2024-05-12 21:57:21 +00:00
|
|
|
game::GamePlugin,
|
2024-05-12 20:17:17 +00:00
|
|
|
menu::MenuPlugin,
|
2024-05-10 08:37:40 +00:00
|
|
|
visual::VisualPlugin,
|
2024-04-04 11:33:54 +00:00
|
|
|
hud::HudPlugin,
|
2024-05-10 08:27:52 +00:00
|
|
|
load::LoadPlugin,
|
2024-04-04 11:33:54 +00:00
|
|
|
world::WorldPlugin,
|
2024-03-17 23:04:23 +00:00
|
|
|
));
|
|
|
|
}
|
2024-03-16 14:00:31 +00:00
|
|
|
}
|
|
|
|
|
2024-04-25 01:23:30 +00:00
|
|
|
#[derive(Resource, Default)]
|
|
|
|
pub struct CommandLineOptions {
|
|
|
|
window_mode_fullscreen: WindowMode,
|
|
|
|
window_mode_initial: WindowMode,
|
2024-04-30 21:41:37 +00:00
|
|
|
use_gl: bool,
|
2024-04-25 01:23:30 +00:00
|
|
|
}
|
|
|
|
|
2024-03-16 18:07:28 +00:00
|
|
|
fn setup(
|
2024-04-07 22:24:03 +00:00
|
|
|
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
2024-04-25 01:23:30 +00:00
|
|
|
opt: Res<CommandLineOptions>,
|
2024-03-16 18:07:28 +00:00
|
|
|
) {
|
|
|
|
for mut window in &mut windows {
|
|
|
|
window.cursor.grab_mode = CursorGrabMode::Locked;
|
|
|
|
window.cursor.visible = false;
|
2024-04-25 01:23:30 +00:00
|
|
|
window.mode = opt.window_mode_initial;
|
2024-05-12 21:57:21 +00:00
|
|
|
window.title = var::WINDOW_TITLE.to_string();
|
2024-03-16 18:07:28 +00:00
|
|
|
}
|
2024-03-16 15:22:44 +00:00
|
|
|
}
|
|
|
|
|
2024-03-16 15:12:35 +00:00
|
|
|
fn handle_input(
|
|
|
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
2024-04-14 12:55:00 +00:00
|
|
|
settings: Res<var::Settings>,
|
2024-04-25 01:23:30 +00:00
|
|
|
opt: Res<CommandLineOptions>,
|
2024-04-07 22:23:55 +00:00
|
|
|
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
|
|
|
|
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
2024-04-25 01:52:32 +00:00
|
|
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
2024-03-16 15:12:35 +00:00
|
|
|
) {
|
2024-03-18 03:39:26 +00:00
|
|
|
if keyboard_input.pressed(settings.key_exit) {
|
2024-03-16 15:12:35 +00:00
|
|
|
app_exit_events.send(bevy::app::AppExit);
|
2024-03-16 14:13:00 +00:00
|
|
|
}
|
2024-04-07 22:23:55 +00:00
|
|
|
if keyboard_input.just_pressed(settings.key_fullscreen) {
|
2024-04-25 01:52:32 +00:00
|
|
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
2024-04-07 22:23:55 +00:00
|
|
|
for mut window in &mut windows {
|
|
|
|
window.mode = if window.mode == WindowMode::Windowed {
|
2024-04-25 01:23:30 +00:00
|
|
|
opt.window_mode_fullscreen
|
2024-04-07 22:23:55 +00:00
|
|
|
} else {
|
|
|
|
WindowMode::Windowed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-16 14:13:00 +00:00
|
|
|
}
|
2024-04-16 14:28:04 +00:00
|
|
|
|
|
|
|
fn debug(
|
|
|
|
settings: Res<var::Settings>,
|
|
|
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
|
|
|
mut commands: Commands,
|
2024-05-10 08:27:52 +00:00
|
|
|
mut extended_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, load::AsteroidSurface>>>,
|
2024-04-16 16:28:15 +00:00
|
|
|
materials: Query<(Entity, Option<&Name>, &Handle<Mesh>)>,
|
2024-04-16 14:28:04 +00:00
|
|
|
) {
|
|
|
|
if settings.dev_mode && keyboard_input.pressed(KeyCode::KeyP) {
|
2024-04-16 16:28:15 +00:00
|
|
|
for (entity, _name, mesh) in &materials {
|
|
|
|
dbg!(mesh);
|
2024-04-16 14:28:04 +00:00
|
|
|
let mut entity = commands.entity(entity);
|
|
|
|
entity.remove::<Handle<StandardMaterial>>();
|
2024-05-10 08:27:52 +00:00
|
|
|
let material = extended_materials.add(load::AsteroidSurface::material());
|
2024-04-16 14:28:04 +00:00
|
|
|
entity.insert(material);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|