From 5ed8637ecf837bb42f7960850d92127146064d99 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 24 Feb 2003 18:40:41 +0000 Subject: [PATCH] In order to properly pick up any changes made to ObjectInfo records in our objects array, we have to recreate it completely because objects could become interesting or uninteresting and we'd never know when to remove them from one storage mechanism and stick them in the other. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2289 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/miso/data/MisoScene.java | 7 +++- .../miso/data/SimpleMisoSceneImpl.java | 37 +++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/java/com/threerings/miso/data/MisoScene.java b/src/java/com/threerings/miso/data/MisoScene.java index 44c6bfb77..8e1205449 100644 --- a/src/java/com/threerings/miso/data/MisoScene.java +++ b/src/java/com/threerings/miso/data/MisoScene.java @@ -1,5 +1,5 @@ // -// $Id: MisoScene.java,v 1.2 2003/02/20 00:40:13 ray Exp $ +// $Id: MisoScene.java,v 1.3 2003/02/24 18:40:41 mdb Exp $ package com.threerings.miso.data; @@ -68,7 +68,10 @@ public interface MisoScene public boolean removeObject (ObjectInfo info); /** - * Returns the scene model used by this scene. + * Returns the scene model used by this scene. This is an expensive + * operation as it must recreate the scene model from the (possibly + * changed) runtime data. Thus it should not be called in a normal + * client display and is provided mainly for scene editors and such. */ public MisoSceneModel getSceneModel (); } diff --git a/src/java/com/threerings/miso/data/SimpleMisoSceneImpl.java b/src/java/com/threerings/miso/data/SimpleMisoSceneImpl.java index 72cc27823..6fe74b83a 100644 --- a/src/java/com/threerings/miso/data/SimpleMisoSceneImpl.java +++ b/src/java/com/threerings/miso/data/SimpleMisoSceneImpl.java @@ -1,5 +1,5 @@ // -// $Id: SimpleMisoSceneImpl.java,v 1.1 2003/02/12 05:39:15 mdb Exp $ +// $Id: SimpleMisoSceneImpl.java,v 1.2 2003/02/24 18:40:41 mdb Exp $ package com.threerings.miso.data; @@ -38,7 +38,10 @@ public class SimpleMisoSceneImpl // create display object infos for our interesting objects for (int ii = 0, ll = _model.objectInfo.length; ii < ll; ii++) { - _objects.add(createObjectInfo(_model.objectInfo[ii])); + // replace the object info in our model with the possibly + // expanded derived class + _model.objectInfo[ii] = createObjectInfo(_model.objectInfo[ii]); + _objects.add(_model.objectInfo[ii]); } } @@ -80,7 +83,6 @@ public class SimpleMisoSceneImpl public ObjectInfo addObject (int fqTileId, int x, int y) { ObjectInfo info = createObjectInfo(fqTileId, x, y); - _model.addObject(info); _objects.add(info); return info; } @@ -88,13 +90,40 @@ public class SimpleMisoSceneImpl // documentation inherited from interface public boolean removeObject (ObjectInfo info) { - _model.removeObject(info); return _objects.remove(info); } // documentation inherited from interface public MisoSceneModel getSceneModel () { + // flush our objects list back to the arrays so that we pick up + // any changes made since we created the list from the model + int plain = 0, ocount = _objects.size(); + for (int ii = 0; ii < ocount; ii++) { + ObjectInfo info = (ObjectInfo)_objects.get(ii); + if (!info.isInteresting()) { + plain++; + } + } + + // create new arrays of the appropriate size + _model.objectInfo = new ObjectInfo[ocount-plain]; + _model.objectTileIds = new int[plain]; + _model.objectXs = new short[plain]; + _model.objectYs = new short[plain]; + + // populate those arrays appropriately + for (int cc = 0, pp = 0, ii = 0; cc < ocount; cc++) { + ObjectInfo info = (ObjectInfo)_objects.get(cc); + if (info.isInteresting()) { + _model.objectInfo[ii++] = info; + } else { + _model.objectTileIds[pp] = info.tileId; + _model.objectXs[pp] = (short)info.x; + _model.objectYs[pp++] = (short)info.y; + } + } + return _model; }