Skip to content

Commit

Permalink
PointFile module initialising itself
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 3, 2017
1 parent b9fed9b commit 12a9380
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 69 deletions.
1 change: 1 addition & 0 deletions include/imap.h
Expand Up @@ -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<void, MapEvent> MapEventSignal;
Expand Down
5 changes: 0 additions & 5 deletions radiant/RadiantModule.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand All @@ -223,8 +220,6 @@ void RadiantModule::shutdownModule()

GlobalFileSystem().shutdown();

map::PointFile::Instance().destroy();

_radiantShutdown.clear();
}

Expand Down
3 changes: 1 addition & 2 deletions radiant/map/Map.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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");

Expand Down
136 changes: 91 additions & 45 deletions radiant/map/PointFile.cpp
Expand Up @@ -18,55 +18,48 @@
#include "xyview/GlobalXYWnd.h"
#include <boost/format.hpp>

#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)
{
if (ev == IMap::MapUnloading)
{
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;
}

/*
* 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) {
Expand All @@ -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());
Expand All @@ -107,21 +103,24 @@ 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();
std::string pfName = mapName.substr(0, mapName.rfind(".")) + ".lin";

// 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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<PointFile> pointFileModule;

} // namespace map
31 changes: 14 additions & 17 deletions radiant/map/PointFile.h
Expand Up @@ -3,6 +3,7 @@
#include <vector>
#include "irender.h"
#include "imap.h"
#include "imodule.h"
#include "icommandsystem.h"
#include "irenderable.h"
#include "math/Vector3.h"
Expand All @@ -11,6 +12,7 @@ namespace map
{

class PointFile :
public RegisterableModule,
public Renderable,
public OpenGLRenderable
{
Expand All @@ -24,7 +26,7 @@ class PointFile :
// GL display list pointer for rendering the point path
int _displayList;

static ShaderPtr _renderstate;
ShaderPtr _renderstate;

public:
// Constructor
Expand All @@ -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;

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 12a9380

Please sign in to comment.