Skip to content

Commit

Permalink
chore: update Rust version and fix clippy warnings. (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag authored Sep 8, 2024
1 parent 2106f95 commit 870b47d
Show file tree
Hide file tree
Showing 17 changed files with 554 additions and 484 deletions.
969 changes: 528 additions & 441 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ authors = ["The Fish Folk & Spicy Lobster Developers"]
categories = ["game-development", "game-engines", "wasm", "data-structures"]
keywords = ["bones", "bevy", "scripting", "ecs", "framework"]

[workspace.lints.clippy]
correctness = "warn"

[profile.release]
lto = true
17 changes: 0 additions & 17 deletions framework_crates/bones_asset/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ use serde::Deserialize;

use crate::prelude::*;

/// Deserializeable struct for schema files.
///
/// This struct is required because you can't use `serde(with = "..")` directly on the [`Schema`]
/// enum to make it use nested struct syntax instead of YAML tags for enum representation. Avoiding
/// tags is necessary because we use nested enums such as `vec: primitive: string`.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub struct SchemaFile {
/// The schema defined in the file
#[cfg_attr(
feature = "serde",
serde(with = "serde_yaml::with::singleton_map_recursive")
)]
#[cfg_attr(feature = "serde", serde(flatten))]
pub schema: Schema,
}

impl FromStr for AssetPackReq {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand Down
4 changes: 2 additions & 2 deletions framework_crates/bones_asset/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ impl AssetServer {
if T::schema() == <SchemaBox as HasSchema>::schema() {
// SOUND: the above comparison verifies that T is concretely a SchemaBox so &Schemabox
// is the same as &T.
Some(unsafe { std::mem::transmute(asset) })
Some(unsafe { std::mem::transmute::<&SchemaBox, &T>(asset) })
} else {
asset.try_cast_ref().ok()
}
Expand Down Expand Up @@ -964,7 +964,7 @@ impl AssetServer {
if T::schema() == <SchemaBox as HasSchema>::schema() {
// SOUND: the above comparison verifies that T is concretely a SchemaBox so &mut Schemabox
// is the same as &mut T.
unsafe { std::mem::transmute(asset) }
unsafe { std::mem::transmute::<&mut SchemaBox, &mut T>(asset) }
} else {
asset.cast_mut()
}
Expand Down
5 changes: 5 additions & 0 deletions framework_crates/bones_framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ image_ico = ["image/ico"]
## Enable BMP image loader.
image_bmp = ["image/bmp"]

#! ### Debuging Features

## Simulate dramatic network latency by inserting random sleeps into the networking code. This is extremely cheap and hacky but may be useful.
debug-network-slowdown = []

document-features = ["dep:document-features"]

[dependencies]
Expand Down
6 changes: 0 additions & 6 deletions framework_crates/bones_framework/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ pub struct AnimatedSprite {
pub repeat: bool,
}

#[cfg(feature = "serde")]
fn default_true() -> bool {
true
}

/// Component that may be added to an [`AtlasSprite`] to control which animation, out of a set of
/// animations, is playing.
///
Expand All @@ -45,7 +40,6 @@ pub struct AnimationBankSprite {
/// The collection of animations in this animation bank.
// TODO: Put Animation Frames in an `Arc` to Avoid Snapshot Clone Cost.
pub animations: SMap<Ustr, AnimatedSprite>,
#[cfg_attr(feature = "serde", serde(default))]
/// The last animation that was playing.
pub last_animation: Ustr,
}
Expand Down
4 changes: 2 additions & 2 deletions framework_crates/bones_framework/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn frame_diagnostic_window(
state.reset();
}

ui.monospace(&format!(
ui.monospace(format!(
"{label:20}: {fps:4.0}{suffix:3} ( {min:4.0}{suffix:3}, {avg:4.0}{suffix:3}, {max:4.0}{suffix:3} )",
// label = localization.get("frames-per-second"),
label = "Frames Per Second",
Expand All @@ -90,7 +90,7 @@ pub fn frame_diagnostic_window(
avg = state.fps_avg,
max = state.max_fps,
));
ui.monospace(&format!(
ui.monospace(format!(
"{label:20}: {fps:4.1}{suffix:3} ( {min:4.1}{suffix:3}, {avg:4.0}{suffix:3}, {max:4.1}{suffix:3} )",
// label = localization.get("frame-time"),
label = "Frame Time",
Expand Down
6 changes: 3 additions & 3 deletions framework_crates/bones_framework/src/networking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub struct NetworkMatchSocket(Arc<dyn NetworkSocket>);

/// Wraps [`ggrs::Message`] with included `match_id`, used to determine if message received
/// from current match.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GameMessage {
/// Socket match id
pub match_id: u8,
Expand Down Expand Up @@ -575,8 +575,8 @@ where
// to integer so our computed timestep will match that of ggrs.
let network_fps = (simulation_fps * NETWORK_FRAME_RATE_FACTOR) as f64;
let network_fps = network_fps
.max(std::usize::MIN as f64)
.min(std::usize::MAX as f64)
.max(usize::MIN as f64)
.min(usize::MAX as f64)
.round() as usize;

// There may be value in dynamically negotitaing these values based on client's pings
Expand Down
5 changes: 2 additions & 3 deletions framework_crates/bones_framework/src/networking/online.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ When a client connects to the matchmaking server, the very first thing it will d
[`RequestMatch`][crate::external::bones_matchmaker_proto::MatchmakerRequest::RequestMatch] message
to the server over a reliable channel.

This message contains the [`MatchInfo`][crate::external::bones_matchmaker_proto::MatchInfo] that
tells the server how many players the client wants to connect to for the match, along with an
arbitrary byte sequence for the `match_data`.
This message contains the [`MatchInfo`] that tells the server how many players the client wants to
connect to for the match, along with an arbitrary byte sequence for the `match_data`.

In order for players to end up in the same match as each-other, they must specify the _exact_ same
`MatchInfo`, including the `match_data`. We use the `match_data` as a way to specify which game mode
Expand Down
1 change: 0 additions & 1 deletion framework_crates/bones_framework/src/networking/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use super::{GameMessage, NetworkSocket, SocketTarget, RUNTIME};
/// The [`NetworkSocket`] implementation.
#[derive(Debug, Clone)]
pub struct Socket {
///
pub connections: Vec<(u32, iroh_quinn::Connection)>,
pub ggrs_receiver: async_channel::Receiver<(u32, GameMessage)>,
pub reliable_receiver: async_channel::Receiver<(u32, Vec<u8>)>,
Expand Down
2 changes: 1 addition & 1 deletion framework_crates/bones_framework/src/render/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl CameraShake {
decay_rate: f32,
) -> Self {
let mut shake = Self::new(max_angle_deg, max_offset, speed, decay_rate);
shake.trauma = trauma.min(1.0).max(0.0);
shake.trauma = trauma.clamp(0.0, 1.0);
shake
}

Expand Down
3 changes: 1 addition & 2 deletions framework_crates/bones_framework/src/time/stopwatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use std::time::Duration;
/// assert!(stopwatch.paused());
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
/// ```
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Stopwatch {
paused: bool,
elapsed: Duration,
Expand Down
5 changes: 3 additions & 2 deletions framework_crates/bones_framework/src/time/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,9 @@ impl Timer {
}

/// Specifies [`Timer`] behavior.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
#[derive(
Debug, Clone, Copy, Eq, PartialEq, Hash, Default, serde::Deserialize, serde::Serialize,
)]
pub enum TimerMode {
/// Run once and stop.
#[default]
Expand Down
2 changes: 1 addition & 1 deletion framework_crates/bones_schema/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ macro_rules! throw {
///
/// ## derive_type_data attribute
/// This attribute is simply a shortcut equivalent to using the type_data attribute
/// with any type's FromType<YourHasSchemaType> implementation like so:
/// with any type's `FromType<YourHasSchemaType>` implementation like so:
/// ```ignore
/// #[derive(HasSchema, Clone, Default)]
/// #[type_data(<OtherType as FromType<Data>>::from_type())]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn metatable(ctx: Context) -> Table {
Callback::from_fn(&ctx, move |ctx, _fuel, mut stack| {
let this: UserData = stack.consume(ctx)?;
let this = this.downcast_static::<&Schema>()?;
let s = piccolo::String::from_slice(&ctx, &format!("Schema({})", this.full_name));
let s = piccolo::String::from_slice(&ctx, format!("Schema({})", this.full_name));

stack.push_front(Value::String(s));
Ok(CallbackReturn::Return)
Expand Down
2 changes: 1 addition & 1 deletion other_crates/bones_matchmaker/src/matchmaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async fn impl_matchmaker(ep: iroh_net::Endpoint, conn: Connection) -> anyhow::Re
let random_seed = rand::random();

for (idx, conn) in members_to_join.iter().enumerate() {
let id = get_remote_node_id(&conn)?;
let id = get_remote_node_id(conn)?;
let mut addr = NodeAddr::new(id);
if let Some(info) = ep.connection_info(id) {
if let Some(relay_url) = info.relay_url {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.76"
channel = "1.81"

0 comments on commit 870b47d

Please sign in to comment.