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

2
Source/engine.h

@ -50,7 +50,7 @@ void __cdecl mem_atexit_mutex();
void __cdecl mem_free_mutex(void);
unsigned char *__fastcall DiabloAllocPtr(int dwBytes);
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 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);

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);
LoadFileWithMem(filestr, &pLightTbl[256 * (uniquetrans + 19)]);
LoadFileWithMem(filestr, (BYTE*)&pLightTbl[256 * (uniquetrans + 19)]);
Monst->_uniqtrans = uniquetrans++;

12
Source/player.cpp

@ -851,17 +851,17 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime)
if (plr[pnum]._pHitPoints >> 6 > 0) {
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]._pAnimCnt = random(2, 3);
} else {
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]._pVar8 = 2 * plr[pnum]._pAnimLen;
}
plr[pnum]._pdir = 0;
plr[pnum]._pdir = DIR_S;
plr[pnum]._peflag = 0;
if (pnum == myplr) {
@ -921,7 +921,7 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime)
deathflag = FALSE;
ScrollInfo._sxoff = 0;
ScrollInfo._syoff = 0;
ScrollInfo._sdir = 0;
ScrollInfo._sdir = SDIR_NONE;
}
}
// 52572C: using guessed type int leveldebug;
@ -1084,7 +1084,7 @@ void __fastcall FixPlayerLocation(int pnum, int dir)
if (pnum == myplr) {
ScrollInfo._sxoff = 0;
ScrollInfo._syoff = 0;
ScrollInfo._sdir = 0;
ScrollInfo._sdir = SDIR_NONE;
ViewX = plr[pnum].WorldX;
ViewY = plr[pnum].WorldY;
}
@ -1129,7 +1129,7 @@ void __fastcall StartWalkStand(int pnum)
if (pnum == myplr) {
ScrollInfo._sxoff = 0;
ScrollInfo._syoff = 0;
ScrollInfo._sdir = 0;
ScrollInfo._sdir = SDIR_NONE;
ViewX = plr[pnum].WorldX;
ViewY = plr[pnum].WorldY;
}

2
Source/scrollrt.cpp

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

Loading…
Cancel
Save