Skip to content

Commit

Permalink
Resolve some magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
carstene1ns committed Feb 18, 2024
1 parent 3b0ebb7 commit dda5786
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/jj1/level/jj1levelload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ int JJ1Level::load (char* fileName, bool checkpoint) {

switch (type) {

case 2:
case PE_SKY:

sky = true;

Expand All @@ -956,21 +956,21 @@ int JJ1Level::load (char* fileName, bool checkpoint) {

break;

case 8:
case PE_2D:

// Parallaxing background effect
paletteEffects = new P2DPaletteEffect(128, 64, FE, NULL);

break;

case 9:
case PE_1D:

// Diagonal stripes "parallaxing" background effect
paletteEffects = new P1DPaletteEffect(128, 32, FH, NULL);

break;

case 11:
case PE_WATER:

// The deeper below water, the darker it gets
paletteEffects = new WaterPaletteEffect(TTOF(32), NULL);
Expand All @@ -981,6 +981,7 @@ int JJ1Level::load (char* fileName, bool checkpoint) {

// No effect
paletteEffects = NULL;
LOG_TRACE("Unknown palette effect: %d", type);

break;

Expand Down
16 changes: 8 additions & 8 deletions src/menu/gamemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ GameMenu::GameMenu (File *file) {

}

episodes = 11;
episodes = MAX_EPISODES;

for (int i = 0; i < 11; i++) {
for (int i = 0; i < MAX_EPISODES; i++) {

episodeScreens[i] = file->loadSurface(134, 110);

if (file->tell() >= file->getSize()) {

episodes = ++i;

for (; i < 11; i++) {
for (; i < MAX_EPISODES; i++) {

unsigned char pixel = 0;
episodeScreens[i] = createSurface(&pixel, 1, 1);
Expand All @@ -94,7 +94,7 @@ GameMenu::GameMenu (File *file) {
*/
GameMenu::~GameMenu () {

for (int i = 0; i < 11; i++) SDL_FreeSurface(episodeScreens[i]);
for (int i = 0; i < MAX_EPISODES; i++) SDL_FreeSurface(episodeScreens[i]);

SDL_FreeSurface(difficultyScreen);

Expand Down Expand Up @@ -302,14 +302,14 @@ int GameMenu::loadGame () {

if (controls.release(C_LEFT)) {

if (option) levelNum = ((levelNum + 11) % 11) - 1;
if (option) levelNum = ((levelNum + MAX_EPISODES) % MAX_EPISODES) - 1;
else worldNum = (worldNum + 999) % 1000;

}

if (controls.release(C_RIGHT)) {

if (option) levelNum = ((levelNum + 2) % 11) - 1;
if (option) levelNum = ((levelNum + 2) % MAX_EPISODES) - 1;
else worldNum = (worldNum + 1) % 1000;

}
Expand Down Expand Up @@ -493,7 +493,7 @@ int GameMenu::newGameEpisode (GameModeType mode) {

} else exists[10] = false;

exists[11] = true; // always possible to load custom level
exists[MAX_EPISODES] = true; // always possible to load custom level

episode = 0;

Expand All @@ -503,7 +503,7 @@ int GameMenu::newGameEpisode (GameModeType mode) {

if (controls.release(C_ESCAPE)) return E_NONE;

if (controls.release(C_UP)) episode = (episode + 11) % 12;
if (controls.release(C_UP)) episode = (episode + MAX_EPISODES) % 12;

if (controls.release(C_DOWN)) episode = (episode + 1) % 12;

Expand Down
4 changes: 3 additions & 1 deletion src/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#define ESCAPE_STRING "(esc) quits"

#define MAX_EPISODES 11

// Demo timeout
#define T_DEMO 20000

Expand All @@ -54,7 +56,7 @@ class Menu {
class GameMenu : public Menu {

private:
SDL_Surface* episodeScreens[11]; ///< Episode images
SDL_Surface* episodeScreens[MAX_EPISODES]; ///< Episode images
SDL_Surface* difficultyScreen; ///< 4 difficulty images
SDL_Color palette[MAX_PALETTE_COLORS]; ///< Episode selection palette
SDL_Color greyPalette[MAX_PALETTE_COLORS]; ///< Greyed-out episode selection palette
Expand Down

0 comments on commit dda5786

Please sign in to comment.