Skip to content

Commit

Permalink
GRAPHICS: Make Highlightable framerate independent
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii authored and DrMcCoy committed Aug 20, 2017
1 parent 4191625 commit 17096f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/graphics/aurora/highlightable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

#include "src/events/events.h"
#include "src/graphics/aurora/highlightable.h"

namespace Graphics {
Expand All @@ -27,7 +28,8 @@ namespace Aurora {
Highlightable::Highlightable() : _highlightable(false), _isHighlighted(false),
_deltaR(0), _deltaG(0), _deltaB(0), _deltaA(0),
_upperBoundR(0), _upperBoundG(0), _upperBoundB(0), _upperBoundA(0),
_lowerBoundR(0), _lowerBoundG(0), _lowerBoundB(0), _lowerBoundA(0) {
_lowerBoundR(0), _lowerBoundG(0), _lowerBoundB(0), _lowerBoundA(0),
_prevIncTime(EventMan.getTimestamp()) {

}

Expand Down Expand Up @@ -88,10 +90,13 @@ void Highlightable::flipHighlightDelta() {

void Highlightable::incrementColor(float initialR, float initialG, float initialB, float initialA,
float &r, float &g, float &b, float &a) {
r = initialR + _deltaR;
g = initialG + _deltaG;
b = initialB + _deltaB;
a = initialA + _deltaA;
uint32 time = EventMan.getTimestamp();
float dt = (time - _prevIncTime) / 50.f;

r = initialR + _deltaR * dt;
g = initialG + _deltaG * dt;
b = initialB + _deltaB * dt;
a = initialA + _deltaA * dt;

if (_upperBoundR < r || _upperBoundG < g || _upperBoundB < b || _upperBoundA < a ||
_lowerBoundR > r || _lowerBoundG > g || _lowerBoundB > b || _lowerBoundA > a) {
Expand All @@ -102,6 +107,8 @@ void Highlightable::incrementColor(float initialR, float initialG, float initial
b = initialB;
a = initialA;
}

_prevIncTime = time;
}

} // End of namespace Aurora
Expand Down
4 changes: 4 additions & 0 deletions src/graphics/aurora/highlightable.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef GRAPHICS_AURORA_HIGHLIGHTABLE_H
#define GRAPHICS_AURORA_HIGHLIGHTABLE_H

#include "src/common/types.h"

namespace Graphics {

namespace Aurora {
Expand Down Expand Up @@ -76,6 +78,8 @@ class Highlightable {
float _lowerBoundG;
float _lowerBoundB;
float _lowerBoundA;

uint32 _prevIncTime;
};

} // End of namespace Aurora
Expand Down

0 comments on commit 17096f2

Please sign in to comment.