Skip to content

Commit

Permalink
Add some components to be rolled back
Browse files Browse the repository at this point in the history
  • Loading branch information
haihala committed Sep 9, 2024
1 parent 8528043 commit 08ebcfd
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/input_parsing/src/input_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod parrot_stream;
mod prewritten_stream;
mod test_stream;

pub(crate) use pad_stream::{update_pads, PadStream};
pub use pad_stream::{update_pads, PadStream};
pub use parrot_stream::{update_parrots, ParrotStream};
pub use prewritten_stream::PreWrittenStream;
pub use test_stream::TestStream;
Expand Down
4 changes: 2 additions & 2 deletions client/input_parsing/src/input_stream/pad_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::helper_types::{Diff, InputEvent};

use super::{InputStream, ParrotStream};

#[derive(Default, Component)]
#[derive(Default, Component, Clone)]
pub struct PadStream {
next_read: Vec<InputEvent>,
stick_position: IVec2,
Expand Down Expand Up @@ -76,7 +76,7 @@ impl InputStream for PadStream {
}
}

pub(crate) fn update_pads(
pub fn update_pads(
mut gamepad_events: EventReader<WagInputEvent>,
mut readers: Query<(&mut PadStream, &mut ParrotStream, &Player)>,
controllers: Res<Controllers>,
Expand Down
3 changes: 2 additions & 1 deletion client/input_parsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ mod motion_input;

pub use helper_types::InputEvent;
pub use input_parser::InputParser;
pub use input_stream::PadStream;

use input_stream::{update_pads, update_parrots, PadStream, ParrotStream};
use input_stream::{update_pads, update_parrots, ParrotStream};

const MAX_SECONDS_BETWEEN_SUBSEQUENT_MOTIONS: f32 = 0.2; // In seconds

Expand Down
2 changes: 1 addition & 1 deletion client/lib/src/damage/defense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const REWARD_FLOOR: i32 = 5;
const REWARD_RAMP: i32 = 3;
const TIME_UNTIL_RESET: usize = (wag_core::FPS * 1.0) as usize;

#[derive(Debug, Default, Component)]
#[derive(Debug, Default, Component, Clone, Copy)]
pub struct Defense {
streak: i32,
streak_last_event: Option<usize>,
Expand Down
20 changes: 17 additions & 3 deletions client/lib/src/networking.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use bevy::{input::gamepad::GamepadEvent, prelude::*, utils::HashMap};
use bevy_ggrs::*;
use bevy_matchbox::prelude::*;
use characters::WAGResources;
use input_parsing::{InputParser, PadStream};
use player_state::PlayerState;
use wag_core::{
Characters, Controllers, GameState, LocalCharacter, LocalController, OnlineState,
RollbackSchedule, WagInputButton, WagInputEvent,
Characters, Clock, Controllers, Facing, GameState, LocalCharacter, LocalController,
OnlineState, RollbackSchedule, WagInputButton, WagInputEvent,
};

use crate::{damage::Defense, movement::PlayerVelocity};

type Config = bevy_ggrs::GgrsConfig<u16, PeerId>;

pub struct NetworkPlugin;
Expand Down Expand Up @@ -33,7 +38,16 @@ impl Plugin for NetworkPlugin {
.run_if(|session: Option<Res<bevy_ggrs::Session<Config>>>| session.is_none()),
)
.add_plugins(GgrsPlugin::<Config>::default())
.rollback_component_with_clone::<Transform>();
// Probably an incomplete list of things to roll back
.rollback_resource_with_copy::<Clock>()
.rollback_component_with_clone::<PlayerState>()
.rollback_component_with_clone::<PadStream>()
.rollback_component_with_clone::<InputParser>()
.rollback_component_with_clone::<WAGResources>()
.rollback_component_with_clone::<PlayerVelocity>()
.rollback_component_with_copy::<Defense>()
.rollback_component_with_copy::<Facing>()
.rollback_component_with_copy::<Transform>();
}
}

Expand Down
6 changes: 3 additions & 3 deletions client/lib/src/player_state_management/move_activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use wag_core::{ActionId, Clock, Facing, Player, Stats};

use crate::{movement::PlayerVelocity, ui::Notifications};

#[derive(Debug, Default, Reflect)]
#[derive(Debug, Default, Reflect, Clone, Copy)]
pub(super) struct MoveActivation {
pub kind: ActivationType,
pub id: ActionId,
}

#[derive(Debug, Default, Reflect)]
#[derive(Debug, Default, Reflect, Clone, Copy)]
pub(super) enum ActivationType {
Continuation,
#[default]
Expand All @@ -25,7 +25,7 @@ pub(super) enum ActivationType {

const AUTOCORRECT: usize = (0.1 * wag_core::FPS) as usize;

#[derive(Debug, Default, Component, Reflect)]
#[derive(Debug, Default, Component, Reflect, Clone)]
pub struct MoveBuffer {
buffer: Vec<(usize, ActionId)>,
activation: Option<MoveActivation>,
Expand Down
2 changes: 1 addition & 1 deletion client/wag_core/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const COMBAT_DURATION: f32 = 99.0;
pub const POST_ROUND_DURATION: f32 = 4.0;
pub const POST_SHOP_DURATION: f32 = 11.0;

#[derive(Reflect, Resource, Debug)]
#[derive(Reflect, Resource, Debug, Clone, Copy)]
pub struct Clock {
pub frame: usize,
start_time: f32,
Expand Down

0 comments on commit 08ebcfd

Please sign in to comment.