diff --git a/include/imap.h b/include/imap.h index eea5b7321a..36c290d6e6 100644 --- a/include/imap.h +++ b/include/imap.h @@ -114,3 +114,4 @@ inline IMap& GlobalMapModule() { ); return _mapModule; } + diff --git a/libs/maplib.h b/libs/maplib.h new file mode 100644 index 0000000000..394c1fb3cf --- /dev/null +++ b/libs/maplib.h @@ -0,0 +1,20 @@ +#pragma once + +#include "imap.h" +#include "ientity.h" + +namespace map +{ + +namespace current +{ + +/// Convenience method to return the worldspawn entity pointer +inline Entity* getWorldspawn() +{ + return Node_getEntity(GlobalMapModule().getWorldspawn()); +} + +} + +} diff --git a/plugins/dm.difficulty/DifficultySettingsManager.cpp b/plugins/dm.difficulty/DifficultySettingsManager.cpp index c3ba88735d..437afd5ec4 100644 --- a/plugins/dm.difficulty/DifficultySettingsManager.cpp +++ b/plugins/dm.difficulty/DifficultySettingsManager.cpp @@ -4,6 +4,7 @@ #include "itextstream.h" #include "entitylib.h" #include "gamelib.h" +#include "maplib.h" #include "string/string.h" #include "registry/registry.h" #include "DifficultyEntity.h" @@ -71,7 +72,7 @@ void DifficultySettingsManager::loadMapSettings() { void DifficultySettingsManager::loadDifficultyNames() { // Locate the worldspawn entity - Entity* worldspawn = Scene_FindEntityByClass("worldspawn"); + Entity* worldspawn = map::current::getWorldspawn(); // Try to locate the difficulty menu entity, where the default names are defined IEntityClassPtr menuEclass = GlobalEntityClassManager().findClass( diff --git a/radiant/map/Map.h b/radiant/map/Map.h index d12f2e69c9..4a13596dc2 100644 --- a/radiant/map/Map.h +++ b/radiant/map/Map.h @@ -23,6 +23,7 @@ namespace map class MapPositionManager; class StartupMapLoader; +/// Main class representing the current map class Map : public IMap, public scene::Graph::Observer diff --git a/radiant/map/MapPositionManager.cpp b/radiant/map/MapPositionManager.cpp index c364d5040d..251d3508ec 100644 --- a/radiant/map/MapPositionManager.cpp +++ b/radiant/map/MapPositionManager.cpp @@ -1,5 +1,6 @@ #include "MapPositionManager.h" +#include "maplib.h" #include "ientity.h" #include "ieventmanager.h" #include "iregistry.h" @@ -56,12 +57,7 @@ MapPositionManager::MapPositionManager() void MapPositionManager::loadPositions() { - // Find the worldspawn node - const scene::INodePtr& wsNode = GlobalMapModule().getWorldspawn(); - - if (!wsNode) return; - - Entity* worldspawn = Node_getEntity(wsNode); + Entity* worldspawn = map::current::getWorldspawn(); if (worldspawn != nullptr) { @@ -81,12 +77,7 @@ void MapPositionManager::loadPositions() void MapPositionManager::savePositions() { - // Find the worldspawn node - const scene::INodePtr& wsNode = GlobalMapModule().getWorldspawn(); - - if (!wsNode) return; - - Entity* worldspawn = Node_getEntity(wsNode); + Entity* worldspawn = map::current::getWorldspawn(); for (unsigned int i = 1; i <= MAX_POSITIONS; ++i) { @@ -100,11 +91,7 @@ void MapPositionManager::savePositions() void MapPositionManager::removePositions() { // Find the worldspawn node - const scene::INodePtr& wsNode = GlobalMapModule().getWorldspawn(); - - if (!wsNode) return; - - Entity* worldspawn = Node_getEntity(wsNode); + Entity* worldspawn = map::current::getWorldspawn(); for (unsigned int i = 1; i <= MAX_POSITIONS; ++i) { diff --git a/radiant/xyview/XYWnd.cpp b/radiant/xyview/XYWnd.cpp index 92127d5b97..1e8116d4f1 100644 --- a/radiant/xyview/XYWnd.cpp +++ b/radiant/xyview/XYWnd.cpp @@ -34,6 +34,7 @@ #include "XYRenderer.h" #include "gamelib.h" #include "scenelib.h" +#include "maplib.h" #include "render/frontend/RenderableCollectionWalker.h" #include @@ -939,14 +940,15 @@ void XYWnd::drawGrid() void XYWnd::drawBlockGrid() { - if (GlobalMap().getWorldspawn() == NULL) { - return; // no worldspawn yet - } + // Do nothing if there is no worldspawn yet + Entity* worldSpawn = map::current::getWorldspawn(); + if (!worldSpawn) + return; + // Set a default blocksize of 1024 int blockSize = GlobalXYWnd().defaultBlockSize(); // Check the worldspawn for a custom blocksize - Entity* worldSpawn = Node_getEntity(GlobalMap().getWorldspawn()); assert(worldSpawn); std::string sizeVal = worldSpawn->getKeyValue("_blocksize");