Skip to content

Commit

Permalink
Refactor|libcommon: Use de::Uri with P_SetupMap() and P_InitSky()
Browse files Browse the repository at this point in the history
As of this commit, usage of de::Uri's C wrapper API is limited to
communication with Doomsday's public APIs.
  • Loading branch information
danij-deng committed Jul 2, 2014
1 parent 795e323 commit a94cf2c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 39 deletions.
3 changes: 1 addition & 2 deletions doomsday/client/include/audio/s_sfx.h
Expand Up @@ -82,8 +82,7 @@ void Sfx_Reset(void);
void Sfx_AllowRefresh(dd_bool allow);

/**
* Must be done before the map is changed (from P_SetupMap, via
* S_MapChange).
* Must be done before the map is changed.
*/
void Sfx_MapChange(void);

Expand Down
19 changes: 9 additions & 10 deletions doomsday/plugins/common/include/p_mapsetup.h
@@ -1,9 +1,9 @@
/** @file p_mapsetup.h Common map setup routines.
/** @file p_mapsetup.h Common map setup routines.
*
* Management of extended map data objects (e.g., xlines) is done here.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -29,6 +29,12 @@
DENG_EXTERN_C dd_bool mapSetup;

#ifdef __cplusplus

/**
* Change the current map to that referenced by @a mapUri.
*/
void P_SetupMap(de::Uri const &mapUri);

extern "C" {
#endif

Expand All @@ -39,13 +45,6 @@ extern "C" {
*/
void P_FinalizeMapChange(Uri const *uri);

/**
* Load the specified map.
*
* @param uri URI e.g., "E1M1".
*/
void P_SetupMap(Uri const *uri);

/**
* To be called to reset the local world state (e.g., when leaving a networked game).
* Note that @ref P_SetupMap() calls this automatically when the current map changes.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/gamesession.cpp
Expand Up @@ -544,7 +544,7 @@ DENG2_PIMPL(GameSession), public SavedSession::IMapStateReaderFactory
S_PauseMusic(true);
}

P_SetupMap(reinterpret_cast<uri_s *>(&gameMapUri));
P_SetupMap(gameMapUri);

if(revisit)
{
Expand Down Expand Up @@ -948,7 +948,7 @@ void GameSession::leaveMap()

#if __JHEXEN__
// Take a copy of the player objects (they will be cleared in the process
// of calling P_SetupMap() and we need to restore them after).
// of calling @ref P_SetupMap() and we need to restore them after).
Instance::playerbackup_t playerBackup[MAXPLAYERS];
d->backupPlayersInHub(playerBackup);

Expand Down
33 changes: 14 additions & 19 deletions doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -681,10 +681,8 @@ static void initFog(ddmapinfo_t *ddMapInfo)
#endif
}

void P_SetupMap(uri_s const *mapUri)
void P_SetupMap(de::Uri const &mapUri)
{
DENG2_ASSERT(mapUri != 0);

if(IS_DEDICATED)
{
// Whenever the map changes, update the game rule config.
Expand Down Expand Up @@ -722,21 +720,16 @@ void P_SetupMap(uri_s const *mapUri)
// Initialize the logical sound manager.
S_MapChange();

AutoStr *mapUriStr = Uri_Compose(mapUri);
if(!P_MapChange(Str_Text(mapUriStr)))
if(!P_MapChange(mapUri.compose().toUtf8().constData()))
{
AutoStr *path = Uri_ToString(mapUri);
Con_Error("P_SetupMap: Failed changing/loading map \"%s\".\n", Str_Text(path));
Con_Error("P_SetupMap: Failed changing/loading map \"%s\".\n", mapUri.compose().toUtf8().constData());
exit(1); // Unreachable.
}

// Is MapInfo data available for this map?
{
AutoStr *mapUriStr = Uri_Compose(mapUri);
ddmapinfo_t mapInfo;
bool haveMapInfo = Def_Get(DD_DEF_MAP_INFO, Str_Text(mapUriStr), &mapInfo);
initFog(haveMapInfo? &mapInfo : 0);
}
ddmapinfo_t mapInfo;
bool const haveMapInfo = Def_Get(DD_DEF_MAP_INFO, mapUri.compose().toUtf8().constData(), &mapInfo);
initFog(haveMapInfo? &mapInfo : 0);

// Make sure the game is paused for the requested period.
Pause_MapStarted();
Expand All @@ -745,10 +738,11 @@ void P_SetupMap(uri_s const *mapUri)
mapSetup = false;
}

typedef struct {
struct mobjtype_precachedata_t
{
mobjtype_t type;
int gameModeBits;
} mobjtype_precachedata_t;
};

static void precacheResources()
{
Expand Down Expand Up @@ -912,10 +906,11 @@ static void precacheResources()
#endif
}

void P_FinalizeMapChange(uri_s const *uri)
void P_FinalizeMapChange(uri_s const *mapUri_)
{
de::Uri const &mapUri = *reinterpret_cast<de::Uri const *>(mapUri_);
#if !__JHEXEN__
DENG_UNUSED(uri);
DENG2_UNUSED(mapUri);
#endif

initXLines();
Expand All @@ -937,7 +932,7 @@ void P_FinalizeMapChange(uri_s const *uri)
if(!IS_CLIENT)
{
/// @todo Should be translated by the map converter.
lumpnum_t const mapMarkerLumpNum = CentralLumpIndex().findLast(String(Str_Text(Uri_Path(uri))) + ".lmp");
lumpnum_t const mapMarkerLumpNum = CentralLumpIndex().findLast(mapUri.path() + ".lmp");
lumpnum_t acsLumpNum = mapMarkerLumpNum + 11 /*ML_BEHAVIOR*/;
if(acsLumpNum < CentralLumpIndex().size())
{
Expand Down Expand Up @@ -969,7 +964,7 @@ void P_FinalizeMapChange(uri_s const *uri)
#endif

#if __JHEXEN__
P_InitSky(uri);
P_InitSky(mapUri);
#endif

// Preload resources we'll likely need but which aren't present (usually) in the map.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/heretic/include/p_spec.h
Expand Up @@ -62,7 +62,7 @@ void P_SpawnAllSpecialThinkers(void);
void P_InitAmbientSound(void);

/**
* Called by spawnMapThing during (P_setup):P_SetupMap.
* Called by spawnMapThing during @ref P_SetupMap()
*/
void P_AddAmbientSfx(int sequence);

Expand Down
7 changes: 4 additions & 3 deletions doomsday/plugins/hexen/include/p_spec.h
Expand Up @@ -92,11 +92,12 @@ dd_bool EV_ThingDeactivate(int tid);
dd_bool EV_ThingRemove(int tid);
dd_bool EV_ThingDestroy(int tid);

void P_InitSky(Uri const *mapUri);
void P_AnimateSky(void);

#ifdef __cplusplus
} // extern "C"

void P_InitSky(de::Uri const &mapUri);
void P_AnimateSky(void);

#endif

#endif /* LIBHEXEN_P_SPEC_H */
4 changes: 2 additions & 2 deletions doomsday/plugins/hexen/src/p_spec.cpp
Expand Up @@ -75,9 +75,9 @@ void P_InitLava(void)
lavaInflictor.flags2 = MF2_FIREDAMAGE | MF2_NODMGTHRUST;
}

void P_InitSky(Uri const *mapUri)
void P_InitSky(de::Uri const &mapUri)
{
mapinfo_t const *mapInfo = P_MapInfo(reinterpret_cast<de::Uri const *>(mapUri));
mapinfo_t const *mapInfo = P_MapInfo(&mapUri);
if(mapInfo)
{
sky1Material = mapInfo->sky1Material;
Expand Down

0 comments on commit a94cf2c

Please sign in to comment.