diff --git a/src/main/java/dev/slimevr/VRServer.java b/src/main/java/dev/slimevr/VRServer.java index d6bcaf622..b3a1b9f75 100644 --- a/src/main/java/dev/slimevr/VRServer.java +++ b/src/main/java/dev/slimevr/VRServer.java @@ -29,6 +29,8 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.List; import java.util.Queue; +import java.util.Timer; +import java.util.TimerTask; import java.util.concurrent.LinkedBlockingQueue; import java.util.function.Consumer; @@ -51,6 +53,7 @@ public class VRServer extends Thread { private final AutoBoneHandler autoBoneHandler; private final ProtocolAPI protocolAPI; private final ConfigManager configManager; + private final Timer timer = new Timer(); private final NanoTimer fpsTimer = new NanoTimer(); /** @@ -251,16 +254,47 @@ public class VRServer extends Thread { queueTask(humanPoseProcessor::resetTrackers); } - public void resetTrackersMounting() { - queueTask(() -> { - humanPoseProcessor.resetTrackersMounting(); - }); - } - public void resetTrackersYaw() { queueTask(humanPoseProcessor::resetTrackersYaw); } + public void resetTrackersMounting() { + queueTask(humanPoseProcessor::resetTrackersMounting); + } + + public void scheduleResetTrackers(long delay) { + TimerTask resetTask = new resetTask(); + timer.schedule(resetTask, delay); + } + + public void scheduleResetTrackersYaw(long delay) { + TimerTask yawResetTask = new yawResetTask(); + timer.schedule(yawResetTask, delay); + } + + public void scheduleResetTrackersMounting(long delay) { + TimerTask resetMountingTask = new resetMountingTask(); + timer.schedule(resetMountingTask, delay); + } + + class resetTask extends TimerTask { + public void run() { + queueTask(humanPoseProcessor::resetTrackers); + } + } + + class yawResetTask extends TimerTask { + public void run() { + queueTask(humanPoseProcessor::resetTrackersYaw); + } + } + + class resetMountingTask extends TimerTask { + public void run() { + queueTask(humanPoseProcessor::resetTrackersMounting); + } + } + public void setLegTweaksEnabled(boolean value) { queueTask(() -> humanPoseProcessor.setLegTweaksEnabled(value)); } diff --git a/src/main/java/dev/slimevr/config/KeybindingsConfig.java b/src/main/java/dev/slimevr/config/KeybindingsConfig.java index b19fc0c2d..095b90f5c 100644 --- a/src/main/java/dev/slimevr/config/KeybindingsConfig.java +++ b/src/main/java/dev/slimevr/config/KeybindingsConfig.java @@ -8,6 +8,13 @@ public class KeybindingsConfig { private String resetMountingBinding = "CTRL+ALT+SHIFT+I"; + private long resetDelay = 0L; + + private long quickResetDelay = 0L; + + private long resetMountingDelay = 0L; + + public KeybindingsConfig() { } @@ -22,4 +29,28 @@ public class KeybindingsConfig { public String getResetMountingBinding() { return resetMountingBinding; } + + public long getResetDelay() { + return resetDelay; + } + + public void setResetDelay(long delay) { + resetDelay = delay; + } + + public long getQuickResetDelay() { + return quickResetDelay; + } + + public void setQuickResetDelay(long delay) { + quickResetDelay = delay; + } + + public long getResetMountingDelay() { + return resetMountingDelay; + } + + public void setResetMountingDelay(long delay) { + resetMountingDelay = delay; + } } diff --git a/src/main/java/dev/slimevr/gui/Keybinding.java b/src/main/java/dev/slimevr/gui/Keybinding.java index 764735530..85d0364b3 100644 --- a/src/main/java/dev/slimevr/gui/Keybinding.java +++ b/src/main/java/dev/slimevr/gui/Keybinding.java @@ -14,8 +14,6 @@ public class Keybinding implements HotkeyListener { private static final int QUICK_RESET = 2; private static final int RESET_MOUNTING = 3; public final VRServer server; - - public final KeybindingsConfig config; @AWTThread @@ -50,7 +48,7 @@ public class Keybinding implements HotkeyListener { } } catch (Throwable e) { LogManager - .info( + .warning( "[Keybinding] JIntellitype initialization failed. Keybindings will be disabled. Try restarting your computer." ); } @@ -62,15 +60,15 @@ public class Keybinding implements HotkeyListener { switch (identifier) { case RESET -> { LogManager.info("[Keybinding] Reset pressed"); - server.resetTrackers(); + server.scheduleResetTrackers(this.config.getResetDelay()); } case QUICK_RESET -> { LogManager.info("[Keybinding] Quick reset pressed"); - server.resetTrackersYaw(); + server.scheduleResetTrackersYaw(this.config.getQuickResetDelay()); } case RESET_MOUNTING -> { LogManager.info("[Keybinding] Reset mounting pressed"); - server.resetTrackersMounting(); + server.scheduleResetTrackersMounting(this.config.getResetMountingDelay()); } } }