Reworked LevelView loading priorities to try to get world simulating earlier.

This commit is contained in:
Nick Winter 2014-05-02 12:32:41 -07:00
parent eacbf571c6
commit d54149d0f3
9 changed files with 50 additions and 41 deletions

View file

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

View file

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

View file

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

View file

@ -685,6 +685,7 @@
user_schema: "User Schema"
user_profile: "User Profile"
patches: "Patches"
patched_model: "Source Document"
model: "Model"
system: "System"
component: "Component"

View file

@ -1,3 +1,6 @@
.patches-view
.status-buttons
margin-bottom: 10px
.patch-icon
cursor: pointer

View file

@ -24,7 +24,7 @@ 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()

View file

@ -22,7 +22,6 @@ module.exports = class PatchesView extends CocoView
@patches = new PatchesCollection([], {}, @model, @status)
load: ->
console.log 'load patches view?'
@initPatches()
@patches = @supermodel.loadCollection(@patches, 'patches').model
@listenTo @patches, 'sync', @onPatchesLoaded
@ -51,6 +50,7 @@ module.exports = class PatchesView extends CocoView
@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)

View file

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

View file

@ -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 = []