Skip to content

Commit

Permalink
Removed Name mangling, added a new data node with systemDataNode as i…
Browse files Browse the repository at this point in the history
…t source,

Add user defined systemDataNode to XML3DDataAdapter

Update systemDataNode filter if the sys flag is removed
  • Loading branch information
ariyapour committed Nov 9, 2015
1 parent 1294092 commit 87eac4e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
33 changes: 14 additions & 19 deletions src/data/adapter/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ function recursiveDataAdapterConstruction(adapter, systemDataNode) {
//Here we check for data nodes with sys flag set
if (child.sys != undefined){
//Check if a system parameter with this name exists
// todo(ksons): Remove name mangling
if (systemDataNode.getChildByName("_system_" + child.name)) {
//Check if the systemDataNode is already added to adapter or not
if (systemDataNode.getChildByName(child.name)) {
filterNames.push(child.name);
} else {
// TODO: Use else part to have a normal value if system parameter does not exist
Expand Down Expand Up @@ -144,26 +142,23 @@ function recursiveDataAdapterConstruction(adapter, systemDataNode) {

}
}
// Passes _platform values to children nodes starting from the node
// where these attributes are first defined
if (adapter.xflowDataNode._platform !== null) {
recursiveDataNodeAttrInit(adapter.xflowDataNode);
}
}

if(filterNames.length) {
assert(!adapter.xflowDataNode.hasSystemDataNode());
//todo(ksons): Add a new DataNode that references the system data node
adapter.xflowDataNode.appendChild(systemDataNode);
var filter = "keep("+filterNames.join(",")+")";
var sysData = new DataNode(false);
sysData.systemDataAdapter = true;
sysData.sourceNode = systemDataNode;
sysData.setFilter(filter);
XML3D.debug.assert(!adapter.xflowDataNode.hasSystemDataNode());
adapter.xflowDataNode.appendChild(sysData);
}

// Passes _platform values to children nodes starting from the node
// where these attributes are first defined
if (adapter.xflowDataNode._platform !== null) {
recursiveDataNodeAttrInit(adapter.xflowDataNode);
}

// todo(ksons): Add the filter to the new data node
/*
filter = "keep({";
filter += child.name + ":_system_" + child.name + ",";
filter = filter.slice(0, -1) + "})";
newDataNode.setFilter(filter);
*/
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/data/adapter/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ ValueDataAdapter.prototype.attributeChangedCallback = function (name, oldValue,
this.xflowInputNode.key = newValue;
} else if (name == "param") {
this.xflowInputNode.paramName = newValue ? this.node.name : null;
}else if (name == "sys"){
var parentDataAdapter = this.factory.getAdapter(this.node.parentNode);
var filterNames = parentDataAdapter.xflowDataNode.hasSystemDataNode()._filterMapping._names;
var index = filterNames.indexOf(this.node.name);
filterNames.splice(index, 1);
//TODO: update the parent. The same question here. what would be the value of the parameter
}
// TODO: sys flag removed -> Update parent data node
};


Expand Down
14 changes: 11 additions & 3 deletions src/data/adapter/xml3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,31 @@ createClass(XML3DDataAdapter, NodeAdapter);
XML3DDataAdapter.prototype.init = function()
{
// todo(ksons): Check if system attribute is set,
// request data adapter and use this (with appenden sysdatanode) instead if it exsits
// request data adapter and use this (with appenden sysdatanode) instead if it exists

this.xflowDataNode = new DataNode(false);
this.xflowDataNode.addLoadListener(this.onXflowLoadEvent.bind(this));
this.xflowDataNode.userData = this.node;
this.xflowDataNode.systemDataAdapter = true;
this.setDefaultValues();

var systemDataNodeURI = this.node.getAttribute("sys");
if (systemDataNodeURI){
var systemDataNodeHandler = this.getAdapterHandle(systemDataNodeURI);
//TODO(RF) : Should I add the whole data node or should iterate over the children in user defined node and add the children?
this.xflowDataNode.appendChild(systemDataNodeHandler.adapter.xflowDataNode._children[0]);
}

};

XML3DDataAdapter.prototype.setDefaultValues = function(){
var inputNode = new InputNode();
inputNode.name="_system_time";
inputNode.name="time";
inputNode.data = new BufferEntry(XC.DATA_TYPE.FLOAT, new Float32Array([0.0]));
this.xflowDataNode.appendChild(inputNode);

inputNode = new InputNode();
inputNode.name="_system_test";
inputNode.name="test";
inputNode.data = new BufferEntry(XC.DATA_TYPE.FLOAT, new Float32Array([5.0]));
this.xflowDataNode.appendChild(inputNode);
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/renderer/scene/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ XML3D.createClass(Scene, EventEmitter, {

setRendererIndependentData: function () {
//Set the time
this.systemDataAdapter.xflowDataNode.getChildByName("_system_time").data.setValue(new Float32Array([performance.now()]));
this.systemDataAdapter.xflowDataNode.getChildByName("_system_test").data.setValue(new Float32Array([10.0]));
this.systemDataAdapter.xflowDataNode.getChildByName("time").data.setValue(new Float32Array([performance.now()]));
this.systemDataAdapter.xflowDataNode.getChildByName("test").data.setValue(new Float32Array([10.0]));

}
});
Expand Down
5 changes: 2 additions & 3 deletions src/xflow/interface/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,7 @@ DataNode.prototype.removeChild = function(child){
* @param {InputNodeI|dataNode} child
*/
DataNode.prototype.getChildByName = function(name){
// TODO(ksons): Do not use for(i in obj) for arrays
for (var i in this._children){
for (var i=0; i<this._children.length; i++){
if (this._children[i].name == name)
return this._children[i];
}
Expand All @@ -528,7 +527,7 @@ DataNode.prototype.getChildByName = function(name){
* @param {dataNode} child
*/
DataNode.prototype.hasSystemDataNode = function(){
for (var i in this._children){
for (var i=0; i< this._children.length; i++){
if (this._children[i].systemDataAdapter != undefined)
return this._children[i];
}
Expand Down

0 comments on commit 87eac4e

Please sign in to comment.