Commit 1cf67f1a authored by Mike Wiering's avatar Mike Wiering
Browse files

Improved 256 color support

parent 8d976905
......@@ -368,6 +368,19 @@ OBJECTREC *GetObjectRec (int ID)
return obj;
}
/* update last position if pos has been changed during an event */
void UpdatePosition (OBJECTREC *obj)
{
obj->iLastXPos = obj->iXPos;
obj->iLastYPos = obj->iYPos;
obj->iFixedXPos = obj->iXPos << 8;
obj->iFixedYPos = obj->iYPos << 8;
obj->iLastFixedXPos = obj->iFixedXPos;
obj->iLastFixedYPos = obj->iFixedYPos;
}
/* initialize a new game object */
void InitGameObject (int mapx, int mapy)
......@@ -454,18 +467,6 @@ void InitGameObject (int mapx, int mapy)
UpdatePosition (objNew);
}
/* update last position if pos has been changed during an event */
UpdatePosition (OBJECTREC *obj)
{
obj->iLastXPos = obj->iXPos;
obj->iLastYPos = obj->iYPos;
obj->iFixedXPos = obj->iXPos << 8;
obj->iFixedYPos = obj->iYPos << 8;
obj->iLastFixedXPos = obj->iFixedXPos;
obj->iLastFixedYPos = obj->iFixedYPos;
}
/* remove game object with id ID and all objects that are not active (id==0) */
void GameObjectDone (int id)
{
......@@ -874,6 +875,26 @@ void RunGame ()
}
/* create a new event */
void ScheduleEvent (int event, int par1, int par2, int par3, int par4,
int target, int subtarget, int time)
{
struct USER_EVENT_INFO *uei;
uei = rmalloc (sizeof (USER_EVENT_INFO));
uei->iEventID = event;
uei->iEventParameter1 = par1;
uei->iEventParameter2 = par2;
uei->iEventParameter3 = par3;
uei->iEventParameter4 = par4;
uei->iDestination = target;
uei->iSubDestination = subtarget;
uei->iTimeCounter = time;
uei->ueiNext = ueiUserEventInfo;
ueiUserEventInfo = uei;
}
/* play (actually schedule) a sound sample */
void PlaySoundSample (int id, int vol, int pan, int freq, int delay)
{
......@@ -2842,25 +2863,6 @@ int NextFrame (int fade)
}
/* create a new event */
ScheduleEvent (int event, int par1, int par2, int par3, int par4,
int target, int subtarget, int time)
{
struct USER_EVENT_INFO *uei;
uei = rmalloc (sizeof (USER_EVENT_INFO));
uei->iEventID = event;
uei->iEventParameter1 = par1;
uei->iEventParameter2 = par2;
uei->iEventParameter3 = par3;
uei->iEventParameter4 = par4;
uei->iDestination = target;
uei->iSubDestination = subtarget;
uei->iTimeCounter = time;
uei->ueiNext = ueiUserEventInfo;
ueiUserEventInfo = uei;
}
/* make the screen follow an object */
extern EXPORT_TO_CLEAN void
WinSetObjectFocus (int x1, int y1, int x2, int y2, int maxxv, int maxyv,
......
......@@ -62,6 +62,12 @@ static GAMEBITMAPINFO *gbipPrev = NULL;
/* release DirectDraw object */
void ReleaseDD (void)
{
if (lpDDPal)
{
IDirectDrawSurface_Release (lpDDPal);
lpDDPal = NULL;
}
if (clipper)
{
IDirectDrawClipper_Release (clipper);
......@@ -219,7 +225,7 @@ BOOL OSInitGameWindow ()
{
if (!(ddrval == DD_OK))
{
BitsPerPixel == 8;
BitsPerPixel = 8;
ddrval = IDirectDraw_SetDisplayMode (lpDD, ScreenWidth, ScreenHeight, BitsPerPixel);
}
}
......@@ -237,7 +243,7 @@ BOOL OSInitGameWindow ()
{
if (!(ddrval == DD_OK))
{
BitsPerPixel == 8;
BitsPerPixel = 8;
ddrval = IDirectDraw_SetDisplayMode (lpDD, ScreenWidth, ScreenHeight, BitsPerPixel);
}
}
......@@ -314,6 +320,16 @@ BOOL OSInitGameWindow ()
if (!(ddrval == DD_OK))
ShowError ("IDirectDrawSurface_GetAttachedSurface failed");
else
{
if (BitsPerPixel == 8)
{
lpDDPal = DDLoadPalette (lpDD, NULL);
if (lpDDPal == NULL)
ShowError ("DDMakeDefaultPalette failed");
else
IDirectDrawSurface_SetPalette (lpDDSFront, lpDDPal);
}
result = TRUE;
}
}
......@@ -323,6 +339,7 @@ BOOL OSInitGameWindow ()
}
}
}
}
return result;
}
......@@ -606,6 +623,7 @@ BOOL OSGetGameBitmapInfo (int id, int *width, int *height,
*blockheight = gbip->iBlockHeight;
*blockcountx = gbip->iBlockCountX;
*blockcounty = gbip->iBlockCountY;
return TRUE;
}
else
return FALSE;
......
......@@ -6,8 +6,6 @@
* Content: Routines for loading bitmap and palettes from resources
*
***************************************************************************/
#undef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>
......@@ -47,7 +45,7 @@ extern "C" IDirectDrawSurface * DDLoadBitmap(IDirectDraw *pdd, LPCSTR szBitmap,
//
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
......@@ -162,20 +160,31 @@ extern "C" HRESULT DDCopyBitmap(IDirectDrawSurface *pdds, HBITMAP hbm, int x, in
// if the resource does not exist or NULL is passed create a
// default 332 palette.
//
extern "C" IDirectDrawPalette * DDLoadPalette(IDirectDraw *pdd, LPCSTR szBitmap)
extern "C" IDirectDrawPalette * DDLoadPalette (IDirectDraw *pdd, LPCSTR szBitmap)
{
IDirectDrawPalette* ddpal;
int i;
int i, j, r, g, b;
int n;
int fh;
// int fh;
// Mike ... //
HANDLE fh;
SECURITY_ATTRIBUTES sa;
// ... Mike //
HRSRC h;
LPBITMAPINFOHEADER lpbi;
PALETTEENTRY ape[256];
RGBQUAD * prgb;
// Mike ... //
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = FALSE;
// ... Mike //
//
// build a 332 palette as the default.
//
/*
for (i=0; i<256; i++)
{
ape[i].peRed = (BYTE)(((i >> 5) & 0x07) * 255 / 7);
......@@ -183,6 +192,31 @@ extern "C" IDirectDrawPalette * DDLoadPalette(IDirectDraw *pdd, LPCSTR szBitmap)
ape[i].peBlue = (BYTE)(((i >> 0) & 0x03) * 255 / 3);
ape[i].peFlags = (BYTE)0;
}
*/
for (i = 0; i < 256; i++)
{
if (i < 6 * 7 * 6)
{
r = 224 * ( i % 6) / 5 + 16;
g = 224 * ((i / 6) % 7) / 6 + 16;
b = 224 * ((i / 42) % 6) / 5 + 16;
}
else
{
switch (i)
{
case 252: { r = 0; g = 0; b = 0; break; }
case 253: { r = 8; g = 8; b = 8; break; }
case 254: { r = 247; g = 247; b = 247; break; }
case 255: { r = 255; g = 255; b = 255; break; }
}
}
ape[i].peRed = (BYTE) r;
ape[i].peGreen = (BYTE) g;
ape[i].peBlue = (BYTE) b;
ape[i].peFlags = (BYTE) 0;
}
//
// get a pointer to the bitmap resource.
......@@ -215,15 +249,32 @@ extern "C" IDirectDrawPalette * DDLoadPalette(IDirectDraw *pdd, LPCSTR szBitmap)
ape[i].peFlags = 0;
}
}
else if (szBitmap && (fh = _lopen(szBitmap, OF_READ)) != -1)
else if (szBitmap &&
// (fh = _lopen(szBitmap, OF_READ)) != -1
// Mike ... //
(fh = CreateFile (szBitmap, GENERIC_READ,
FILE_SHARE_READ, &sa, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL)
) != NULL
)
// ... Mike //
{
BITMAPFILEHEADER bf;
BITMAPINFOHEADER bi;
unsigned long iNumRead;
/*
_lread(fh, &bf, sizeof(bf));
_lread(fh, &bi, sizeof(bi));
_lread(fh, ape, sizeof(ape));
_lclose(fh);
*/
// Mike ... //
ReadFile (fh, &bf, sizeof (bf), &iNumRead, NULL);
ReadFile (fh, &bi, sizeof (bi), &iNumRead, NULL);
ReadFile (fh, ape, sizeof (ape), &iNumRead, NULL);
CloseHandle (fh);
// ... Mike //
if (bi.biSize != sizeof(BITMAPINFOHEADER))
n = 0;
......@@ -246,11 +297,13 @@ extern "C" IDirectDrawPalette * DDLoadPalette(IDirectDraw *pdd, LPCSTR szBitmap)
}
}
pdd->CreatePalette(DDPCAPS_8BIT, ape, &ddpal, NULL);
return ddpal;
}
/*
* DDColorMatch
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment