Skip to content

Commit

Permalink
Remove LightNode projected colour accessor methods
Browse files Browse the repository at this point in the history
By making the _projColours member mutable we can avoid the const_casts in
render methods which update vertex colours.
  • Loading branch information
Matthew Mott committed Jan 6, 2022
1 parent b20f884 commit df659a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
37 changes: 18 additions & 19 deletions radiantcore/entity/light/LightNode.cpp
Expand Up @@ -444,14 +444,19 @@ void LightNode::renderComponents(RenderableCollector& collector, const VolumeTes
const Vector3& colourVertexDeselected = settings.getLightVertexColour(LightEditVertexType::Deselected);

// Update the colour of the light center dot
const_cast<LightNode&>(*this).colourLightTarget() = (_lightTargetInstance.isSelected()) ? colourVertexSelected : colourVertexDeselected;
const_cast<LightNode&>(*this).colourLightRight() = (_lightRightInstance.isSelected()) ? colourVertexSelected : colourVertexDeselected;
const_cast<LightNode&>(*this).colourLightUp() = (_lightUpInstance.isSelected()) ? colourVertexSelected : colourVertexDeselected;

const_cast<LightNode&>(*this).colourLightStart() = (_lightStartInstance.isSelected()) ? colourStartEndSelected : colourStartEndDeselected;
const_cast<LightNode&>(*this).colourLightEnd() = (_lightEndInstance.isSelected()) ? colourStartEndSelected : colourStartEndDeselected;

// Render the projection points
_projColours.target = (_lightTargetInstance.isSelected()) ? colourVertexSelected
: colourVertexDeselected;
_projColours.right = (_lightRightInstance.isSelected()) ? colourVertexSelected
: colourVertexDeselected;
_projColours.up = (_lightUpInstance.isSelected()) ? colourVertexSelected
: colourVertexDeselected;

_projColours.start = (_lightStartInstance.isSelected()) ? colourStartEndSelected
: colourStartEndDeselected;
_projColours.end = (_lightEndInstance.isSelected()) ? colourStartEndSelected
: colourStartEndDeselected;

// Render the projection points
renderProjectionPoints(collector, volume, localToWorld());
}
else
Expand Down Expand Up @@ -489,11 +494,11 @@ void LightNode::renderInactiveComponents(RenderableCollector& collector, const V
const Vector3& colourStartEndInactive = settings.getLightVertexColour(LightEditVertexType::StartEndDeselected);
const Vector3& colourVertexInactive = settings.getLightVertexColour(LightEditVertexType::Deselected);

const_cast<LightNode&>(*this).colourLightStart() = colourStartEndInactive;
const_cast<LightNode&>(*this).colourLightEnd() = colourStartEndInactive;
const_cast<LightNode&>(*this).colourLightTarget() = colourVertexInactive;
const_cast<LightNode&>(*this).colourLightRight() = colourVertexInactive;
const_cast<LightNode&>(*this).colourLightUp() = colourVertexInactive;
_projColours.start = colourStartEndInactive;
_projColours.end = colourStartEndInactive;
_projColours.target = colourVertexInactive;
_projColours.right = colourVertexInactive;
_projColours.up = colourVertexInactive;

// Render the projection points
renderProjectionPoints(collector, volume, localToWorld());
Expand Down Expand Up @@ -1139,12 +1144,6 @@ Vector3 LightNode::getLightOrigin() const
}
}

Vector3& LightNode::colourLightTarget() { return _projColours.target; }
Vector3& LightNode::colourLightRight() { return _projColours.right; }
Vector3& LightNode::colourLightUp() { return _projColours.up; }
Vector3& LightNode::colourLightStart() { return _projColours.start; }
Vector3& LightNode::colourLightEnd() { return _projColours.end; }

/* greebo: A light is projected, if the entity keys light_target/light_up/light_right are not empty.
*/
bool LightNode::isProjected() const {
Expand Down
8 changes: 1 addition & 7 deletions radiantcore/entity/light/LightNode.h
Expand Up @@ -69,7 +69,7 @@ class LightNode :
scene::TransformedCopy<Projected<Vector3>> _projVectors;

// Projected light vector colours
Projected<Vector3> _projColours;
mutable Projected<Vector3> _projColours;

// Projected light use flags
Projected<bool> _projUseFlags;
Expand Down Expand Up @@ -290,12 +290,6 @@ class LightNode :
const ShaderPtr& getShader() const override;
AABB lightAABB() const override;

Vector3& colourLightTarget();
Vector3& colourLightRight();
Vector3& colourLightUp();
Vector3& colourLightStart();
Vector3& colourLightEnd();

bool useStartEnd() const;

}; // class LightNode
Expand Down

0 comments on commit df659a1

Please sign in to comment.