-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): allow layer to specify which elements should be updatable #789
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,10 +65,37 @@ function updateElements(context, geometryLayer, elements) { | |
// and then update Debug.js:addGeometryLayerDebugFeatures | ||
const newElementsToUpdate = geometryLayer.update(context, geometryLayer, element); | ||
|
||
// update attached layers | ||
for (const attachedLayer of geometryLayer._attachedLayers) { | ||
if (attachedLayer.ready) { | ||
attachedLayer.update(context, attachedLayer, element); | ||
const sub = geometryLayer.getObjectToUpdateForAttachedLayers(element); | ||
|
||
if (sub) { | ||
if (sub.element) { | ||
if (__DEBUG__) { | ||
if (!(sub.element.isObject3D)) { | ||
throw new Error(` | ||
Invalid object for attached layer to update. | ||
Must be a THREE.Object and have a THREE.Material`); | ||
} | ||
} | ||
// update attached layers | ||
for (const attachedLayer of geometryLayer._attachedLayers) { | ||
if (attachedLayer.ready) { | ||
attachedLayer.update(context, attachedLayer, sub.element, sub.parent); | ||
} | ||
} | ||
} else if (sub.elements) { | ||
for (let i = 0; i < sub.elements.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dislike more and more the Anyway I'll change it because for now we settled on using it everywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it seems that performance wise it is the slowest (as tested quickly here http://jsben.ch/iEYTg) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this test misses one of the cost: in itowns we never run native for (const word of words) {
console.log(word);
} becomes: "use strict";
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = words[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var word = _step.value;
console.log(word);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
} |
||
if (!(sub.elements[i].isObject3D)) { | ||
throw new Error(` | ||
Invalid object for attached layer to update. | ||
Must be a THREE.Object and have a THREE.Material`); | ||
} | ||
// update attached layers | ||
for (const attachedLayer of geometryLayer._attachedLayers) { | ||
if (attachedLayer.ready) { | ||
attachedLayer.update(context, attachedLayer, sub.elements[i], sub.parent); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
updateElements(context, geometryLayer, newElementsToUpdate); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getObjectToUpdateForAttachedLayers
can always return an Array?it would simplify this part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is internal only (= no user of iTowns will have to write the same code in its application), so I don't mind having a bit more complicated code if it performs better.
I'll check, and simplify if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that it is more of a problem of structure of our elements. We should not complicate this part of the process to be able to adapt to all structures. I'll go deeper and I'll come back on the subject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @gchoqueux, even if it is hidden, it should always return
elements
as an array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that this piece of code is executed multiple times during each update loop.
So creating an array by default, even if it's for a single element might pressure the GC or cause a perf hit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that's a good point. We still have duplicated code though, could you move both part into another function ?