Devilution
Diablo devolved - magic behind the 1996 computer game
|
Go to the documentation of this file.
14 #include "../3rdParty/Storm/Source/storm.h"
47 void CelDraw(
int sx,
int sy, BYTE *pCelBuff,
int nCel,
int nWidth)
59 void CelBlitFrame(BYTE *pBuff, BYTE *pCelBuff,
int nCel,
int nWidth)
67 pRLEBytes =
CelGetFrame(pCelBuff, nCel, &nDataSize);
104 void CelDrawLight(
int sx,
int sy, BYTE *pCelBuff,
int nCel,
int nWidth, BYTE *tbl)
107 BYTE *pDecodeTo, *pRLEBytes;
112 pRLEBytes =
CelGetFrame(pCelBuff, nCel, &nDataSize);
118 CelBlitSafe(pDecodeTo, pRLEBytes, nDataSize, nWidth);
132 BYTE *pRLEBytes, *pDecodeTo;
143 CelBlitSafe(pDecodeTo, pRLEBytes, nDataSize, nWidth);
155 void CelDrawLightRed(
int sx,
int sy, BYTE *pCelBuff,
int nCel,
int nWidth,
char light)
157 int nDataSize, w, idx;
158 BYTE *pRLEBytes, *dst, *tbl;
170 idx += (light - 1) << 8;
176 end = &pRLEBytes[nDataSize];
178 for (; pRLEBytes != end; dst -=
BUFFER_WIDTH + nWidth) {
179 for (w = nWidth; w;) {
180 width = *pRLEBytes++;
181 if (!(width & 0x80)) {
184 *dst = tbl[*pRLEBytes];
190 width = -(char)width;
205 void CelBlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes,
int nDataSize,
int nWidth)
211 assert(pDecodeTo != NULL);
212 assert(pRLEBytes != NULL);
219 for (; src != &pRLEBytes[nDataSize]; dst -=
BUFFER_WIDTH + w) {
222 if (!(width & 0x80)) {
225 memcpy(dst, src, width);
230 width = -(char)width;
271 void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes,
int nDataSize,
int nWidth, BYTE *tbl)
277 assert(pDecodeTo != NULL);
278 assert(pRLEBytes != NULL);
287 for (; src != &pRLEBytes[nDataSize]; dst -=
BUFFER_WIDTH + w) {
290 if (!(width & 0x80)) {
294 dst[0] = tbl[src[0]];
300 dst[0] = tbl[src[0]];
301 dst[1] = tbl[src[1]];
306 for (; width; width--) {
307 dst[0] = tbl[src[0]];
308 dst[1] = tbl[src[1]];
309 dst[2] = tbl[src[2]];
310 dst[3] = tbl[src[3]];
319 width = -(char)width;
340 assert(pDecodeTo != NULL);
341 assert(pRLEBytes != NULL);
352 shift = (BYTE)(
size_t)dst & 1;
354 for (; src != &pRLEBytes[nDataSize]; dst -=
BUFFER_WIDTH + w, shift = (shift + 1) & 1) {
357 if (!(width & 0x80)) {
360 if (((BYTE)(size_t)dst & 1) == shift) {
369 dst[0] = tbl[src[0]];
374 for (; width; width--) {
375 dst[0] = tbl[src[0]];
376 dst[2] = tbl[src[2]];
385 dst[0] = tbl[src[0]];
391 dst[1] = tbl[src[1]];
396 for (; width; width--) {
397 dst[1] = tbl[src[1]];
398 dst[3] = tbl[src[3]];
409 width = -(char)width;
452 int nDataSize, w, idx;
453 BYTE *pRLEBytes, *dst, *tbl;
465 idx += (light - 1) << 8;
472 end = &pRLEBytes[nDataSize];
474 for (; pRLEBytes != end; dst -=
BUFFER_WIDTH + nWidth) {
475 for (w = nWidth; w;) {
476 width = *pRLEBytes++;
477 if (!(width & 0x80)) {
481 *dst = tbl[*pRLEBytes];
491 width = -(char)width;
509 void CelBlitWidth(BYTE *pBuff,
int x,
int y,
int wdt, BYTE *pCelBuff,
int nCel,
int nWidth)
511 BYTE *pRLEBytes, *dst, *end;
519 pRLEBytes =
CelGetFrame(pCelBuff, nCel, &nDataSize);
520 end = &pRLEBytes[nDataSize];
521 dst = &pBuff[y * wdt + x];
523 for (; pRLEBytes != end; dst -= wdt + nWidth) {
524 for (i = nWidth; i;) {
525 width = *pRLEBytes++;
526 if (!(width & 0x80)) {
528 memcpy(dst, pRLEBytes, width);
532 width = -(char)width;
549 void CelBlitOutline(
char col,
int sx,
int sy, BYTE *pCelBuff,
int nCel,
int nWidth)
552 BYTE *src, *dst, *end;
559 end = &src[nDataSize];
563 for (w = nWidth; w;) {
565 if (!(width & 0x80)) {
595 width = -(char)width;
657 void DrawLine(
int x0,
int y0,
int x1,
int y1, BYTE col)
659 int i, dx, dy, steps;
660 float ix, iy, sx, sy;
664 steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
665 ix = dx / (float)steps;
666 iy = dy / (float)steps;
670 for(i = 0; i <= steps; i++, sx += ix, sy += iy) {
770 buf = (BYTE *)SMemAlloc(dwBytes, __FILE__, __LINE__, 0);
774 char *text =
"System memory exhausted.\n"
775 "Make sure you have at least 64MB of free system memory before running the game";
776 ERR_DLG(
"Out of Memory Error", text);
790 SMemFree(p, __FILE__, __LINE__, 0);
811 *pdwFileLen = fileLen;
814 app_fatal(
"Zero length SFILE:\n%s", pszName);
837 app_fatal(
"LoadFileWithMem(NULL):\n%s", pszName);
843 if (dwFileLen == 0) {
844 app_fatal(
"Zero length SFILE:\n%s", pszName);
847 WReadFile(hsFile, p, dwFileLen, pszName);
868 for (i = 1; i <= nCel; i++) {
904 void Cl2Draw(
int sx,
int sy, BYTE *pCelBuff,
int nCel,
int nWidth)
929 void Cl2BlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes,
int nDataSize,
int nWidth)
1015 assert(pCelBuff != NULL);
1056 if (*src++ && dst < gpBufEnd && dst >
gpBufStart) {
1126 BYTE *pRLEBytes, *pDecodeTo;
1129 assert(pCelBuff != NULL);
1139 idx += (light - 1) << 8;
1157 void Cl2BlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes,
int nDataSize,
int nWidth, BYTE *pTable)
1177 fill = pTable[*src++];
1196 *dst = pTable[*src];
1240 BYTE *pRLEBytes, *pDecodeTo;
1243 assert(pCelBuff != NULL);
1252 Cl2BlitSafe(pDecodeTo, pRLEBytes, nDataSize, nWidth);
BYTE * CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize)
void play_movie(char *pszMovie, BOOL user_can_close)
void Cl2DrawLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, char light)
Blit CL2 sprite, and apply a given lighting, to the back buffer at the given coordianates.
void Cl2DrawOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Blit a solid colder shape one pixel larger then the given sprite shape, to the back buffer at the giv...
const int RndMult
Specifies the multiplier used in the Borland C/C++ pseudo-random number generator algorithm.
void Cl2BlitOutlineSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col)
Blit a solid colder shape one pixel larger then the given sprite shape, to the given buffer.
void SetRndSeed(int s)
Set the RNG seed.
void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel)
Apply the color swaps to a CL2 sprite.
void PaletteFadeIn(int fr)
DEVILUTION_BEGIN_NAMESPACE char gbPixelCol
automap pixel color 8-bit (palette entry)
void CelClippedBlitLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth)
Same as CelBlitLightTransSafe.
int GetDirection(int x1, int y1, int x2, int y2)
Calculate the best fit direction between two points.
static CCritSect sgMemCrit
void CelBlitFrame(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth)
Blit a given CEL frame to the given buffer.
void PlayInGameMovie(char *pszMovie)
Fade to black and play a video.
void Cl2BlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
Blit CL2 sprite to the given buffer.
LONG WGetFileSize(HANDLE hsFile, DWORD *lpFileSizeHigh, const char *FileName)
int sgnWidth
Width of sprite being blitted.
int orgseed
Seed value before the most recent call to SetRndSeed()
int sglGameSeed
Current game seed.
void CelBlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
Blit CEL sprite to the given buffer, checks for drawing outside the buffer.
void Cl2BlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable)
Blit CL2 sprite, and apply lighting, to the given buffer.
DWORD LoadFileWithMem(const char *pszName, void *p)
Load a file in to the given buffer.
BOOL WOpenFile(const char *FileName, HANDLE *phsFile, BOOL mayNotExist)
void Cl2DrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Blit CL2 sprite, and apply lighting, to the back buffer at the given coordinates.
void CelClippedDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Same as CelDrawLight but with the option to skip parts of the top and bottom of the sprite.
#define ERR_DLG(title, text)
int SeedCount
Track number of calls to GetRndSeed() since last call to SetRndSeed()
BOOL gbNotInView
valid - if x/y are in bounds
void ENG_set_pixel(int sx, int sy, BYTE col)
Set the value of a single pixel in the back buffer, checks bounds.
void app_fatal(const char *pszFmt,...)
#define DEVILUTION_END_NAMESPACE
BYTE * CelGetFrameClipped(BYTE *pCelBuff, int nCel, int *nDataSize)
BYTE * LoadFileInMem(char *pszName, DWORD *pdwFileLen)
Load a file in to a buffer.
void CelDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Blit CEL sprite to the back buffer at the given coordinates.
void DrawLine(int x0, int y0, int x1, int y1, BYTE col)
Draw a line on the back buffer.
BOOL gbRotateMap
flip - if y < x
int GetRndSeed()
Get the current RNG seed.
void CelClippedDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Same as CelDraw but with the option to skip parts of the top and bottom of the sprite.
void CelBlitWidth(BYTE *pBuff, int x, int y, int wdt, BYTE *pCelBuff, int nCel, int nWidth)
Blit to a buffer at given coordinates.
DEVILUTION_BEGIN_NAMESPACE BOOL WCloseFile(HANDLE file)
void CelClippedDrawSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Same as CelClippedDraw but checks for drawing outside the buffer.
BYTE * DiabloAllocPtr(DWORD dwBytes)
Multithreaded safe malloc.
void PaletteFadeOut(int fr)
int random_(BYTE idx, int v)
Main RNG function.
void mem_free_dbg(void *p)
Multithreaded safe memfree.
void CelDrawLightRedSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, char light)
Same as CelDrawLightRed but checks for drawing outside the buffer.
void engine_draw_pixel(int sx, int sy)
Set the value of a single pixel in the back buffer to that of gbPixelCol, checks bounds.
void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *tbl)
Blit CEL sprite, and apply lighting, to the given buffer, checks for drawing outside the buffer.
void CelDrawLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, char light)
Blit CEL sprite, and apply lighting, to the back buffer at the given coordinates, translated to a red...
void WReadFile(HANDLE hsFile, LPVOID buf, DWORD to_read, const char *FileName)
void CelBlitLightTransSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
Same as CelBlitLightSafe, with transparancy applied.
void Cl2Draw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Blit CL2 sprite, to the back buffer at the given coordianates.
const int RndInc
Specifies the increment used in the Borland C/C++ pseudo-random.
void CelBlitOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Blit a solid colder shape one pixel larger then the given sprite shape, to the back buffer at the giv...
void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, BYTE *tbl)
Blit CEL sprite, and apply lighting, to the back buffer at the given coordinates.