Skip to content

Commit

Permalink
Initial IMap::forEachPointfile() method to enumerate pointfiles
Browse files Browse the repository at this point in the history
New method with a unit test which is currently trivial because the method does
not yet do anything.
  • Loading branch information
Matthew Mott committed May 12, 2021
1 parent 4176466 commit bf131e1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
12 changes: 9 additions & 3 deletions include/imap.h
Expand Up @@ -28,8 +28,8 @@ class ITargetManager;
// see ilayer.h
class ILayerManager;

namespace selection
{
namespace selection
{
class ISelectionSetManager;
class ISelectionGroupManager;
}
Expand Down Expand Up @@ -161,14 +161,20 @@ class IMap :
// Create a MapExporter instance which can be used to export a scene,
// including the necessary preparation, info-file handling, etc.
// This is mainly a service method for external code, like the gameconnection.
virtual map::IMapExporter::Ptr createMapExporter(map::IMapWriter& writer,
virtual map::IMapExporter::Ptr createMapExporter(map::IMapWriter& writer,
const scene::IMapRootNodePtr& root, std::ostream& mapStream) = 0;

// Exports the current selection to the given output stream, using the map's format
virtual void exportSelected(std::ostream& out) = 0;

// Exports the current selection to the given output stream, using the given map format
virtual void exportSelected(std::ostream& out, const map::MapFormatPtr& format) = 0;

/// Functor to receive pointfile names
using PointfileFunctor = std::function<void(const std::string&)>;

/// Enumerate pointfiles associated with the current map
virtual void forEachPointfile(PointfileFunctor func) const = 0;
};
typedef std::shared_ptr<IMap> IMapPtr;

Expand Down
35 changes: 20 additions & 15 deletions radiantcore/map/Map.cpp
Expand Up @@ -58,10 +58,10 @@
#include <fmt/format.h>
#include "scene/ChildPrimitives.h"

namespace map
namespace map
{

namespace
namespace
{
const char* const MAP_UNNAMED_STRING = N_("unnamed.map");
}
Expand Down Expand Up @@ -98,13 +98,13 @@ void Map::loadMapResourceFromArchive(const std::string& archive, const std::stri

void Map::loadMapResourceFromLocation(const MapLocation& location)
{
rMessage() << "Loading map from " << location.path <<
rMessage() << "Loading map from " << location.path <<
(location.isArchive ? " [" + location.archiveRelativePath + "]" : "") << std::endl;

// Map loading started
emitMapEvent(MapLoading);

_resource = location.isArchive ?
_resource = location.isArchive ?
GlobalMapResourceManager().createFromArchiveFile(location.path, location.archiveRelativePath) :
GlobalMapResourceManager().createFromPath(location.path);

Expand Down Expand Up @@ -193,6 +193,11 @@ bool Map::isUnnamed() const {
return _mapName == _(MAP_UNNAMED_STRING);
}

void Map::forEachPointfile(PointfileFunctor func) const
{

}

void Map::onSceneNodeErase(const scene::INodePtr& node)
{
// Detect when worldspawn is removed from the map
Expand Down Expand Up @@ -234,9 +239,9 @@ MapFormatPtr Map::getFormat()
}

// free all map elements, reinitialize the structures that depend on them
void Map::freeMap()
void Map::freeMap()
{
// Fire the map unloading event,
// Fire the map unloading event,
// This will de-select stuff, clear the pointfile, etc.
emitMapEvent(MapUnloading);

Expand Down Expand Up @@ -294,7 +299,7 @@ scene::INodePtr Map::findWorldspawn()
// Traverse the scenegraph and search for the worldspawn
GlobalSceneGraph().root()->foreachNode([&](const scene::INodePtr& node)
{
if (Node_isWorldspawn(node))
if (Node_isWorldspawn(node))
{
worldspawn = node;
return false; // done traversing
Expand Down Expand Up @@ -383,7 +388,7 @@ bool Map::save(const MapFormatPtr& mapFormat)

_saveInProgress = false;

// Redraw the views, sometimes the backbuffer containing
// Redraw the views, sometimes the backbuffer containing
// the previous frame will remain visible
SceneChangeNotify();

Expand Down Expand Up @@ -565,7 +570,7 @@ bool Map::saveAs()
{
if (_saveInProgress) return false; // safeguard

auto fileInfo = MapFileManager::getMapFileSelection(false,
auto fileInfo = MapFileManager::getMapFileSelection(false,
_("Save Map"), filetype::TYPE_MAP, getMapName());

if (fileInfo.fullPath.empty())
Expand All @@ -579,7 +584,7 @@ bool Map::saveAs()

// Create a new resource pointing to the given path...
_resource = GlobalMapResourceManager().createFromPath(fileInfo.fullPath);

// ...and import the existing root node into that resource
_resource->setRootNode(oldResource->getRootNode());

Expand Down Expand Up @@ -608,7 +613,7 @@ void Map::saveCopyAs()
_lastCopyMapName = getMapName();
}

auto fileInfo = MapFileManager::getMapFileSelection(false,
auto fileInfo = MapFileManager::getMapFileSelection(false,
_("Save Copy As..."), filetype::TYPE_MAP, _lastCopyMapName);

if (!fileInfo.fullPath.empty())
Expand Down Expand Up @@ -636,7 +641,7 @@ void Map::loadPrefabAt(const cmd::ArgumentList& args)
{
if (args.size() < 2 || args.size() > 3)
{
rWarning() << "Usage: " << LOAD_PREFAB_AT_CMD <<
rWarning() << "Usage: " << LOAD_PREFAB_AT_CMD <<
" <prefabPath:String> <targetCoords:Vector3> [insertAsGroup:0|1]" << std::endl;
return;
}
Expand Down Expand Up @@ -707,7 +712,7 @@ void Map::registerCommands()
GlobalCommandSystem().addCommand("OpenMap", Map::openMap, { cmd::ARGTYPE_STRING | cmd::ARGTYPE_OPTIONAL });
GlobalCommandSystem().addCommand("OpenMapFromArchive", Map::openMapFromArchive, { cmd::ARGTYPE_STRING, cmd::ARGTYPE_STRING });
GlobalCommandSystem().addCommand("ImportMap", Map::importMap);
GlobalCommandSystem().addCommand(LOAD_PREFAB_AT_CMD, std::bind(&Map::loadPrefabAt, this, std::placeholders::_1),
GlobalCommandSystem().addCommand(LOAD_PREFAB_AT_CMD, std::bind(&Map::loadPrefabAt, this, std::placeholders::_1),
{ cmd::ARGTYPE_STRING, cmd::ARGTYPE_VECTOR3, cmd::ARGTYPE_INT|cmd::ARGTYPE_OPTIONAL });
GlobalCommandSystem().addCommand("SaveSelectedAsPrefab", Map::saveSelectedAsPrefab);
GlobalCommandSystem().addCommand("SaveMap", std::bind(&Map::saveMapCmd, this, std::placeholders::_1));
Expand All @@ -717,7 +722,7 @@ void Map::registerCommands()
GlobalCommandSystem().addCommand("SaveSelected", Map::exportSelection);
GlobalCommandSystem().addCommand("ReloadSkins", map::algorithm::reloadSkins);
GlobalCommandSystem().addCommand("ExportSelectedAsModel", map::algorithm::exportSelectedAsModelCmd,
{ cmd::ARGTYPE_STRING,
{ cmd::ARGTYPE_STRING,
cmd::ARGTYPE_STRING,
cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL,
cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL,
Expand Down Expand Up @@ -938,7 +943,7 @@ const std::string& Map::getName() const
return _name;
}

const StringSet& Map::getDependencies() const
const StringSet& Map::getDependencies() const
{
static StringSet _dependencies;

Expand Down
20 changes: 6 additions & 14 deletions radiantcore/map/Map.h
Expand Up @@ -82,20 +82,12 @@ class Map :
// Gets called when a node is removed from the scenegraph
void onSceneNodeErase(const scene::INodePtr& node) override;

/** greebo: Returns true if the map has not been named yet.
*/
// IMap implementation
bool isUnnamed() const override;

/** greebo: Updates the name of the map (and triggers an update
* of the mainframe window title)
*/
void setMapName(const std::string& newName);

/** greebo: Returns the name of this map
*/
std::string getMapName() const override;

sigc::signal<void>& signal_mapNameChanged() override;
void forEachPointfile(PointfileFunctor func) const override;

/**
* greebo: Saves the current map, doesn't ask for any filenames,
Expand Down Expand Up @@ -126,7 +118,7 @@ class Map :
void saveCopyAs();

/**
* Saves a copy of the current map to the given path, using the
* Saves a copy of the current map to the given path, using the
* given format (which may be an empty reference, in which case the map format
* will be guessed from the filename).
*/
Expand All @@ -145,7 +137,7 @@ class Map :
*/
bool import(const std::string& filename);

/**
/**
* greebo: Exports the current map directly to the given filename.
* This skips any "modified" or "unnamed" checks, it just dumps
* the current scenegraph content to the file.
Expand Down Expand Up @@ -210,7 +202,7 @@ class Map :
static void saveSelectedAsPrefab(const cmd::ArgumentList& args);

private:
/**
/**
* greebo: Asks the user if the current changes should be saved.
*
* @returns: true, if the user gave clearance (map was saved, had no
Expand All @@ -225,7 +217,7 @@ class Map :
void loadPrefabAt(const cmd::ArgumentList& args);

/**
* greebo: Tries to locate the worldspawn in the global scenegraph and
* greebo: Tries to locate the worldspawn in the global scenegraph and
* stores it into the local member variable.
* Returns the node that was found (can be an empty ptr).
*/
Expand Down
11 changes: 11 additions & 0 deletions test/PointTrace.cpp
Expand Up @@ -36,4 +36,15 @@ TEST_F(PointTraceTest, ConstructPointTraceWithData)
EXPECT_EQ(trace.size(), 5);
}

TEST_F(PointTraceTest, IdentifyMapPointfiles)
{
GlobalCommandSystem().executeCommand("OpenMap", std::string("altar.map"));

// Check the number of pointfiles for this map
int pointfiles = 0;
GlobalMapModule().forEachPointfile([&](const std::string&)
{ ++pointfiles; });
EXPECT_EQ(pointfiles, 0);
}

}

0 comments on commit bf131e1

Please sign in to comment.