Skip to content

Commit

Permalink
Refactor|MapArchive: Moved all post load map init to P_LoadMap()
Browse files Browse the repository at this point in the history
The MapArchive is no longer concerned about other tasks the engine
needs to perform in order to prepare a loaded map for use.
  • Loading branch information
danij-deng committed Apr 6, 2013
1 parent 69e34df commit 0185d2a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 70 deletions.
10 changes: 5 additions & 5 deletions doomsday/client/include/map/dam_main.h
Expand Up @@ -28,13 +28,13 @@ class GameMap;
DENG_EXTERN_C byte mapCache;

/// To be called during init to register the cvars and ccmds for this module.
void DAM_Register();
void MapArchive_Register();

/// Initialize this module.
void DAM_Init();
void MapArchive_Initialize();

/// Shutdown this module.
void DAM_Shutdown();
void MapArchive_Shutdown();

#if 0
/**
Expand All @@ -44,12 +44,12 @@ void DAM_Shutdown();
* @param sourcePath Path to the primary resource file for the original map data.
* @return The composed path.
*/
AutoStr* DAM_ComposeCacheDir(char const *sourcePath);
AutoStr* MapArchive_MapCachePath(char const *sourcePath);
#endif

/**
* Attempt to load the map associated with the specified identifier.
*/
GameMap *DAM_LoadMap(de::Uri const &uri);
GameMap *MapArchive_LoadMap(de::Uri const &uri);

#endif // LIBDENG_ARCHIVED_MAP_MAIN_H
2 changes: 1 addition & 1 deletion doomsday/client/include/render/rend_decor.h
Expand Up @@ -36,7 +36,7 @@ void Rend_DecorRegister(void);
* Re-initialize the decoration source tracking (might be called during a map
* load or othersuch situation).
*/
void Rend_DecorInit(void);
void Rend_DecorInitForMap(void);

/**
* Decorations are generated for each frame.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -648,7 +648,7 @@ void DD_Register(void)
Materials::consoleRegister();
Textures::consoleRegister();
Net_Register();
DAM_Register();
MapArchive_Register();
MPE_Register();
FI_Register();
}
Expand Down Expand Up @@ -882,7 +882,7 @@ static int DD_BeginGameChangeWorker(void* parameters)
if(p->initiatedBusyMode)
Con_SetProgress(100);

DAM_Init();
MapArchive_Initialize();

if(p->initiatedBusyMode)
{
Expand Down
74 changes: 18 additions & 56 deletions doomsday/client/src/map/dam_main.cpp
Expand Up @@ -26,17 +26,11 @@
* 02110-1301 USA</small>
*/

#include <cmath>

#include <de/Log>

#include "de_base.h"
#include "de_dam.h"
#include "de_defs.h"
#include "de_edit.h"
#include "de_filesys.h"
#include "de_network.h"
#include "de_render.h"
#include "map/gamemap.h"

#include "map/dam_main.h"
Expand All @@ -50,7 +44,7 @@ byte mapCache = true;
static char const *mapCacheDir = "mapcache/";
*/

void DAM_Register()
void MapArchive_Register()
{
//C_VAR_BYTE("map-cache", &mapCache, 0, 0, 1);
}
Expand Down Expand Up @@ -152,7 +146,7 @@ class MapArchive
friend class MapArchive;

private:
inline lumpnum_t markerLumpNum()
inline lumpnum_t markerLumpNumForPath()
{
return App_FileSystem().lumpNumForName(_uri.path());
}
Expand Down Expand Up @@ -187,7 +181,8 @@ class MapArchive

LOG_VERBOSE("Attempting \"%s\"...") << _uri;

if(markerLumpNum() < 0)
lumpnum_t markerLumpNum = markerLumpNumForPath();
if(markerLumpNum < 0)
return 0;

// Ask each converter in turn whether the map format is
Expand All @@ -205,11 +200,17 @@ class MapArchive
DENG_ASSERT(map != 0);
map->_uri = _uri;

// Generate the unique map id.
de::File1 &markerLump = App_FileSystem().nameIndex().lump(markerLumpNum);
String uniqueId = composeUniqueMapId(markerLump);
QByteArray uniqueIdUtf8 = uniqueId.toUtf8();
qstrncpy(map->_oldUniqueId, uniqueIdUtf8.constData(), sizeof(map->_oldUniqueId));

// Are we caching this map?
/*if(mapCache)
{
AutoStr *cachedMapDir =
DAM_ComposeCacheDir(Str_Text(F_ComposeLumpFilePath(markerLumpNum())));
MapArchive_MapCachePath(Str_Text(F_ComposeLumpFilePath(markerLumpNum())));
AutoStr *cachedMapPath = AutoStr_NewStd();
F_FileName(cachedMapPath, F_LumpName(markerLumpName));
Expand Down Expand Up @@ -273,7 +274,7 @@ class MapArchive
lumpnum_t markerLumpNum = F_LumpNumForName(uri.path().toString().toLatin1().constData());
if(markerLumpNum >= 0)
{
AutoStr *cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_ComposeLumpFilePath(markerLumpNum)));
AutoStr *cachedMapDir = MapArchive_MapCachePath(Str_Text(F_ComposeLumpFilePath(markerLumpNum)));
F_MakePath(Str_Text(cachedMapDir));
// Compose the full path to the cached map data file.
Expand All @@ -293,64 +294,25 @@ class MapArchive

static MapArchive archive;

void DAM_Init()
void MapArchive_Initialize()
{
// Allow re-init.
archive.clear();
}

void DAM_Shutdown()
void MapArchive_Shutdown()
{
archive.clear();
}

GameMap *DAM_LoadMap(de::Uri const &uri)
GameMap *MapArchive_LoadMap(de::Uri const &uri)
{
// Record this map in the archive if we haven't already.
MapArchive::Info &arcInfo = archive.createInfo(uri);

// Load in the map!
GameMap *map = arcInfo.loadMap();
if(!map) return 0;

// Call the game's setup routines.
if(gx.SetupForMapData)
{
gx.SetupForMapData(DMU_VERTEX, map->vertexCount());
gx.SetupForMapData(DMU_LINEDEF, map->lineCount());
gx.SetupForMapData(DMU_SIDEDEF, map->sideDefCount());
gx.SetupForMapData(DMU_SECTOR, map->sectorCount());
}

// Do any initialization/error checking work we need to do.
// Must be called before we go any further.
P_InitUnusedMobjList();

// Must be called before any mobjs are spawned.
map->initNodePiles();

#ifdef __CLIENT__
// Prepare the client-side data.
if(isClient)
{
map->initClMobjs();
}
#endif

Rend_DecorInit();

// Generate the unique map id.
lumpnum_t markerLumpNum = App_FileSystem().lumpNumForName(arcInfo.mapUri().path());
de::File1 &markerLump = App_FileSystem().nameIndex().lump(markerLumpNum);
String uniqueId = composeUniqueMapId(markerLump);
QByteArray uniqueIdUtf8 = uniqueId.toUtf8();
qstrncpy(map->_oldUniqueId, uniqueIdUtf8.constData(), sizeof(map->_oldUniqueId));

return map;
// Record this map if we haven't already and load then it in!
return archive.createInfo(uri).loadMap();
}

#if 0
AutoStr *DAM_ComposeCacheDir(char const *sourcePath)
AutoStr *MapArchive_MapCachePath(char const *sourcePath)
{
if(!sourcePath || !sourcePath[0]) return 0;

Expand Down
28 changes: 27 additions & 1 deletion doomsday/client/src/map/p_data.cpp
Expand Up @@ -108,8 +108,34 @@ DENG_EXTERN_C boolean P_LoadMap(char const *uriCString)

Z_FreeTags(PU_MAP, PU_PURGELEVEL - 1);

if((theMap = DAM_LoadMap(uri)))
if((theMap = MapArchive_LoadMap(uri)))
{
// Call the game's setup routines.
if(gx.SetupForMapData)
{
gx.SetupForMapData(DMU_VERTEX, theMap->vertexCount());
gx.SetupForMapData(DMU_LINEDEF, theMap->lineCount());
gx.SetupForMapData(DMU_SIDEDEF, theMap->sideDefCount());
gx.SetupForMapData(DMU_SECTOR, theMap->sectorCount());
}

// Do any initialization/error checking work we need to do.
// Must be called before we go any further.
P_InitUnusedMobjList();

// Must be called before any mobjs are spawned.
theMap->initNodePiles();

#ifdef __CLIENT__
// Prepare the client-side data.
if(isClient)
{
theMap->initClMobjs();
}

Rend_DecorInitForMap();
#endif

// See what mapinfo says about this map.
de::Uri mapUri = theMap->uri();
ded_mapinfo_t *mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&mapUri));
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/r_main.cpp
Expand Up @@ -595,7 +595,7 @@ void R_Update()
P_UpdateParticleGens(); // Defs might've changed.

// Reset the archived map cache (the available maps may have changed).
DAM_Init();
MapArchive_Initialize();

for(uint i = 0; i < DDMAXPLAYERS; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_decor.cpp
Expand Up @@ -163,7 +163,7 @@ static void projectSource(decorsource_t const &src)
}
}

void Rend_DecorInit()
void Rend_DecorInitForMap()
{
recycleSources();
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/server/include/server_dummies.h
Expand Up @@ -58,7 +58,7 @@ DENG_EXTERN_C void Fonts_ClearDefinitionLinks(void);
DENG_EXTERN_C void Fonts_ClearRuntime(void);

DENG_EXTERN_C void Rend_Init(void);
DENG_EXTERN_C void Rend_DecorInit();
//DENG_EXTERN_C void Rend_DecorInitForMap();
//DENG_EXTERN_C void Rend_CacheForMap();
DENG_EXTERN_C void Rend_CacheForMobjType(int num);
DENG_EXTERN_C void Rend_CalcLightModRange();
Expand Down
6 changes: 4 additions & 2 deletions doomsday/server/src/server_dummies.cpp
Expand Up @@ -428,11 +428,13 @@ struct font_s* R_CreateFontFromDef(ded_compositefont_t* def)
return 0;
}

void Rend_Init(void)
void Rend_Init()
{}

void Rend_DecorInit()
/*
void Rend_DecorInitForMap()
{}
*/

void Rend_CacheForMobjType(int num)
{
Expand Down

0 comments on commit 0185d2a

Please sign in to comment.