From 12a9380230c033e176fdf1b3df96e613f82f1098 Mon Sep 17 00:00:00 2001 From: codereader Date: Tue, 3 Jan 2017 13:15:27 +0100 Subject: [PATCH] PointFile module initialising itself --- include/imap.h | 1 + radiant/RadiantModule.cpp | 5 -- radiant/map/Map.cpp | 3 +- radiant/map/PointFile.cpp | 136 +++++++++++++++++++++++++------------- radiant/map/PointFile.h | 31 ++++----- 5 files changed, 107 insertions(+), 69 deletions(-) diff --git a/include/imap.h b/include/imap.h index 62da4166ff..999bdddcc5 100644 --- a/include/imap.h +++ b/include/imap.h @@ -66,6 +66,7 @@ class IMap : MapLoaded, // emitted when the current map is done loading MapUnloading, // emitted just before a map is unloaded from memory MapUnloaded, // emitted after a map has been unloaded + MapSaved, // emitted right after a map has been saved }; typedef sigc::signal MapEventSignal; diff --git a/radiant/RadiantModule.cpp b/radiant/RadiantModule.cpp index ac40f35f99..995bf8fe48 100644 --- a/radiant/RadiantModule.cpp +++ b/radiant/RadiantModule.cpp @@ -19,7 +19,6 @@ #include "scene/Node.h" -#include "map/PointFile.h" #include "ui/texturebrowser/TextureBrowser.h" #include "ui/mainframe/ScreenUpdateBlocker.h" #include "textool/TexTool.h" @@ -200,8 +199,6 @@ void RadiantModule::initialiseModule(const ApplicationContext& ctx) // Reset the node id count scene::Node::resetIds(); - map::PointFile::Instance().registerCommands(); - registerUICommands(); ui::TexTool::registerCommands(); @@ -223,8 +220,6 @@ void RadiantModule::shutdownModule() GlobalFileSystem().shutdown(); - map::PointFile::Instance().destroy(); - _radiantShutdown.clear(); } diff --git a/radiant/map/Map.cpp b/radiant/map/Map.cpp index f776c80631..65e1943413 100644 --- a/radiant/map/Map.cpp +++ b/radiant/map/Map.cpp @@ -32,7 +32,6 @@ #include "scene/BasicRootNode.h" #include "map/MapFileManager.h" #include "map/MapPositionManager.h" -#include "map/PointFile.h" #include "map/RootNode.h" #include "map/MapResource.h" #include "map/algorithm/Clone.h" @@ -446,7 +445,7 @@ bool Map::save(const MapFormatPtr& mapFormat) // Store the map positions into the worldspawn spawnargs GlobalMapPosition().savePositions(); - PointFile::Instance().clear(); + signal_mapEvent().emit(IMap::MapSaved); wxutil::ScopeTimer timer("map save"); diff --git a/radiant/map/PointFile.cpp b/radiant/map/PointFile.cpp index 3d44714e36..70583cae41 100644 --- a/radiant/map/PointFile.cpp +++ b/radiant/map/PointFile.cpp @@ -18,27 +18,20 @@ #include "xyview/GlobalXYWnd.h" #include +#include "modulesystem/StaticModule.h" + #ifdef MessageBox #undef MessageBox #endif -namespace map { +namespace map +{ // Constructor PointFile::PointFile() : _curPos(_points.begin()), _displayList(0) -{ - _renderstate = GlobalRenderSystem().capture("$POINTFILE"); - GlobalRenderSystem().attachRenderable(*this); - - GlobalMap().signal_mapEvent().connect(sigc::mem_fun(*this, &PointFile::onMapEvent)); -} - -void PointFile::destroy() { - GlobalRenderSystem().detachRenderable(*this); - _renderstate = ShaderPtr(); -} +{} void PointFile::onMapEvent(IMap::MapEvent ev) { @@ -46,16 +39,15 @@ void PointFile::onMapEvent(IMap::MapEvent ev) { clear(); } -} - -// Static accessor method -PointFile& PointFile::Instance() { - static PointFile _instance; - return _instance; + else if (ev == IMap::MapSaved) + { + clear(); + } } // Query whether the point path is currently visible -bool PointFile::isVisible() const { +bool PointFile::isVisible() const +{ return _displayList != 0; } @@ -63,10 +55,11 @@ bool PointFile::isVisible() const { * Toggle the status of the pointfile rendering. If the pointfile must be * shown, the file is parsed automatically. */ -void PointFile::show(bool show) { - +void PointFile::show(bool show) +{ // Update the status if required - if(show && _displayList == 0) { + if(show && _displayList == 0) + { // Parse the pointfile from disk parse(); if (_points.size() > 0) { @@ -89,15 +82,18 @@ void PointFile::show(bool show) { /* * OpenGL render function (back-end). */ -void PointFile::render(const RenderInfo& info) const { +void PointFile::render(const RenderInfo& info) const +{ glCallList(_displayList); } /* * Solid renderable submission function (front-end) */ -void PointFile::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const { - if(isVisible()) { +void PointFile::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const +{ + if (isVisible()) + { collector.SetState(_renderstate, RenderableCollector::eWireframeOnly); collector.SetState(_renderstate, RenderableCollector::eFullMaterials); collector.addRenderable(*this, Matrix4::getIdentity()); @@ -107,13 +103,14 @@ void PointFile::renderSolid(RenderableCollector& collector, const VolumeTest& vo /* * Wireframe renderable submission function (front-end). */ -void PointFile::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const { +void PointFile::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const +{ renderSolid(collector, volume); } // Parse the current pointfile and read the vectors into the point list -void PointFile::parse() { - +void PointFile::parse() +{ // Pointfile is the same as the map file but with a .lin extension // instead of .map std::string mapName = GlobalMap().getMapName(); @@ -121,7 +118,9 @@ void PointFile::parse() { // Open the pointfile and get its input stream if possible std::ifstream inFile(pfName.c_str()); - if (!inFile) { + + if (!inFile) + { wxutil::Messagebox::ShowError( (boost::format(_("Could not open pointfile: %s")) % pfName).str()); return; @@ -137,7 +136,8 @@ void PointFile::parse() { } // create the display list at the end -void PointFile::generateDisplayList() { +void PointFile::generateDisplayList() +{ _displayList = glGenLists(1); glNewList (_displayList, GL_COMPILE); @@ -155,11 +155,9 @@ void PointFile::generateDisplayList() { glEndList(); } -// Static shader -ShaderPtr PointFile::_renderstate; - // advance camera to previous point -void PointFile::advance(bool forward) { +void PointFile::advance(bool forward) +{ if (!isVisible()) { return; } @@ -200,30 +198,78 @@ void PointFile::advance(bool forward) { SceneChangeNotify(); } -void PointFile::nextLeakSpot(const cmd::ArgumentList& args) { - Instance().advance(true); +void PointFile::nextLeakSpot(const cmd::ArgumentList& args) +{ + advance(true); } -void PointFile::prevLeakSpot(const cmd::ArgumentList& args) { - Instance().advance(false); +void PointFile::prevLeakSpot(const cmd::ArgumentList& args) +{ + advance(false); } -void PointFile::clear() { +void PointFile::clear() +{ show(false); } -void PointFile::toggle(const cmd::ArgumentList& args) { - Instance().show(!Instance().isVisible()); +void PointFile::toggle(const cmd::ArgumentList& args) +{ + show(!isVisible()); } -void PointFile::registerCommands() { - GlobalCommandSystem().addCommand("TogglePointfile", toggle); - GlobalCommandSystem().addCommand("NextLeakSpot", nextLeakSpot); - GlobalCommandSystem().addCommand("PrevLeakSpot", prevLeakSpot); +void PointFile::registerCommands() +{ + GlobalCommandSystem().addCommand("TogglePointfile", sigc::mem_fun(*this, &PointFile::toggle)); + GlobalCommandSystem().addCommand("NextLeakSpot", sigc::mem_fun(*this, &PointFile::nextLeakSpot)); + GlobalCommandSystem().addCommand("PrevLeakSpot", sigc::mem_fun(*this, &PointFile::prevLeakSpot)); GlobalEventManager().addCommand("TogglePointfile", "TogglePointfile"); GlobalEventManager().addCommand("NextLeakSpot", "NextLeakSpot"); GlobalEventManager().addCommand("PrevLeakSpot", "PrevLeakSpot"); } +// RegisterableModule implementation +const std::string& PointFile::getName() const +{ + static std::string _name("PointFile"); + return _name; +} + +const StringSet& PointFile::getDependencies() const +{ + static StringSet _dependencies; + + if (_dependencies.empty()) + { + _dependencies.insert(MODULE_COMMANDSYSTEM); + _dependencies.insert(MODULE_EVENTMANAGER); + _dependencies.insert(MODULE_RENDERSYSTEM); + _dependencies.insert(MODULE_MAP); + } + + return _dependencies; +} + +void PointFile::initialiseModule(const ApplicationContext& ctx) +{ + rMessage() << getName() << "::initialiseModule called" << std::endl; + + registerCommands(); + + _renderstate = GlobalRenderSystem().capture("$POINTFILE"); + + GlobalRenderSystem().attachRenderable(*this); + + GlobalMap().signal_mapEvent().connect(sigc::mem_fun(*this, &PointFile::onMapEvent)); +} + +void PointFile::shutdownModule() +{ + GlobalRenderSystem().detachRenderable(*this); + _renderstate.reset(); +} + +module::StaticModule pointFileModule; + } // namespace map diff --git a/radiant/map/PointFile.h b/radiant/map/PointFile.h index 77b008aabf..e5e47b5b5c 100644 --- a/radiant/map/PointFile.h +++ b/radiant/map/PointFile.h @@ -3,6 +3,7 @@ #include #include "irender.h" #include "imap.h" +#include "imodule.h" #include "icommandsystem.h" #include "irenderable.h" #include "math/Vector3.h" @@ -11,6 +12,7 @@ namespace map { class PointFile : + public RegisterableModule, public Renderable, public OpenGLRenderable { @@ -24,7 +26,7 @@ class PointFile : // GL display list pointer for rendering the point path int _displayList; - static ShaderPtr _renderstate; + ShaderPtr _renderstate; public: // Constructor @@ -33,15 +35,6 @@ class PointFile : // Destructor virtual ~PointFile() {} - /** greebo: Accessor method containing the singleton instance. - */ - static PointFile& Instance(); - - /** greebo: This releases the shader and detaches this class from - * the shadercache. - */ - void destroy(); - // Query whether the point path is currently visible bool isVisible() const; @@ -84,17 +77,21 @@ class PointFile : */ void clear(); - // Registers the events to the EventManager - static void registerCommands(); + const std::string& getName() const override; + const StringSet& getDependencies() const override; + void initialiseModule(const ApplicationContext& ctx) override; + void shutdownModule() override; - // Static command targets, these re-route the call to the static instance - static void nextLeakSpot(const cmd::ArgumentList& args); - static void prevLeakSpot(const cmd::ArgumentList& args); +private: + // Registers the events to the EventManager + void registerCommands(); + // command targets // Toggles visibility of the point file line - static void toggle(const cmd::ArgumentList& args); + void toggle(const cmd::ArgumentList& args); + void nextLeakSpot(const cmd::ArgumentList& args); + void prevLeakSpot(const cmd::ArgumentList& args); -private: // Parse the current pointfile and read the vectors into the point list void parse();