Several fixes for level editor update speed--should be faster for making changes on complex levels

This commit is contained in:
Nick Winter 2016-05-31 15:32:32 -07:00
parent ebc94e6e4b
commit e7f79ab721
2 changed files with 22 additions and 15 deletions
app
models
views/editor/level/thangs

View file

@ -59,11 +59,13 @@ module.exports = class Level extends CocoModel
denormalize: (supermodel, session, otherSession) -> denormalize: (supermodel, session, otherSession) ->
o = $.extend true, {}, @attributes o = $.extend true, {}, @attributes
if o.thangs and @get('type', true) in ['hero', 'hero-ladder', 'hero-coop', 'course', 'course-ladder'] if o.thangs and @get('type', true) in ['hero', 'hero-ladder', 'hero-coop', 'course', 'course-ladder']
thangTypesWithComponents = (tt for tt in supermodel.getModels(ThangType) when tt.get('components')?)
thangTypesByOriginal = _.indexBy thangTypesWithComponents, (tt) -> tt.get('original') # Optimization
for levelThang in o.thangs for levelThang in o.thangs
@denormalizeThang(levelThang, supermodel, session, otherSession) @denormalizeThang(levelThang, supermodel, session, otherSession, thangTypesByOriginal)
o o
denormalizeThang: (levelThang, supermodel, session, otherSession) -> denormalizeThang: (levelThang, supermodel, session, otherSession, thangTypesByOriginal) ->
levelThang.components ?= [] levelThang.components ?= []
isHero = /Hero Placeholder/.test(levelThang.id) and @get('type', true) in ['hero', 'hero-ladder', 'hero-coop'] isHero = /Hero Placeholder/.test(levelThang.id) and @get('type', true) in ['hero', 'hero-ladder', 'hero-coop']
if isHero and otherSession if isHero and otherSession
@ -79,7 +81,7 @@ module.exports = class Level extends CocoModel
if isHero if isHero
placeholders = {} placeholders = {}
placeholdersUsed = {} placeholdersUsed = {}
placeholderThangType = supermodel.getModelByOriginal(ThangType, levelThang.thangType) placeholderThangType = thangTypesByOriginal[levelThang.thangType]
unless placeholderThangType unless placeholderThangType
console.error "Couldn't find placeholder ThangType for the hero!" console.error "Couldn't find placeholder ThangType for the hero!"
isHero = false isHero = false
@ -92,7 +94,7 @@ module.exports = class Level extends CocoModel
heroThangType = session?.get('heroConfig')?.thangType heroThangType = session?.get('heroConfig')?.thangType
levelThang.thangType = heroThangType if heroThangType levelThang.thangType = heroThangType if heroThangType
thangType = supermodel.getModelByOriginal(ThangType, levelThang.thangType, (m) -> m.get('components')?) thangType = thangTypesByOriginal[levelThang.thangType]
configs = {} configs = {}
for thangComponent in levelThang.components for thangComponent in levelThang.components
@ -168,11 +170,16 @@ module.exports = class Level extends CocoModel
# Decision? Just special case the sort logic in here until we have more examples than these two and decide how best to handle most of the cases then, since we don't really know the whole of the problem yet. # Decision? Just special case the sort logic in here until we have more examples than these two and decide how best to handle most of the cases then, since we don't really know the whole of the problem yet.
# TODO: anything that depends on Programmable will break right now. # TODO: anything that depends on Programmable will break right now.
originalsToComponents = _.indexBy levelComponents, 'original' # Optimization for speed
alliedComponent = _.find levelComponents, name: 'Allied'
actsComponent = _.find levelComponents, name: 'Acts'
for thang in thangs ? [] for thang in thangs ? []
originalsToThangComponents = _.indexBy thang.components, 'original'
sorted = [] sorted = []
visit = (c, namesToIgnore) -> visit = (c, namesToIgnore) ->
return if c in sorted return if c in sorted
lc = _.find levelComponents, {original: c.original} lc = originalsToComponents[c.original]
console.error thang.id or thang.name, 'couldn\'t find lc for', c, 'of', levelComponents unless lc console.error thang.id or thang.name, 'couldn\'t find lc for', c, 'of', levelComponents unless lc
return unless lc return unless lc
return if namesToIgnore and lc.name in namesToIgnore return if namesToIgnore and lc.name in namesToIgnore
@ -184,20 +191,18 @@ module.exports = class Level extends CocoModel
visit c2, [lc.name] for c2 in thang.components visit c2, [lc.name] for c2 in thang.components
else else
for d in lc.dependencies or [] for d in lc.dependencies or []
c2 = _.find thang.components, {original: d.original} c2 = originalsToThangComponents[d.original]
unless c2 unless c2
dependent = _.find levelComponents, {original: d.original} dependent = originalsToComponents[d.original]
dependent = dependent?.name or d.original dependent = dependent?.name or d.original
console.error parentType, thang.id or thang.name, 'does not have dependent Component', dependent, 'from', lc.name console.error parentType, thang.id or thang.name, 'does not have dependent Component', dependent, 'from', lc.name
visit c2 if c2 visit c2 if c2
if lc.name is 'Collides' if lc.name is 'Collides' and alliedComponent
if allied = _.find levelComponents, {name: 'Allied'} if allied = originalsToThangComponents[alliedComponent.original]
allied = _.find(thang.components, {original: allied.original}) visit allied
visit allied if allied if lc.name is 'Moves' and actsComponent
if lc.name is 'Moves' if acts = originalsToThangComponents[actsComponent.original]
if acts = _.find levelComponents, {name: 'Acts'} visit acts
acts = _.find(thang.components, {original: acts.original})
visit acts if acts
#console.log thang.id, 'sorted comps adding', lc.name #console.log thang.id, 'sorted comps adding', lc.name
sorted.push c sorted.push c
for comp in thang.components for comp in thang.components

View file

@ -90,6 +90,8 @@ module.exports = class ThangsTabView extends CocoView
getRenderData: (context={}) -> getRenderData: (context={}) ->
context = super(context) context = super(context)
return context unless @supermodel.finished() return context unless @supermodel.finished()
for thangType in @thangTypes.models
thangType.notInLevel = true
thangTypes = (thangType.attributes for thangType in @supermodel.getModels(ThangType)) thangTypes = (thangType.attributes for thangType in @supermodel.getModels(ThangType))
thangTypes = _.uniq thangTypes, false, 'original' thangTypes = _.uniq thangTypes, false, 'original'
thangTypes = _.reject thangTypes, (tt) -> tt.kind in ['Mark', undefined] thangTypes = _.reject thangTypes, (tt) -> tt.kind in ['Mark', undefined]