Commit aa5afd18 authored by Neil Fraser's avatar Neil Fraser

Improve rendering speed.

parent 3e893da2
This diff is collapsed.
...@@ -512,6 +512,17 @@ Blockly.Block.prototype.setEditable = function(editable) { ...@@ -512,6 +512,17 @@ Blockly.Block.prototype.setEditable = function(editable) {
} }
}; };
/**
* Set whether the connections are hidden (not tracked in a database) or not.
* @param {boolean} hidden True if connections are hidden.
*/
Blockly.Block.prototype.setConnectionsHidden = function(hidden) {
var myConnections = this.getConnections_(true);
for (var i = 0, connection; connection = myConnections[i]; i++) {
connection.setHidden(hidden);
}
};
/** /**
* Set the URL of this block's help page. * Set the URL of this block's help page.
* @param {string|Function} url URL string for block help, or function that * @param {string|Function} url URL string for block help, or function that
......
...@@ -40,9 +40,10 @@ Blockly.Connection = function(source, type) { ...@@ -40,9 +40,10 @@ Blockly.Connection = function(source, type) {
this.type = type; this.type = type;
this.x_ = 0; this.x_ = 0;
this.y_ = 0; this.y_ = 0;
this.inDB_ = false;
// Shortcut for the databases for this connection's workspace. // Shortcut for the databases for this connection's workspace.
this.dbList_ = this.sourceBlock_.workspace.connectionDBList; this.dbList_ = source.workspace.connectionDBList;
this.hidden_ = !this.dbList_;
this.inDB_ = false;
}; };
/** /**
...@@ -54,7 +55,6 @@ Blockly.Connection.prototype.dispose = function() { ...@@ -54,7 +55,6 @@ Blockly.Connection.prototype.dispose = function() {
} }
if (this.inDB_) { if (this.inDB_) {
this.dbList_[this.type].removeConnection_(this); this.dbList_[this.type].removeConnection_(this);
this.inDB_ = false;
} }
if (Blockly.highlightedConnection_ == this) { if (Blockly.highlightedConnection_ == this) {
Blockly.highlightedConnection_ = null; Blockly.highlightedConnection_ = null;
...@@ -322,7 +322,7 @@ Blockly.Connection.prototype.moveTo = function(x, y) { ...@@ -322,7 +322,7 @@ Blockly.Connection.prototype.moveTo = function(x, y) {
this.x_ = x; this.x_ = x;
this.y_ = y; this.y_ = y;
// Insert it into its new location in the database. // Insert it into its new location in the database.
if (this.dbList_) { if (!this.hidden_) {
this.dbList_[this.type].addConnection_(this); this.dbList_[this.type].addConnection_(this);
} }
}; };
...@@ -336,6 +336,19 @@ Blockly.Connection.prototype.moveBy = function(dx, dy) { ...@@ -336,6 +336,19 @@ Blockly.Connection.prototype.moveBy = function(dx, dy) {
this.moveTo(this.x_ + dx, this.y_ + dy); this.moveTo(this.x_ + dx, this.y_ + dy);
}; };
/**
* Set whether this connections is hidden (not tracked in a database) or not.
* @param {boolean} hidden True if connection is hidden.
*/
Blockly.Connection.prototype.setHidden = function(hidden) {
this.hidden_ = hidden;
if (hidden && this.inDB_) {
this.dbList_[this.type].removeConnection_(this);
} else if (!hidden && !this.inDB_) {
this.dbList_[this.type].addConnection_(this);
}
};
/** /**
* Add highlighting around this connection. * Add highlighting around this connection.
*/ */
...@@ -653,7 +666,7 @@ Blockly.Connection.prototype.hideAll = function() { ...@@ -653,7 +666,7 @@ Blockly.Connection.prototype.hideAll = function() {
* @return {!Array.<!Blockly.Block>} List of blocks to render. * @return {!Array.<!Blockly.Block>} List of blocks to render.
*/ */
Blockly.Connection.prototype.unhideAll = function() { Blockly.Connection.prototype.unhideAll = function() {
if (!this.inDB_) { if (!this.hidden_) {
this.dbList_[this.type].addConnection_(this); this.dbList_[this.type].addConnection_(this);
} }
// All blocks that need unhiding must be unhidden before any rendering takes // All blocks that need unhiding must be unhidden before any rendering takes
......
...@@ -248,11 +248,15 @@ Blockly.Xml.domToBlock = function(workspace, xmlBlock, opt_reuseBlock) { ...@@ -248,11 +248,15 @@ Blockly.Xml.domToBlock = function(workspace, xmlBlock, opt_reuseBlock) {
var blocks = topBlock.getDescendants(); var blocks = topBlock.getDescendants();
// Render each block. // Render each block.
for (var i = blocks.length - 1; i >= 0; i--) { for (var i = blocks.length - 1; i >= 0; i--) {
blocks[i].setConnectionsHidden(true);
blocks[i].initSvg(); blocks[i].initSvg();
} }
for (var i = blocks.length - 1; i >= 0; i--) { for (var i = blocks.length - 1; i >= 0; i--) {
blocks[i].render(false); blocks[i].render(false);
} }
for (var i = blocks.length - 1; i >= 0; i--) {
blocks[i].setConnectionsHidden(false);
}
topBlock.updateDisabled(); topBlock.updateDisabled();
// Fire an event to allow scrollbars to resize. // Fire an event to allow scrollbars to resize.
Blockly.fireUiEvent(window, 'resize'); Blockly.fireUiEvent(window, 'resize');
......
...@@ -439,7 +439,7 @@ h1 { ...@@ -439,7 +439,7 @@ h1 {
<p> <p>
Stress test: Stress test:
<input type="button" value="Airstrike!" onclick="airstrike(100)"> <input type="button" value="Airstrike!" onclick="airstrike(100)">
<input type="button" value="Spaghetti!" onclick="spaghetti(6)"> <input type="button" value="Spaghetti!" onclick="spaghetti(8)">
</p> </p>
<!-- Realtime setup buttons. --> <!-- Realtime setup buttons. -->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment