Implement direct P2P session scaffolding (#39)
CI / build-and-test (push) Successful in 1m10s
CI / build-and-test (push) Successful in 1m10s
Closes #24 Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
This commit was merged in pull request #39.
This commit is contained in:
+44
-7
@@ -8,25 +8,28 @@ use bevy_ggrs::prelude::Session;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
AppState,
|
||||
args::Args,
|
||||
fighter::{
|
||||
FighterId, FighterRoster,
|
||||
animation::AnimKind,
|
||||
attack::{AttackKind, FighterAttackScriptAssets},
|
||||
baked_animation::{BAKED_ANIMATION_FPS, BakedFighterAnimations},
|
||||
baked_animation::{BakedFighterAnimations, BAKED_ANIMATION_FPS},
|
||||
manifest::{FighterManifest, FighterManifestRegistry},
|
||||
spawn_fighter,
|
||||
visual::FighterAnimations,
|
||||
FighterId, FighterRoster,
|
||||
},
|
||||
input::{LocalInputAssignments, LocalInputSource},
|
||||
math::{int::FGi32, vec::FGVec2},
|
||||
netcode::{GGRSCfg, session::create_session},
|
||||
netcode::{
|
||||
session::{create_session, ConnectionStatus, SessionConfig},
|
||||
GGRSCfg,
|
||||
},
|
||||
scripting::FighterAttackScript,
|
||||
stage::{
|
||||
self,
|
||||
manifest::{StageId, StageManifest, StageManifestRegistry},
|
||||
},
|
||||
AppState,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -140,6 +143,7 @@ pub fn initiate_match(
|
||||
next_state: &mut NextState<AppState>,
|
||||
request: PendingMatch,
|
||||
) {
|
||||
commands.remove_resource::<crate::netcode::session::MatchDisconnected>();
|
||||
commands.insert_resource(request);
|
||||
next_state.set(AppState::LoadingMatch);
|
||||
}
|
||||
@@ -176,6 +180,14 @@ pub fn initiate_default_match(
|
||||
}
|
||||
return;
|
||||
}
|
||||
let session_config = match SessionConfig::from_args(&args, args.players) {
|
||||
Ok(config) => config,
|
||||
Err(error) => {
|
||||
error!("Invalid network configuration: {error}");
|
||||
next_state.set(AppState::MatchLoadFailed);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let players = (0..args.players)
|
||||
.map(|handle| MatchPlayer {
|
||||
handle,
|
||||
@@ -183,10 +195,21 @@ pub fn initiate_default_match(
|
||||
})
|
||||
.collect();
|
||||
|
||||
assigments.push((0, LocalInputSource::Keyboard));
|
||||
assigments.clear();
|
||||
let local_handles = session_config
|
||||
.players
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(handle, player)| {
|
||||
matches!(player, crate::netcode::session::PlayerConnection::Local).then_some(handle)
|
||||
});
|
||||
let mut local_handles = local_handles;
|
||||
if let Some(handle) = local_handles.next() {
|
||||
assigments.push((handle, LocalInputSource::Keyboard));
|
||||
}
|
||||
|
||||
for (idx, entity) in gamepads.iter().take(args.players - 1).enumerate() {
|
||||
assigments.push((idx + 1, LocalInputSource::Gamepad(entity)));
|
||||
for (entity, handle) in gamepads.iter().zip(local_handles) {
|
||||
assigments.push((handle, LocalInputSource::Gamepad(entity)));
|
||||
}
|
||||
|
||||
initiate_match(
|
||||
@@ -373,6 +396,16 @@ pub fn prepare_match(
|
||||
));
|
||||
}
|
||||
|
||||
let session_config = match SessionConfig::from_args(&args, request.players.len()) {
|
||||
Ok(config) => config,
|
||||
Err(error) => {
|
||||
fail_match(
|
||||
&mut next_state,
|
||||
&format!("invalid network configuration: {error}"),
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let session = match create_session(&args, request.players.len()) {
|
||||
Ok(session) => session,
|
||||
Err(error) => {
|
||||
@@ -418,6 +451,8 @@ pub fn prepare_match(
|
||||
}
|
||||
|
||||
commands.insert_resource(FighterRoster(fighter_roster));
|
||||
commands.insert_resource(session_config);
|
||||
commands.insert_resource(ConnectionStatus::default());
|
||||
commands.insert_resource::<Session<GGRSCfg>>(session);
|
||||
next_state.set(AppState::InMatch);
|
||||
}
|
||||
@@ -448,6 +483,8 @@ pub fn cleanup_match(
|
||||
commands.entity(fighter).despawn();
|
||||
}
|
||||
commands.remove_resource::<Session<GGRSCfg>>();
|
||||
commands.remove_resource::<SessionConfig>();
|
||||
commands.remove_resource::<ConnectionStatus>();
|
||||
commands.remove_resource::<stage::line::StageCollision>();
|
||||
commands.remove_resource::<MatchAssets>();
|
||||
commands.remove_resource::<PendingMatch>();
|
||||
|
||||
Reference in New Issue
Block a user