Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libdoomsday|Resources: Added LumpCatalog: package-aware WAD lump indexer
Currently implements a simple WAD lump directory latest-lump-applies logic, operating in any specified package order.
- Loading branch information
Showing
5 changed files
with
200 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "resource/lumpcatalog.h" |
59 changes: 59 additions & 0 deletions
59
doomsday/apps/libdoomsday/include/doomsday/resource/lumpcatalog.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,59 @@ | ||
/** @file lumpcatalog.h Catalog of lumps from multiple bundles. | ||
* | ||
* @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> | ||
*/ | ||
|
||
#ifndef LIBDOOMSDAY_LUMPCATALOG_H | ||
#define LIBDOOMSDAY_LUMPCATALOG_H | ||
|
||
#include "../libdoomsday.h" | ||
#include <de/String> | ||
#include <de/Block> | ||
|
||
namespace res { | ||
|
||
/** | ||
* Catalog of lumps from multiple bundles. | ||
* | ||
* This is a utility for locating and reading lumps from a set of data bundles. | ||
* It does not cache data: caching should either occur in the File objects or | ||
* a LumpBank that is backed by a LumpCatalog. | ||
*/ | ||
class LIBDOOMSDAY_PUBLIC LumpCatalog | ||
{ | ||
public: | ||
LumpCatalog(); | ||
|
||
/** | ||
* Sets the list of packages where data lumps are to be read from. Only data bundle | ||
* packages of Wad and Lump types are used. | ||
* | ||
* @param packageIds List of packages. These are specifiesd in "load order", meaning | ||
* later ones override the contents of earlier ones. | ||
* | ||
* @return @c true, if the list of packages is different than the one set previously. | ||
*/ | ||
bool setPackages(de::StringList const &packageIds); | ||
|
||
de::Block read(de::String const &lumpName) const; | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace res | ||
|
||
#endif // LIBDOOMSDAY_LUMPCATALOG_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
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,105 @@ | ||
/** @file lumpcatalog.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/lumpcatalog.h" | ||
#include "doomsday/resource/lumpdirectory.h" | ||
#include "doomsday/resource/databundle.h" | ||
|
||
#include <de/App> | ||
#include <de/LinkFile> | ||
#include <de/PackageLoader> | ||
#include <utility> | ||
|
||
using namespace de; | ||
|
||
namespace res { | ||
|
||
DENG2_PIMPL(LumpCatalog) | ||
{ | ||
using Found = std::pair<DataBundle const *, LumpDirectory::Pos>; | ||
|
||
StringList packageIds; | ||
QList<DataBundle const *> bundles; /// @todo Should observe for deletion. -jk | ||
|
||
Instance(Public *i) : Base(i) {} | ||
|
||
void updateBundles() | ||
{ | ||
bundles.clear(); | ||
|
||
for(auto const &pkg : packageIds) | ||
{ | ||
// The package must be available as a file. | ||
if(File const *file = App::packageLoader().select(pkg)) | ||
{ | ||
auto const *bundle = file->target().maybeAs<DataBundle>(); | ||
if(bundle && bundle->lumpDirectory()) | ||
{ | ||
bundles << bundle; | ||
} | ||
} | ||
} | ||
} | ||
|
||
Found findLump(String const &name) const | ||
{ | ||
Block const lumpName = name.toLatin1(); | ||
Found found { nullptr, LumpDirectory::InvalidPos }; | ||
|
||
// The last bundle is checked first. | ||
for(int i = bundles.size() - 1; i >= 0; --i) | ||
{ | ||
auto const pos = bundles.at(i)->lumpDirectory()->find(lumpName); | ||
if(pos != LumpDirectory::InvalidPos) | ||
{ | ||
found = Found(bundles.at(i), pos); | ||
break; | ||
} | ||
} | ||
return found; | ||
} | ||
}; | ||
|
||
LumpCatalog::LumpCatalog() | ||
: d(new Instance(this)) | ||
{} | ||
|
||
bool LumpCatalog::setPackages(StringList const &packageIds) | ||
{ | ||
if(packageIds != d->packageIds) | ||
{ | ||
d->packageIds = packageIds; | ||
d->updateBundles(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
Block LumpCatalog::read(String const &lumpName) const | ||
{ | ||
Block data; | ||
Instance::Found found = d->findLump(lumpName); | ||
if(found.first) | ||
{ | ||
auto const &entry = found.first->lumpDirectory()->entry(found.second); | ||
data.copyFrom(*found.first, entry.offset, entry.size); | ||
} | ||
return data; | ||
} | ||
|
||
} // namespace res |
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