]> git.vomp.tv Git - vompclient.git/commitdiff
Move functions into class in Colour, Switch VScreensaver to std::thread
authorChris Tallon <chris@vomp.tv>
Sat, 11 Apr 2020 17:29:05 +0000 (18:29 +0100)
committerChris Tallon <chris@vomp.tv>
Sat, 11 Apr 2020 17:29:05 +0000 (18:29 +0100)
colour.cc
colour.h
vscreensaver.cc
vscreensaver.h

index eff30ed1f087a8eb6691418d3c6b71dc58c7b1d4..699dd0c30f1fdfdc58617786c178423246f2ca9c 100644 (file)
--- 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 <https://www.gnu.org/licenses/>.
 */
 
 #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
index 0224cd476922a0ea881fca56a37758238e518d3e..47f338a6fc4937d536062d03f032b8dbf4cbc508 100644 (file)
--- 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 <https://www.gnu.org/licenses/>.
 */
 
 #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
index 7355467591e39595ab34bb72c350e947f9961bb0..3d1a83afbf94a7db11932ae83451792e597eba2e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright 2004-2005 Chris Tallon
+    Copyright 2004-2020 Chris Tallon
 
     This file is part of VOMP.
 
     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 <https://www.gnu.org/licenses/>.
 */
 
-#include "vscreensaver.h"
+#include <stdlib.h>
+#include <time.h>
+#include <math.h>
 
 #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<int>(fx);
+    y[head] = static_cast<int>(fy);
 
     surface->drawPoint(x[head], y[head], light); // was rgba
+
+    if (threadReqStop) return;
     MILLISLEEP(10);
   }
 }
index bbd02865e16d088e4864329ce4fdef9cf72687be..b9676ebf347954df05caa87813be19e723d438a6 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright 2007 Chris Tallon
+    Copyright 2007-2020 Chris Tallon
 
     This file is part of VOMP.
 
     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 <https://www.gnu.org/licenses/>.
 */
 
 #ifndef VSCREENSAVER_H
 #define VSCREENSAVER_H
 
-#include <stdlib.h>
-#include <time.h>
-#include <math.h>
+#include <thread>
+#include <mutex>
 
 #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