~starkingdoms/starkingdoms

ref: e2c74ff0a4af609afb2869c59835838dd76f639c starkingdoms/crates/unified/src/main.rs -rw-r--r-- 4.8 KiB
e2c74ff0 — core Revert "aaa ??? ?? ? ?? ???????????????????????????????????????????? i would like to explosion" 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#![warn(clippy::pedantic)] // Be annoying, and disable specific irritating lints if needed
#![deny(
    clippy::allow_attributes_without_reason,
    clippy::assertions_on_result_states
)]
#![warn(clippy::if_then_some_else_none)]
#![allow(clippy::type_complexity, reason = "Bevy makes this a nightmare")]
#![allow(clippy::needless_pass_by_value, reason = "Bevy makes this a nightmare")]
#![allow(
    clippy::cast_precision_loss,
    clippy::cast_possible_truncation,
    clippy::cast_sign_loss,
    reason = "We cast ints to floats a lot"
)]
#![allow(clippy::missing_panics_doc, reason = "Gamedev! We panic a lot")]
#![allow(clippy::too_many_arguments, reason = "Le Bevy:tm:")]
#![allow(
    clippy::too_many_lines,
    reason = "With the three of us, this is impossible"
)]

pub mod attachment;
#[cfg(feature = "client")]
pub mod client;
#[cfg(feature = "client")]
pub mod client_plugins;
pub mod config;
pub mod ecs;
#[cfg(feature = "particle_editor")]
pub mod particle_editor;
pub mod particles;
#[cfg(feature = "server")]
pub mod server;
#[cfg(feature = "server")]
pub mod server_plugins;
pub mod shared_plugins;
pub mod world_config;

pub mod physics;
pub mod prelude;

#[cfg(target_arch = "wasm32")]
pub mod wasm_entrypoint;
mod cli;
mod build_meta;
mod thrust;

use std::str::FromStr;
#[cfg(target_arch = "wasm32")]
pub use wasm_entrypoint::*;

use crate::cli::StkArgs;
use crate::prelude::*;
#[cfg(feature = "client")]
use crate::client_plugins::ClientPluginGroup;
#[cfg(feature = "server")]
use crate::server_plugins::ServerPluginGroup;


#[allow(unused_mut, reason = "Conditional compilation hell")]
fn run(cli: StkArgs) -> AppExit {
    let mut app = App::new();

    match cli {
        #[cfg(feature = "client")]
        StkArgs::Client { server } => {
            app.add_plugins(
                DefaultPlugins.build()
                    .disable::<bevy::log::LogPlugin>()
                    .disable::<bevy::ui::UiPlugin>()
            );
            app.add_plugins(ClientPluginGroup { server: Some(server) });
            app.add_plugins(shared_plugins::SharedPluginGroup);
        }
        #[cfg(feature = "server")]
        StkArgs::Server {
            bind_to,
            tick_rate,
            max_clients,
            #[cfg(feature = "client")]
            with_client
        } => {
            let mut with_client_all = false;
            #[cfg(feature = "client")]
            if with_client {
                with_client_all = true;
                app.add_plugins(
                    DefaultPlugins.build()
                        .disable::<bevy::log::LogPlugin>()
                        .disable::<bevy::ui::UiPlugin>()
                );
                app.add_plugins(|app: &mut App| {
                    app.add_systems(Startup, server::player::join::ls_magically_invent_player);
                });
            }
            if !with_client_all {
               app
                   .add_plugins(AssetPlugin::default())
                   .add_plugins(bevy::state::app::StatesPlugin)
                    .add_plugins(TaskPoolPlugin::default())
                    .add_plugins(bevy::diagnostic::FrameCountPlugin)
                    .add_plugins(bevy::time::TimePlugin)
                    .add_plugins(bevy::app::ScheduleRunnerPlugin::run_loop(std::time::Duration::from_secs_f32(
                        1.0 / tick_rate,
                    )));
            }

            app.add_plugins(shared_plugins::SharedPluginGroup);

            let mut pg = ServerPluginGroup {
                bind: bind_to,
                tick_rate,
                max_clients: max_clients.into(),
            }.build();

            #[cfg(feature = "client")]
            if with_client {
                pg = pg.add_group(ClientPluginGroup {
                    server: None
                });
            }

            app.add_plugins(pg);
        }
        #[cfg(feature = "particle_editor")]
        StkArgs::ParticleEditor {} => {
            app.add_plugins(crate::particle_editor::particle_editor_plugin);
        }
    }

    app.run()
}

#[cfg(feature = "wasm")]
fn main() {
    // noop on webassembly
}

#[cfg(feature = "native")]
fn main() -> AppExit {
    use tracing_subscriber::util::SubscriberInitExt;
    use bevy::log::{tracing_subscriber};

    let cli = crate::cli::parse_args();

    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::from_default_env()
                .add_directive(tracing_subscriber::filter::Directive::from_str("naga=error").unwrap())
                .add_directive(tracing_subscriber::filter::Directive::from_str("info").unwrap())
                .add_directive(tracing_subscriber::filter::Directive::from_str("starkingdoms=trace").unwrap())
            ,
        )
        .finish()
        .init();

    ctrlc::set_handler(|| {
        info!("caught ^C, ciao!");
        std::process::exit(0);
    }).unwrap();

    run(cli)
}