Implemented fading for OpenGL mode, some misc fixes

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@59 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
gewlitys
2002-09-22 02:44:48 +00:00
parent 3b43a48f10
commit f76658ae7e
6 changed files with 103 additions and 163 deletions
+17 -149
View File
@@ -31,7 +31,8 @@ static struct
} tc; } tc;
} TaskControl; } TaskControl;
UBYTE _batch_flags; static int cur = FADE_NORMAL_INTENSITY, end, XForming;
DWORD* _varPLUTs; DWORD* _varPLUTs;
static unsigned int varPLUTsize = VARPLUTS_SIZE; static unsigned int varPLUTsize = VARPLUTS_SIZE;
@@ -40,6 +41,16 @@ static TFB_Palette cmap_rgb[256];
static int cmap_type = 0; static int cmap_type = 0;
int TFB_GetFadeStatus ()
{
return XForming;
}
int TFB_GetFadeAmount ()
{
return cur;
}
BOOLEAN TFB_HasColorMap () BOOLEAN TFB_HasColorMap ()
{ {
return has_colormap; return has_colormap;
@@ -125,14 +136,12 @@ BOOLEAN TFB_CopyRGBColorMap (TFB_Palette *dst)
return TRUE; return TRUE;
} }
// Status: Implemented
BOOLEAN BOOLEAN
BatchColorMap (COLORMAPPTR ColorMapPtr) BatchColorMap (COLORMAPPTR ColorMapPtr)
{ {
return (SetColorMap (ColorMapPtr, TFB_COLORMAP_NONE)); return (SetColorMap (ColorMapPtr, TFB_COLORMAP_NONE));
} }
// Status: Implemented
BOOLEAN BOOLEAN
SetColorMap (COLORMAPPTR map, int type) SetColorMap (COLORMAPPTR map, int type)
{ {
@@ -168,138 +177,6 @@ SetColorMap (COLORMAPPTR map, int type)
return TRUE; 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 static
int xform_clut_task (void *data) int xform_clut_task (void *data)
{ {
@@ -326,7 +203,7 @@ int xform_clut_task (void *data)
TDelta = TTotal; TDelta = TTotal;
cur += (end - cur) * 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))); } while (TTotal -= TDelta && (!Task_ReadState (task, TASK_EXIT)));
} }
@@ -336,15 +213,12 @@ int xform_clut_task (void *data)
return 0; return 0;
} }
//Status: Partially implemented
DWORD DWORD
XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval) XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
{ {
BYTE what; BYTE what;
DWORD TimeOut; DWORD TimeOut;
//printf ("Partially implemented function activated: XFormColorMap()\n");
FlushColorXForms (); FlushColorXForms ();
if (ColorMapPtr == (COLORMAPPTR)0) if (ColorMapPtr == (COLORMAPPTR)0)
@@ -355,29 +229,26 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
{ {
case FadeAllToBlack: case FadeAllToBlack:
case FadeSomeToBlack: case FadeSomeToBlack:
end = NO_INTENSITY; end = FADE_NO_INTENSITY;
break; break;
case FadeAllToColor: case FadeAllToColor:
case FadeSomeToColor: case FadeSomeToColor:
end = NORMAL_INTENSITY; end = FADE_NORMAL_INTENSITY;
break; break;
case FadeAllToWhite: case FadeAllToWhite:
case FadeSomeToWhite: case FadeSomeToWhite:
end = FULL_INTENSITY; end = FADE_FULL_INTENSITY;
break; break;
default: default:
return (GetTimeCounter ()); return (GetTimeCounter ());
} }
//if (what == FadeAllToBlack || what == FadeAllToWhite || what == FadeAllToColor)
//_threedo_enable_fade ();
TaskControl.Ticks = TimeInterval; TaskControl.Ticks = TimeInterval;
if (TaskControl.Ticks <= 0 || if (TaskControl.Ticks <= 0 ||
(TaskControl.tc.XFormTask = AssignTask (xform_clut_task, (TaskControl.tc.XFormTask = AssignTask (xform_clut_task,
1024, "transform colormap")) == 0) 1024, "transform colormap")) == 0)
{ {
//_threedo_change_clut (end); cur = end;
TimeOut = GetTimeCounter (); TimeOut = GetTimeCounter ();
} }
else else
@@ -392,12 +263,9 @@ XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
return (TimeOut); return (TimeOut);
} }
//Status: Implemented
void void
FlushColorXForms() FlushColorXForms()
{ {
//printf ("Partially implemented function activated: FlushColorXForms()\n");
if (XForming) if (XForming)
{ {
XForming = FALSE; XForming = FALSE;
+6 -1
View File
@@ -37,6 +37,10 @@
#define CYCLE_PENDING (1 << 5) #define CYCLE_PENDING (1 << 5)
#define ENABLE_CYCLE (1 << 6) #define ENABLE_CYCLE (1 << 6)
#define FADE_NO_INTENSITY 0
#define FADE_NORMAL_INTENSITY 255
#define FADE_FULL_INTENSITY 510
enum enum
{ {
TFB_COLORMAP_NONE, TFB_COLORMAP_NONE,
@@ -47,8 +51,9 @@ enum
}; };
extern DWORD* _varPLUTs; extern DWORD* _varPLUTs;
extern UBYTE _batch_flags;
int TFB_GetFadeStatus ();
int TFB_GetFadeAmount ();
BOOLEAN TFB_HasColorMap (); BOOLEAN TFB_HasColorMap ();
int TFB_GetColorMapType (); int TFB_GetColorMapType ();
void TFB_ReleaseColorMap (); void TFB_ReleaseColorMap ();
@@ -10,5 +10,6 @@ noinst_LTLIBRARIES = libsdl.la
libsdl_la_SOURCES = 3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c \ 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 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
@@ -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
+43 -11
View File
@@ -187,13 +187,33 @@ TFB_GL_TVEffect()
glVertex2i(ScreenWidthActual, y); glVertex2i(ScreenWidthActual, y);
glEnd(); 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 void
TFB_GL_SwapBuffers () TFB_GL_SwapBuffers ()
{ {
int fade_amount;
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glOrtho (0,ScreenWidthActual,ScreenHeightActual, 0, -1, 1); 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_MAG_FILTER, ScreenFilterMode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScreenFilterMode); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ScreenFilterMode);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glColor4f(1,1,1,1); glColor4f(1,1,1,1);
glBegin(GL_TRIANGLE_FAN); TFB_GL_DrawQuad ();
glTexCoord2f(0, 0); fade_amount = TFB_GetFadeAmount ();
glVertex2i(0, 0); if (fade_amount != 255)
{
float c;
glTexCoord2f(ScreenWidth / 512.0f, 0); if (fade_amount < 255)
glVertex2i(ScreenWidthActual, 0); {
c = fade_amount / 255.0f;
glBlendFunc(GL_DST_COLOR, GL_ZERO);
}
else
{
c = (fade_amount - 255) / 255.0f;
glBlendFunc(GL_ONE, GL_ONE);
}
glTexCoord2f(ScreenWidth / 512.0f, ScreenHeight / 256.0f); glColor3f(c, c, c);
glVertex2i(ScreenWidthActual, ScreenHeightActual); glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glTexCoord2f(0, ScreenHeight / 256.0f); //printf("fade_amount %d c %f\n",fade_amount, c);
glVertex2i(0, ScreenHeightActual);
glEnd(); TFB_GL_DrawQuad ();
}
if (tveffect) if (tveffect)
TFB_GL_TVEffect(); TFB_GL_TVEffect();
@@ -23,6 +23,8 @@
#include "pure.h" #include "pure.h"
#include "rotozoom.h" #include "rotozoom.h"
#include "primitives.h" #include "primitives.h"
#include "dcqueue.h"
#include "SDL_thread.h"
SDL_Surface *SDL_Video; SDL_Surface *SDL_Video;
SDL_Surface *SDL_Screen; SDL_Surface *SDL_Screen;
@@ -316,6 +318,13 @@ TFB_FlushGraphics () // Only call from main thread!!
// but it is likely to not be very destructive. // but it is likely to not be very destructive.
if (DrawCommandQueue == 0 || DrawCommandQueue->Size == 0) 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); SDL_Delay(5);
return; return;
} }