small fixes for clippy compliance
This commit is contained in:
parent
0e191c617c
commit
88d188a794
@ -32,7 +32,7 @@ use syn::{parse_macro_input, ItemFn};
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// If you need macroquad types not re-exported by turtle_lib:
|
||||
/// If you need macroquad types not re-exported by `turtle_lib`:
|
||||
///
|
||||
/// ```ignore
|
||||
/// use macroquad::prelude::SKYBLUE; // Import specific items
|
||||
|
||||
@ -268,7 +268,7 @@ impl TurtlePlan {
|
||||
///
|
||||
/// Speed controls how fast the turtle moves during animations:
|
||||
/// - Values `>= 1000`: Instant mode - commands execute immediately without animation.
|
||||
/// The bigger the number, the more segments are drawn per frame.
|
||||
/// The bigger the number, the more segments are drawn per frame.
|
||||
/// - Values `< 1000`: Animated mode - turtle moves at specified pixels per second
|
||||
///
|
||||
/// You can dynamically switch between instant and animated modes during execution.
|
||||
|
||||
@ -112,7 +112,7 @@ impl TurtleCommandSender {
|
||||
pub fn send(&self, queue: CommandQueue) -> Result<(), String> {
|
||||
self.tx
|
||||
.send(queue)
|
||||
.map_err(|e| format!("Channel disconnected: {}", e))
|
||||
.map_err(|e| format!("Channel disconnected: {e}"))
|
||||
}
|
||||
|
||||
/// Send commands (non-blocking)
|
||||
@ -137,7 +137,7 @@ impl TurtleCommandSender {
|
||||
pub fn try_send(&self, queue: CommandQueue) -> Result<(), String> {
|
||||
self.tx
|
||||
.try_send(queue)
|
||||
.map_err(|e| format!("Failed to send: {}", e))
|
||||
.map_err(|e| format!("Failed to send: {e}"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,6 +165,7 @@ impl TurtleCommandReceiver {
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn recv_all(&self) -> Vec<CommandQueue> {
|
||||
self.rx.try_iter().collect()
|
||||
}
|
||||
@ -192,14 +193,14 @@ impl TurtleCommandReceiver {
|
||||
///
|
||||
/// The tuple represents (sender, receiver) where:
|
||||
/// - Sender goes to game logic threads (cloneable, can be distributed)
|
||||
/// - Receiver stays in the render thread (part of TurtleApp internally)
|
||||
/// - Receiver stays in the render thread (part of `TurtleApp` internally)
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `turtle_id` - The ID of the turtle this channel is for (must be valid)
|
||||
/// * `buffer_size` - Maximum number of pending command batches before sender blocks
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if buffer_size is 0.
|
||||
/// Panics if `buffer_size` is 0.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```no_run
|
||||
@ -207,9 +208,10 @@ impl TurtleCommandReceiver {
|
||||
/// # fn example() {
|
||||
/// let (tx, _rx) = turtle_command_channel(0, 100);
|
||||
/// // Sender goes to game threads
|
||||
/// // Receiver stays in render thread (or TurtleApp)
|
||||
/// // Receiver stays in render thread (or `TurtleApp`)
|
||||
/// # }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn turtle_command_channel(
|
||||
turtle_id: usize,
|
||||
buffer_size: usize,
|
||||
|
||||
@ -93,7 +93,7 @@ pub fn render_world_with_tweens(world: &TurtleWorld, zoom_level: f32) {
|
||||
}
|
||||
|
||||
// Draw in-progress tween lines for all active tweens
|
||||
for turtle in world.turtles.iter() {
|
||||
for turtle in &world.turtles {
|
||||
if let Some(tween) = turtle.tween_controller.current_tween() {
|
||||
// Only draw if pen is down
|
||||
if tween.start_params.pen_down {
|
||||
@ -132,7 +132,7 @@ pub fn render_world_with_tweens(world: &TurtleWorld, zoom_level: f32) {
|
||||
}
|
||||
|
||||
// Draw live fill preview for all turtles that are currently filling
|
||||
for turtle in world.turtles.iter() {
|
||||
for turtle in &world.turtles {
|
||||
if let Some(ref fill_state) = turtle.filling {
|
||||
// Build all contours: completed contours + current contour with animation
|
||||
let mut all_contours: Vec<Vec<Vec2>> = Vec::new();
|
||||
|
||||
@ -11,6 +11,7 @@ use crate::general::AnimationSpeed;
|
||||
|
||||
/// Execute side effects for commands that don't involve movement
|
||||
/// Returns true if the command was handled (caller should skip movement processing)
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn execute_command_side_effects(command: &TurtleCommand, state: &mut Turtle) -> bool {
|
||||
match command {
|
||||
TurtleCommand::BeginFill => {
|
||||
|
||||
@ -118,7 +118,7 @@ impl TurtleApp {
|
||||
///
|
||||
/// # Returns
|
||||
/// A `TurtleCommandSender` that can be cloned and sent to game logic threads.
|
||||
/// The turtle is automatically managed by TurtleApp.
|
||||
/// The turtle is automatically managed by `TurtleApp`.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```no_run
|
||||
@ -236,7 +236,7 @@ impl TurtleApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Append commands from a CommandQueue to a turtle's animation queue
|
||||
/// Append commands from a `CommandQueue` to a turtle's animation queue
|
||||
///
|
||||
/// Used internally by `process_commands()` and can be used directly
|
||||
/// when you have a `CommandQueue` instead of a `TurtlePlan`.
|
||||
@ -258,7 +258,7 @@ impl TurtleApp {
|
||||
self.handle_mouse_zoom();
|
||||
|
||||
// Update all turtles' tween controllers
|
||||
for turtle in self.world.turtles.iter_mut() {
|
||||
for turtle in &mut self.world.turtles {
|
||||
// Extract draw_commands and controller temporarily to avoid borrow conflicts
|
||||
|
||||
// Update the controller
|
||||
|
||||
@ -38,7 +38,7 @@ pub struct TurtleParams {
|
||||
}
|
||||
|
||||
impl Default for TurtleParams {
|
||||
/// Create TurtleParams from default values
|
||||
/// Create `TurtleParams` from default values
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
position: vec2(0.0, 0.0),
|
||||
@ -92,7 +92,7 @@ impl Turtle {
|
||||
Angle::radians(self.params.heading)
|
||||
}
|
||||
|
||||
/// Reset turtle to default state (preserves turtle_id and queued commands)
|
||||
/// Reset turtle to default state (preserves `turtle_id` and queued commands)
|
||||
pub fn reset(&mut self) {
|
||||
// Clear all drawings
|
||||
self.commands.clear();
|
||||
@ -316,10 +316,10 @@ impl TurtleWorld {
|
||||
/// Add a new turtle and return its ID
|
||||
pub fn add_turtle(&mut self) -> usize {
|
||||
let turtle_id = self.turtles.len();
|
||||
let mut new_turtle = Turtle::default();
|
||||
new_turtle.turtle_id = turtle_id;
|
||||
new_turtle.tween_controller =
|
||||
TweenController::new(CommandQueue::new(), AnimationSpeed::default());
|
||||
let new_turtle = Turtle {
|
||||
turtle_id,
|
||||
..Default::default()
|
||||
};
|
||||
self.turtles.push(new_turtle);
|
||||
turtle_id
|
||||
}
|
||||
|
||||
@ -294,6 +294,7 @@ pub fn tessellate_circle(
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if tessellation fails.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn tessellate_arc(
|
||||
center: Vec2,
|
||||
radius: f32,
|
||||
|
||||
@ -44,23 +44,13 @@ impl From<TweenVec2> for Vec2 {
|
||||
}
|
||||
|
||||
/// Controls tweening of turtle commands
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct TweenController {
|
||||
queue: CommandQueue,
|
||||
current_tween: Option<CommandTween>,
|
||||
speed: AnimationSpeed,
|
||||
}
|
||||
|
||||
impl Default for TweenController {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
queue: CommandQueue::new(),
|
||||
current_tween: None,
|
||||
speed: AnimationSpeed::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CommandTween {
|
||||
pub turtle_id: usize,
|
||||
@ -98,6 +88,7 @@ impl TweenController {
|
||||
/// Update the tween, returns `Vec` of (`command`, `start_state`, `end_state`) for all completed commands this frame
|
||||
/// Also takes commands vec to handle side effects like fill operations
|
||||
/// Each `command` has its own `start_state` and `end_state` pair
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn update(state: &mut Turtle) -> Vec<(TurtleCommand, TurtleParams, TurtleParams)> {
|
||||
// In instant mode, execute commands up to the draw calls per frame limit
|
||||
if let AnimationSpeed::Instant(max_draw_calls) = state.tween_controller.speed {
|
||||
@ -106,12 +97,7 @@ impl TweenController {
|
||||
let mut draw_call_count = 0;
|
||||
|
||||
// Consume commands from the real queue so the current_index advances
|
||||
loop {
|
||||
let command = match state.tween_controller.queue.next() {
|
||||
Some(cmd) => cmd,
|
||||
None => break,
|
||||
};
|
||||
|
||||
while let Some(command) = state.tween_controller.queue.next() {
|
||||
// Handle SetSpeed command to potentially switch modes
|
||||
if let TurtleCommand::SetSpeed(new_speed) = &command {
|
||||
state.params.speed = *new_speed;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user