mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Finished tuning the supermodel loading and progress.
This commit is contained in:
parent
b4ad34eb8f
commit
4b404ae124
5 changed files with 33 additions and 9 deletions
|
@ -137,12 +137,18 @@ module.exports = class LevelLoader extends CocoClass
|
|||
thangsToLoad = _.uniq( (t.spriteName for t in @world.thangs) )
|
||||
nameModelTuples = ([thangType.get('name'), thangType] for thangType in @thangNames.models)
|
||||
nameModelMap = _.zipObject nameModelTuples
|
||||
@spriteSheetsToBuild = []
|
||||
|
||||
for thangTypeName in thangsToLoad
|
||||
thang = nameModelMap[thangTypeName]
|
||||
thang.fetch()
|
||||
thang = @supermodel.loadModel(thang, 'thang').model
|
||||
@listenToOnce thang, 'sync', @buildSpriteSheetsForThangType
|
||||
thangType = nameModelMap[thangTypeName]
|
||||
thangType.fetch()
|
||||
thangType = @supermodel.loadModel(thangType, 'thang').model
|
||||
res = @supermodel.addSomethingResource "sprite_sheet", 5
|
||||
res.thangType = thangType
|
||||
res.markLoading()
|
||||
@spriteSheetsToBuild.push res
|
||||
|
||||
@buildLoopInterval = setInterval @buildLoop, 5
|
||||
|
||||
maybeLoadURL: (url, Model, resourceName) ->
|
||||
return if @supermodel.getModel(url)
|
||||
|
@ -150,9 +156,22 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@supermodel.loadModel(model, resourceName)
|
||||
|
||||
onSupermodelLoaded: ->
|
||||
console.log 'SuperModel for Level loaded in', new Date().getTime() - @t0, 'ms'
|
||||
@loadLevelSounds()
|
||||
@denormalizeSession()
|
||||
app.tracker.updatePlayState(@level, @session) unless @headless
|
||||
|
||||
buildLoop: =>
|
||||
return if @lastBuilt and new Date().getTime() - @lastBuilt < 10
|
||||
return clearInterval @buildLoopInterval unless @spriteSheetsToBuild.length
|
||||
|
||||
for spriteSheetResource, i in @spriteSheetsToBuild
|
||||
if spriteSheetResource.thangType.loaded
|
||||
@buildSpriteSheetsForThangType spriteSheetResource.thangType
|
||||
@spriteSheetsToBuild.splice i, 1
|
||||
@lastBuilt = new Date().getTime()
|
||||
spriteSheetResource.markLoaded()
|
||||
return
|
||||
|
||||
denormalizeSession: ->
|
||||
return if @headless or @sessionDenormalized or @spectateMode
|
||||
|
@ -246,3 +265,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
# everything else sound wise is loaded as needed as worlds are generated
|
||||
|
||||
progress: -> @supermodel.progress
|
||||
|
||||
destroy: ->
|
||||
clearInterval @buildLoopInterval if @buildLoopInterval
|
||||
super()
|
||||
|
|
|
@ -715,6 +715,7 @@
|
|||
top_simulators: "Top Simulators"
|
||||
source_document: "Source Document"
|
||||
document: "Document" # note to diplomats: not a physical document, a document in MongoDB, ie a record in a database
|
||||
sprite_sheet: "Sprite Sheet"
|
||||
|
||||
delta:
|
||||
added: "Added"
|
||||
|
|
|
@ -19,7 +19,6 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
loadModel: (model, name, fetchOptions, value=1) ->
|
||||
cachedModel = @getModelByURL(model.getURL())
|
||||
if cachedModel
|
||||
console.debug 'Model cache hit', cachedModel.get('name') or cachedModel.getURL()
|
||||
if cachedModel.loaded
|
||||
res = @addModelResource(cachedModel, name, fetchOptions, 0)
|
||||
res.markLoaded()
|
||||
|
@ -141,7 +140,7 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
@listenToOnce(resource, 'loaded', @onResourceLoaded)
|
||||
@listenTo(resource, 'failed', @onResourceFailed)
|
||||
@denom += value
|
||||
@updateProgress() if @denom
|
||||
_.defer @updateProgress if @denom
|
||||
|
||||
onResourceLoaded: (r) ->
|
||||
@num += r.value
|
||||
|
|
|
@ -61,7 +61,9 @@ module.exports = class ThangType extends CocoModel
|
|||
return false unless @isFullyLoaded()
|
||||
@options = @fillOptions options
|
||||
key = @spriteSheetKey(@options)
|
||||
if ss = @spriteSheets[key] then return ss
|
||||
return if @building[key]
|
||||
@t0 = new Date().getTime()
|
||||
@initBuild(options)
|
||||
@addGeneralFrames() unless @options.portraitOnly
|
||||
@addPortrait()
|
||||
|
@ -151,9 +153,8 @@ module.exports = class ThangType extends CocoModel
|
|||
@builder.buildAsync() unless buildQueue.length > 1
|
||||
@builder.on 'complete', @onBuildSpriteSheetComplete, @, true, key
|
||||
return true
|
||||
t0 = new Date()
|
||||
spriteSheet = @builder.build()
|
||||
console.debug "Built #{@get('name')} in #{new Date() - t0}ms."
|
||||
console.debug "Built #{@get('name')} in #{new Date().getTime() - @t0}ms."
|
||||
@spriteSheets[key] = spriteSheet
|
||||
delete @building[key]
|
||||
spriteSheet
|
||||
|
|
|
@ -35,7 +35,7 @@ module.exports = class ThangAvatarView extends View
|
|||
context.thang = @thang
|
||||
options = @thang?.getSpriteOptions() or {}
|
||||
options.async = false
|
||||
context.avatarURL = @thangType.getPortraitSource(options)
|
||||
context.avatarURL = @thangType.getPortraitSource(options) unless @thangType.loading
|
||||
context.includeName = @includeName
|
||||
context
|
||||
|
||||
|
|
Loading…
Reference in a new issue