Got rid of potentially unnecessary (and definitely slow) SpriteSheetBuilder _.cloneDeep. Watch out.
This commit is contained in:
parent
aef1bc63ba
commit
97197bd89d
2 changed files with 12 additions and 8 deletions
app/lib
|
@ -99,6 +99,8 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
onSupermodelError: ->
|
onSupermodelError: ->
|
||||||
|
|
||||||
onSupermodelLoadedOne: (e) ->
|
onSupermodelLoadedOne: (e) ->
|
||||||
|
#if e.model instanceof ThangType
|
||||||
|
# console.log "LevelLoader loaded ThangType", e.model.get('name'), "so we should figure out how to build it."
|
||||||
@update()
|
@update()
|
||||||
|
|
||||||
# Things to do when either the Session or Supermodel load
|
# Things to do when either the Session or Supermodel load
|
||||||
|
@ -171,10 +173,12 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
building = thangType.buildSpriteSheet options
|
building = thangType.buildSpriteSheet options
|
||||||
return unless building
|
return unless building
|
||||||
console.log 'Building:', thangType.get('name'), options
|
console.log 'Building:', thangType.get('name'), options
|
||||||
|
t0 = new Date()
|
||||||
@spriteSheetsToBuild += 1
|
@spriteSheetsToBuild += 1
|
||||||
thangType.once 'build-complete', =>
|
thangType.once 'build-complete', =>
|
||||||
@spriteSheetsBuilt += 1
|
@spriteSheetsBuilt += 1
|
||||||
@notifyProgress()
|
@notifyProgress()
|
||||||
|
console.log "Built", thangType.get('name'), 'after', ((new Date()) - t0), 'ms'
|
||||||
|
|
||||||
# Initial Sound Loading
|
# Initial Sound Loading
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
module.exports = class SpriteBuilder
|
module.exports = class SpriteBuilder
|
||||||
constructor: (@thangType, @options) ->
|
constructor: (@thangType, @options) ->
|
||||||
@options ?= {}
|
@options ?= {}
|
||||||
raw = _.cloneDeep(@thangType.get('raw'))
|
raw = @thangType.get('raw')
|
||||||
@shapeStore = raw.shapes
|
@shapeStore = raw.shapes
|
||||||
@containerStore = raw.containers
|
@containerStore = raw.containers
|
||||||
@animationStore = raw.animations
|
@animationStore = raw.animations
|
||||||
|
@ -124,7 +124,7 @@ module.exports = class SpriteBuilder
|
||||||
cont.addChild(child)
|
cont.addChild(child)
|
||||||
cont.bounds = new createjs.Rectangle(contData.b...)
|
cont.bounds = new createjs.Rectangle(contData.b...)
|
||||||
cont
|
cont
|
||||||
|
|
||||||
buildColorMaps: ->
|
buildColorMaps: ->
|
||||||
@colorMap = {}
|
@colorMap = {}
|
||||||
colorGroups = @thangType.get('colorGroups')
|
colorGroups = @thangType.get('colorGroups')
|
||||||
|
@ -136,7 +136,7 @@ module.exports = class SpriteBuilder
|
||||||
for group, config of colorConfig
|
for group, config of colorConfig
|
||||||
continue unless colorGroups[group] # color group not found...
|
continue unless colorGroups[group] # color group not found...
|
||||||
@buildColorMapForGroup(colorGroups[group], config)
|
@buildColorMapForGroup(colorGroups[group], config)
|
||||||
|
|
||||||
buildColorMapForGroup: (shapes, config) ->
|
buildColorMapForGroup: (shapes, config) ->
|
||||||
return unless shapes.length
|
return unless shapes.length
|
||||||
colors = @initColorMap(shapes)
|
colors = @initColorMap(shapes)
|
||||||
|
@ -144,7 +144,7 @@ module.exports = class SpriteBuilder
|
||||||
@adjustValueForColorMap(colors, 1, config.saturation)
|
@adjustValueForColorMap(colors, 1, config.saturation)
|
||||||
@adjustValueForColorMap(colors, 2, config.lightness)
|
@adjustValueForColorMap(colors, 2, config.lightness)
|
||||||
@applyColorMap(shapes, colors)
|
@applyColorMap(shapes, colors)
|
||||||
|
|
||||||
initColorMap: (shapes) ->
|
initColorMap: (shapes) ->
|
||||||
colors = {}
|
colors = {}
|
||||||
for shapeKey in shapes
|
for shapeKey in shapes
|
||||||
|
@ -156,18 +156,18 @@ module.exports = class SpriteBuilder
|
||||||
|
|
||||||
adjustHuesForColorMap: (colors, targetHue) ->
|
adjustHuesForColorMap: (colors, targetHue) ->
|
||||||
hues = (hsl[0] for hex, hsl of colors)
|
hues = (hsl[0] for hex, hsl of colors)
|
||||||
|
|
||||||
# 'rotate' the hue spectrum so averaging works
|
# 'rotate' the hue spectrum so averaging works
|
||||||
if Math.max(hues) - Math.min(hues) > 0.5
|
if Math.max(hues) - Math.min(hues) > 0.5
|
||||||
hues = (if h < 0.5 then h + 1.0 else h for h in hues)
|
hues = (if h < 0.5 then h + 1.0 else h for h in hues)
|
||||||
averageHue = sum(hues) / hues.length
|
averageHue = sum(hues) / hues.length
|
||||||
averageHue %= 1
|
averageHue %= 1
|
||||||
# end result should be something like a hue array of [0.9, 0.3] gets an average of 0.1
|
# end result should be something like a hue array of [0.9, 0.3] gets an average of 0.1
|
||||||
|
|
||||||
targetHue ?= 0
|
targetHue ?= 0
|
||||||
diff = targetHue - averageHue
|
diff = targetHue - averageHue
|
||||||
hsl[0] = (hsl[0] + diff + 1) % 1 for hex, hsl of colors
|
hsl[0] = (hsl[0] + diff + 1) % 1 for hex, hsl of colors
|
||||||
|
|
||||||
adjustValueForColorMap: (colors, index, targetValue) ->
|
adjustValueForColorMap: (colors, index, targetValue) ->
|
||||||
values = (hsl[index] for hex, hsl of colors)
|
values = (hsl[index] for hex, hsl of colors)
|
||||||
averageValue = sum(values) / values.length
|
averageValue = sum(values) / values.length
|
||||||
|
@ -183,4 +183,4 @@ module.exports = class SpriteBuilder
|
||||||
@colorMap[shapeKey] = hslToHex(colors[shape.fc])
|
@colorMap[shapeKey] = hslToHex(colors[shape.fc])
|
||||||
|
|
||||||
|
|
||||||
sum = (nums) -> _.reduce(nums, (s, num) -> s + num)
|
sum = (nums) -> _.reduce(nums, (s, num) -> s + num)
|
||||||
|
|
Reference in a new issue