diff --git a/src/as/com/threerings/crowd/client/LocationDirector.as b/src/as/com/threerings/crowd/client/LocationDirector.as index c29102b10..ce6f7d9fc 100644 --- a/src/as/com/threerings/crowd/client/LocationDirector.as +++ b/src/as/com/threerings/crowd/client/LocationDirector.as @@ -21,6 +21,8 @@ package com.threerings.crowd.client { +import flash.utils.getTimer; // function import + import com.threerings.util.ObserverList; import com.threerings.util.ResultListener; @@ -372,7 +374,7 @@ public class LocationDirector extends BasicDirector */ public function checkRepeatMove () :Boolean { - var now :Number = new Date().getTime(); + var now :Number = getTimer(); if (now - _lastRequestTime < STALE_REQUEST_DURATION) { return true; diff --git a/src/as/com/threerings/presents/client/Client.as b/src/as/com/threerings/presents/client/Client.as index 96cedeefc..94c69f622 100644 --- a/src/as/com/threerings/presents/client/Client.as +++ b/src/as/com/threerings/presents/client/Client.as @@ -292,19 +292,29 @@ public class Client extends EventDispatcher notifyObservers(ClientEvent.CLIENT_FAILED_TO_LOGON, cause); } - // TODO: this should be 'internal' except for a fucking bug with AS3 + /** + * Called by the invocation director when it successfully subscribes + * to the client object immediately following logon. + */ public function gotClientObject (clobj :ClientObject) :void { _clobj = clobj; notifyObservers(ClientEvent.CLIENT_DID_LOGON); } - // TODO: this should be 'internal' except for a fucking bug with AS3 + /** + * Called by the invocation director if it fails to subscribe to the + * client object after logon. + */ public function getClientObjectFailed (cause :Error) :void { notifyObservers(ClientEvent.CLIENT_FAILED_TO_LOGON, cause); } + /** + * Called by the invocation director when it discovers that the client + * object has changed. + */ protected function clientObjectDidChange (clobj :ClientObject) :void { _clobj = clobj; diff --git a/src/as/com/threerings/presents/client/ClientDObjectMgr.as b/src/as/com/threerings/presents/client/ClientDObjectMgr.as index c70b09c22..1d0953bad 100644 --- a/src/as/com/threerings/presents/client/ClientDObjectMgr.as +++ b/src/as/com/threerings/presents/client/ClientDObjectMgr.as @@ -24,6 +24,7 @@ package com.threerings.presents.client { import flash.events.Event; import flash.events.TimerEvent; import flash.utils.Timer; +import flash.utils.getTimer; // function import import mx.collections.IList; @@ -141,22 +142,15 @@ public class ClientDObjectMgr { // if this object has a registered flush delay, don't can it just // yet, just slip it onto the flush queue - var oclass :Class = ClassUtil.getClass(obj); - /* - // TODO - // TODO - for (Iterator iter = _delays.keySet().iterator(); iter.hasNext(); ) { - Class dclass = (Class)iter.next(); - if (dclass.isAssignableFrom(oclass)) { - long expire = System.currentTimeMillis() + - ((Long)_delays.get(dclass)).longValue(); + for each (var dclass :Class in _delays.keys()) { + if (obj is dclass) { + var expire :Number = getTimer() + Number(_delays.get(dclass)); _flushes.put(obj.getOid(), new FlushRecord(obj, expire)); // log.info("Flushing " + obj.getOid() + " at " + // new java.util.Date(expire)); return; } } - */ // if we didn't find a delay registration, flush immediately flushObject(obj); @@ -169,8 +163,7 @@ public class ClientDObjectMgr */ public function registerFlushDelay (objclass :Class, delay :Number) :void { - // TODO - //_delays.put(objclass, new Long(delay)); + _delays.put(objclass, delay); } /** @@ -424,8 +417,8 @@ public class ClientDObjectMgr */ protected function flushObjects (event :TimerEvent) :void { - var now :Number = new Date().getTime(); - for (var oid :String in _flushes.keys()) { + var now :Number = getTimer(); + for each (var oid :int in _flushes.keys()) { var rec :FlushRecord = (_flushes.get(oid) as FlushRecord); if (rec.expire <= now) { _flushes.remove(oid); diff --git a/src/as/com/threerings/presents/client/InvocationDirector.as b/src/as/com/threerings/presents/client/InvocationDirector.as index bea868611..81f638b35 100644 --- a/src/as/com/threerings/presents/client/InvocationDirector.as +++ b/src/as/com/threerings/presents/client/InvocationDirector.as @@ -1,5 +1,7 @@ package com.threerings.presents.client { +import flash.utils.getTimer; // function import + import mx.collections.IViewCursor; import mx.collections.ArrayCollection; @@ -145,7 +147,7 @@ public class InvocationDirector (arg as InvocationMarshaller_ListenerMarshaller); lm.callerOid = _clobj.getOid(); lm.requestId = nextRequestId(); - lm.mapStamp = new Date().getTime(); + lm.mapStamp = getTimer(); // create a mapping for this marshaller so that we can // properly dispatch responses sent to it @@ -218,7 +220,7 @@ public class InvocationDirector } // flush expired listeners periodically - var now :Number = new Date().getTime(); + var now :Number = getTimer(); if (now - _lastFlushTime > LISTENER_FLUSH_INTERVAL) { _lastFlushTime = now; flushListeners(now); @@ -272,11 +274,12 @@ public class InvocationDirector protected function flushListeners (now :Number) :void { var then :Number = now - LISTENER_MAX_AGE; - for (var skey :String in _listeners.keys()) { + for each (var reqId :int in _listeners.keys()) { var lm :InvocationMarshaller_ListenerMarshaller = - (_listeners.get(skey) as InvocationMarshaller_ListenerMarshaller); + (_listeners.get(reqId) as + InvocationMarshaller_ListenerMarshaller); if (lm.mapStamp < then) { - _listeners.remove(skey); + _listeners.remove(reqId); } } } diff --git a/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as b/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as index fb71b5a93..ca5f55bc0 100644 --- a/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as +++ b/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as @@ -3,8 +3,8 @@ package com.threerings.presents.dobj { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; -import com.threerings.util.Integer; import com.threerings.util.StringBuilder; +import com.threerings.util.Wrapped; /** * An attribute changed event is dispatched when a single attribute of a @@ -46,16 +46,7 @@ public class AttributeChangedEvent extends NamedEvent _oldValue = target[_name]; // fucking wack-ass language } - // possibly convert the value - var v :Object = _value; - if (v is Integer) { - v = (v as Integer).value - - } else { - // TODO: more! - } - - target[_name] = v; + target[_name] = _value; return true; } @@ -108,6 +99,11 @@ public class AttributeChangedEvent extends NamedEvent { super.readObject(ins); _value = ins.readObject(); + + // possibly convert the value + if (_value is Wrapped) { + _value = (_value as Wrapped).unwrap(); + } } protected var _value :Object; diff --git a/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as b/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as index 1ae6781e7..a48369412 100644 --- a/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as +++ b/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as @@ -4,6 +4,7 @@ import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.util.StringBuilder; +import com.threerings.util.Wrapped; /** * An element updated event is dispatched when an element of an array @@ -93,6 +94,10 @@ public class ElementUpdatedEvent extends NamedEvent super.readObject(ins); _value = ins.readObject(); _index = ins.readInt(); + + if (_value is Wrapped) { + _value = (_value as Wrapped).unwrap(); + } } // documentation inherited diff --git a/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as b/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as index 1ec9c29dd..8319c3f77 100644 --- a/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as +++ b/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as @@ -3,8 +3,8 @@ package com.threerings.presents.dobj { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; -import com.threerings.util.Integer; import com.threerings.util.StringBuilder; +import com.threerings.util.Wrapped; /** * An entry removed event is dispatched when an entry is removed from a @@ -101,9 +101,8 @@ public class EntryRemovedEvent extends NamedEvent super.readObject(ins); _key = ins.readObject(); - // TODO: for now... - if (_key is Integer) { - _key = (_key as Integer).value; + if (_key is Wrapped) { + _key = (_key as Wrapped).unwrap(); } } diff --git a/src/as/com/threerings/util/Byte.as b/src/as/com/threerings/util/Byte.as index b5a01a71a..41829e1d6 100644 --- a/src/as/com/threerings/util/Byte.as +++ b/src/as/com/threerings/util/Byte.as @@ -4,7 +4,7 @@ package com.threerings.util { * Equivalent to java.lang.Byte. */ public class Byte - implements Equalable + implements Equalable, Wrapped { public var value :int; @@ -18,13 +18,19 @@ public class Byte this.value = value; } - // documentation inherited from interface Equalable + // from Equalable public function equals (other :Object) :Boolean { return (other is Byte) && (value === (other as Byte).value); } - // documentation inherited + // from Wrapped + public function unwrap () :Object + { + return value; + } + + // override public function toString () :String { return "Byte(" + value + ")"; diff --git a/src/as/com/threerings/util/Config.as b/src/as/com/threerings/util/Config.as index b059e1249..4e606a182 100644 --- a/src/as/com/threerings/util/Config.as +++ b/src/as/com/threerings/util/Config.as @@ -71,7 +71,7 @@ public class Config var listener :Function = function (evt :NetStatusEvent) :void { // TODO: as of beta3 there is a bug where the status // is always "SharedObject.Flush.Failed", even on success - //trace("================[" + evt.info.code + "]"); + trace("================[" + evt.info.code + "]"); if ("SharedObject.Flush.Success" == evt.info.code) { rl.requestCompleted(thisConfig); } else { diff --git a/src/as/com/threerings/util/Float.as b/src/as/com/threerings/util/Float.as index 8d08f66ed..79eb0a6f4 100644 --- a/src/as/com/threerings/util/Float.as +++ b/src/as/com/threerings/util/Float.as @@ -4,7 +4,7 @@ package com.threerings.util { * Equivalent to java.lang.Float. */ public class Float - implements Equalable + implements Equalable, Wrapped { public var value :Number; @@ -18,10 +18,16 @@ public class Float this.value = value; } - // documentation inherited from interface Equalable + // from Equalable public function equals (other :Object) :Boolean { return (other is Float) && (value === (other as Float).value); } + + // from Wrapped + public function unwrap () :Object + { + return value; + } } } diff --git a/src/as/com/threerings/util/Integer.as b/src/as/com/threerings/util/Integer.as index e75efbba0..ffd62cb13 100644 --- a/src/as/com/threerings/util/Integer.as +++ b/src/as/com/threerings/util/Integer.as @@ -9,7 +9,7 @@ package com.threerings.util { // Number <--> java.lang.Double. However, a Number object that refers // to an integer value is actually an int. Yes, it's totally fucked. public class Integer - implements Equalable + implements Equalable, Wrapped { public var value :int; @@ -23,10 +23,16 @@ public class Integer this.value = value; } - // documentation inherited from interface Equalable + // from Equalable public function equals (other :Object) :Boolean { return (other is Integer) && (value === (other as Integer).value); } + + // from Wrapped + public function unwrap () :Object + { + return value; + } } } diff --git a/src/as/com/threerings/util/Long.as b/src/as/com/threerings/util/Long.as index 04196d0a7..ac7294568 100644 --- a/src/as/com/threerings/util/Long.as +++ b/src/as/com/threerings/util/Long.as @@ -4,7 +4,7 @@ package com.threerings.util { * Equivalent to java.lang.Long. */ public class Long - implements Equalable + implements Equalable, Wrapped { public var high :int; public var low :int; @@ -20,7 +20,7 @@ public class Long this.high = high; } - // documentation inherited from interface Equalable + // from Equalable public function equals (other :Object) :Boolean { if (!(other is Long)) { @@ -29,5 +29,11 @@ public class Long var that :Long = (other as Long); return (this.high == that.high) && (this.low == that.low); } + + // from Wrapped + public function unwrap () :Object + { + return low; // TODO + } } } diff --git a/src/as/com/threerings/util/Short.as b/src/as/com/threerings/util/Short.as index df0cd8330..70e87f7e4 100644 --- a/src/as/com/threerings/util/Short.as +++ b/src/as/com/threerings/util/Short.as @@ -4,7 +4,7 @@ package com.threerings.util { * Equivalent to java.lang.Short. */ public class Short - implements Equalable + implements Equalable, Wrapped { public var value :int; @@ -18,10 +18,16 @@ public class Short this.value = value; } - // documentation inherited from interface Equalable + // from Equalable public function equals (other :Object) :Boolean { return (other is Short) && (value === (other as Short).value); } + + // from Wrapped + public function unwrap () :Object + { + return value; + } } } diff --git a/src/as/com/threerings/util/Wrapped.as b/src/as/com/threerings/util/Wrapped.as new file mode 100644 index 000000000..d74a7188b --- /dev/null +++ b/src/as/com/threerings/util/Wrapped.as @@ -0,0 +1,13 @@ +package com.threerings.util { + +/** + * An interface implemented by our wrapper classes. + */ +public interface Wrapped +{ + /** + * Return the wrapped value. + */ + function unwrap () :Object; +} +} diff --git a/src/as/com/threerings/util/langBoolean.as b/src/as/com/threerings/util/langBoolean.as index 87d4138ed..d1de815bd 100644 --- a/src/as/com/threerings/util/langBoolean.as +++ b/src/as/com/threerings/util/langBoolean.as @@ -8,7 +8,7 @@ import com.threerings.io.Streamable; * Equivalent to java.lang.Boolean. */ public class langBoolean - implements Equalable, Streamable + implements Equalable, Streamable, Wrapped { public var value :Boolean; @@ -40,5 +40,11 @@ public class langBoolean { value = ins.readBoolean(); } + + // from Wrapped + public function unwrap () :Object + { + return value; + } } }