Skip to content

Commit

Permalink
Refactor: Reimplemented the MapArchive with proper SoC
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 5, 2013
1 parent 0ff5e18 commit d42cc11
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 361 deletions.
37 changes: 14 additions & 23 deletions doomsday/client/include/map/dam_main.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* @file dam_main.h
* Doomsday Archived Map (DAM), map management. @ingroup map
/** @file dam_main.h Doomsday Archived Map (DAM), map management.
*
* @author Copyright &copy; 2007-2013 Daniel Swanson <danij@dengine.net>
*
Expand All @@ -22,27 +20,21 @@
#ifndef LIBDENG_ARCHIVED_MAP_MAIN_H
#define LIBDENG_ARCHIVED_MAP_MAIN_H

#ifdef __cplusplus
extern "C" {
#endif
#include "dd_share.h"
#include "uri.hh"

typedef struct archivedmap_s {
Uri* uri;
/*ddstring_t cachedMapPath;
boolean cachedMapFound;
boolean lastLoadAttemptFailed;*/
} archivedmap_t;
class GameMap;

extern byte mapCache;
DENG_EXTERN_C byte mapCache;

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

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

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

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

boolean DAM_AttemptMapLoad(const Uri* uri);

#ifdef __cplusplus
} // extern "C"
#endif
/**
* Attempt to load the map associated with the specified identifier.
*/
GameMap *DAM_LoadMap(de::Uri const &uri);

#endif /* LIBDENG_ARCHIVED_MAP_MAIN_H */
#endif // LIBDENG_ARCHIVED_MAP_MAIN_H
82 changes: 25 additions & 57 deletions doomsday/client/src/edit_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ boolean MPE_End()
printMissingMaterialsInDict();
clearMaterialDict();

GameMap *gamemap = new GameMap;
GameMap *map = new GameMap;

/*
* Perform cleanup on the loaded map data, removing duplicate vertexes,
Expand All @@ -1199,41 +1199,41 @@ boolean MPE_End()
/*
* Acquire ownership of the map elements from the editable map.
*/
gamemap->entityDatabase = editMap.entityDatabase; // Take ownership.
map->entityDatabase = editMap.entityDatabase; // Take ownership.

// Collate sectors:
DENG2_ASSERT(gamemap->_sectors.isEmpty());
DENG2_ASSERT(map->_sectors.isEmpty());
#ifdef DENG2_QT_4_7_OR_NEWER
gamemap->_sectors.reserve(editMap.sectors.count());
map->_sectors.reserve(editMap.sectors.count());
#endif
foreach(Sector *sector, editMap.sectors)
{
gamemap->_sectors.append(sector); // Take ownership.
map->_sectors.append(sector); // Take ownership.
}

// Collate sidedefs:
DENG2_ASSERT(gamemap->_sideDefs.isEmpty());
DENG2_ASSERT(map->_sideDefs.isEmpty());
#ifdef DENG2_QT_4_7_OR_NEWER
gamemap->_sideDefs.reserve(editMap.sideDefs.count());
map->_sideDefs.reserve(editMap.sideDefs.count());
#endif
foreach(SideDef *sideDef, editMap.sideDefs)
{
gamemap->_sideDefs.append(sideDef); // Take ownership.
map->_sideDefs.append(sideDef); // Take ownership.
}

// Collate lines:
DENG2_ASSERT(gamemap->_lines.isEmpty());
DENG2_ASSERT(map->_lines.isEmpty());
#ifdef DENG2_QT_4_7_OR_NEWER
gamemap->_lines.reserve(editMap.lines.count());
map->_lines.reserve(editMap.lines.count());
#endif
foreach(LineDef *line, editMap.lines)
{
gamemap->_lines.append(line); // Take ownership.
map->_lines.append(line); // Take ownership.
}

buildVertexLineOwnerRings();

hardenPolyobjs(*gamemap, editMap);
hardenPolyobjs(*map, editMap);
editMap.clearPolyobjs();

/*
Expand All @@ -1242,74 +1242,42 @@ boolean MPE_End()
vec2d_t min, max;
findBounds(editMap.vertexes, min, max);

gamemap->initLineBlockmap(min, max);
foreach(LineDef *line, gamemap->lines())
map->initLineBlockmap(min, max);
foreach(LineDef *line, map->lines())
{
gamemap->linkLine(*line);
map->linkLine(*line);
}

// Mobj and Polyobj blockmaps are maintained dynamically.
gamemap->initMobjBlockmap(min, max);
gamemap->initPolyobjBlockmap(min, max);
map->initMobjBlockmap(min, max);
map->initPolyobjBlockmap(min, max);

/*
* Build a BSP for this map.
* Build a BSP.
*/
bool builtOK = gamemap->buildBsp();
bool builtOK = map->buildBsp();

// Destroy the rest of editable map, we are finished with it.
editMap.clear();

if(!builtOK)
{
// Darn, clean up...
EntityDatabase_Delete(gamemap->entityDatabase);
delete gamemap;
EntityDatabase_Delete(map->entityDatabase);
delete map;

lastBuiltMapResult = false; // Failed :$
return lastBuiltMapResult;
}

editMapInited = false;

gamemap->finishMapElements();
gamemap->updateBounds();
map->finishMapElements();
map->updateBounds();

S_DetermineBspLeafsAffectingSectorReverb(gamemap);
S_DetermineBspLeafsAffectingSectorReverb(map);

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

// Are we caching this map?
/*de::Uri mapUri = gamemap->uri();
if(!mapUri.isEmpty())
{
// Yes, write the cached map data file.
char const *markerLumpName = Str_Text(Uri_Path(gamemap->uri));
lumpnum_t markerLumpNum = F_LumpNumForName(markerLumpName);
AutoStr *cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_ComposeLumpFilePath(markerLumpNum)));
AutoStr *cachedMapPath = AutoStr_NewStd();
F_FileName(cachedMapPath, markerLumpName);
Str_Append(cachedMapPath, ".dcm");
Str_Prepend(cachedMapPath, Str_Text(cachedMapDir));
F_ExpandBasePath(cachedMapPath, cachedMapPath);
// Ensure the destination directory exists.
F_MakePath(Str_Text(cachedMapDir));
// Archive this map!
DAM_MapWrite(gamemap, Str_Text(cachedMapPath));
}*/

lastBuiltMap = gamemap;
lastBuiltMap = map;
lastBuiltMapResult = true; // Success.

return lastBuiltMapResult;
Expand Down
Loading

0 comments on commit d42cc11

Please sign in to comment.