Refactor loading
This commit is contained in:
Generated
+37
@@ -707,6 +707,36 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bevy_asset_loader"
|
||||||
|
version = "0.27.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ef4cba5fb56abd9842dece351e61f9c4f6beaa08a9e92760e5cd9472c43e14d"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"bevy_app",
|
||||||
|
"bevy_asset",
|
||||||
|
"bevy_asset_loader_derive",
|
||||||
|
"bevy_ecs",
|
||||||
|
"bevy_log",
|
||||||
|
"bevy_platform",
|
||||||
|
"bevy_reflect",
|
||||||
|
"bevy_state",
|
||||||
|
"bevy_utils",
|
||||||
|
"path-slash",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bevy_asset_loader_derive"
|
||||||
|
version = "0.27.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c0596de511aeb25cd2d9e0680a67a9e51ce37962806a1c7aaa4b9ad2c6fd4ff"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.119",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_asset_macros"
|
name = "bevy_asset_macros"
|
||||||
version = "0.19.0"
|
version = "0.19.0"
|
||||||
@@ -3445,6 +3475,7 @@ dependencies = [
|
|||||||
"avian3d",
|
"avian3d",
|
||||||
"bevy",
|
"bevy",
|
||||||
"bevy-inspector-egui",
|
"bevy-inspector-egui",
|
||||||
|
"bevy_asset_loader",
|
||||||
"bevy_common_assets",
|
"bevy_common_assets",
|
||||||
"bevy_egui",
|
"bevy_egui",
|
||||||
"bevy_ggrs",
|
"bevy_ggrs",
|
||||||
@@ -5475,6 +5506,12 @@ version = "1.0.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "path-slash"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pathdiff"
|
name = "pathdiff"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
|
|||||||
+2
-1
@@ -29,10 +29,11 @@ serde = "1.0.229"
|
|||||||
bitfields = "3.0.0"
|
bitfields = "3.0.0"
|
||||||
clap = { version = "4.6.6", features = ["derive"] }
|
clap = { version = "4.6.6", features = ["derive"] }
|
||||||
bevy_wind_waker_shader = { git = "https://github.com/lavaeater/bevy_wind_waker_shader.git" }
|
bevy_wind_waker_shader = { git = "https://github.com/lavaeater/bevy_wind_waker_shader.git" }
|
||||||
fixed = { version = "1.31.0", features = ["serde"] }
|
fixed = { version = "1.31.0", features = ["serde", "serde-str"] }
|
||||||
strum = "0.28.0"
|
strum = "0.28.0"
|
||||||
strum_macros = "0.28.0"
|
strum_macros = "0.28.0"
|
||||||
bevy_common_assets = { version = "0.17.0", features = ["ron"] }
|
bevy_common_assets = { version = "0.17.0", features = ["ron"] }
|
||||||
|
bevy_asset_loader = "0.27.0"
|
||||||
|
|
||||||
# Enable a large amount of optimization in the dev profile for dependencies.
|
# Enable a large amount of optimization in the dev profile for dependencies.
|
||||||
[profile.dev.package."*"]
|
[profile.dev.package."*"]
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
(
|
||||||
|
id: TestFighter,
|
||||||
|
model_path: "fighters/test/test-fighter-normal.glb",
|
||||||
|
attributes: (
|
||||||
|
base_walk_accel: "0.1",
|
||||||
|
stick_walk_accel: "0.16",
|
||||||
|
max_walk_vel: "0.7",
|
||||||
|
ground_friction: "0.09",
|
||||||
|
dash_acceleration_duration: 13,
|
||||||
|
dash_duration: 24,
|
||||||
|
base_dash_accel: "0.02",
|
||||||
|
stick_dash_accel: "0.065",
|
||||||
|
max_dash_vel: "1.1",
|
||||||
|
short_hop_vertical_velocity: "1.05",
|
||||||
|
full_jump_vertical_velocity: "1.6",
|
||||||
|
jump_horizontal_velocity: "0.7",
|
||||||
|
dash_initial_velocity: "1.4",
|
||||||
|
terminal_velocity: "2.8",
|
||||||
|
gravity: "0.23",
|
||||||
|
jumpsquat_duration: 4,
|
||||||
|
),
|
||||||
|
animations: {
|
||||||
|
Wait: "PlyPurin5K_Share_ACTION_Wait",
|
||||||
|
Walk: "PlyPurin5K_Share_ACTION_WalkFast",
|
||||||
|
Run: "PlyPurin5K_Share_ACTION_Run",
|
||||||
|
Dash: "PlyPurin5K_Share_ACTION_Dash",
|
||||||
|
JumpSquat: "PlyPurin5K_Share_ACTION_Landing"
|
||||||
|
JumpForward: "PlyPurin5K_Share_ACTION_JumpF"
|
||||||
|
JumpBack: "PlyPurin5K_Share_ACTION_JumpB"
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
(
|
||||||
|
input_common: (
|
||||||
|
stick_deadzone: "0.28",
|
||||||
|
trigger_deadzone: "0.3",
|
||||||
|
smash_input_reset_axis_threshold: "0.25",
|
||||||
|
smash_input_axis_threshold: "0.8",
|
||||||
|
run_stick_threshold: "0.625",
|
||||||
|
smash_input_frame_threshold: 2,
|
||||||
|
input_buffer_size: 5
|
||||||
|
|
||||||
|
),
|
||||||
|
fighter_common: (
|
||||||
|
walk_speed_ease: "0.5",
|
||||||
|
ground_max_horizontal_velocity: "3.0",
|
||||||
|
ground_friction_over_walk_speed_multiplier: "2.0"
|
||||||
|
),
|
||||||
|
fighter_manifest_paths: [
|
||||||
|
"fighters/test/test.fighter.ron"
|
||||||
|
]
|
||||||
|
)
|
||||||
+1
-1
@@ -11,5 +11,5 @@ pub struct Args {
|
|||||||
#[clap(long, default_value_t = 2)]
|
#[clap(long, default_value_t = 2)]
|
||||||
pub check_distance: usize,
|
pub check_distance: usize,
|
||||||
#[clap(long, default_value_t = 1)]
|
#[clap(long, default_value_t = 1)]
|
||||||
pub players: usize
|
pub players: usize,
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-19
@@ -1,9 +1,9 @@
|
|||||||
use std::{collections::HashMap, time::Duration};
|
use std::time::Duration;
|
||||||
|
|
||||||
use bevy::{mesh::skinning::SkinnedMesh, prelude::*};
|
use bevy::{mesh::skinning::SkinnedMesh, prelude::*};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
fighter::{FighterECB, FighterTranslation, FighterVisual, visual::FighterAnimations}, player::Player,
|
fighter::{FighterECB, FighterFacingDirection, FighterTranslation, FighterVisual, visual::FighterAnimations}, player::Player,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@@ -47,44 +47,43 @@ pub fn setup_fighter_animation_player(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_animation(children: Query<&mut Transform, With<FighterVisual>>) {
|
pub fn apply_animation(children: Query<(&mut Transform, &FighterFacingDirection), With<FighterVisual>>) {
|
||||||
for mut trf in children {
|
for (mut trf, facing_direction) in children {
|
||||||
// Melee model scale is in decimeters
|
// Melee model scale is in decimeters
|
||||||
trf.rotation = Quat::IDENTITY;
|
trf.rotation = Quat::IDENTITY;
|
||||||
trf.rotate_local_y(std::f32::consts::PI * 0.5);
|
trf.rotate_local_y(std::f32::consts::PI * 0.5 * facing_direction.to_sign().to_num::<f32>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn animation_init(
|
pub fn animation_init(
|
||||||
fighters: Query<
|
fighters: Query<
|
||||||
(
|
(&FighterAnimations, &FighterAnimationPlayerLink),
|
||||||
&FighterAnimations,
|
Added<FighterAnimationPlayerLink>,
|
||||||
&FighterAnimationPlayerLink,
|
|
||||||
),
|
|
||||||
Added<FighterAnimationPlayerLink>
|
|
||||||
>,
|
>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut anim_player_query: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>
|
mut anim_player_query: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
|
||||||
) {
|
) {
|
||||||
for (anim, link) in fighters {
|
for (anim, link) in fighters {
|
||||||
commands.entity(link.0).insert(
|
commands
|
||||||
AnimationGraphHandle(anim.graph.clone())
|
.entity(link.0)
|
||||||
);
|
.insert(AnimationGraphHandle(anim.graph.clone()));
|
||||||
info!("BEGIN! {:?}", fighters);
|
info!("BEGIN! {:?}", fighters);
|
||||||
if let Ok((mut player, mut transitions)) = anim_player_query.get_mut(link.0) {
|
if let Ok((mut player, mut transitions)) = anim_player_query.get_mut(link.0) {
|
||||||
info!("DOS");
|
info!("DOS");
|
||||||
transitions.play(&mut player, anim.clips[&AnimKind::Wait], Duration::ZERO).repeat();
|
transitions
|
||||||
|
.play(&mut player, anim.clips[&AnimKind::Wait], Duration::ZERO)
|
||||||
|
.repeat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Deserialize)]
|
#[derive(
|
||||||
|
Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Deserialize, serde::Serialize, Reflect,
|
||||||
|
)]
|
||||||
pub enum AnimKind {
|
pub enum AnimKind {
|
||||||
Wait,
|
Wait,
|
||||||
Walk,
|
Walk,
|
||||||
Run,
|
Run,
|
||||||
Dash,
|
Dash,
|
||||||
|
JumpSquat,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath)]
|
|
||||||
pub struct AnimManifest(pub HashMap<AnimKind, String>);
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{input::FighterInputFrame, math::int::FGi32};
|
use crate::{input::FighterInputFrame, math::int::FGi32};
|
||||||
|
|
||||||
/// Per-fighter tuning values. These are character data, not global rules —
|
/// Per-fighter tuning values. These are character data, not global rules —
|
||||||
/// anything that applies to every fighter belongs in
|
/// anything that applies to every fighter belongs in
|
||||||
/// [`crate::game_settings::FighterSettingsCommon`] instead.
|
/// [`crate::game_settings::FighterSettingsCommon`] instead.
|
||||||
#[derive(Component, Clone, Copy)]
|
#[derive(Asset, Component, Clone, Copy, Reflect, Serialize, Deserialize)]
|
||||||
|
#[reflect(opaque)]
|
||||||
pub struct FighterAttributes {
|
pub struct FighterAttributes {
|
||||||
pub base_walk_accel: FGi32,
|
pub base_walk_accel: FGi32,
|
||||||
pub stick_walk_accel: FGi32,
|
pub stick_walk_accel: FGi32,
|
||||||
@@ -19,7 +21,9 @@ pub struct FighterAttributes {
|
|||||||
pub max_dash_vel: FGi32,
|
pub max_dash_vel: FGi32,
|
||||||
|
|
||||||
pub jumpsquat_duration: u32,
|
pub jumpsquat_duration: u32,
|
||||||
pub jump_vertical_velocity: FGi32,
|
pub short_hop_vertical_velocity: FGi32,
|
||||||
|
pub full_jump_vertical_velocity: FGi32,
|
||||||
|
pub jump_horizontal_velocity: FGi32,
|
||||||
|
|
||||||
pub ground_friction: FGi32,
|
pub ground_friction: FGi32,
|
||||||
pub terminal_velocity: FGi32,
|
pub terminal_velocity: FGi32,
|
||||||
@@ -27,7 +31,11 @@ pub struct FighterAttributes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FighterAttributes {
|
impl FighterAttributes {
|
||||||
pub fn get_accel_and_target_dashrun(&self, input: &FighterInputFrame, direction: FGi32) -> (FGi32, FGi32) {
|
pub fn get_accel_and_target_dashrun(
|
||||||
|
&self,
|
||||||
|
input: &FighterInputFrame,
|
||||||
|
direction: FGi32,
|
||||||
|
) -> (FGi32, FGi32) {
|
||||||
let accel = input.movement.x * self.stick_dash_accel;
|
let accel = input.movement.x * self.stick_dash_accel;
|
||||||
let accel = accel + direction * self.base_dash_accel;
|
let accel = accel + direction * self.base_dash_accel;
|
||||||
let target_vel = input.movement.x * self.max_dash_vel;
|
let target_vel = input.movement.x * self.max_dash_vel;
|
||||||
@@ -45,3 +53,7 @@ impl FighterAttributes {
|
|||||||
(accel, target_vel)
|
(accel, target_vel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct FighterAttributesLink {
|
||||||
|
attributes: Handle<FighterAttributes>,
|
||||||
|
}
|
||||||
|
|||||||
+16
-3
@@ -9,11 +9,24 @@ use crate::fighter::state::StateNameDebug;
|
|||||||
use crate::fighter::{FighterECB, FighterPreviousTranslation, FighterTranslation, FighterVelocity};
|
use crate::fighter::{FighterECB, FighterPreviousTranslation, FighterTranslation, FighterVelocity};
|
||||||
use crate::input::FighterInput;
|
use crate::input::FighterInput;
|
||||||
|
|
||||||
pub fn debug_draw_ecb(ecbs: Query<(&FighterECB, &FighterTranslation, &FighterPreviousECB, &FighterPreviousTranslation)>, mut gizmos: Gizmos) {
|
pub fn debug_draw_ecb(
|
||||||
|
ecbs: Query<(
|
||||||
|
&FighterECB,
|
||||||
|
&FighterTranslation,
|
||||||
|
&FighterPreviousECB,
|
||||||
|
&FighterPreviousTranslation,
|
||||||
|
)>,
|
||||||
|
mut gizmos: Gizmos,
|
||||||
|
) {
|
||||||
for (ecb, trf, ecb_prev, trf_prev) in ecbs {
|
for (ecb, trf, ecb_prev, trf_prev) in ecbs {
|
||||||
let transformed = ecb.to_3d_lineloop(Transform::from_xyz(trf.x.to_num(), trf.y.to_num(), 0.0));
|
let transformed =
|
||||||
|
ecb.to_3d_lineloop(Transform::from_xyz(trf.x.to_num(), trf.y.to_num(), 0.0));
|
||||||
gizmos.lineloop(transformed, YELLOW);
|
gizmos.lineloop(transformed, YELLOW);
|
||||||
let prev_transformed = ecb_prev.to_3d_lineloop(Transform::from_xyz(trf_prev.x.to_num(), trf_prev.y.to_num(), -0.1));
|
let prev_transformed = ecb_prev.to_3d_lineloop(Transform::from_xyz(
|
||||||
|
trf_prev.x.to_num(),
|
||||||
|
trf_prev.y.to_num(),
|
||||||
|
-0.1,
|
||||||
|
));
|
||||||
gizmos.lineloop(prev_transformed, ORANGE);
|
gizmos.lineloop(prev_transformed, ORANGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -28,9 +28,7 @@ impl From<FighterECB> for FighterPreviousECB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot_fighter_ecb(
|
pub fn snapshot_fighter_ecb(fighters: Query<(&FighterECB, &mut FighterPreviousECB)>) {
|
||||||
fighters: Query<(&FighterECB, &mut FighterPreviousECB)>,
|
|
||||||
) {
|
|
||||||
for (ecb, mut previous_ecb) in fighters {
|
for (ecb, mut previous_ecb) in fighters {
|
||||||
*previous_ecb = (*ecb).into();
|
*previous_ecb = (*ecb).into();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use bevy::{asset::UntypedHandle, prelude::*};
|
||||||
|
use bevy_asset_loader::asset_collection::AssetCollection;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
use strum_macros::EnumIter;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
AppState,
|
||||||
|
fighter::{FighterAttributes, animation::AnimKind},
|
||||||
|
game_settings::GameSettings,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, EnumIter)]
|
||||||
|
pub enum FighterId {
|
||||||
|
TestFighter,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Asset, Reflect)]
|
||||||
|
pub struct FighterManifest {
|
||||||
|
pub id: FighterId,
|
||||||
|
pub model_path: String,
|
||||||
|
pub attributes: FighterAttributes,
|
||||||
|
pub animations: HashMap<AnimKind, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub struct FighterManifestAssets(pub Vec<Handle<FighterManifest>>);
|
||||||
|
|
||||||
|
impl FighterManifestAssets {
|
||||||
|
fn requested(world: &World) -> Self {
|
||||||
|
let settings = world.resource::<GameSettings>();
|
||||||
|
let asset_server = world.resource::<AssetServer>();
|
||||||
|
|
||||||
|
Self(
|
||||||
|
settings
|
||||||
|
.fighter_manifest_paths
|
||||||
|
.iter()
|
||||||
|
.map(|path| asset_server.load(path.clone()))
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AssetCollection for FighterManifestAssets {
|
||||||
|
fn create(world: &mut World) -> Self {
|
||||||
|
Self::requested(world)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load(world: &mut World) -> Vec<UntypedHandle> {
|
||||||
|
Self::requested(world)
|
||||||
|
.0
|
||||||
|
.into_iter()
|
||||||
|
.map(Handle::untyped)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub struct FighterManifestRegistry(HashMap<FighterId, Handle<FighterManifest>>);
|
||||||
|
|
||||||
|
impl FighterManifestRegistry {
|
||||||
|
pub fn get(&self, fighter: FighterId) -> Option<&Handle<FighterManifest>> {
|
||||||
|
self.0.get(&fighter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn prepare_fighter_manifests(
|
||||||
|
mut commands: Commands,
|
||||||
|
handles: Res<FighterManifestAssets>,
|
||||||
|
manifests: Res<Assets<FighterManifest>>,
|
||||||
|
mut next_state: ResMut<NextState<AppState>>,
|
||||||
|
) {
|
||||||
|
let mut registry = HashMap::with_capacity(handles.0.len());
|
||||||
|
|
||||||
|
for handle in &handles.0 {
|
||||||
|
let Some(manifest) = manifests.get(handle) else {
|
||||||
|
fail(&mut next_state, "a loaded fighter manifest is unavailable");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if manifest.model_path.is_empty() {
|
||||||
|
fail(
|
||||||
|
&mut next_state,
|
||||||
|
&format!("{:?} has an empty model path", manifest.id),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if !manifest.animations.contains_key(&AnimKind::Wait) {
|
||||||
|
fail(
|
||||||
|
&mut next_state,
|
||||||
|
&format!("{:?} has no Wait animation", manifest.id),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if registry.insert(manifest.id, handle.clone()).is_some() {
|
||||||
|
fail(
|
||||||
|
&mut next_state,
|
||||||
|
&format!("duplicate manifest for {:?}", manifest.id),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for fighter in FighterId::iter() {
|
||||||
|
if !registry.contains_key(&fighter) {
|
||||||
|
fail(
|
||||||
|
&mut next_state,
|
||||||
|
&format!("no manifest configured for {fighter:?}"),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commands.insert_resource(FighterManifestRegistry(registry));
|
||||||
|
next_state.set(AppState::Idle);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fail(next_state: &mut NextState<AppState>, message: &str) {
|
||||||
|
error!("Fighter manifest preparation failed: {message}");
|
||||||
|
next_state.set(AppState::CommonAssetLoadFailed);
|
||||||
|
}
|
||||||
+23
-21
@@ -10,6 +10,7 @@ pub mod attributes;
|
|||||||
pub mod collision;
|
pub mod collision;
|
||||||
pub mod debug;
|
pub mod debug;
|
||||||
pub mod ecb;
|
pub mod ecb;
|
||||||
|
pub mod manifest;
|
||||||
pub mod motion;
|
pub mod motion;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
pub mod visual;
|
pub mod visual;
|
||||||
@@ -20,6 +21,7 @@ pub mod visual;
|
|||||||
// silently change what this module exports.
|
// silently change what this module exports.
|
||||||
pub use attributes::FighterAttributes;
|
pub use attributes::FighterAttributes;
|
||||||
pub use ecb::FighterECB;
|
pub use ecb::FighterECB;
|
||||||
|
pub use manifest::FighterId;
|
||||||
pub use motion::{FighterPreviousTranslation, FighterTranslation, FighterVelocity, Grounded};
|
pub use motion::{FighterPreviousTranslation, FighterTranslation, FighterVelocity, Grounded};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -41,12 +43,21 @@ use state::state_interrupt_system;
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FighterPlugin;
|
pub struct FighterPlugin;
|
||||||
|
|
||||||
#[derive(Component, Copy, Clone, Hash)]
|
#[derive(Component, Copy, Clone, Hash, Debug, PartialEq, Reflect)]
|
||||||
pub enum FighterFacingDirection {
|
pub enum FighterFacingDirection {
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FighterFacingDirection {
|
||||||
|
pub fn to_sign(&self) -> FGi32 {
|
||||||
|
match self {
|
||||||
|
FighterFacingDirection::Left => FGi32::NEG_ONE,
|
||||||
|
FighterFacingDirection::Right => FGi32::ONE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
#[require(Transform)]
|
#[require(Transform)]
|
||||||
pub struct FighterVisual;
|
pub struct FighterVisual;
|
||||||
@@ -105,41 +116,32 @@ impl Plugin for FighterPlugin {
|
|||||||
.add_systems(EguiPrimaryContextPass, debug::fighter_debug)
|
.add_systems(EguiPrimaryContextPass, debug::fighter_debug)
|
||||||
.add_systems(EguiPrimaryContextPass, debug::update_config)
|
.add_systems(EguiPrimaryContextPass, debug::update_config)
|
||||||
.rollback_component_with_clone::<FighterState>()
|
.rollback_component_with_clone::<FighterState>()
|
||||||
.checksum_component_with_hash::<FighterState>();
|
.checksum_component_with_hash::<FighterState>()
|
||||||
|
.register_type::<FighterFacingDirection>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_fighter(
|
pub fn spawn_fighter(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
|
player_handle: usize,
|
||||||
|
spawn_position: FGVec2,
|
||||||
|
attributes: FighterAttributes,
|
||||||
animations: FighterAnimations,
|
animations: FighterAnimations,
|
||||||
visual_root: WorldAssetRoot,
|
visual_root: WorldAssetRoot,
|
||||||
) {
|
) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Name("Fighter".into()),
|
Name(format!("Fighter {player_handle}").into()),
|
||||||
Player { handle: 0 },
|
Player {
|
||||||
|
handle: player_handle,
|
||||||
|
},
|
||||||
FighterFacingDirection::Right,
|
FighterFacingDirection::Right,
|
||||||
FighterECB {
|
FighterECB {
|
||||||
vertical_half: FGi32::lit("5.0"),
|
vertical_half: FGi32::lit("5.0"),
|
||||||
horizontal_half: FGi32::lit("2.5"),
|
horizontal_half: FGi32::lit("2.5"),
|
||||||
},
|
},
|
||||||
FighterVelocity::default(),
|
FighterVelocity::default(),
|
||||||
FighterTranslation(FGVec2::lit("5.0", "12.5")),
|
FighterTranslation(spawn_position),
|
||||||
FighterAttributes {
|
attributes,
|
||||||
base_walk_accel: FGi32::lit("0.1"),
|
|
||||||
stick_walk_accel: FGi32::lit("0.16"),
|
|
||||||
max_walk_vel: FGi32::lit("0.7"),
|
|
||||||
ground_friction: FGi32::lit("0.09"),
|
|
||||||
dash_acceleration_duration: 13,
|
|
||||||
dash_duration: 24,
|
|
||||||
base_dash_accel: FGi32::lit("0.02"),
|
|
||||||
stick_dash_accel: FGi32::lit("0.065"),
|
|
||||||
max_dash_vel: FGi32::lit("1.1"),
|
|
||||||
jump_vertical_velocity: FGi32::lit("2.5"),
|
|
||||||
dash_initial_velocity: FGi32::lit("1.4"),
|
|
||||||
terminal_velocity: FGi32::lit("2.8"),
|
|
||||||
gravity: FGi32::lit("0.23"),
|
|
||||||
jumpsquat_duration: 4,
|
|
||||||
},
|
|
||||||
visual_root,
|
visual_root,
|
||||||
animations,
|
animations,
|
||||||
FighterState::Fall(FallState),
|
FighterState::Fall(FallState),
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ pub fn apply_air_motion(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_fighter_transform_to_visuals(
|
pub fn copy_fighter_transform_to_visuals(fighters: Query<(&FighterTranslation, &mut Transform)>) {
|
||||||
fighters: Query<(&FighterTranslation, &mut Transform)>,
|
|
||||||
) {
|
|
||||||
for (translation, mut transform) in fighters {
|
for (translation, mut transform) in fighters {
|
||||||
transform.translation = Vec3::new(translation.x.to_num(), translation.y.to_num(), 0.0);
|
transform.translation = Vec3::new(translation.x.to_num(), translation.y.to_num(), 0.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::fighter::{*};
|
use crate::fighter::*;
|
||||||
|
|
||||||
pub fn integrate_gravity(velocity: &mut FighterVelocity, attributes: &FighterAttributes) {
|
pub fn integrate_gravity(velocity: &mut FighterVelocity, attributes: &FighterAttributes) {
|
||||||
velocity.y -= attributes.gravity;
|
velocity.y -= attributes.gravity;
|
||||||
|
|||||||
+33
-25
@@ -3,13 +3,13 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use super::{FighterStateImpl, FighterStateContext, ground, run, wait, walk};
|
use super::{FighterStateContext, FighterStateImpl, ground, run, wait, walk};
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
|
use crate::fighter::state::FighterState;
|
||||||
use crate::fighter::state::fall::FallState;
|
use crate::fighter::state::fall::FallState;
|
||||||
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||||
use crate::fighter::state::wait::WaitState;
|
use crate::fighter::state::wait::WaitState;
|
||||||
use crate::fighter::state::{FighterState};
|
use crate::fighter::{FighterAttributes, FighterFacingDirection, FighterVelocity, collision};
|
||||||
use crate::fighter::{FighterAttributes, FighterVelocity, collision};
|
|
||||||
use crate::game_settings::GameSettings;
|
use crate::game_settings::GameSettings;
|
||||||
use crate::input::{
|
use crate::input::{
|
||||||
FighterCommands::{SmashMoveLeft, SmashMoveRight},
|
FighterCommands::{SmashMoveLeft, SmashMoveRight},
|
||||||
@@ -20,33 +20,30 @@ use crate::math::int::FGi32;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DashState {
|
pub struct DashState {
|
||||||
frames_in_dash: u32,
|
frames_in_dash: u32,
|
||||||
direction: FGi32,
|
direction: FighterFacingDirection,
|
||||||
ground_common: GroundedStateCommon
|
ground_common: GroundedStateCommon,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::hash::Hash for DashState {
|
impl std::hash::Hash for DashState {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.direction.to_bits().hash(state);
|
self.direction.hash(state);
|
||||||
self.frames_in_dash.hash(state);
|
self.frames_in_dash.hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DashState {
|
impl DashState {
|
||||||
pub fn new(direction: FGi32, ground_common: GroundedStateCommon) -> Self {
|
pub fn new(direction: FighterFacingDirection, ground_common: GroundedStateCommon) -> Self {
|
||||||
Self {
|
Self {
|
||||||
frames_in_dash: 0,
|
frames_in_dash: 0,
|
||||||
direction,
|
direction,
|
||||||
ground_common
|
ground_common,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FighterStateImpl for DashState {
|
impl FighterStateImpl for DashState {
|
||||||
const NAME: &'static str = "Dash";
|
const NAME: &'static str = "Dash";
|
||||||
fn check_interrupt(
|
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
||||||
&self,
|
|
||||||
state_context: &FighterStateContext,
|
|
||||||
) -> Option<FighterState> {
|
|
||||||
if self.frames_in_dash > state_context.fighter_attribs.dash_duration {
|
if self.frames_in_dash > state_context.fighter_attribs.dash_duration {
|
||||||
run::check_input(state_context, &self.ground_common)
|
run::check_input(state_context, &self.ground_common)
|
||||||
.or_else(|| walk::check_input(state_context, &self.ground_common))
|
.or_else(|| walk::check_input(state_context, &self.ground_common))
|
||||||
@@ -58,13 +55,20 @@ impl FighterStateImpl for DashState {
|
|||||||
} else {
|
} else {
|
||||||
check_smash_input_with_dir(state_context)
|
check_smash_input_with_dir(state_context)
|
||||||
.filter(|dir| *dir != self.direction)
|
.filter(|dir| *dir != self.direction)
|
||||||
.and_then(|dir| Some(FighterState::Dash(DashState::new(dir, self.ground_common.clone()))))
|
.and_then(|dir| {
|
||||||
|
Some(FighterState::Dash(DashState::new(
|
||||||
|
dir,
|
||||||
|
self.ground_common.clone(),
|
||||||
|
)))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter(&mut self, state_context: &mut FighterStateContext) {
|
fn on_enter(&mut self, state_context: &mut FighterStateContext) {
|
||||||
|
*state_context.facing_direction = self.direction;
|
||||||
state_context.input.clear_buffer();
|
state_context.input.clear_buffer();
|
||||||
state_context.velocity.x = state_context.fighter_attribs.dash_initial_velocity * self.direction;
|
state_context.velocity.x =
|
||||||
|
state_context.fighter_attribs.dash_initial_velocity * self.direction.to_sign();
|
||||||
|
|
||||||
state_context.animation_transitions.play(
|
state_context.animation_transitions.play(
|
||||||
&mut state_context.animation_player,
|
&mut state_context.animation_player,
|
||||||
@@ -79,7 +83,9 @@ impl FighterStateImpl for DashState {
|
|||||||
info!("{}", self.frames_in_dash);
|
info!("{}", self.frames_in_dash);
|
||||||
|
|
||||||
let last_frame = state_context.input.get_last_frame();
|
let last_frame = state_context.input.get_last_frame();
|
||||||
let (accel, target_vel) = state_context.fighter_attribs.get_accel_and_target_dashrun(&last_frame, self.direction);
|
let (accel, target_vel) = state_context
|
||||||
|
.fighter_attribs
|
||||||
|
.get_accel_and_target_dashrun(&last_frame, self.direction.to_sign());
|
||||||
let accel = ground::compute_ground_accel(
|
let accel = ground::compute_ground_accel(
|
||||||
accel,
|
accel,
|
||||||
target_vel,
|
target_vel,
|
||||||
@@ -100,11 +106,9 @@ impl FighterStateImpl for DashState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut FighterStateContext,
|
state_context: &mut FighterStateContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
if let GroundedMotionResult::InAir = ground::collide_with_stage_grounded(
|
if let GroundedMotionResult::InAir =
|
||||||
state_context,
|
ground::collide_with_stage_grounded(state_context, &mut self.ground_common, true)
|
||||||
&mut self.ground_common,
|
{
|
||||||
true
|
|
||||||
) {
|
|
||||||
Some(FighterState::Fall(FallState))
|
Some(FighterState::Fall(FallState))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -112,16 +116,20 @@ impl FighterStateImpl for DashState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_smash_input_with_dir(state_context: &FighterStateContext) -> Option<FGi32> {
|
fn check_smash_input_with_dir(state_context: &FighterStateContext) -> Option<FighterFacingDirection> {
|
||||||
if state_context.input.has_command(SmashMoveLeft) {
|
if state_context.input.has_command(SmashMoveLeft) {
|
||||||
return Some(FGi32::NEG_ONE);
|
return Some(FighterFacingDirection::Left);
|
||||||
} else if state_context.input.has_command(SmashMoveRight) {
|
} else if state_context.input.has_command(SmashMoveRight) {
|
||||||
return Some(FGi32::ONE);
|
return Some(FighterFacingDirection::Right);
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_input(state_context: &FighterStateContext, ground_common: &GroundedStateCommon) -> Option<FighterState> {
|
pub fn check_input(
|
||||||
check_smash_input_with_dir(state_context).map(|dir| FighterState::Dash(DashState::new(dir, ground_common.clone())))
|
state_context: &FighterStateContext,
|
||||||
|
ground_common: &GroundedStateCommon,
|
||||||
|
) -> Option<FighterState> {
|
||||||
|
check_smash_input_with_dir(state_context)
|
||||||
|
.map(|dir| FighterState::Dash(DashState::new(dir, ground_common.clone())))
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -1,9 +1,9 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use super::{FighterStateImpl, FighterStateContext, ground, walk};
|
use super::{FighterStateContext, FighterStateImpl, ground, walk};
|
||||||
use crate::fighter::state::{FighterState, air};
|
|
||||||
use crate::fighter::state::ground::GroundedStateCommon;
|
use crate::fighter::state::ground::GroundedStateCommon;
|
||||||
use crate::fighter::state::wait::WaitState;
|
use crate::fighter::state::wait::WaitState;
|
||||||
|
use crate::fighter::state::{FighterState, air};
|
||||||
use crate::fighter::{FighterAttributes, FighterVelocity, collision, motion};
|
use crate::fighter::{FighterAttributes, FighterVelocity, collision, motion};
|
||||||
use crate::game_settings::GameSettings;
|
use crate::game_settings::GameSettings;
|
||||||
use crate::stage::line::StageCollision;
|
use crate::stage::line::StageCollision;
|
||||||
@@ -13,10 +13,7 @@ pub struct FallState;
|
|||||||
|
|
||||||
impl FighterStateImpl for FallState {
|
impl FighterStateImpl for FallState {
|
||||||
const NAME: &'static str = "Fall";
|
const NAME: &'static str = "Fall";
|
||||||
fn check_interrupt(
|
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
||||||
&self,
|
|
||||||
state_context: &FighterStateContext,
|
|
||||||
) -> Option<FighterState> {
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +21,11 @@ impl FighterStateImpl for FallState {
|
|||||||
|
|
||||||
fn update(&mut self, state_context: &mut super::FighterStateContext) {
|
fn update(&mut self, state_context: &mut super::FighterStateContext) {
|
||||||
air::integrate_gravity(state_context.velocity, state_context.fighter_attribs);
|
air::integrate_gravity(state_context.velocity, state_context.fighter_attribs);
|
||||||
air::apply_air_motion(state_context.velocity, state_context.translation, state_context.prev_translation);
|
air::apply_air_motion(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.translation,
|
||||||
|
state_context.prev_translation,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_collision_interrupt(
|
fn check_collision_interrupt(
|
||||||
@@ -35,9 +36,9 @@ impl FighterStateImpl for FallState {
|
|||||||
// Adjust translation
|
// Adjust translation
|
||||||
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
||||||
let grounded_common = GroundedStateCommon {
|
let grounded_common = GroundedStateCommon {
|
||||||
current_line_id: res.line_id
|
current_line_id: res.line_id,
|
||||||
};
|
};
|
||||||
Some(FighterState::Wait(WaitState { grounded_common } ))
|
Some(FighterState::Wait(WaitState { grounded_common }))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -52,4 +53,3 @@ pub fn check_input(state_context: &FighterStateContext) -> Option<FighterState>
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ pub fn compute_ground_accel(
|
|||||||
} else {
|
} else {
|
||||||
let mut accel = accel;
|
let mut accel = accel;
|
||||||
let ground_max_horizontal_velocity =
|
let ground_max_horizontal_velocity =
|
||||||
game_settings.figher_common.ground_max_horizontal_velocity;
|
game_settings.fighter_common.ground_max_horizontal_velocity;
|
||||||
if !(gr_vel * accel < FGi32::ZERO) {
|
if !(gr_vel * accel < FGi32::ZERO) {
|
||||||
// accelerating, not reversing
|
// accelerating, not reversing
|
||||||
if accel > FGi32::ZERO {
|
if accel > FGi32::ZERO {
|
||||||
@@ -146,7 +146,7 @@ pub fn collide_with_stage_grounded(
|
|||||||
|
|
||||||
pub fn grounded_movement_common_interrupts(
|
pub fn grounded_movement_common_interrupts(
|
||||||
state_context: &FighterStateContext,
|
state_context: &FighterStateContext,
|
||||||
ground_common: &GroundedStateCommon
|
ground_common: &GroundedStateCommon,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
super::jump::check_input(state_context, ground_common)
|
super::jump::check_input(state_context, ground_common)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
fighter::state::{
|
fighter::{animation::AnimKind, state::{
|
||||||
FighterState, FighterStateContext, FighterStateImpl,
|
FighterState, FighterStateContext, FighterStateImpl,
|
||||||
fall::FallState,
|
fall::FallState,
|
||||||
ground::{self, GroundedMotionResult, GroundedStateCommon},
|
ground::{self, GroundedMotionResult, GroundedStateCommon},
|
||||||
},
|
}}, input::FighterCommands,
|
||||||
input::FighterCommands,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum JumpType {
|
pub enum JumpType {
|
||||||
@@ -52,7 +53,7 @@ impl FighterStateImpl for JumpSquatState {
|
|||||||
state_context.fighter_attribs.ground_friction
|
state_context.fighter_attribs.ground_friction
|
||||||
* state_context
|
* state_context
|
||||||
.game_settings
|
.game_settings
|
||||||
.figher_common
|
.fighter_common
|
||||||
.ground_friction_over_walk_speed_multiplier
|
.ground_friction_over_walk_speed_multiplier
|
||||||
} else {
|
} else {
|
||||||
state_context.fighter_attribs.ground_friction
|
state_context.fighter_attribs.ground_friction
|
||||||
@@ -81,6 +82,17 @@ impl FighterStateImpl for JumpSquatState {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn play_animation(
|
||||||
|
&self,
|
||||||
|
transitions: &mut AnimationTransitions,
|
||||||
|
player: &mut AnimationPlayer,
|
||||||
|
anims: &crate::fighter::visual::FighterAnimations,
|
||||||
|
) {
|
||||||
|
transitions.play(player, anims.clips[&AnimKind::JumpSquat], Duration::ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_enter(&mut self, _state_context: &mut FighterStateContext) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FighterStateImpl for JumpState {
|
impl FighterStateImpl for JumpState {
|
||||||
@@ -99,7 +111,5 @@ pub fn check_input(
|
|||||||
state_context
|
state_context
|
||||||
.input
|
.input
|
||||||
.has_command(FighterCommands::Jump)
|
.has_command(FighterCommands::Jump)
|
||||||
.then(|| FighterState::JumpSquat(JumpSquatState::create(
|
.then(|| FighterState::JumpSquat(JumpSquatState::create(ground_common.clone())))
|
||||||
ground_common.clone(),
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use crate::fighter::animation::FighterAnimationPlayerLink;
|
|||||||
use crate::fighter::ecb::FighterPreviousECB;
|
use crate::fighter::ecb::FighterPreviousECB;
|
||||||
use crate::fighter::visual::FighterAnimations;
|
use crate::fighter::visual::FighterAnimations;
|
||||||
use crate::fighter::{
|
use crate::fighter::{
|
||||||
FighterAttributes, FighterECB, FighterPreviousTranslation, FighterTranslation, FighterVelocity,
|
FighterAttributes, FighterECB, FighterFacingDirection, FighterPreviousTranslation, FighterTranslation, FighterVelocity,
|
||||||
};
|
};
|
||||||
use crate::game_settings::GameSettings;
|
use crate::game_settings::GameSettings;
|
||||||
use crate::input::FighterInput;
|
use crate::input::FighterInput;
|
||||||
@@ -88,6 +88,7 @@ pub struct FighterStateContext<'a> {
|
|||||||
pub ecb: &'a mut FighterECB,
|
pub ecb: &'a mut FighterECB,
|
||||||
pub prev_ecb: &'a mut FighterPreviousECB,
|
pub prev_ecb: &'a mut FighterPreviousECB,
|
||||||
pub fighter_attribs: &'a FighterAttributes,
|
pub fighter_attribs: &'a FighterAttributes,
|
||||||
|
pub facing_direction: &'a mut FighterFacingDirection,
|
||||||
pub game_settings: &'a GameSettings,
|
pub game_settings: &'a GameSettings,
|
||||||
pub stage_collision: &'a StageCollision,
|
pub stage_collision: &'a StageCollision,
|
||||||
pub animations: &'a FighterAnimations,
|
pub animations: &'a FighterAnimations,
|
||||||
@@ -114,6 +115,7 @@ pub struct FighterFrameQuery {
|
|||||||
pub velocity: &'static mut FighterVelocity,
|
pub velocity: &'static mut FighterVelocity,
|
||||||
pub ecb: &'static mut FighterECB,
|
pub ecb: &'static mut FighterECB,
|
||||||
pub prev_ecb: &'static mut FighterPreviousECB,
|
pub prev_ecb: &'static mut FighterPreviousECB,
|
||||||
|
pub facing_direction: &'static mut FighterFacingDirection,
|
||||||
pub attributes: &'static FighterAttributes,
|
pub attributes: &'static FighterAttributes,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +135,7 @@ impl<'w, 's> FighterFrameQueryItem<'w, 's> {
|
|||||||
velocity: &mut self.velocity,
|
velocity: &mut self.velocity,
|
||||||
ecb: &mut self.ecb,
|
ecb: &mut self.ecb,
|
||||||
prev_ecb: &mut self.prev_ecb,
|
prev_ecb: &mut self.prev_ecb,
|
||||||
|
facing_direction: &mut self.facing_direction,
|
||||||
fighter_attribs: self.attributes,
|
fighter_attribs: self.attributes,
|
||||||
game_settings,
|
game_settings,
|
||||||
stage_collision,
|
stage_collision,
|
||||||
|
|||||||
+29
-21
@@ -2,7 +2,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use super::{FighterStateImpl, FighterStateContext, ground, wait, walk};
|
use super::{FighterStateContext, FighterStateImpl, ground, wait, walk};
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
use crate::fighter::state::FighterState;
|
use crate::fighter::state::FighterState;
|
||||||
use crate::fighter::state::fall::FallState;
|
use crate::fighter::state::fall::FallState;
|
||||||
@@ -14,34 +14,39 @@ use crate::math::int::FGi32;
|
|||||||
|
|
||||||
#[derive(Component, Debug, Clone, Hash)]
|
#[derive(Component, Debug, Clone, Hash)]
|
||||||
pub struct RunState {
|
pub struct RunState {
|
||||||
pub grounded_common: GroundedStateCommon
|
pub grounded_common: GroundedStateCommon,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FighterStateImpl for RunState {
|
impl FighterStateImpl for RunState {
|
||||||
const NAME: &'static str = "Run";
|
const NAME: &'static str = "Run";
|
||||||
fn check_interrupt(
|
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
||||||
&self,
|
|
||||||
state_context: &FighterStateContext,
|
|
||||||
) -> Option<FighterState> {
|
|
||||||
let input_frame = state_context.input.get_last_frame();
|
let input_frame = state_context.input.get_last_frame();
|
||||||
if input_frame.movement.x.abs() >= state_context.game_settings.input_common.run_stick_threshold {
|
if input_frame.movement.x.abs()
|
||||||
|
>= state_context.game_settings.input_common.run_stick_threshold
|
||||||
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
walk::check_input(state_context, &self.grounded_common).or_else(|| wait::check_input(state_context, &self.grounded_common))
|
walk::check_input(state_context, &self.grounded_common)
|
||||||
|
.or_else(|| wait::check_input(state_context, &self.grounded_common))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter(&mut self, state_context: &mut super::FighterStateContext) {
|
fn on_enter(&mut self, state_context: &mut super::FighterStateContext) {
|
||||||
state_context.animation_transitions.play(
|
state_context
|
||||||
&mut state_context.animation_player,
|
.animation_transitions
|
||||||
state_context.animations.clips[&AnimKind::Run],
|
.play(
|
||||||
Duration::ZERO,
|
&mut state_context.animation_player,
|
||||||
).repeat();
|
state_context.animations.clips[&AnimKind::Run],
|
||||||
|
Duration::ZERO,
|
||||||
|
)
|
||||||
|
.repeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, state_context: &mut super::FighterStateContext) {
|
fn update(&mut self, state_context: &mut super::FighterStateContext) {
|
||||||
let last_frame = state_context.input.get_last_frame();
|
let last_frame = state_context.input.get_last_frame();
|
||||||
let (accel, target_vel) = state_context.fighter_attribs.get_accel_and_target_dashrun(&last_frame, FGi32::ONE);
|
let (accel, target_vel) = state_context
|
||||||
|
.fighter_attribs
|
||||||
|
.get_accel_and_target_dashrun(&last_frame, FGi32::ONE);
|
||||||
let accel = ground::compute_ground_accel(
|
let accel = ground::compute_ground_accel(
|
||||||
accel,
|
accel,
|
||||||
target_vel,
|
target_vel,
|
||||||
@@ -62,11 +67,9 @@ impl FighterStateImpl for RunState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut FighterStateContext,
|
state_context: &mut FighterStateContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
if let GroundedMotionResult::InAir = ground::collide_with_stage_grounded(
|
if let GroundedMotionResult::InAir =
|
||||||
state_context,
|
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||||
&mut self.grounded_common,
|
{
|
||||||
false
|
|
||||||
) {
|
|
||||||
Some(FighterState::Fall(FallState))
|
Some(FighterState::Fall(FallState))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -74,11 +77,16 @@ impl FighterStateImpl for RunState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_input(state_context: &FighterStateContext, ground_state_common: &GroundedStateCommon) -> Option<FighterState> {
|
pub fn check_input(
|
||||||
|
state_context: &FighterStateContext,
|
||||||
|
ground_state_common: &GroundedStateCommon,
|
||||||
|
) -> Option<FighterState> {
|
||||||
let input_frame = state_context.input.get_last_frame();
|
let input_frame = state_context.input.get_last_frame();
|
||||||
if input_frame.movement.x.abs() >= state_context.game_settings.input_common.run_stick_threshold
|
if input_frame.movement.x.abs() >= state_context.game_settings.input_common.run_stick_threshold
|
||||||
{
|
{
|
||||||
return Some(FighterState::Run(RunState { grounded_common: ground_state_common.clone() }));
|
return Some(FighterState::Run(RunState {
|
||||||
|
grounded_common: ground_state_common.clone(),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
+14
-10
@@ -4,11 +4,11 @@ use bevy::prelude::*;
|
|||||||
|
|
||||||
use super::{FighterStateContext, FighterStateImpl, ground, walk};
|
use super::{FighterStateContext, FighterStateImpl, ground, walk};
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
use crate::fighter::state::{FighterState, dash};
|
|
||||||
use crate::fighter::state::fall::FallState;
|
use crate::fighter::state::fall::FallState;
|
||||||
use crate::fighter::state::ground::{
|
use crate::fighter::state::ground::{
|
||||||
GroundedMotionResult, GroundedStateCommon, grounded_movement_common_interrupts,
|
GroundedMotionResult, GroundedStateCommon, grounded_movement_common_interrupts,
|
||||||
};
|
};
|
||||||
|
use crate::fighter::state::{FighterState, dash};
|
||||||
use crate::fighter::{FighterAttributes, FighterVelocity};
|
use crate::fighter::{FighterAttributes, FighterVelocity};
|
||||||
use crate::game_settings::GameSettings;
|
use crate::game_settings::GameSettings;
|
||||||
use crate::stage::line::StageLineID;
|
use crate::stage::line::StageLineID;
|
||||||
@@ -21,17 +21,21 @@ pub struct WaitState {
|
|||||||
impl FighterStateImpl for WaitState {
|
impl FighterStateImpl for WaitState {
|
||||||
const NAME: &'static str = "Wait";
|
const NAME: &'static str = "Wait";
|
||||||
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
||||||
dash::check_input(state_context, &self.grounded_common).or_else(||
|
dash::check_input(state_context, &self.grounded_common).or_else(|| {
|
||||||
grounded_movement_common_interrupts(state_context, &self.grounded_common)
|
grounded_movement_common_interrupts(state_context, &self.grounded_common)
|
||||||
.or_else(|| walk::check_input(state_context, &self.grounded_common)))
|
.or_else(|| walk::check_input(state_context, &self.grounded_common))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter(&mut self, state_context: &mut super::FighterStateContext) {
|
fn on_enter(&mut self, state_context: &mut super::FighterStateContext) {
|
||||||
state_context.animation_transitions.play(
|
state_context
|
||||||
&mut state_context.animation_player,
|
.animation_transitions
|
||||||
state_context.animations.clips[&AnimKind::Wait],
|
.play(
|
||||||
Duration::ZERO,
|
&mut state_context.animation_player,
|
||||||
).repeat();
|
state_context.animations.clips[&AnimKind::Wait],
|
||||||
|
Duration::ZERO,
|
||||||
|
)
|
||||||
|
.repeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, state_context: &mut super::FighterStateContext) {
|
fn update(&mut self, state_context: &mut super::FighterStateContext) {
|
||||||
@@ -40,7 +44,7 @@ impl FighterStateImpl for WaitState {
|
|||||||
state_context.fighter_attribs.ground_friction
|
state_context.fighter_attribs.ground_friction
|
||||||
* state_context
|
* state_context
|
||||||
.game_settings
|
.game_settings
|
||||||
.figher_common
|
.fighter_common
|
||||||
.ground_friction_over_walk_speed_multiplier
|
.ground_friction_over_walk_speed_multiplier
|
||||||
} else {
|
} else {
|
||||||
state_context.fighter_attribs.ground_friction
|
state_context.fighter_attribs.ground_friction
|
||||||
|
|||||||
@@ -24,11 +24,14 @@ impl FighterStateImpl for WalkState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter(&mut self, state_context: &mut FighterStateContext) {
|
fn on_enter(&mut self, state_context: &mut FighterStateContext) {
|
||||||
state_context.animation_transitions.play(
|
state_context
|
||||||
&mut state_context.animation_player,
|
.animation_transitions
|
||||||
state_context.animations.clips[&AnimKind::Walk],
|
.play(
|
||||||
Duration::ZERO,
|
&mut state_context.animation_player,
|
||||||
).repeat();
|
state_context.animations.clips[&AnimKind::Walk],
|
||||||
|
Duration::ZERO,
|
||||||
|
)
|
||||||
|
.repeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, state_context: &mut FighterStateContext) {
|
fn update(&mut self, state_context: &mut FighterStateContext) {
|
||||||
|
|||||||
+2
-90
@@ -1,98 +1,10 @@
|
|||||||
use bevy::gltf::Gltf;
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{AppState, fighter::{
|
use crate::fighter::animation::AnimKind;
|
||||||
animation::{AnimKind, AnimManifest},
|
|
||||||
spawn_fighter,
|
|
||||||
}};
|
|
||||||
|
|
||||||
// One entry per character being loaded
|
#[derive(Component, Clone)]
|
||||||
pub struct PendingCharacter {
|
|
||||||
pub id: String,
|
|
||||||
pub gltf: Handle<Gltf>,
|
|
||||||
pub manifest: Handle<AnimManifest>,
|
|
||||||
pub resolved: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
|
||||||
pub struct CharacterLoadQueue(pub Vec<PendingCharacter>);
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct FighterAnimations {
|
pub struct FighterAnimations {
|
||||||
pub graph: Handle<AnimationGraph>,
|
pub graph: Handle<AnimationGraph>,
|
||||||
pub clips: HashMap<AnimKind, AnimationNodeIndex>,
|
pub clips: HashMap<AnimKind, AnimationNodeIndex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_loading(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
||||||
let queue = vec![PendingCharacter {
|
|
||||||
id: "jigglypuff".to_owned(),
|
|
||||||
gltf: asset_server.load(format!("fighters/jiggs/jigglypuff-normal.glb")),
|
|
||||||
manifest: asset_server.load(format!("fighters/jiggs/jigglypuff-anims.ron")),
|
|
||||||
resolved: false,
|
|
||||||
}];
|
|
||||||
|
|
||||||
commands.insert_resource(CharacterLoadQueue(queue));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn resolve_character_assets(
|
|
||||||
mut commands: Commands,
|
|
||||||
mut queue: ResMut<CharacterLoadQueue>,
|
|
||||||
gltf_assets: Res<Assets<Gltf>>,
|
|
||||||
manifest_assets: Res<Assets<AnimManifest>>,
|
|
||||||
mut graphs: ResMut<Assets<AnimationGraph>>,
|
|
||||||
anim_clips: Res<Assets<AnimationClip>>,
|
|
||||||
mut next_state: ResMut<NextState<AppState>>,
|
|
||||||
) {
|
|
||||||
for pending in queue.0.iter_mut().filter(|p| !p.resolved) {
|
|
||||||
let (Some(gltf), Some(manifest)) = (
|
|
||||||
gltf_assets.get(&pending.gltf),
|
|
||||||
manifest_assets.get(&pending.manifest),
|
|
||||||
) else {
|
|
||||||
continue; // still loading, try again next frame
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut graph = AnimationGraph::new();
|
|
||||||
let mut clips = HashMap::new();
|
|
||||||
let mut missing = Vec::new();
|
|
||||||
|
|
||||||
for (kind, clip_name) in manifest.0.iter() {
|
|
||||||
match gltf.named_animations.get(clip_name.as_str()) {
|
|
||||||
Some(clip_handle) => {
|
|
||||||
let animation = anim_clips.get(clip_handle);
|
|
||||||
info!("{clip_name}, {}", animation.unwrap().duration());
|
|
||||||
let node = graph.add_clip(clip_handle.clone(), 1.0, graph.root);
|
|
||||||
clips.insert(*kind, node);
|
|
||||||
}
|
|
||||||
None => missing.push(clip_name.clone()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !missing.is_empty() {
|
|
||||||
panic!(
|
|
||||||
"character '{}': manifest references animations not found in glb: {:?}",
|
|
||||||
pending.id, missing
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let graph_handle = graphs.add(graph);
|
|
||||||
|
|
||||||
|
|
||||||
spawn_fighter(
|
|
||||||
&mut commands,
|
|
||||||
FighterAnimations {
|
|
||||||
graph: graph_handle,
|
|
||||||
clips,
|
|
||||||
},
|
|
||||||
WorldAssetRoot(gltf.scenes[0].clone()),
|
|
||||||
);
|
|
||||||
|
|
||||||
pending.resolved = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All done? Move on.
|
|
||||||
if queue.0.iter().all(|p| p.resolved) {
|
|
||||||
next_state.set(AppState::InGame);
|
|
||||||
commands.remove_resource::<CharacterLoadQueue>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+32
-22
@@ -1,38 +1,48 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use bevy_asset_loader::asset_collection::AssetCollection;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::math::int::FGi32;
|
use crate::math::int::FGi32;
|
||||||
|
|
||||||
|
#[derive(Reflect, Serialize, Deserialize, Clone)]
|
||||||
|
#[reflect(opaque)]
|
||||||
pub struct FighterSettingsCommon {
|
pub struct FighterSettingsCommon {
|
||||||
pub walk_speed_ease: FGi32,
|
pub walk_speed_ease: FGi32,
|
||||||
pub ground_max_horizontal_velocity: FGi32,
|
pub ground_max_horizontal_velocity: FGi32,
|
||||||
pub ground_friction_over_walk_speed_multiplier: FGi32
|
pub ground_friction_over_walk_speed_multiplier: FGi32,
|
||||||
}
|
}
|
||||||
|
#[derive(Reflect, Serialize, Deserialize, Clone)]
|
||||||
|
#[reflect(opaque)]
|
||||||
pub struct InputSettingsCommon {
|
pub struct InputSettingsCommon {
|
||||||
pub stick_deadzone: f32,
|
pub stick_deadzone: FGi32,
|
||||||
pub trigger_deadzone: f32,
|
pub trigger_deadzone: FGi32,
|
||||||
pub smash_input_reset_axis_threshold: f32,
|
pub smash_input_reset_axis_threshold: FGi32,
|
||||||
pub smash_input_axis_threshold: f32,
|
pub smash_input_axis_threshold: FGi32,
|
||||||
pub run_stick_threshold: f32,
|
pub run_stick_threshold: FGi32,
|
||||||
pub smash_input_frame_threshold: u8,
|
pub smash_input_frame_threshold: u8,
|
||||||
pub input_buffer_size: u8,
|
pub input_buffer_size: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InputSettingsCommon {
|
#[derive(Reflect, Serialize, Deserialize, Resource, Asset, Clone)]
|
||||||
fn default() -> Self {
|
pub struct GameSettings {
|
||||||
Self {
|
pub fighter_common: FighterSettingsCommon,
|
||||||
stick_deadzone: 0.28f32,
|
pub input_common: InputSettingsCommon,
|
||||||
trigger_deadzone: 0.3f32,
|
pub fighter_manifest_paths: Vec<String>,
|
||||||
smash_input_reset_axis_threshold: 0.25,
|
|
||||||
smash_input_axis_threshold: 0.8,
|
|
||||||
run_stick_threshold: 0.625,
|
|
||||||
smash_input_frame_threshold: 2,
|
|
||||||
input_buffer_size: 5
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(AssetCollection, Resource)]
|
||||||
pub struct GameSettings {
|
pub struct CommonAssets {
|
||||||
pub figher_common: FighterSettingsCommon,
|
#[asset(path = "game_settings.ron")]
|
||||||
pub input_common: InputSettingsCommon
|
game_settings: Handle<GameSettings>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromWorld for GameSettings {
|
||||||
|
fn from_world(world: &mut World) -> Self {
|
||||||
|
let game_settings_handle = world.resource::<CommonAssets>().game_settings.clone();
|
||||||
|
world
|
||||||
|
.resource::<Assets<GameSettings>>()
|
||||||
|
.get(&game_settings_handle)
|
||||||
|
.expect("GameSettings should already be loaded! Bug?")
|
||||||
|
.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+4
-2
@@ -100,7 +100,6 @@ pub fn postprocess_input(
|
|||||||
game_settings: Res<GameSettings>,
|
game_settings: Res<GameSettings>,
|
||||||
) {
|
) {
|
||||||
for (mut input, player) in query {
|
for (mut input, player) in query {
|
||||||
|
|
||||||
for command in FighterCommands::iter() {
|
for command in FighterCommands::iter() {
|
||||||
input.reduce_command_lifetime(command);
|
input.reduce_command_lifetime(command);
|
||||||
}
|
}
|
||||||
@@ -128,7 +127,10 @@ pub fn postprocess_input(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !input.prev_frame.jump && input.current_frame.jump {
|
if !input.prev_frame.jump && input.current_frame.jump {
|
||||||
input.set_lifetime(FighterCommands::Jump, game_settings.input_common.input_buffer_size);
|
input.set_lifetime(
|
||||||
|
FighterCommands::Jump,
|
||||||
|
game_settings.input_common.input_buffer_size,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if x_abs >= axis_threshold && input.frames_in_smash_move_deadzone <= frame_threshold {
|
if x_abs >= axis_threshold && input.frames_in_smash_move_deadzone <= frame_threshold {
|
||||||
|
|||||||
+1
-1
@@ -9,5 +9,5 @@ use crate::{input::InputActionState, math::vec::FGVec2};
|
|||||||
pub struct FighterInputFrame {
|
pub struct FighterInputFrame {
|
||||||
pub movement: FGVec2,
|
pub movement: FGVec2,
|
||||||
pub directional_attack: FGVec2,
|
pub directional_attack: FGVec2,
|
||||||
pub jump: bool
|
pub jump: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,9 +44,7 @@ pub fn preprocess_keyboard_input(
|
|||||||
InputMapAction::MovementYDir(sign) => {
|
InputMapAction::MovementYDir(sign) => {
|
||||||
input_frame.movement.y += (sign) * action_strength
|
input_frame.movement.y += (sign) * action_strength
|
||||||
}
|
}
|
||||||
InputMapAction::Jump => {
|
InputMapAction::Jump => input_frame.jump = action_strength != FGi32::ZERO,
|
||||||
input_frame.jump = action_strength != FGi32::ZERO
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+61
-43
@@ -21,21 +21,22 @@
|
|||||||
//! save, click Rebuild in jackdaw (or run `jd build`) and it
|
//! save, click Rebuild in jackdaw (or run `jd build`) and it
|
||||||
//! appears in `Add Component`. No registration code is needed.
|
//! appears in `Add Component`. No registration code is needed.
|
||||||
|
|
||||||
use bevy::{mesh::SphereMeshBuilder, prelude::*};
|
use bevy::prelude::*;
|
||||||
|
use bevy_asset_loader::prelude::*;
|
||||||
use bevy_wind_waker_shader::prelude::*;
|
use bevy_wind_waker_shader::prelude::*;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use jackdaw_runtime::prelude::*;
|
use jackdaw_runtime::EditorCategory;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
fighter::{
|
fighter::manifest::FighterManifest, game_settings::GameSettings,
|
||||||
FighterAttributes, FighterECB, FighterTranslation, FighterVelocity, FighterVisual, animation::{AnimManifest}, state::{FighterState, fall::FallState, wait::WaitState}, visual::resolve_character_assets,
|
schedule::GameplaySchedulePlugin,
|
||||||
}, game_settings::{FighterSettingsCommon, GameSettings, InputSettingsCommon}, input::FighterInput, math::{int::FGi32, vec::FGVec2}, player::Player, schedule::GameplaySchedulePlugin,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
pub mod fighter;
|
pub mod fighter;
|
||||||
pub mod game_settings;
|
pub mod game_settings;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
|
pub mod match_loading;
|
||||||
mod math;
|
mod math;
|
||||||
pub mod netcode;
|
pub mod netcode;
|
||||||
pub mod player;
|
pub mod player;
|
||||||
@@ -45,8 +46,15 @@ pub mod stage;
|
|||||||
#[derive(States, Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
|
#[derive(States, Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
|
||||||
pub enum AppState {
|
pub enum AppState {
|
||||||
#[default]
|
#[default]
|
||||||
LoadingCharacters,
|
LoadCommonAssets,
|
||||||
InGame,
|
LoadFighterManifests,
|
||||||
|
PrepareFighterManifests,
|
||||||
|
CommonAssetLoadFailed,
|
||||||
|
Idle,
|
||||||
|
LoadingMatch,
|
||||||
|
PreparingMatch,
|
||||||
|
InMatch,
|
||||||
|
MatchLoadFailed,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Your game's Bevy plugin. The editor finds it by this name (override
|
/// Your game's Bevy plugin. The editor finds it by this name (override
|
||||||
@@ -55,47 +63,57 @@ pub enum AppState {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct GamePlugin;
|
pub struct GamePlugin;
|
||||||
|
|
||||||
pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
||||||
// debug stage
|
|
||||||
|
|
||||||
let _stage = commands.spawn((
|
|
||||||
WorldAssetRoot(asset_server.load("stages/YoshiStory.glb#Scene0")),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Plugin for GamePlugin {
|
impl Plugin for GamePlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
// Each module owns its own systems, rollback registrations and
|
// Each module owns its own systems, rollback registrations and
|
||||||
// resources; this plugin only wires them together and supplies the
|
// resources; this plugin only wires them together and supplies the
|
||||||
// game-level content and configuration.
|
// game-level content and configuration.
|
||||||
app
|
app.init_state::<AppState>()
|
||||||
.init_state::<AppState>()
|
.add_plugins((
|
||||||
.add_plugins((
|
WindWakerShaderPlugin::default(),
|
||||||
WindWakerShaderPlugin::default(),
|
// Brings up GGRS (and with it `GgrsSchedule`), so it goes first.
|
||||||
// Brings up GGRS (and with it `GgrsSchedule`), so it goes first.
|
netcode::FighterNetcodePlugin::default(),
|
||||||
netcode::FighterNetcodePlugin::default(),
|
GameplaySchedulePlugin,
|
||||||
GameplaySchedulePlugin,
|
input::FighterInputPlugin,
|
||||||
input::FighterInputPlugin,
|
fighter::FighterPlugin,
|
||||||
fighter::FighterPlugin,
|
stage::StagePlugin,
|
||||||
stage::StagePlugin,
|
bevy_common_assets::ron::RonAssetPlugin::<FighterManifest>::new(&["fighter.ron"]),
|
||||||
bevy_common_assets::ron::RonAssetPlugin::<AnimManifest>::new(&[])
|
bevy_common_assets::ron::RonAssetPlugin::<GameSettings>::new(&["ron"]),
|
||||||
))
|
))
|
||||||
.add_systems(Startup, setup)
|
.add_loading_state(
|
||||||
.add_systems(Update, spin_cubes)
|
LoadingState::new(AppState::LoadingMatch)
|
||||||
.insert_resource(args::Args::parse())
|
.continue_to_state(AppState::PreparingMatch)
|
||||||
.insert_resource(GameSettings {
|
.on_failure_continue_to_state(AppState::MatchLoadFailed)
|
||||||
figher_common: FighterSettingsCommon {
|
.load_collection::<match_loading::MatchAssets>(),
|
||||||
walk_speed_ease: FGi32::lit("0.5"),
|
)
|
||||||
ground_max_horizontal_velocity: FGi32::lit("3.0"),
|
.add_loading_state(
|
||||||
ground_friction_over_walk_speed_multiplier: FGi32::lit("2.0"),
|
LoadingState::new(AppState::LoadCommonAssets)
|
||||||
},
|
.continue_to_state(AppState::LoadFighterManifests)
|
||||||
input_common: InputSettingsCommon::default(),
|
.on_failure_continue_to_state(AppState::CommonAssetLoadFailed)
|
||||||
})
|
.load_collection::<game_settings::CommonAssets>()
|
||||||
.add_systems(OnEnter(AppState::LoadingCharacters), crate::fighter::visual::start_loading)
|
.finally_init_resource::<GameSettings>(),
|
||||||
.add_systems(
|
)
|
||||||
Update,
|
.add_loading_state(
|
||||||
resolve_character_assets.run_if(in_state(AppState::LoadingCharacters)),
|
LoadingState::new(AppState::LoadFighterManifests)
|
||||||
);
|
.continue_to_state(AppState::PrepareFighterManifests)
|
||||||
|
.on_failure_continue_to_state(AppState::CommonAssetLoadFailed)
|
||||||
|
.load_collection::<fighter::manifest::FighterManifestAssets>(),
|
||||||
|
)
|
||||||
|
.add_systems(
|
||||||
|
OnEnter(AppState::PrepareFighterManifests),
|
||||||
|
fighter::manifest::prepare_fighter_manifests,
|
||||||
|
)
|
||||||
|
.add_systems(
|
||||||
|
OnEnter(AppState::Idle),
|
||||||
|
match_loading::initiate_default_match,
|
||||||
|
)
|
||||||
|
.add_systems(
|
||||||
|
OnEnter(AppState::PreparingMatch),
|
||||||
|
match_loading::prepare_match,
|
||||||
|
)
|
||||||
|
.add_systems(OnExit(AppState::InMatch), match_loading::cleanup_match)
|
||||||
|
.add_systems(Update, spin_cubes)
|
||||||
|
.insert_resource(args::Args::parse());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -5,12 +5,10 @@
|
|||||||
use bevy::camera_controller::free_camera::FreeCameraPlugin;
|
use bevy::camera_controller::free_camera::FreeCameraPlugin;
|
||||||
use bevy::image::{ImageAddressMode, ImagePlugin, ImageSamplerDescriptor};
|
use bevy::image::{ImageAddressMode, ImagePlugin, ImageSamplerDescriptor};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use bevy::remote::RemotePlugin;
|
||||||
use bevy::remote::http::RemoteHttpPlugin;
|
use bevy::remote::http::RemoteHttpPlugin;
|
||||||
use bevy::remote::{RemotePlugin};
|
|
||||||
use bevy_egui::EguiPlugin;
|
use bevy_egui::EguiPlugin;
|
||||||
use bevy_inspector_egui::{
|
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||||
quick::WorldInspectorPlugin
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() -> AppExit {
|
fn main() -> AppExit {
|
||||||
// A `Repeat` sampler so the tileable materials authored in the
|
// A `Repeat` sampler so the tileable materials authored in the
|
||||||
|
|||||||
@@ -0,0 +1,326 @@
|
|||||||
|
//! Match selection, asset loading, preparation, and cleanup.
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use bevy::{asset::UntypedHandle, gltf::Gltf, prelude::*};
|
||||||
|
use bevy_asset_loader::prelude::*;
|
||||||
|
use bevy_ggrs::prelude::Session;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
AppState,
|
||||||
|
args::Args,
|
||||||
|
fighter::{
|
||||||
|
FighterId,
|
||||||
|
animation::AnimKind,
|
||||||
|
manifest::{FighterManifest, FighterManifestRegistry},
|
||||||
|
spawn_fighter,
|
||||||
|
visual::FighterAnimations,
|
||||||
|
},
|
||||||
|
math::{int::FGi32, vec::FGVec2},
|
||||||
|
netcode::{GGRSCfg, session::create_session},
|
||||||
|
stage,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub enum StageId {
|
||||||
|
Battlefield,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StageId {
|
||||||
|
fn scene_path(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Battlefield => "stages/battlefield.glb#Scene0",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub struct MatchPlayer {
|
||||||
|
pub handle: usize,
|
||||||
|
pub fighter: FighterId,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource, Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct PendingMatch {
|
||||||
|
pub stage: StageId,
|
||||||
|
pub players: Vec<MatchPlayer>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SelectedFighterAssets {
|
||||||
|
pub fighter: FighterId,
|
||||||
|
pub model: Handle<Gltf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub struct MatchAssets {
|
||||||
|
pub stage: Handle<WorldAsset>,
|
||||||
|
pub fighters: Vec<SelectedFighterAssets>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MatchAssets {
|
||||||
|
fn requested(world: &World) -> Self {
|
||||||
|
let request = world.resource::<PendingMatch>();
|
||||||
|
let asset_server = world.resource::<AssetServer>();
|
||||||
|
let registry = world.resource::<FighterManifestRegistry>();
|
||||||
|
let manifests = world.resource::<Assets<FighterManifest>>();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
stage: asset_server.load(request.stage.scene_path()),
|
||||||
|
fighters: request
|
||||||
|
.players
|
||||||
|
.iter()
|
||||||
|
.map(|player| {
|
||||||
|
let handle = registry
|
||||||
|
.get(player.fighter)
|
||||||
|
.expect("startup validation guarantees every fighter has a manifest");
|
||||||
|
let manifest = manifests
|
||||||
|
.get(handle)
|
||||||
|
.expect("startup-loaded fighter manifest should remain available");
|
||||||
|
|
||||||
|
SelectedFighterAssets {
|
||||||
|
fighter: player.fighter,
|
||||||
|
model: asset_server.load(manifest.model_path.clone()),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AssetCollection for MatchAssets {
|
||||||
|
fn create(world: &mut World) -> Self {
|
||||||
|
Self::requested(world)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load(world: &mut World) -> Vec<UntypedHandle> {
|
||||||
|
let assets = Self::requested(world);
|
||||||
|
let mut handles = Vec::with_capacity(1 + assets.fighters.len());
|
||||||
|
handles.push(assets.stage.clone().untyped());
|
||||||
|
for character in assets.fighters {
|
||||||
|
handles.push(character.model.untyped());
|
||||||
|
}
|
||||||
|
handles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct MatchRoot;
|
||||||
|
|
||||||
|
pub fn initiate_match(
|
||||||
|
commands: &mut Commands,
|
||||||
|
next_state: &mut NextState<AppState>,
|
||||||
|
request: PendingMatch,
|
||||||
|
) {
|
||||||
|
commands.insert_resource(request);
|
||||||
|
next_state.set(AppState::LoadingMatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn initiate_default_match(
|
||||||
|
mut commands: Commands,
|
||||||
|
args: Res<Args>,
|
||||||
|
mut next_state: ResMut<NextState<AppState>>,
|
||||||
|
) {
|
||||||
|
let players = (0..args.players)
|
||||||
|
.map(|handle| MatchPlayer {
|
||||||
|
handle,
|
||||||
|
fighter: FighterId::TestFighter,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
initiate_match(
|
||||||
|
&mut commands,
|
||||||
|
&mut next_state,
|
||||||
|
PendingMatch {
|
||||||
|
stage: StageId::Battlefield,
|
||||||
|
players,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn prepare_match(
|
||||||
|
mut commands: Commands,
|
||||||
|
request: Res<PendingMatch>,
|
||||||
|
assets: Res<MatchAssets>,
|
||||||
|
gltfs: Res<Assets<Gltf>>,
|
||||||
|
registry: Res<FighterManifestRegistry>,
|
||||||
|
manifests: Res<Assets<FighterManifest>>,
|
||||||
|
mut graphs: ResMut<Assets<AnimationGraph>>,
|
||||||
|
args: Res<Args>,
|
||||||
|
mut next_state: ResMut<NextState<AppState>>,
|
||||||
|
) {
|
||||||
|
if !valid_player_handles(&request.players) {
|
||||||
|
fail_match(
|
||||||
|
&mut next_state,
|
||||||
|
"player handles must be unique and cover 0..player_count",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if assets.fighters.len() != request.players.len() {
|
||||||
|
fail_match(
|
||||||
|
&mut next_state,
|
||||||
|
"loaded character assets do not match the requested player slots",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut prepared = Vec::with_capacity(assets.fighters.len());
|
||||||
|
let mut shared_animations = HashMap::<FighterId, FighterAnimations>::new();
|
||||||
|
|
||||||
|
for character in &assets.fighters {
|
||||||
|
let manifest_handle = registry
|
||||||
|
.get(character.fighter)
|
||||||
|
.expect("startup validation guarantees every fighter has a manifest");
|
||||||
|
let Some(manifest) = manifests.get(manifest_handle) else {
|
||||||
|
fail_match(&mut next_state, "a fighter manifest is unavailable");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Some(gltf) = gltfs.get(&character.model) else {
|
||||||
|
fail_match(&mut next_state, "a loaded character GLTF is unavailable");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Some(scene) = gltf.scenes.first().cloned() else {
|
||||||
|
fail_match(&mut next_state, "a character GLTF contains no scene");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(animations) = shared_animations.get(&character.fighter) {
|
||||||
|
prepared.push((scene, animations.clone(), manifest.attributes));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut graph = AnimationGraph::new();
|
||||||
|
let mut clips = HashMap::<AnimKind, AnimationNodeIndex>::new();
|
||||||
|
|
||||||
|
for (kind, clip_name) in &manifest.animations {
|
||||||
|
let Some(clip) = gltf.named_animations.get(clip_name.as_str()) else {
|
||||||
|
fail_match(
|
||||||
|
&mut next_state,
|
||||||
|
&format!(
|
||||||
|
"{:?} animation manifest references missing clip '{clip_name}'",
|
||||||
|
character.fighter
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
clips.insert(*kind, graph.add_clip(clip.clone(), 1.0, graph.root));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !clips.contains_key(&AnimKind::Wait) {
|
||||||
|
fail_match(&mut next_state, "a character has no Wait animation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let animations = FighterAnimations {
|
||||||
|
graph: graphs.add(graph),
|
||||||
|
clips,
|
||||||
|
};
|
||||||
|
shared_animations.insert(character.fighter, animations.clone());
|
||||||
|
prepared.push((scene, animations, manifest.attributes));
|
||||||
|
}
|
||||||
|
|
||||||
|
let session = match create_session(&args, request.players.len()) {
|
||||||
|
Ok(session) => session,
|
||||||
|
Err(error) => {
|
||||||
|
fail_match(
|
||||||
|
&mut next_state,
|
||||||
|
&format!("failed to create GGRS session: {error}"),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let root = commands.spawn((Name::new("Match"), MatchRoot)).id();
|
||||||
|
stage::spawn_stage(&mut commands, root, assets.stage.clone());
|
||||||
|
|
||||||
|
for (index, (player, (scene, animations, attributes))) in
|
||||||
|
request.players.iter().zip(prepared).enumerate()
|
||||||
|
{
|
||||||
|
let spawn_x = (index as i32 * 2 + 1 - request.players.len() as i32) * 5;
|
||||||
|
spawn_fighter(
|
||||||
|
&mut commands,
|
||||||
|
player.handle,
|
||||||
|
FGVec2::new(FGi32::from_num(spawn_x), FGi32::lit("12.5")),
|
||||||
|
attributes,
|
||||||
|
animations,
|
||||||
|
WorldAssetRoot(scene),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
commands.insert_resource::<Session<GGRSCfg>>(session);
|
||||||
|
next_state.set(AppState::InMatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fail_match(next_state: &mut NextState<AppState>, message: &str) {
|
||||||
|
error!("Match preparation failed: {message}");
|
||||||
|
next_state.set(AppState::MatchLoadFailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn valid_player_handles(players: &[MatchPlayer]) -> bool {
|
||||||
|
let mut handles = players
|
||||||
|
.iter()
|
||||||
|
.map(|player| player.handle)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
handles.sort_unstable();
|
||||||
|
handles == (0..players.len()).collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cleanup_match(
|
||||||
|
mut commands: Commands,
|
||||||
|
roots: Query<Entity, With<MatchRoot>>,
|
||||||
|
fighters: Query<Entity, With<crate::player::Player>>,
|
||||||
|
) {
|
||||||
|
for root in &roots {
|
||||||
|
commands.entity(root).despawn();
|
||||||
|
}
|
||||||
|
for fighter in &fighters {
|
||||||
|
commands.entity(fighter).despawn();
|
||||||
|
}
|
||||||
|
commands.remove_resource::<Session<GGRSCfg>>();
|
||||||
|
commands.remove_resource::<stage::line::StageCollision>();
|
||||||
|
commands.remove_resource::<MatchAssets>();
|
||||||
|
commands.remove_resource::<PendingMatch>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn match_request_keeps_duplicate_fighter_slots() {
|
||||||
|
let request = PendingMatch {
|
||||||
|
stage: StageId::Battlefield,
|
||||||
|
players: vec![
|
||||||
|
MatchPlayer {
|
||||||
|
handle: 0,
|
||||||
|
fighter: FighterId::TestFighter,
|
||||||
|
},
|
||||||
|
MatchPlayer {
|
||||||
|
handle: 1,
|
||||||
|
fighter: FighterId::TestFighter,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(request.players.len(), 2);
|
||||||
|
assert_eq!(request.players[0].handle, 0);
|
||||||
|
assert_eq!(request.players[1].handle, 1);
|
||||||
|
assert!(valid_player_handles(&request.players));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn player_handles_must_match_the_session_range() {
|
||||||
|
let players = [
|
||||||
|
MatchPlayer {
|
||||||
|
handle: 0,
|
||||||
|
fighter: FighterId::TestFighter,
|
||||||
|
},
|
||||||
|
MatchPlayer {
|
||||||
|
handle: 0,
|
||||||
|
fighter: FighterId::TestFighter,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
assert!(!valid_player_handles(&players));
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
-9
@@ -11,15 +11,13 @@ use crate::math::{
|
|||||||
#[derive(Clone, Copy, PartialEq, Reflect)]
|
#[derive(Clone, Copy, PartialEq, Reflect)]
|
||||||
pub struct FGSegment2d {
|
pub struct FGSegment2d {
|
||||||
point1: FGVec2,
|
point1: FGVec2,
|
||||||
point2: FGVec2
|
point2: FGVec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FGSegment2d {
|
impl FGSegment2d {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(point1: FGVec2, point2: FGVec2) -> Self {
|
pub fn new(point1: FGVec2, point2: FGVec2) -> Self {
|
||||||
Self {
|
Self { point1, point2 }
|
||||||
point1, point2
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -41,7 +39,8 @@ impl FGSegment2d {
|
|||||||
/// Panics if a valid direction could not be computed, for example when the endpoints are coincident, NaN, or infinite.
|
/// Panics if a valid direction could not be computed, for example when the endpoints are coincident, NaN, or infinite.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn direction(&self) -> FGVec2 {
|
pub fn direction(&self) -> FGVec2 {
|
||||||
self.try_direction().expect("Failed to compute the direction of a line segment")
|
self.try_direction()
|
||||||
|
.expect("Failed to compute the direction of a line segment")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to compute the normalized direction pointing from the first endpoint to the second endpoint.
|
/// Try to compute the normalized direction pointing from the first endpoint to the second endpoint.
|
||||||
@@ -100,7 +99,10 @@ impl FGSegment2d {
|
|||||||
///
|
///
|
||||||
/// Panics if a valid normal could not be computed, for example when the endpoints are coincident
|
/// Panics if a valid normal could not be computed, for example when the endpoints are coincident
|
||||||
pub fn left_normal(&self) -> FGVec2 {
|
pub fn left_normal(&self) -> FGVec2 {
|
||||||
self.point1.direction_to(self.point2).map(|o| { FGVec2::new(-o.y, o.x)}).expect("a valid normal could not be computed")
|
self.point1
|
||||||
|
.direction_to(self.point2)
|
||||||
|
.map(|o| FGVec2::new(-o.y, o.x))
|
||||||
|
.expect("a valid normal could not be computed")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn segment_intersection(&self, rhs: &FGSegment2d) -> Option<FGVec2> {
|
pub fn segment_intersection(&self, rhs: &FGSegment2d) -> Option<FGVec2> {
|
||||||
@@ -150,9 +152,18 @@ mod tests {
|
|||||||
fn closest_point_projects_and_clamps_to_segment() {
|
fn closest_point_projects_and_clamps_to_segment() {
|
||||||
let segment = FGSegment2d::new(FGVec2::lit("-4", "0"), FGVec2::lit("4", "0"));
|
let segment = FGSegment2d::new(FGVec2::lit("-4", "0"), FGVec2::lit("4", "0"));
|
||||||
|
|
||||||
assert_eq!(segment.closest_point(FGVec2::lit("2", "1")), FGVec2::lit("2", "0"));
|
assert_eq!(
|
||||||
assert_eq!(segment.closest_point(FGVec2::lit("-6", "1")), segment.point1());
|
segment.closest_point(FGVec2::lit("2", "1")),
|
||||||
assert_eq!(segment.closest_point(FGVec2::lit("6", "1")), segment.point2());
|
FGVec2::lit("2", "0")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
segment.closest_point(FGVec2::lit("-6", "1")),
|
||||||
|
segment.point1()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
segment.closest_point(FGVec2::lit("6", "1")),
|
||||||
|
segment.point2()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
+29
-10
@@ -2,7 +2,7 @@ use bevy::math::Vec2;
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use fixed::types::I32F32;
|
use fixed::types::I32F32;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::ops::{AddAssign, Add, Div, Mul, Sub};
|
use std::ops::{Add, AddAssign, Div, Mul, Sub};
|
||||||
|
|
||||||
use super::int::{FGWide, FGi32};
|
use super::int::{FGWide, FGi32};
|
||||||
|
|
||||||
@@ -29,7 +29,10 @@ impl FGVec2 {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub const fn lit(x: &str, y: &str) -> Self {
|
pub const fn lit(x: &str, y: &str) -> Self {
|
||||||
Self { x: FGi32::lit(x), y: FGi32::lit(y) }
|
Self {
|
||||||
|
x: FGi32::lit(x),
|
||||||
|
y: FGi32::lit(y),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@@ -213,7 +216,7 @@ impl AddAssign for FGVec2 {
|
|||||||
fn add_assign(&mut self, rhs: Self) {
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
*self = Self {
|
*self = Self {
|
||||||
x: self.x + rhs.x,
|
x: self.x + rhs.x,
|
||||||
y: self.y + rhs.y
|
y: self.y + rhs.y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,8 +254,12 @@ mod is_normalized_tests {
|
|||||||
let x = mag * theta.cos();
|
let x = mag * theta.cos();
|
||||||
let y = mag * theta.sin();
|
let y = mag * theta.sin();
|
||||||
|
|
||||||
let Some(fx) = FGi32::checked_from_num(x) else { continue };
|
let Some(fx) = FGi32::checked_from_num(x) else {
|
||||||
let Some(fy) = FGi32::checked_from_num(y) else { continue };
|
continue;
|
||||||
|
};
|
||||||
|
let Some(fy) = FGi32::checked_from_num(y) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
let v = FGVec2 { x: fx, y: fy };
|
let v = FGVec2 { x: fx, y: fy };
|
||||||
|
|
||||||
@@ -301,24 +308,36 @@ mod is_normalized_tests {
|
|||||||
for &mag in &[0.01, 1.0, 100.0, 10000.0] {
|
for &mag in &[0.01, 1.0, 100.0, 10000.0] {
|
||||||
let x = mag * theta.cos();
|
let x = mag * theta.cos();
|
||||||
let y = mag * theta.sin();
|
let y = mag * theta.sin();
|
||||||
let Some(fx) = FGi32::checked_from_num(x) else { continue };
|
let Some(fx) = FGi32::checked_from_num(x) else {
|
||||||
let Some(fy) = FGi32::checked_from_num(y) else { continue };
|
continue;
|
||||||
|
};
|
||||||
|
let Some(fy) = FGi32::checked_from_num(y) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
let v = FGVec2 { x: fx, y: fy };
|
let v = FGVec2 { x: fx, y: fy };
|
||||||
|
|
||||||
if let Some(normalized) = v.normalize() {
|
if let Some(normalized) = v.normalize() {
|
||||||
assert!(
|
assert!(
|
||||||
normalized.is_normalized(),
|
normalized.is_normalized(),
|
||||||
"normalized({}, {}) failed is_normalized(): length_squared = {:?}",
|
"normalized({}, {}) failed is_normalized(): length_squared = {:?}",
|
||||||
x, y, normalized.length_squared()
|
x,
|
||||||
|
y,
|
||||||
|
normalized.length_squared()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let non_unit = FGVec2 { x: FGi32::from_num(2.0), y: FGi32::from_num(0.0) };
|
let non_unit = FGVec2 {
|
||||||
|
x: FGi32::from_num(2.0),
|
||||||
|
y: FGi32::from_num(0.0),
|
||||||
|
};
|
||||||
assert!(!non_unit.is_normalized());
|
assert!(!non_unit.is_normalized());
|
||||||
|
|
||||||
let non_unit_small = FGVec2 { x: FGi32::from_num(0.5), y: FGi32::from_num(0.0) };
|
let non_unit_small = FGVec2 {
|
||||||
|
x: FGi32::from_num(0.5),
|
||||||
|
y: FGi32::from_num(0.0),
|
||||||
|
};
|
||||||
assert!(!non_unit_small.is_normalized());
|
assert!(!non_unit_small.is_normalized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ use bevy_ggrs::prelude::*;
|
|||||||
|
|
||||||
use crate::netcode::GGRSCfg;
|
use crate::netcode::GGRSCfg;
|
||||||
|
|
||||||
pub fn network_debug(
|
pub fn network_debug(mut contexts: EguiContexts, session: Option<Res<Session<GGRSCfg>>>) -> Result {
|
||||||
mut contexts: EguiContexts,
|
|
||||||
session: Option<Res<Session<GGRSCfg>>>,
|
|
||||||
) -> Result {
|
|
||||||
if let Some(sess) = session {
|
if let Some(sess) = session {
|
||||||
match sess.as_ref() {
|
match sess.as_ref() {
|
||||||
Session::P2P(s) => {
|
Session::P2P(s) => {
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ impl Plugin for FighterNetcodePlugin {
|
|||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
let plugin = GgrsPlugin::<GGRSCfg>::default();
|
let plugin = GgrsPlugin::<GGRSCfg>::default();
|
||||||
app.add_plugins(plugin)
|
app.add_plugins(plugin)
|
||||||
.add_systems(Startup, session::netcode_setup)
|
|
||||||
// Engine-level components that every rolled-back entity may carry.
|
// Engine-level components that every rolled-back entity may carry.
|
||||||
// Gameplay components are registered by the plugin that owns them.
|
// Gameplay components are registered by the plugin that owns them.
|
||||||
.rollback_component_with_clone::<Transform>()
|
.rollback_component_with_clone::<Transform>()
|
||||||
|
|||||||
@@ -6,31 +6,32 @@ use bevy_ggrs::{ggrs::UdpNonBlockingSocket, prelude::*};
|
|||||||
use crate::args::Args;
|
use crate::args::Args;
|
||||||
use crate::netcode::GGRSCfg;
|
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()
|
let mut sess_build = SessionBuilder::<GGRSCfg>::new()
|
||||||
.with_num_players(args.players)?
|
.with_num_players(player_count)?
|
||||||
.with_check_distance(args.check_distance)
|
.with_check_distance(args.check_distance)
|
||||||
.with_input_delay(args.input_delay); // (optional) set input delay for the local player
|
.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)?;
|
sess_build = sess_build.add_player(PlayerType::Local, i)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.synctest {
|
if args.synctest {
|
||||||
println!("Start synctest!");
|
println!("Start synctest!");
|
||||||
let sess = sess_build.start_synctest_session()?;
|
let sess = sess_build.start_synctest_session()?;
|
||||||
commands.insert_resource(Session::SyncTest(sess));
|
Ok(Session::SyncTest(sess))
|
||||||
} else {
|
} else {
|
||||||
println!("Start p2p!");
|
println!("Start p2p!");
|
||||||
let socket = UdpNonBlockingSocket::bind_to_port(6969)?;
|
let socket = UdpNonBlockingSocket::bind_to_port(6969)?;
|
||||||
let sess = sess_build.start_p2p_session(socket)?;
|
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() {
|
match session.as_mut() {
|
||||||
Session::P2P(s) => {
|
Session::P2P(s) => {
|
||||||
for event in s.events() {
|
for event in s.events() {
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ pub enum GameplaySet {
|
|||||||
Physics,
|
Physics,
|
||||||
/// Resolve the integrated positions against the stage.
|
/// Resolve the integrated positions against the stage.
|
||||||
Collision,
|
Collision,
|
||||||
Animation
|
Animation,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Declares the order of [`GameplaySet`] inside [`GgrsSchedule`]. Added by
|
/// Declares the order of [`GameplaySet`] inside [`GgrsSchedule`]. Added by
|
||||||
|
|||||||
@@ -14,6 +14,5 @@ pub fn debug_draw_scene(mut gizmos: Gizmos, stage_collision: Res<StageCollision>
|
|||||||
let midpoint = (from_3d + end_3d) * 0.5;
|
let midpoint = (from_3d + end_3d) * 0.5;
|
||||||
gizmos.arrow(midpoint, midpoint + normal_3d, RED);
|
gizmos.arrow(midpoint, midpoint + normal_3d, RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-36
@@ -4,51 +4,52 @@ use std::default;
|
|||||||
|
|
||||||
use bevy::{math::InvalidDirectionError, prelude::*};
|
use bevy::{math::InvalidDirectionError, prelude::*};
|
||||||
|
|
||||||
use crate::math::{segment::{FGSegment2d}, vec::FGVec2};
|
use crate::math::{segment::FGSegment2d, vec::FGVec2};
|
||||||
|
|
||||||
#[derive(Reflect, Clone, Copy, PartialEq)]
|
#[derive(Reflect, Clone, Copy, PartialEq)]
|
||||||
pub enum StagePolyLineSegmentType {
|
pub enum StagePolyLineSegmentType {
|
||||||
Floor, Wall, Ceiling
|
Floor,
|
||||||
|
Wall,
|
||||||
|
Ceiling,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Reflect, Clone)]
|
#[derive(Reflect, Clone)]
|
||||||
pub struct StagePolyLineSegment {
|
pub struct StagePolyLineSegment {
|
||||||
pub segment: FGSegment2d,
|
pub segment: FGSegment2d,
|
||||||
pub normal: FGVec2,
|
pub normal: FGVec2,
|
||||||
pub segment_type: StagePolyLineSegmentType
|
pub segment_type: StagePolyLineSegmentType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Reflect, Clone, Default)]
|
#[derive(Reflect, Clone, Default)]
|
||||||
pub enum StagePolyType {
|
pub enum StagePolyType {
|
||||||
#[default]
|
#[default]
|
||||||
Closed,
|
Closed,
|
||||||
Platform
|
Platform,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Reflect, Hash, Debug, Clone, Copy, Default)]
|
#[derive(Reflect, Hash, Debug, Clone, Copy, Default)]
|
||||||
pub struct StageLineID {
|
pub struct StageLineID {
|
||||||
pub polygon: usize,
|
pub polygon: usize,
|
||||||
pub segment: usize
|
pub segment: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Reflect, Clone, Default)]
|
#[derive(Component, Reflect, Clone, Default)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct StagePoly {
|
pub struct StagePoly {
|
||||||
poly_type: StagePolyType,
|
poly_type: StagePolyType,
|
||||||
pub segments: Vec<StagePolyLineSegment>
|
pub segments: Vec<StagePolyLineSegment>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StagePlaneIntersectResult {
|
pub struct StagePlaneIntersectResult {
|
||||||
pub position: FGVec2,
|
pub position: FGVec2,
|
||||||
pub segment_idx: usize,
|
pub segment_idx: usize,
|
||||||
pub normal: FGVec2
|
pub normal: FGVec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource, Reflect, Clone, Default)]
|
#[derive(Resource, Reflect, Clone, Default)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
pub struct StageCollision {
|
pub struct StageCollision {
|
||||||
pub stage_polys: Vec<StagePoly>
|
pub stage_polys: Vec<StagePoly>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StagePoly {
|
impl StagePoly {
|
||||||
@@ -134,20 +135,22 @@ impl StagePoly {
|
|||||||
.zip(points.iter().cycle().skip(1))
|
.zip(points.iter().cycle().skip(1))
|
||||||
.take(segment_count);
|
.take(segment_count);
|
||||||
|
|
||||||
let segments = windows.map(|segment_window| {
|
let segments = windows
|
||||||
let (first_point, segment_type) = segment_window.0;
|
.map(|segment_window| {
|
||||||
let (second_point, _) = segment_window.1;
|
let (first_point, segment_type) = segment_window.0;
|
||||||
let segment = FGSegment2d::new(*first_point, *second_point);
|
let (second_point, _) = segment_window.1;
|
||||||
StagePolyLineSegment {
|
let segment = FGSegment2d::new(*first_point, *second_point);
|
||||||
segment_type: *segment_type,
|
StagePolyLineSegment {
|
||||||
segment,
|
segment_type: *segment_type,
|
||||||
normal: segment.left_normal()
|
segment,
|
||||||
}
|
normal: segment.left_normal(),
|
||||||
}).collect();
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
poly_type,
|
poly_type,
|
||||||
segments
|
segments,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +208,10 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let hit = stage_poly
|
let hit = stage_poly
|
||||||
.intersect_ray(FGSegment2d::new(FGVec2::lit("0", "2"), FGVec2::lit("0", "-1")))
|
.intersect_ray(FGSegment2d::new(
|
||||||
|
FGVec2::lit("0", "2"),
|
||||||
|
FGVec2::lit("0", "-1"),
|
||||||
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(hit.segment_idx, 1);
|
assert_eq!(hit.segment_idx, 1);
|
||||||
@@ -214,35 +220,53 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ray_intersection_test() {
|
fn ray_intersection_test() {
|
||||||
let stage_poly = StagePoly::build(crate::stage::line::StagePolyType::Platform, &[
|
let stage_poly = StagePoly::build(
|
||||||
(FGVec2::lit("-4.5", "0.0"), StagePolyLineSegmentType::Floor),
|
crate::stage::line::StagePolyType::Platform,
|
||||||
(FGVec2::lit("4.5", "0.0"), StagePolyLineSegmentType::Floor),
|
&[
|
||||||
]);
|
(FGVec2::lit("-4.5", "0.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
(FGVec2::lit("4.5", "0.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let res = stage_poly.intersect_ray(FGSegment2d::new(FGVec2::lit("0.0", "1.0"), FGVec2::lit("0.0", "-1.0")));
|
let res = stage_poly.intersect_ray(FGSegment2d::new(
|
||||||
|
FGVec2::lit("0.0", "1.0"),
|
||||||
|
FGVec2::lit("0.0", "-1.0"),
|
||||||
|
));
|
||||||
assert!(res.is_some());
|
assert!(res.is_some());
|
||||||
assert_eq!(res.unwrap().position, FGVec2::ZERO);
|
assert_eq!(res.unwrap().position, FGVec2::ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ray_intersection_test_side() {
|
fn ray_intersection_test_side() {
|
||||||
let stage_poly = StagePoly::build(crate::stage::line::StagePolyType::Platform, &[
|
let stage_poly = StagePoly::build(
|
||||||
(FGVec2::lit("-4.5", "0.0"), StagePolyLineSegmentType::Floor),
|
crate::stage::line::StagePolyType::Platform,
|
||||||
(FGVec2::lit("4.5", "0.0"), StagePolyLineSegmentType::Floor),
|
&[
|
||||||
]);
|
(FGVec2::lit("-4.5", "0.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
(FGVec2::lit("4.5", "0.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let res = stage_poly.intersect_ray(FGSegment2d::new(FGVec2::lit("2.0", "1.0"), FGVec2::lit("2.0", "-1.0")));
|
let res = stage_poly.intersect_ray(FGSegment2d::new(
|
||||||
|
FGVec2::lit("2.0", "1.0"),
|
||||||
|
FGVec2::lit("2.0", "-1.0"),
|
||||||
|
));
|
||||||
assert!(res.is_some());
|
assert!(res.is_some());
|
||||||
assert!(res.unwrap().position.distance(FGVec2::lit("2.0", "0.0")) < FGi32::from_bits(4));
|
assert!(res.unwrap().position.distance(FGVec2::lit("2.0", "0.0")) < FGi32::from_bits(4));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn ray_intersection_test_diagonal() {
|
fn ray_intersection_test_diagonal() {
|
||||||
let stage_poly = StagePoly::build(crate::stage::line::StagePolyType::Platform, &[
|
let stage_poly = StagePoly::build(
|
||||||
(FGVec2::lit("0.0", "0.0"), StagePolyLineSegmentType::Floor),
|
crate::stage::line::StagePolyType::Platform,
|
||||||
(FGVec2::lit("2.0", "2.0"), StagePolyLineSegmentType::Floor),
|
&[
|
||||||
]);
|
(FGVec2::lit("0.0", "0.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
(FGVec2::lit("2.0", "2.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let res = stage_poly.intersect_ray(FGSegment2d::new(FGVec2::lit("1.0", "2.0"), FGVec2::lit("1.0", "-2.0")));
|
let res = stage_poly.intersect_ray(FGSegment2d::new(
|
||||||
|
FGVec2::lit("1.0", "2.0"),
|
||||||
|
FGVec2::lit("1.0", "-2.0"),
|
||||||
|
));
|
||||||
assert!(res.is_some());
|
assert!(res.is_some());
|
||||||
assert_eq!(res.unwrap().position, FGVec2::lit("1.0", "1.0"));
|
assert_eq!(res.unwrap().position, FGVec2::lit("1.0", "1.0"));
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -7,7 +7,7 @@ pub mod debug;
|
|||||||
pub mod line;
|
pub mod line;
|
||||||
pub mod scene;
|
pub mod scene;
|
||||||
|
|
||||||
pub use line::{StagePoly, StagePlaneIntersectResult};
|
pub use line::{StagePlaneIntersectResult, StagePoly};
|
||||||
|
|
||||||
/// Owns the stage geometry: which scene gets spawned and how it is drawn.
|
/// Owns the stage geometry: which scene gets spawned and how it is drawn.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -15,7 +15,14 @@ pub struct StagePlugin;
|
|||||||
|
|
||||||
impl Plugin for StagePlugin {
|
impl Plugin for StagePlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, scene::test_scene.spawn())
|
app.add_systems(
|
||||||
.add_systems(Update, debug::debug_draw_scene);
|
Update,
|
||||||
|
debug::debug_draw_scene.run_if(resource_exists::<line::StageCollision>),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn spawn_stage(commands: &mut Commands, match_root: Entity, visual: Handle<WorldAsset>) {
|
||||||
|
commands.entity(match_root).insert(WorldAssetRoot(visual));
|
||||||
|
scene::spawn_stage_support(commands, match_root);
|
||||||
|
}
|
||||||
|
|||||||
+59
-41
@@ -1,49 +1,67 @@
|
|||||||
//! The scene content that gets spawned at startup.
|
//! Code-defined deterministic stage collision and development lighting.
|
||||||
|
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::{camera_controller::free_camera::FreeCamera, prelude::*};
|
use bevy::{camera_controller::free_camera::FreeCamera, prelude::*};
|
||||||
|
|
||||||
use crate::{math::vec::FGVec2, stage::{StagePoly, line::{StageCollision, StagePolyLineSegmentType}}};
|
use crate::{
|
||||||
|
math::vec::FGVec2,
|
||||||
|
stage::{
|
||||||
|
StagePoly,
|
||||||
|
line::{StageCollision, StagePolyLineSegmentType, StagePolyType},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/// set up a simple 3D scene
|
pub fn spawn_stage_support(commands: &mut Commands, match_root: Entity) {
|
||||||
pub fn test_scene() -> impl SceneList {
|
let stage_poly = StagePoly::build(
|
||||||
|
StagePolyType::Closed,
|
||||||
|
&[
|
||||||
|
(
|
||||||
|
FGVec2::lit("-56.0", "-3.5"),
|
||||||
|
StagePolyLineSegmentType::Floor,
|
||||||
|
),
|
||||||
|
(FGVec2::lit("-39.2", "0.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
(FGVec2::lit("0.0", "0.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
(FGVec2::lit("39.2", "0.0"), StagePolyLineSegmentType::Floor),
|
||||||
|
(FGVec2::lit("56.0", "-3.5"), StagePolyLineSegmentType::Wall),
|
||||||
|
(
|
||||||
|
FGVec2::lit("56.0", "-200.0"),
|
||||||
|
StagePolyLineSegmentType::Ceiling,
|
||||||
|
),
|
||||||
|
(FGVec2::lit("-56", "-200.0"), StagePolyLineSegmentType::Wall),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let stage_poly = StagePoly::build(crate::stage::line::StagePolyType::Closed, &[
|
commands.insert_resource(StageCollision {
|
||||||
(FGVec2::lit("-56.0", "-3.5"), StagePolyLineSegmentType::Floor),
|
stage_polys: vec![stage_poly.clone()],
|
||||||
(FGVec2::lit("-39.2", "0.0"), StagePolyLineSegmentType::Floor),
|
});
|
||||||
(FGVec2::lit("0.0", "0.0"), StagePolyLineSegmentType::Floor),
|
commands.spawn((
|
||||||
(FGVec2::lit("39.2", "0.0"), StagePolyLineSegmentType::Floor),
|
Name::new("Stage Collision"),
|
||||||
(FGVec2::lit("56.0", "-3.5"), StagePolyLineSegmentType::Wall),
|
stage_poly,
|
||||||
(FGVec2::lit("56.0", "-200.0"), StagePolyLineSegmentType::Ceiling),
|
ChildOf(match_root),
|
||||||
(FGVec2::lit("-56", "-200.0"), StagePolyLineSegmentType::Wall)
|
));
|
||||||
]);
|
commands.spawn((
|
||||||
|
DirectionalLight {
|
||||||
bsn_list! [
|
shadow_maps_enabled: true,
|
||||||
(
|
..default()
|
||||||
#StageCollision
|
},
|
||||||
template_value(StageCollision {
|
Transform {
|
||||||
stage_polys: vec!(stage_poly)
|
translation: Vec3::new(0.0, 2.0, 0.0),
|
||||||
})
|
rotation: Quat::from_rotation_x(-PI / 4.0),
|
||||||
),
|
..default()
|
||||||
(
|
},
|
||||||
DirectionalLight {
|
ChildOf(match_root),
|
||||||
shadow_maps_enabled: true,
|
));
|
||||||
}
|
commands.spawn((
|
||||||
Transform {
|
Camera3d::default(),
|
||||||
translation: Vec3::new(0.0, 2.0, 0.0),
|
Transform::from_xyz(0.0, 10.5, 150.0),
|
||||||
rotation: Quat::from_rotation_x(-PI / 4.),
|
/*FreeCamera {
|
||||||
}
|
sensitivity: 0.2,
|
||||||
),
|
friction: 25.0,
|
||||||
(
|
walk_speed: 3.0,
|
||||||
Camera3d
|
run_speed: 9.0,
|
||||||
template_value(Transform::from_xyz(0.0, 1.5, 9.0))
|
..default()
|
||||||
FreeCamera {
|
},*/
|
||||||
sensitivity: 0.2,
|
ChildOf(match_root),
|
||||||
friction: 25.0,
|
));
|
||||||
walk_speed: 3.0,
|
|
||||||
run_speed: 9.0,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user