From 6b45ec53827c2e2938b697fb55de9f158dce295a Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Sat, 14 Sep 2024 09:04:07 -0400 Subject: [PATCH 01/31] first draft --- .../edu/wpi/first/wpilibj2/command/Command.java | 17 +++++++++++++++++ .../main/native/cpp/frc2/command/Command.cpp | 4 ++++ .../main/native/cpp/frc2/command/CommandPtr.cpp | 7 +++++++ .../main/native/include/frc2/command/Command.h | 17 +++++++++++++++++ .../native/include/frc2/command/CommandPtr.h | 13 +++++++++++++ 5 files changed, 58 insertions(+) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index a53d792d0e4..f895b0d791a 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -398,6 +398,23 @@ public ProxyCommand asProxy() { return new ProxyCommand(this); } + /** + * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this for + * "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, + * the composition will not know about the + * status of the scheduled commands, and will treat this command as finishing instantly. + * + * @return the decorated command + * @see ScheduleCommand + * @see WPILib + * docs + */ + public ScheduleCommand fork() { + return new ScheduleCommand(this); + } + /** * Decorates this command to only run if this condition is not met. If the command is already * running and the condition changes to true, the command will not stop running. The requirements diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp index ff5e8f6aa51..bd401a6825b 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp @@ -120,6 +120,10 @@ CommandPtr Command::AsProxy() && { return std::move(*this).ToPtr().AsProxy(); } +CommandPtr Command::Fork() && { + return std::move(*this).ToPtr().Fork(); +} + CommandPtr Command::Unless(std::function condition) && { return std::move(*this).ToPtr().Unless(std::move(condition)); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index ee7182a7847..92784880997 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -15,6 +15,7 @@ #include "frc2/command/PrintCommand.h" #include "frc2/command/ProxyCommand.h" #include "frc2/command/RepeatCommand.h" +#include "frc2/command/ScheduleCommand.h" #include "frc2/command/SequentialCommandGroup.h" #include "frc2/command/WaitCommand.h" #include "frc2/command/WaitUntilCommand.h" @@ -53,6 +54,12 @@ CommandPtr CommandPtr::AsProxy() && { return std::move(*this); } +CommandPtr CommandPtr::Fork() && { + AssertValid(); + m_ptr = std::make_unique(std::move(m_ptr)); + return std::move(*this); +} + class RunsWhenDisabledCommand : public WrapperCommand { public: RunsWhenDisabledCommand(std::unique_ptr&& command, diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h index c4af1afe81b..d7d17eaec84 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h @@ -285,6 +285,23 @@ class Command : public wpi::Sendable, public wpi::SendableHelper { [[nodiscard]] CommandPtr AsProxy() &&; + /** + * Decorates this command to run "forked" by wrapping it in a ScheduleCommand. + * Use this for "forking off" from command compositions when the user does not + * wish to extend the command's requirements to the entire command + * composition. Note that if run from a composition, the composition will not know about the + * status of the scheduled commands, and will treat this command as finishing instantly, see WPILib + * docs for a full explanation. + * + *

This overload transfers command ownership to the returned CommandPtr. + * + * @return the decorated command + * @see ScheduleCommand + */ + [[nodiscard]] + CommandPtr Fork() &&; + /** * Decorates this command to only run if this condition is not met. If the * command is already running and the condition changes to true, the command diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index e2f534f7547..6e3f1b73ef2 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -63,6 +63,19 @@ class CommandPtr final { [[nodiscard]] CommandPtr AsProxy() &&; + /** + * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this for + * "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, + * the composition will not know about the + * status of the scheduled commands, and will treat this command as finishing instantly. + * + * @return the decorated command + * @see ScheduleCommand + */ + [[nodiscard]] + CommandPtr Fork() &&; + /** * Decorates this command to run or stop when disabled. * From 1fb92f0007b3b71916502e17299012f9d2e73ad6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 03:09:31 +0000 Subject: [PATCH 02/31] Formatting fixes --- .../edu/wpi/first/wpilibj2/command/Command.java | 12 ++++++------ .../src/main/native/include/frc2/command/Command.h | 7 ++++--- .../main/native/include/frc2/command/CommandPtr.h | 13 +++++++------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index f895b0d791a..10974f45b11 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -399,11 +399,11 @@ public ProxyCommand asProxy() { } /** - * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this for - * "forking off" from command compositions when the user does not wish to extend the command's - * requirements to the entire command composition. Note that if run from a composition, - * the composition will not know about the - * status of the scheduled commands, and will treat this command as finishing instantly. + * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this + * for "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, the + * composition will not know about the status of the scheduled commands, and will treat this + * command as finishing instantly. * * @return the decorated command * @see ScheduleCommand @@ -413,7 +413,7 @@ public ProxyCommand asProxy() { */ public ScheduleCommand fork() { return new ScheduleCommand(this); - } + } /** * Decorates this command to only run if this condition is not met. If the command is already diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h index d7d17eaec84..453b7f11251 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h @@ -289,8 +289,9 @@ class Command : public wpi::Sendable, public wpi::SendableHelper { * Decorates this command to run "forked" by wrapping it in a ScheduleCommand. * Use this for "forking off" from command compositions when the user does not * wish to extend the command's requirements to the entire command - * composition. Note that if run from a composition, the composition will not know about the - * status of the scheduled commands, and will treat this command as finishing instantly, see WPILib * docs for a full explanation. * @@ -300,7 +301,7 @@ class Command : public wpi::Sendable, public wpi::SendableHelper { * @see ScheduleCommand */ [[nodiscard]] - CommandPtr Fork() &&; + CommandPtr Fork() &&; /** * Decorates this command to only run if this condition is not met. If the diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 6e3f1b73ef2..17fa93c8b3a 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -64,17 +64,18 @@ class CommandPtr final { CommandPtr AsProxy() &&; /** - * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this for - * "forking off" from command compositions when the user does not wish to extend the command's - * requirements to the entire command composition. Note that if run from a composition, - * the composition will not know about the - * status of the scheduled commands, and will treat this command as finishing instantly. + * Decorates this command to run "forked" by wrapping it in a {@link + * ScheduleCommand}. Use this for "forking off" from command compositions when + * the user does not wish to extend the command's requirements to the entire + * command composition. Note that if run from a composition, the composition + * will not know about the status of the scheduled commands, and will treat + * this command as finishing instantly. * * @return the decorated command * @see ScheduleCommand */ [[nodiscard]] - CommandPtr Fork() &&; + CommandPtr Fork() &&; /** * Decorates this command to run or stop when disabled. From 2952b47fdcd1183a39f4c25576ab4f4763ab0fcf Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Sat, 14 Sep 2024 23:22:29 -0400 Subject: [PATCH 03/31] fix Java argument requirements --- .../java/edu/wpi/first/wpilibj2/command/Command.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index f895b0d791a..233c35b661a 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -404,15 +404,22 @@ public ProxyCommand asProxy() { * requirements to the entire command composition. Note that if run from a composition, * the composition will not know about the * status of the scheduled commands, and will treat this command as finishing instantly. + * Commands can be added to this and will be scheduled in order with this command scheduled first. * + * @param commands other commands to schedule along with this one. This command is scheduled first * @return the decorated command * @see ScheduleCommand * @see WPILib * docs */ - public ScheduleCommand fork() { - return new ScheduleCommand(this); + public ScheduleCommand fork(Command... other) { + Command[] commands = new Command[1 + other.length]; + commands[0] = this; + for(int i = 1; i < commands.length; i++){ + commands[i] = other[i - 1]; + } + return new ScheduleCommand(commands); } /** From 0ed013f030349854579781eb2208106baee2c712 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 03:31:45 +0000 Subject: [PATCH 04/31] Formatting fixes --- .../wpi/first/wpilibj2/command/Command.java | 20 +++++++++---------- .../native/include/frc2/command/Command.h | 5 +++-- .../native/include/frc2/command/CommandPtr.h | 11 +++++----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index 233c35b661a..180243e295c 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -399,14 +399,14 @@ public ProxyCommand asProxy() { } /** - * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this for - * "forking off" from command compositions when the user does not wish to extend the command's - * requirements to the entire command composition. Note that if run from a composition, - * the composition will not know about the - * status of the scheduled commands, and will treat this command as finishing instantly. - * Commands can be added to this and will be scheduled in order with this command scheduled first. - * - * @param commands other commands to schedule along with this one. This command is scheduled first + * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this + * for "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, the + * composition will not know about the status of the scheduled commands, and will treat this + * command as finishing instantly. Commands can be added to this and will be scheduled in order + * with this command scheduled first. + * + * @param commands other commands to schedule along with this one. This command is scheduled first * @return the decorated command * @see ScheduleCommand * @see { * Decorates this command to run "forked" by wrapping it in a ScheduleCommand. * Use this for "forking off" from command compositions when the user does not * wish to extend the command's requirements to the entire command - * composition. Note that if run from a composition, the composition will not know about the - * status of the scheduled commands, and will treat this command as finishing instantly, see WPILib * docs for a full explanation. * diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 825031e0886..17fa93c8b3a 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -64,11 +64,12 @@ class CommandPtr final { CommandPtr AsProxy() &&; /** - * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this for - * "forking off" from command compositions when the user does not wish to extend the command's - * requirements to the entire command composition. Note that if run from a composition, - * the composition will not know about the - * status of the scheduled commands, and will treat this command as finishing instantly. + * Decorates this command to run "forked" by wrapping it in a {@link + * ScheduleCommand}. Use this for "forking off" from command compositions when + * the user does not wish to extend the command's requirements to the entire + * command composition. Note that if run from a composition, the composition + * will not know about the status of the scheduled commands, and will treat + * this command as finishing instantly. * * @return the decorated command * @see ScheduleCommand From 883c761cdc2460608b01afadfb5ac2302fb6b1e8 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Sat, 14 Sep 2024 23:38:06 -0400 Subject: [PATCH 05/31] missing period --- .../src/main/java/edu/wpi/first/wpilibj2/command/Command.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index 233c35b661a..7ca08af1dd2 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -406,7 +406,7 @@ public ProxyCommand asProxy() { * status of the scheduled commands, and will treat this command as finishing instantly. * Commands can be added to this and will be scheduled in order with this command scheduled first. * - * @param commands other commands to schedule along with this one. This command is scheduled first + * @param commands other commands to schedule along with this one. This command is scheduled first. * @return the decorated command * @see ScheduleCommand * @see Date: Sat, 14 Sep 2024 23:39:03 -0400 Subject: [PATCH 06/31] removed C++ for now --- .../main/native/cpp/frc2/command/CommandPtr.cpp | 6 ------ .../main/native/include/frc2/command/CommandPtr.h | 14 -------------- 2 files changed, 20 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 92784880997..47e0515154b 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -54,12 +54,6 @@ CommandPtr CommandPtr::AsProxy() && { return std::move(*this); } -CommandPtr CommandPtr::Fork() && { - AssertValid(); - m_ptr = std::make_unique(std::move(m_ptr)); - return std::move(*this); -} - class RunsWhenDisabledCommand : public WrapperCommand { public: RunsWhenDisabledCommand(std::unique_ptr&& command, diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 17fa93c8b3a..e2f534f7547 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -63,20 +63,6 @@ class CommandPtr final { [[nodiscard]] CommandPtr AsProxy() &&; - /** - * Decorates this command to run "forked" by wrapping it in a {@link - * ScheduleCommand}. Use this for "forking off" from command compositions when - * the user does not wish to extend the command's requirements to the entire - * command composition. Note that if run from a composition, the composition - * will not know about the status of the scheduled commands, and will treat - * this command as finishing instantly. - * - * @return the decorated command - * @see ScheduleCommand - */ - [[nodiscard]] - CommandPtr Fork() &&; - /** * Decorates this command to run or stop when disabled. * From 256dc211bf6884d9d3a9b3b708b6acaa8d7235aa Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Sat, 14 Sep 2024 23:45:17 -0400 Subject: [PATCH 07/31] fully remove c++ for now. --- .../main/native/cpp/frc2/command/Command.cpp | 4 ---- .../main/native/include/frc2/command/Command.h | 18 ------------------ 2 files changed, 22 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp index bd401a6825b..ff5e8f6aa51 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp @@ -120,10 +120,6 @@ CommandPtr Command::AsProxy() && { return std::move(*this).ToPtr().AsProxy(); } -CommandPtr Command::Fork() && { - return std::move(*this).ToPtr().Fork(); -} - CommandPtr Command::Unless(std::function condition) && { return std::move(*this).ToPtr().Unless(std::move(condition)); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h index 453b7f11251..c4af1afe81b 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h @@ -285,24 +285,6 @@ class Command : public wpi::Sendable, public wpi::SendableHelper { [[nodiscard]] CommandPtr AsProxy() &&; - /** - * Decorates this command to run "forked" by wrapping it in a ScheduleCommand. - * Use this for "forking off" from command compositions when the user does not - * wish to extend the command's requirements to the entire command - * composition. Note that if run from a composition, the composition will not - * know about the status of the scheduled commands, and will treat this - * command as finishing instantly, see WPILib - * docs for a full explanation. - * - *

This overload transfers command ownership to the returned CommandPtr. - * - * @return the decorated command - * @see ScheduleCommand - */ - [[nodiscard]] - CommandPtr Fork() &&; - /** * Decorates this command to only run if this condition is not met. If the * command is already running and the condition changes to true, the command From 9a684d672d52d5d6ce90bacd9cae28c3871daaf7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 03:54:55 +0000 Subject: [PATCH 08/31] Formatting fixes --- .../src/main/java/edu/wpi/first/wpilibj2/command/Command.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index c952920714e..ffda1476d83 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -406,7 +406,8 @@ public ProxyCommand asProxy() { * command as finishing instantly. Commands can be added to this and will be scheduled in order * with this command scheduled first. * - * @param commands other commands to schedule along with this one. This command is scheduled first. + * @param commands other commands to schedule along with this one. This command is scheduled + * first. * @return the decorated command * @see ScheduleCommand * @see Date: Sun, 15 Sep 2024 01:01:25 -0400 Subject: [PATCH 09/31] param rename --- .../src/main/java/edu/wpi/first/wpilibj2/command/Command.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index ffda1476d83..110c365e0af 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -406,7 +406,7 @@ public ProxyCommand asProxy() { * command as finishing instantly. Commands can be added to this and will be scheduled in order * with this command scheduled first. * - * @param commands other commands to schedule along with this one. This command is scheduled + * @param other other commands to schedule along with this one. This command is scheduled * first. * @return the decorated command * @see ScheduleCommand From 354020551f5573cbf4629d0f84a351c9a53fef30 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 05:18:25 +0000 Subject: [PATCH 10/31] Formatting fixes --- .../src/main/java/edu/wpi/first/wpilibj2/command/Command.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index 110c365e0af..63d66e353fb 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -406,8 +406,7 @@ public ProxyCommand asProxy() { * command as finishing instantly. Commands can be added to this and will be scheduled in order * with this command scheduled first. * - * @param other other commands to schedule along with this one. This command is scheduled - * first. + * @param other other commands to schedule along with this one. This command is scheduled first. * @return the decorated command * @see ScheduleCommand * @see Date: Sun, 15 Sep 2024 01:33:21 -0400 Subject: [PATCH 11/31] fixed loop copy of array --- .../main/java/edu/wpi/first/wpilibj2/command/Command.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index 63d66e353fb..94a42c7797e 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -12,6 +12,8 @@ import edu.wpi.first.util.sendable.Sendable; import edu.wpi.first.util.sendable.SendableBuilder; import edu.wpi.first.util.sendable.SendableRegistry; + +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -416,9 +418,7 @@ public ProxyCommand asProxy() { public ScheduleCommand fork(Command... other) { Command[] commands = new Command[1 + other.length]; commands[0] = this; - for (int i = 1; i < commands.length; i++) { - commands[i] = other[i - 1]; - } + System.arraycopy(other, 0, commands, 1, other.length); return new ScheduleCommand(commands); } From 3e5898921c5826ddeee7e6f9bf0bbc6be154004b Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Sun, 15 Sep 2024 01:40:47 -0400 Subject: [PATCH 12/31] formatting fixes --- .../src/main/java/edu/wpi/first/wpilibj2/command/Command.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index 94a42c7797e..ed934b39c3e 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -12,8 +12,6 @@ import edu.wpi.first.util.sendable.Sendable; import edu.wpi.first.util.sendable.SendableBuilder; import edu.wpi.first.util.sendable.SendableRegistry; - -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Set; From 1191215a9f7c1c7fea17c2334c4eec85691cd638 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Fri, 11 Oct 2024 07:46:08 -0400 Subject: [PATCH 13/31] attempt --- .../main/native/cpp/frc2/command/CommandPtr.cpp | 10 ++++++++++ .../main/native/include/frc2/command/CommandPtr.h | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 4d48c5706b9..fed7b284d1f 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -57,6 +57,16 @@ CommandPtr CommandPtr::AsProxy() && { return std::move(*this); } +CommandPtr CommandPtr::Fork(CommandPtr&& other) && { + AssertValid(); + std::vector> vec; + vec.emplace_back(std::move(m_ptr)); + vec.emplace_back(std::move(other).Unwrap()); + std::span> span(vec); + m_ptr = std::make_unique(std::move(span)); + return std::move(*this); +} + class RunsWhenDisabledCommand : public WrapperCommand { public: RunsWhenDisabledCommand(std::unique_ptr&& command, diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index e2f534f7547..92fa532d35b 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -63,6 +63,21 @@ class CommandPtr final { [[nodiscard]] CommandPtr AsProxy() &&; + /** + * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this + * for "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, the + * composition will not know about the status of the scheduled commands, and will treat this + * command as finishing instantly. Commands can be added to this and will be scheduled in order + * with this command scheduled first. + * + * @param other other commands to schedule along with this one. This command is scheduled first. + * @return the decorated command + * @see ScheduleCommand + */ + [[nodiscard]] + CommandPtr Fork(CommandPtr&& other) &&; + /** * Decorates this command to run or stop when disabled. * From 1b64ab23cc307868fa16c0a8eb9e161ec8e4e207 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Tue, 22 Oct 2024 21:54:36 -0400 Subject: [PATCH 14/31] pointer updates --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index fed7b284d1f..9f13e888c2a 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -59,10 +59,10 @@ CommandPtr CommandPtr::AsProxy() && { CommandPtr CommandPtr::Fork(CommandPtr&& other) && { AssertValid(); - std::vector> vec; + std::vector vec; vec.emplace_back(std::move(m_ptr)); vec.emplace_back(std::move(other).Unwrap()); - std::span> span(vec); + std::span span(vec); m_ptr = std::make_unique(std::move(span)); return std::move(*this); } From 5172e87c76b153e46d36bcbc99305578b551ff2f Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Tue, 22 Oct 2024 22:00:34 -0400 Subject: [PATCH 15/31] fix thanks space-sooty --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 9f13e888c2a..afba43b00d2 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -59,11 +59,8 @@ CommandPtr CommandPtr::AsProxy() && { CommandPtr CommandPtr::Fork(CommandPtr&& other) && { AssertValid(); - std::vector vec; - vec.emplace_back(std::move(m_ptr)); - vec.emplace_back(std::move(other).Unwrap()); - std::span span(vec); - m_ptr = std::make_unique(std::move(span)); + std::vector vec{m_ptr.get(), other.get()}; + m_ptr = make_unique(std::span(vec)); return std::move(*this); } From 4793d6cbcb11c46af8e647163e1cf310578685a2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 02:09:55 +0000 Subject: [PATCH 16/31] Formatting fixes --- .../main/native/cpp/frc2/command/CommandPtr.cpp | 2 +- .../native/include/frc2/command/CommandPtr.h | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index afba43b00d2..62c466c3651 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -60,7 +60,7 @@ CommandPtr CommandPtr::AsProxy() && { CommandPtr CommandPtr::Fork(CommandPtr&& other) && { AssertValid(); std::vector vec{m_ptr.get(), other.get()}; - m_ptr = make_unique(std::span(vec)); + m_ptr = make_unique(std::span(vec)); return std::move(*this); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 92fa532d35b..5a325ab99c9 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -64,14 +64,16 @@ class CommandPtr final { CommandPtr AsProxy() &&; /** - * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this - * for "forking off" from command compositions when the user does not wish to extend the command's - * requirements to the entire command composition. Note that if run from a composition, the - * composition will not know about the status of the scheduled commands, and will treat this - * command as finishing instantly. Commands can be added to this and will be scheduled in order - * with this command scheduled first. + * Decorates this command to run "forked" by wrapping it in a {@link + * ScheduleCommand}. Use this for "forking off" from command compositions when + * the user does not wish to extend the command's requirements to the entire + * command composition. Note that if run from a composition, the composition + * will not know about the status of the scheduled commands, and will treat + * this command as finishing instantly. Commands can be added to this and will + * be scheduled in order with this command scheduled first. * - * @param other other commands to schedule along with this one. This command is scheduled first. + * @param other other commands to schedule along with this one. This command + * is scheduled first. * @return the decorated command * @see ScheduleCommand */ From e4d268d8c89a4492ae37d880f4a786d32ba1946e Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Tue, 22 Oct 2024 22:31:08 -0400 Subject: [PATCH 17/31] varargs added? --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 2 +- .../src/main/native/include/frc2/command/CommandPtr.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index afba43b00d2..5ab402e4f26 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -57,7 +57,7 @@ CommandPtr CommandPtr::AsProxy() && { return std::move(*this); } -CommandPtr CommandPtr::Fork(CommandPtr&& other) && { +CommandPtr CommandPtr::Fork(CommandPtr&&... other) && { AssertValid(); std::vector vec{m_ptr.get(), other.get()}; m_ptr = make_unique(std::span(vec)); diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 92fa532d35b..14c8da3a10c 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -76,7 +76,7 @@ class CommandPtr final { * @see ScheduleCommand */ [[nodiscard]] - CommandPtr Fork(CommandPtr&& other) &&; + CommandPtr Fork(CommandPtr&&... other) &&; /** * Decorates this command to run or stop when disabled. From 84202484c17fc68a96308e9bb35f6593ebfa0c11 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Tue, 22 Oct 2024 22:36:03 -0400 Subject: [PATCH 18/31] revert --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 5 +++-- .../src/main/native/include/frc2/command/CommandPtr.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index cf1a6d1db54..fd944888277 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -57,13 +57,14 @@ CommandPtr CommandPtr::AsProxy() && { return std::move(*this); } -CommandPtr CommandPtr::Fork(CommandPtr&&... other) && { +CommandPtr CommandPtr::Fork(CommandPtr&& other) && { AssertValid(); std::vector vec{m_ptr.get(), other.get()}; - m_ptr = make_unique(std::span(vec)); + m_ptr = make_unique(std::span(vec)); return std::move(*this); } + class RunsWhenDisabledCommand : public WrapperCommand { public: RunsWhenDisabledCommand(std::unique_ptr&& command, diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 44e58768c14..5a325ab99c9 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -78,7 +78,7 @@ class CommandPtr final { * @see ScheduleCommand */ [[nodiscard]] - CommandPtr Fork(CommandPtr&&... other) &&; + CommandPtr Fork(CommandPtr&& other) &&; /** * Decorates this command to run or stop when disabled. From 7f05e7d004e2279d8b16a7b71a01e9fdd09d9b5c Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Tue, 22 Oct 2024 22:37:41 -0400 Subject: [PATCH 19/31] varargs attempt 2 --- .../main/native/cpp/frc2/command/CommandPtr.cpp | 7 +++++++ .../native/include/frc2/command/CommandPtr.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index fd944888277..624cf94dc71 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -64,6 +64,13 @@ CommandPtr CommandPtr::Fork(CommandPtr&& other) && { return std::move(*this); } +CommandPtr CommandPtr::Fork(CommandPtr&&... other) && { + AssertValid(); + std::vector vec{m_ptr.get(), other.get()}; + m_ptr = make_unique(std::span(vec)); + return std::move(*this); +} + class RunsWhenDisabledCommand : public WrapperCommand { public: diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 5a325ab99c9..15b448c353b 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -80,6 +80,23 @@ class CommandPtr final { [[nodiscard]] CommandPtr Fork(CommandPtr&& other) &&; + /** + * Decorates this command to run "forked" by wrapping it in a {@link + * ScheduleCommand}. Use this for "forking off" from command compositions when + * the user does not wish to extend the command's requirements to the entire + * command composition. Note that if run from a composition, the composition + * will not know about the status of the scheduled commands, and will treat + * this command as finishing instantly. Commands can be added to this and will + * be scheduled in order with this command scheduled first. + * + * @param other other commands to schedule along with this one. This command + * is scheduled first. + * @return the decorated command + * @see ScheduleCommand + */ + [[nodiscard]] + CommandPtr Fork(CommandPtr&&... other) &&; + /** * Decorates this command to run or stop when disabled. * From f9abc956ea9f44b3342adfa6733603ab028d6eb0 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Tue, 22 Oct 2024 22:48:54 -0400 Subject: [PATCH 20/31] another attempt using std::vector --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 4 ++-- .../src/main/native/include/frc2/command/CommandPtr.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 624cf94dc71..5aee2e96c8c 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -64,9 +64,9 @@ CommandPtr CommandPtr::Fork(CommandPtr&& other) && { return std::move(*this); } -CommandPtr CommandPtr::Fork(CommandPtr&&... other) && { +CommandPtr CommandPtr::Fork(std::vector> other) && { AssertValid(); - std::vector vec{m_ptr.get(), other.get()}; + std::vector vec{m_ptr.get(), std::move(other)}; m_ptr = make_unique(std::span(vec)); return std::move(*this); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 15b448c353b..5a725005eda 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -78,7 +78,7 @@ class CommandPtr final { * @see ScheduleCommand */ [[nodiscard]] - CommandPtr Fork(CommandPtr&& other) &&; + CommandPtr Fork(std::vector> other) &&; /** * Decorates this command to run "forked" by wrapping it in a {@link From 13313f3572743a1fcbe7c38fc74c82ad745cbcb2 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Tue, 22 Oct 2024 23:00:21 -0400 Subject: [PATCH 21/31] revert again --- .../native/cpp/frc2/command/CommandPtr.cpp | 8 -------- .../native/include/frc2/command/CommandPtr.h | 19 +------------------ 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 5aee2e96c8c..afba43b00d2 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -64,14 +64,6 @@ CommandPtr CommandPtr::Fork(CommandPtr&& other) && { return std::move(*this); } -CommandPtr CommandPtr::Fork(std::vector> other) && { - AssertValid(); - std::vector vec{m_ptr.get(), std::move(other)}; - m_ptr = make_unique(std::span(vec)); - return std::move(*this); -} - - class RunsWhenDisabledCommand : public WrapperCommand { public: RunsWhenDisabledCommand(std::unique_ptr&& command, diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 5a725005eda..5a325ab99c9 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -78,24 +78,7 @@ class CommandPtr final { * @see ScheduleCommand */ [[nodiscard]] - CommandPtr Fork(std::vector> other) &&; - - /** - * Decorates this command to run "forked" by wrapping it in a {@link - * ScheduleCommand}. Use this for "forking off" from command compositions when - * the user does not wish to extend the command's requirements to the entire - * command composition. Note that if run from a composition, the composition - * will not know about the status of the scheduled commands, and will treat - * this command as finishing instantly. Commands can be added to this and will - * be scheduled in order with this command scheduled first. - * - * @param other other commands to schedule along with this one. This command - * is scheduled first. - * @return the decorated command - * @see ScheduleCommand - */ - [[nodiscard]] - CommandPtr Fork(CommandPtr&&... other) &&; + CommandPtr Fork(CommandPtr&& other) &&; /** * Decorates this command to run or stop when disabled. From 49c52c0b3aada3b8dc09152e8e899285d01d1237 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 03:37:25 +0000 Subject: [PATCH 22/31] Formatting fixes --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index afba43b00d2..62c466c3651 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -60,7 +60,7 @@ CommandPtr CommandPtr::AsProxy() && { CommandPtr CommandPtr::Fork(CommandPtr&& other) && { AssertValid(); std::vector vec{m_ptr.get(), other.get()}; - m_ptr = make_unique(std::span(vec)); + m_ptr = make_unique(std::span(vec)); return std::move(*this); } From 71a038c28b124aa32363c19e3e5f4d3ade7856d2 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Wed, 23 Oct 2024 05:29:22 -0400 Subject: [PATCH 23/31] separate overload --- .../main/native/cpp/frc2/command/CommandPtr.cpp | 7 +++++++ .../native/include/frc2/command/CommandPtr.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index afba43b00d2..6e398b0a586 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -64,6 +64,13 @@ CommandPtr CommandPtr::Fork(CommandPtr&& other) && { return std::move(*this); } +CommandPtr CommandPtr::Fork(std::vector&& other) && { + AssertValid(); + std::vector vec{m_ptr.get(), }; + m_ptr = make_unique(std::span(vec)); + return std::move(*this); +} + class RunsWhenDisabledCommand : public WrapperCommand { public: RunsWhenDisabledCommand(std::unique_ptr&& command, diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 5a325ab99c9..703509315ce 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -80,6 +80,23 @@ class CommandPtr final { [[nodiscard]] CommandPtr Fork(CommandPtr&& other) &&; + /** + * Decorates this command to run "forked" by wrapping it in a {@link + * ScheduleCommand}. Use this for "forking off" from command compositions when + * the user does not wish to extend the command's requirements to the entire + * command composition. Note that if run from a composition, the composition + * will not know about the status of the scheduled commands, and will treat + * this command as finishing instantly. Commands can be added to this and will + * be scheduled in order with this command scheduled first. + * + * @param other other commands to schedule along with this one. This command + * is scheduled first. + * @return the decorated command + * @see ScheduleCommand + */ + [[nodiscard]] + CommandPtr Fork(std::vector&& other) &&; + /** * Decorates this command to run or stop when disabled. * From d1b111dbb04e989c64e355ead279edcc86bf9acc Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Wed, 23 Oct 2024 05:37:46 -0400 Subject: [PATCH 24/31] possible fix --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 5324a69c594..507ac4ecba0 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -66,8 +66,11 @@ CommandPtr CommandPtr::Fork(CommandPtr&& other) && { CommandPtr CommandPtr::Fork(std::vector&& other) && { AssertValid(); - std::vector vec{m_ptr.get(), }; - m_ptr = make_unique(std::span(vec)); + std::vector vec{m_ptr.get()}; + for (auto&& ptr : other) { + vec.emplace_back(std::move(ptr).Unwrap().get()); + } + m_ptr = make_unique(std::span(vec)); return std::move(*this); } From 47abdc83807470cfe5784dabc46aa53db6450d00 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:44:48 +0000 Subject: [PATCH 25/31] Formatting fixes --- .../src/main/native/include/frc2/command/CommandPtr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 703509315ce..d470a0618c1 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -95,7 +95,7 @@ class CommandPtr final { * @see ScheduleCommand */ [[nodiscard]] - CommandPtr Fork(std::vector&& other) &&; + CommandPtr Fork(std::vector&& other) &&; /** * Decorates this command to run or stop when disabled. From 44f542e13963fc1270180b0e17a90676218cb3dc Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Wed, 23 Oct 2024 07:06:14 -0400 Subject: [PATCH 26/31] Update wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp Co-authored-by: Jade --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 507ac4ecba0..a0b18e05f27 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -66,11 +66,8 @@ CommandPtr CommandPtr::Fork(CommandPtr&& other) && { CommandPtr CommandPtr::Fork(std::vector&& other) && { AssertValid(); - std::vector vec{m_ptr.get()}; - for (auto&& ptr : other) { - vec.emplace_back(std::move(ptr).Unwrap().get()); - } - m_ptr = make_unique(std::span(vec)); + other.emplace_back(std::move(m_ptr).get()); + m_ptr = make_unique(std::span(other)); return std::move(*this); } From e208fa91c60c3b0f4e525d6ec750076d12ad143a Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Wed, 23 Oct 2024 07:13:43 -0400 Subject: [PATCH 27/31] revert --- .../src/main/native/cpp/frc2/command/CommandPtr.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index a0b18e05f27..507ac4ecba0 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -66,8 +66,11 @@ CommandPtr CommandPtr::Fork(CommandPtr&& other) && { CommandPtr CommandPtr::Fork(std::vector&& other) && { AssertValid(); - other.emplace_back(std::move(m_ptr).get()); - m_ptr = make_unique(std::span(other)); + std::vector vec{m_ptr.get()}; + for (auto&& ptr : other) { + vec.emplace_back(std::move(ptr).Unwrap().get()); + } + m_ptr = make_unique(std::span(vec)); return std::move(*this); } From b667e1891392f5379e3f0a45341704bbf7065e06 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Thu, 24 Oct 2024 16:12:40 -0400 Subject: [PATCH 28/31] requested changes --- .../wpi/first/wpilibj2/command/Command.java | 11 ++----- .../wpi/first/wpilibj2/command/Commands.java | 19 +++++++++++ .../native/cpp/frc2/command/CommandPtr.cpp | 12 +------ .../main/native/cpp/frc2/command/Commands.cpp | 15 +++++++++ .../native/include/frc2/command/CommandPtr.h | 24 ++------------ .../native/include/frc2/command/Commands.h | 33 +++++++++++++++++++ 6 files changed, 73 insertions(+), 41 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index ed934b39c3e..10974f45b11 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -403,21 +403,16 @@ public ProxyCommand asProxy() { * for "forking off" from command compositions when the user does not wish to extend the command's * requirements to the entire command composition. Note that if run from a composition, the * composition will not know about the status of the scheduled commands, and will treat this - * command as finishing instantly. Commands can be added to this and will be scheduled in order - * with this command scheduled first. + * command as finishing instantly. * - * @param other other commands to schedule along with this one. This command is scheduled first. * @return the decorated command * @see ScheduleCommand * @see WPILib * docs */ - public ScheduleCommand fork(Command... other) { - Command[] commands = new Command[1 + other.length]; - commands[0] = this; - System.arraycopy(other, 0, commands, 1, other.length); - return new ScheduleCommand(commands); + public ScheduleCommand fork() { + return new ScheduleCommand(this); } /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index c53409a033d..cf4a562dccf 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -209,6 +209,25 @@ public static Command deferredProxy(Supplier supplier) { return new ProxyCommand(supplier); } + /** + * Constructs a command by wrapping the provided commands in a {@link ScheduleCommand}. Use this + * for "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, the + * composition will not know about the status of the scheduled commands, and will treat this + * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order + * with this command scheduled first. + * + * @param commands the commands to schedule in order + * @return the command + * @see ScheduleCommand + * @see WPILib + * docs + */ + public static Command fork(Command... commands) { + return new ScheduleCommand(commands); + } + // Command Groups /** diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 507ac4ecba0..6b373b7f01e 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -57,19 +57,9 @@ CommandPtr CommandPtr::AsProxy() && { return std::move(*this); } -CommandPtr CommandPtr::Fork(CommandPtr&& other) && { - AssertValid(); - std::vector vec{m_ptr.get(), other.get()}; - m_ptr = make_unique(std::span(vec)); - return std::move(*this); -} - -CommandPtr CommandPtr::Fork(std::vector&& other) && { +CommandPtr CommandPtr::Fork() && { AssertValid(); std::vector vec{m_ptr.get()}; - for (auto&& ptr : other) { - vec.emplace_back(std::move(ptr).Unwrap().get()); - } m_ptr = make_unique(std::span(vec)); return std::move(*this); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp index bc4bd39da73..ce9f1969ba0 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp @@ -83,6 +83,21 @@ CommandPtr cmd::DeferredProxy(wpi::unique_function supplier) { } WPI_UNIGNORE_DEPRECATED +CommandPtr cmd::Fork(CommandPtr&& other) { + std::vector vec{other.get()}; + auto m_ptr = make_unique(std::span(vec)); + return ScheduleCommand(std::move(*m_ptr)).ToPtr(); +} + +CommandPtr cmd::Fork(std::vector&& commands) { + std::vector vec{}; + for (auto&& ptr : commands) { + vec.emplace_back(std::move(ptr).Unwrap().get()); + } + auto m_ptr = make_unique(std::span(vec)); + return ScheduleCommand(std::move(*m_ptr)).ToPtr(); +} + CommandPtr cmd::Wait(units::second_t duration) { return WaitCommand(duration).ToPtr(); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h index 703509315ce..17fa93c8b3a 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h @@ -69,33 +69,13 @@ class CommandPtr final { * the user does not wish to extend the command's requirements to the entire * command composition. Note that if run from a composition, the composition * will not know about the status of the scheduled commands, and will treat - * this command as finishing instantly. Commands can be added to this and will - * be scheduled in order with this command scheduled first. + * this command as finishing instantly. * - * @param other other commands to schedule along with this one. This command - * is scheduled first. * @return the decorated command * @see ScheduleCommand */ [[nodiscard]] - CommandPtr Fork(CommandPtr&& other) &&; - - /** - * Decorates this command to run "forked" by wrapping it in a {@link - * ScheduleCommand}. Use this for "forking off" from command compositions when - * the user does not wish to extend the command's requirements to the entire - * command composition. Note that if run from a composition, the composition - * will not know about the status of the scheduled commands, and will treat - * this command as finishing instantly. Commands can be added to this and will - * be scheduled in order with this command scheduled first. - * - * @param other other commands to schedule along with this one. This command - * is scheduled first. - * @return the decorated command - * @see ScheduleCommand - */ - [[nodiscard]] - CommandPtr Fork(std::vector&& other) &&; + CommandPtr Fork() &&; /** * Decorates this command to run or stop when disabled. diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index 6cfad01b1f0..885ec68887d 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -16,6 +16,7 @@ #include "frc2/command/CommandPtr.h" #include "frc2/command/Requirements.h" +#include "frc2/command/ScheduleCommand.h" #include "frc2/command/SelectCommand.h" namespace frc2 { @@ -192,6 +193,38 @@ CommandPtr DeferredProxy(wpi::unique_function supplier); "Defer(supplier).AsProxy() instead.")]] CommandPtr DeferredProxy(wpi::unique_function supplier); WPI_UNIGNORE_DEPRECATED + + /** + * Constructs a command by wrapping the provided commands in a {@link ScheduleCommand}. Use this + * for "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, the + * composition will not know about the status of the scheduled commands, and will treat this + * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order + * with this command scheduled first. + * + * @param commands the commands to schedule in order + * @return the command + * @see ScheduleCommand + */ + [[nodiscard]] + CommandPtr Fork(CommandPtr&& commands); + + /** + * Constructs a command by wrapping the provided commands in a {@link ScheduleCommand}. Use this + * for "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, the + * composition will not know about the status of the scheduled commands, and will treat this + * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order + * with this command scheduled first. + * + * @param commands the commands to schedule in order + * @return the command + * @see ScheduleCommand + */ + [[nodiscard]] + CommandPtr Fork(std::vector&& commands); + + // Command Groups namespace impl { From 5124914b503098bd855ea4bbf0f63795147f9f12 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Thu, 24 Oct 2024 16:43:27 -0400 Subject: [PATCH 29/31] formatting fixes --- .../main/java/edu/wpi/first/wpilibj2/command/Commands.java | 3 +-- .../src/main/native/include/frc2/command/Commands.h | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index cf4a562dccf..e74fce698c6 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -214,8 +214,7 @@ public static Command deferredProxy(Supplier supplier) { * for "forking off" from command compositions when the user does not wish to extend the command's * requirements to the entire command composition. Note that if run from a composition, the * composition will not know about the status of the scheduled commands, and will treat this - * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order - * with this command scheduled first. + * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order. * * @param commands the commands to schedule in order * @return the command diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index 885ec68887d..fca01f1f11d 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -199,8 +199,7 @@ WPI_UNIGNORE_DEPRECATED * for "forking off" from command compositions when the user does not wish to extend the command's * requirements to the entire command composition. Note that if run from a composition, the * composition will not know about the status of the scheduled commands, and will treat this - * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order - * with this command scheduled first. + * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order. * * @param commands the commands to schedule in order * @return the command @@ -214,8 +213,7 @@ WPI_UNIGNORE_DEPRECATED * for "forking off" from command compositions when the user does not wish to extend the command's * requirements to the entire command composition. Note that if run from a composition, the * composition will not know about the status of the scheduled commands, and will treat this - * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order - * with this command scheduled first. + * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order. * * @param commands the commands to schedule in order * @return the command From e2ff78a617b95ffd3bbb0310b51a903174805af0 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Thu, 24 Oct 2024 19:09:07 -0400 Subject: [PATCH 30/31] formatting fixes --- .../main/java/edu/wpi/first/wpilibj2/command/Commands.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index e74fce698c6..8c81106f83b 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -214,7 +214,8 @@ public static Command deferredProxy(Supplier supplier) { * for "forking off" from command compositions when the user does not wish to extend the command's * requirements to the entire command composition. Note that if run from a composition, the * composition will not know about the status of the scheduled commands, and will treat this - * command as finishing instantly. Multiple commands can be added to this and will be scheduled in order. + * command as finishing instantly. Multiple commands can be added to this and will be scheduled in + * order. * * @param commands the commands to schedule in order * @return the command @@ -225,7 +226,7 @@ public static Command deferredProxy(Supplier supplier) { */ public static Command fork(Command... commands) { return new ScheduleCommand(commands); - } + } // Command Groups From 9c6c77f8e9349ba5bf787e6c84ae0c06665f9c11 Mon Sep 17 00:00:00 2001 From: Nicholas Armstrong Date: Thu, 24 Oct 2024 19:22:15 -0400 Subject: [PATCH 31/31] updates --- wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp index ce9f1969ba0..0650d6e4be3 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp @@ -6,7 +6,7 @@ #include #include - +#include #include #include "frc2/command/ConditionalCommand.h"