From 31d855837aacba22d1f9241722f1427ba3ab006d Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Wed, 30 Jul 2008 00:58:36 +0000 Subject: [PATCH] StatSet.updateStat -> StatSet.syncStat. syncStat() should be called after a stat has been successfully updated in the repository, to keep the in-memory version in sync with the repo changes. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@688 c613c5cb-e716-0410-b11b-feb51c14d237 --- src/java/com/threerings/stats/data/StatSet.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/stats/data/StatSet.java b/src/java/com/threerings/stats/data/StatSet.java index 74f629db..9ea97178 100644 --- a/src/java/com/threerings/stats/data/StatSet.java +++ b/src/java/com/threerings/stats/data/StatSet.java @@ -60,13 +60,18 @@ public final class StatSet extends DSet } /** - * Updates a stat in this set, using the supplied StatModifier. + * Updates a stat in this set, using the supplied StatModifier. This function should + * only be called after a successful stat modification has been made to the StatRepository. + * It will increment the Stat's modCount, and won't set its dirty bit if it's not already + * set, to prevent the Stat from being re-written to the repo unnecessarily. */ @SuppressWarnings("unchecked") - public void updateStat (StatModifier modifier) + public void syncStat (StatModifier modifier) { + boolean wasModified = false; Stat stat = getStat(modifier.getType()); if (stat != null) { + wasModified = stat.isModified(); modifier.modify((T)stat); updateStat(stat); @@ -75,6 +80,9 @@ public final class StatSet extends DSet modifier.modify((T)stat); addStat(stat); } + + stat.setModified(wasModified); + stat.setModCount((byte)((stat.getModCount() + 1) % Byte.MAX_VALUE)); } /**