#include <QMouseEvent>
#include <QPainter>
+// Uncomment for Scope debugging.
+//#define DEBUG_ASW
+
+#ifdef DEBUG_ASW
+#include <QDebug>
+#endif
+
const int REALTIME_FPS = 30;
const QColor light(250, 238, 226, 255);
void AbstractScopeWidget::prodHUDThread()
{
if (this->visibleRegion().isEmpty()) {
-// qDebug() << "Scope " << m_widgetName << " is not visible. Not calculating HUD.";
+#ifdef DEBUG_ASW
+ qDebug() << "Scope " << m_widgetName << " is not visible. Not calculating HUD.";
+#endif
} else {
if (m_semaphoreHUD.tryAcquire(1)) {
Q_ASSERT(!m_threadHUD.isRunning());
m_newHUDFrames.fetchAndStoreRelaxed(0);
m_newHUDUpdates.fetchAndStoreRelaxed(0);
m_threadHUD = QtConcurrent::run(this, &AbstractScopeWidget::renderHUD, m_accelFactorHUD);
-// qDebug() << "HUD thread started in " << m_widgetName;
+#ifdef DEBUG_ASW
+ qDebug() << "HUD thread started in " << m_widgetName;
+#endif
- } else {
-// qDebug() << "HUD semaphore locked, not prodding in " << m_widgetName << ". Thread running: " << m_threadHUD.isRunning();
}
+#ifdef DEBUG_ASW
+ else {
+ qDebug() << "HUD semaphore locked, not prodding in " << m_widgetName << ". Thread running: " << m_threadHUD.isRunning();
+ }
+#endif
}
}
// Only start a new thread if the scope is actually visible
// and not hidden by another widget on the stack and if user want the scope to update.
if (this->visibleRegion().isEmpty() || (!m_aAutoRefresh->isChecked() && !m_requestForcedUpdate)) {
-// qDebug() << "Scope " << m_widgetName << " is not visible. Not calculating scope.";
+#ifdef DEBUG_ASW
+ qDebug() << "Scope " << m_widgetName << " is not visible. Not calculating scope.";
+#endif
} else {
// Try to acquire the semaphore. This must only succeed if m_threadScope is not running
// anymore. Therefore the semaphore must NOT be released before m_threadScope ends.
m_threadScope = QtConcurrent::run(this, &AbstractScopeWidget::renderScope, m_accelFactorScope);
m_requestForcedUpdate = false;
-// qDebug() << "Scope thread started in " << m_widgetName;
+#ifdef DEBUG_ASW
+ qDebug() << "Scope thread started in " << m_widgetName;
+#endif
} else {
-// qDebug() << "Scope semaphore locked, not prodding in " << m_widgetName << ". Thread running: " << m_threadScope.isRunning();
+#ifdef DEBUG_ASW
+ qDebug() << "Scope semaphore locked, not prodding in " << m_widgetName << ". Thread running: " << m_threadScope.isRunning();
+#endif
}
}
}
void AbstractScopeWidget::prodBackgroundThread()
{
if (this->visibleRegion().isEmpty()) {
-// qDebug() << "Scope " << m_widgetName << " is not visible. Not calculating background.";
+#ifdef DEBUG_ASW
+ qDebug() << "Scope " << m_widgetName << " is not visible. Not calculating background.";
+#endif
} else {
if (m_semaphoreBackground.tryAcquire(1)) {
Q_ASSERT(!m_threadBackground.isRunning());
m_newBackgroundFrames.fetchAndStoreRelaxed(0);
m_newBackgroundUpdates.fetchAndStoreRelaxed(0);
m_threadBackground = QtConcurrent::run(this, &AbstractScopeWidget::renderBackground, m_accelFactorBackground);
-// qDebug() << "Background thread started in " << m_widgetName;
+
+#ifdef DEBUG_ASW
+ qDebug() << "Background thread started in " << m_widgetName;
+#endif
} else {
-// qDebug() << "Background semaphore locked, not prodding in " << m_widgetName << ". Thread running: " << m_threadBackground.isRunning();
+#ifdef DEBUG_ASW
+ qDebug() << "Background semaphore locked, not prodding in " << m_widgetName << ". Thread running: " << m_threadBackground.isRunning();
+#endif
}
}
}
void AbstractScopeWidget::forceUpdate(bool doUpdate)
{
-// qDebug() << "Force update called in " << widgetName() << ". Arg: " << doUpdate;
+#ifdef DEBUG_ASW
+ qDebug() << "Force update called in " << widgetName() << ". Arg: " << doUpdate;
+#endif
+
if (!doUpdate) {
return;
}
}
if ((m_newHUDFrames > 0 && m_aAutoRefresh->isChecked()) || m_newHUDUpdates > 0) {
-// qDebug() << "Trying to start a new HUD thread for " << m_widgetName
-// << ". New frames/updates: " << m_newHUDFrames << "/" << m_newHUDUpdates;
+#ifdef DEBUG_ASW
+ qDebug() << "Trying to start a new HUD thread for " << m_widgetName
+ << ". New frames/updates: " << m_newHUDFrames << "/" << m_newHUDUpdates;
+#endif
prodHUDThread();;
}
}
{
// The signal can be received before the thread has really finished. So we
// need to wait until it has really finished before starting a new thread.
-// qDebug() << "Scope rendering has finished, waiting for termination in " << m_widgetName;
+#ifdef DEBUG_ASW
+ qDebug() << "Scope rendering has finished, waiting for termination in " << m_widgetName;
+#endif
m_threadScope.waitForFinished();
m_imgScope = m_threadScope.result();
}
if ((m_newScopeFrames > 0 && m_aAutoRefresh->isChecked()) || m_newScopeUpdates > 0) {
-// qDebug() << "Trying to start a new scope thread for " << m_widgetName
-// << ". New frames/updates: " << m_newScopeFrames << "/" << m_newScopeUpdates;
+#ifdef DEBUG_ASW
+ qDebug() << "Trying to start a new scope thread for " << m_widgetName
+ << ". New frames/updates: " << m_newScopeFrames << "/" << m_newScopeUpdates;
+#endif
prodScopeThread();
}
}
void AbstractScopeWidget::slotBackgroundRenderingFinished(uint mseconds, uint oldFactor)
{
-// qDebug() << "Background rendering has finished, waiting for termination in " << m_widgetName;
+#ifdef DEBUG_ASW
+ qDebug() << "Background rendering has finished, waiting for termination in " << m_widgetName;
+#endif
m_threadBackground.waitForFinished();
m_imgBackground = m_threadBackground.result();
}
if ((m_newBackgroundFrames > 0 && m_aAutoRefresh->isChecked()) || m_newBackgroundUpdates > 0) {
-// qDebug() << "Trying to start a new background thread for " << m_widgetName
-// << ". New frames/updates: " << m_newBackgroundFrames << "/" << m_newBackgroundUpdates;
+#ifdef DEBUG_ASW
+ qDebug() << "Trying to start a new background thread for " << m_widgetName
+ << ". New frames/updates: " << m_newBackgroundFrames << "/" << m_newBackgroundUpdates;
+#endif
prodBackgroundThread();;
}
}
m_newScopeFrames.fetchAndAddRelaxed(1);
m_newBackgroundFrames.fetchAndAddRelaxed(1);
-// qDebug() << "Monitor incoming. New frames total HUD/Scope/Background: " << m_newHUDFrames
-// << "/" << m_newScopeFrames << "/" << m_newBackgroundFrames;
+#ifdef DEBUG_ASW
+ qDebug() << "Monitor incoming. New frames total HUD/Scope/Background: " << m_newHUDFrames
+ << "/" << m_newScopeFrames << "/" << m_newBackgroundFrames;
+#endif
if (this->visibleRegion().isEmpty()) {
-// qDebug() << "Scope of widget " << m_widgetName << " is not at the top, not rendering.";
+#ifdef DEBUG_ASW
+ qDebug() << "Scope of widget " << m_widgetName << " is not at the top, not rendering.";
+#endif
} else {
if (m_aAutoRefresh->isChecked()) {
prodHUDThread();
m_requestForcedUpdate = true;
}
}
+
+
+#ifdef DEBUG_ASW
+#undef DEBUG_ASW
+#endif