Merge branch 'master' into production

This commit is contained in:
Nick Winter 2014-05-20 08:01:08 -07:00
commit f93753b4bc
6 changed files with 31 additions and 18 deletions

View file

@ -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'});

View file

@ -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) ->

View file

@ -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()

View file

@ -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

View file

@ -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')

View file

@ -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)