Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5893: Coarse implementation of the surface collection used by IRende…
…rEntities.
- Loading branch information
1 parent
8f56350
commit 6bc219f
Showing
6 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#pragma once | ||
|
||
#include <set> | ||
#include "irender.h" | ||
|
||
namespace entity | ||
{ | ||
|
||
class RenderableSurfaceCollection | ||
{ | ||
private: | ||
AABB _collectionBounds; | ||
bool _collectionBoundsNeedUpdate; | ||
|
||
std::set<render::IRenderableSurface::Ptr> _surfaces; | ||
|
||
public: | ||
RenderableSurfaceCollection() : | ||
_collectionBoundsNeedUpdate(true) | ||
{} | ||
|
||
void addSurface(const render::IRenderableSurface::Ptr& surface) | ||
{ | ||
_surfaces.insert(surface); | ||
_collectionBoundsNeedUpdate = true; | ||
} | ||
|
||
void removeSurface(const render::IRenderableSurface::Ptr& surface) | ||
{ | ||
_surfaces.erase(surface); | ||
_collectionBoundsNeedUpdate = true; | ||
} | ||
|
||
void foreachSurfaceTouchingBounds(const AABB& bounds, | ||
const std::function<void(const render::IRenderableSurface::Ptr&)>& functor) | ||
{ | ||
if (_surfaces.empty()) return; | ||
|
||
ensureBoundsUpToDate(); | ||
|
||
// If the whole collection doesn't intersect, quit early | ||
// TODO: bounds not updated when surface changes | ||
//if (!_collectionBounds.intersects(bounds)) return; | ||
|
||
for (const auto& surface : _surfaces) | ||
{ | ||
auto orientedBounds = AABB::createFromOrientedAABBSafe( | ||
surface->getSurfaceBounds(), surface->getSurfaceTransform()); | ||
|
||
if (bounds.intersects(orientedBounds)) | ||
{ | ||
functor(surface); | ||
} | ||
} | ||
} | ||
|
||
private: | ||
void ensureBoundsUpToDate() | ||
{ | ||
if (!_collectionBoundsNeedUpdate) return; | ||
|
||
_collectionBoundsNeedUpdate = false; | ||
|
||
_collectionBounds = AABB(); | ||
|
||
for (const auto& surface : _surfaces) | ||
{ | ||
_collectionBounds.includeAABB(AABB::createFromOrientedAABBSafe( | ||
surface->getSurfaceBounds(), surface->getSurfaceTransform())); | ||
} | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters