Permalink
Browse files

adding several v1.3 changes

git-svn-id: https://kitchensynclib.googlecode.com/svn/trunk@290 6a906af3-0c40-0410-b003-45319c8c72c3
  • Loading branch information...
1 parent d01d2e1 commit 6a7cede89d44dece0ec5b317e678a646ede8e9a5 @mimshwright committed May 16, 2008
View
@@ -1,3 +1,11 @@
+===== v1.3 =====
+ADDED FrameRateView which displays the framerate of the Synchronizer.
+FIXED a bug in KSStaggeredGroup that caused some children not to fire.
+RENAMED 'offset' to 'delay'
+CHANGED default policy for snapToValueOnComplete to true.
+CHANGED the core of the Synchronizer to a timer based system.
+REFACTORED to optimize performance. Saw an improvement of about 50%
+
===== v1.2 (2008.05.2) =====
RENAMED Nearly the entire library
MOVED All classes into new packages
@@ -20,7 +20,7 @@ package org.as3lib.kitchensync
* The current version of the library. Use this to verify that the library is the
* version that your software expects.
*/
- public static const VERSION:String = "1.2"
+ public static const VERSION:String = "1.3"
private static var _initialized:Boolean = false;
/**
@@ -12,7 +12,7 @@ package org.as3lib.kitchensync
public static var easingFunction:Function = Linear.ease;
// TWEENS
- public static var snapToValueOnComplete:Boolean = false;
+ public static var snapToValueOnComplete:Boolean = true;
public static var snapToWholeNumber:Boolean = false;
}
}
@@ -16,13 +16,13 @@ package org.as3lib.kitchensync.action
/**
* This can be any action that takes place at a specifity time and uses the Synchronizer class to coordinate
* timing.
- *
- * -todo - sync mode seems to work but i'm seeing multiple calls of the same function sometimes one frame apart.
- * 18100 msec; 819 frames We use debuggers
- * 18121 msec; 820 frames We use debuggers
- * -todo - add a settings object
- * -todo - better implementation of ids
- */
+ *
+ */
+ // todo - sync mode seems to work but i'm seeing multiple calls of the same function sometimes one frame apart.
+ // 18100 msec; 819 frames We use debuggers
+ // 18121 msec; 820 frames We use debuggers
+ // todo - add a settings object
+ // todo - better implementation of ids
public class AbstractAction extends EventDispatcher
{
@@ -56,24 +56,30 @@ package org.as3lib.kitchensync.action
/**
- * offset is the time that will pass after the start() method is called
+ * delay is the time that will pass after the start() method is called
* before the action begins. Also known as delay.
* Will accept an integer or a parsable string.
*
* @see org.as3lib.kitchensync.ITimeStringParser
*
* @see #timeUnit
*/
- public function get offset():int { return _offset; }
- public function set offset(offset:*):void {
- if (!isNaN(offset)) {
- _offset = offset;
+ public function get delay():int { return _delay; }
+ public function set delay(delay:*):void {
+ if (!isNaN(delay)) {
+ _delay = delay;
} else {
- var timeString:String = offset.toString();
- _offset = timeStringParser.parseTimeString(timeString);
+ var timeString:String = delay.toString();
+ _delay = timeStringParser.parseTimeString(timeString);
}
}
- protected var _offset:int = 0;
+ protected var _delay:int = 0;
+
+ /**
+ * legacy accessors. synonomous with delay.
+ */
+ public function get offset():int { return offset; }
+ public function set offset(offset:*):void { this.offset = offset; }
/**
@@ -136,14 +142,14 @@ package org.as3lib.kitchensync.action
public function get pauseTime():Timestamp { return _pauseTime; }
//
+
/**
* Constructor.
* @abstract
*/
public function AbstractAction()
{
- super(null);
-
+ super();
timeStringParser = KitchenSyncDefaults.timeStringParser;
autoDelete = KitchenSyncDefaults.autoDelete;
sync = KitchenSyncDefaults.sync;
@@ -154,8 +160,8 @@ package org.as3lib.kitchensync.action
/**
* Adds the action as a listener to the Synchronizer's update event.
*
- * @todo see if moving forceUpdate() into start helps.
*/
+ // todo see if moving forceUpdate() into start helps.
internal function register():void {
Synchronizer.getInstance().addEventListener(KitchenSyncEvent.UPDATE, onUpdate);
@@ -197,7 +203,7 @@ package org.as3lib.kitchensync.action
* Causes the action to be paused. The action temporarily ignores update events from the Synchronizer
* and the onUpdate() handler will not be called. When unpause() is called,
* the action will continue at the point where it was paused.
- * If the pause() method affects the start time even if the offset time hasn't expired yet.
+ * If the pause() method affects the start time even if the delay time hasn't expired yet.
*/
public function pause():void {
if (!_running) {
@@ -291,9 +297,8 @@ package org.as3lib.kitchensync.action
* @see #addTrigger()
* @see #addEventTrigger()
*
- * @todo make sure this doesn't screw up if there are multiple triggers or if the thing isn't meant to
- * repeat.
*/
+ // todo - make sure this doesn't screw up if there are multiple triggers or if the thing isn't meant to repeat.
protected function onTrigger(event:Event):void {
if (!_running) { start(); }
}
@@ -324,16 +329,16 @@ package org.as3lib.kitchensync.action
}
/**
- * Checks to see whether the start time offset has elapsed and if the _startTime is defined. In other words,
+ * Checks to see whether the start time delay has elapsed and if the _startTime is defined. In other words,
* checks to see whether the action is ready to execute. Duration is handled seperately.
- * @return false if _startTime is null, true if the offset has elapsed.
+ * @return false if _startTime is null, true if the delay has elapsed.
*/
public function get startTimeHasElapsed():Boolean {
if (!_startTime || !_running || _paused) { return false; }
if (_sync) {
- if (_startTime.currentTime + _offset <= Synchronizer.getInstance().currentTimestamp.currentTime) { return true; }
+ if (_startTime.currentTime + _delay <= Synchronizer.getInstance().currentTimestamp.currentTime) { return true; }
} else {
- if (_startTime.currentFrame + TimestampUtil.millisecondsToFrames(_offset) <= Synchronizer.getInstance().currentTimestamp.currentFrame) { return true; }
+ if (_startTime.currentFrame + TimestampUtil.millisecondsToFrames(_delay) <= Synchronizer.getInstance().currentTimestamp.currentFrame) { return true; }
}
return false;
}
@@ -346,9 +351,9 @@ package org.as3lib.kitchensync.action
public function get durationHasElapsed():Boolean {
if (!_startTime || !_running || _paused) { return false; }
if (_sync) {
- if (_startTime.currentTime + _offset + _duration < Synchronizer.getInstance().currentTimestamp.currentTime) { return true; }
+ if (_startTime.currentTime + _delay + _duration < Synchronizer.getInstance().currentTimestamp.currentTime) { return true; }
} else {
- if (_startTime.currentFrame + TimestampUtil.millisecondsToFrames(_offset) + TimestampUtil.millisecondsToFrames(_duration)-1 < Synchronizer.getInstance().currentTimestamp.currentFrame) { return true; }
+ if (_startTime.currentFrame + TimestampUtil.millisecondsToFrames(_delay) + TimestampUtil.millisecondsToFrames(_duration)-1 < Synchronizer.getInstance().currentTimestamp.currentFrame) { return true; }
}
return false;
}
@@ -102,8 +102,8 @@ package org.as3lib.kitchensync.action
/**
* Reverse the order that the children play back in. Essentially, this just reverses the child array.
- * -todo - test this
*/
+ // todo - test this
public function reverseChildOrder():void {
_childActions = _childActions.reverse();
}
@@ -113,8 +113,8 @@ package org.as3lib.kitchensync.action
*
* @param event - The SynchronizerEvent.START from the child action
* @event SynchronizerEvent.CHILD_START
- * -todo - Add a reference to the started child to the event.
*/
+ // todo - Add a reference to the started child to the event.
protected function onChildStart(event:KitchenSyncEvent):void {
dispatchEvent(new KitchenSyncEvent(KitchenSyncEvent.CHILD_START, event.timestamp));
}
@@ -124,8 +124,8 @@ package org.as3lib.kitchensync.action
*
* @param event - The SynchronizerEvent.COMPLETE from the child action
* @event SynchronizerEvent.CHILD_COMPLETE
- * -todo - Add a reference to the completed child to the event.
*/
+ // todo - Add a reference to the completed child to the event.
protected function onChildFinished (event:KitchenSyncEvent):void {
dispatchEvent(new KitchenSyncEvent(KitchenSyncEvent.CHILD_COMPLETE, event.timestamp));
}
@@ -20,10 +20,10 @@ package org.as3lib.kitchensync.action
*
* @param target - the AbstractSynchronizedAction that will receive the commands from the controller.
* @param command - the function that the SynchronizedAction will perform when the ActionController executes.
- * @param offset - the number of frames to offset the action.
+ * @param delay - the number of frames to delay the action.
*/
- public function KSActionController (target:AbstractAction, command:ActionControllerCommand = null, offset:* = 0) {
- super(offset, null);
+ public function KSActionController (target:AbstractAction, command:ActionControllerCommand = null, delay:* = 0) {
+ super(delay, null);
if (target) {
_target = target;
} else {
@@ -0,0 +1,57 @@
+package org.as3lib.kitchensync.action
+{
+ import flash.events.*;
+
+ import org.as3lib.kitchensync.core.*;
+
+ public class KSAsynchronousFunction extends KSFunction
+ {
+
+ protected var _completeEventDispatcher:IEventDispatcher;
+ protected var _completeEventType:String;
+
+ public function KSAsynchronousFunction(delay:*, func:Function, completeEventDispatcher:IEventDispatcher, completeEventType:String, ...args)
+ {
+ super(delay, func);
+ this._args = args;
+
+ _completeEventDispatcher = completeEventDispatcher;
+ _completeEventType = completeEventType;
+
+ _completeEventDispatcher.addEventListener(_completeEventType, onFunctionComplete, false, 0, true);
+ }
+
+ /**
+ * Executes the function when the delay has elapsed.
+ */
+ override protected function onUpdate(event:KitchenSyncEvent):void {
+ var time:Timestamp = event.timestamp;
+ if (startTimeHasElapsed) {
+ invoke();
+ unregister();
+ }
+ }
+
+ /**
+ * Event listener that is called when the asyncronous function is completed.
+ */
+ protected function onFunctionComplete(event:Event):void {
+ _completeEventDispatcher.removeEventListener(_completeEventType, onFunctionComplete);
+ complete();
+ }
+
+ override public function clone():AbstractAction {
+ var clone:KSAsynchronousFunction = new KSAsynchronousFunction(_delay, _func, _completeEventDispatcher, _completeEventType);
+ clone._args = _args;
+ clone.duration = _duration;
+ clone.autoDelete = _autoDelete;
+ return clone;
+ }
+
+ override public function kill():void {
+ super.kill();
+ _completeEventDispatcher = null;
+ }
+
+ }
+}
@@ -55,10 +55,10 @@ package org.as3lib.kitchensync.action
* @param event - Can be either an Event object or a String. If event is an Event, that object is used.
* If event is a string, a new event with that type is automatically created.
* @param target - The IEventDispatcher that will dispatch the event. The default is <code>this</code>.
- * @param offset - time to wait before execution
+ * @param delay - time to wait before execution
* @param listeners - Any additional objects passed in will be added as listeners (if they're functions)
*/
- public function KSDispatchEvent(event:*, target:IEventDispatcher = SELF, offset:* = 0, ... listeners) {
+ public function KSDispatchEvent(event:*, target:IEventDispatcher = SELF, delay:* = 0, ... listeners) {
super();
if (event is Event) {
@@ -75,7 +75,7 @@ package org.as3lib.kitchensync.action
_target = target;
}
- this.offset = offset;
+ this.delay = delay;
for (var i:int = 0; i < listeners.length; i++) {
var func:Function = listeners[i] as Function;
@@ -103,7 +103,7 @@ package org.as3lib.kitchensync.action
}
/**
- * When the offset is reached, the event will be fired from the target.
+ * When the delay is reached, the event will be fired from the target.
* Note that if duration is > 0, this will continue to fire for every frame until duration is elapsed.
*/
override protected function onUpdate(event:KitchenSyncEvent):void {
@@ -125,7 +125,7 @@ package org.as3lib.kitchensync.action
}
override public function clone():AbstractAction {
- var clone:KSDispatchEvent = new KSDispatchEvent(_event, _target, _offset);
+ var clone:KSDispatchEvent = new KSDispatchEvent(_event, _target, _delay);
//clone.timeUnit = _timeUnit;
clone.duration = _duration;
clone.autoDelete = _autoDelete;
@@ -28,14 +28,14 @@ package org.as3lib.kitchensync.action
/**
* Constructor.
*
- * @param offset - the number of frames to offset the action
+ * @param delay - the number of frames to delay the action
* @param func - the function or method to call at the specified time
* @param args - the rest of the parameters become arguments passed to the function at the time it's called.
*/
- public function KSFunction(offset:*, func:Function, ... args)
+ public function KSFunction(delay:*, func:Function, ... args)
{
super();
- this.offset = offset;
+ this.delay = delay;
_func = func;
_args = args;
}
@@ -52,7 +52,7 @@ package org.as3lib.kitchensync.action
}
/**
- * Executes the function when the offset has elapsed.
+ * Executes the function when the delay has elapsed.
* If the duration is > 0, it will repeat until the duration has elapsed.
*/
override protected function onUpdate(event:KitchenSyncEvent):void {
@@ -66,7 +66,7 @@ package org.as3lib.kitchensync.action
}
override public function clone():AbstractAction {
- var clone:KSFunction = new KSFunction(_offset, _func);
+ var clone:KSFunction = new KSFunction(_delay, _func);
//clone.timeUnit = _timeUnit;
clone._args = _args;
clone._result = _result;
@@ -5,9 +5,8 @@ package org.as3lib.kitchensync.action
/**
* Tells a target MovieClip to play a specified frame.
*
- * @todo consider expanding this to a MovieClip controller
- * @todo test
*/
+ // todo test
public class KSMovieClipController extends KSFunction
{
protected var _target:MovieClip;
@@ -24,17 +23,17 @@ package org.as3lib.kitchensync.action
/**
* Constructor.
*
- * @param offset - the number of frames to offset the action
+ * @param delay - the number of frames to delay the action
* @param target - the MovieClip whose frames you are going to
* @param frameIdentifier - a String or uint to go to
*/
- public function KSMovieClipController(offset:*, target:MovieClip, frameIdentifier:*)
+ public function KSMovieClipController(delay:*, target:MovieClip, frameIdentifier:*)
{
- super(offset, target.gotoAndPlay, frameIdentifier);
+ super(delay, target.gotoAndPlay, frameIdentifier);
}
override public function clone():AbstractAction {
- var clone:KSMovieClipController = new KSMovieClipController(offset, target, frameIdentifier);
+ var clone:KSMovieClipController = new KSMovieClipController(delay, target, frameIdentifier);
//clone.timeUnit = _timeUnit;
clone._args = _args;
clone._result = _result;
Oops, something went wrong.

0 comments on commit 6a7cede

Please sign in to comment.