-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclusive and Priority for SceneLayer (#2046)
* Exclusive and Priority for SceneLayer - Sort SceneLayers such that all exclusive layers come before non-exclusive layers and in order of increasing priority * Fix SceneLayer sorting and clean up parameters * Remove declaration of un-implemented DrawRule method * Clarify SceneLayer sorting and fix lexical comparison * Don't store depth with layer, calculate during traversal * More cleanup in DrawRule * Refactor drawRuleTests to reduce repetition * Refactor layerTests and add exclusive/priority checks * Use 'exclusive' and 'priority' in demo scene Co-authored-by: Matt Blair <[email protected]>
- Loading branch information
1 parent
ab32ca9
commit d5cdf97
Showing
11 changed files
with
373 additions
and
533 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,34 +1,38 @@ | ||
#include "scene/sceneLayer.h" | ||
|
||
#include <algorithm> | ||
#include <type_traits> | ||
|
||
namespace Tangram { | ||
|
||
static_assert(std::is_move_constructible<SceneLayer>::value, "check"); | ||
|
||
SceneLayer::SceneLayer(std::string _name, Filter _filter, | ||
std::vector<DrawRuleData> _rules, | ||
std::vector<SceneLayer> _sublayers, | ||
bool _enabled) : | ||
m_filter(std::move(_filter)), | ||
m_name(_name), | ||
m_rules(_rules), | ||
m_sublayers(std::move(_sublayers)), | ||
m_enabled(_enabled) { | ||
|
||
setDepth(1); | ||
|
||
} | ||
|
||
void SceneLayer::setDepth(size_t _d) { | ||
|
||
m_depth = _d; | ||
|
||
for (auto& layer : m_sublayers) { | ||
layer.setDepth(m_depth + 1); | ||
} | ||
|
||
SceneLayer::SceneLayer(std::string name, Filter filter, | ||
std::vector<DrawRuleData> rules, | ||
std::vector<SceneLayer> sublayers, | ||
Options options) : | ||
m_filter(std::move(filter)), | ||
m_name(std::move(name)), | ||
m_rules(std::move(rules)), | ||
m_sublayers(std::move(sublayers)), | ||
m_options(options) { | ||
|
||
// Sort sublayers for precedence in matching operations. If multiple values for a parameter are assigned to the same | ||
// draw group at the same layer depth, then the value that comes *first* in the layer list will be the final value. | ||
std::sort(m_sublayers.begin(), m_sublayers.end(), | ||
[](const SceneLayer& a, const SceneLayer& b) { | ||
if (a.exclusive() != b.exclusive()) { | ||
// Exclusive layers always precede non-exclusive layers. | ||
return a.exclusive(); | ||
} else if (a.priority() != b.priority()) { | ||
// Layers whose priority value is closer to -infinity take precedence. | ||
return a.priority() < b.priority(); | ||
} | ||
// If priority and exclusivity are the same for two layers, precedence is determined by reverse | ||
// alphabetical ordering of their names (which must be unique among sibling layers). That is, if there | ||
// are two sibling layers with the same exclusivity and priority named 'a' and 'b', then 'b' will come | ||
// first. | ||
return a.name() > b.name(); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.