Skip to content
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

Merge attempt #3 #5

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 18 additions & 5 deletions core/Dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,26 @@ Dispatch.prototype.dismount = function dismount (path) {
if (node.isMounted()) {
if (node.onDismount) node.onDismount(path);

for (i = 0, len = children.length ; i < len ; i++)
if (children[i] && children[i].dismount) children[i].dismount();
else if (children[i]) this.dismount(path + '/' + i);
// NOTE! Traverse the list backwards as the child will be removed from the list and the list is shrunk in the back per dismount. This avoids a bug where only half the elements would get removed!
for (i = children.length - 1 ; i >= 0 ; i--)
{
if (children[i] && children[i].dismount)
{
children[i].dismount();
}
else if (children[i])
{
this.dismount(path + '/' + i);
}
}

for (i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onDismount)
components[i].onDismount();
{
if (components[i] && components[i].onDismount)
{
components[i].onDismount();
}
}

node._setMounted(false);
node._setParent(null);
Expand Down
2 changes: 2 additions & 0 deletions core/FamousEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ FamousEngine.prototype._update = function _update () {

SizeSystem.update();
TransformSystem.update();
if (stats) stats.ProfileStart("osUp")
OpacitySystem.update();
if (stats) stats.ProfileEnd("osUp")

while (nextQueue.length) queue.unshift(nextQueue.pop());

Expand Down
51 changes: 48 additions & 3 deletions core/Opacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function Opacity (parent) {
this.parent = parent ? parent : null;
this.breakPoint = false;
this.calculatingWorldOpacity = false;
this.refresh = false;
this.childs = [];
}

Opacity.WORLD_CHANGED = 1;
Expand All @@ -41,8 +43,26 @@ Opacity.prototype.reset = function reset () {
this.breakPoint = false;
};

Opacity.prototype.setParent = function setParent (parent) {
this.parent = parent;
Opacity.prototype.setParent = function setParent(parent)
{
if (this.parent)
{
// Remove as child.
var index = this.parent.childs.indexOf(this, 0);
if (index != undefined)
{
this.parent.childs.splice(index, 1);
}
}

this.parent = parent;

if (parent)
{
parent.childs.push(this);
this._refresh();
}

};

Opacity.prototype.getParent = function getParent () {
Expand All @@ -52,6 +72,7 @@ Opacity.prototype.getParent = function getParent () {
Opacity.prototype.setBreakPoint = function setBreakPoint () {
this.breakPoint = true;
this.calculatingWorldOpacity = true;
this._refresh();
};

/**
Expand Down Expand Up @@ -89,8 +110,32 @@ Opacity.prototype.getOpacity = function getOpacity () {
return this.opacity;
};

Opacity.prototype._refresh = function _refresh(opacity)
{
if (!this.refresh)
{
this.refresh = true;

// Tell all it's children.
for (var i = 0, len = this.childs.length ; i < len ; i++)
{
if (!this.childs[i].refresh)
{
this.childs[i]._refresh();
}
}
}
}

Opacity.prototype.setOpacity = function setOpacity (opacity) {
this.opacity = opacity;
var changed = this.opacity !== opacity;
this.opacity = opacity;

if (changed)
{
this._refresh();
}

};

Opacity.prototype.calculateWorldOpacity = function calculateWorldOpacity () {
Expand Down
36 changes: 24 additions & 12 deletions core/OpacitySystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ OpacitySystem.prototype.registerOpacityAtPath = function registerOpacityAtPath (
*
* @param {String} path at which to register the opacity
*/
OpacitySystem.prototype.deregisterOpacityAtPath = function deregisterOpacityAtPath (path) {
OpacitySystem.prototype.deregisterOpacityAtPath = function deregisterOpacityAtPath(path)
{
var op = this.pathStore.get(path);
op.setParent(null);

this.pathStore.remove(path);
};

Expand Down Expand Up @@ -140,17 +144,25 @@ OpacitySystem.prototype.update = function update () {
var node;
var components;

for (var i = 0, len = opacities.length ; i < len ; i++) {
node = Dispatch.getNode(paths[i]);
if (!node) continue;
components = node.getComponents();
opacity = opacities[i];

if ((changed = opacity.calculate())) {
opacityChanged(node, components, opacity);
if (changed & Opacity.LOCAL_CHANGED) localOpacityChanged(node, components, opacity.getLocalOpacity());
if (changed & Opacity.WORLD_CHANGED) worldOpacityChanged(node, components, opacity.getWorldOpacity());
}
for (var i = 0, len = opacities.length ; i < len ; i++)
{
opacity = opacities[i];
if (opacity.refresh)
{
opacity.refresh = false;

node = Dispatch.getNode(paths[i]);
if (node)
{
if ((changed = opacity.calculate()))
{
components = node.getComponents();
opacityChanged(node, components, opacity);
if (changed & Opacity.LOCAL_CHANGED) localOpacityChanged(node, components, opacity.getLocalOpacity());
if (changed & Opacity.WORLD_CHANGED) worldOpacityChanged(node, components, opacity.getWorldOpacity());
}
}
}
}
};

Expand Down
27 changes: 19 additions & 8 deletions core/Size.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function Size (parent) {
this.renderSizeChanged = false;

this.parent = parent != null ? parent : null;

this.refresh = false;
}

// an enumeration of the different types of size modes
Expand Down Expand Up @@ -170,8 +172,9 @@ Size.prototype.setSizeMode = function setSizeMode (x, y, z) {
if (x != null) x = resolveSizeMode(x);
if (y != null) y = resolveSizeMode(y);
if (z != null) z = resolveSizeMode(z);
this.sizeModeChanged = setVec(this.sizeMode, x, y, z);
return this;
var ch = setVec(this.sizeMode, x, y, z);
this.sizeModeChanged = ch;
this.refresh |= ch;
};

/**
Expand All @@ -197,8 +200,10 @@ Size.prototype.getSizeMode = function getSizeMode () {
* @return {Size} this
*/
Size.prototype.setAbsolute = function setAbsolute (x, y, z) {
this.absoluteSizeChanged = setVec(this.absoluteSize, x, y, z);
return this;
var ch = setVec(this.absoluteSize, x, y, z);
this.absoluteSizeChanged = ch;
this.refresh |= ch;
return this;
};

/**
Expand All @@ -224,8 +229,10 @@ Size.prototype.getAbsolute = function getAbsolute () {
* @return {Size} this
*/
Size.prototype.setProportional = function setProportional (x, y, z) {
this.proportionalSizeChanged = setVec(this.proportionalSize, x, y, z);
return this;
var ch = setVec(this.proportionalSize, x, y, z);
this.proportionalSizeChanged = ch;
this.refresh |= ch;
return this;
};

/**
Expand All @@ -251,7 +258,9 @@ Size.prototype.getProportional = function getProportional () {
* @return {Size} this
*/
Size.prototype.setDifferential = function setDifferential (x, y, z) {
this.differentialSizeChanged = setVec(this.differentialSize, x, y, z);
var ch = setVec(this.differentialSize, x, y, z);
this.differentialSizeChanged = ch;
this.refresh |= ch;
return this;
};

Expand Down Expand Up @@ -324,7 +333,9 @@ Size.prototype.fromComponents = function fromComponents (components) {
}
changed = changed || prev !== target[i];
}
this.sizeChanged = changed;
var ch = changed;
this.sizeChanged = ch;
this.refresh |= ch;
return changed;
};

Expand Down
37 changes: 25 additions & 12 deletions core/SizeSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ SizeSystem.prototype.get = function get (path) {
*
* @return {undefined} undefined
*/
SizeSystem.prototype.update = function update () {
SizeSystem.prototype.update = function update()
{
if (stats) stats.ProfileStart("ssUp")

var sizes = this.pathStore.getItems();
var paths = this.pathStore.getPaths();
var node;
Expand All @@ -108,18 +111,28 @@ SizeSystem.prototype.update = function update () {
var len;
var components;

for (i = 0, len = sizes.length ; i < len ; i++) {
node = Dispatch.getNode(paths[i]);
components = node.getComponents();
if (!node) continue;
size = sizes[i];
if (size.sizeModeChanged) sizeModeChanged(node, components, size);
if (size.absoluteSizeChanged) absoluteSizeChanged(node, components, size);
if (size.proportionalSizeChanged) proportionalSizeChanged(node, components, size);
if (size.differentialSizeChanged) differentialSizeChanged(node, components, size);
if (size.renderSizeChanged) renderSizeChanged(node, components, size);
if (size.fromComponents(components)) sizeChanged(node, components, size);
for (i = 0, len = sizes.length ; i < len ; i++)
{
size = sizes[i];
if (size.refresh)
{
size.refresh = false;

node = Dispatch.getNode(paths[i]);
if (node)
{
components = node.getComponents();
if (size.sizeModeChanged) sizeModeChanged(node, components, size);
if (size.absoluteSizeChanged) absoluteSizeChanged(node, components, size);
if (size.proportionalSizeChanged) proportionalSizeChanged(node, components, size);
if (size.differentialSizeChanged) differentialSizeChanged(node, components, size);
if (size.renderSizeChanged) renderSizeChanged(node, components, size);
if (size.fromComponents(components)) sizeChanged(node, components, size);
}
}
}

if (stats) stats.ProfileEnd("ssUp")
};

// private methods
Expand Down