Skip to content

Commit

Permalink
Ignore ball rot in packets
Browse files Browse the repository at this point in the history
On-by-default option that's toggleable
  • Loading branch information
VirxEC committed May 19, 2024
1 parent d6768d6 commit aa12121
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
version = "0.7.2"
version = "0.7.3"
name = "rlviser"
edition = "2021"
publish = false
Expand Down
22 changes: 22 additions & 0 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl Plugin for DebugOverlayPlugin {
.insert_resource(PacketSendTime::default())
.insert_resource(RenderInfo::default())
.insert_resource(UpdateRenderInfoTime::default())
.insert_resource(CalcBallRot::default())
.add_event::<UserSetBallState>()
.add_event::<UserSetCarState>()
.add_event::<UserSetPadState>()
Expand All @@ -120,6 +121,7 @@ impl Plugin for DebugOverlayPlugin {
update_allow_rendering,
update_render_info,
update_interpolation,
update_calc_ball_rot,
update_ball_info.run_if(resource_equals(EnableBallInfo(true))),
update_car_info.run_if(|enable_menu: Res<EnableCarInfo>| !enable_menu.0.is_empty()),
update_boost_pad_info.run_if(|enable_menu: Res<EnablePadInfo>| !enable_menu.0.is_empty()),
Expand All @@ -146,6 +148,16 @@ impl Plugin for DebugOverlayPlugin {
}
}

#[derive(Resource)]
pub struct CalcBallRot(pub bool);

impl Default for CalcBallRot {
#[inline]
fn default() -> Self {
Self(true)
}
}

#[derive(Resource, Default, PartialEq, Eq)]
pub struct EnableBallInfo(bool);

Expand Down Expand Up @@ -776,6 +788,7 @@ struct Options {
mouse_sensitivity: f32,
allow_rendering: bool,
interpolation: bool,
calc_ball_rot: bool,
}

impl Default for Options {
Expand All @@ -800,6 +813,7 @@ impl Default for Options {
mouse_sensitivity: 1.,
allow_rendering: true,
interpolation: false,
calc_ball_rot: true,
}
}
}
Expand Down Expand Up @@ -846,6 +860,7 @@ impl Options {
"mouse_sensitivity" => options.mouse_sensitivity = value.parse().unwrap(),
"allow_rendering" => options.allow_rendering = value.parse().unwrap(),
"interpolation" => options.interpolation = value.parse().unwrap(),
"calc_ball_rot" => options.calc_ball_rot = value.parse().unwrap(),
_ => println!("Unknown key {key} with value {value}"),
}
}
Expand Down Expand Up @@ -883,6 +898,7 @@ impl Options {
file.write_fmt(format_args!("mouse_sensitivity={}\n", self.mouse_sensitivity))?;
file.write_fmt(format_args!("allow_rendering={}\n", self.allow_rendering))?;
file.write_fmt(format_args!("interpolation={}\n", self.interpolation))?;
file.write_fmt(format_args!("calc_ball_rot={}\n", self.calc_ball_rot))?;

Ok(())
}
Expand All @@ -907,6 +923,7 @@ impl Options {
|| self.mouse_sensitivity != other.mouse_sensitivity
|| self.allow_rendering != other.allow_rendering
|| self.interpolation != other.interpolation
|| self.calc_ball_rot != other.calc_ball_rot
}
}

Expand Down Expand Up @@ -1022,6 +1039,7 @@ fn ui_system(
});

ui.checkbox(&mut options.interpolation, "Packet Interpolation");
ui.checkbox(&mut options.calc_ball_rot, "Ignore packet ball rotation");

ui.menu_button("Open rendering manager", |ui| {
ui.checkbox(&mut options.allow_rendering, "Allow rendering");
Expand Down Expand Up @@ -1152,6 +1170,10 @@ fn toggle_vsync(options: Res<Options>, mut framepace: ResMut<FramepaceSettings>)
};
}

fn update_calc_ball_rot(options: Res<Options>, mut calc_ball_rot: ResMut<CalcBallRot>) {
calc_ball_rot.0 = options.calc_ball_rot;
}

#[cfg(not(feature = "ssao"))]
fn update_msaa(options: Res<Options>, mut msaa: ResMut<Msaa>) {
const MSAA_SAMPLES: [u32; 4] = [1, 2, 4, 8];
Expand Down
48 changes: 40 additions & 8 deletions src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
assets::{get_material, get_mesh_info, BoostPickupGlows, CarWheelMesh},
bytes::{FromBytes, ToBytes, ToBytesExact},
camera::{BoostAmount, HighlightedEntity, PrimaryCamera, TimeDisplay, BOOST_INDICATOR_FONT_SIZE, BOOST_INDICATOR_POS},
gui::{BallCam, GameSpeed, ShowTime, UiScale, UserCarStates},
gui::{BallCam, CalcBallRot, GameSpeed, ShowTime, UiScale, UserCarStates},
mesh::{BoostPadClicked, CarClicked, ChangeCarPos, LargeBoostPadLocRots},
morton::Morton,
renderer::{RenderGroups, RenderMessage, UdpRendererPlugin},
Expand Down Expand Up @@ -382,6 +382,7 @@ pub struct PausedUpdate(pub bool);
fn handle_udp(
socket: Res<Connection>,
game_speed: Res<GameSpeed>,
calc_ball_rot: Res<CalcBallRot>,
mut game_state: ResMut<GameState>,
mut exit: EventWriter<AppExit>,
mut packet_updated: ResMut<PacketUpdated>,
Expand Down Expand Up @@ -516,7 +517,14 @@ fn handle_udp(
}

packet_updated.0 = true;
*game_state = GameState::from_bytes(&buf);

let mut new_game_state = GameState::from_bytes(&buf);

if calc_ball_rot.0 {
new_game_state.ball.rot_mat = game_state.ball.rot_mat;
};

*game_state = new_game_state;
}

fn update_ball(
Expand Down Expand Up @@ -1103,15 +1111,24 @@ fn update_field(state: Res<GameState>, mut game_mode: ResMut<GameMode>, mut load
}
}

fn interpolate_packet(mut state: ResMut<GameState>, game_speed: Res<GameSpeed>, time: Res<Time>) {
fn update_ball_rotation(
mut state: ResMut<GameState>,
interpolation: Res<Interpolation>,
game_speed: Res<GameSpeed>,
time: Res<Time>,
mut last_game_tick: Local<u64>,
) {
if game_speed.paused {
return;
}

let delta_time = time.delta_seconds() * game_speed.speed;
let delta_time = if interpolation.0 {
time.delta_seconds() * game_speed.speed
} else {
(state.tick_count - *last_game_tick) as f32 / state.tick_rate
};

let ball_pos = state.ball.vel * delta_time;
state.ball.pos += ball_pos;
*last_game_tick = state.tick_count;

let ball_ang_vel = state.ball.ang_vel * delta_time;
let ang_vel = ball_ang_vel.length();
Expand All @@ -1120,6 +1137,17 @@ fn interpolate_packet(mut state: ResMut<GameState>, game_speed: Res<GameSpeed>,
let rot = Mat3A::from_axis_angle(axis.into(), ang_vel);
state.ball.rot_mat = rot * state.ball.rot_mat;
}
}

fn interpolate_packet(mut state: ResMut<GameState>, game_speed: Res<GameSpeed>, time: Res<Time>) {
if game_speed.paused {
return;
}

let delta_time = time.delta_seconds() * game_speed.speed;

let ball_pos = state.ball.vel * delta_time;
state.ball.pos += ball_pos;

for car in state.cars.iter_mut() {
let car_pos = car.state.vel * delta_time;
Expand Down Expand Up @@ -1178,7 +1206,11 @@ impl Plugin for RocketSimPlugin {
handle_udp,
(
(
update_ball,
(
update_ball_rotation.run_if(|calc_ball_rot: Res<CalcBallRot>| calc_ball_rot.0),
update_ball,
)
.chain(),
(
pre_update_car,
(update_car, update_car_extra, update_car_wheels),
Expand All @@ -1190,7 +1222,7 @@ impl Plugin for RocketSimPlugin {
)
.run_if(|updated: Res<PacketUpdated>| updated.0),
(
interpolate_packet,
(interpolate_packet, update_ball_rotation),
(update_ball, (update_car, post_update_car).chain(), update_car_wheels),
)
.chain()
Expand Down

0 comments on commit aa12121

Please sign in to comment.