From 7ed7e896e184a1cdec6bf7585a017d41b1dbd6a3 Mon Sep 17 00:00:00 2001 From: Ian Scott Date: Tue, 20 Jan 2015 15:50:40 -0800 Subject: [PATCH 1/2] Handle cases where depths appear multiple times --- lib/handshake.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/handshake.js b/lib/handshake.js index 254837b..1abb9a4 100644 --- a/lib/handshake.js +++ b/lib/handshake.js @@ -46,7 +46,14 @@ function readDepths(bl, display, depths, n_depths, cb) var visuals = {}; readVisuals(bl, visuals, n_visuals, function() { - depths[dep] = visuals; + if (dep in depths) { + for (var visual in visuals) { + depths[dep][visual] = visuals[visual]; + } + n_depths--; + } else { + depths[dep] = visuals; + } if (Object.keys(depths).length == n_depths) cb(); else From bbaf2a8654d0170694ffb32922e241a9a081342b Mon Sep 17 00:00:00 2001 From: Ian Scott Date: Wed, 21 Jan 2015 11:04:10 -0800 Subject: [PATCH 2/2] Refactor to keep number of parsed depths in a counter --- lib/handshake.js | 61 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/lib/handshake.js b/lib/handshake.js index 1abb9a4..8f9c1c9 100644 --- a/lib/handshake.js +++ b/lib/handshake.js @@ -32,38 +32,39 @@ function readVisuals(bl, visuals, n_visuals, cb) }); } -function readDepths(bl, display, depths, n_depths, cb) -{ - if (n_depths == 0) - { - cb(); - return; - } - - bl.unpack( 'CxSxxxx', function(res) { - var dep = res[0]; - var n_visuals = res[1]; - var visuals = {}; - readVisuals(bl, visuals, n_visuals, function() - { - if (dep in depths) { - for (var visual in visuals) { - depths[dep][visual] = visuals[visual]; - } - n_depths--; - } else { - depths[dep] = visuals; - } - if (Object.keys(depths).length == n_depths) - cb(); - else - readDepths(bl, display, depths, n_depths, cb); - }); - }); -} - function readScreens(bl, display, cbDisplayReady) { + var numParsedDepths = 0; + var readDepths = function(bl, display, depths, n_depths, cb) + { + if (n_depths == 0) + { + cb(); + return; + } + + bl.unpack( 'CxSxxxx', function(res) { + var dep = res[0]; + var n_visuals = res[1]; + var visuals = {}; + readVisuals(bl, visuals, n_visuals, function() + { + if (dep in depths) { + for (var visual in visuals) { + depths[dep][visual] = visuals[visual]; + } + } else { + depths[dep] = visuals; + } + numParsedDepths++; + if (numParsedDepths == n_depths) + cb(); + else + readDepths(bl, display, depths, n_depths, cb); + }); + }); + } + // for (i=0; i < display.screen_num; ++i) { var scr = {};