Browse Source

Use GetDunSize in loops

pull/6842/head
obligaron 2 years ago committed by Anders Jenbo
parent
commit
42e1b82a91
  1. 23
      Source/levels/gendung.cpp
  2. 10
      Source/levels/town.cpp
  3. 16
      Source/monster.cpp
  4. 38
      Source/objects.cpp
  5. 11
      Source/quests.cpp

23
Source/levels/gendung.cpp

@ -537,19 +537,17 @@ void DRLG_CopyTrans(int sx, int sy, int dx, int dy)
void LoadTransparency(const uint16_t *dunData)
{
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
WorldTileSize size = GetDunSize(dunData);
int layer2Offset = 2 + width * height;
int layer2Offset = 2 + size.width * size.height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
size *= static_cast<WorldTileCoord>(2);
const uint16_t *transparentLayer = &dunData[layer2Offset + width * height * 3];
const uint16_t *transparentLayer = &dunData[layer2Offset + size.width * size.height * 3];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
for (WorldTileCoord j = 0; j < size.height; j++) {
for (WorldTileCoord i = 0; i < size.width; i++) {
dTransVal[16 + i][16 + j] = SDL_SwapLE16(*transparentLayer);
transparentLayer++;
}
@ -631,14 +629,13 @@ std::optional<Point> PlaceMiniSet(const Miniset &miniset, int tries, bool drlg1Q
void PlaceDunTiles(const uint16_t *dunData, Point position, int floorId)
{
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
WorldTileSize size = GetDunSize(dunData);
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
auto tileId = static_cast<uint8_t>(SDL_SwapLE16(tileLayer[j * width + i]));
for (WorldTileCoord j = 0; j < size.height; j++) {
for (WorldTileCoord i = 0; i < size.width; i++) {
auto tileId = static_cast<uint8_t>(SDL_SwapLE16(tileLayer[j * size.width + i]));
if (tileId != 0) {
dungeon[position.x + i][position.y + j] = tileId;
Protected.set(position.x + i, position.y + j);

10
Source/levels/town.cpp

@ -24,20 +24,18 @@ void FillSector(const char *path, int xi, int yy)
{
auto dunData = LoadFileInMem<uint16_t>(path);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
WorldTileSize size = GetDunSize(dunData.get());
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (WorldTileCoord j = 0; j < size.height; j++) {
int xx = xi;
for (int i = 0; i < width; i++) {
for (WorldTileCoord i = 0; i < size.width; i++) {
int v1 = 218;
int v2 = 218;
int v3 = 218;
int v4 = 218;
int tileId = SDL_SwapLE16(tileLayer[j * width + i]) - 1;
int tileId = SDL_SwapLE16(tileLayer[j * size.width + i]) - 1;
if (tileId >= 0) {
MegaTile mega = pMegaTiles[tileId];
v1 = SDL_SwapLE16(mega.micro1);

16
Source/monster.cpp

@ -3601,20 +3601,18 @@ void SetMapMonsters(const uint16_t *dunData, Point startPosition)
PlaceUniqueMonst(UniqueMonsterType::BlackJade, 0, 0);
}
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
WorldTileSize size = GetDunSize(dunData);
int layer2Offset = 2 + width * height;
int layer2Offset = 2 + size.width * size.height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
size *= static_cast<WorldTileCoord>(2);
const uint16_t *monsterLayer = &dunData[layer2Offset + width * height];
const uint16_t *monsterLayer = &dunData[layer2Offset + size.width * size.height];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
auto monsterId = static_cast<uint8_t>(SDL_SwapLE16(monsterLayer[j * width + i]));
for (WorldTileCoord j = 0; j < size.height; j++) {
for (WorldTileCoord i = 0; i < size.width; i++) {
auto monsterId = static_cast<uint8_t>(SDL_SwapLE16(monsterLayer[j * size.width + i]));
if (monsterId != 0) {
const size_t typeIndex = AddMonsterType(MonstConvTbl[monsterId - 1], PLACE_SPECIAL);
PlaceMonster(ActiveMonsterCount++, typeIndex, startPosition + Displacement { i, j });

38
Source/objects.cpp

@ -559,20 +559,18 @@ void LoadMapObjects(const char *path, Point start, WorldTileRectangle mapRange =
auto dunData = LoadFileInMem<uint16_t>(path);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
WorldTileSize size = GetDunSize(dunData.get());
int layer2Offset = 2 + width * height;
int layer2Offset = 2 + size.width * size.height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
size.width *= static_cast<WorldTileCoord>(2);
const uint16_t *objectLayer = &dunData[layer2Offset + width * height * 2];
const uint16_t *objectLayer = &dunData[layer2Offset + size.width * size.height * 2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
auto objectId = static_cast<uint8_t>(SDL_SwapLE16(objectLayer[j * width + i]));
for (WorldTileCoord j = 0; j < size.height; j++) {
for (WorldTileCoord i = 0; i < size.width; i++) {
auto objectId = static_cast<uint8_t>(SDL_SwapLE16(objectLayer[j * size.width + i]));
if (objectId != 0) {
Point mapPos = start + Displacement { i, j };
Object *mapObject = AddObject(ObjTypeConv[objectId], mapPos);
@ -3949,20 +3947,18 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty)
ClrAllObjects();
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
WorldTileSize size = GetDunSize(dunData);
int layer2Offset = 2 + width * height;
int layer2Offset = 2 + size.width * size.height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
size.width *= static_cast<WorldTileCoord>(2);
const uint16_t *objectLayer = &dunData[layer2Offset + width * height * 2];
const uint16_t *objectLayer = &dunData[layer2Offset + size.width * size.height * 2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
auto objectId = static_cast<uint8_t>(SDL_SwapLE16(objectLayer[j * width + i]));
for (WorldTileCoord j = 0; j < size.height; j++) {
for (WorldTileCoord i = 0; i < size.width; i++) {
auto objectId = static_cast<uint8_t>(SDL_SwapLE16(objectLayer[j * size.width + i]));
if (objectId != 0) {
const ObjectData &objectData = AllObjects[ObjTypeConv[objectId]];
filesWidths[objectData.ofindex] = objectData.animWidth;
@ -3972,9 +3968,9 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty)
LoadLevelObjects(filesWidths);
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
auto objectId = static_cast<uint8_t>(SDL_SwapLE16(objectLayer[j * width + i]));
for (WorldTileCoord j = 0; j < size.height; j++) {
for (WorldTileCoord i = 0; i < size.width; i++) {
auto objectId = static_cast<uint8_t>(SDL_SwapLE16(objectLayer[j * size.width + i]));
if (objectId != 0) {
AddObject(ObjTypeConv[objectId], { startx + 16 + i, starty + 16 + j });
}

11
Source/quests.cpp

@ -167,16 +167,15 @@ void DrawLTBanner(Point position)
{
auto dunData = LoadFileInMem<uint16_t>("levels\\l1data\\banner1.dun");
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
WorldTileSize size = GetDunSize(dunData.get());
SetPiece = { position, GetDunSize(dunData.get()) };
SetPiece = { position, size };
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
auto tileId = static_cast<uint8_t>(SDL_SwapLE16(tileLayer[j * width + i]));
for (WorldTileCoord j = 0; j < size.height; j++) {
for (WorldTileCoord i = 0; i < size.width; i++) {
auto tileId = static_cast<uint8_t>(SDL_SwapLE16(tileLayer[j * size.width + i]));
if (tileId != 0) {
pdungeon[position.x + i][position.y + j] = tileId;
}

Loading…
Cancel
Save