Browse Source

Calculate fade based on frame level time

This makes the frame lenght FPS independant and fixes #459
pull/464/head
Anders Jenbo 6 years ago
parent
commit
aa23194591
  1. 7
      Source/palette.cpp
  2. 8
      SourceX/DiabloUI/diabloui.cpp
  3. 2
      SourceX/DiabloUI/diabloui.h

7
Source/palette.cpp

@ -167,7 +167,6 @@ void SetFadeLevel(DWORD fadeval)
system_palette[i].peGreen = (fadeval * logical_palette[i].peGreen) >> 8;
system_palette[i].peBlue = (fadeval * logical_palette[i].peBlue) >> 8;
}
Sleep(3);
palette_update();
// Workaround for flickering mouse in caves https://github.com/diasurgical/devilutionX/issues/7
@ -185,7 +184,8 @@ void PaletteFadeIn(int fr)
int i;
ApplyGamma(logical_palette, orig_palette, 256);
for (i = 0; i < 256; i += fr) {
DWORD tc = SDL_GetTicks();
for (i = 0; i < 256; i = (SDL_GetTicks() - tc) / 1.875) { // 1000ms / 60 * 32
SetFadeLevel(i);
}
SetFadeLevel(256);
@ -198,7 +198,8 @@ void PaletteFadeOut(int fr)
int i;
if (sgbFadedIn) {
for (i = 256; i > 0; i -= fr) {
DWORD tc = SDL_GetTicks();
for (i = 256; i > 0; i = 256 - (SDL_GetTicks() - tc) / 1.875) { // 1000ms / 60 * 32
SetFadeLevel(i);
}
SetFadeLevel(0);

8
SourceX/DiabloUI/diabloui.cpp

@ -500,12 +500,16 @@ void LoadBackgroundArt(const char *pszFile)
ApplyGamma(logical_palette, orig_palette, 256);
}
void UiFadeIn(int steps)
void UiFadeIn()
{
static DWORD tc;
if (fadeValue == 0 && tc == 0)
tc = SDL_GetTicks();
if (fadeValue < 256) {
fadeValue += steps;
fadeValue = (SDL_GetTicks() - tc) / 1.875; // 1000ms / 60 * 32
if (fadeValue > 256) {
fadeValue = 256;
tc = 0;
}
}

2
SourceX/DiabloUI/diabloui.h

@ -39,7 +39,7 @@ constexpr size_t size(T (&)[N])
extern void (*gfnSoundFunction)(char *file);
bool IsInsideRect(const SDL_Event &event, const SDL_Rect &rect);
void UiFadeIn(int steps = 16);
void UiFadeIn();
bool UiFocusNavigation(SDL_Event *event);
bool UiItemMouseEvents(SDL_Event *event, UiItem *items, std::size_t size);
int GetCenterOffset(int w, int bw = 0);

Loading…
Cancel
Save