Skip to content

Commit

Permalink
Refactor|PathTree|File1: PathTree::Node and File1 names now return de…
Browse files Browse the repository at this point in the history
…::String

Todo: This commit introduces some additional overhead due StringPool
storing the strings internally as ddstring_t. StringPool should now
be refactored to use de::String natively.
  • Loading branch information
danij-deng committed Nov 8, 2012
1 parent efec42b commit 0ca0538
Show file tree
Hide file tree
Showing 32 changed files with 180 additions and 290 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/api/dd_wad.h
Expand Up @@ -41,7 +41,7 @@ extern "C" {
size_t W_LumpLength(lumpnum_t lumpNum);

/// @return Name of the lump associated with @a lumpNum.
char const* W_LumpName(lumpnum_t lumpNum);
AutoStr* W_LumpName(lumpnum_t lumpNum);

/// @return "Last modified" timestamp of the zip entry.
uint W_LumpLastModified(lumpnum_t lumpNum);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/file.h
Expand Up @@ -80,7 +80,7 @@ class File1
virtual ~File1();

/// @return Name of this file.
virtual ddstring_t const* name() const;
virtual String /*const&*/ name() const;

/**
* Compose the absolute VFS path to this file.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/fs_main.h
Expand Up @@ -398,7 +398,7 @@ AutoStr* F_ComposeLumpFilePath(lumpnum_t absoluteLumpNum);

boolean F_LumpIsCustom(lumpnum_t absoluteLumpNum);

ddstring_t const* F_LumpName(lumpnum_t absoluteLumpNum);
AutoStr* F_LumpName(lumpnum_t absoluteLumpNum);

size_t F_LumpLength(lumpnum_t absoluteLumpNum);

Expand Down
9 changes: 0 additions & 9 deletions doomsday/engine/portable/include/p_mapdata.h
Expand Up @@ -233,15 +233,6 @@ extern GameMap* theMap;
*/
void P_SetCurrentMap(GameMap* map);

/**
* Generate a 'unique' identifier for the map. This identifier
* contains information about the map tag (E3M3), the WAD that
* contains the map (DOOM.IWAD), and the game mode (doom-ultimate).
*
* The entire ID string will be in lowercase letters.
*/
const char* P_GenerateUniqueMapId(const char* mapId);

/**
* Is there a known map referenced by @a uri and if so, is it available for loading?
*
Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/portable/include/p_object.h
Expand Up @@ -36,6 +36,10 @@
# error "Attempted to include internal Doomsday p_object.h from a game"
#endif

#ifdef __cplusplus
extern "C" {
#endif

// This macro can be used to calculate a mobj-specific 'random' number.
#define MOBJ_TO_ID(mo) ( (long)(mo)->thinker.id * 48 + ((unsigned long)(mo)/1000) )

Expand Down Expand Up @@ -82,4 +86,8 @@ angle_t Mobj_AngleSmoothed(mobj_t* mobj);

coord_t Mobj_ApproxPointDistance(mobj_t* start, coord_t const* point);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /// LIBDENG_MAP_MOBJ
6 changes: 3 additions & 3 deletions doomsday/engine/portable/include/pathtree.h
Expand Up @@ -147,7 +147,7 @@ namespace de
}

/// @return Name for this node's path fragment.
ddstring_t const* name() const;
String /*const&*/ name() const;

/// @return Hash for this node's path fragment.
ushort hash() const;
Expand All @@ -156,7 +156,7 @@ namespace de
* @param candidatePath Mapped search pattern (path).
* @param flags @ref pathComparisonFlags
*
* @return Non-zero iff the candidate path matched this.
* @return Zero iff the candidate path matched this.
*
* @todo An alternative version of this whose candidate path is specified
* using another tree node (possibly from another PathTree), would
Expand Down Expand Up @@ -306,7 +306,7 @@ namespace de
*/

/// @return The path fragment associated with @a fragmentId.
ddstring_t const* fragmentName(FragmentId fragmentId) const;
String /*const&*/ fragmentName(FragmentId fragmentId) const;

/// @return Hash associated with @a fragmentId.
ushort fragmentHash(FragmentId fragmentId) const;
Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/portable/include/r_fakeradio.h
Expand Up @@ -43,6 +43,10 @@
#ifndef LIBDENG_REFRESH_FAKERADIO_H
#define LIBDENG_REFRESH_FAKERADIO_H

#ifdef __cplusplus
extern "C" {
#endif

/**
* To be called after map load to perform necessary initialization within this module.
*/
Expand All @@ -51,4 +55,8 @@ void R_InitFakeRadioForMap(void);
/// @return @c true if @a lineDef qualifies as a (edge) shadow caster.
boolean R_IsShadowingLinedef(LineDef* lineDef);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_REFRESH_FAKERADIO_H */
8 changes: 8 additions & 0 deletions doomsday/engine/portable/include/r_sky.h
Expand Up @@ -31,6 +31,10 @@

#include "models.h"

#ifdef __cplusplus
extern "C" {
#endif

#define MAX_SKY_LAYERS ( 2 )
#define MAX_SKY_MODELS ( 32 )

Expand Down Expand Up @@ -133,4 +137,8 @@ void R_SkyLayerSetOffset(int layerId, float offset);
*/
void R_SkyParams(int layer, int param, void* data);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_REFRESH_SKY_H */
8 changes: 8 additions & 0 deletions doomsday/engine/portable/include/render/rend_decor.h
Expand Up @@ -29,6 +29,10 @@
#ifndef LIBDENG_RENDER_DECOR_H
#define LIBDENG_RENDER_DECOR_H

#ifdef __cplusplus
extern "C" {
#endif

extern byte useLightDecorations;
extern float decorMaxDist; // No decorations are visible beyond this.
extern float decorLightBrightFactor;
Expand All @@ -42,4 +46,8 @@ void Rend_InitDecorationsForFrame(void);
void Rend_AddLuminousDecorations(void);
void Rend_ProjectDecorations(void);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_RENDER_DECOR_H */
37 changes: 21 additions & 16 deletions doomsday/engine/portable/src/dam_main.cpp
Expand Up @@ -228,6 +228,16 @@ static boolean convertMap(GameMap** map, archivedmap_t* dam)
return converted;
}

static de::String DAM_ComposeUniqueId(de::File1& markerLump)
{
return de::String("%1|%2|%3|%4")
.arg(markerLump.name().fileNameWithoutExtension())
.arg(markerLump.container().name().fileNameWithoutExtension())
.arg(markerLump.container().hasCustom()? "pwad" : "iwad")
.arg(Str_Text(&reinterpret_cast<de::Game*>(App_CurrentGame())->identityKey()))
.toLower();
}

/**
* Attempt to load the map associated with the specified identifier.
*/
Expand All @@ -247,21 +257,21 @@ boolean DAM_AttemptMapLoad(const Uri* uri)
if(!dam)
{
// We've not yet attempted to load this map.
const char* mapId = Str_Text(Uri_Path(uri));
lumpnum_t markerLump;
char const* markerLumpName = Str_Text(Uri_Path(uri));
lumpnum_t markerLumpNum;
AutoStr* cachedMapDir;
Str cachedMapPath;

markerLump = F_LumpNumForName(mapId);
if(0 > markerLump) return false;
markerLumpNum = F_LumpNumForName(markerLumpName);
if(0 > markerLumpNum) return false;

// Compose the cache directory path and ensure it exists.
cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_ComposeLumpFilePath(markerLump)));
cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_ComposeLumpFilePath(markerLumpNum)));
F_MakePath(Str_Text(cachedMapDir));

// Compose the full path to the cached map data file.
Str_InitStd(&cachedMapPath);
F_FileName(&cachedMapPath, Str_Text(F_LumpName(markerLump)));
F_FileName(&cachedMapPath, Str_Text(F_LumpName(markerLumpNum)));
Str_Append(&cachedMapPath, ".dcm");
Str_Prepend(&cachedMapPath, Str_Text(cachedMapDir));

Expand Down Expand Up @@ -325,17 +335,12 @@ boolean DAM_AttemptMapLoad(const Uri* uri)
map->uri = Uri_Dup(dam->uri);

// Generate the unique map id.
char const* markerLumpName = Str_Text(Uri_Path(map->uri));
lumpnum_t markerLumpNum = App_FileSystem()->lumpNumForName(markerLumpName);
de::File1 const& markerLump = App_FileSystem()->nameIndexForLump(markerLumpNum).lump(markerLumpNum);

AutoStr* fileName = AutoStr_NewStd();
F_FileName(fileName, Str_Text(markerLump.container().name()));
lumpnum_t markerLumpNum = App_FileSystem()->lumpNumForName(Str_Text(Uri_Path(map->uri)));
de::File1& markerLump = App_FileSystem()->nameIndexForLump(markerLumpNum).lump(markerLumpNum);

qsnprintf(map->uniqueId, 255, "%s|%s|%s|%s", markerLumpName, Str_Text(fileName),
(!markerLump.container().hasCustom()? "iwad" : "pwad"),
Str_Text(&reinterpret_cast<de::Game*>(App_CurrentGame())->identityKey()));
strlwr(map->uniqueId);
de::String uniqueId = DAM_ComposeUniqueId(markerLump);
QByteArray uniqueIdUtf8 = uniqueId.toUtf8();
qstrncpy(map->uniqueId, uniqueIdUtf8.constData(), sizeof(map->uniqueId));

// See what mapinfo says about this map.
mapInfo = Def_GetMapInfo(map->uri);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dd_main.cpp
Expand Up @@ -636,7 +636,7 @@ static void initPathLumpMappings()
de::File1& lump = **i;
FileInfo const& lumpInfo = lump.info();

if(strnicmp(Str_Text(lump.name()), "DD_DIREC", 8)) continue;
if(!lump.name().beginsWith("DD_DIREC", Qt::CaseInsensitive)) continue;

// Make a copy of it so we can ensure it ends in a null.
if(bufSize < lumpInfo.size + 1)
Expand Down
8 changes: 5 additions & 3 deletions doomsday/engine/portable/src/dd_wad.cpp
Expand Up @@ -53,18 +53,20 @@ size_t W_LumpLength(lumpnum_t absoluteLumpNum)
return 0;
}

char const* W_LumpName(lumpnum_t absoluteLumpNum)
AutoStr* W_LumpName(lumpnum_t absoluteLumpNum)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
return Str_Text(App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).name());
String /*const&*/ name = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).name();
QByteArray nameUtf8 = name.toUtf8();
return AutoStr_FromTextStd(nameUtf8.constData());
}
catch(FS1::NotFoundError const&)
{
W_Error("W_LumpName: Invalid lumpnum %i.", absoluteLumpNum);
}
return "";
return AutoStr_NewStd();
}

uint W_LumpLastModified(lumpnum_t absoluteLumpNum)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/def_main.cpp
Expand Up @@ -754,7 +754,7 @@ void Def_ReadLumpDefs(void)
DENG2_FOR_EACH_CONST(de::LumpIndex::Lumps, i, App_FileSystem()->nameIndex().lumps())
{
de::File1 const& lump = **i;
if(strnicmp(Str_Text(lump.name()), "DD_DEFNS", 8)) continue;
if(!lump.name().beginsWith("DD_DEFNS", Qt::CaseInsensitive)) continue;

numProcessedLumps += 1;

Expand Down
5 changes: 3 additions & 2 deletions doomsday/engine/portable/src/edit_map.cpp
Expand Up @@ -1665,12 +1665,13 @@ boolean MPE_End(void)
if(gamemap->uri && !Str_IsEmpty(Uri_Path(gamemap->uri)))
{
// Yes, write the cached map data file.
lumpnum_t markerLumpNum = F_LumpNumForName(Str_Text(Uri_Path(gamemap->uri)));
char const* markerLumpName = Str_Text(Uri_Path(gamemap->uri));
lumpnum_t markerLumpNum = F_LumpNumForName(markerLumpName);
AutoStr* cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_ComposeLumpFilePath(markerLumpNum)));
Str cachedMapPath;

Str_InitStd(&cachedMapPath);
F_FileName(&cachedMapPath, Str_Text(F_LumpName(markerLumpNum)));
F_FileName(&cachedMapPath, markerLumpName);
Str_Append(&cachedMapPath, ".dcm");
Str_Prepend(&cachedMapPath, Str_Text(cachedMapDir));
F_ExpandBasePath(&cachedMapPath, &cachedMapPath);
Expand Down
6 changes: 2 additions & 4 deletions doomsday/engine/portable/src/file.cpp
Expand Up @@ -105,13 +105,11 @@ File1& File1::setCustom(bool yes)
return *this;
}

ddstring_t const* File1::name() const
String /*const&*/ File1::name() const
{
/// @todo Contained files will be able to provide the name without needing to
/// extract it from the virtual path.
AutoStr* name_ = AutoStr_NewStd();
F_FileNameAndExtension(name_, Str_Text(&path_));
return name_;
return String(Str_Text(&path_)).fileName();
}

size_t File1::read(uint8_t* /*buffer*/, bool /*tryCache*/)
Expand Down

0 comments on commit 0ca0538

Please sign in to comment.