mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Reworked LevelView loading priorities to try to get world simulating earlier.
This commit is contained in:
parent
eacbf571c6
commit
d54149d0f3
9 changed files with 50 additions and 41 deletions
|
@ -2,7 +2,7 @@ var window = self;
|
|||
var Global = self;
|
||||
|
||||
importScripts("/javascripts/tome_aether.js");
|
||||
console.log("imported scripts!");
|
||||
console.log("Aether Tome worker has finished importing scripts.");
|
||||
var aethers = {};
|
||||
|
||||
var createAether = function (spellKey, options)
|
||||
|
@ -96,4 +96,4 @@ self.addEventListener('message', function(e) {
|
|||
var returnObject = {"message":message, "function":"none"};
|
||||
self.postMessage(JSON.stringify(returnObject));
|
||||
}
|
||||
}, false);
|
||||
}, false);
|
||||
|
|
|
@ -17,11 +17,11 @@ module.exports = class God
|
|||
@id = God.nextID()
|
||||
options ?= {}
|
||||
@maxAngels = options.maxAngels ? 2 # How many concurrent web workers to use; if set past 8, make up more names
|
||||
@maxWorkerPoolSize = options.maxWorkerPoolSize ? 2 # ~20MB per idle worker
|
||||
@maxWorkerPoolSize = options.maxWorkerPoolSize ? 1 # ~20MB per idle worker
|
||||
@angels = []
|
||||
@firstWorld = true
|
||||
Backbone.Mediator.subscribe 'tome:cast-spells', @onTomeCast, @
|
||||
@fillWorkerPool = _.throttle @fillWorkerPool, 3000, leading: false
|
||||
@fillWorkerPool = _.throttle @fillWorkerPool, 3000
|
||||
@fillWorkerPool()
|
||||
|
||||
onTomeCast: (e) ->
|
||||
|
@ -87,7 +87,7 @@ module.exports = class God
|
|||
Backbone.Mediator.publish 'god:user-code-problem', problem: problem
|
||||
|
||||
createWorld: ->
|
||||
#console.log @id + ': "Let there be light upon', @world.name + '!"'
|
||||
console.log @id + ': "Let there be light upon', @level.name + '!"'
|
||||
unless Worker? # profiling world simulation is easier on main thread, or we are IE9
|
||||
setTimeout @simulateWorld, 1
|
||||
return
|
||||
|
@ -98,7 +98,6 @@ module.exports = class God
|
|||
else
|
||||
@worldWaiting = true
|
||||
return
|
||||
#console.log "going to run world with code", @getUserCodeMap()
|
||||
angel.worker.postMessage {func: 'runWorld', args: {
|
||||
worldName: @level.name
|
||||
userCodeMap: @getUserCodeMap()
|
||||
|
|
|
@ -110,7 +110,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@thangIDs = _.uniq thangIDs
|
||||
thangNames = new ThangNamesCollection(@thangIDs)
|
||||
worldNecessities.push @supermodel.loadCollection(thangNames, 'thang_names')
|
||||
|
||||
|
||||
for obj in objUniq componentVersions
|
||||
url = "/db/level.component/#{obj.original}/version/#{obj.majorVersion}"
|
||||
worldNecessities.push @maybeLoadURL(url, LevelComponent, 'component')
|
||||
|
@ -127,7 +127,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
unless @headless and not @editorMode
|
||||
wizard = ThangType.loadUniversalWizard()
|
||||
@supermodel.loadModel wizard, 'thang'
|
||||
|
||||
|
||||
jqxhrs = (resource.jqxhr for resource in worldNecessities when resource?.jqxhr)
|
||||
$.when(jqxhrs...).done(@onWorldNecessitiesLoaded)
|
||||
|
||||
|
@ -210,6 +210,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@world = new World @level.get('name')
|
||||
serializedLevel = @level.serialize(@supermodel)
|
||||
@world.loadFromLevel serializedLevel, false
|
||||
console.log "World has been initialized from level loader."
|
||||
|
||||
# Initial Sound Loading
|
||||
|
||||
|
|
|
@ -685,6 +685,7 @@
|
|||
user_schema: "User Schema"
|
||||
user_profile: "User Profile"
|
||||
patches: "Patches"
|
||||
patched_model: "Source Document"
|
||||
model: "Model"
|
||||
system: "System"
|
||||
component: "Component"
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
.patches-view
|
||||
.status-buttons
|
||||
margin-bottom: 10px
|
||||
|
||||
.patch-icon
|
||||
cursor: pointer
|
||||
|
|
|
@ -8,7 +8,7 @@ module.exports = class PatchModal extends ModalView
|
|||
template: template
|
||||
plain: true
|
||||
modalWidthPercent: 60
|
||||
|
||||
|
||||
events:
|
||||
'click #withdraw-button': 'withdrawPatch'
|
||||
'click #reject-button': 'rejectPatch'
|
||||
|
@ -24,8 +24,8 @@ module.exports = class PatchModal extends ModalView
|
|||
@originalSource = new targetModel.constructor({_id:targetID})
|
||||
@originalSource.fetch()
|
||||
@listenToOnce @originalSource, 'sync', @onOriginalLoaded
|
||||
@addResourceToLoad(@originalSource)
|
||||
|
||||
@supermodel.addModelResource @originalSource, 'patched_model' # TODO: Doesn't work?
|
||||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
c.isPatchCreator = @patch.get('creator') is auth.me.id
|
||||
|
@ -33,14 +33,14 @@ module.exports = class PatchModal extends ModalView
|
|||
c.status = @patch.get 'status'
|
||||
c.patch = @patch
|
||||
c
|
||||
|
||||
|
||||
afterRender: ->
|
||||
return if @originalSource.loading
|
||||
headModel = null
|
||||
if @targetModel.hasWriteAccess()
|
||||
headModel = @originalSource.clone(false)
|
||||
headModel.set(@targetModel.attributes)
|
||||
|
||||
|
||||
pendingModel = @originalSource.clone(false)
|
||||
pendingModel.applyDelta(@patch.get('delta'))
|
||||
|
||||
|
@ -48,18 +48,18 @@ module.exports = class PatchModal extends ModalView
|
|||
changeEl = @$el.find('.changes-stub')
|
||||
@insertSubView(@deltaView, changeEl)
|
||||
super()
|
||||
|
||||
|
||||
acceptPatch: ->
|
||||
delta = @deltaView.getApplicableDelta()
|
||||
@targetModel.applyDelta(delta)
|
||||
@patch.setStatus('accepted')
|
||||
@trigger 'accepted-patch'
|
||||
@hide()
|
||||
|
||||
|
||||
rejectPatch: ->
|
||||
@patch.setStatus('rejected')
|
||||
@hide()
|
||||
|
||||
|
||||
withdrawPatch: ->
|
||||
@patch.setStatus('withdrawn')
|
||||
@hide()
|
||||
@hide()
|
||||
|
|
|
@ -8,7 +8,7 @@ module.exports = class PatchesView extends CocoView
|
|||
template: template
|
||||
className: 'patches-view'
|
||||
status: 'pending'
|
||||
|
||||
|
||||
events:
|
||||
'change .status-buttons': 'onStatusButtonsChanged'
|
||||
'click .patch-icon': 'openPatchModal'
|
||||
|
@ -16,17 +16,16 @@ module.exports = class PatchesView extends CocoView
|
|||
constructor: (@model, options) ->
|
||||
super(options)
|
||||
@initPatches()
|
||||
|
||||
|
||||
initPatches: ->
|
||||
@startedLoading = false
|
||||
@patches = new PatchesCollection([], {}, @model, @status)
|
||||
|
||||
|
||||
load: ->
|
||||
console.log 'load patches view?'
|
||||
@initPatches()
|
||||
@patches = @supermodel.loadCollection(@patches, 'patches').model
|
||||
@listenTo @patches, 'sync', @onPatchesLoaded
|
||||
|
||||
|
||||
onPatchesLoaded: ->
|
||||
ids = (p.get('creator') for p in @patches.models)
|
||||
jqxhrOptions = nameLoader.loadNames ids
|
||||
|
@ -38,19 +37,20 @@ module.exports = class PatchesView extends CocoView
|
|||
c.patches = @patches.models
|
||||
c.status
|
||||
c
|
||||
|
||||
|
||||
afterRender: ->
|
||||
@$el.find(".#{@status}").addClass 'active'
|
||||
|
||||
onStatusButtonsChanged: (e) ->
|
||||
@status = $(e.target).val()
|
||||
@reloadPatches()
|
||||
|
||||
|
||||
reloadPatches: ->
|
||||
@load()
|
||||
@render()
|
||||
|
||||
openPatchModal: (e) ->
|
||||
console.log "open patch modal"
|
||||
patch = _.find @patches.models, {id:$(e.target).data('patch-id')}
|
||||
modal = new PatchModal(patch, @model)
|
||||
@openModalView(modal)
|
||||
|
|
|
@ -64,7 +64,7 @@ module.exports = class SpellView extends View
|
|||
@createFirepad()
|
||||
else
|
||||
# needs to happen after the code generating this view is complete
|
||||
setTimeout @onAllLoaded, 1
|
||||
_.defer @onAllLoaded
|
||||
|
||||
createACE: ->
|
||||
# Test themes and settings here: http://ace.ajax.org/build/kitchen-sink.html
|
||||
|
|
|
@ -110,8 +110,8 @@ module.exports = class PlayLevelView extends View
|
|||
|
||||
load: ->
|
||||
@loadStartTime = new Date()
|
||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, sessionID: @sessionID, opponentSessionID: @getQueryVariable('opponent'), team: @getQueryVariable("team")
|
||||
@god = new God()
|
||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, sessionID: @sessionID, opponentSessionID: @getQueryVariable('opponent'), team: @getQueryVariable("team")
|
||||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
|
@ -131,6 +131,9 @@ module.exports = class PlayLevelView extends View
|
|||
|
||||
updateProgress: (progress) ->
|
||||
super(progress)
|
||||
if not @worldInitialized and @levelLoader.session.loaded and @levelLoader.level.loaded and @levelLoader.world and (not @levelLoader.opponentSession or @levelLoader.opponentSession.loaded)
|
||||
@grabLevelLoaderData()
|
||||
@onWorldInitialized()
|
||||
return if @seenDocs
|
||||
return unless @levelLoader.session.loaded and @levelLoader.level.loaded
|
||||
return unless showFrequency = @levelLoader.level.get('showsGuide')
|
||||
|
@ -142,6 +145,21 @@ module.exports = class PlayLevelView extends View
|
|||
return unless article.loaded
|
||||
@showGuide()
|
||||
|
||||
onWorldInitialized: ->
|
||||
@worldInitialized = true
|
||||
team = @getQueryVariable("team") ? @world.teamForPlayer(0)
|
||||
@loadOpponentTeam(team)
|
||||
@god.level = @level.serialize @supermodel
|
||||
@god.worldClassMap = @world.classMap
|
||||
@setTeam team
|
||||
@initGoalManager()
|
||||
@insertSubviews ladderGame: (@level.get('type') is "ladder")
|
||||
@initVolume()
|
||||
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
|
||||
@originalSessionState = $.extend(true, {}, @session.get('state'))
|
||||
@register()
|
||||
@controlBar.setBus(@bus)
|
||||
|
||||
showGuide: ->
|
||||
@seenDocs = true
|
||||
DocsModal = require './level/modal/docs_modal'
|
||||
|
@ -163,21 +181,10 @@ module.exports = class PlayLevelView extends View
|
|||
if not (@levelLoader.level.get('type') in ['ladder', 'ladder-tutorial'])
|
||||
me.set('lastLevel', @levelID)
|
||||
me.save()
|
||||
@grabLevelLoaderData()
|
||||
team = @getQueryVariable("team") ? @world.teamForPlayer(0)
|
||||
@loadOpponentTeam(team)
|
||||
@god.level = @level.serialize @supermodel
|
||||
@god.worldClassMap = @world.classMap
|
||||
@setTeam team
|
||||
@levelLoader.destroy()
|
||||
@levelLoader = null
|
||||
@initSurface()
|
||||
@initGoalManager()
|
||||
@initScriptManager()
|
||||
@insertSubviews ladderGame: (@level.get('type') is "ladder")
|
||||
@initVolume()
|
||||
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
|
||||
@originalSessionState = $.extend(true, {}, @session.get('state'))
|
||||
@register()
|
||||
@controlBar.setBus(@bus)
|
||||
@surface.showLevel()
|
||||
if @otherSession
|
||||
# TODO: colorize name and cloud by team, colorize wizard by user's color config
|
||||
|
@ -188,8 +195,6 @@ module.exports = class PlayLevelView extends View
|
|||
@world = @levelLoader.world
|
||||
@level = @levelLoader.level
|
||||
@otherSession = @levelLoader.opponentSession
|
||||
@levelLoader.destroy()
|
||||
@levelLoader = null
|
||||
|
||||
loadOpponentTeam: (myTeam) ->
|
||||
opponentSpells = []
|
||||
|
|
Loading…
Reference in a new issue