Skip to content

Commit

Permalink
Re: #541 - Utilize IComponent::AttributesChanged for EC_ParticleSyste…
Browse files Browse the repository at this point in the history
…m and EC_Billboard components. EC_Fog left untouched intentionally as it wouldn't gain anything from the refactoring (it's not interested in which attributes have been changed, as it does the same update routine always).
  • Loading branch information
Stinkfist0 committed Oct 30, 2012
1 parent e642875 commit 0fba536
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
14 changes: 6 additions & 8 deletions src/Core/OgreRenderingModule/EC_Billboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ EC_Billboard::EC_Billboard(Scene* scene) :
connect(materialAsset_.get(), SIGNAL(TransferFailed(IAssetTransfer*, QString)), this, SLOT(OnMaterialAssetFailed(IAssetTransfer*, QString)), Qt::UniqueConnection);

connect(this, SIGNAL(ParentEntitySet()), SLOT(OnParentEntitySet()));
connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), SLOT(OnAttributeUpdated(IAttribute*)));
}

EC_Billboard::~EC_Billboard()
Expand Down Expand Up @@ -190,20 +189,19 @@ void EC_Billboard::DetachBillboard()
// Matches OgrePrerequisites.h:62 (OGRE_VERSION #define)
#define OGRE_VER(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))

void EC_Billboard::OnAttributeUpdated(IAttribute *attribute)
void EC_Billboard::AttributesChanged()
{
if (attribute == &position || attribute == &width || attribute == &height || attribute == &rotation)
if (!ViewEnabled())
return;
if (position.ValueChanged() || width.ValueChanged() || height.ValueChanged() || rotation.ValueChanged())
{
if (billboard_)
UpdateBillboardProperties();
else
CreateBillboard();
}
else if (attribute == &materialRef)
if (materialRef.ValueChanged())
{
if (!ViewEnabled())
return;

// In the case of empty ref setting it to the ref listener will
// make sure we don't get called to OnMaterialAssetLoaded. This would happen
// if something touches the previously set material in the asset system (eg. reload).
Expand All @@ -222,7 +220,7 @@ void EC_Billboard::OnAttributeUpdated(IAttribute *attribute)
LogError("EC_Billboard: Failed to reset visuals after material was removed: " + std::string(e.what()));
}
}
else if (attribute == &show)
if (show.ValueChanged())
{
if (show.Get())
Show();
Expand Down
5 changes: 2 additions & 3 deletions src/Core/OgreRenderingModule/EC_Billboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ private slots:
/// Component removed; check if it was the placeable
void OnComponentRemoved(IComponent* component, AttributeChange::Type change);

/// Called when some of the attributes has been changed
void OnAttributeUpdated(IAttribute *attribute);

/// Called when material asset has been downloaded.
void OnMaterialAssetLoaded(AssetPtr material);

Expand All @@ -141,6 +138,8 @@ private slots:
/// Detach billboardset from the placeable's scene node
void DetachBillboard();

void AttributesChanged();

/// Ogre world ptr
OgreWorldWeakPtr world_;

Expand Down
32 changes: 14 additions & 18 deletions src/Core/OgreRenderingModule/EC_ParticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ EC_ParticleSystem::EC_ParticleSystem(Scene* scene):
world_ = scene->GetWorld<OgreWorld>();

connect(this, SIGNAL(ParentEntitySet()), this, SLOT(EntitySet()));
connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), this, SLOT(OnAttributeUpdated(IAttribute*)));

particleAsset_ = AssetRefListenerPtr(new AssetRefListener());
connect(particleAsset_.get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnParticleAssetLoaded(AssetPtr)), Qt::UniqueConnection);
Expand Down Expand Up @@ -210,32 +209,29 @@ void EC_ParticleSystem::SoftStopParticleSystem(const QString& systemName)
system->setEmitting(false);
}

void EC_ParticleSystem::OnAttributeUpdated(IAttribute *attribute)
void EC_ParticleSystem::AttibutesChanged()
{
if(attribute == &castShadows)
{
for (std::map<QString, Ogre::ParticleSystem*>::const_iterator i = particleSystems_.begin(); i != particleSystems_.end(); ++i)
if (!ViewEnabled())
return;

if (castShadows.ValueChanged())
for(std::map<QString, Ogre::ParticleSystem*>::const_iterator i = particleSystems_.begin(); i != particleSystems_.end(); ++i)
i->second->setCastShadows(castShadows.Get());
}
else if (attribute == &renderingDistance)
{
for (std::map<QString, Ogre::ParticleSystem*>::const_iterator i = particleSystems_.begin(); i != particleSystems_.end(); ++i)

if (renderingDistance.ValueChanged())
for(std::map<QString, Ogre::ParticleSystem*>::const_iterator i = particleSystems_.begin(); i != particleSystems_.end(); ++i)
i->second->setRenderingDistance(renderingDistance.Get());
}
else if (attribute == &particleRef)

if (particleRef.ValueChanged())
{
if (!ViewEnabled())
return;
if (!particleRef.Get().ref.trimmed().isEmpty())
particleAsset_->HandleAssetRefChange(&particleRef);
else
// If the ref is cleared, delete any existing particle systems.
else // If the ref is cleared, delete any existing particle systems.
DeleteParticleSystem();
}
else if (attribute == &enabled)

if (enabled.ValueChanged())
{
if (!ViewEnabled())
return;
if (enabled.Get() && particleAsset_->Asset())
CreateParticleSystem(); // True: create/start all systems
else if (!enabled.Get())
Expand Down
2 changes: 1 addition & 1 deletion src/Core/OgreRenderingModule/EC_ParticleSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public slots:
void SoftStopParticleSystem(const QString& systemName = QString());

private slots:
void OnAttributeUpdated(IAttribute *attribute);
void OnParticleAssetLoaded(AssetPtr asset);
void OnParticleAssetFailed(IAssetTransfer* transfer, QString reason);
void EntitySet();
void OnComponentRemoved(IComponent *component, AttributeChange::Type change);

private:
void AttibutesChanged();
ComponentPtr FindPlaceable() const;

std::map<QString, Ogre::ParticleSystem*> particleSystems_;
Expand Down

0 comments on commit 0fba536

Please sign in to comment.