Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup|libdoomsday: Moved MapManifests into its own source file
- Loading branch information
Showing
8 changed files
with
193 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
doomsday/apps/libdoomsday/include/doomsday/resource/mapmanifests.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** @file mapmanifests.h | ||
* | ||
* @authors Copyright © 2013-2015 Daniel Swanson <danij@dengine.net> | ||
* @authors Copyright © 2013-2016 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBDOOMSDAY_RESOURCE_MAPMANIFESTS_H | ||
#define LIBDOOMSDAY_RESOURCE_MAPMANIFESTS_H | ||
|
||
#include "mapmanifest.h" | ||
#include <de/PathTree> | ||
|
||
namespace res { | ||
|
||
class LIBDOOMSDAY_PUBLIC MapManifests | ||
{ | ||
public: | ||
typedef de::PathTreeT<MapManifest> Tree; | ||
|
||
public: | ||
MapManifests(); | ||
|
||
/** | ||
* Locate the map resource manifest associated with the given, unique @a mapUri. | ||
* | ||
* Note that the existence of a resource manifest does not automatically mean the | ||
* associated resource data is actually loadable. | ||
*/ | ||
res::MapManifest &findMapManifest(de::Uri const &mapUri) const; | ||
|
||
/** | ||
* Lookup the map resource manifest associated with the given, unique @a mapUri. | ||
* Note that the existence of a resource manifest does not automatically mean the | ||
* associated resource data is actually loadable. | ||
* | ||
* @return MapManifest associated with @a mapUri if found; otherwise @c nullptr. | ||
*/ | ||
res::MapManifest *tryFindMapManifest(de::Uri const &mapUri) const; | ||
|
||
/** | ||
* Returns the total number of map resource manifests in the system. | ||
*/ | ||
de::dint mapManifestCount() const; | ||
|
||
/// @todo make private. | ||
void initMapManifests(); | ||
|
||
Tree const &allMapManifests() const; | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace res | ||
|
||
#endif // LIBDOOMSDAY_RESOURCE_MAPMANIFESTS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
doomsday/apps/libdoomsday/src/resource/mapmanifests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** @file mapmanifests.cpp | ||
* | ||
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#include "doomsday/resource/mapmanifests.h" | ||
#include "doomsday/filesys/fs_main.h" | ||
#include "doomsday/resource/resources.h" // MissingResourceManifestError | ||
|
||
using namespace de; | ||
|
||
namespace res { | ||
|
||
DENG2_PIMPL_NOREF(MapManifests) | ||
{ | ||
Tree manifests; | ||
|
||
~Impl() | ||
{ | ||
clear(); | ||
} | ||
|
||
void clear() | ||
{ | ||
manifests.clear(); | ||
} | ||
}; | ||
|
||
MapManifests::MapManifests() : d(new Impl) | ||
{} | ||
|
||
res::MapManifest &MapManifests::findMapManifest(de::Uri const &mapUri) const | ||
{ | ||
// Only one resource scheme is known for maps. | ||
if (!mapUri.scheme().compareWithoutCase("Maps")) | ||
{ | ||
if (res::MapManifest *found = d->manifests.tryFind( | ||
mapUri.path(), PathTree::MatchFull | PathTree::NoBranch)) | ||
return *found; | ||
} | ||
/// @throw MissingResourceManifestError An unknown map URI was specified. | ||
throw Resources::MissingResourceManifestError("MapManifests::findMapManifest", "Failed to locate a manifest for \"" + mapUri.asText() + "\""); | ||
} | ||
|
||
res::MapManifest *MapManifests::tryFindMapManifest(de::Uri const &mapUri) const | ||
{ | ||
// Only one resource scheme is known for maps. | ||
if (mapUri.scheme().compareWithoutCase("Maps")) return nullptr; | ||
return d->manifests.tryFind(mapUri.path(), PathTree::MatchFull | PathTree::NoBranch); | ||
} | ||
|
||
dint MapManifests::mapManifestCount() const | ||
{ | ||
return d->manifests.count(); | ||
} | ||
|
||
void MapManifests::initMapManifests() | ||
{ | ||
d->clear(); | ||
|
||
// Locate all the maps using the central lump index: | ||
/// @todo Locate new maps each time a package is loaded rather than rely on | ||
/// the central lump index. | ||
LumpIndex const &lumpIndex = App_FileSystem().nameIndex(); | ||
lumpnum_t lastLump = -1; | ||
while (lastLump < lumpIndex.size()) | ||
{ | ||
std::unique_ptr<Id1MapRecognizer> recognizer(new Id1MapRecognizer(lumpIndex, lastLump)); | ||
lastLump = recognizer->lastLump(); | ||
if (recognizer->format() != Id1MapRecognizer::UnknownFormat) | ||
{ | ||
File1 *sourceFile = recognizer->sourceFile(); | ||
String const mapId = recognizer->id(); | ||
|
||
res::MapManifest &manifest = d->manifests.insert(mapId); | ||
manifest.set("id", mapId); | ||
manifest.setSourceFile(sourceFile) | ||
.setRecognizer(recognizer.release()); | ||
} | ||
} | ||
} | ||
|
||
MapManifests::Tree const &MapManifests::allMapManifests() const | ||
{ | ||
return d->manifests; | ||
} | ||
|
||
} // namespace res |
Oops, something went wrong.