More memory fixes.

This commit is contained in:
Scott Erickson 2014-02-11 14:24:06 -08:00
parent 1b0c3fb236
commit b904e1f939
7 changed files with 23 additions and 26 deletions

View file

@ -103,7 +103,7 @@ module.exports = class God
window.BOX2D_ENABLED = true window.BOX2D_ENABLED = true
@lastSerializedWorldFrames = serialized.frames @lastSerializedWorldFrames = serialized.frames
finishBeholdingWorld: (newWorld) => finishBeholdingWorld: (newWorld) ->
newWorld.findFirstChangedFrame @world newWorld.findFirstChangedFrame @world
@world = newWorld @world = newWorld
errorCount = (t for t in @world.thangs when t.errorsOut).length errorCount = (t for t in @world.thangs when t.errorsOut).length

View file

@ -182,7 +182,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
# STARTING NOTES # STARTING NOTES
run: => run: ->
# catch all for analyzing the current state and doing whatever needs to happen next # catch all for analyzing the current state and doing whatever needs to happen next
return if @scriptInProgress return if @scriptInProgress
@skipAhead() @skipAhead()

View file

@ -92,6 +92,10 @@ module.exports = Surface = class Surface extends CocoClass
@stage.removeEventListener 'stagemousemove', @onMouseMove @stage.removeEventListener 'stagemousemove', @onMouseMove
@stage.removeEventListener 'stagemousedown', @onMouseDown @stage.removeEventListener 'stagemousedown', @onMouseDown
@stage.removeAllEventListeners() @stage.removeAllEventListeners()
@playScrubbedSounds = null
@onMouseMove = null
@onMouseDown = null
@tick = null
setWorld: (@world) -> setWorld: (@world) ->
@worldLoaded = true @worldLoaded = true

View file

@ -11,7 +11,7 @@ makeScopeName = -> "view-scope-#{classCount++}"
module.exports = class CocoView extends Backbone.View module.exports = class CocoView extends Backbone.View
startsLoading: false startsLoading: false
cache: true # signals to the router to keep this view around cache: true # signals to the router to keep this view around
template: => '' template: -> ''
events: events:
'click a': 'toggleModal' 'click a': 'toggleModal'
@ -41,6 +41,7 @@ module.exports = class CocoView extends Backbone.View
@stopListeningToShortcuts() @stopListeningToShortcuts()
@undelegateEvents() # removes both events and subs @undelegateEvents() # removes both events and subs
view.destroy() for id, view of @subviews view.destroy() for id, view of @subviews
@modalClosed = null
afterInsert: -> afterInsert: ->
@ -60,7 +61,7 @@ module.exports = class CocoView extends Backbone.View
# View Rendering # View Rendering
render: => render: ->
return @ unless me return @ unless me
super() super()
return @template if _.isString(@template) return @template if _.isString(@template)
@ -70,7 +71,7 @@ module.exports = class CocoView extends Backbone.View
@$el.i18n() @$el.i18n()
@ @
getRenderData: (context) => getRenderData: (context) ->
context ?= {} context ?= {}
context.isProduction = document.location.href.search(/codecombat.com/) isnt -1 context.isProduction = document.location.href.search(/codecombat.com/) isnt -1
context.me = me context.me = me
@ -81,7 +82,6 @@ module.exports = class CocoView extends Backbone.View
context context
afterRender: -> afterRender: ->
@registerModalsWithin()
# Modals # Modals
@ -95,12 +95,6 @@ module.exports = class CocoView extends Backbone.View
view = application.router.getView(target, '_modal') # could set up a system for loading cached modals, if told to view = application.router.getView(target, '_modal') # could set up a system for loading cached modals, if told to
@openModalView(view) @openModalView(view)
registerModalsWithin: (e...) ->
# TODO: Get rid of this part
for modal in $('.modal', @$el)
# console.warn 'Registered modal to get rid of...', modal
$(modal).on('show.bs.modal', @clearModals)
openModalView: (modalView) -> openModalView: (modalView) ->
return if @waitingModal # can only have one waiting at once return if @waitingModal # can only have one waiting at once
if visibleModal if visibleModal
@ -112,11 +106,11 @@ module.exports = class CocoView extends Backbone.View
modalView.afterInsert() modalView.afterInsert()
visibleModal = modalView visibleModal = modalView
modalOptions = {show: true, backdrop: if modalView.closesOnClickOutside then true else 'static'} modalOptions = {show: true, backdrop: if modalView.closesOnClickOutside then true else 'static'}
$('#modal-wrapper .modal').modal(modalOptions).on('hidden.bs.modal', => @modalClosed()) $('#modal-wrapper .modal').modal(modalOptions).on('hidden.bs.modal', @modalClosed)
window.currentModal = modalView window.currentModal = modalView
@getRootView().stopListeningToShortcuts(true) @getRootView().stopListeningToShortcuts(true)
modalClosed: => modalClosed: =>
visibleModal.willDisappear() if visibleModal visibleModal.willDisappear() if visibleModal
visibleModal.destroy() visibleModal.destroy()
visibleModal = null visibleModal = null
@ -128,12 +122,6 @@ module.exports = class CocoView extends Backbone.View
@getRootView().listenToShortcuts(true) @getRootView().listenToShortcuts(true)
Backbone.Mediator.publish 'modal-closed' Backbone.Mediator.publish 'modal-closed'
clearModals: =>
if visibleModal
visibleModal.$el.addClass('hide')
waitingModal = null
@modalClosed()
# Loading RootViews # Loading RootViews
showLoading: ($el=@$el) -> showLoading: ($el=@$el) ->

View file

@ -45,7 +45,7 @@ module.exports = class ControlBarView extends View
text += " (#{numPlayers})" if numPlayers > 1 text += " (#{numPlayers})" if numPlayers > 1
$('#multiplayer-button', @$el).text(text) $('#multiplayer-button', @$el).text(text)
getRenderData: (context={}) => getRenderData: (context={}) ->
super context super context
context.worldName = @worldName context.worldName = @worldName
context.multiplayerEnabled = @session.get('multiplayer') context.multiplayerEnabled = @session.get('multiplayer')

View file

@ -43,7 +43,7 @@ module.exports = class PlaybackView extends View
super(arguments...) super(arguments...)
me.on('change:music', @updateMusicButton, @) me.on('change:music', @updateMusicButton, @)
afterRender: => afterRender: ->
super() super()
@hookUpScrubber() @hookUpScrubber()
@updateMusicButton() @updateMusicButton()
@ -62,7 +62,7 @@ module.exports = class PlaybackView extends View
onWindowResize: (s...) => onWindowResize: (s...) =>
@barWidth = $('.progress', @$el).width() @barWidth = $('.progress', @$el).width()
onNewWorld: (e) => onNewWorld: (e) ->
pct = parseInt(100 * e.world.totalFrames / e.world.maxTotalFrames) + '%' pct = parseInt(100 * e.world.totalFrames / e.world.maxTotalFrames) + '%'
@barWidth = $('.progress', @$el).css('width', pct).removeClass('hide').width() @barWidth = $('.progress', @$el).css('width', pct).removeClass('hide').width()
@ -79,7 +79,7 @@ module.exports = class PlaybackView extends View
onEditWizardSettings: -> onEditWizardSettings: ->
Backbone.Mediator.publish 'edit-wizard-settings' Backbone.Mediator.publish 'edit-wizard-settings'
onDisableControls: (e) => onDisableControls: (e) ->
if not e.controls or 'playback' in e.controls if not e.controls or 'playback' in e.controls
@disabled = true @disabled = true
$('button', @$el).addClass('disabled') $('button', @$el).addClass('disabled')
@ -91,7 +91,7 @@ module.exports = class PlaybackView extends View
@hoverDisabled = true @hoverDisabled = true
$('#volume-button', @$el).removeClass('disabled') $('#volume-button', @$el).removeClass('disabled')
onEnableControls: (e) => onEnableControls: (e) ->
if not e.controls or 'playback' in e.controls if not e.controls or 'playback' in e.controls
@disabled = false @disabled = false
$('button', @$el).removeClass('disabled') $('button', @$el).removeClass('disabled')
@ -102,7 +102,7 @@ module.exports = class PlaybackView extends View
if not e.controls or 'playback-hover' in e.controls if not e.controls or 'playback-hover' in e.controls
@hoverDisabled = false @hoverDisabled = false
onSetPlaying: (e) => onSetPlaying: (e) ->
@playing = (e ? {}).playing ? true @playing = (e ? {}).playing ? true
button = @$el.find '#play-button' button = @$el.find '#play-button'
ended = button.hasClass 'ended' ended = button.hasClass 'ended'
@ -241,3 +241,7 @@ module.exports = class PlaybackView extends View
super() super()
me.off('change:music', @updateMusicButton, @) me.off('change:music', @updateMusicButton, @)
$(window).off('resize', @onWindowResize) $(window).off('resize', @onWindowResize)
@onWindowResize = null
@onProgressMouseOver = null
@onProgressMouseLeave = null
@onProgressMouseMove = null

View file

@ -385,6 +385,7 @@ module.exports = class PlayLevelView extends View
@goalManager?.destroy() @goalManager?.destroy()
@scriptManager?.destroy() @scriptManager?.destroy()
$(window).off('resize', @onWindowResize) $(window).off('resize', @onWindowResize)
delete window.world # not sure where this is set, but this is one way to clean it up
clearInterval(@pointerInterval) clearInterval(@pointerInterval)
@bus?.destroy() @bus?.destroy()