From cdeca65be7a3782fdb24138351cfb88a3ce9d51d Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 23 May 2023 18:37:32 -0700 Subject: [PATCH] Use enums for music tracks This adds an anonymous enum for music tracks and replaces all calls to music.play and music.niceplay that use integer literals. Additionally, this is also done for integer literals for cl.levmusic (except 0) and music.currentsong where appropriate, but _not_ the music areamap because that would not make it look very aesthetically pleasing in the code. This is not a named enum (that can be used for strict typechecking) because music track IDs are essentially part of the API of the game - almost every custom level uses these numbers. This is just to make the source code more readable without needing a comment to denote what number is what track. --- desktop_version/src/Editor.cpp | 32 ++++++++++++++++---------------- desktop_version/src/Game.cpp | 33 ++++++++++++++++++--------------- desktop_version/src/Input.cpp | 14 +++++++------- desktop_version/src/Logic.cpp | 22 +++++++++++----------- desktop_version/src/Map.cpp | 4 ++-- desktop_version/src/Music.cpp | 7 +++++-- desktop_version/src/Music.h | 20 ++++++++++++++++++++ desktop_version/src/Script.cpp | 8 ++++---- 8 files changed, 83 insertions(+), 57 deletions(-) diff --git a/desktop_version/src/Editor.cpp b/desktop_version/src/Editor.cpp index a936f9ba..e6617d65 100644 --- a/desktop_version/src/Editor.cpp +++ b/desktop_version/src/Editor.cpp @@ -299,49 +299,49 @@ static void editormenurender(int tr, int tg, int tb) case 0: songname = loc::gettext("No background music"); break; - case 1: + case Music_PUSHINGONWARDS: songname = loc::gettext("1: Pushing Onwards"); break; - case 2: + case Music_POSITIVEFORCE: songname = loc::gettext("2: Positive Force"); break; - case 3: + case Music_POTENTIALFORANYTHING: songname = loc::gettext("3: Potential for Anything"); break; - case 4: + case Music_PASSIONFOREXPLORING: songname = loc::gettext("4: Passion for Exploring"); break; - case 5: + case Music_PAUSE: songname = loc::gettext("N/A: Pause"); break; - case 6: + case Music_PRESENTINGVVVVVV: songname = loc::gettext("5: Presenting VVVVVV"); break; - case 7: + case Music_PLENARY: songname = loc::gettext("N/A: Plenary"); break; - case 8: + case Music_PREDESTINEDFATE: songname = loc::gettext("6: Predestined Fate"); break; - case 9: + case Music_POSITIVEFORCEREVERSED: songname = loc::gettext("N/A: ecroF evitisoP"); break; - case 10: + case Music_POPULARPOTPOURRI: songname = loc::gettext("7: Popular Potpourri"); break; - case 11: + case Music_PIPEDREAM: songname = loc::gettext("8: Pipe Dream"); break; - case 12: + case Music_PRESSURECOOKER: songname = loc::gettext("9: Pressure Cooker"); break; - case 13: + case Music_PACEDENERGY: songname = loc::gettext("10: Paced Energy"); break; - case 14: + case Music_PIERCINGTHESKY: songname = loc::gettext("11: Piercing the Sky"); break; - case 15: + case Music_PREDESTINEDFATEREMIX: songname = loc::gettext("N/A: Predestined Fate Remix"); break; default: @@ -1909,7 +1909,7 @@ void editorlogic(void) graphics.titlebg.colstate = 10; map.nexttowercolour(); game.quittomenu(); - music.play(6); //should be before game.quittomenu() + music.play(Music_PRESENTINGVVVVVV); // should be before game.quittomenu() } } diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 81c2584e..fef6cade 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -1501,7 +1501,7 @@ void Game::updatestate(void) if (!obj.flags[71]) { obj.flags[71] = true; - music.niceplay(15); //Final level remix + music.niceplay(Music_PREDESTINEDFATEREMIX); setstate(0); } obj.removetrigger(49); @@ -1575,7 +1575,7 @@ void Game::updatestate(void) break; case 81: quittomenu(); - music.play(6); //should be after quittomenu() + music.play(Music_PRESENTINGVVVVVV); //should be after quittomenu() setstate(0); break; @@ -1669,7 +1669,7 @@ void Game::updatestate(void) //Init final stretch incstate(); music.playef(9); - music.play(2); + music.play(Music_POSITIVEFORCE); obj.flags[72] = true; screenshake = 10; @@ -2210,7 +2210,7 @@ void Game::updatestate(void) } #endif quittomenu(); - music.play(6); //should be after quittomenu() + music.play(Music_PRESENTINGVVVVVV); //should be after quittomenu() setstate(0); break; @@ -2223,7 +2223,7 @@ void Game::updatestate(void) case 2500: - music.play(5); + music.play(Music_PAUSE); //Activating a teleporter (appear) incstate(); setstatedelay(15); @@ -2364,7 +2364,7 @@ void Game::updatestate(void) advancetext = false; setstate(0); - music.play(3); + music.play(Music_POTENTIALFORANYTHING); break; @@ -2464,7 +2464,7 @@ void Game::updatestate(void) //Level complete! (warp zone) unlocknum(4); lastsaved = 4; - music.play(0); + music.play(Music_PATHCOMPLETE); incstate(); setstatedelay(75); @@ -2505,7 +2505,7 @@ void Game::updatestate(void) //Level complete! (Space Station 2) unlocknum(3); lastsaved = 2; - music.play(0); + music.play(Music_PATHCOMPLETE); incstate(); setstatedelay(75); @@ -2547,7 +2547,7 @@ void Game::updatestate(void) //Level complete! (Lab) unlocknum(1); lastsaved = 5; - music.play(0); + music.play(Music_PATHCOMPLETE); incstate(); setstatedelay(75); @@ -2588,7 +2588,7 @@ void Game::updatestate(void) //Level complete! (Space Station 1) unlocknum(0); lastsaved = 1; - music.play(0); + music.play(Music_PATHCOMPLETE); incstate(); setstatedelay(75); @@ -2655,7 +2655,7 @@ void Game::updatestate(void) //Level complete! (Tower) unlocknum(2); lastsaved = 3; - music.play(0); + music.play(Music_PATHCOMPLETE); incstate(); setstatedelay(75); @@ -2863,7 +2863,7 @@ void Game::updatestate(void) break; case 3101: quittomenu(); - music.play(6); //should be after quittomenu(); + music.play(Music_PRESENTINGVVVVVV); //should be after quittomenu(); setstate(0); break; @@ -2879,7 +2879,7 @@ void Game::updatestate(void) crewstats[0] = true; incstate(); setstatedelay(75); - music.play(7); + music.play(Music_PLENARY); graphics.createtextboxflipme("", -1, 12, 164, 165, 255); graphics.addline(" "); @@ -5006,7 +5006,10 @@ void Game::start(void) deathseq = -1; lifeseq = 0; - if (!nocutscenes) music.play(5); + if (!nocutscenes) + { + music.play(Music_PAUSE); + } } void Game::deathsequence(void) @@ -7290,7 +7293,7 @@ void Game::returntolab(void) savedir = obj.entities[player].dir; } - music.play(11); + music.play(Music_PIPEDREAM); } #if !defined(NO_CUSTOM_LEVELS) && !defined(NO_EDITOR) diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 6096e3d5..0e929cb8 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -954,11 +954,11 @@ static void menuactionpress(void) { if (graphics.setflipmode) { - music.play(9); // ecroF evitisoP + music.play(Music_POSITIVEFORCEREVERSED); } else { - music.play(2); // Positive Force + music.play(Music_POSITIVEFORCE); } } } @@ -2045,7 +2045,7 @@ static void menuactionpress(void) case Menu::gameover2: //back music.playef(11); - music.play(6); + music.play(Music_PRESENTINGVVVVVV); game.returntomenu(Menu::playmodes); map.nexttowercolour(); break; @@ -2109,7 +2109,7 @@ static void menuactionpress(void) case 0: //back music.playef(11); - music.play(6); + music.play(Music_PRESENTINGVVVVVV); game.returntomenu(Menu::timetrials); map.nexttowercolour(); break; @@ -2122,7 +2122,7 @@ static void menuactionpress(void) break; case Menu::gamecompletecontinue: case Menu::nodeathmodecomplete2: - music.play(6); + music.play(Music_PRESENTINGVVVVVV); music.playef(11); game.returnmenu(); map.nexttowercolour(); @@ -2363,7 +2363,7 @@ void titleinput(void) if (!game.menustart) { game.menustart = true; - music.play(6); + music.play(Music_PRESENTINGVVVVVV); music.playef(18); game.screenshake = 10; game.flashlight = 5; @@ -2886,7 +2886,7 @@ void mapinput(void) else { game.quittomenu(); - music.play(6); //should be after game.quittomenu() + music.play(Music_PRESENTINGVVVVVV); // should be after game.quittomenu() game.fadetomenu = false; } } diff --git a/desktop_version/src/Logic.cpp b/desktop_version/src/Logic.cpp index 6ccb1991..17e8c855 100644 --- a/desktop_version/src/Logic.cpp +++ b/desktop_version/src/Logic.cpp @@ -27,7 +27,7 @@ void titlelogic(void) { if (game.menudest == Menu::mainmenu) { - music.play(6); + music.play(Music_PRESENTINGVVVVVV); } else if (game.menudest == Menu::gameover2) { @@ -110,7 +110,7 @@ void gamecompletelogic2(void) //Fix the save thingy game.deletequick(); int tmp=music.currentsong; - music.currentsong=4; + music.currentsong = Music_PASSIONFOREXPLORING; obj.flags[67] = true; game.savetele(); music.currentsong=tmp; @@ -562,7 +562,7 @@ void gamelogic(void) game.swntimer -= 1; if (game.swntimer <= 0) { - music.niceplay(8); + music.niceplay(Music_PREDESTINEDFATE); game.swngame = 5; } else @@ -690,7 +690,7 @@ void gamelogic(void) { game.swngame = 3; obj.createentity(-8, 84 - 32, 11, 8); // (horizontal gravity line) - music.niceplay(2); + music.niceplay(Music_POSITIVEFORCE); game.swndeaths = game.deathcounts; } else if (game.swngame == 5) //remove line @@ -709,7 +709,7 @@ void gamelogic(void) else if (game.swngame == 6) //Init the super gravitron { game.swngame = 7; - music.niceplay(3); + music.niceplay(Music_POTENTIALFORANYTHING); } else if (game.swngame == 7) //introduce game b { @@ -761,22 +761,22 @@ void gamelogic(void) switch(game.timetriallevel) { case 0: - music.play(1); + music.play(Music_PUSHINGONWARDS); break; case 1: - music.play(3); + music.play(Music_POTENTIALFORANYTHING); break; case 2: - music.play(2); + music.play(Music_POSITIVEFORCE); break; case 3: - music.play(1); + music.play(Music_PUSHINGONWARDS); break; case 4: - music.play(12); + music.play(Music_PRESSURECOOKER); break; case 5: - music.play(15); + music.play(Music_PREDESTINEDFATEREMIX); break; } music.playef(22); diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 33b24eee..8d5881d4 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -953,9 +953,9 @@ void mapclass::gotoroom(int rx, int ry) } //Final level for time trial - if (game.intimetrial) + if (game.intimetrial && game.roomx == 46 && game.roomy == 54) { - if (game.roomx == 46 && game.roomy == 54) music.niceplay(15); //Final level remix + music.niceplay(Music_PREDESTINEDFATEREMIX); } } #if !defined(NO_CUSTOM_LEVELS) diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 4ce46b34..98da3840 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -966,9 +966,12 @@ void musicclass::play(int t) return; } - if (currentsong == 0 || currentsong == 7 || (!map.custommode && (currentsong == 0+num_mmmmmm_tracks || currentsong == 7+num_mmmmmm_tracks))) + if (currentsong == Music_PATHCOMPLETE || + currentsong == Music_PLENARY || + (!map.custommode && (currentsong == Music_PATHCOMPLETE + num_mmmmmm_tracks + || currentsong == Music_PLENARY + num_mmmmmm_tracks))) { - // Level Complete theme, no fade in or repeat + // No fade in or repeat if (musicTracks[t].Play(false)) { m_doFadeInVol = false; diff --git a/desktop_version/src/Music.h b/desktop_version/src/Music.h index 8c6b3ee0..9be0fb9b 100644 --- a/desktop_version/src/Music.h +++ b/desktop_version/src/Music.h @@ -11,6 +11,26 @@ /* It is advised that USER_VOLUME_MAX be divisible by this. */ #define USER_VOLUME_STEP 32 +enum +{ + Music_PATHCOMPLETE = 0, + Music_PUSHINGONWARDS = 1, + Music_POSITIVEFORCE = 2, + Music_POTENTIALFORANYTHING = 3, + Music_PASSIONFOREXPLORING = 4, + Music_PAUSE = 5, + Music_PRESENTINGVVVVVV = 6, + Music_PLENARY = 7, + Music_PREDESTINEDFATE = 8, + Music_POSITIVEFORCEREVERSED = 9, + Music_POPULARPOTPOURRI = 10, + Music_PIPEDREAM = 11, + Music_PRESSURECOOKER = 12, + Music_PACEDENERGY = 13, + Music_PIERCINGTHESKY = 14, + Music_PREDESTINEDFATEREMIX = 15 +}; + class musicclass { public: diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index d179ff36..e0d593c1 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -409,7 +409,7 @@ void scriptclass::run(void) } if (words[0] == "trinketscriptmusic") { - music.play(4); + music.play(Music_PASSIONFOREXPLORING); } if (words[0] == "gotoposition") { @@ -2527,7 +2527,7 @@ static void gotoerrorloadinglevel(void) game.quittomenu(); game.createmenu(Menu::errorloadinglevel); music.currentsong = -1; /* otherwise music.play won't work */ - music.play(6); /* title screen music */ + music.play(Music_PRESENTINGVVVVVV); } #define DECLARE_MODE_FUNC(funcname, modename) \ @@ -2721,7 +2721,7 @@ void scriptclass::startgamemode(const enum StartMode mode) game.insecretlab = true; map.showteleporters = true; - music.play(11); + music.play(Music_PIPEDREAM); graphics.fademode = FADE_START_FADEIN; break; @@ -3044,7 +3044,7 @@ void scriptclass::teleport(void) { /* Special case: Ship music needs to be set here; * ship teleporter on music map is -1 for jukebox. */ - music.niceplay(4); + music.niceplay(Music_PASSIONFOREXPLORING); } game.savetele_textbox(); }