From b7a2c29aa076bd140b24c3f9a7d98fff38c4ecd6 Mon Sep 17 00:00:00 2001 From: Travis Weston Date: Sat, 12 Jul 2014 20:09:36 -0400 Subject: [PATCH] Fixed a memory usage issue when using system over long periods or with large numbers of notifications. Now, notifications that fall outside the notification gradient are automatically removed --- script/notifications.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/script/notifications.js b/script/notifications.js index db56f02..4ee2c4c 100644 --- a/script/notifications.js +++ b/script/notifications.js @@ -43,9 +43,29 @@ var Notifications = { Engine.saveGame(); }, + clearHidden: function() { + + // To fix some memory usage issues, we clear notifications that have been hidden. + + // We use position().top here, because we know that the parent will be the same, so the position will be the same. + var bottom = $('#notifyGradient').position().top + $('#notifyGradient').outerHeight(true); + + $('.notification').each(function() { + + if($(this).position().top > bottom){ + $(this).remove(); + } + + }); + + }, + printMessage: function(t) { var text = $('
').addClass('notification').css('opacity', '0').text(t).prependTo('div#notifications'); - text.animate({opacity: 1}, 500, 'linear'); + text.animate({opacity: 1}, 500, 'linear', function() { + // Do this every time we add a new message, this way we never have a large backlog to iterate through. Keeps things faster. + Notifications.clearHidden(); + }); }, printQueue: function(module) { @@ -55,4 +75,4 @@ var Notifications = { } } } -}; \ No newline at end of file +};