Browse Source

Test cathedral level generation

pull/4642/head
Anders Jenbo 4 years ago committed by GitHub
parent
commit
c241cae9e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      Source/gendung.h
  2. 6
      Source/setmaps.cpp
  3. 138
      test/drlg_l1_test.cpp
  4. BIN
      test/fixtures/diablo/1-743271966.dun
  5. BIN
      test/fixtures/diablo/2-1383137027.dun
  6. BIN
      test/fixtures/diablo/3-844660068.dun
  7. BIN
      test/fixtures/diablo/4-609325643.dun
  8. BIN
      test/fixtures/hellfire/1-401921334.dun
  9. BIN
      test/fixtures/hellfire/2-128964898.dun
  10. BIN
      test/fixtures/hellfire/3-1799396623.dun
  11. BIN
      test/fixtures/hellfire/4-1190318991.dun

8
Source/gendung.h

@ -134,7 +134,7 @@ struct ShadowStruct {
};
/** Contains the tile IDs of the map. */
extern uint8_t dungeon[DMAXX][DMAXY];
extern DVL_API_FOR_TEST uint8_t dungeon[DMAXX][DMAXY];
/** Contains a backup of the tile IDs of the map. */
extern uint8_t pdungeon[DMAXX][DMAXY];
extern uint8_t dflags[DMAXX][DMAXY];
@ -152,7 +152,7 @@ extern std::unique_ptr<uint16_t[]> pSetPiece;
extern bool setloadflag;
extern std::optional<OwnedCelSprite> pSpecialCels;
/** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */
extern std::unique_ptr<MegaTile[]> pMegaTiles;
extern DVL_API_FOR_TEST std::unique_ptr<MegaTile[]> pMegaTiles;
extern std::unique_ptr<uint16_t[]> pLevelPieces;
extern std::unique_ptr<byte[]> pDungeonCels;
/**
@ -190,7 +190,7 @@ extern _setlevels setlvlnum;
/** Specifies the player viewpoint X-coordinate of the map. */
extern dungeon_type setlvltype;
/** Specifies the player viewpoint X,Y-coordinates of the map. */
extern Point ViewPosition;
extern DVL_API_FOR_TEST Point ViewPosition;
extern ScrollStruct ScrollInfo;
extern int MicroTileLen;
extern char TransVal;
@ -201,7 +201,7 @@ extern DVL_API_FOR_TEST int dPiece[MAXDUNX][MAXDUNY];
/** Specifies the dungeon piece information for a given coordinate and block number. */
extern MICROS dpiece_defs_map_2[MAXDUNX][MAXDUNY];
/** Specifies the transparency at each coordinate of the map. */
extern int8_t dTransVal[MAXDUNX][MAXDUNY];
extern DVL_API_FOR_TEST int8_t dTransVal[MAXDUNX][MAXDUNY];
extern DVL_API_FOR_TEST char dLight[MAXDUNX][MAXDUNY];
extern char dPreLight[MAXDUNX][MAXDUNY];
/** Holds various information about dungeon tiles, @see DungeonFlag */

6
Source/setmaps.cpp

@ -129,12 +129,12 @@ void SetMapTransparency(const char *path)
width *= 2;
height *= 2;
const uint16_t *transparantLayer = &dunData[layer2Offset + width * height * 3];
const uint16_t *transparentLayer = &dunData[layer2Offset + width * height * 3];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
dTransVal[16 + i][16 + j] = SDL_SwapLE16(*transparantLayer);
transparantLayer++;
dTransVal[16 + i][16 + j] = SDL_SwapLE16(*transparentLayer);
transparentLayer++;
}
}
}

138
test/drlg_l1_test.cpp

@ -1,11 +1,18 @@
#include <fmt/format.h>
#include <gtest/gtest.h>
#include "diablo.h"
#include "drlg_l1.h"
#include "engine/load_file.hpp"
#include "lighting.h"
#include "player.h"
#include "quests.h"
#include "utils/paths.h"
using namespace devilution;
namespace {
TEST(Drlg_l1, DRLG_Init_Globals_noflag)
{
DisableLighting = false;
@ -19,3 +26,134 @@ TEST(Drlg_l1, DRLG_Init_Globals)
DRLG_Init_Globals();
EXPECT_EQ(dLight[0][0], 0);
}
void TestCreateL5Dungeon(bool hellfire, int level, uint32_t seed, lvl_entry entry)
{
pMegaTiles = std::make_unique<MegaTile[]>(1648);
MyPlayer->pOriginalCathedral = !hellfire;
currlevel = level;
leveltype = DTYPE_CATHEDRAL;
CreateL5Dungeon(seed, entry);
std::string path = paths::BasePath();
paths::SetPrefPath(path);
std::string dunPath;
if (hellfire)
dunPath = fmt::format("../test/fixtures/hellfire/{}-{}.dun", level, seed);
else
dunPath = fmt::format("../test/fixtures/diablo/{}-{}.dun", level, seed);
auto dunData = LoadFileInMem<uint16_t>(dunPath.c_str());
ASSERT_EQ(DMAXX, dunData[0]);
ASSERT_EQ(DMAXY, dunData[1]);
const uint16_t *tileLayer = &dunData[2];
for (int y = 0; y < DMAXY; y++) {
for (int x = 0; x < DMAXX; x++) {
auto tileId = static_cast<uint8_t>(SDL_SwapLE16(*tileLayer));
tileLayer++;
ASSERT_EQ(dungeon[x][y], tileId);
}
}
const uint16_t *transparentLayer = &dunData[2 + DMAXX * DMAXY * 13];
for (int y = 16; y < 16 + DMAXY * 2; y++) {
for (int x = 16; x < 16 + DMAXX * 2; x++) {
auto sectorId = static_cast<uint8_t>(SDL_SwapLE16(*transparentLayer));
transparentLayer++;
ASSERT_EQ(dTransVal[x][y], sectorId) << "Room/region indexes don't match";
}
}
}
TEST(Drlg_l1, CreateL5Dungeon_diablo_1_743271966)
{
TestCreateL5Dungeon(false, 1, 743271966, ENTRY_MAIN);
EXPECT_EQ(ViewPosition.x, 51);
EXPECT_EQ(ViewPosition.y, 82);
TestCreateL5Dungeon(false, 1, 743271966, ENTRY_PREV);
EXPECT_EQ(ViewPosition.x, 81);
EXPECT_EQ(ViewPosition.y, 47);
}
TEST(Drlg_l1, CreateL5Dungeon_diablo_2_1383137027)
{
Quests[Q_PWATER]._qlevel = 2;
Quests[Q_PWATER]._qactive = QUEST_INIT;
TestCreateL5Dungeon(false, 2, 1383137027, ENTRY_MAIN);
EXPECT_EQ(ViewPosition.x, 57);
EXPECT_EQ(ViewPosition.y, 74);
TestCreateL5Dungeon(false, 2, 1383137027, ENTRY_PREV);
EXPECT_EQ(ViewPosition.x, 57);
EXPECT_EQ(ViewPosition.y, 79);
}
TEST(Drlg_l1, CreateL5Dungeon_diablo_3_844660068)
{
TestCreateL5Dungeon(false, 3, 844660068, ENTRY_MAIN);
EXPECT_EQ(ViewPosition.x, 67);
EXPECT_EQ(ViewPosition.y, 52);
TestCreateL5Dungeon(false, 3, 844660068, ENTRY_PREV);
EXPECT_EQ(ViewPosition.x, 85);
EXPECT_EQ(ViewPosition.y, 45);
}
TEST(Drlg_l1, CreateL5Dungeon_diablo_4_609325643)
{
TestCreateL5Dungeon(false, 4, 609325643, ENTRY_MAIN);
EXPECT_EQ(ViewPosition.x, 85);
EXPECT_EQ(ViewPosition.y, 78);
TestCreateL5Dungeon(false, 4, 609325643, ENTRY_PREV);
EXPECT_EQ(ViewPosition.x, 55);
EXPECT_EQ(ViewPosition.y, 47);
}
TEST(Drlg_l1, CreateL5Dungeon_hellfire_1_401921334)
{
TestCreateL5Dungeon(true, 1, 401921334, ENTRY_MAIN);
EXPECT_EQ(ViewPosition.x, 79);
EXPECT_EQ(ViewPosition.y, 80);
TestCreateL5Dungeon(true, 1, 401921334, ENTRY_PREV);
EXPECT_EQ(ViewPosition.x, 49);
EXPECT_EQ(ViewPosition.y, 63);
}
TEST(Drlg_l1, CreateL5Dungeon_hellfire_2_128964898)
{
Quests[Q_PWATER]._qactive = QUEST_NOTAVAIL;
TestCreateL5Dungeon(true, 2, 128964898, ENTRY_MAIN);
EXPECT_EQ(ViewPosition.x, 55);
EXPECT_EQ(ViewPosition.y, 68);
TestCreateL5Dungeon(true, 2, 128964898, ENTRY_PREV);
EXPECT_EQ(ViewPosition.x, 49);
EXPECT_EQ(ViewPosition.y, 63);
}
TEST(Drlg_l1, CreateL5Dungeon_hellfire_3_1799396623)
{
TestCreateL5Dungeon(true, 3, 1799396623, ENTRY_MAIN);
EXPECT_EQ(ViewPosition.x, 59);
EXPECT_EQ(ViewPosition.y, 68);
TestCreateL5Dungeon(true, 3, 1799396623, ENTRY_PREV);
EXPECT_EQ(ViewPosition.x, 47);
EXPECT_EQ(ViewPosition.y, 55);
}
TEST(Drlg_l1, CreateL5Dungeon_hellfire_4_1190318991)
{
TestCreateL5Dungeon(true, 4, 1190318991, ENTRY_MAIN);
EXPECT_EQ(ViewPosition.x, 67);
EXPECT_EQ(ViewPosition.y, 80);
TestCreateL5Dungeon(true, 4, 1190318991, ENTRY_PREV);
EXPECT_EQ(ViewPosition.x, 77);
EXPECT_EQ(ViewPosition.y, 45);
}
} // namespace

BIN
test/fixtures/diablo/1-743271966.dun vendored

Binary file not shown.

BIN
test/fixtures/diablo/2-1383137027.dun vendored

Binary file not shown.

BIN
test/fixtures/diablo/3-844660068.dun vendored

Binary file not shown.

BIN
test/fixtures/diablo/4-609325643.dun vendored

Binary file not shown.

BIN
test/fixtures/hellfire/1-401921334.dun vendored

Binary file not shown.

BIN
test/fixtures/hellfire/2-128964898.dun vendored

Binary file not shown.

BIN
test/fixtures/hellfire/3-1799396623.dun vendored

Binary file not shown.

BIN
test/fixtures/hellfire/4-1190318991.dun vendored

Binary file not shown.
Loading…
Cancel
Save