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:
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
package com.threerings.crowd.client {
|
package com.threerings.crowd.client {
|
||||||
|
|
||||||
|
import flash.utils.getTimer; // function import
|
||||||
|
|
||||||
import com.threerings.util.ObserverList;
|
import com.threerings.util.ObserverList;
|
||||||
import com.threerings.util.ResultListener;
|
import com.threerings.util.ResultListener;
|
||||||
|
|
||||||
@@ -372,7 +374,7 @@ public class LocationDirector extends BasicDirector
|
|||||||
*/
|
*/
|
||||||
public function checkRepeatMove () :Boolean
|
public function checkRepeatMove () :Boolean
|
||||||
{
|
{
|
||||||
var now :Number = new Date().getTime();
|
var now :Number = getTimer();
|
||||||
if (now - _lastRequestTime < STALE_REQUEST_DURATION) {
|
if (now - _lastRequestTime < STALE_REQUEST_DURATION) {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
@@ -292,19 +292,29 @@ public class Client extends EventDispatcher
|
|||||||
notifyObservers(ClientEvent.CLIENT_FAILED_TO_LOGON, cause);
|
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
|
public function gotClientObject (clobj :ClientObject) :void
|
||||||
{
|
{
|
||||||
_clobj = clobj;
|
_clobj = clobj;
|
||||||
notifyObservers(ClientEvent.CLIENT_DID_LOGON);
|
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
|
public function getClientObjectFailed (cause :Error) :void
|
||||||
{
|
{
|
||||||
notifyObservers(ClientEvent.CLIENT_FAILED_TO_LOGON, cause);
|
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
|
protected function clientObjectDidChange (clobj :ClientObject) :void
|
||||||
{
|
{
|
||||||
_clobj = clobj;
|
_clobj = clobj;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ package com.threerings.presents.client {
|
|||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import flash.events.TimerEvent;
|
import flash.events.TimerEvent;
|
||||||
import flash.utils.Timer;
|
import flash.utils.Timer;
|
||||||
|
import flash.utils.getTimer; // function import
|
||||||
|
|
||||||
import mx.collections.IList;
|
import mx.collections.IList;
|
||||||
|
|
||||||
@@ -141,22 +142,15 @@ public class ClientDObjectMgr
|
|||||||
{
|
{
|
||||||
// if this object has a registered flush delay, don't can it just
|
// if this object has a registered flush delay, don't can it just
|
||||||
// yet, just slip it onto the flush queue
|
// yet, just slip it onto the flush queue
|
||||||
var oclass :Class = ClassUtil.getClass(obj);
|
for each (var dclass :Class in _delays.keys()) {
|
||||||
/*
|
if (obj is dclass) {
|
||||||
// TODO
|
var expire :Number = getTimer() + Number(_delays.get(dclass));
|
||||||
// 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();
|
|
||||||
_flushes.put(obj.getOid(), new FlushRecord(obj, expire));
|
_flushes.put(obj.getOid(), new FlushRecord(obj, expire));
|
||||||
// log.info("Flushing " + obj.getOid() + " at " +
|
// log.info("Flushing " + obj.getOid() + " at " +
|
||||||
// new java.util.Date(expire));
|
// new java.util.Date(expire));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// if we didn't find a delay registration, flush immediately
|
// if we didn't find a delay registration, flush immediately
|
||||||
flushObject(obj);
|
flushObject(obj);
|
||||||
@@ -169,8 +163,7 @@ public class ClientDObjectMgr
|
|||||||
*/
|
*/
|
||||||
public function registerFlushDelay (objclass :Class, delay :Number) :void
|
public function registerFlushDelay (objclass :Class, delay :Number) :void
|
||||||
{
|
{
|
||||||
// TODO
|
_delays.put(objclass, delay);
|
||||||
//_delays.put(objclass, new Long(delay));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -424,8 +417,8 @@ public class ClientDObjectMgr
|
|||||||
*/
|
*/
|
||||||
protected function flushObjects (event :TimerEvent) :void
|
protected function flushObjects (event :TimerEvent) :void
|
||||||
{
|
{
|
||||||
var now :Number = new Date().getTime();
|
var now :Number = getTimer();
|
||||||
for (var oid :String in _flushes.keys()) {
|
for each (var oid :int in _flushes.keys()) {
|
||||||
var rec :FlushRecord = (_flushes.get(oid) as FlushRecord);
|
var rec :FlushRecord = (_flushes.get(oid) as FlushRecord);
|
||||||
if (rec.expire <= now) {
|
if (rec.expire <= now) {
|
||||||
_flushes.remove(oid);
|
_flushes.remove(oid);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.threerings.presents.client {
|
package com.threerings.presents.client {
|
||||||
|
|
||||||
|
import flash.utils.getTimer; // function import
|
||||||
|
|
||||||
import mx.collections.IViewCursor;
|
import mx.collections.IViewCursor;
|
||||||
import mx.collections.ArrayCollection;
|
import mx.collections.ArrayCollection;
|
||||||
|
|
||||||
@@ -145,7 +147,7 @@ public class InvocationDirector
|
|||||||
(arg as InvocationMarshaller_ListenerMarshaller);
|
(arg as InvocationMarshaller_ListenerMarshaller);
|
||||||
lm.callerOid = _clobj.getOid();
|
lm.callerOid = _clobj.getOid();
|
||||||
lm.requestId = nextRequestId();
|
lm.requestId = nextRequestId();
|
||||||
lm.mapStamp = new Date().getTime();
|
lm.mapStamp = getTimer();
|
||||||
|
|
||||||
// create a mapping for this marshaller so that we can
|
// create a mapping for this marshaller so that we can
|
||||||
// properly dispatch responses sent to it
|
// properly dispatch responses sent to it
|
||||||
@@ -218,7 +220,7 @@ public class InvocationDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
// flush expired listeners periodically
|
// flush expired listeners periodically
|
||||||
var now :Number = new Date().getTime();
|
var now :Number = getTimer();
|
||||||
if (now - _lastFlushTime > LISTENER_FLUSH_INTERVAL) {
|
if (now - _lastFlushTime > LISTENER_FLUSH_INTERVAL) {
|
||||||
_lastFlushTime = now;
|
_lastFlushTime = now;
|
||||||
flushListeners(now);
|
flushListeners(now);
|
||||||
@@ -272,11 +274,12 @@ public class InvocationDirector
|
|||||||
protected function flushListeners (now :Number) :void
|
protected function flushListeners (now :Number) :void
|
||||||
{
|
{
|
||||||
var then :Number = now - LISTENER_MAX_AGE;
|
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 =
|
var lm :InvocationMarshaller_ListenerMarshaller =
|
||||||
(_listeners.get(skey) as InvocationMarshaller_ListenerMarshaller);
|
(_listeners.get(reqId) as
|
||||||
|
InvocationMarshaller_ListenerMarshaller);
|
||||||
if (lm.mapStamp < then) {
|
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.ObjectInputStream;
|
||||||
import com.threerings.io.ObjectOutputStream;
|
import com.threerings.io.ObjectOutputStream;
|
||||||
|
|
||||||
import com.threerings.util.Integer;
|
|
||||||
import com.threerings.util.StringBuilder;
|
import com.threerings.util.StringBuilder;
|
||||||
|
import com.threerings.util.Wrapped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An attribute changed event is dispatched when a single attribute of a
|
* 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
|
_oldValue = target[_name]; // fucking wack-ass language
|
||||||
}
|
}
|
||||||
|
|
||||||
// possibly convert the value
|
target[_name] = _value;
|
||||||
var v :Object = _value;
|
|
||||||
if (v is Integer) {
|
|
||||||
v = (v as Integer).value
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// TODO: more!
|
|
||||||
}
|
|
||||||
|
|
||||||
target[_name] = v;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +99,11 @@ public class AttributeChangedEvent extends NamedEvent
|
|||||||
{
|
{
|
||||||
super.readObject(ins);
|
super.readObject(ins);
|
||||||
_value = ins.readObject();
|
_value = ins.readObject();
|
||||||
|
|
||||||
|
// possibly convert the value
|
||||||
|
if (_value is Wrapped) {
|
||||||
|
_value = (_value as Wrapped).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected var _value :Object;
|
protected var _value :Object;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.threerings.io.ObjectInputStream;
|
|||||||
import com.threerings.io.ObjectOutputStream;
|
import com.threerings.io.ObjectOutputStream;
|
||||||
|
|
||||||
import com.threerings.util.StringBuilder;
|
import com.threerings.util.StringBuilder;
|
||||||
|
import com.threerings.util.Wrapped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An element updated event is dispatched when an element of an array
|
* An element updated event is dispatched when an element of an array
|
||||||
@@ -93,6 +94,10 @@ public class ElementUpdatedEvent extends NamedEvent
|
|||||||
super.readObject(ins);
|
super.readObject(ins);
|
||||||
_value = ins.readObject();
|
_value = ins.readObject();
|
||||||
_index = ins.readInt();
|
_index = ins.readInt();
|
||||||
|
|
||||||
|
if (_value is Wrapped) {
|
||||||
|
_value = (_value as Wrapped).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package com.threerings.presents.dobj {
|
|||||||
import com.threerings.io.ObjectInputStream;
|
import com.threerings.io.ObjectInputStream;
|
||||||
import com.threerings.io.ObjectOutputStream;
|
import com.threerings.io.ObjectOutputStream;
|
||||||
|
|
||||||
import com.threerings.util.Integer;
|
|
||||||
import com.threerings.util.StringBuilder;
|
import com.threerings.util.StringBuilder;
|
||||||
|
import com.threerings.util.Wrapped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An entry removed event is dispatched when an entry is removed from a
|
* 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);
|
super.readObject(ins);
|
||||||
_key = ins.readObject();
|
_key = ins.readObject();
|
||||||
|
|
||||||
// TODO: for now...
|
if (_key is Wrapped) {
|
||||||
if (_key is Integer) {
|
_key = (_key as Wrapped).unwrap();
|
||||||
_key = (_key as Integer).value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package com.threerings.util {
|
|||||||
* Equivalent to java.lang.Byte.
|
* Equivalent to java.lang.Byte.
|
||||||
*/
|
*/
|
||||||
public class Byte
|
public class Byte
|
||||||
implements Equalable
|
implements Equalable, Wrapped
|
||||||
{
|
{
|
||||||
public var value :int;
|
public var value :int;
|
||||||
|
|
||||||
@@ -18,13 +18,19 @@ public class Byte
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Equalable
|
// from Equalable
|
||||||
public function equals (other :Object) :Boolean
|
public function equals (other :Object) :Boolean
|
||||||
{
|
{
|
||||||
return (other is Byte) && (value === (other as Byte).value);
|
return (other is Byte) && (value === (other as Byte).value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// from Wrapped
|
||||||
|
public function unwrap () :Object
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// override
|
||||||
public function toString () :String
|
public function toString () :String
|
||||||
{
|
{
|
||||||
return "Byte(" + value + ")";
|
return "Byte(" + value + ")";
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class Config
|
|||||||
var listener :Function = function (evt :NetStatusEvent) :void {
|
var listener :Function = function (evt :NetStatusEvent) :void {
|
||||||
// TODO: as of beta3 there is a bug where the status
|
// TODO: as of beta3 there is a bug where the status
|
||||||
// is always "SharedObject.Flush.Failed", even on success
|
// is always "SharedObject.Flush.Failed", even on success
|
||||||
//trace("================[" + evt.info.code + "]");
|
trace("================[" + evt.info.code + "]");
|
||||||
if ("SharedObject.Flush.Success" == evt.info.code) {
|
if ("SharedObject.Flush.Success" == evt.info.code) {
|
||||||
rl.requestCompleted(thisConfig);
|
rl.requestCompleted(thisConfig);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package com.threerings.util {
|
|||||||
* Equivalent to java.lang.Float.
|
* Equivalent to java.lang.Float.
|
||||||
*/
|
*/
|
||||||
public class Float
|
public class Float
|
||||||
implements Equalable
|
implements Equalable, Wrapped
|
||||||
{
|
{
|
||||||
public var value :Number;
|
public var value :Number;
|
||||||
|
|
||||||
@@ -18,10 +18,16 @@ public class Float
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Equalable
|
// from Equalable
|
||||||
public function equals (other :Object) :Boolean
|
public function equals (other :Object) :Boolean
|
||||||
{
|
{
|
||||||
return (other is Float) && (value === (other as Float).value);
|
return (other is Float) && (value === (other as Float).value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from Wrapped
|
||||||
|
public function unwrap () :Object
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ package com.threerings.util {
|
|||||||
// Number <--> java.lang.Double. However, a Number object that refers
|
// Number <--> java.lang.Double. However, a Number object that refers
|
||||||
// to an integer value is actually an int. Yes, it's totally fucked.
|
// to an integer value is actually an int. Yes, it's totally fucked.
|
||||||
public class Integer
|
public class Integer
|
||||||
implements Equalable
|
implements Equalable, Wrapped
|
||||||
{
|
{
|
||||||
public var value :int;
|
public var value :int;
|
||||||
|
|
||||||
@@ -23,10 +23,16 @@ public class Integer
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Equalable
|
// from Equalable
|
||||||
public function equals (other :Object) :Boolean
|
public function equals (other :Object) :Boolean
|
||||||
{
|
{
|
||||||
return (other is Integer) && (value === (other as Integer).value);
|
return (other is Integer) && (value === (other as Integer).value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from Wrapped
|
||||||
|
public function unwrap () :Object
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package com.threerings.util {
|
|||||||
* Equivalent to java.lang.Long.
|
* Equivalent to java.lang.Long.
|
||||||
*/
|
*/
|
||||||
public class Long
|
public class Long
|
||||||
implements Equalable
|
implements Equalable, Wrapped
|
||||||
{
|
{
|
||||||
public var high :int;
|
public var high :int;
|
||||||
public var low :int;
|
public var low :int;
|
||||||
@@ -20,7 +20,7 @@ public class Long
|
|||||||
this.high = high;
|
this.high = high;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Equalable
|
// from Equalable
|
||||||
public function equals (other :Object) :Boolean
|
public function equals (other :Object) :Boolean
|
||||||
{
|
{
|
||||||
if (!(other is Long)) {
|
if (!(other is Long)) {
|
||||||
@@ -29,5 +29,11 @@ public class Long
|
|||||||
var that :Long = (other as Long);
|
var that :Long = (other as Long);
|
||||||
return (this.high == that.high) && (this.low == that.low);
|
return (this.high == that.high) && (this.low == that.low);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from Wrapped
|
||||||
|
public function unwrap () :Object
|
||||||
|
{
|
||||||
|
return low; // TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package com.threerings.util {
|
|||||||
* Equivalent to java.lang.Short.
|
* Equivalent to java.lang.Short.
|
||||||
*/
|
*/
|
||||||
public class Short
|
public class Short
|
||||||
implements Equalable
|
implements Equalable, Wrapped
|
||||||
{
|
{
|
||||||
public var value :int;
|
public var value :int;
|
||||||
|
|
||||||
@@ -18,10 +18,16 @@ public class Short
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Equalable
|
// from Equalable
|
||||||
public function equals (other :Object) :Boolean
|
public function equals (other :Object) :Boolean
|
||||||
{
|
{
|
||||||
return (other is Short) && (value === (other as Short).value);
|
return (other is Short) && (value === (other as Short).value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from Wrapped
|
||||||
|
public function unwrap () :Object
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import com.threerings.io.Streamable;
|
|||||||
* Equivalent to java.lang.Boolean.
|
* Equivalent to java.lang.Boolean.
|
||||||
*/
|
*/
|
||||||
public class langBoolean
|
public class langBoolean
|
||||||
implements Equalable, Streamable
|
implements Equalable, Streamable, Wrapped
|
||||||
{
|
{
|
||||||
public var value :Boolean;
|
public var value :Boolean;
|
||||||
|
|
||||||
@@ -40,5 +40,11 @@ public class langBoolean
|
|||||||
{
|
{
|
||||||
value = ins.readBoolean();
|
value = ins.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from Wrapped
|
||||||
|
public function unwrap () :Object
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user