Skip to content

Commit

Permalink
Some refactoring in the map code
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Apr 6, 2024
1 parent c546308 commit 58c33d2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 47 deletions.
41 changes: 2 additions & 39 deletions src/common/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ using std::endl;


extern gfxSprite spr_frontmap[2];
extern short g_iTileConversion[];
// extern int32_t g_iVersion[];

extern bool VersionIsEqual(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild);
Expand Down Expand Up @@ -96,40 +95,6 @@ SDL_Rect g_rPirhanaRects[4][4][4] = { { { {0, 0, 32, 48}, {32, 0, 32, 48}, {64,
}
};

// Conversion to switch 1.6 tiles into 1.7 tiles
short g_iTileConversion[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 575,670,702,703,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 332,331,330,637,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 365,299,366,853,
537,595,505,658,659,656,657,774,775,776,
540,96, 97, 98, 643,644,645,26, 27, 506,
122,123,124,690,691,688,689,745,746,747,
569,128,129,130,704,677,907,90, 91, 572,
931,602,539,885,728,729,730,731,186,187,
188,160,161,162,736,192,194,30, 31, 898,
737,738,739,800,760,761,762,763,218,219,
220,864,865,509,768,224,226,62, 63, 930,
769,770,771,508,598,599,600,507,601,510,
603,896,897,192,193,260,259,193,194,541,
627,699,697,940,941,942,860,861,862,250,
252,543,158,498,499,500,922,924,854,886,
605,125,126,127,720,721,752,754,753,722,
723,928,929,563,531,532,923,571,882,851,
309,310,311,343,278,341,99, 100,101,489,
490,491,384,385,386,147,113,148,914,664,
373,374,375,376,310,377,131,132,133,553,
554,555,416,417,418,179,145,180,946,570,
867,868,869,213,214,215,163,164,165,566,
567,568,448,449,450,863,530,504,892,883,
899,900,901,245,246,247,777,778,779,250,
251,252,856,857,858,859,562,712,893,905,
908,909,910,624,625,626,592,593,594,282,
283,284,888,889,890,891,710,711,894,937
};

short iPlatformPathDotOffset[3] = {0, 12, 18};
short iPlatformPathDotSize[3] = {12, 6, 4};

Expand All @@ -138,8 +103,6 @@ short iFireballHazardSize[3] = {18, 9, 5};
short iStandardOffset[3] = {0, 32, 48};
float dBulletBillFrequency[3] = {10.0f, 5.0f, 2.5f};

short iPirhanaPlantOffsetY[4][3] = {{0, 0, 0}, {48, 24, 12}, {96, 48, 24}, {160, 80, 40}};


namespace {
int GetScreenWidth(int iSize) {
Expand Down Expand Up @@ -238,7 +201,7 @@ void DrawMapHazard(MapHazard * hazard, short iSize, bool fDrawCenter)
iBulletPathX += hazard->iparam[0] < 0.0f ? -iBulletPathSpacing : iBulletPathSpacing;
}
} else if (hazard->itype == 3) { //flame cannon
SDL_Rect * rect = &g_rFlameRects[hazard->iparam[1]][2];
const SDL_Rect * rect = &g_rFlameRects[hazard->iparam[1]][2];

short iOffsetX = 0;
short iOffsetY = 0;
Expand All @@ -251,7 +214,7 @@ void DrawMapHazard(MapHazard * hazard, short iSize, bool fDrawCenter)

rm->spr_hazard_flame[iSize].draw(rPathDst.x + iOffsetX, rPathDst.y + iOffsetY, rect->x >> iSize, rect->y >> iSize, rect->w >> iSize, rect->h >> iSize);
} else if (hazard->itype >= 4 && hazard->itype <= 7) { //pirhana plants
SDL_Rect * rect = &g_rPirhanaRects[hazard->itype - 4][hazard->iparam[1]][0];
const SDL_Rect * rect = &g_rPirhanaRects[hazard->itype - 4][hazard->iparam[1]][0];
short iOffsetX = 0;
short iOffsetY = 0;

Expand Down
5 changes: 0 additions & 5 deletions src/common/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ struct TilesetTile {
short iRow;
};

struct TilesetTranslation {
short iID;
char szName[128];
};

struct AnimatedTile {
short id;
TilesetTile layers[4];
Expand Down
39 changes: 38 additions & 1 deletion src/common/map/MapReader16xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,47 @@
#include <iostream>

extern CTilesetManager* g_tilesetmanager;
extern short g_iTileConversion[];
extern short g_iTileTypeConversion[NUMTILETYPES];
extern short g_iDefaultPowerupPresets[NUM_POWERUP_PRESETS][NUM_POWERUPS];


namespace {
// Conversion to switch 1.6 tiles into 1.7 tiles
constexpr short g_iTileConversion[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 575,670,702,703,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 332,331,330,637,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 365,299,366,853,
537,595,505,658,659,656,657,774,775,776,
540,96, 97, 98, 643,644,645,26, 27, 506,
122,123,124,690,691,688,689,745,746,747,
569,128,129,130,704,677,907,90, 91, 572,
931,602,539,885,728,729,730,731,186,187,
188,160,161,162,736,192,194,30, 31, 898,
737,738,739,800,760,761,762,763,218,219,
220,864,865,509,768,224,226,62, 63, 930,
769,770,771,508,598,599,600,507,601,510,
603,896,897,192,193,260,259,193,194,541,
627,699,697,940,941,942,860,861,862,250,
252,543,158,498,499,500,922,924,854,886,
605,125,126,127,720,721,752,754,753,722,
723,928,929,563,531,532,923,571,882,851,
309,310,311,343,278,341,99, 100,101,489,
490,491,384,385,386,147,113,148,914,664,
373,374,375,376,310,377,131,132,133,553,
554,555,416,417,418,179,145,180,946,570,
867,868,869,213,214,215,163,164,165,566,
567,568,448,449,450,863,530,504,892,883,
899,900,901,245,246,247,777,778,779,250,
251,252,856,857,858,859,562,712,893,905,
908,909,910,624,625,626,592,593,594,282,
283,284,888,889,890,891,710,711,894,937
};
} // namespace


MapReader1600::MapReader1600()
: MapReader1500()
, parse_nospawn(false)
Expand Down
9 changes: 9 additions & 0 deletions src/common/map/MapReader18xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ extern short g_iTileTypeConversion[NUMTILETYPES];

using namespace std;


namespace {
struct TilesetTranslation {
short iID;
char szName[128];
};
} // namespace


MapReader1800::MapReader1800()
: MapReader1702()
, iMaxTilesetID(-1)
Expand Down
4 changes: 2 additions & 2 deletions src/smw/objecthazard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void IO_FlameCannon::update()
void IO_FlameCannon::draw()
{
if (state > 0) {
SDL_Rect * rect = &g_rFlameRects[iDirection][iFrame];
const SDL_Rect * rect = &g_rFlameRects[iDirection][iFrame];
rm->spr_hazard_flame[0].draw(ix, iy, rect->x, rect->y, rect->w, rect->h);
}
}
Expand All @@ -550,7 +550,7 @@ void IO_FlameCannon::draw()
void IO_FlameCannon::draw(short iOffsetX, short iOffsetY)
{
if (state > 0) {
SDL_Rect * rect = &g_rFlameRects[iDirection][iFrame];
const SDL_Rect * rect = &g_rFlameRects[iDirection][iFrame];
gfx_drawpreview(rm->spr_hazard_flame[1].getSurface(), (ix >> 1) + iOffsetX, (iy >> 1) + iOffsetY, rect->x >> 1, rect->y >> 1, rect->w >> 1, rect->h >> 1, iOffsetX, iOffsetY, 320, 240, true);
}
}
Expand Down

0 comments on commit 58c33d2

Please sign in to comment.