mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-02 11:58:10 -05:00
Merge branch 'master' into production
This commit is contained in:
commit
f93753b4bc
6 changed files with 31 additions and 18 deletions
|
@ -378,6 +378,7 @@ self.onWorldLoaded = function onWorldLoaded() {
|
||||||
}
|
}
|
||||||
var t3 = new Date();
|
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");
|
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;
|
self.world = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -408,6 +409,7 @@ self.onWorldLoadProgress = function onWorldLoadProgress(progress) {
|
||||||
self.abort = function abort() {
|
self.abort = function abort() {
|
||||||
if(self.world) {
|
if(self.world) {
|
||||||
self.world.abort();
|
self.world.abort();
|
||||||
|
self.world.goalManager.destroy();
|
||||||
self.world = null;
|
self.world = null;
|
||||||
}
|
}
|
||||||
self.postMessage({type: 'abort'});
|
self.postMessage({type: 'abort'});
|
||||||
|
|
|
@ -47,7 +47,9 @@ module.exports = class God extends CocoClass
|
||||||
|
|
||||||
setLevel: (@level) ->
|
setLevel: (@level) ->
|
||||||
setLevelSessionIDs: (@levelSessionIDs) ->
|
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
|
setWorldClassMap: (worldClassMap) -> @angelsShare.worldClassMap = worldClassMap
|
||||||
|
|
||||||
onTomeCast: (e) ->
|
onTomeCast: (e) ->
|
||||||
|
|
|
@ -23,7 +23,7 @@ module.exports = class Simulator extends CocoClass
|
||||||
@cleanupSimulation()
|
@cleanupSimulation()
|
||||||
@god?.destroy()
|
@god?.destroy()
|
||||||
super()
|
super()
|
||||||
|
|
||||||
fetchAndSimulateOneGame: (humanGameID, ogresGameID) =>
|
fetchAndSimulateOneGame: (humanGameID, ogresGameID) =>
|
||||||
return if @destroyed
|
return if @destroyed
|
||||||
$.ajax
|
$.ajax
|
||||||
|
@ -36,18 +36,20 @@ module.exports = class Simulator extends CocoClass
|
||||||
error: (errorData) ->
|
error: (errorData) ->
|
||||||
console.log "There was an error fetching two games! #{JSON.stringify errorData}"
|
console.log "There was an error fetching two games! #{JSON.stringify errorData}"
|
||||||
success: (taskData) =>
|
success: (taskData) =>
|
||||||
|
return if @destroyed
|
||||||
@trigger 'statusUpdate', 'Setting up simulation...'
|
@trigger 'statusUpdate', 'Setting up simulation...'
|
||||||
#refactor this
|
#refactor this
|
||||||
@task = new SimulationTask(taskData)
|
@task = new SimulationTask(taskData)
|
||||||
|
|
||||||
@supermodel ?= new SuperModel()
|
@supermodel ?= new SuperModel()
|
||||||
@supermodel.resetProgress()
|
@supermodel.resetProgress()
|
||||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @task.getLevelName(), sessionID: @task.getFirstSessionID(), headless: true
|
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @task.getLevelName(), sessionID: @task.getFirstSessionID(), headless: true
|
||||||
|
|
||||||
if @supermodel.finished()
|
if @supermodel.finished()
|
||||||
@simulateSingleGame()
|
@simulateSingleGame()
|
||||||
else
|
else
|
||||||
@listenToOnce @supermodel, 'loaded-all', @simulateSingleGame
|
@listenToOnce @supermodel, 'loaded-all', @simulateSingleGame
|
||||||
|
|
||||||
simulateSingleGame: ->
|
simulateSingleGame: ->
|
||||||
return if @destroyed
|
return if @destroyed
|
||||||
@trigger 'statusUpdate', 'Simulating...'
|
@trigger 'statusUpdate', 'Simulating...'
|
||||||
|
@ -58,26 +60,26 @@ module.exports = class Simulator extends CocoClass
|
||||||
catch err
|
catch err
|
||||||
console.log err
|
console.log err
|
||||||
@handleSingleSimulationError()
|
@handleSingleSimulationError()
|
||||||
|
|
||||||
commenceSingleSimulation: ->
|
commenceSingleSimulation: ->
|
||||||
@god.createWorld @generateSpellsObject()
|
@god.createWorld @generateSpellsObject()
|
||||||
Backbone.Mediator.subscribeOnce 'god:infinite-loop', @handleSingleSimulationInfiniteLoop, @
|
Backbone.Mediator.subscribeOnce 'god:infinite-loop', @handleSingleSimulationInfiniteLoop, @
|
||||||
Backbone.Mediator.subscribeOnce 'god:goals-calculated', @processSingleGameResults, @
|
Backbone.Mediator.subscribeOnce 'god:goals-calculated', @processSingleGameResults, @
|
||||||
|
|
||||||
handleSingleSimulationError: ->
|
handleSingleSimulationError: ->
|
||||||
console.log "There was an error simulating a single game!"
|
console.log "There was an error simulating a single game!"
|
||||||
if @options.headlessClient
|
if @options.headlessClient
|
||||||
console.log "GAMERESULT:tie"
|
console.log "GAMERESULT:tie"
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
@cleanupSimulation()
|
@cleanupSimulation()
|
||||||
|
|
||||||
handleSingleSimulationInfiniteLoop: ->
|
handleSingleSimulationInfiniteLoop: ->
|
||||||
console.log "There was an infinite loop in the single game!"
|
console.log "There was an infinite loop in the single game!"
|
||||||
if @options.headlessClient
|
if @options.headlessClient
|
||||||
console.log "GAMERESULT:tie"
|
console.log "GAMERESULT:tie"
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
@cleanupSimulation()
|
@cleanupSimulation()
|
||||||
|
|
||||||
processSingleGameResults: (simulationResults) ->
|
processSingleGameResults: (simulationResults) ->
|
||||||
console.log "Processing results!"
|
console.log "Processing results!"
|
||||||
taskResults = @formTaskResultsObject simulationResults
|
taskResults = @formTaskResultsObject simulationResults
|
||||||
|
@ -93,12 +95,12 @@ module.exports = class Simulator extends CocoClass
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
else
|
else
|
||||||
@sendSingleGameBackToServer(taskResults)
|
@sendSingleGameBackToServer(taskResults)
|
||||||
|
|
||||||
@cleanupSimulation()
|
@cleanupSimulation()
|
||||||
|
|
||||||
sendSingleGameBackToServer: (results) ->
|
sendSingleGameBackToServer: (results) ->
|
||||||
@trigger 'statusUpdate', 'Simulation completed, sending results back to server!'
|
@trigger 'statusUpdate', 'Simulation completed, sending results back to server!'
|
||||||
|
|
||||||
$.ajax
|
$.ajax
|
||||||
url: "/queue/scoring/recordTwoGames"
|
url: "/queue/scoring/recordTwoGames"
|
||||||
data: results
|
data: results
|
||||||
|
@ -107,8 +109,8 @@ module.exports = class Simulator extends CocoClass
|
||||||
success: @handleTaskResultsTransferSuccess
|
success: @handleTaskResultsTransferSuccess
|
||||||
error: @handleTaskResultsTransferError
|
error: @handleTaskResultsTransferError
|
||||||
complete: @cleanupAndSimulateAnotherTask
|
complete: @cleanupAndSimulateAnotherTask
|
||||||
|
|
||||||
|
|
||||||
fetchAndSimulateTask: =>
|
fetchAndSimulateTask: =>
|
||||||
return if @destroyed
|
return if @destroyed
|
||||||
|
|
||||||
|
@ -134,7 +136,7 @@ module.exports = class Simulator extends CocoClass
|
||||||
console.error "There was a horrible Error: #{JSON.stringify errorData}"
|
console.error "There was a horrible Error: #{JSON.stringify errorData}"
|
||||||
@trigger 'statusUpdate', 'There was an error fetching games to simulate. Retrying in 10 seconds.'
|
@trigger 'statusUpdate', 'There was an error fetching games to simulate. Retrying in 10 seconds.'
|
||||||
@simulateAnotherTaskAfterDelay()
|
@simulateAnotherTaskAfterDelay()
|
||||||
|
|
||||||
|
|
||||||
handleNoGamesResponse: ->
|
handleNoGamesResponse: ->
|
||||||
info = 'Finding game to simulate...'
|
info = 'Finding game to simulate...'
|
||||||
|
@ -191,7 +193,7 @@ module.exports = class Simulator extends CocoClass
|
||||||
|
|
||||||
setupGod: ->
|
setupGod: ->
|
||||||
@god.setLevel @level.serialize @supermodel
|
@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.setWorldClassMap @world.classMap
|
||||||
@god.setGoalManager new GoalManager(@world, @level.get 'goals')
|
@god.setGoalManager new GoalManager(@world, @level.get 'goals')
|
||||||
|
|
||||||
|
@ -250,6 +252,7 @@ module.exports = class Simulator extends CocoClass
|
||||||
complete: @cleanupAndSimulateAnotherTask
|
complete: @cleanupAndSimulateAnotherTask
|
||||||
|
|
||||||
handleTaskResultsTransferSuccess: (result) =>
|
handleTaskResultsTransferSuccess: (result) =>
|
||||||
|
return if @destroyed
|
||||||
console.log "Task registration result: #{JSON.stringify result}"
|
console.log "Task registration result: #{JSON.stringify result}"
|
||||||
@trigger 'statusUpdate', 'Results were successfully sent back to server!'
|
@trigger 'statusUpdate', 'Results were successfully sent back to server!'
|
||||||
console.log "Simulated by you: " + @simulatedByYou
|
console.log "Simulated by you: " + @simulatedByYou
|
||||||
|
@ -260,10 +263,12 @@ module.exports = class Simulator extends CocoClass
|
||||||
application.tracker?.trackEvent 'Simulator Result', label: "Success"
|
application.tracker?.trackEvent 'Simulator Result', label: "Success"
|
||||||
|
|
||||||
handleTaskResultsTransferError: (error) =>
|
handleTaskResultsTransferError: (error) =>
|
||||||
|
return if @destroyed
|
||||||
@trigger 'statusUpdate', 'There was an error sending the results back to the server.'
|
@trigger 'statusUpdate', 'There was an error sending the results back to the server.'
|
||||||
console.log "Task registration error: #{JSON.stringify error}"
|
console.log "Task registration error: #{JSON.stringify error}"
|
||||||
|
|
||||||
cleanupAndSimulateAnotherTask: =>
|
cleanupAndSimulateAnotherTask: =>
|
||||||
|
return if @destroyed
|
||||||
@cleanupSimulation()
|
@cleanupSimulation()
|
||||||
@fetchAndSimulateTask()
|
@fetchAndSimulateTask()
|
||||||
|
|
||||||
|
|
|
@ -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"])
|
if @name is 'debug' or (@name is 'shadow' and @sprite.thang?.shape in ["rectangle", "box"])
|
||||||
@mark.rotation = @sprite.thang.rotation * 180 / Math.PI
|
@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)
|
if @name is 'bounds' and (@sprite.thang.width isnt @lastWidth or @sprite.thang.height isnt @lastHeight)
|
||||||
oldMark = @mark
|
oldMark = @mark
|
||||||
@buildBounds()
|
@buildBounds()
|
||||||
|
@ -243,6 +243,7 @@ module.exports = class Mark extends CocoClass
|
||||||
oldMark.parent.removeChild oldMark
|
oldMark.parent.removeChild oldMark
|
||||||
|
|
||||||
if @markSprite?
|
if @markSprite?
|
||||||
|
@markSprite.scaleFactor = 1.2
|
||||||
@markSprite.updateScale()
|
@markSprite.updateScale()
|
||||||
return unless @name in ["selection", "target", "repair", "highlight"]
|
return unless @name in ["selection", "target", "repair", "highlight"]
|
||||||
if @sprite?.imageObject
|
if @sprite?.imageObject
|
||||||
|
|
|
@ -94,6 +94,7 @@ module.exports = class MyMatchesTabView extends CocoView
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
super()
|
super()
|
||||||
|
@removeSubView subview for key, subview of @subviews when subview instanceof LadderSubmissionView
|
||||||
@$el.find('.ladder-submission-view').each (i, el) =>
|
@$el.find('.ladder-submission-view').each (i, el) =>
|
||||||
placeholder = $(el)
|
placeholder = $(el)
|
||||||
sessionID = placeholder.data('session-id')
|
sessionID = placeholder.data('session-id')
|
||||||
|
|
|
@ -21,8 +21,10 @@ module.exports = class ThangAvatarView extends View
|
||||||
|
|
||||||
unless @thangType.isFullyLoaded() or @thangType.loading
|
unless @thangType.isFullyLoaded() or @thangType.loading
|
||||||
@thangType.fetch()
|
@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: ->
|
getSpriteThangType: ->
|
||||||
thangs = @supermodel.getModels(ThangType)
|
thangs = @supermodel.getModels(ThangType)
|
||||||
|
|
Loading…
Reference in a new issue