diff --git a/packages/timing/animation-view.coffee b/packages/timing/animation-view.coffee deleted file mode 100644 index 4a5b9e9..0000000 --- a/packages/timing/animation-view.coffee +++ /dev/null @@ -1,82 +0,0 @@ - -import Promise from 'bluebird' - -import { - EventEmitter, juggleEvents, Mixin, Property -} from '@avocado/composition' -import {Container, Image, Sprite} from '@avocado/graphics' -import {Vector} from '@avocado/math' - -import {Animation} from './animation' - -export class AnimationView extends Mixin(Container).with( - EventEmitter - Property 'animation' - Property 'image', default: null -) - - constructor: (animation) -> - - super() - - @_sprite = null - - @on 'animationChanged', (oldAnimation) => @onAnimationChanged oldAnimation - - @setAnimation animation - - destroy: -> @_sprite?.destroy - - onAnimationChanged: (oldAnimation) -> - - animation = @animation() - - juggleEvents( - this, oldAnimation, animation - positionChanged: @onAnimationPositionChanged - sourceRectangleChanged: @onSourceRectangleChanged - ) - - juggleEvents( - this, oldAnimation, animation - imageUriChanged: @onAnimationImageUriChanged - ) - - @onAnimationImageUriChanged() - - onAnimationImageUriChanged: -> - - return unless animation = @animation() - return unless uri = animation.imageUri() - - Image.load(uri).done (image) => @setImage image - - onAnimationPositionChanged: -> @_sprite.setPosition @position() - - onSourceRectangleChanged: => - @_sprite?.setSourceRectangle @animation().sourceRectangle() - - onSpriteSourceRectangleChanged: => @emit 'sourceRectangleChanged' - - setImage: ( - image - ) -> - - if @_sprite - - @removeChild @_sprite - @_sprite?.off 'sourceRectangleChanged', @onSpriteSourceRectangleChanged - @_sprite.destroy() - - return unless image - - # Add to render list before actually setting inner image. This way, - # AnimationView::onSetImage is useful for render timing. - ownedImage = image.clone() - @addChild @_sprite = new Sprite ownedImage - @_sprite.on 'sourceRectangleChanged', @onSpriteSourceRectangleChanged - @_sprite.setSourceRectangle @animation().sourceRectangle() - - super ownedImage - - sprite: -> @_sprite diff --git a/packages/timing/animation.coffee b/packages/timing/animation.coffee deleted file mode 100644 index c71d8e2..0000000 --- a/packages/timing/animation.coffee +++ /dev/null @@ -1,114 +0,0 @@ - -import Promise from 'bluebird' - -import { - EventEmitter, Mixin, Property -} from '@avocado/composition' -import {Rectangle, Vector} from '@avocado/math' -import {Resource} from '@avocado/resource' -import {setterName} from '@avocado/string' -import { - TimedIndexMixin as TimedIndex -} from './timed-index' - -export class Animation extends Mixin(Resource).with( - - EventEmitter - - Property 'direction', default: 0 - Property 'directionCount', default: 1 - TimedIndex 'frame' - Property 'frameSize', default: [0, 0] - Property 'imageUri', default: '' - Vector.Mixin( - 'position', 'x', 'y' - x: default: 0 - y: default: 0 - ) - Property 'sourceRectangle', default: [0, 0, 0, 0] - Property 'uri', default: '' -) - - @load: @createLoad Animation - - @reduce: (O) -> - - O = Object.assign (new Animation()).toJSON(), O - - O.directionCount = parseInt O.directionCount - O.direction = parseInt O.direction ? 0 - O.frameCount = parseInt O.frameCount - O.frameRate = parseInt O.frameRate - O.frameSize = O.frameSize.map (x) -> parseInt x - - O.uri or= '' - O.imageUri or= O.uri.replace '.animation.json', '.png' - - return O - - constructor: -> - - super() - - @on [ - 'directionChanged', 'frameSizeChanged', 'indexChanged' - ], => @setSourceRectangle @rawSourceRectangle @index() - - @on 'directionCountChanged', => @setDirection @direction() - - clampDirection: (direction) -> - - return 0 if @directionCount() is 1 - - direction = Math.min 7, Math.max direction, 0 - direction = { - 4: 1 - 5: 1 - 6: 3 - 7: 3 - }[direction] if @directionCount() is 4 and direction > 3 - - direction - - # Only mutates if not Vector.equals size, [0, 0] - deriveFrameSize: (size) -> - - return frameSize unless Vector.isZero frameSize = @frameSize() ? [0, 0] - return [0, 0] if Vector.isZero size - return [0, 0] if @directionCount() is 0 - return [0, 0] if @frameCount() is 0 - - # If the frame size isn't explicitly given, then calculate the - # size of one frame using the total number of frames and the total - # spritesheet size. Width is calculated by dividing the total - # spritesheet width by the number of frames, and the height is the - # height of the spritesheet divided by the number of directions - # in the animation. - return Vector.div size, [@frameCount(), @directionCount()] - - rawSourceRectangle: (index) -> - - return [0, 0, 0, 0] unless frameCount = @frameCount() - - frameSize = @frameSize() - Rectangle.compose( - Vector.mul frameSize, [ - (index ? @index()) % frameCount - @direction() - ] - frameSize - ) - - setDirection: (direction) -> super @clampDirection parseInt direction - - setDirectionCount: (directionCount) -> super parseInt directionCount - - toJSON: -> - - defaultImageUri = @uri().replace '.animation.json', '.png' - - directionCount: @directionCount() - frameRate: @frameRate() - frameCount: @frameCount() - frameSize: @frameSize() - imageUri: @imageUri() if @imageUri() isnt defaultImageUri diff --git a/packages/timing/cps.coffee b/packages/timing/cps.coffee deleted file mode 100644 index 25a3ba3..0000000 --- a/packages/timing/cps.coffee +++ /dev/null @@ -1,36 +0,0 @@ -# **Cps** is used to measure the cycles per second of a process. Avocado uses -# this class to measure the cycles per second and renders per second of the -# engine itself. If you instantiate **Cps** and call **Cps**::tick() -# every time a process runs, you can call **Cps**::count() to found how -# many times the cycle runs per second. -# -# *NOTE:* When you instantiate **Cps**, a **frequency** is specified. You -# must call **Cps**.tick() for at least **frequency** milliseconds to get -# an accurate reading. Until then, you will read 0. - -export class Cps - - # Instantiate the CPS counter. By default, it counts the cycles every 250 - # milliseconds. - constructor: (frequency = 250) -> - - previous = Date.now() - - setInterval => - - now = Date.now() - elapsed = now - previous - previous = now - @fps = @c * (1000 / elapsed) - @c = 0 - - , frequency - - @fps = 0 - @c = 0 - - # Call every time the process you want to measure runs. - tick: -> @c++ - - # Call to retrieve how many cycles the process runs per second. - count: -> @fps diff --git a/packages/timing/index.coffee b/packages/timing/index.coffee deleted file mode 100644 index f1362de..0000000 --- a/packages/timing/index.coffee +++ /dev/null @@ -1,13 +0,0 @@ - -export { - cancelAnimationFrame, clearAnimation, requestAnimationFrame, setAnimation -} from './animation-frame' - -export {Animation} from './animation' -export {AnimationView} from './animation-view' - -export {Cps} from './cps' - -export {Ticker} from './ticker' - -export {TimedIndexMixin as TimedIndex} from './timed-index'