The whole WebGL system now dynamically renders needed frames when actions it doesn't support get activated.
This commit is contained in:
parent
0404b94e5e
commit
c7279e68a8
4 changed files with 18 additions and 5 deletions
app/lib/surface
test/app/lib/surface
|
@ -47,6 +47,7 @@ module.exports = class WebGLLayer extends CocoClass
|
||||||
|
|
||||||
cocoSprite.layer = @
|
cocoSprite.layer = @
|
||||||
cocoSprite.updateBaseScale()
|
cocoSprite.updateBaseScale()
|
||||||
|
@listenTo(cocoSprite, 'action-needs-render', @onActionNeedsRender)
|
||||||
@cocoSprites.push cocoSprite
|
@cocoSprites.push cocoSprite
|
||||||
@loadThangType(cocoSprite.thangType)
|
@loadThangType(cocoSprite.thangType)
|
||||||
@addDefaultActionsToRender(cocoSprite)
|
@addDefaultActionsToRender(cocoSprite)
|
||||||
|
@ -54,9 +55,13 @@ module.exports = class WebGLLayer extends CocoClass
|
||||||
# TODO: actually add it as a child
|
# TODO: actually add it as a child
|
||||||
|
|
||||||
removeCocoSprite: (cocoSprite) ->
|
removeCocoSprite: (cocoSprite) ->
|
||||||
|
@stopListening(cocoSprite)
|
||||||
cocoSprite.imageObject.parent.removeChild cocoSprite.imageObject
|
cocoSprite.imageObject.parent.removeChild cocoSprite.imageObject
|
||||||
@cocoSprites = _.without @cocoSprites, cocoSprite
|
@cocoSprites = _.without @cocoSprites, cocoSprite
|
||||||
|
|
||||||
|
onActionNeedsRender: (cocoSprite, action) ->
|
||||||
|
@upsertActionToRender(cocoSprite.thangType, action.name, cocoSprite.options.colorConfig)
|
||||||
|
|
||||||
loadThangType: (thangType) ->
|
loadThangType: (thangType) ->
|
||||||
if not thangType.isFullyLoaded()
|
if not thangType.isFullyLoaded()
|
||||||
thangType.setProjection null
|
thangType.setProjection null
|
||||||
|
|
|
@ -49,6 +49,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
||||||
animationName = @spriteSheetPrefix + actionName
|
animationName = @spriteSheetPrefix + actionName
|
||||||
if not (animationName in @spriteSheet.getAnimations())
|
if not (animationName in @spriteSheet.getAnimations())
|
||||||
@singleChildSprite.gotoAndStop(0)
|
@singleChildSprite.gotoAndStop(0)
|
||||||
|
@notifyActionNeedsRender(action)
|
||||||
return
|
return
|
||||||
@singleChildSprite[func](animationName)
|
@singleChildSprite[func](animationName)
|
||||||
@singleChildSprite.framerate = action.framerate or 20
|
@singleChildSprite.framerate = action.framerate or 20
|
||||||
|
@ -63,6 +64,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
||||||
@baseMovieClip = @buildMovieClip(action.animation)
|
@baseMovieClip = @buildMovieClip(action.animation)
|
||||||
if not @baseMovieClip
|
if not @baseMovieClip
|
||||||
@children = []
|
@children = []
|
||||||
|
@notifyActionNeedsRender(action)
|
||||||
return
|
return
|
||||||
@children = @baseMovieClip.children
|
@children = @baseMovieClip.children
|
||||||
@frames = action.frames
|
@frames = action.frames
|
||||||
|
@ -81,6 +83,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
||||||
animationName = @spriteSheetPrefix + actionName
|
animationName = @spriteSheetPrefix + actionName
|
||||||
if not (animationName in @spriteSheet.getAnimations())
|
if not (animationName in @spriteSheet.getAnimations())
|
||||||
@singleChildSprite.gotoAndStop(0)
|
@singleChildSprite.gotoAndStop(0)
|
||||||
|
@notifyActionNeedsRender(action)
|
||||||
return
|
return
|
||||||
@singleChildSprite.gotoAndStop(animationName)
|
@singleChildSprite.gotoAndStop(animationName)
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
||||||
containerName = @spriteSheetPrefix + action.container
|
containerName = @spriteSheetPrefix + action.container
|
||||||
if not (containerName in @spriteSheet.getAnimations())
|
if not (containerName in @spriteSheet.getAnimations())
|
||||||
@children = []
|
@children = []
|
||||||
|
@notifyActionNeedsRender(action)
|
||||||
return
|
return
|
||||||
sprite = new createjs.Sprite(@spriteSheet)
|
sprite = new createjs.Sprite(@spriteSheet)
|
||||||
sprite.gotoAndStop(containerName)
|
sprite.gotoAndStop(containerName)
|
||||||
|
@ -99,6 +103,9 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
notifyActionNeedsRender: (action) ->
|
||||||
|
@sprite.trigger('action-needs-render', @sprite, action)
|
||||||
|
|
||||||
buildMovieClip: (animationName, mode, startPosition, loops) ->
|
buildMovieClip: (animationName, mode, startPosition, loops) ->
|
||||||
raw = @thangType.get('raw')
|
raw = @thangType.get('raw')
|
||||||
animData = raw.animations[animationName]
|
animData = raw.animations[animationName]
|
||||||
|
|
|
@ -60,9 +60,10 @@ describe 'SpriteBoss', ->
|
||||||
defaultLayer = spriteBoss.spriteLayers.Default
|
defaultLayer = spriteBoss.spriteLayers.Default
|
||||||
defaultLayer.buildAsync = false # cause faster
|
defaultLayer.buildAsync = false # cause faster
|
||||||
|
|
||||||
# Don't have the layer automatically draw for move_fore, instead have it notified from WebGLSprites that
|
# Sort of an implicit test. By default, all the default actions are always rendered,
|
||||||
# this animation or its containers are needed.
|
# but I want to make sure the system can dynamically hear about actions it needs to render for
|
||||||
defaultLayer.setDefaultActions(_.without defaultLayer.defaultActions, 'move_fore')
|
# as they are used.
|
||||||
|
defaultLayer.setDefaultActions(['idle'])
|
||||||
|
|
||||||
# Render the simple world with just trees
|
# Render the simple world with just trees
|
||||||
spriteBoss.update(true)
|
spriteBoss.update(true)
|
||||||
|
|
|
@ -56,7 +56,7 @@ describe 'WebGLLayer', ->
|
||||||
animations = sheet.getAnimations()
|
animations = sheet.getAnimations()
|
||||||
expect(animations.length).toBe(1)
|
expect(animations.length).toBe(1)
|
||||||
expect(animations[0]).toBe(key)
|
expect(animations[0]).toBe(key)
|
||||||
expect(sheet.getNumFrames()).toBe(1)
|
expect(sheet.getNumFrames()).toBe(2) # one idle frame, and the emptiness frame
|
||||||
|
|
||||||
it 'renders a raster image onto a sheet', (done) ->
|
it 'renders a raster image onto a sheet', (done) ->
|
||||||
bootsThangType = new ThangType(require 'test/app/fixtures/leather-boots.thang.type')
|
bootsThangType = new ThangType(require 'test/app/fixtures/leather-boots.thang.type')
|
||||||
|
|
Reference in a new issue