diff --git a/app/assets/javascripts/workers/worker_world.js b/app/assets/javascripts/workers/worker_world.js index 7547c282a..3da92969c 100644 --- a/app/assets/javascripts/workers/worker_world.js +++ b/app/assets/javascripts/workers/worker_world.js @@ -378,6 +378,7 @@ self.onWorldLoaded = function onWorldLoaded() { } var t3 = new Date(); console.log("And it was so: (" + (diff / self.world.totalFrames).toFixed(3) + "ms per frame,", self.world.totalFrames, "frames)\nSimulation :", diff + "ms \nSerialization:", (t2 - t1) + "ms\nDelivery :", (t3 - t2) + "ms"); + self.world.goalManager.destroy(); self.world = null; }; @@ -408,6 +409,7 @@ self.onWorldLoadProgress = function onWorldLoadProgress(progress) { self.abort = function abort() { if(self.world) { self.world.abort(); + self.world.goalManager.destroy(); self.world = null; } self.postMessage({type: 'abort'}); diff --git a/app/lib/God.coffee b/app/lib/God.coffee index e88e96024..622552e1b 100644 --- a/app/lib/God.coffee +++ b/app/lib/God.coffee @@ -47,7 +47,9 @@ module.exports = class God extends CocoClass setLevel: (@level) -> setLevelSessionIDs: (@levelSessionIDs) -> - setGoalManager: (goalManager) -> @angelsShare.goalManager = goalManager + setGoalManager: (goalManager) -> + @angelsShare.goalManager?.destroy() unless @angelsShare.goalManager is goalManager + @angelsShare.goalManager = goalManager setWorldClassMap: (worldClassMap) -> @angelsShare.worldClassMap = worldClassMap onTomeCast: (e) -> diff --git a/app/lib/simulator/Simulator.coffee b/app/lib/simulator/Simulator.coffee index 81df8013a..d0606fa1d 100644 --- a/app/lib/simulator/Simulator.coffee +++ b/app/lib/simulator/Simulator.coffee @@ -23,7 +23,7 @@ module.exports = class Simulator extends CocoClass @cleanupSimulation() @god?.destroy() super() - + fetchAndSimulateOneGame: (humanGameID, ogresGameID) => return if @destroyed $.ajax @@ -36,18 +36,20 @@ module.exports = class Simulator extends CocoClass error: (errorData) -> console.log "There was an error fetching two games! #{JSON.stringify errorData}" success: (taskData) => + return if @destroyed @trigger 'statusUpdate', 'Setting up simulation...' #refactor this @task = new SimulationTask(taskData) - + @supermodel ?= new SuperModel() @supermodel.resetProgress() @levelLoader = new LevelLoader supermodel: @supermodel, levelID: @task.getLevelName(), sessionID: @task.getFirstSessionID(), headless: true - + if @supermodel.finished() @simulateSingleGame() else @listenToOnce @supermodel, 'loaded-all', @simulateSingleGame + simulateSingleGame: -> return if @destroyed @trigger 'statusUpdate', 'Simulating...' @@ -58,26 +60,26 @@ module.exports = class Simulator extends CocoClass catch err console.log err @handleSingleSimulationError() - + commenceSingleSimulation: -> @god.createWorld @generateSpellsObject() Backbone.Mediator.subscribeOnce 'god:infinite-loop', @handleSingleSimulationInfiniteLoop, @ Backbone.Mediator.subscribeOnce 'god:goals-calculated', @processSingleGameResults, @ - + handleSingleSimulationError: -> console.log "There was an error simulating a single game!" if @options.headlessClient console.log "GAMERESULT:tie" process.exit(0) @cleanupSimulation() - + handleSingleSimulationInfiniteLoop: -> console.log "There was an infinite loop in the single game!" if @options.headlessClient console.log "GAMERESULT:tie" process.exit(0) @cleanupSimulation() - + processSingleGameResults: (simulationResults) -> console.log "Processing results!" taskResults = @formTaskResultsObject simulationResults @@ -93,12 +95,12 @@ module.exports = class Simulator extends CocoClass process.exit(0) else @sendSingleGameBackToServer(taskResults) - + @cleanupSimulation() - + sendSingleGameBackToServer: (results) -> @trigger 'statusUpdate', 'Simulation completed, sending results back to server!' - + $.ajax url: "/queue/scoring/recordTwoGames" data: results @@ -107,8 +109,8 @@ module.exports = class Simulator extends CocoClass success: @handleTaskResultsTransferSuccess error: @handleTaskResultsTransferError complete: @cleanupAndSimulateAnotherTask - - + + fetchAndSimulateTask: => return if @destroyed @@ -134,7 +136,7 @@ module.exports = class Simulator extends CocoClass console.error "There was a horrible Error: #{JSON.stringify errorData}" @trigger 'statusUpdate', 'There was an error fetching games to simulate. Retrying in 10 seconds.' @simulateAnotherTaskAfterDelay() - + handleNoGamesResponse: -> info = 'Finding game to simulate...' @@ -191,7 +193,7 @@ module.exports = class Simulator extends CocoClass setupGod: -> @god.setLevel @level.serialize @supermodel - @god.setLevelSessionIDs (session.id for session in @task.getSessions()) + @god.setLevelSessionIDs (session.sessionID for session in @task.getSessions()) @god.setWorldClassMap @world.classMap @god.setGoalManager new GoalManager(@world, @level.get 'goals') @@ -250,6 +252,7 @@ module.exports = class Simulator extends CocoClass complete: @cleanupAndSimulateAnotherTask handleTaskResultsTransferSuccess: (result) => + return if @destroyed console.log "Task registration result: #{JSON.stringify result}" @trigger 'statusUpdate', 'Results were successfully sent back to server!' console.log "Simulated by you: " + @simulatedByYou @@ -260,10 +263,12 @@ module.exports = class Simulator extends CocoClass application.tracker?.trackEvent 'Simulator Result', label: "Success" handleTaskResultsTransferError: (error) => + return if @destroyed @trigger 'statusUpdate', 'There was an error sending the results back to the server.' console.log "Task registration error: #{JSON.stringify error}" cleanupAndSimulateAnotherTask: => + return if @destroyed @cleanupSimulation() @fetchAndSimulateTask() diff --git a/app/lib/surface/Mark.coffee b/app/lib/surface/Mark.coffee index 114fdc2eb..2b74ce95f 100644 --- a/app/lib/surface/Mark.coffee +++ b/app/lib/surface/Mark.coffee @@ -234,7 +234,7 @@ module.exports = class Mark extends CocoClass if @name is 'debug' or (@name is 'shadow' and @sprite.thang?.shape in ["rectangle", "box"]) @mark.rotation = @sprite.thang.rotation * 180 / Math.PI - updateScale: -> + updateScale: (log) -> if @name is 'bounds' and (@sprite.thang.width isnt @lastWidth or @sprite.thang.height isnt @lastHeight) oldMark = @mark @buildBounds() @@ -243,6 +243,7 @@ module.exports = class Mark extends CocoClass oldMark.parent.removeChild oldMark if @markSprite? + @markSprite.scaleFactor = 1.2 @markSprite.updateScale() return unless @name in ["selection", "target", "repair", "highlight"] if @sprite?.imageObject diff --git a/app/views/play/ladder/my_matches_tab.coffee b/app/views/play/ladder/my_matches_tab.coffee index 916ae3dfa..d700753e8 100644 --- a/app/views/play/ladder/my_matches_tab.coffee +++ b/app/views/play/ladder/my_matches_tab.coffee @@ -94,6 +94,7 @@ module.exports = class MyMatchesTabView extends CocoView afterRender: -> super() + @removeSubView subview for key, subview of @subviews when subview instanceof LadderSubmissionView @$el.find('.ladder-submission-view').each (i, el) => placeholder = $(el) sessionID = placeholder.data('session-id') diff --git a/app/views/play/level/thang_avatar_view.coffee b/app/views/play/level/thang_avatar_view.coffee index a1af2102b..88f4110d0 100644 --- a/app/views/play/level/thang_avatar_view.coffee +++ b/app/views/play/level/thang_avatar_view.coffee @@ -21,8 +21,10 @@ module.exports = class ThangAvatarView extends View unless @thangType.isFullyLoaded() or @thangType.loading @thangType.fetch() - - @supermodel.loadModel @thangType, 'thang' + + # couldn't get the level view to load properly through the supermodel + # so just doing it manually this time. + @listenTo @thangType, 'sync', @render getSpriteThangType: -> thangs = @supermodel.getModels(ThangType)