Skip to content

Commit

Permalink
Refactor PointFile to use RenderablePointVector instead of display lists
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 3, 2017
1 parent 12a9380 commit e8e830c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 106 deletions.
108 changes: 35 additions & 73 deletions radiant/map/PointFile.cpp
Expand Up @@ -29,80 +29,53 @@ namespace map

// Constructor
PointFile::PointFile() :
_curPos(_points.begin()),
_displayList(0)
_points(GL_LINE_STRIP),
_curPos(0)
{}

void PointFile::onMapEvent(IMap::MapEvent ev)
{
if (ev == IMap::MapUnloading)
{
clear();
}
else if (ev == IMap::MapSaved)
if (ev == IMap::MapUnloading || ev == IMap::MapSaved)
{
clear();
}
}

// Query whether the point path is currently visible
bool PointFile::isVisible() const
{
return _displayList != 0;
return !_points.empty();
}

/*
* Toggle the status of the pointfile rendering. If the pointfile must be
* shown, the file is parsed automatically.
*/
void PointFile::show(bool show)
{
// Update the status if required
if(show && _displayList == 0)
if (show)
{
// Parse the pointfile from disk
parse();
if (_points.size() > 0) {
generateDisplayList();
}
}
else if(!show && _displayList != 0) {
glDeleteLists (_displayList, 1);
_displayList = 0;
else
{
_points.clear();
}

// Regardless whether hide or show, we reset the current position
_curPos = _points.begin();
_curPos = 0;

// Redraw the scene
SceneChangeNotify();
}

/*
* OpenGL render function (back-end).
*/
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())
{
collector.SetState(_renderstate, RenderableCollector::eWireframeOnly);
collector.SetState(_renderstate, RenderableCollector::eFullMaterials);
collector.addRenderable(*this, Matrix4::getIdentity());
collector.addRenderable(_points, Matrix4::getIdentity());
}
}

/*
* Wireframe renderable submission function (front-end).
*/
void PointFile::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const
{
renderSolid(collector, volume);
Expand All @@ -128,51 +101,36 @@ void PointFile::parse()

// Pointfile is a list of float vectors, one per line, with components
// separated by spaces.
while (inFile.good()) {
while (inFile.good())
{
float x, y, z;
inFile >> x; inFile >> y; inFile >> z;
_points.push_back(Vector3(x, y, z));
_points.push_back(VertexCb(Vertex3f(x, y, z), Colour4b(255,0,0,1)));
}
}

// create the display list at the end
void PointFile::generateDisplayList()
{
_displayList = glGenLists(1);

glNewList (_displayList, GL_COMPILE);

glBegin(GL_LINE_STRIP);
for (VectorList::iterator i = _points.begin();
i != _points.end();
++i)
{
glVertex3dv(*i);
}
glEnd();
glLineWidth (1);

glEndList();
}

// advance camera to previous point
void PointFile::advance(bool forward)
{
if (!isVisible()) {
if (!isVisible())
{
return;
}

if (forward) {
if (_curPos+2 == _points.end()) {
if (forward)
{
if (_curPos + 2 >= _points.size())
{
rMessage() << "End of pointfile" << std::endl;
return;
}

_curPos++;
}
else {
// Backward movement
if (_curPos == _points.begin()) {
else // Backward movement
{
if (_curPos == 0)
{
rMessage() << "Start of pointfile" << std::endl;
return;
}
Expand All @@ -181,17 +139,21 @@ void PointFile::advance(bool forward)
}

ui::CamWndPtr cam = GlobalCamera().getActiveCamWnd();
if (cam == NULL) return;
ui::CamWnd& camwnd = *cam;

camwnd.setCameraOrigin(*_curPos);
GlobalXYWnd().getActiveXY()->setOrigin(*_curPos);
if (!cam) return;

cam->setCameraOrigin(_points[_curPos].vertex);

GlobalXYWnd().getActiveXY()->setOrigin(_points[_curPos].vertex);

{
Vector3 dir((*(_curPos+1) - camwnd.getCameraOrigin()).getNormalised());
Vector3 angles(camwnd.getCameraAngles());
angles[ui::CAMERA_YAW] = static_cast<double>(radians_to_degrees(atan2(dir[1], dir[0])));
angles[ui::CAMERA_PITCH] = static_cast<double>(radians_to_degrees(asin(dir[2])));
camwnd.setCameraAngles(angles);
Vector3 dir((_points[_curPos+1].vertex - cam->getCameraOrigin()).getNormalised());
Vector3 angles(cam->getCameraAngles());

angles[ui::CAMERA_YAW] = radians_to_degrees(atan2(dir[1], dir[0]));
angles[ui::CAMERA_PITCH] = radians_to_degrees(asin(dir[2]));

cam->setCameraAngles(angles);
}

// Redraw the scene
Expand Down
56 changes: 23 additions & 33 deletions radiant/map/PointFile.h
Expand Up @@ -7,24 +7,21 @@
#include "icommandsystem.h"
#include "irenderable.h"
#include "math/Vector3.h"
#include "render.h"

namespace map
{

class PointFile :
public RegisterableModule,
public Renderable,
public OpenGLRenderable
public Renderable
{
private:
// Vector of point coordinates
typedef std::vector<Vector3> VectorList;
VectorList _points;

RenderablePointVector _points;

// Holds the current position in the point file chain
VectorList::iterator _curPos;

// GL display list pointer for rendering the point path
int _displayList;
std::size_t _curPos;

ShaderPtr _renderstate;

Expand All @@ -39,17 +36,6 @@ class PointFile :
bool isVisible() const;

/*
* Toggle the status of the pointfile rendering. If the pointfile must be
* shown, the file is parsed automatically.
*/
void show(bool show);

/*
* OpenGL render function (back-end).
*/
void render(const RenderInfo& info) const;

/*
* Solid renderable submission function (front-end)
*/
void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override;
Expand All @@ -67,16 +53,6 @@ class PointFile :
return Highlight::NoHighlight;
}

/** greebo: This sets the camera position to the next/prev leak spot.
*
* @forward: pass true to set to the next leak spot, false for the previous
*/
void advance(bool forward);

/** greebo: Clears the point file vector and hides it, if applicable.
*/
void clear();

const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const ApplicationContext& ctx) override;
Expand All @@ -86,6 +62,23 @@ class PointFile :
// Registers the events to the EventManager
void registerCommands();

/*
* Toggle the status of the pointfile rendering. If the pointfile must be
* shown, the file is parsed automatically.
*/
void show(bool show);

/**
* greebo: Clears the point file vector, which is the same as hiding it.
*/
void clear();

/**
* greebo: This sets the camera position to the next/prev leak spot.
* @forward: pass true to set to the next leak spot, false for the previous
*/
void advance(bool forward);

// command targets
// Toggles visibility of the point file line
void toggle(const cmd::ArgumentList& args);
Expand All @@ -95,9 +88,6 @@ class PointFile :
// Parse the current pointfile and read the vectors into the point list
void parse();

// Generates the OpenGL displaylist from the point vector
void generateDisplayList();

void onMapEvent(IMap::MapEvent ev);
};

Expand Down

0 comments on commit e8e830c

Please sign in to comment.