diff options
author | Julian T <julian@jtle.dk> | 2021-01-24 18:13:44 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-01-24 18:22:11 +0100 |
commit | 41ea2d8f94043d49fc26aaaa8030a73dcfdc2da9 (patch) | |
tree | fcc07052425c65b38c1724f4fc30299a1cb48716 /app/rendercoord.hpp | |
parent | a38e6014ea5441e9d29fcb3b5607cd94e4061cff (diff) |
Create rust project
Diffstat (limited to 'app/rendercoord.hpp')
-rw-r--r-- | app/rendercoord.hpp | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/app/rendercoord.hpp b/app/rendercoord.hpp deleted file mode 100644 index eea1b40..0000000 --- a/app/rendercoord.hpp +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef RENDER_THREAD_H -#define RENDER_THREAD_H - -#include "draw.hpp" -#include "config.hpp" -#include <atomic> -#include <qlabel.h> -#include <render.hpp> - -#include <qobject.h> -#include <qrgb.h> -#include <qthread.h> -#include <qsemaphore.h> -#include <vector> -// https://doc.qt.io/archives/qt-4.8/qt-threads-mandelbrot-example.html - -class RenderThread : public QThread { - Q_OBJECT - - public: - RenderThread(Renderer r, unsigned threads, const Config &cfg, QObject *parent = nullptr, unsigned id = 0); - - // Returns 0 if successful or 1 if busy - int render(QRgb *buffer, unsigned samples); - - void pause(); - void resume(); - - unsigned stop(); - void stopAt(int at); - - unsigned current_samples(); - - signals: - void done(unsigned workerid); - - protected: - void run(); - - QSemaphore m_lock; - - QRgb *m_writebuffer; - std::atomic_int m_samples; - std::atomic_int m_current_samples; - - Renderer m_render; - - unsigned m_workers; - - Config const m_conf; - - // Value in here means work is to be done - QSemaphore m_work; - QSemaphore m_pause; - unsigned m_id; -}; - -const std::string states[] = { "Stopped", "Running", "Stopping" }; -enum State { stopped, running, stopping }; - -class RenderCoordinator : public QObject { - Q_OBJECT - - public: - RenderCoordinator(QObject *parent, DrawWidget &target, Renderer r, const Config &conf, QLabel *status=nullptr); - void setSamples(unsigned samples); - void render(); - - public slots: - void workerDone(unsigned workerid); - void stop(); - - private slots: - void updateUi(); - - private: - unsigned calcStats(unsigned *max, unsigned *min, double *avg); - - DrawWidget &m_target; - - Renderer m_renderer; - std::vector<RenderThread*> m_workers; - unsigned m_started; - - QLabel *m_status; - QTimer m_timer; - - State m_state; - - const Config &m_conf; -}; - -#endif |