Browse Source

♻️Add type to MIN-files and TRN-files

pull/1870/head
Anders Jenbo 5 years ago
parent
commit
3746723f52
  1. 16
      Source/diablo.cpp
  2. 5
      Source/engine.cpp
  3. 10
      Source/engine.h
  4. 35
      Source/gendung.cpp
  5. 2
      Source/gendung.h
  6. 20
      Source/lighting.cpp
  7. 37
      Source/monster.cpp
  8. 5
      Source/monster.h
  9. 34
      Source/objects.cpp

16
Source/diablo.cpp

@ -1505,11 +1505,11 @@ void LoadLvlGFX()
if (gbIsHellfire) { if (gbIsHellfire) {
pDungeonCels = LoadFileInMem<BYTE>("NLevels\\TownData\\Town.CEL"); pDungeonCels = LoadFileInMem<BYTE>("NLevels\\TownData\\Town.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\TownData\\Town.TIL"); pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\TownData\\Town.TIL");
pLevelPieces = LoadFileInMem<BYTE>("NLevels\\TownData\\Town.MIN"); pLevelPieces = LoadFileInMem<uint16_t>("NLevels\\TownData\\Town.MIN");
} else { } else {
pDungeonCels = LoadFileInMem<BYTE>("Levels\\TownData\\Town.CEL"); pDungeonCels = LoadFileInMem<BYTE>("Levels\\TownData\\Town.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\TownData\\Town.TIL"); pMegaTiles = LoadFileInMem<MegaTile>("Levels\\TownData\\Town.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\TownData\\Town.MIN"); pLevelPieces = LoadFileInMem<uint16_t>("Levels\\TownData\\Town.MIN");
} }
pSpecialCels = LoadCel("Levels\\TownData\\TownS.CEL", SpecialCelWidth); pSpecialCels = LoadCel("Levels\\TownData\\TownS.CEL", SpecialCelWidth);
break; break;
@ -1517,37 +1517,37 @@ void LoadLvlGFX()
if (currlevel < 21) { if (currlevel < 21) {
pDungeonCels = LoadFileInMem<BYTE>("Levels\\L1Data\\L1.CEL"); pDungeonCels = LoadFileInMem<BYTE>("Levels\\L1Data\\L1.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L1Data\\L1.TIL"); pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L1Data\\L1.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\L1Data\\L1.MIN"); pLevelPieces = LoadFileInMem<uint16_t>("Levels\\L1Data\\L1.MIN");
pSpecialCels = LoadCel("Levels\\L1Data\\L1S.CEL", SpecialCelWidth); pSpecialCels = LoadCel("Levels\\L1Data\\L1S.CEL", SpecialCelWidth);
} else { } else {
pDungeonCels = LoadFileInMem<BYTE>("NLevels\\L5Data\\L5.CEL"); pDungeonCels = LoadFileInMem<BYTE>("NLevels\\L5Data\\L5.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\L5Data\\L5.TIL"); pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\L5Data\\L5.TIL");
pLevelPieces = LoadFileInMem<BYTE>("NLevels\\L5Data\\L5.MIN"); pLevelPieces = LoadFileInMem<uint16_t>("NLevels\\L5Data\\L5.MIN");
pSpecialCels = LoadCel("NLevels\\L5Data\\L5S.CEL", SpecialCelWidth); pSpecialCels = LoadCel("NLevels\\L5Data\\L5S.CEL", SpecialCelWidth);
} }
break; break;
case DTYPE_CATACOMBS: case DTYPE_CATACOMBS:
pDungeonCels = LoadFileInMem<BYTE>("Levels\\L2Data\\L2.CEL"); pDungeonCels = LoadFileInMem<BYTE>("Levels\\L2Data\\L2.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L2Data\\L2.TIL"); pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L2Data\\L2.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\L2Data\\L2.MIN"); pLevelPieces = LoadFileInMem<uint16_t>("Levels\\L2Data\\L2.MIN");
pSpecialCels = LoadCel("Levels\\L2Data\\L2S.CEL", SpecialCelWidth); pSpecialCels = LoadCel("Levels\\L2Data\\L2S.CEL", SpecialCelWidth);
break; break;
case DTYPE_CAVES: case DTYPE_CAVES:
if (currlevel < 17) { if (currlevel < 17) {
pDungeonCels = LoadFileInMem<BYTE>("Levels\\L3Data\\L3.CEL"); pDungeonCels = LoadFileInMem<BYTE>("Levels\\L3Data\\L3.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L3Data\\L3.TIL"); pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L3Data\\L3.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\L3Data\\L3.MIN"); pLevelPieces = LoadFileInMem<uint16_t>("Levels\\L3Data\\L3.MIN");
} else { } else {
pDungeonCels = LoadFileInMem<BYTE>("NLevels\\L6Data\\L6.CEL"); pDungeonCels = LoadFileInMem<BYTE>("NLevels\\L6Data\\L6.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\L6Data\\L6.TIL"); pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\L6Data\\L6.TIL");
pLevelPieces = LoadFileInMem<BYTE>("NLevels\\L6Data\\L6.MIN"); pLevelPieces = LoadFileInMem<uint16_t>("NLevels\\L6Data\\L6.MIN");
} }
pSpecialCels = LoadCel("Levels\\L1Data\\L1S.CEL", SpecialCelWidth); pSpecialCels = LoadCel("Levels\\L1Data\\L1S.CEL", SpecialCelWidth);
break; break;
case DTYPE_HELL: case DTYPE_HELL:
pDungeonCels = LoadFileInMem<BYTE>("Levels\\L4Data\\L4.CEL"); pDungeonCels = LoadFileInMem<BYTE>("Levels\\L4Data\\L4.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L4Data\\L4.TIL"); pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L4Data\\L4.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\L4Data\\L4.MIN"); pLevelPieces = LoadFileInMem<uint16_t>("Levels\\L4Data\\L4.MIN");
pSpecialCels = LoadCel("Levels\\L2Data\\L2S.CEL", SpecialCelWidth); pSpecialCels = LoadCel("Levels\\L2Data\\L2S.CEL", SpecialCelWidth);
break; break;
default: default:

5
Source/engine.cpp

@ -11,6 +11,8 @@
* - Video playback * - Video playback
*/ */
#include <array>
#include "lighting.h" #include "lighting.h"
#include "movie.h" #include "movie.h"
#include "options.h" #include "options.h"
@ -765,10 +767,9 @@ DWORD LoadFileWithMem(const char *pszName, BYTE *p)
* @param ttbl Palette translation table * @param ttbl Palette translation table
* @param nCel Frame number in CL2 file * @param nCel Frame number in CL2 file
*/ */
void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel) void Cl2ApplyTrans(BYTE *p, const std::array<uint8_t, 256> &ttbl, int nCel)
{ {
assert(p != nullptr); assert(p != nullptr);
assert(ttbl != nullptr);
for (int i = 1; i <= nCel; i++) { for (int i = 1; i <= nCel; i++) {
int nDataSize; int nDataSize;

10
Source/engine.h

@ -609,10 +609,16 @@ int32_t GenerateRnd(int32_t v);
size_t GetFileSize(const char *pszName); size_t GetFileSize(const char *pszName);
void LoadFileData(const char *pszName, byte *buffer, size_t bufferSize); void LoadFileData(const char *pszName, byte *buffer, size_t bufferSize);
template <typename T>
void LoadFileInMem(const char *path, T *data, std::size_t count)
{
LoadFileData(path, reinterpret_cast<byte *>(data), count * sizeof(T));
}
template <typename T, std::size_t N> template <typename T, std::size_t N>
void LoadFileInMem(const char *path, std::array<T, N> &data) void LoadFileInMem(const char *path, std::array<T, N> &data)
{ {
LoadFileData(path, reinterpret_cast<byte *>(&data), N * sizeof(T)); LoadFileInMem(path, &data, N);
} }
/** /**
@ -640,7 +646,7 @@ std::unique_ptr<T[]> LoadFileInMem(const char *path, size_t *elements = nullptr)
} }
DWORD LoadFileWithMem(const char *pszName, BYTE *p); DWORD LoadFileWithMem(const char *pszName, BYTE *p);
void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel); void Cl2ApplyTrans(BYTE *p, const std::array<uint8_t, 256> &ttbl, int nCel);
void PlayInGameMovie(const char *pszMovie); void PlayInGameMovie(const char *pszMovie);
} // namespace devilution } // namespace devilution

35
Source/gendung.cpp

@ -29,7 +29,7 @@ bool setloadflag;
std::optional<CelSprite> pSpecialCels; std::optional<CelSprite> pSpecialCels;
/** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */ /** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */
std::unique_ptr<MegaTile[]> pMegaTiles; std::unique_ptr<MegaTile[]> pMegaTiles;
std::unique_ptr<BYTE[]> pLevelPieces; std::unique_ptr<uint16_t[]> pLevelPieces;
std::unique_ptr<BYTE[]> pDungeonCels; std::unique_ptr<BYTE[]> pDungeonCels;
std::array<uint8_t, MAXTILES + 1> block_lvid; std::array<uint8_t, MAXTILES + 1> block_lvid;
std::array<bool, MAXTILES + 1> nBlockTable; std::array<bool, MAXTILES + 1> nBlockTable;
@ -145,43 +145,36 @@ void FillSolidBlockTbls()
nBlockTable[i + 1] = (bv & 0x02) != 0; nBlockTable[i + 1] = (bv & 0x02) != 0;
nMissileTable[i + 1] = (bv & 0x04) != 0; nMissileTable[i + 1] = (bv & 0x04) != 0;
nTransTable[i + 1] = (bv & 0x08) != 0; nTransTable[i + 1] = (bv & 0x08) != 0;
nTrapTable[i + 1] = (bv & 0x80) != 0 ; nTrapTable[i + 1] = (bv & 0x80) != 0;
block_lvid[i + 1] = (bv & 0x70) >> 4; block_lvid[i + 1] = (bv & 0x70) >> 4;
} }
} }
void SetDungeonMicros() void SetDungeonMicros()
{ {
int i, x, y, lv, blocks; MicroTileLen = 10;
uint16_t *pPiece; int blocks = 10;
MICROS *pMap;
if (leveltype == DTYPE_TOWN) { if (leveltype == DTYPE_TOWN) {
MicroTileLen = 16; MicroTileLen = 16;
blocks = 16; blocks = 16;
} else if (leveltype != DTYPE_HELL) { } else if (leveltype == DTYPE_HELL) {
MicroTileLen = 10;
blocks = 10;
} else {
MicroTileLen = 12; MicroTileLen = 12;
blocks = 16; blocks = 16;
} }
for (y = 0; y < MAXDUNY; y++) { for (int y = 0; y < MAXDUNY; y++) {
for (x = 0; x < MAXDUNX; x++) { for (int x = 0; x < MAXDUNX; x++) {
lv = dPiece[x][y]; int lv = dPiece[x][y];
pMap = &dpiece_defs_map_2[x][y]; MICROS &micros = dpiece_defs_map_2[x][y];
if (lv != 0) { if (lv != 0) {
lv--; lv--;
if (leveltype != DTYPE_HELL && leveltype != DTYPE_TOWN) uint16_t *pieces = &pLevelPieces[blocks * lv];
pPiece = (uint16_t *)&pLevelPieces[20 * lv]; for (int i = 0; i < blocks; i++)
else micros.mt[i] = SDL_SwapLE16(pieces[blocks - 2 + (i & 1) - (i & 0xE)]);
pPiece = (uint16_t *)&pLevelPieces[32 * lv];
for (i = 0; i < blocks; i++)
pMap->mt[i] = SDL_SwapLE16(pPiece[(i & 1) + blocks - 2 - (i & 0xE)]);
} else { } else {
for (i = 0; i < blocks; i++) for (int i = 0; i < blocks; i++)
pMap->mt[i] = 0; micros.mt[i] = 0;
} }
} }
} }

2
Source/gendung.h

@ -131,7 +131,7 @@ extern std::unique_ptr<uint16_t[]> pSetPiece;
extern bool setloadflag; extern bool setloadflag;
extern std::optional<CelSprite> pSpecialCels; extern std::optional<CelSprite> pSpecialCels;
extern std::unique_ptr<MegaTile[]> pMegaTiles; extern std::unique_ptr<MegaTile[]> pMegaTiles;
extern std::unique_ptr<BYTE[]> pLevelPieces; extern std::unique_ptr<uint16_t[]> pLevelPieces;
extern std::unique_ptr<BYTE[]> pDungeonCels; extern std::unique_ptr<BYTE[]> pDungeonCels;
/** /**
* List of transparancy masks to use for dPieces * List of transparancy masks to use for dPieces

20
Source/lighting.cpp

@ -22,7 +22,7 @@ char lightmax;
bool dolighting; bool dolighting;
BYTE lightblock[64][16][16]; BYTE lightblock[64][16][16];
int visionid; int visionid;
std::array<BYTE, LIGHTSIZE> pLightTbl; std::array<uint8_t, LIGHTSIZE> pLightTbl;
bool lightflag; bool lightflag;
/** /**
@ -769,7 +769,7 @@ void MakeLightTable()
int i, j, k, l, lights, shade, l1, l2, cnt, rem, div; int i, j, k, l, lights, shade, l1, l2, cnt, rem, div;
double fs, fa; double fs, fa;
BYTE col, max; BYTE col, max;
BYTE *tbl; uint8_t *tbl;
BYTE blood[16]; BYTE blood[16];
tbl = pLightTbl.data(); tbl = pLightTbl.data();
@ -893,19 +893,11 @@ void MakeLightTable()
tbl += 240; tbl += 240;
} }
{ LoadFileInMem("PlrGFX\\Infra.TRN", tbl, 256);
auto trn = LoadFileInMem<BYTE>("PlrGFX\\Infra.TRN"); tbl += 256;
for (i = 0; i < 256; i++) {
*tbl++ = trn[i];
}
}
{ LoadFileInMem("PlrGFX\\Stone.TRN", tbl, 256);
auto trn = LoadFileInMem<BYTE>("PlrGFX\\Stone.TRN"); tbl += 256;
for (i = 0; i < 256; i++) {
*tbl++ = trn[i];
}
}
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
for (col = 226; col < 239; col++) { for (col = 226; col < 239; col++) {

37
Source/monster.cpp

@ -6,6 +6,7 @@
#include "monster.h" #include "monster.h"
#include <algorithm> #include <algorithm>
#include <array>
#include <climits> #include <climits>
#include "control.h" #include "control.h"
@ -141,28 +142,24 @@ void (*AiProc[])(int i) = {
&MAI_BoneDemon &MAI_BoneDemon
}; };
void InitMonsterTRN(int monst, bool special) void InitMonsterTRN(CMonster &monst)
{ {
BYTE *f; std::array<uint8_t, 256> colorTranslations;
int i, n, j; LoadFileInMem(monst.MData->TransFile, colorTranslations);
f = Monsters[monst].trans_file; std::replace(colorTranslations.begin(), colorTranslations.end(), 255, 0);
for (i = 0; i < 256; i++) {
if (*f == 255) { int n = monst.MData->has_special ? 6 : 5;
*f = 0; for (int i = 0; i < n; i++) {
if (i == 1 && monst.mtype >= MT_COUNSLR && monst.mtype <= MT_ADVOCATE) {
continue;
} }
f++;
}
n = special ? 6 : 5; for (int j = 0; j < 8; j++) {
for (i = 0; i < n; i++) { Cl2ApplyTrans(
if (i != 1 || Monsters[monst].mtype < MT_COUNSLR || Monsters[monst].mtype > MT_ADVOCATE) { monst.Anims[i].Data[j],
for (j = 0; j < 8; j++) { colorTranslations,
Cl2ApplyTrans( monst.Anims[i].Frames);
Monsters[monst].Anims[i].Data[j],
Monsters[monst].trans_file,
Monsters[monst].Anims[i].Frames);
}
} }
} }
} }
@ -384,9 +381,7 @@ void InitMonsterGFX(int monst)
Monsters[monst].MData = &monsterdata[mtype]; Monsters[monst].MData = &monsterdata[mtype];
if (monsterdata[mtype].has_trans) { if (monsterdata[mtype].has_trans) {
Monsters[monst].trans_file = LoadFileInMem<BYTE>(monsterdata[mtype].TransFile).release(); InitMonsterTRN(Monsters[monst]);
InitMonsterTRN(monst, monsterdata[mtype].has_special);
delete[] Monsters[monst].trans_file;
} }
if (mtype >= MT_NMAGMA && mtype <= MT_WMAGMA && !(MissileFileFlag & 1)) { if (mtype >= MT_NMAGMA && mtype <= MT_WMAGMA && !(MissileFileFlag & 1)) {

5
Source/monster.h

@ -130,11 +130,6 @@ struct CMonster {
uint8_t mAFNum; uint8_t mAFNum;
int8_t mdeadval; int8_t mdeadval;
const MonsterData *MData; const MonsterData *MData;
/**
* A TRN file contains a sequence of color transitions, represented
* as indexes into a palette. (a 256 byte array of palette indices)
*/
uint8_t *trans_file;
}; };
struct MonsterStruct { // note: missing field _mAFNum struct MonsterStruct { // note: missing field _mAFNum

34
Source/objects.cpp

@ -2237,37 +2237,27 @@ void ProcessObjects()
void ObjSetMicro(int dx, int dy, int pn) void ObjSetMicro(int dx, int dy, int pn)
{ {
uint16_t *v;
MICROS *defs;
int i;
dPiece[dx][dy] = pn; dPiece[dx][dy] = pn;
pn--; pn--;
defs = &dpiece_defs_map_2[dx][dy];
if (leveltype != DTYPE_HELL) { int blocks = leveltype != DTYPE_HELL ? 10 : 16;
v = (uint16_t *)pLevelPieces.get() + 10 * pn;
for (i = 0; i < 10; i++) { uint16_t *piece = &pLevelPieces[blocks * pn ];
defs->mt[i] = SDL_SwapLE16(v[(i & 1) - (i & 0xE) + 8]); MICROS &micros = dpiece_defs_map_2[dx][dy];
}
} else { for (int i = 0; i < blocks; i++) {
v = (uint16_t *)pLevelPieces.get() + 16 * pn; micros.mt[i] = SDL_SwapLE16(piece[blocks - 2 + (i & 1) - (i & 0xE)]);
for (i = 0; i < 16; i++) {
defs->mt[i] = SDL_SwapLE16(v[(i & 1) - (i & 0xE) + 14]);
}
} }
} }
void objects_set_door_piece(int x, int y) void objects_set_door_piece(int x, int y)
{ {
int pn; int pn = dPiece[x][y] - 1;
long v1, v2;
pn = dPiece[x][y] - 1; uint16_t *piece = &pLevelPieces[10 * pn + 8];
v1 = *((uint16_t *)pLevelPieces.get() + 10 * pn + 8); dpiece_defs_map_2[x][y].mt[0] = SDL_SwapLE16(piece[0]);
v2 = *((uint16_t *)pLevelPieces.get() + 10 * pn + 9); dpiece_defs_map_2[x][y].mt[1] = SDL_SwapLE16(piece[1]);
dpiece_defs_map_2[x][y].mt[0] = SDL_SwapLE16(v1);
dpiece_defs_map_2[x][y].mt[1] = SDL_SwapLE16(v2);
} }
void ObjSetMini(int x, int y, int v) void ObjSetMini(int x, int y, int v)

Loading…
Cancel
Save