Skip to content

Commit

Permalink
Reordered G_DoLoadMap so that if a briefing is not present; the curre…
Browse files Browse the repository at this point in the history
…nt music track is changed and instantly paused, just before entering busy mode to load the map. The music is then unpaused when the map starts.

The idea is to reposition the very noticeable system locking which occurs under Windows when a music track is changed (culprit unknown at present). Ideally the cached music file write should be done during busy mode but thats not an option presently due to multi-thread communication with the audio system (and thus the underlying API).

The result is much smoother transitions when loading maps on Windows.

Note however that this means there will be no music playing during the load process (not such a big deal? Shouldn't take long anyway, especially once map caching is implemented).
  • Loading branch information
danij-deng committed Mar 7, 2010
1 parent 1fd0c0a commit c0d8f3f
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 86 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/api/doomsday.def
Expand Up @@ -37,7 +37,6 @@ NAME "DOOMSDAY"
; 204 formerly TGA_Save16_rgb888
; 205 formerly TGA_GetSize
; 206 formerly GL_Update
; 232 formerly R_SetAnimGroup
; 238 formerly DGL_Color2
; 255 formerly P_PointToBlock
; 326 formerly PO_Alloc
Expand Down Expand Up @@ -445,6 +444,7 @@ EXPORTS
S_StartMusic @219 NONAME
S_StartMusicNum @222 NONAME
S_StopMusic @220 NONAME
S_PauseMusic @232 NONAME

; Miscellaneous.
M_ReadFile @133 NONAME
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -487,6 +487,7 @@ extern "C" {
int S_StartMusic(const char* musicID, boolean looped);
int S_StartMusicNum(int id, boolean looped);
void S_StopMusic(void);
void S_PauseMusic(boolean doPause);

// Miscellaneous.
size_t M_ReadFile(const char* name, byte** buffer);
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/s_main.h
Expand Up @@ -72,6 +72,7 @@ void S_StopSound(int sound_id, mobj_t* origin);
int S_IsPlaying(int sound_id, mobj_t* emitter);
int S_StartMusic(const char* musicid, boolean looped);
void S_StopMusic(void);
void S_PauseMusic(boolean paused);
void S_Drawer(void);

#endif
8 changes: 8 additions & 0 deletions doomsday/engine/portable/src/s_main.c
Expand Up @@ -607,6 +607,14 @@ void S_StopMusic(void)
Mus_Stop();
}

/**
* Change paused state of the current music.
*/
void S_PauseMusic(boolean paused)
{
Mus_Pause(paused);
}

/**
* Draws debug information on-screen.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/include/f_infine.h
Expand Up @@ -51,8 +51,8 @@ void FI_Reset(void);
void FI_Start(char* finalescript, infinemode_t mode);
void FI_End(void);
void FI_SetCondition(int index, boolean value);
int FI_Briefing(int episode, int map);
int FI_Debriefing(int episode, int map);
int FI_Briefing(int episode, int map, ddfinale_t* fin);
int FI_Debriefing(int episode, int map, ddfinale_t* fin);
void FI_DemoEnds(void);
int FI_SkipRequest(void);
void FI_Ticker(void);
Expand Down
42 changes: 22 additions & 20 deletions doomsday/plugins/common/src/f_infine.c
Expand Up @@ -679,7 +679,7 @@ void FI_End(void)
{
// Enter the map, this was a briefing.
G_ChangeGameState(GS_MAP);
S_MapMusic();
S_MapMusic(gameEpisode, gameMap);
mapStartTic = (int) GAMETIC;
mapTime = actualMapTime = 0;
}
Expand Down Expand Up @@ -734,13 +734,12 @@ DEFCC(CCmdStopInFine)
}

/**
* Check if there is a finale before the map and play it.
* Returns true if a finale was begun.
* Check if there is a finale before the map.
* Returns true if a finale was found.
*/
int FI_Briefing(int episode, int map)
int FI_Briefing(int episode, int map, ddfinale_t* fin)
{
char mid[20];
ddfinale_t fin;
char mid[20];

// If we're already in the INFINE state, don't start a finale.
if(briefDisabled || G_GetGameState() == GS_INFINE || IS_CLIENT ||
Expand All @@ -750,29 +749,32 @@ int FI_Briefing(int episode, int map)
// Is there such a finale definition?
P_GetMapLumpName(episode, map, mid);

if(!Def_Get(DD_DEF_FINALE_BEFORE, mid, &fin))
return false;

FI_Start(fin.script, FIMODE_BEFORE);
return true;
return Def_Get(DD_DEF_FINALE_BEFORE, mid, &fin);
}

/**
* Check if there is a finale after the map and play it.
* Returns true if a finale was begun.
* Check if there is a finale after the map.
* Returns true if a finale was found.
*/
int FI_Debriefing(int episode, int map)
int FI_Debriefing(int episode, int map, ddfinale_t* fin)
{
char mid[20];
ddfinale_t fin;

// Is there such a finale definition?
P_GetMapLumpName(episode, map, mid);
if(!Def_Get(DD_DEF_FINALE_AFTER, mid, &fin))
// If we're already in the INFINE state, don't start a finale.
if(briefDisabled)
return false;
#if __JHEXEN__
if(cfg.overrideHubMsg && G_GetGameState() == GS_MAP &&
!(leaveMap == -1 && leavePosition == -1) &&
P_GetMapCluster(gameMap) != P_GetMapCluster(leaveMap))
return false;
#endif
if(G_GetGameState() == GS_INFINE || IS_CLIENT || Get(DD_PLAYBACK))
return false;

FI_Start(fin.script, FIMODE_AFTER);
return true;
// Is there such a finale definition?
P_GetMapLumpName(episode, map, mid);
return Def_Get(DD_DEF_FINALE_AFTER, mid, fin);
}

void FI_DemoEnds(void)
Expand Down
56 changes: 31 additions & 25 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -842,8 +842,10 @@ void G_StartTitle(void)

void G_DoLoadMap(void)
{
int i;
char *lname, *ptr;
int i;
char* lname, *ptr;
ddfinale_t fin;
boolean hasBrief;

#if __JHEXEN__ || __JSTRIFE__
static int firstFragReset = 1;
Expand Down Expand Up @@ -884,6 +886,15 @@ void G_DoLoadMap(void)
G_ResetLookOffset(i);
}

// Determine whether there is a briefing to run before the map starts
// (played after the map has been loaded).
hasBrief = FI_Briefing(gameEpisode, gameMap, &fin);
if(!hasBrief)
{
S_MapMusic(gameEpisode, gameMap);
S_PauseMusic(true);
}

P_SetupMap(gameEpisode, gameMap, 0, gameSkill);
Set(DD_DISPLAYPLAYER, CONSOLEPLAYER); // View the guy you are playing.
G_SetGameAction(GA_NONE);
Expand All @@ -892,6 +903,7 @@ void G_DoLoadMap(void)

// Clear cmd building stuff.
G_ResetMousePos();

sendPause = paused = false;

G_ControlReset(-1); // Clear all controls for all local players.
Expand Down Expand Up @@ -927,10 +939,14 @@ void G_DoLoadMap(void)
}

// Start a briefing, if there is one.
if(!FI_Briefing(gameEpisode, gameMap))
{ // No briefing, start the map.
if(hasBrief)
{
FI_Start(fin.script, FIMODE_BEFORE);
}
else // No briefing, start the map.
{
G_ChangeGameState(GS_MAP);
S_MapMusic();
S_PauseMusic(false);
}
}

Expand Down Expand Up @@ -1673,6 +1689,8 @@ void G_StartNewGame(skillmode_t skill)

void G_DoTeleportNewMap(void)
{
ddfinale_t fin;

// Clients trust the server in these things.
if(IS_CLIENT)
{
Expand All @@ -1686,7 +1704,8 @@ void G_DoTeleportNewMap(void)
rebornPosition = leavePosition;

// Is there a briefing before this map?
FI_Briefing(gameEpisode, gameMap);
if(FI_Briefing(gameEpisode, gameMap, &fin))
FI_Start(fin.script, FIMODE_BEFORE);
}
#endif

Expand Down Expand Up @@ -2016,23 +2035,6 @@ void G_PrepareWIData(void)
}
#endif

boolean G_DebriefingEnabled(void)
{
// If we're already in the INFINE state, don't start a finale.
if(briefDisabled)
return false;
#if __JHEXEN__
if(cfg.overrideHubMsg && G_GetGameState() == GS_MAP &&
!(leaveMap == -1 && leavePosition == -1) &&
P_GetMapCluster(gameMap) != P_GetMapCluster(leaveMap))
return false;
#endif
if(G_GetGameState() == GS_INFINE || IS_CLIENT || Get(DD_PLAYBACK))
return false;

return true;
}

void G_WorldDone(void)
{
#if __JDOOM__ || __JDOOM64__
Expand All @@ -2044,12 +2046,16 @@ void G_WorldDone(void)
// @note FI_Reset() changes the game state so we must determine
// whether the debrief is enabled first.
{
boolean doDebrief = G_DebriefingEnabled();
ddfinale_t fin;
boolean doDebrief = FI_Debriefing(gameEpisode, gameMap, &fin);

FI_Reset();

if(doDebrief && FI_Debriefing(gameEpisode, gameMap))
if(doDebrief)
{
FI_Start(fin.script, FIMODE_AFTER);
return;
}

// We have either just returned from a debriefing or there wasn't one.
briefDisabled = false;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/g_update.c
Expand Up @@ -169,7 +169,7 @@ void G_UpdateState(int step)
#endif

#if __JDOOM__ || __JHERETIC__ || __JDOOM64__
S_MapMusic();
S_MapMusic(gameEpisode, gameMap);
#endif
break;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jdoom/include/p_sound.h
Expand Up @@ -40,7 +40,7 @@ typedef enum {
SORG_CEILING
} sectorsoundorigin_t;

void S_MapMusic(void);
void S_MapMusic(int episode, int map);
void S_SectorSound(sector_t* sec, sectorsoundorigin_t origin,
int id);

Expand Down
20 changes: 11 additions & 9 deletions doomsday/plugins/jdoom/src/p_sound.c
Expand Up @@ -52,20 +52,22 @@
// CODE --------------------------------------------------------------------

/**
* Starts playing the music for the current map.
* Start the song for the specified map.
*/
void S_MapMusic(void)
void S_MapMusic(int episode, int map)
{
int songid;
ddmapinfo_t mapInfo;
char mapId[8];

if(G_GetGameState() != GS_MAP)
return;
P_GetMapLumpName(episode, map, mapId);

songid = Get(DD_MAP_MUSIC);
if(S_StartMusicNum(songid, true))
if(Def_Get(DD_DEF_MAP_INFO, mapId, &mapInfo))
{
// Set the game status cvar for the map music.
gsvMapMusic = songid;
if(S_StartMusicNum(mapInfo.music, true))
{
// Set the game status cvar for the map music.
gsvMapMusic = mapInfo.music;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jdoom64/include/p_sound.h
Expand Up @@ -40,7 +40,7 @@ enum {
SORG_CEILING
};

void S_MapMusic(void);
void S_MapMusic(int episode, int map);
void S_SectorSound(sector_t* sec, int origin, int id);

#endif
20 changes: 11 additions & 9 deletions doomsday/plugins/jdoom64/src/p_sound.c
Expand Up @@ -48,20 +48,22 @@
// CODE --------------------------------------------------------------------

/**
* Starts playing the music for the current map.
* Start the song for the specified map.
*/
void S_MapMusic(void)
void S_MapMusic(int episode, int map)
{
int songid;
ddmapinfo_t mapInfo;
char mapId[8];

if(G_GetGameState() != GS_MAP)
return;
P_GetMapLumpName(episode, map, mapId);

songid = Get(DD_MAP_MUSIC);
if(S_StartMusicNum(songid, true))
if(Def_Get(DD_DEF_MAP_INFO, mapId, &mapInfo))
{
// Set the game status cvar for the map music.
gsvMapMusic = songid;
if(S_StartMusicNum(mapInfo.music, true))
{
// Set the game status cvar for the map music.
gsvMapMusic = mapInfo.music;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jheretic/include/p_sound.h
Expand Up @@ -40,7 +40,7 @@ enum {
SORG_CEILING
};

void S_MapMusic(void);
void S_MapMusic(int episode, int map);
void S_SectorSound(sector_t* sec, int origin, int id);

#endif
20 changes: 11 additions & 9 deletions doomsday/plugins/jheretic/src/p_sound.c
Expand Up @@ -51,20 +51,22 @@
// CODE --------------------------------------------------------------------

/**
* Start the song for the current map.
* Start the song for the specified map.
*/
void S_MapMusic(void)
void S_MapMusic(int episode, int map)
{
int songid;
ddmapinfo_t mapInfo;
char mapId[8];

if(G_GetGameState() != GS_MAP)
return;
P_GetMapLumpName(episode, map, mapId);

songid = Get(DD_MAP_MUSIC);
if(S_StartMusicNum(songid, true))
if(Def_Get(DD_DEF_MAP_INFO, mapId, &mapInfo))
{
// Set the game status cvar for the map music.
gsvMapMusic = songid;
if(S_StartMusicNum(mapInfo.music, true))
{
// Set the game status cvar for the map music.
gsvMapMusic = mapInfo.music;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jhexen/include/p_sound.h
Expand Up @@ -37,7 +37,7 @@
#define MAX_CHANNELS (16)

int S_GetSoundID(const char* name);
void S_MapMusic(void);
void S_MapMusic(int episode, int map);

void S_ParseSndInfoLump(void);

Expand Down

0 comments on commit c0d8f3f

Please sign in to comment.