From 36b006028acb5a19f01a1808b172f70807ed00b8 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 29 Mar 2020 23:35:45 -0500 Subject: [PATCH] Make SMXPanelAnimation stop temporarily if lights are set in another way. This is a simple way of making it so things like the "light panels" button don't fight with animations. --- sdk/Windows/SMX.cpp | 3 +++ sdk/Windows/SMXPanelAnimation.cpp | 18 +++++++++++++++++- sdk/Windows/SMXPanelAnimation.h | 7 +++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/sdk/Windows/SMX.cpp b/sdk/Windows/SMX.cpp index 0cdcaca..98052b8 100644 --- a/sdk/Windows/SMX.cpp +++ b/sdk/Windows/SMX.cpp @@ -95,6 +95,9 @@ SMX_API void SMX_SetLights2(const char *lightData, int lightDataSize) } SMXManager::g_pSMX->SetLights(lights); + + // If we're running auto animations, stop them when we get an API call to set lights. + SMXAutoPanelAnimations::TemporaryStopAnimating(); } // This is internal for SMXConfig. These lights aren't meant to be animated. diff --git a/sdk/Windows/SMXPanelAnimation.cpp b/sdk/Windows/SMXPanelAnimation.cpp index b731bc7..1e3c917 100644 --- a/sdk/Windows/SMXPanelAnimation.cpp +++ b/sdk/Windows/SMXPanelAnimation.cpp @@ -383,6 +383,18 @@ bool SMX_LightsAnimation_Load(const char *gif, int size, int pad, SMX_LightsType return true; } +namespace +{ + double g_fStopAnimatingUntil = -1; +} + +void SMXAutoPanelAnimations::TemporaryStopAnimating() +{ + // Stop animating for 100ms. + double fStopForSeconds = 1/10.0f; + g_fStopAnimatingUntil = SMX::GetMonotonicTime() + fStopForSeconds; +} + // A thread to handle setting light animations. We do this in a separate // thread rather than in the SMXManager thread so this can be treated as // if it's external application thread, and it's making normal threaded @@ -407,8 +419,12 @@ private: while(!m_bShutdown) { + // Check if we've temporarily stopped updating lights. + bool bSkipUpdate = g_fStopAnimatingUntil > SMX::GetMonotonicTime(); + // Run a single panel lights update. - UpdateLights(); + if(!bSkipUpdate) + UpdateLights(); // Wait up to 30 FPS, or until we're signalled. We can only be signalled // if we're shutting down, so we don't need to worry about partial frame diff --git a/sdk/Windows/SMXPanelAnimation.h b/sdk/Windows/SMXPanelAnimation.h index 8cfd30a..791b448 100644 --- a/sdk/Windows/SMXPanelAnimation.h +++ b/sdk/Windows/SMXPanelAnimation.h @@ -28,6 +28,13 @@ public: std::vector m_iFrameDurations; }; +namespace SMXAutoPanelAnimations +{ + // If SMX_LightsAnimation_SetAuto is active, stop sending animations briefly. This is + // called when lights are set directly, so they don't compete with the animation. + void TemporaryStopAnimating(); +} + // For SMX_API: #include "../SMX.h"