Skip to content

Commit

Permalink
engine: more engine adaptations to latest attribute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Aug 13, 2017
1 parent 5aca38a commit 638b34a
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 26 deletions.
44 changes: 25 additions & 19 deletions engine/src/collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,9 @@ bool Collection::contains(quint32 functionId)
Doc* doc = qobject_cast <Doc*> (parent());
Q_ASSERT(doc != NULL);

QListIterator <quint32> it(m_functions);
while (it.hasNext() == true)
foreach (quint32 fid, m_functions)
{
Function* function = doc->function(it.next());
Function* function = doc->function(fid);
// contains() can be called during init, function may be NULL
if (function == NULL)
continue;
Expand All @@ -278,24 +277,26 @@ FunctionParent Collection::functionParent() const
return FunctionParent(FunctionParent::Function, id());
}

void Collection::preRun(MasterTimer* timer)
void Collection::preRun(MasterTimer *timer)
{
Doc* doc = this->doc();
Doc *doc = this->doc();
Q_ASSERT(doc != NULL);
{
QMutexLocker locker(&m_functionListMutex);
m_runningChildren.clear();
foreach(QVariant fid, m_functions)
foreach (quint32 fid, m_functions)
{
Function* function = doc->function(fid.toUInt());
Function *function = doc->function(fid);
Q_ASSERT(function != NULL);

m_intensityOverrideIds << function->requestAttributeOverride(Function::Intensity, getAttributeValue(Function::Intensity));

// Append the IDs of all functions started by this collection
// to a set so that we can track which of them are still controlled
// by this collection which are not.
m_runningChildren << function->id();

// Listen to the children's stopped signals so that this collection
// Listen to the children's stopped signals so that this Collection
// can give up its rights to stop the function later.
connect(function, SIGNAL(stopped(quint32)),
this, SLOT(slotChildStopped(quint32)));
Expand All @@ -305,7 +306,7 @@ void Collection::preRun(MasterTimer* timer)
connect(function, SIGNAL(running(quint32)),
this, SLOT(slotChildStarted(quint32)));

function->adjustAttribute(getAttributeValue(Function::Intensity), Function::Intensity);
//function->adjustAttribute(getAttributeValue(Function::Intensity), Function::Intensity);
function->start(timer, functionParent(), 0, overrideFadeInSpeed(), overrideFadeOutSpeed(), overrideDuration());
}
m_tick = 1;
Expand All @@ -315,18 +316,18 @@ void Collection::preRun(MasterTimer* timer)

void Collection::setPause(bool enable)
{
Doc* doc = this->doc();
Doc *doc = this->doc();
Q_ASSERT(doc != NULL);
foreach (quint32 fid, m_runningChildren)
{
Function* function = doc->function(fid);
Function *function = doc->function(fid);
Q_ASSERT(function != NULL);
function->setPause(enable);
}
Function::setPause(enable);
}

void Collection::write(MasterTimer* timer, QList<Universe *> universes)
void Collection::write(MasterTimer *timer, QList<Universe *> universes)
{
Q_UNUSED(timer);
Q_UNUSED(universes);
Expand All @@ -340,13 +341,13 @@ void Collection::write(MasterTimer* timer, QList<Universe *> universes)
else if (m_tick == 2)
{
m_tick = 0;
Doc* doc = this->doc();
Doc *doc = this->doc();
Q_ASSERT(doc != NULL);

QMutexLocker locker(&m_functionListMutex);
foreach (quint32 fid, m_runningChildren)
{
Function* function = doc->function(fid);
Function *function = doc->function(fid);
Q_ASSERT(function != NULL);

// First tick may correspond to this collection starting the function
Expand Down Expand Up @@ -386,9 +387,9 @@ void Collection::postRun(MasterTimer* timer, QList<Universe *> universes)

m_runningChildren.clear();

foreach(QVariant fid, m_functions)
for (int i = 0; i < m_functions.count(); i++)
{
Function* function = doc->function(fid.toUInt());
Function* function = doc->function(m_functions.at(i));
Q_ASSERT(function != NULL);

disconnect(function, SIGNAL(stopped(quint32)),
Expand All @@ -398,7 +399,11 @@ void Collection::postRun(MasterTimer* timer, QList<Universe *> universes)
disconnect(function, SIGNAL(running(quint32)),
this, SLOT(slotChildStarted(quint32)));
}

function->releaseAttributeOverride(m_intensityOverrideIds.at(i));
}

m_intensityOverrideIds.clear();
}

Function::postRun(timer, universes);
Expand Down Expand Up @@ -426,11 +431,12 @@ int Collection::adjustAttribute(qreal fraction, int attributeId)
Q_ASSERT(document != NULL);

QMutexLocker locker(&m_functionListMutex);
foreach(QVariant fid, m_functions)

for (int i = 0; i < m_functions.count(); i++)
{
Function* function = document->function(fid.toUInt());
Function* function = document->function(m_functions.at(i));
Q_ASSERT(function != NULL);
function->adjustAttribute(getAttributeValue(Function::Intensity), Function::Intensity);
function->adjustAttribute(getAttributeValue(Function::Intensity), m_intensityOverrideIds.at(i));
}
}

Expand Down
11 changes: 11 additions & 0 deletions engine/src/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class QXmlStreamReader;
* @{
*/

typedef struct
{
quint32 m_id;
int m_intensityId;
} ChildFunction;

class Collection : public Function
{
Q_OBJECT
Expand Down Expand Up @@ -97,7 +103,12 @@ public slots:
void slotFunctionRemoved(quint32 function);

protected:
/** The list of Function IDs added to this Collection */
QList <quint32> m_functions;
/** A list of intesity attribute override IDs populated when this Collection is
* started and cleaned when it's stopped */
QList <int> m_intensityOverrideIds;

mutable QMutex m_functionListMutex;

/*********************************************************************
Expand Down
2 changes: 1 addition & 1 deletion engine/src/show.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected slots:
* Attributes
*************************************************************************/
public:
/** @reimpl */
/** @reimp */
int adjustAttribute(qreal fraction, int attributeId = 0);
};

Expand Down
11 changes: 11 additions & 0 deletions engine/src/showfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ShowFunction::ShowFunction(QObject *parent)
m_duration = 0;
m_color = QColor();
m_locked = false;
m_intensityOverrideId = -1;
}

void ShowFunction::setFunctionID(quint32 id)
Expand Down Expand Up @@ -137,6 +138,16 @@ bool ShowFunction::isLocked() const
return m_locked;
}

int ShowFunction::intensityOverrideId() const
{
return m_intensityOverrideId;
}

void ShowFunction::setIntensityOverrideId(int id)
{
m_intensityOverrideId = id;
}

/************************************************************************
* Load & Save
***********************************************************************/
Expand Down
17 changes: 14 additions & 3 deletions engine/src/showfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,34 @@ class ShowFunction: public QObject
ShowFunction(QObject *parent = 0);
virtual ~ShowFunction() {}

/** Get/Set the Function ID this class represents */
void setFunctionID(quint32 id);
quint32 functionID() const;

/** Get/Set the Function start time over a Show timeline */
void setStartTime(quint32 time);
quint32 startTime() const;

/** Get/Set this item duration, not necessarily corresponding
* to the original Function duration */
void setDuration(quint32 duration);
quint32 duration() const;

/** Get/Set the color of the item when rendered in the Show Manager */
void setColor(QColor color);
QColor color() const;

static QColor defaultColor(Function::Type type);

/** Set the lock state of this ShowFunction */
/** Get/Set the lock state of this ShowFunction */
void setLocked(bool locked);

/** Get the lock state of this ShowFunction */
bool isLocked() const;

/** Get/Set the intensity attribute override ID to
* control a Function intensity */
int intensityOverrideId() const;
void setIntensityOverrideId(int id);

signals:
void functionIDChanged();
void startTimeChanged();
Expand All @@ -91,6 +99,9 @@ class ShowFunction: public QObject
/** Flag to indicate if this function is locked in the Show Manager timeline */
bool m_locked;

/** Intensity attribute override ID */
int m_intensityOverrideId;

/************************************************************************
* Load & Save
***********************************************************************/
Expand Down
8 changes: 5 additions & 3 deletions engine/src/showrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ void ShowRunner::write()
{
if (track->showFunctions().contains(sf))
{
f->adjustAttribute(m_intensityMap[track->id()], Function::Intensity);
int intOverrideId = f->requestAttributeOverride(Function::Intensity, m_intensityMap[track->id()]);
//f->adjustAttribute(m_intensityMap[track->id()], Function::Intensity);
sf->setIntensityOverrideId(intOverrideId);
break;
}
}
Expand All @@ -178,7 +180,7 @@ void ShowRunner::write()
}

// Phase 2. Check if we need to stop some running Functions
// It is done in reverse order for two reason:
// It is done in reverse order for two reasons:
// 1- m_runningQueue is not ordered by stop time
// 2- to avoid messing up with indices when an entry is removed
for(int i = m_runningQueue.count() - 1; i >= 0; i--)
Expand Down Expand Up @@ -231,7 +233,7 @@ void ShowRunner::adjustIntensity(qreal fraction, Track *track)
{
Function *rf = m_runningQueue.at(i).first;
if (f == rf)
f->adjustAttribute(fraction, Function::Intensity);
f->adjustAttribute(fraction, sf->intensityOverrideId());
}
}
}
Expand Down
1 change: 1 addition & 0 deletions engine/src/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public slots:
bool fullscreen();
void setFullscreen(bool enable);

/** @reimp */
int adjustAttribute(qreal fraction, int attributeId);

signals:
Expand Down

0 comments on commit 638b34a

Please sign in to comment.