Skip to content

Commit

Permalink
Move LitObject implementation up to scene::Node
Browse files Browse the repository at this point in the history
Every major renderable node class had its own implementation of
LitObject::intersectsLight, but all of these implementations were identical.
This method is now implemented at the Node level, and inherited by all
subclasses.
  • Loading branch information
Matthew Mott committed Dec 7, 2021
1 parent 135fe53 commit 966d6b1
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 47 deletions.
5 changes: 5 additions & 0 deletions libs/scene/Node.cpp
Expand Up @@ -479,6 +479,11 @@ void Node::setRenderSystem(const RenderSystemPtr& renderSystem)
_children.setRenderSystem(renderSystem);
}

bool Node::intersectsLight(const RendererLight& light) const
{
return light.lightAABB().intersects(worldAABB());
}

void Node::setForcedVisibility(bool forceVisible, bool includeChildren)
{
_forceVisible = forceVisible;
Expand Down
12 changes: 8 additions & 4 deletions libs/scene/Node.h
Expand Up @@ -18,9 +18,7 @@ class Graph;
typedef std::weak_ptr<Graph> GraphWeakPtr;

/// Main implementation of INode
class Node :
public virtual INode,
public std::enable_shared_from_this<Node>
class Node: public LitObject, public virtual INode, public std::enable_shared_from_this<Node>
{
public:
enum {
Expand Down Expand Up @@ -192,7 +190,13 @@ class Node :

// Base renderable implementation
virtual RenderSystemPtr getRenderSystem() const;
virtual void setRenderSystem(const RenderSystemPtr& renderSystem) override;
void setRenderSystem(const RenderSystemPtr& renderSystem) override;

// Default LitObject::intersectsLight implementation, does a simple
// intersection check between this node's worldAABB and the light's
// lightAABB. Subclasses may override to provide more precise intersection
// tests if appropriate.
bool intersectsLight(const RendererLight& light) const override;

protected:
// Set the "forced visible" flag, only to be used internally by subclasses
Expand Down
7 changes: 1 addition & 6 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -39,7 +39,6 @@ BrushNode::BrushNode(const BrushNode& other) :
ComponentEditable(other),
ComponentSnappable(other),
PlaneSelectable(other),
LitObject(other),
Transformable(other),
m_brush(*this, other.m_brush),
_selectedPoints(GL_POINTS),
Expand Down Expand Up @@ -75,7 +74,7 @@ std::string BrushNode::getFingerprint()
}

math::Hash hash;

hash.addSizet(static_cast<std::size_t>(m_brush.getDetailFlag() + 1));

hash.addSizet(m_brush.getNumFaces());
Expand Down Expand Up @@ -343,10 +342,6 @@ void BrushNode::DEBUG_verify() {
ASSERT_MESSAGE(m_faceInstances.size() == m_brush.DEBUG_size(), "FATAL: mismatch");
}

bool BrushNode::intersectsLight(const RendererLight& light) const {
return light.lightAABB().intersects(worldAABB());
}

void BrushNode::renderComponents(RenderableCollector& collector, const VolumeTest& volume) const
{
m_brush.evaluateBRep();
Expand Down
6 changes: 1 addition & 5 deletions radiantcore/brush/BrushNode.h
Expand Up @@ -27,7 +27,6 @@ class BrushNode :
public ComponentEditable,
public ComponentSnappable,
public PlaneSelectable,
public LitObject,
public Transformable,
public ITraceable,
public scene::IComparableNode
Expand Down Expand Up @@ -136,9 +135,6 @@ class BrushNode :
void vertex_push_back(SelectableVertex& vertex) override;
void DEBUG_verify() override;

// LitObject implementation
bool intersectsLight(const RendererLight& light) const override;

// Renderable implementation
void renderComponents(RenderableCollector& collector, const VolumeTest& volume) const override;
void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override;
Expand All @@ -163,7 +159,7 @@ class BrushNode :
// Returns the center of the untransformed world AABB
const Vector3& getUntransformedOrigin() override;

// Returns true if this node is visible due to its selection status
// Returns true if this node is visible due to its selection status
// even though it might otherwise be filtered or hidden
// Should only be used by the internal Brush object
bool facesAreForcedVisible();
Expand Down
12 changes: 3 additions & 9 deletions radiantcore/model/StaticModelNode.cpp
Expand Up @@ -15,7 +15,7 @@ namespace model {

// greebo: Construct a new StaticModel instance, we re-use the surfaces only
StaticModelNode::StaticModelNode(const StaticModelPtr& picoModel) :
_model(new StaticModel(*picoModel)),
_model(new StaticModel(*picoModel)),
_name(picoModel->getFilename())
{
// Update the skin
Expand All @@ -28,7 +28,7 @@ StaticModelNode::~StaticModelNode()
void StaticModelNode::onInsertIntoScene(scene::IMapRootNode& root)
{
_model->connectUndoSystem(root.getUndoSystem());

Node::onInsertIntoScene(root);
}

Expand All @@ -44,7 +44,7 @@ const IModel& StaticModelNode::getIModel() const
return *_model;
}

IModel& StaticModelNode::getIModel()
IModel& StaticModelNode::getIModel()
{
return *_model;
}
Expand Down Expand Up @@ -85,12 +85,6 @@ void StaticModelNode::setModel(const StaticModelPtr& model) {
_model = model;
}

// LitObject test function
bool StaticModelNode::intersectsLight(const RendererLight& light) const
{
return light.lightAABB().intersects(worldAABB());
}

void StaticModelNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
{
assert(_renderEntity);
Expand Down
4 changes: 0 additions & 4 deletions radiantcore/model/StaticModelNode.h
Expand Up @@ -26,7 +26,6 @@ class StaticModelNode :
public scene::Node,
public ModelNode,
public SelectionTestable,
public LitObject,
public SkinnedModel,
public ITraceable,
public Transformable
Expand Down Expand Up @@ -75,9 +74,6 @@ class StaticModelNode :
const StaticModelPtr& getModel() const;
void setModel(const StaticModelPtr& model);

// LitObject test function
bool intersectsLight(const RendererLight& light) const override;

// Renderable implementation
void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const override;
Expand Down
5 changes: 0 additions & 5 deletions radiantcore/model/md5/MD5ModelNode.cpp
Expand Up @@ -67,11 +67,6 @@ bool MD5ModelNode::getIntersection(const Ray& ray, Vector3& intersection)
return _model->getIntersection(ray, intersection, localToWorld());
}

bool MD5ModelNode::intersectsLight(const RendererLight& light) const
{
return light.lightAABB().intersects(worldAABB());
}

void MD5ModelNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
{
assert(_renderEntity);
Expand Down
6 changes: 1 addition & 5 deletions radiantcore/model/md5/MD5ModelNode.h
Expand Up @@ -12,7 +12,6 @@ class MD5ModelNode :
public scene::Node,
public model::ModelNode,
public SelectionTestable,
public LitObject,
public SkinnedModel,
public ITraceable
{
Expand Down Expand Up @@ -47,9 +46,6 @@ class MD5ModelNode :
// Traceable implementation
bool getIntersection(const Ray& ray, Vector3& intersection) override;

// LitObject implementation
bool intersectsLight(const RendererLight& light) const override;

// Renderable implementation
void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const override;
Expand All @@ -65,7 +61,7 @@ class MD5ModelNode :
void skinChanged(const std::string& newSkinName) override;

private:
void render(RenderableCollector& collector, const VolumeTest& volume,
void render(RenderableCollector& collector, const VolumeTest& volume,
const Matrix4& localToWorld, const IRenderEntity& entity) const;
};
typedef std::shared_ptr<MD5ModelNode> MD5ModelNodePtr;
Expand Down
5 changes: 0 additions & 5 deletions radiantcore/patch/PatchNode.cpp
Expand Up @@ -29,7 +29,6 @@ PatchNode::PatchNode(const PatchNode& other) :
ComponentEditable(other),
ComponentSnappable(other),
PlaneSelectable(other),
LitObject(other),
Transformable(other),
m_dragPlanes(std::bind(&PatchNode::selectedChangedComponent, this, std::placeholders::_1)),
m_render_selected(GL_POINTS),
Expand Down Expand Up @@ -300,10 +299,6 @@ bool PatchNode::getIntersection(const Ray& ray, Vector3& intersection)
return m_patch.getIntersection(ray, intersection);
}

bool PatchNode::intersectsLight(const RendererLight& light) const {
return light.lightAABB().intersects(worldAABB());
}

void PatchNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
{
// Don't render invisible shaders
Expand Down
4 changes: 0 additions & 4 deletions radiantcore/patch/PatchNode.h
Expand Up @@ -21,7 +21,6 @@ class PatchNode :
public ComponentEditable,
public ComponentSnappable,
public PlaneSelectable,
public LitObject,
public Transformable,
public ITraceable,
public scene::IComparableNode
Expand Down Expand Up @@ -123,9 +122,6 @@ class PatchNode :
// (see ObservedSelectable and PatchControlInstance)
void selectedChangedComponent(const ISelectable& selectable);

// LitObject implementation
bool intersectsLight(const RendererLight& light) const override;

// Renderable implementation

// Render functions, these make sure that all things get rendered properly. The calls are also passed on
Expand Down

0 comments on commit 966d6b1

Please sign in to comment.