Compare commits

...

3 Commits

Author SHA1 Message Date
Misa c52a274a7a Reset invis and lifeseq when loading in, in mapclass::resetplayer()
When I did #569, I forgot that taking out the code path that set the
player's invis to false meant that the player would still be invisible
upon loading back in to the game if they exited the game while
invisible. Taking out that code path also meant that if game.lifeseq was
nonzero, it wouldn't be reset properly, either. So this fixes those
things.
2020-12-28 16:43:13 -05:00
Misa 385f9d244e Fix player being invisible upon loading into game again
When I did #567, I didn't test it. And I should have tested it, because
it made the player invisible. This is because map.resetplayer() also
sets the invis attribute of the player to true as well, and I only undid
it setting game.lifeseq to 10.

So instead, I'll just add a flag to map.resetplayer() that by default
doesn't set game.lifeseq or the player's invis attribute. And I tested
it this time, and it works fine. I tested both respawning after death
and exiting to the menu and loading in the game again.
2020-12-28 16:22:13 -05:00
Misa eb7b540346 Fix no-draw frames when exiting a level with custom assets
When exiting a level, music.init() gets called again, and every time it
gets called after the first time it gets called, it will free all music
tracks.

To do so, it calls Mix_FreeMusic(). Unfortunately, if there is music
fading, Mix_FreeMusic() will call SDL_Delay(), which will result in
annoying no-draw frames. Meaning, the screen freezes and doesn't draw
anything, and has to wait a bit before continuing.

Here's the relevant piece of code from SDL2_mixer's music.c:

    if (music == music_playing) {
        /* Wait for any fade out to finish */
        while (music->fading == MIX_FADING_OUT) {
            Mix_UnlockAudio();
            SDL_Delay(100);
            Mix_LockAudio();
        }
        if (music == music_playing) {
            music_internal_halt();
        }
    }

This is especially annoying if you're a TASer, because no-draw frames in
a libTAS movie aren't guaranteed to last for a consistent number of
frames when you change your inputs around.

After this patch, as long as your computer can unmount and re-mount
assets fast enough (it doesn't seem like mine can, unfortunately), then
you won't get any freezes when exiting a level that has custom assets.
(This freeze didn't happen when loading a level because the title screen
music fadeout upon pressing ACTION had enough time to fully complete
before the level got loaded.)
2020-12-28 16:01:05 -05:00
5 changed files with 25 additions and 29 deletions

View File

@ -470,7 +470,7 @@ void gamelogic()
game.gravitycontrol = game.savegc; game.gravitycontrol = game.savegc;
graphics.textboxremove(); graphics.textboxremove();
map.resetplayer(); map.resetplayer(true);
} }
} }
} }

View File

@ -802,6 +802,11 @@ void mapclass::showship()
} }
void mapclass::resetplayer() void mapclass::resetplayer()
{
resetplayer(false);
}
void mapclass::resetplayer(const bool player_died)
{ {
bool was_in_tower = towermode; bool was_in_tower = towermode;
if (game.roomx != game.saverx || game.roomy != game.savery) if (game.roomx != game.saverx || game.roomy != game.savery)
@ -821,8 +826,15 @@ void mapclass::resetplayer()
obj.entities[i].yp = game.savey; obj.entities[i].yp = game.savey;
obj.entities[i].dir = game.savedir; obj.entities[i].dir = game.savedir;
obj.entities[i].colour = 0; obj.entities[i].colour = 0;
game.lifeseq = 10; if (player_died)
obj.entities[i].invis = true; {
game.lifeseq = 10;
obj.entities[i].invis = true;
}
else
{
obj.entities[i].invis = false;
}
if (!game.glitchrunnermode) if (!game.glitchrunnermode)
{ {
obj.entities[i].size = 0; obj.entities[i].size = 0;

View File

@ -69,6 +69,7 @@ public:
void showship(); void showship();
void resetplayer(const bool player_died);
void resetplayer(); void resetplayer();
void warpto(int rx, int ry , int t, int tx, int ty); void warpto(int rx, int ry , int t, int tx, int ty);

View File

@ -33,11 +33,18 @@ musicclass::musicclass()
void musicclass::init() void musicclass::init()
{ {
for (size_t i = 0; i < soundTracks.size(); ++i) { for (size_t i = 0; i < soundTracks.size(); ++i)
{
Mix_FreeChunk(soundTracks[i].sound); Mix_FreeChunk(soundTracks[i].sound);
} }
soundTracks.clear(); soundTracks.clear();
for (size_t i = 0; i < musicTracks.size(); ++i) {
// Before we free all the music: stop playing music, else SDL2_mixer
// will call SDL_Delay() if we are fading, resulting in no-draw frames
Mix_HaltMusic();
for (size_t i = 0; i < musicTracks.size(); ++i)
{
Mix_FreeMusic(musicTracks[i].m_music); Mix_FreeMusic(musicTracks[i].m_music);
} }
musicTracks.clear(); musicTracks.clear();

View File

@ -2675,7 +2675,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -2701,7 +2700,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
graphics.fademode = 4; graphics.fademode = 4;
@ -2742,7 +2740,6 @@ void scriptclass::startgamemode( int t )
map.cameramode = 0; map.cameramode = 0;
map.colsuperstate = 0; map.colsuperstate = 0;
} }
game.lifeseq = 0;
graphics.fademode = 4; graphics.fademode = 4;
break; break;
case 3: case 3:
@ -2770,7 +2767,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
graphics.fademode = 4; graphics.fademode = 4;
@ -2800,7 +2796,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
graphics.fademode = 4; graphics.fademode = 4;
@ -2830,7 +2825,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
graphics.fademode = 4; graphics.fademode = 4;
@ -2860,7 +2854,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
graphics.fademode = 4; graphics.fademode = 4;
@ -2890,7 +2883,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
graphics.fademode = 4; graphics.fademode = 4;
@ -2926,7 +2918,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
graphics.fademode = 4; graphics.fademode = 4;
@ -2952,7 +2943,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -2982,7 +2972,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3019,7 +3008,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
music.play(11); music.play(11);
@ -3056,7 +3044,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3093,7 +3080,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3130,7 +3116,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3167,7 +3152,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3201,7 +3185,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3235,7 +3218,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3269,7 +3251,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3303,7 +3284,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3328,7 +3308,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
graphics.fademode = 4; graphics.fademode = 4;
@ -3365,7 +3344,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
if(ed.levmusic>0){ if(ed.levmusic>0){
@ -3404,7 +3382,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
@ -3451,7 +3428,6 @@ void scriptclass::startgamemode( int t )
{ {
map.resetplayer(); map.resetplayer();
} }
game.lifeseq = 0;
map.gotoroom(game.saverx, game.savery); map.gotoroom(game.saverx, game.savery);
map.initmapdata(); map.initmapdata();
ed.generatecustomminimap(); ed.generatecustomminimap();