Skip to content

Commit

Permalink
Fixed|libdeng2: AssetGroup must observe state changes in members
Browse files Browse the repository at this point in the history
The state of the group depends on the state of the members.
  • Loading branch information
skyjake committed Apr 27, 2013
1 parent 60199ac commit 5a99114
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions doomsday/libdeng2/include/de/core/asset.h
Expand Up @@ -114,6 +114,11 @@ class DENG2_PUBLIC AssetGroup : public Asset,
return *this;
}

AssetGroup &operator -= (Asset const &dep) {
remove(dep);
return *this;
}

bool has(Asset const &dep) const;

void setPolicy(Asset const &asset, Policy policy);
Expand Down
8 changes: 7 additions & 1 deletion doomsday/libdeng2/src/core/asset.cpp
Expand Up @@ -110,6 +110,7 @@ void AssetGroup::clear()
DENG2_FOR_EACH(Members, i, d->deps)
{
i->first->audienceForDeletion -= this;
i->first->audienceForStateChange -= this;
}

d->deps.clear();
Expand All @@ -120,12 +121,14 @@ void AssetGroup::insert(Asset const &asset, Policy policy)
{
d->deps[&asset] = policy;
asset.audienceForDeletion += this;
asset.audienceForStateChange += this;
d->update(*this);
}

void AssetGroup::remove(Asset const &asset)
{
asset.audienceForDeletion -= this;
asset.audienceForStateChange -= this;
d->deps.erase(&asset);
d->update(*this);
}
Expand All @@ -150,7 +153,10 @@ AssetGroup::Members const &AssetGroup::all() const

void AssetGroup::assetDeleted(Asset &asset)
{
remove(asset);
if(has(asset))
{
remove(asset);
}
}

void AssetGroup::assetStateChanged(Asset &)
Expand Down

0 comments on commit 5a99114

Please sign in to comment.