Skip to content

Commit

Permalink
libdoomsday|DED: Locating MapGraphNode records from defn::Episode
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 7, 2014
1 parent fe4263d commit 763d0ac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doomsday/libdoomsday/include/doomsday/defs/episode.h
Expand Up @@ -51,6 +51,8 @@ class LIBDOOMSDAY_PUBLIC Episode : public de::RecordAccessor
de::Record &hub(int index);
de::Record const &hub(int index) const;

de::Record *tryFindMapGraphNode(de::String const &mapId);

private:
de::Record *_def; ///< Modifiable access.
};
Expand Down
21 changes: 21 additions & 0 deletions doomsday/libdoomsday/src/defs/episode.cpp
Expand Up @@ -94,4 +94,25 @@ Record const &Episode::hub(int index) const
return *geta("hub")[index].as<RecordValue>().record();
}

Record *Episode::tryFindMapGraphNode(String const &mapId)
{
de::Uri const mapUri(mapId, RC_NULL);
if(!mapUri.path().isEmpty())
{
for(int i = 0; i < hubCount(); ++i)
{
Record const &hubRec = hub(i);
foreach(Value *mapIt, hubRec.geta("map").elements())
{
Record &mapGraphNode = mapIt->as<RecordValue>().dereference();
if(mapUri == de::Uri(mapGraphNode.gets("id"), RC_NULL))
{
return &mapGraphNode;
}
}
}
}
return 0;
}

} // namespace defn
6 changes: 6 additions & 0 deletions doomsday/plugins/common/include/gamesession.h
Expand Up @@ -68,6 +68,12 @@ class GameSession : public de::game::Session
*/
de::Record *episodeDef();

/**
* Returns the (current) MapGraphNode definition for the game session in progress. If the
* session has not yet begun then @c NULL is returned.
*/
de::Record *mapGraphNodeDef();

/**
* Returns the (current) MapInfo definition for the game session in progress. If the session
* has not yet begun, or no definition exists for the current map then @c NULL is returned.
Expand Down
15 changes: 13 additions & 2 deletions doomsday/plugins/common/src/gamesession.cpp
Expand Up @@ -26,6 +26,7 @@
#include <de/Time>
#include <de/ZipArchive>
#include <de/game/SavedSession>
#include <doomsday/defs/episode.h>
#include "d_netsv.h"
#include "g_common.h"
#include "hu_menu.h"
Expand Down Expand Up @@ -788,17 +789,27 @@ Record *GameSession::episodeDef()
{
if(hasBegun())
{
/// @todo cache this result.
/// @todo cache this result?
return Defs().episodes.tryFind("id", String::number(::gameEpisode + 1));
}
return 0;
}

Record *GameSession::mapGraphNodeDef()
{
if(Record const *episode = episodeDef())
{
/// @todo cache this result?
return defn::Episode(*episode).tryFindMapGraphNode(::gameMapUri.compose());
}
return 0;
}

Record *GameSession::mapInfo()
{
if(hasBegun())
{
/// @todo cache this result.
/// @todo cache this result?
return Defs().mapInfos.tryFind("id", ::gameMapUri.compose());
}
return 0;
Expand Down

0 comments on commit 763d0ac

Please sign in to comment.