diff --git a/sc2/src/sc2code/libs/graphics/cmap.c b/sc2/src/sc2code/libs/graphics/cmap.c index b5f396885..7fd3a3093 100644 --- a/sc2/src/sc2code/libs/graphics/cmap.c +++ b/sc2/src/sc2code/libs/graphics/cmap.c @@ -31,7 +31,8 @@ static struct } tc; } TaskControl; -UBYTE _batch_flags; +static int cur = FADE_NORMAL_INTENSITY, end, XForming; + DWORD* _varPLUTs; static unsigned int varPLUTsize = VARPLUTS_SIZE; @@ -40,6 +41,16 @@ static TFB_Palette cmap_rgb[256]; static int cmap_type = 0; +int TFB_GetFadeStatus () +{ + return XForming; +} + +int TFB_GetFadeAmount () +{ + return cur; +} + BOOLEAN TFB_HasColorMap () { return has_colormap; @@ -125,14 +136,12 @@ BOOLEAN TFB_CopyRGBColorMap (TFB_Palette *dst) return TRUE; } -// Status: Implemented BOOLEAN BatchColorMap (COLORMAPPTR ColorMapPtr) { return (SetColorMap (ColorMapPtr, TFB_COLORMAP_NONE)); } -// Status: Implemented BOOLEAN SetColorMap (COLORMAPPTR map, int type) { @@ -168,138 +177,6 @@ SetColorMap (COLORMAPPTR map, int type) return TRUE; } -void -_threedo_set_colors (UBYTE *colors, unsigned int indices) -{ - int i, start, end; - //unsigned int *ce; - - start = (int)LOBYTE (indices); - end = (int)HIBYTE (indices); - - //ce = colorEntries; - for (i = start; i <= end; i++) - { - UBYTE r, g, b; - - r = (*colors << 2) | (*colors >> 4); - ++colors; - g = (*colors << 2) | (*colors >> 4); - ++colors; - b = (*colors << 2) | (*colors >> 4); - ++colors; - - //*ce++ = MakeCLUTColorEntry (i, r, g, b); - } - - //ceCt = end - start + 1; - - //_threedo_add_task (Thread_SET_CLUT); - //_batch_flags |= CYCLE_PENDING; -} - -static int -color_cycle (void *data) -{ - UWORD color_beg, color_len, color_indices; - COUNT Cycles, CycleCount; - DWORD TimeIn, SleepTicks; - COLORMAPPTR BegMapPtr, CurMapPtr; - Task task = (Task)data; - - Cycles = CycleCount = TaskControl.tc.NumCycles; - BegMapPtr = TaskControl.CMapPtr; - SleepTicks = TaskControl.Ticks; - - color_indices = MAKE_WORD (BegMapPtr[0], BegMapPtr[1]); - color_beg = *BegMapPtr++ * 3; - color_len = (*BegMapPtr++ + 1) * 3 - color_beg; - CurMapPtr = BegMapPtr; - - TaskControl.CMapPtr = 0; - TimeIn = GetTimeCounter (); - while (!Task_ReadState(task, TASK_EXIT)) - { - //_threedo_set_colors (CurMapPtr, color_indices); - - if (--Cycles) - CurMapPtr += color_len + sizeof (BYTE) * 2; - else - { - Cycles = CycleCount; - CurMapPtr = BegMapPtr; - } - - SleepThreadUntil (TimeIn + SleepTicks); - TimeIn = GetTimeCounter (); - - if (TaskControl.CMapPtr) - { - TaskControl.CMapPtr = (COLORMAPPTR)0; - while (!Task_ReadState(task, TASK_EXIT)) - TaskSwitch (); - } - } - FinishTask (task); - return 0; -} - -CYCLE_REF -CycleColorMap (COLORMAPPTR ColorMapPtr, COUNT Cycles, SIZE TimeInterval) -{ - if (ColorMapPtr && Cycles && ColorMapPtr[0] <= ColorMapPtr[1]) - { - Task T; - - while (TaskControl.CMapPtr) - { - TaskSwitch (); - } - - TaskControl.CMapPtr = ColorMapPtr; - TaskControl.tc.NumCycles = Cycles; - if ((TaskControl.Ticks = TimeInterval) <= 0) - TaskControl.Ticks = 1; - - T = AssignTask (color_cycle, 0, "color cycle"); - if (T) - { - _batch_flags |= ENABLE_CYCLE; - do - TaskSwitch (); - while (TaskControl.CMapPtr); - } - TaskControl.CMapPtr = 0; - - return ((CYCLE_REF)T); - } - - return (0); -} - -void -StopCycleColorMap (CYCLE_REF CycleRef) -{ - Task T; - - T = (Task) CycleRef; - if (T) - { - TaskControl.CMapPtr = (COLORMAPPTR)1; - while (TaskControl.CMapPtr) - TaskSwitch (); - - _batch_flags &= ~ENABLE_CYCLE; - Task_SetState (T, TASK_EXIT); - } -} - -#define NO_INTENSITY 0x00 -#define NORMAL_INTENSITY 0xff -#define FULL_INTENSITY (0xff * 32) - -static int cur = NORMAL_INTENSITY, end, XForming; - static int xform_clut_task (void *data) { @@ -326,7 +203,7 @@ int xform_clut_task (void *data) TDelta = TTotal; cur += (end - cur) * TDelta / TTotal; - //_threedo_change_clut (cur); + //printf("xform_clut_task cur %d\n", cur); } while (TTotal -= TDelta && (!Task_ReadState (task, TASK_EXIT))); } @@ -336,15 +213,12 @@ int xform_clut_task (void *data) return 0; } -//Status: Partially implemented DWORD XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) { BYTE what; DWORD TimeOut; - //printf ("Partially implemented function activated: XFormColorMap()\n"); - FlushColorXForms (); if (ColorMapPtr == (COLORMAPPTR)0) @@ -355,29 +229,26 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) { case FadeAllToBlack: case FadeSomeToBlack: - end = NO_INTENSITY; + end = FADE_NO_INTENSITY; break; case FadeAllToColor: case FadeSomeToColor: - end = NORMAL_INTENSITY; + end = FADE_NORMAL_INTENSITY; break; case FadeAllToWhite: case FadeSomeToWhite: - end = FULL_INTENSITY; + end = FADE_FULL_INTENSITY; break; default: return (GetTimeCounter ()); } - //if (what == FadeAllToBlack || what == FadeAllToWhite || what == FadeAllToColor) - //_threedo_enable_fade (); - TaskControl.Ticks = TimeInterval; if (TaskControl.Ticks <= 0 || (TaskControl.tc.XFormTask = AssignTask (xform_clut_task, 1024, "transform colormap")) == 0) { - //_threedo_change_clut (end); + cur = end; TimeOut = GetTimeCounter (); } else @@ -392,12 +263,9 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) return (TimeOut); } -//Status: Implemented void FlushColorXForms() { - //printf ("Partially implemented function activated: FlushColorXForms()\n"); - if (XForming) { XForming = FALSE; diff --git a/sc2/src/sc2code/libs/graphics/cmap.h b/sc2/src/sc2code/libs/graphics/cmap.h index f41f0cd0f..0cc6a2f53 100644 --- a/sc2/src/sc2code/libs/graphics/cmap.h +++ b/sc2/src/sc2code/libs/graphics/cmap.h @@ -37,6 +37,10 @@ #define CYCLE_PENDING (1 << 5) #define ENABLE_CYCLE (1 << 6) +#define FADE_NO_INTENSITY 0 +#define FADE_NORMAL_INTENSITY 255 +#define FADE_FULL_INTENSITY 510 + enum { TFB_COLORMAP_NONE, @@ -47,8 +51,9 @@ enum }; extern DWORD* _varPLUTs; -extern UBYTE _batch_flags; +int TFB_GetFadeStatus (); +int TFB_GetFadeAmount (); BOOLEAN TFB_HasColorMap (); int TFB_GetColorMapType (); void TFB_ReleaseColorMap (); diff --git a/sc2/src/sc2code/libs/graphics/sdl/Makefile.am b/sc2/src/sc2code/libs/graphics/sdl/Makefile.am index 04382bc77..54d0b4103 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/Makefile.am +++ b/sc2/src/sc2code/libs/graphics/sdl/Makefile.am @@ -10,5 +10,6 @@ noinst_LTLIBRARIES = libsdl.la libsdl_la_SOURCES = 3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c \ primitives.c pure.c rotozoom.c sdl_common.c -noinst_HEADERS = opengl.h primitives.h pure.h rotozoom.h sdl_common.h +noinst_HEADERS = opengl.h primitives.h pure.h rotozoom.h sdl_common.h \ + dcqueue.h diff --git a/sc2/src/sc2code/libs/graphics/sdl/dcqueue.h b/sc2/src/sc2code/libs/graphics/sdl/dcqueue.h new file mode 100644 index 000000000..065a1291f --- /dev/null +++ b/sc2/src/sc2code/libs/graphics/sdl/dcqueue.h @@ -0,0 +1,25 @@ +//Copyright Paul Reiche, Fred Ford. 1992-2002 + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef DCQUEUE_H +#define DCQUEUE_H + +void Lock_DCQ (void); +void Unlock_DCQ (void); + +#endif diff --git a/sc2/src/sc2code/libs/graphics/sdl/opengl.c b/sc2/src/sc2code/libs/graphics/sdl/opengl.c index ccbc77c51..f0a650930 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/opengl.c +++ b/sc2/src/sc2code/libs/graphics/sdl/opengl.c @@ -187,13 +187,33 @@ TFB_GL_TVEffect() glVertex2i(ScreenWidthActual, y); glEnd(); } +} - glDisable(GL_BLEND); +void +TFB_GL_DrawQuad () +{ + glBegin(GL_TRIANGLE_FAN); + + glTexCoord2f(0, 0); + glVertex2i(0, 0); + + glTexCoord2f(ScreenWidth / 512.0f, 0); + glVertex2i(ScreenWidthActual, 0); + + glTexCoord2f(ScreenWidth / 512.0f, ScreenHeight / 256.0f); + glVertex2i(ScreenWidthActual, ScreenHeightActual); + + glTexCoord2f(0, ScreenHeight / 256.0f); + glVertex2i(0, ScreenHeightActual); + + glEnd(); } void TFB_GL_SwapBuffers () { + int fade_amount; + glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho (0,ScreenWidthActual,ScreenHeightActual, 0, -1, 1); @@ -211,24 +231,36 @@ TFB_GL_SwapBuffers () glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ScreenFilterMode); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScreenFilterMode); + glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); glColor4f(1,1,1,1); - glBegin(GL_TRIANGLE_FAN); + TFB_GL_DrawQuad (); - glTexCoord2f(0, 0); - glVertex2i(0, 0); + fade_amount = TFB_GetFadeAmount (); + if (fade_amount != 255) + { + float c; - glTexCoord2f(ScreenWidth / 512.0f, 0); - glVertex2i(ScreenWidthActual, 0); - - glTexCoord2f(ScreenWidth / 512.0f, ScreenHeight / 256.0f); - glVertex2i(ScreenWidthActual, ScreenHeightActual); + if (fade_amount < 255) + { + c = fade_amount / 255.0f; + glBlendFunc(GL_DST_COLOR, GL_ZERO); + } + else + { + c = (fade_amount - 255) / 255.0f; + glBlendFunc(GL_ONE, GL_ONE); + } - glTexCoord2f(0, ScreenHeight / 256.0f); - glVertex2i(0, ScreenHeightActual); + glColor3f(c, c, c); + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); - glEnd(); + //printf("fade_amount %d c %f\n",fade_amount, c); + + TFB_GL_DrawQuad (); + } if (tveffect) TFB_GL_TVEffect(); diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 7c409e0ba..6841e20d6 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -23,6 +23,8 @@ #include "pure.h" #include "rotozoom.h" #include "primitives.h" +#include "dcqueue.h" +#include "SDL_thread.h" SDL_Surface *SDL_Video; SDL_Surface *SDL_Screen; @@ -316,6 +318,13 @@ TFB_FlushGraphics () // Only call from main thread!! // but it is likely to not be very destructive. if (DrawCommandQueue == 0 || DrawCommandQueue->Size == 0) { + static int last_fade = 255; + int current_fade = TFB_GetFadeAmount(); + + if (current_fade != 255 && current_fade != last_fade) + TFB_SwapBuffers(); // if fading, redraw every frame + last_fade = current_fade; + SDL_Delay(5); return; }