Skip to content

Commit

Permalink
Cleanup|libdoomsday: Moved MapManifests into its own source file
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 9, 2016
1 parent ecc117f commit 39f941c
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 97 deletions.
7 changes: 4 additions & 3 deletions doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -66,6 +66,7 @@
#include <doomsday/filesys/virtualmappings.h>
#include <doomsday/resource/databundle.h>
#include <doomsday/resource/manifest.h>
#include <doomsday/resource/mapmanifests.h>
#include <doomsday/help.h>
#include <doomsday/library.h>
#include <doomsday/world/entitydef.h>
Expand Down Expand Up @@ -703,7 +704,7 @@ int DD_ActivateGameWorker(void *context)
resSys.initTextures();
resSys.textureScheme("Lightmaps").clear();
resSys.textureScheme("Flaremaps").clear();
resSys.initMapManifests();
resSys.mapManifests().initMapManifests();

if (parms.initiatedBusyMode)
{
Expand Down Expand Up @@ -1178,7 +1179,7 @@ static void initialize()
App_ResourceSystem().initTextures();
App_ResourceSystem().textureScheme("Lightmaps").clear();
App_ResourceSystem().textureScheme("Flaremaps").clear();
App_ResourceSystem().initMapManifests();
App_ResourceSystem().mapManifests().initMapManifests();

Def_Read();

Expand Down Expand Up @@ -1460,7 +1461,7 @@ void DD_UpdateEngineState()
App_FileSystem().resetAllSchemes();

App_ResourceSystem().initTextures();
App_ResourceSystem().initMapManifests();
App_ResourceSystem().mapManifests().initMapManifests();

if (App_GameLoaded() && gx.UpdateState)
{
Expand Down
6 changes: 4 additions & 2 deletions doomsday/apps/client/src/resource/resourcesystem.cpp
Expand Up @@ -56,6 +56,7 @@
#include <doomsday/filesys/lumpindex.h>
#include <doomsday/resource/patch.h>
#include <doomsday/resource/patchname.h>
#include <doomsday/resource/mapmanifests.h>
#include <doomsday/SavedSession>
#include <doomsday/Session>

Expand Down Expand Up @@ -3956,8 +3957,9 @@ static bool comparePathTreeNodePathsAscending(PathTreeNodeType const *a, PathTre
*/
static dint printMapsIndex2(Path const &like, de::Uri::ComposeAsTextFlags composeUriFlags)
{
Resources::MapManifests::FoundNodes found;
App_ResourceSystem().allMapManifests().findAll(found, pathBeginsWithComparator, const_cast<Path *>(&like));
res::MapManifests::Tree::FoundNodes found;
App_ResourceSystem().mapManifests().allMapManifests()
.findAll(found, pathBeginsWithComparator, const_cast<Path *>(&like));
if(found.isEmpty()) return 0;

//bool const printSchemeName = !(composeUriFlags & de::Uri::OmitScheme);
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/client/src/world/api_map.cpp
Expand Up @@ -29,7 +29,7 @@
#include <cstring>
#include <de/memoryzone.h>
#include <doomsday/filesys/fs_main.h>
#include <doomsday/resource/mapmanifest.h>
#include <doomsday/resource/mapmanifests.h>
#include <doomsday/EntityDatabase>

#include "network/net_main.h"
Expand Down Expand Up @@ -1476,14 +1476,14 @@ void P_GetPtrpv(void *ptr, uint prop, void *params)
DENG_EXTERN_C dd_bool P_MapExists(char const *uriCString)
{
if(!uriCString || !uriCString[0]) return false;
return App_ResourceSystem().tryFindMapManifest(de::Uri(uriCString, RC_NULL)) != nullptr;
return App_ResourceSystem().mapManifests().tryFindMapManifest(de::Uri(uriCString, RC_NULL)) != nullptr;
}

#undef P_MapIsCustom
DENG_EXTERN_C dd_bool P_MapIsCustom(char const *uriCString)
{
if(!uriCString || !uriCString[0]) return false;
if(res::MapManifest const *mapDef = App_ResourceSystem().tryFindMapManifest(de::Uri(uriCString, RC_NULL)))
if(res::MapManifest const *mapDef = App_ResourceSystem().mapManifests().tryFindMapManifest(de::Uri(uriCString, RC_NULL)))
{
return mapDef->sourceFile()->hasCustom();
}
Expand All @@ -1494,7 +1494,7 @@ DENG_EXTERN_C dd_bool P_MapIsCustom(char const *uriCString)
DENG_EXTERN_C AutoStr *P_MapSourceFile(char const *uriCString)
{
if(!uriCString || !uriCString[0]) return nullptr;
if(res::MapManifest const *mapDef = App_ResourceSystem().tryFindMapManifest(de::Uri(uriCString, RC_NULL)))
if(res::MapManifest const *mapDef = App_ResourceSystem().mapManifests().tryFindMapManifest(de::Uri(uriCString, RC_NULL)))
{
return AutoStr_FromTextStd(mapDef->sourceFile()->composePath().toUtf8().constData());
}
Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/client/src/world/clientserverworld.cpp
Expand Up @@ -36,6 +36,7 @@
#include <doomsday/console/exec.h>
#include <doomsday/console/var.h>
#include <doomsday/defs/mapinfo.h>
#include <doomsday/resource/mapmanifests.h>

#include "dd_main.h"
#include "dd_def.h"
Expand Down Expand Up @@ -791,7 +792,7 @@ bool ClientServerWorld::changeMap(de::Uri const &mapUri)

if(!mapUri.path().isEmpty())
{
mapDef = resSys().tryFindMapManifest(mapUri);
mapDef = resSys().mapManifests().tryFindMapManifest(mapUri);
}

// Switch to busy mode (if we haven't already) except when simply unloading.
Expand Down
69 changes: 69 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/resource/mapmanifests.h
@@ -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
35 changes: 4 additions & 31 deletions doomsday/apps/libdoomsday/include/doomsday/resource/resources.h
Expand Up @@ -21,12 +21,13 @@
#define LIBDOOMSDAY_RESOURCES_H

#include "resourceclass.h"
#include "mapmanifest.h"
#include <de/NativePath>
#include <de/PathTree>
#include <de/System>
#include <de/Info>

namespace res { class MapManifests; }

/**
* Base class for the resource management subsystem.
*
Expand All @@ -43,8 +44,6 @@ class LIBDOOMSDAY_PUBLIC Resources : public de::System

static Resources &get();

typedef de::PathTreeT<res::MapManifest> MapManifests;

public:
Resources();

Expand Down Expand Up @@ -74,34 +73,8 @@ class LIBDOOMSDAY_PUBLIC Resources : public de::System
*/
de::NativePath nativeSavePath() const;

//- Resource Manifests ------------------------------------------------------------------

/**
* 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();
void clearMapManifests();
MapManifests const &allMapManifests() const;
res::MapManifests & mapManifests();
res::MapManifests const & mapManifests() const;

private:
DENG2_PRIVATE(d)
Expand Down
101 changes: 101 additions & 0 deletions doomsday/apps/libdoomsday/src/resource/mapmanifests.cpp
@@ -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

0 comments on commit 39f941c

Please sign in to comment.