From e7379cd41a07097c674e94b6a6b29690f6ede8e8 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Mon, 4 Jun 2007 22:00:48 +0000 Subject: [PATCH] Fixed a bug: the 'old value' of some events were not getting set because the oldValue variable didn't contain UNSET_OLD_VALUE, but rather null because it was set that way in the constructor. Additionally, some of the constructors would only set the old value if it wasn't null, which is also wrong because an old value can easily be null. We could probably just rip apart most of this code, because for the most part events are not constructed on the client anyway. We might be able to get away with just making all the event constructors 0 arg, and then we don't have to worry about UNSET_OLD_VALUE, we just always apply. But let's try to be more similar to the Java code, and so now I emulate multiple constructors by checking how many arguments were provided and not configuring event-specific data if it wasn't actually provided to the constructor. Note: none of this would be necessary if we could just declare a constructor: public function AttributeChangedEvent ( targetOid :int = 0, name :String = null, value :Object = null, oldValue :Object = UNSET_OLD_VALUE); But you can't use constants as the default value in a parameter list (commence being boggled) so we have to use null instead of UNSET_OLD_VALUE as the default value, and then check the 'arguments' special variable to see if someone passed in null or whether it came from the default value. Aiya. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4726 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/dobj/AttributeChangedEvent.as | 8 ++++++-- .../threerings/presents/dobj/ElementUpdatedEvent.as | 8 +++++--- src/as/com/threerings/presents/dobj/EntryAddedEvent.as | 6 +++++- .../com/threerings/presents/dobj/EntryRemovedEvent.as | 6 ++++-- .../com/threerings/presents/dobj/EntryUpdatedEvent.as | 6 ++++-- .../presents/dobj/InvocationNotificationEvent.as | 10 +++++++--- .../threerings/presents/dobj/InvocationRequestEvent.as | 10 +++++++--- .../presents/dobj/InvocationResponseEvent.as | 10 +++++++--- src/as/com/threerings/presents/dobj/MessageEvent.as | 6 +++++- .../com/threerings/presents/dobj/ObjectAddedEvent.as | 6 +++++- .../com/threerings/presents/dobj/ObjectRemovedEvent.as | 6 +++++- src/as/com/threerings/presents/dobj/OidList.as | 8 ++++++++ 12 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as b/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as index 77c93e262..970752eec 100644 --- a/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as +++ b/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as @@ -90,8 +90,12 @@ public class AttributeChangedEvent extends NamedEvent oldValue :Object = null) { super(targetOid, name); - _value = value; - _oldValue = oldValue; + + // only init these values if they were specified + if (arguments.length > 0) { + _value = value; + _oldValue = oldValue; + } } // documentation inherited diff --git a/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as b/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as index 96d162814..20b4c91a6 100644 --- a/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as +++ b/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as @@ -56,11 +56,13 @@ public class ElementUpdatedEvent extends NamedEvent oldValue :Object = null, index :int = 0) { super(targetOid, name); - _value = value; - if (oldValue != null) { + + // only init these values if they were specified + if (arguments.length > 0) { + _value = value; _oldValue = oldValue; + _index = index; } - _index = index; } /** diff --git a/src/as/com/threerings/presents/dobj/EntryAddedEvent.as b/src/as/com/threerings/presents/dobj/EntryAddedEvent.as index f60178749..76b60c7bf 100644 --- a/src/as/com/threerings/presents/dobj/EntryAddedEvent.as +++ b/src/as/com/threerings/presents/dobj/EntryAddedEvent.as @@ -49,7 +49,11 @@ public class EntryAddedEvent extends NamedEvent targetOid :int = 0, name :String = null, entry :DSet_Entry = null) { super(targetOid, name); - _entry = entry; + + // only init these values if they were specified + if (arguments.length > 0) { + _entry = entry; + } } /** diff --git a/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as b/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as index 79bf55d14..4901740be 100644 --- a/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as +++ b/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as @@ -53,8 +53,10 @@ public class EntryRemovedEvent extends NamedEvent oldEntry :DSet_Entry = null) { super(targetOid, name); - _key = key; - if (oldEntry != null) { + + // only init these values if they were specified + if (arguments.length > 0) { + _key = key; _oldEntry = oldEntry; } } diff --git a/src/as/com/threerings/presents/dobj/EntryUpdatedEvent.as b/src/as/com/threerings/presents/dobj/EntryUpdatedEvent.as index ba799462f..b1d311342 100644 --- a/src/as/com/threerings/presents/dobj/EntryUpdatedEvent.as +++ b/src/as/com/threerings/presents/dobj/EntryUpdatedEvent.as @@ -51,8 +51,10 @@ public class EntryUpdatedEvent extends NamedEvent oldEntry :DSet_Entry = null) { super(targetOid, name); - _entry = entry; - if (oldEntry != null) { + + // only init these values if they were specified + if (arguments.length > 0) { + _entry = entry; _oldEntry = oldEntry; } } diff --git a/src/as/com/threerings/presents/dobj/InvocationNotificationEvent.as b/src/as/com/threerings/presents/dobj/InvocationNotificationEvent.as index 665765b43..80b03a1b5 100644 --- a/src/as/com/threerings/presents/dobj/InvocationNotificationEvent.as +++ b/src/as/com/threerings/presents/dobj/InvocationNotificationEvent.as @@ -53,9 +53,13 @@ public class InvocationNotificationEvent extends DEvent args :Array = null) { super(targetOid); - _receiverId = receiverId; - _methodId = methodId; - _args = args; + + // only init these values if they were specified + if (arguments.length > 0) { + _receiverId = receiverId; + _methodId = methodId; + _args = args; + } } /** diff --git a/src/as/com/threerings/presents/dobj/InvocationRequestEvent.as b/src/as/com/threerings/presents/dobj/InvocationRequestEvent.as index 00cac5fd5..48a0f0a89 100644 --- a/src/as/com/threerings/presents/dobj/InvocationRequestEvent.as +++ b/src/as/com/threerings/presents/dobj/InvocationRequestEvent.as @@ -49,9 +49,13 @@ public class InvocationRequestEvent extends DEvent args :Array = null) { super(targetOid); - _invCode = invCode; - _methodId = methodId; - _args = args; + + // only init these values if they were specified + if (arguments.length > 0) { + _invCode = invCode; + _methodId = methodId; + _args = args; + } } /** diff --git a/src/as/com/threerings/presents/dobj/InvocationResponseEvent.as b/src/as/com/threerings/presents/dobj/InvocationResponseEvent.as index f84e1d74d..901eeead7 100644 --- a/src/as/com/threerings/presents/dobj/InvocationResponseEvent.as +++ b/src/as/com/threerings/presents/dobj/InvocationResponseEvent.as @@ -49,9 +49,13 @@ public class InvocationResponseEvent extends DEvent args :Array = null) { super(targetOid); - _requestId = requestId; - _methodId = methodId; - _args = args; + + // only init these values if they were specified + if (arguments.length > 0) { + _requestId = requestId; + _methodId = methodId; + _args = args; + } } /** diff --git a/src/as/com/threerings/presents/dobj/MessageEvent.as b/src/as/com/threerings/presents/dobj/MessageEvent.as index a1b91329b..d20b42fe2 100644 --- a/src/as/com/threerings/presents/dobj/MessageEvent.as +++ b/src/as/com/threerings/presents/dobj/MessageEvent.as @@ -53,7 +53,11 @@ public class MessageEvent extends NamedEvent targetOid :int = 0, name :String = null, args :Array = null) { super(targetOid, name); - _args = args; + + // only init these values if they were specified + if (arguments.length > 0) { + _args = args; + } } /** diff --git a/src/as/com/threerings/presents/dobj/ObjectAddedEvent.as b/src/as/com/threerings/presents/dobj/ObjectAddedEvent.as index 169d98689..f64cb99d9 100644 --- a/src/as/com/threerings/presents/dobj/ObjectAddedEvent.as +++ b/src/as/com/threerings/presents/dobj/ObjectAddedEvent.as @@ -50,7 +50,11 @@ public class ObjectAddedEvent extends NamedEvent targetOid :int = 0, name :String = null, oid :int = 0) { super(targetOid, name); - _oid = oid; + + // only init these values if they were specified + if (arguments.length > 0) { + _oid = oid; + } } /** diff --git a/src/as/com/threerings/presents/dobj/ObjectRemovedEvent.as b/src/as/com/threerings/presents/dobj/ObjectRemovedEvent.as index a94cf6329..538aa89c0 100644 --- a/src/as/com/threerings/presents/dobj/ObjectRemovedEvent.as +++ b/src/as/com/threerings/presents/dobj/ObjectRemovedEvent.as @@ -52,7 +52,11 @@ public class ObjectRemovedEvent extends NamedEvent targetOid :int = 0, name :String = null, oid :int = 0) { super(targetOid, name); - _oid = oid; + + // only init these values if they were specified + if (arguments.length > 0) { + _oid = oid; + } } /** diff --git a/src/as/com/threerings/presents/dobj/OidList.as b/src/as/com/threerings/presents/dobj/OidList.as index 30a92f818..cc3925eeb 100644 --- a/src/as/com/threerings/presents/dobj/OidList.as +++ b/src/as/com/threerings/presents/dobj/OidList.as @@ -104,6 +104,14 @@ public class OidList return _oids[index]; } + /** + * Return a new array containing all the oids in this list. + */ + public function toArray () :Array + { + return _oids.concat(); + } + // documentation inherited from interface Streamable public function writeObject (out :ObjectOutputStream) :void {