Refactor loading
This commit is contained in:
@@ -6,10 +6,7 @@ use bevy_ggrs::prelude::*;
|
||||
|
||||
use crate::netcode::GGRSCfg;
|
||||
|
||||
pub fn network_debug(
|
||||
mut contexts: EguiContexts,
|
||||
session: Option<Res<Session<GGRSCfg>>>,
|
||||
) -> Result {
|
||||
pub fn network_debug(mut contexts: EguiContexts, session: Option<Res<Session<GGRSCfg>>>) -> Result {
|
||||
if let Some(sess) = session {
|
||||
match sess.as_ref() {
|
||||
Session::P2P(s) => {
|
||||
|
||||
@@ -19,7 +19,6 @@ impl Plugin for FighterNetcodePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
let plugin = GgrsPlugin::<GGRSCfg>::default();
|
||||
app.add_plugins(plugin)
|
||||
.add_systems(Startup, session::netcode_setup)
|
||||
// Engine-level components that every rolled-back entity may carry.
|
||||
// Gameplay components are registered by the plugin that owns them.
|
||||
.rollback_component_with_clone::<Transform>()
|
||||
|
||||
@@ -6,31 +6,32 @@ use bevy_ggrs::{ggrs::UdpNonBlockingSocket, prelude::*};
|
||||
use crate::args::Args;
|
||||
use crate::netcode::GGRSCfg;
|
||||
|
||||
pub fn netcode_setup(mut commands: Commands, args: Res<Args>) -> Result {
|
||||
pub fn create_session(args: &Args, player_count: usize) -> Result<Session<GGRSCfg>> {
|
||||
let mut sess_build = SessionBuilder::<GGRSCfg>::new()
|
||||
.with_num_players(args.players)?
|
||||
.with_num_players(player_count)?
|
||||
.with_check_distance(args.check_distance)
|
||||
.with_input_delay(args.input_delay); // (optional) set input delay for the local player
|
||||
|
||||
for i in 0..args.players {
|
||||
for i in 0..player_count {
|
||||
sess_build = sess_build.add_player(PlayerType::Local, i)?;
|
||||
}
|
||||
|
||||
if args.synctest {
|
||||
println!("Start synctest!");
|
||||
let sess = sess_build.start_synctest_session()?;
|
||||
commands.insert_resource(Session::SyncTest(sess));
|
||||
Ok(Session::SyncTest(sess))
|
||||
} else {
|
||||
println!("Start p2p!");
|
||||
let socket = UdpNonBlockingSocket::bind_to_port(6969)?;
|
||||
let sess = sess_build.start_p2p_session(socket)?;
|
||||
commands.insert_resource(Session::P2P(sess));
|
||||
Ok(Session::P2P(sess))
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_events_system(mut session: ResMut<Session<GGRSCfg>>) {
|
||||
pub fn print_events_system(session: Option<ResMut<Session<GGRSCfg>>>) {
|
||||
let Some(mut session) = session else {
|
||||
return;
|
||||
};
|
||||
match session.as_mut() {
|
||||
Session::P2P(s) => {
|
||||
for event in s.events() {
|
||||
|
||||
Reference in New Issue
Block a user