aboutsummaryrefslogtreecommitdiff
path: root/sword2/driver
diff options
context:
space:
mode:
authorTorbjörn Andersson2003-08-25 06:13:28 +0000
committerTorbjörn Andersson2003-08-25 06:13:28 +0000
commitfcc904a8136d2b45ace86e30b1e0690770b964a0 (patch)
treea85cad68ef4cf097f5168d97d7cf1bd78e123bed /sword2/driver
parent10d4af4eaebd86853178d41d5b248fd0b22985f8 (diff)
downloadscummvm-rg350-fcc904a8136d2b45ace86e30b1e0690770b964a0.tar.gz
scummvm-rg350-fcc904a8136d2b45ace86e30b1e0690770b964a0.tar.bz2
scummvm-rg350-fcc904a8136d2b45ace86e30b1e0690770b964a0.zip
FadeServer() is now called from ServiceWindows(), thus eliminating the need
for the making it a timer handler. This should eliminate the occasional glitches I've been seeing with fades not being completed. I'm also hoping that it will fix the problem where the game would sometimes hang when moving between rooms. I know that at least once when I had that happen to me the game was busy-waiting for the palette to fade. At the very least, it's one place less to worry about thread-safety in. svn-id: r9854
Diffstat (limited to 'sword2/driver')
-rw-r--r--sword2/driver/palette.cpp143
-rw-r--r--sword2/driver/palette.h2
-rw-r--r--sword2/driver/rdwin.cpp1
3 files changed, 39 insertions, 107 deletions
diff --git a/sword2/driver/palette.cpp b/sword2/driver/palette.cpp
index 4d228a237e..b70634c12e 100644
--- a/sword2/driver/palette.cpp
+++ b/sword2/driver/palette.cpp
@@ -320,8 +320,6 @@ int32 BS2_SetPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, uint
{
debug(0, "BS2_SetPalette(%d, %d, %d)", startEntry, noEntries, fadeNow);
- StackLock lock(g_sword2->_paletteMutex);
-
if (noEntries == 0) {
RestorePalette();
return RD_OK;
@@ -421,122 +419,55 @@ uint8 GetFadeStatus(void)
return(fadeStatus);
}
-
-void FadeServer(void *)
-
-{
+void FadeServer() {
+ static int32 previousTime = 0;
+ const byte *newPalette = (const byte *) fadePalette;
int32 currentTime;
int16 fadeMultiplier;
int16 i;
- StackLock lock(g_sword2->_paletteMutex);
-
- switch (fadeStatus) {
- case RDFADE_UP:
- currentTime = SVM_timeGetTime();
- if (currentTime >= fadeStartTime + fadeTotalTime) {
- fadeStatus = RDFADE_NONE;
- g_system->set_palette((const byte *) palCopy, 0, 256);
- } else {
- fadeMultiplier = (int16) (((int32) (currentTime - fadeStartTime) * 256) / fadeTotalTime);
- for (i=0; i<256; i++) {
- fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8;
- fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8;
- fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8;
- }
- g_system->set_palette((const byte *) fadePalette, 0, 256);
- }
- break;
-
- case RDFADE_DOWN:
- currentTime = SVM_timeGetTime();
- if (currentTime >= fadeStartTime + fadeTotalTime) {
- memset(fadePalette, 0, sizeof(fadePalette));
- fadeStatus = RDFADE_BLACK;
- } else {
- fadeMultiplier = (int16) (((int32) (fadeTotalTime - (currentTime - fadeStartTime)) * 256) / fadeTotalTime);
- for (i=0; i<256; i++) {
- fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8;
- fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8;
- fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8;
- }
- }
- g_system->set_palette((const byte *) fadePalette, 0, 256);
- break;
- }
-
-
-/*
- int32 currentTime;
- int16 fadeMultiplier;
- int16 i;
- HRESULT hr;
+ // This used to be called through a timer, but is now called from
+ // ServiceWindows() instead, since that's the only place where we
+ // actually update the screen.
+ // If we're not in the process of fading, do nothing.
+ if (fadeStatus != RDFADE_UP && fadeStatus != RDFADE_DOWN)
+ return;
- if (lpPalette == NULL)
+ // I don't know if this is necessary, but let's limit how often the
+ // palette is updated, just to be safe.
+ currentTime = SVM_timeGetTime();
+ if (currentTime - previousTime <= 25)
return;
- if (fadeStatus)
- {
- if (fadeStatus == RDFADE_UP)
- {
- currentTime = timeGetTime();
- if (currentTime >= fadeStartTime + fadeTotalTime)
- {
- fadeStatus = RDFADE_NONE;
- if (bFullScreen)
- hr = IDirectDrawPalette_SetEntries(lpPalette, 0, 0, 256, (LPPALETTEENTRY) &palCopy[0][0]);
- else
- hr = IDirectDrawPalette_SetEntries(lpPalette, 0, 10, 236, (LPPALETTEENTRY) &palCopy[10][0]);
- }
- else
- {
- fadeMultiplier = (int16) (((int32) (currentTime - fadeStartTime) * 256) / fadeTotalTime);
- for (i=0; i<256; i++)
- {
- fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8;
- fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8;
- fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8;
- }
- if (bFullScreen)
- hr = IDirectDrawPalette_SetEntries(lpPalette, 0, 0, 256, (LPPALETTEENTRY) &fadePalette[0][0]);
- else
- hr = IDirectDrawPalette_SetEntries(lpPalette, 0, 10, 236, (LPPALETTEENTRY) &fadePalette[10][0]);
+ previousTime = currentTime;
+
+ if (fadeStatus == RDFADE_UP) {
+ if (currentTime >= fadeStartTime + fadeTotalTime) {
+ fadeStatus = RDFADE_NONE;
+ newPalette = (const byte *) palCopy;
+ } else {
+ fadeMultiplier = (int16) (((int32) (currentTime - fadeStartTime) * 256) / fadeTotalTime);
+ for (i = 0; i < 256; i++) {
+ fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8;
+ fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8;
+ fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8;
}
}
- else if (fadeStatus == RDFADE_DOWN)
- {
- currentTime = timeGetTime();
- if (currentTime >= fadeStartTime + fadeTotalTime)
- {
- for (i=0; i<256; i++)
- {
- fadePalette[i][0] = 0;
- fadePalette[i][1] = 0;
- fadePalette[i][2] = 0;
- }
- fadeStatus = RDFADE_BLACK;
- if (bFullScreen)
- hr = IDirectDrawPalette_SetEntries(lpPalette, 0, 0, 256, (LPPALETTEENTRY) &fadePalette[0][0]);
- else
- hr = IDirectDrawPalette_SetEntries(lpPalette, 0, 10, 236, (LPPALETTEENTRY) &fadePalette[10][0]);
- }
- else
- {
- fadeMultiplier = (int16) (((int32) (fadeTotalTime - (currentTime - fadeStartTime)) * 256) / fadeTotalTime);
- for (i=0; i<256; i++)
- {
- fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8;
- fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8;
- fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8;
- }
- if (bFullScreen)
- hr = IDirectDrawPalette_SetEntries(lpPalette, 0, 0, 256, (LPPALETTEENTRY) &fadePalette[0][0]);
- else
- hr = IDirectDrawPalette_SetEntries(lpPalette, 0, 10, 236, (LPPALETTEENTRY) &fadePalette[10][0]);
+ } else {
+ if (currentTime >= fadeStartTime + fadeTotalTime) {
+ fadeStatus = RDFADE_BLACK;
+ memset(fadePalette, 0, sizeof(fadePalette));
+ } else {
+ fadeMultiplier = (int16) (((int32) (fadeTotalTime - (currentTime - fadeStartTime)) * 256) / fadeTotalTime);
+ for (i = 0; i < 256; i++) {
+ fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8;
+ fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8;
+ fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8;
}
}
}
-*/
+
+ g_system->set_palette(newPalette, 0, 256);
}
diff --git a/sword2/driver/palette.h b/sword2/driver/palette.h
index 0f6cdcf843..ab6d194126 100644
--- a/sword2/driver/palette.h
+++ b/sword2/driver/palette.h
@@ -59,7 +59,7 @@
extern uint8 paletteMatch[64*64*64];
extern int32 RestorePalette(void);
-extern void FadeServer(void *);
+extern void FadeServer();
#endif
diff --git a/sword2/driver/rdwin.cpp b/sword2/driver/rdwin.cpp
index 7169d26380..898e0f0e58 100644
--- a/sword2/driver/rdwin.cpp
+++ b/sword2/driver/rdwin.cpp
@@ -543,6 +543,7 @@ int32 ServiceWindows(void)
{
g_sword2->parseEvents();
+ FadeServer();
g_sword2->_system->update_screen();
// warning("stub ServiceWindows"); // too noisy
/*