Fixed up a number of TODOs; created a new Wrapped interface to simplify

auto-unwrapping.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4286 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-07-24 19:53:24 +00:00
parent fb532c1349
commit ed1f43bdfc
15 changed files with 107 additions and 50 deletions
@@ -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;
@@ -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;
@@ -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);
@@ -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);
}
}
}
@@ -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;
@@ -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
@@ -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();
}
}
+9 -3
View File
@@ -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 + ")";
+1 -1
View File
@@ -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 {
+8 -2
View File
@@ -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;
}
}
}
+8 -2
View File
@@ -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;
}
}
}
+8 -2
View File
@@ -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
}
}
}
+8 -2
View File
@@ -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;
}
}
}
+13
View File
@@ -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;
}
}
+7 -1
View File
@@ -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;
}
}
}