Skip to content
Browse files

Folder structure and base code.

  • Loading branch information...
1 parent 568a7bd commit aa5dd48643356ec82735690413c7d133e6205c09 @mrdoob committed Mar 14, 2011
Showing with 180 additions and 0 deletions.
  1. +21 −0 LICENSE
  2. 0 README
  3. +2 −0 README.md
  4. +27 −0 src/Effect.js
  5. +130 −0 src/Sequencer.js
View
21 LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2011 Mr.doob
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
0 README
No changes.
View
2 README.md
@@ -0,0 +1,2 @@
+sequencer.js
+========
View
27 src/Effect.js
@@ -0,0 +1,27 @@
+var Effect = function () {
+
+};
+
+Effect.prototype = {
+
+ init: function () {
+
+ },
+
+ load: function () {
+
+ },
+
+ show: function () {
+
+ },
+
+ hide: function () {
+
+ },
+
+ update: function ( time ) {
+
+ }
+
+}
View
130 src/Sequencer.js
@@ -0,0 +1,130 @@
+var Sequencer = function () {
+
+ var _effect,
+ _effects = [],
+ _effectsActive = [],
+ _effectsToRemove = [],
+
+ _nextEffect = 0,
+ _nextEffectToRemove = 0,
+ _time = 0,
+
+ _layersNeedSorting = false;
+
+ this.add = function ( effect, start_time, end_time, layer ) {
+
+ effect.__active = false;
+ effect.__start_time = start_time;
+ effect.__duration = end_time - start_time;
+ effect.__end_time = end_time;
+ effect.__layer = layer;
+
+ effect.init();
+
+ _effects.push( effect );
+ _effects.sort( function ( a, b ) { return a.__start_time - b.__start_time; } );
+
+ _effectsToRemove.push( effect );
+ _effectsToRemove.sort( function ( a, b ) { return a.__end_time - b.__end_time; } );
+
+ };
+
+ this.update = function ( time ) {
+
+ var effect;
+
+ if ( time < _time ) {
+
+ this.clear();
+
+ }
+
+ while ( _effects[ _nextEffect ] ) {
+
+ effect = _effects[ _nextEffect ];
+
+ if ( effect.__start_time > time ) {
+
+ break;
+
+ }
+
+ if ( !effect.__active && effect.__end_time > time ) {
+
+ effect.show();
+ effect.__active = true;
+
+ _effectsActive.push( effect );
+
+ _layersNeedSorting = true;
+
+ }
+
+ _nextEffect ++;
+
+ }
+
+ while ( _effectsToRemove[ _nextEffectToRemove ] ) {
+
+ effect = _effectsToRemove[ _nextEffectToRemove ];
+
+ if ( effect.__end_time > time ) {
+
+ break;
+
+ }
+
+ if ( effect.__active ) {
+
+ effect.hide();
+ effect.__active = false;
+
+ var i = _effectsActive.indexOf( effect );
+
+ if ( i !== -1 ) {
+
+ _effectsActive.splice( i, 1 );
+
+ }
+
+ }
+
+ _nextEffectToRemove ++;
+
+ }
+
+ if ( _layersNeedSorting ) {
+
+ _effectsActive.sort( function ( a, b ) { return a.__layer - b.__layer; } );
+ _layersNeedSorting = false;
+
+ }
+
+ for ( var i = 0, l = _effectsActive.length; i < l; i ++ ) {
+
+ _effect = _effectsActive[ i ];
+ _effect.update( ( time - _effect.__start_time ) / _effect.__duration );
+
+ }
+
+ _time = time;
+
+ };
+
+ this.clear = function () {
+
+ _nextEffect = 0;
+ _nextEffectToRemove = 0;
+
+ while ( _effectsActive.length ) {
+
+ _effect = _effectsActive[ 0 ];
+ _effect.__active = false;
+ _effect.hide();
+ _effectsActive.splice( 0, 1 );
+
+ }
+
+ };
+
+};

0 comments on commit aa5dd48

Please sign in to comment.
Something went wrong with that request. Please try again.