Skip to content

Commit

Permalink
Avoid Resource unnecessarily asking for new data when nothing changed.
Browse files Browse the repository at this point in the history
This wasn't as simple, turns out I had to fix setFallback() to keep
doing the right thing.
  • Loading branch information
mosra committed Feb 14, 2020
1 parent 2322267 commit 47e1106
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ See also:
- Dynamic plugins on static Magnum builds on Windows were accidentally
searched for in the `lib/` directory instead of `bin/`, and in some cases
in `bin/` instead of `lib/` on Unix platforms.
- @ref Resource was unnecessarily querying the @ref ResourceManager for
updated data even in cases where no resource update was done since last
check

@subsection changelog-latest-deprecated Deprecated APIs

Expand Down
2 changes: 1 addition & 1 deletion src/Magnum/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ template<class T, class U> void Resource<T, U>::acquire() {
if(_state == ResourceState::Final) return;

/* Nothing changed since last check */
if(_manager->lastChange() < _lastCheck) return;
if(_manager->lastChange() <= _lastCheck) return;

/* Acquire new data and save last check time */
const typename Implementation::ResourceManagerData<T>::Data& d = _manager->data(_key);
Expand Down
3 changes: 3 additions & 0 deletions src/Magnum/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ template<class T> void ResourceManagerData<T>::set(const ResourceKey key, T* con
template<class T> void ResourceManagerData<T>::setFallback(T* const data) {
safeDelete(_fallback);
_fallback = data;
/* Notify resources also in this case, as some of them could go from empty
to a fallback (or from a fallback to empty) */
++_lastChange;
}

template<class T> void ResourceManagerData<T>::free() {
Expand Down

0 comments on commit 47e1106

Please sign in to comment.