Got rid of potentially unnecessary (and definitely slow) SpriteSheetBuilder _.cloneDeep. Watch out.

This commit is contained in:
Nick Winter 2014-02-27 20:54:29 -08:00
parent aef1bc63ba
commit 97197bd89d
2 changed files with 12 additions and 8 deletions

View file

@ -99,6 +99,8 @@ module.exports = class LevelLoader extends CocoClass
onSupermodelError: ->
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()
# Things to do when either the Session or Supermodel load
@ -171,10 +173,12 @@ module.exports = class LevelLoader extends CocoClass
building = thangType.buildSpriteSheet options
return unless building
console.log 'Building:', thangType.get('name'), options
t0 = new Date()
@spriteSheetsToBuild += 1
thangType.once 'build-complete', =>
@spriteSheetsBuilt += 1
@notifyProgress()
console.log "Built", thangType.get('name'), 'after', ((new Date()) - t0), 'ms'
# Initial Sound Loading

View file

@ -3,7 +3,7 @@
module.exports = class SpriteBuilder
constructor: (@thangType, @options) ->
@options ?= {}
raw = _.cloneDeep(@thangType.get('raw'))
raw = @thangType.get('raw')
@shapeStore = raw.shapes
@containerStore = raw.containers
@animationStore = raw.animations
@ -124,7 +124,7 @@ module.exports = class SpriteBuilder
cont.addChild(child)
cont.bounds = new createjs.Rectangle(contData.b...)
cont
buildColorMaps: ->
@colorMap = {}
colorGroups = @thangType.get('colorGroups')
@ -136,7 +136,7 @@ module.exports = class SpriteBuilder
for group, config of colorConfig
continue unless colorGroups[group] # color group not found...
@buildColorMapForGroup(colorGroups[group], config)
buildColorMapForGroup: (shapes, config) ->
return unless shapes.length
colors = @initColorMap(shapes)
@ -144,7 +144,7 @@ module.exports = class SpriteBuilder
@adjustValueForColorMap(colors, 1, config.saturation)
@adjustValueForColorMap(colors, 2, config.lightness)
@applyColorMap(shapes, colors)
initColorMap: (shapes) ->
colors = {}
for shapeKey in shapes
@ -156,18 +156,18 @@ module.exports = class SpriteBuilder
adjustHuesForColorMap: (colors, targetHue) ->
hues = (hsl[0] for hex, hsl of colors)
# 'rotate' the hue spectrum so averaging works
if Math.max(hues) - Math.min(hues) > 0.5
hues = (if h < 0.5 then h + 1.0 else h for h in hues)
averageHue = sum(hues) / hues.length
averageHue %= 1
# end result should be something like a hue array of [0.9, 0.3] gets an average of 0.1
targetHue ?= 0
diff = targetHue - averageHue
hsl[0] = (hsl[0] + diff + 1) % 1 for hex, hsl of colors
adjustValueForColorMap: (colors, index, targetValue) ->
values = (hsl[index] for hex, hsl of colors)
averageValue = sum(values) / values.length
@ -183,4 +183,4 @@ module.exports = class SpriteBuilder
@colorMap[shapeKey] = hslToHex(colors[shape.fc])
sum = (nums) -> _.reduce(nums, (s, num) -> s + num)
sum = (nums) -> _.reduce(nums, (s, num) -> s + num)