From 3ac87296a6ea0002696f2b124cb8b9a706e4716a Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Wed, 30 Jul 2008 01:16:42 +0000 Subject: [PATCH] StatModifier is Streamable, so that we can send stat updates from the game server to the world server git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@689 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../stats/data/IntSetStatAdder.java | 5 +++ .../stats/data/IntStatIncrementer.java | 5 +++ .../threerings/stats/data/StatModifier.java | 31 ++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/stats/data/IntSetStatAdder.java b/src/java/com/threerings/stats/data/IntSetStatAdder.java index dac25d8f..3162d747 100644 --- a/src/java/com/threerings/stats/data/IntSetStatAdder.java +++ b/src/java/com/threerings/stats/data/IntSetStatAdder.java @@ -32,6 +32,11 @@ public class IntSetStatAdder extends StatModifier _value = value; } + /** Constructs an empty IntSetStatAdder (for Streaming purposes). */ + public IntSetStatAdder () + { + } + @Override // from StatModifier public void modify (IntSetStat stat) { diff --git a/src/java/com/threerings/stats/data/IntStatIncrementer.java b/src/java/com/threerings/stats/data/IntStatIncrementer.java index bc296fd0..47c9e0c3 100644 --- a/src/java/com/threerings/stats/data/IntStatIncrementer.java +++ b/src/java/com/threerings/stats/data/IntStatIncrementer.java @@ -32,6 +32,11 @@ public class IntStatIncrementer extends StatModifier _delta = delta; } + /** Constructs an empty IntStatIncrementer (for Streaming purposes). */ + public IntStatIncrementer () + { + } + @Override // from StatModifier public void modify (IntStat stat) { diff --git a/src/java/com/threerings/stats/data/StatModifier.java b/src/java/com/threerings/stats/data/StatModifier.java index 4622336a..c4d484ec 100644 --- a/src/java/com/threerings/stats/data/StatModifier.java +++ b/src/java/com/threerings/stats/data/StatModifier.java @@ -21,13 +21,20 @@ package com.threerings.stats.data; +import java.io.IOException; import java.io.Serializable; +import com.threerings.io.NotStreamable; +import com.threerings.io.ObjectInputStream; +import com.threerings.io.ObjectOutputStream; +import com.threerings.io.Streamable; + /** * Encapsulates a modification to a single stat that can be serialized and sent to a different * server, if needed, to update stats loaded at runtime. */ -public abstract class StatModifier implements Serializable +public abstract class StatModifier + implements Serializable, Streamable { /** * Creates a modifier that will operate on the supplied stat type. Note that this type may be @@ -38,6 +45,11 @@ public abstract class StatModifier implements Serializable _type = type; } + /** Constructs an empty StatModifier (for Streaming purposes). */ + protected StatModifier () + { + } + /** * Returns the {@link Stat.Type} of the stat being modified. */ @@ -46,11 +58,28 @@ public abstract class StatModifier implements Serializable return _type; } + /** Writes our custom streamable fields. */ + public void writeObject (ObjectOutputStream out) + throws IOException + { + out.writeInt(_type.code()); + out.defaultWriteObject(); + } + + /** Reads our custom streamable fields. */ + public void readObject (ObjectInputStream in) + throws IOException, ClassNotFoundException + { + _type = Stat.getType(in.readInt()); + in.defaultReadObject(); + } + /** * Applies the modification to the stat in question. */ public abstract void modify (T stat); /** The type of the stat on which we're operating. */ + @NotStreamable protected Stat.Type _type; }