Browse Source

Engine.cpp (#548)

* Clean up DiabloAllocPtr

* Clean up mem_free_dbg

* Clean up GetDirection

* Clean up PlayInGameMovie

* 18 directions
pull/25/head
Anders Jenbo 7 years ago committed by GitHub
parent
commit
fd2a45ff9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Source/diablo.cpp
  2. 94
      Source/engine.cpp
  3. 2
      Source/engine.h
  4. 2
      Source/monster.cpp
  5. 12
      Source/player.cpp
  6. 2
      Source/scrollrt.cpp

2
Source/diablo.cpp

@ -451,7 +451,7 @@ void __cdecl diablo_init_screen()
ScrollInfo._sdy = 0; ScrollInfo._sdy = 0;
ScrollInfo._sxoff = 0; ScrollInfo._sxoff = 0;
ScrollInfo._syoff = 0; ScrollInfo._syoff = 0;
ScrollInfo._sdir = 0; ScrollInfo._sdir = SDIR_NONE;
for (i = 0; i < 1024; i++) for (i = 0; i < 1024; i++)
screen_y_times_768[i] = i * 768; screen_y_times_768[i] = i * 768;

94
Source/engine.cpp

@ -1468,46 +1468,42 @@ void __fastcall DrawLine(int x0, int y0, int x1, int y1, UCHAR col)
int __fastcall GetDirection(int x1, int y1, int x2, int y2) int __fastcall GetDirection(int x1, int y1, int x2, int y2)
{ {
int v4; // esi int mx, my;
int v5; // ecx int md, ny;
int v6; // edx
int result; // eax mx = x2 - x1;
int v8; // esi my = y2 - y1;
int v9; // edx
if (mx >= 0) {
v4 = x2 - x1; if (my >= 0) {
v5 = y2 - y1; md = DIR_S;
if (v4 < 0) { if (2 * mx < my)
v8 = -v4; md = DIR_SW;
v9 = 2 * v8;
if (v5 < 0) {
v5 = -v5;
result = 4;
if (v9 < v5)
result = 5;
} else { } else {
result = 2; my = -my;
if (v9 < v5) md = DIR_E;
result = 1; if (2 * mx < my)
md = DIR_NE;
} }
if (2 * v5 < v8) if (2 * my < mx)
return 3; return DIR_SE;
} else { } else {
v6 = 2 * v4; ny = -mx;
if (v5 < 0) { if (my >= 0) {
v5 = -v5; md = DIR_W;
result = 6; if (2 * ny < my)
if (v6 < v5) md = DIR_SW;
result = 5;
} else { } else {
result = 0; my = -my;
if (v6 < v5) md = DIR_N;
result = 1; if (2 * ny < my)
md = DIR_NE;
} }
if (2 * v5 < v4) if (2 * my < ny)
return 7; return DIR_NW;
} }
return result;
return md;
} }
void __fastcall SetRndSeed(int s) void __fastcall SetRndSeed(int s)
@ -1522,7 +1518,7 @@ void __fastcall SetRndSeed(int s)
int __cdecl GetRndSeed() int __cdecl GetRndSeed()
{ {
++SeedCount; SeedCount++;
sglGameSeed = 0x015A4E35 * sglGameSeed + 1; sglGameSeed = 0x015A4E35 * sglGameSeed + 1;
return abs(sglGameSeed); return abs(sglGameSeed);
} }
@ -1563,34 +1559,29 @@ void __cdecl mem_free_mutex(void)
unsigned char *__fastcall DiabloAllocPtr(int dwBytes) unsigned char *__fastcall DiabloAllocPtr(int dwBytes)
{ {
int v1; // ebx BYTE *buf;
unsigned char *v2; // ebx
int v3; // eax
v1 = dwBytes;
EnterCriticalSection(&sgMemCrit); EnterCriticalSection(&sgMemCrit);
v2 = (unsigned char *)SMemAlloc(v1, "C:\\Src\\Diablo\\Source\\ENGINE.CPP", 2236, 0); buf = (BYTE *)SMemAlloc(dwBytes, "C:\\Src\\Diablo\\Source\\ENGINE.CPP", 2236, 0);
LeaveCriticalSection(&sgMemCrit); LeaveCriticalSection(&sgMemCrit);
if (!v2) {
v3 = GetLastError(); if (buf == NULL) {
ErrDlg(IDD_DIALOG2, v3, "C:\\Src\\Diablo\\Source\\ENGINE.CPP", 2269); ErrDlg(IDD_DIALOG2, GetLastError(), "C:\\Src\\Diablo\\Source\\ENGINE.CPP", 2269);
} }
return v2;
return buf;
} }
void __fastcall mem_free_dbg(void *p) void __fastcall mem_free_dbg(void *p)
{ {
void *v1; // edi
v1 = p;
if (p) { if (p) {
EnterCriticalSection(&sgMemCrit); EnterCriticalSection(&sgMemCrit);
SMemFree(v1, "C:\\Src\\Diablo\\Source\\ENGINE.CPP", 2317, 0); SMemFree(p, "C:\\Src\\Diablo\\Source\\ENGINE.CPP", 2317, 0);
LeaveCriticalSection(&sgMemCrit); LeaveCriticalSection(&sgMemCrit);
} }
} }
unsigned char *__fastcall LoadFileInMem(char *pszName, int *pdwFileLen) BYTE *__fastcall LoadFileInMem(char *pszName, int *pdwFileLen)
{ {
HANDLE file; HANDLE file;
BYTE *buf; BYTE *buf;
@ -2427,11 +2418,8 @@ void __fastcall Cl2DecodeFrm6(int screen_x, int screen_y, char *pCelBuff, int nC
void __fastcall PlayInGameMovie(char *pszMovie) void __fastcall PlayInGameMovie(char *pszMovie)
{ {
char *v1; // esi
v1 = pszMovie;
PaletteFadeOut(8); PaletteFadeOut(8);
play_movie(v1, 0); play_movie(pszMovie, 0);
ClearScreenBuffer(); ClearScreenBuffer();
drawpanflag = 255; drawpanflag = 255;
scrollrt_draw_game_screen(1); scrollrt_draw_game_screen(1);

2
Source/engine.h

@ -50,7 +50,7 @@ void __cdecl mem_atexit_mutex();
void __cdecl mem_free_mutex(void); void __cdecl mem_free_mutex(void);
unsigned char *__fastcall DiabloAllocPtr(int dwBytes); unsigned char *__fastcall DiabloAllocPtr(int dwBytes);
void __fastcall mem_free_dbg(void *p); void __fastcall mem_free_dbg(void *p);
unsigned char *__fastcall LoadFileInMem(char *pszName, int *pdwFileLen); BYTE *__fastcall LoadFileInMem(char *pszName, int *pdwFileLen);
void __fastcall LoadFileWithMem(char *pszName, void *buf); void __fastcall LoadFileWithMem(char *pszName, void *buf);
void __fastcall Cl2ApplyTrans(unsigned char *p, unsigned char *ttbl, int last_frame); void __fastcall Cl2ApplyTrans(unsigned char *p, unsigned char *ttbl, int last_frame);
void __fastcall Cl2DecodeFrm1(int x, int y, char *pCelBuff, int nCel, int width, int dir1, int dir2); void __fastcall Cl2DecodeFrm1(int x, int y, char *pCelBuff, int nCel, int width, int dir1, int dir2);

2
Source/monster.cpp

@ -986,7 +986,7 @@ void __fastcall PlaceUniqueMonst(int uniqindex, int miniontype, int packsize)
} }
sprintf(filestr, "Monsters\\Monsters\\%s.TRN", Uniq->mTrnName); sprintf(filestr, "Monsters\\Monsters\\%s.TRN", Uniq->mTrnName);
LoadFileWithMem(filestr, &pLightTbl[256 * (uniquetrans + 19)]); LoadFileWithMem(filestr, (BYTE*)&pLightTbl[256 * (uniquetrans + 19)]);
Monst->_uniqtrans = uniquetrans++; Monst->_uniqtrans = uniquetrans++;

12
Source/player.cpp

@ -851,17 +851,17 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime)
if (plr[pnum]._pHitPoints >> 6 > 0) { if (plr[pnum]._pHitPoints >> 6 > 0) {
plr[pnum]._pmode = PM_STAND; plr[pnum]._pmode = PM_STAND;
NewPlrAnim(pnum, plr[pnum]._pNAnim[0], plr[pnum]._pNFrames, 3, plr[pnum]._pNWidth); NewPlrAnim(pnum, plr[pnum]._pNAnim[DIR_S], plr[pnum]._pNFrames, 3, plr[pnum]._pNWidth);
plr[pnum]._pAnimFrame = random(2, plr[pnum]._pNFrames - 1) + 1; plr[pnum]._pAnimFrame = random(2, plr[pnum]._pNFrames - 1) + 1;
plr[pnum]._pAnimCnt = random(2, 3); plr[pnum]._pAnimCnt = random(2, 3);
} else { } else {
plr[pnum]._pmode = PM_DEATH; plr[pnum]._pmode = PM_DEATH;
NewPlrAnim(pnum, plr[pnum]._pDAnim[0], plr[pnum]._pDFrames, 1, plr[pnum]._pDWidth); NewPlrAnim(pnum, plr[pnum]._pDAnim[DIR_S], plr[pnum]._pDFrames, 1, plr[pnum]._pDWidth);
plr[pnum]._pAnimFrame = plr[pnum]._pAnimLen - 1; plr[pnum]._pAnimFrame = plr[pnum]._pAnimLen - 1;
plr[pnum]._pVar8 = 2 * plr[pnum]._pAnimLen; plr[pnum]._pVar8 = 2 * plr[pnum]._pAnimLen;
} }
plr[pnum]._pdir = 0; plr[pnum]._pdir = DIR_S;
plr[pnum]._peflag = 0; plr[pnum]._peflag = 0;
if (pnum == myplr) { if (pnum == myplr) {
@ -921,7 +921,7 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime)
deathflag = FALSE; deathflag = FALSE;
ScrollInfo._sxoff = 0; ScrollInfo._sxoff = 0;
ScrollInfo._syoff = 0; ScrollInfo._syoff = 0;
ScrollInfo._sdir = 0; ScrollInfo._sdir = SDIR_NONE;
} }
} }
// 52572C: using guessed type int leveldebug; // 52572C: using guessed type int leveldebug;
@ -1084,7 +1084,7 @@ void __fastcall FixPlayerLocation(int pnum, int dir)
if (pnum == myplr) { if (pnum == myplr) {
ScrollInfo._sxoff = 0; ScrollInfo._sxoff = 0;
ScrollInfo._syoff = 0; ScrollInfo._syoff = 0;
ScrollInfo._sdir = 0; ScrollInfo._sdir = SDIR_NONE;
ViewX = plr[pnum].WorldX; ViewX = plr[pnum].WorldX;
ViewY = plr[pnum].WorldY; ViewY = plr[pnum].WorldY;
} }
@ -1129,7 +1129,7 @@ void __fastcall StartWalkStand(int pnum)
if (pnum == myplr) { if (pnum == myplr) {
ScrollInfo._sxoff = 0; ScrollInfo._sxoff = 0;
ScrollInfo._syoff = 0; ScrollInfo._syoff = 0;
ScrollInfo._sdir = 0; ScrollInfo._sdir = SDIR_NONE;
ViewX = plr[pnum].WorldX; ViewX = plr[pnum].WorldX;
ViewY = plr[pnum].WorldY; ViewY = plr[pnum].WorldY;
} }

2
Source/scrollrt.cpp

@ -2618,7 +2618,7 @@ void __cdecl ScrollView()
} }
if(scroll) if(scroll)
ScrollInfo._sdir = 0; ScrollInfo._sdir = SDIR_NONE;
} }
void __cdecl EnableFrameCount() void __cdecl EnableFrameCount()

Loading…
Cancel
Save