From 8249cb11fa7b02af3e43932bbbdbec638e3e3f69 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 11 Apr 2020 18:29:05 +0100 Subject: [PATCH] Move functions into class in Colour, Switch VScreensaver to std::thread --- colour.cc | 9 ++++----- colour.h | 7 +++++-- vscreensaver.cc | 54 ++++++++++++++++++++++++++++++++----------------- vscreensaver.h | 23 ++++++++++----------- 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/colour.cc b/colour.cc index eff30ed..699dd0c 100644 --- a/colour.cc +++ b/colour.cc @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #include "colour.h" @@ -80,7 +79,7 @@ int SkinFactory::getNumberofSkins() -void InitDefaultSkin() +void SkinFactory::InitDefaultSkin() { /* Real colours @@ -126,7 +125,7 @@ Colour Colour::BUTTONBACKGROUND(255, 255, 255); */ } -void InitEnhancedSkin() +void SkinFactory::InitEnhancedSkin() { /* Real colours @@ -334,7 +333,7 @@ Colour Colour::BUTTONBACKGROUND(255, 255, 255); */ } -void InitNoopacityInspiredSkin() +void SkinFactory::InitNoopacityInspiredSkin() { /* Real colours diff --git a/colour.h b/colour.h index 0224cd4..47f338a 100644 --- a/colour.h +++ b/colour.h @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef COLOUR_H @@ -204,6 +203,10 @@ public: static int getNumberofSkins(); static const char* *getSkinNames(); static bool InitSkin(int n); +private: + static void InitDefaultSkin(); + static void InitEnhancedSkin(); + static void InitNoopacityInspiredSkin(); }; #endif diff --git a/vscreensaver.cc b/vscreensaver.cc index 7355467..3d1a83a 100644 --- a/vscreensaver.cc +++ b/vscreensaver.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,11 +14,12 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ -#include "vscreensaver.h" +#include +#include +#include #include "defines.h" #include "log.h" @@ -27,6 +28,8 @@ #include "video.h" #include "surface.h" +#include "vscreensaver.h" + VScreensaver::VScreensaver() { setPosition(0, 0); @@ -40,32 +43,43 @@ VScreensaver::VScreensaver() VScreensaver::~VScreensaver() { + stopThread(); surface = NULL; // it's the screen. stop view base from killing it. - threadCancel(); } void VScreensaver::draw() { fillColour(DrawStyle::BLACK); - threadStart(); + + ssThreadStartProtect.lock(); + ssThread = std::thread([this] + { + ssThreadStartProtect.lock(); + ssThreadStartProtect.unlock(); + threadMethod(); + }); + ssThreadStartProtect.unlock(); } int VScreensaver::handleCommand(int /*command*/) { - threadCancel(); + stopThread(); return 4; } +void VScreensaver::stopThread() +{ + threadReqStop = true; + if (ssThread.joinable()) ssThread.join(); +} + void VScreensaver::threadMethod() { srand(time(NULL)); - threadSetKillable(); - // Config const int h = 50; // length of line - float deviation = 0.2; // how quickly can it change direction - + double deviation = 0.2; // how quickly can it change direction int x[h]; @@ -73,15 +87,15 @@ void VScreensaver::threadMethod() int i; int head = -1; int tail; - float direction = 0; - float fx, fy, dd; - const float pi2 = 6.28318; - float halfdeviation = deviation / 2; + double direction = 0; + double fx, fy, dd; + const double pi2 = 6.28318; + double halfdeviation = deviation / 2; for(i = 0; i < h; i++) x[i] = -1; - fx = x[0] = 50; - fy = y[0] = 50; + fx = x[0] = 50.0; + fy = y[0] = 50.0; DrawStyle &black=DrawStyle::BLACK; DrawStyle &light=DrawStyle::SELECTHIGHLIGHT; @@ -110,10 +124,12 @@ void VScreensaver::threadMethod() if (fy < 0) fy += screenHeight; if (fy >= screenHeight) fy -= screenHeight; - x[head] = (int)fx; - y[head] = (int)fy; + x[head] = static_cast(fx); + y[head] = static_cast(fy); surface->drawPoint(x[head], y[head], light); // was rgba + + if (threadReqStop) return; MILLISLEEP(10); } } diff --git a/vscreensaver.h b/vscreensaver.h index bbd0286..b9676eb 100644 --- a/vscreensaver.h +++ b/vscreensaver.h @@ -1,5 +1,5 @@ /* - Copyright 2007 Chris Tallon + Copyright 2007-2020 Chris Tallon This file is part of VOMP. @@ -14,23 +14,18 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef VSCREENSAVER_H #define VSCREENSAVER_H -#include -#include -#include +#include +#include #include "boxx.h" -#include "threadsystem.h" - - -class VScreensaver : public Boxx, public Thread_TYPE +class VScreensaver : public Boxx { public: VScreensaver(); @@ -40,11 +35,15 @@ class VScreensaver : public Boxx, public Thread_TYPE void draw(); private: - - virtual void threadMethod(); + void threadMethod(); + void stopThread(); int screenHeight; int screenWidth; + + std::thread ssThread; + std::mutex ssThreadStartProtect; + bool threadReqStop{}; }; #endif -- 2.39.5