com.threerings.tudey.data
Class TudeySceneModel

java.lang.Object
  extended by com.threerings.io.SimpleStreamableObject
      extended by com.threerings.whirled.data.SceneModel
          extended by com.threerings.tudey.data.TudeySceneModel
All Implemented Interfaces:
Exportable, com.threerings.io.Streamable, ActorAdvancer.Environment, Cloneable

public class TudeySceneModel
extends com.threerings.whirled.data.SceneModel
implements ActorAdvancer.Environment, Exportable

Contains a representation of a Tudey scene.


Nested Class Summary
static class TudeySceneModel.AreaEntry
          An area entry.
static class TudeySceneModel.Entry
          An entry in the scene.
static class TudeySceneModel.GlobalEntry
          A global entry.
static class TudeySceneModel.IdEntry
          An entry identified by an integer id.
static interface TudeySceneModel.LayerObserver
          An extended Observer interface for observers interested in layers.
static interface TudeySceneModel.Observer
          An interface for objects interested in changes to the scene model.
static class TudeySceneModel.Paint
          Contains information on a painted location.
static class TudeySceneModel.PathEntry
          A path entry.
static class TudeySceneModel.PlaceableEntry
          A placeable entry.
static class TudeySceneModel.TileEntry
          A tile entry.
static class TudeySceneModel.Vertex
          Represents a single vertex in a path or area.
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Field Summary
 
Fields inherited from class com.threerings.whirled.data.SceneModel
auxModels, name, sceneId, version
 
Constructor Summary
TudeySceneModel()
          Creates a new, empty scene model.
 
Method Summary
 boolean addEntry(TudeySceneModel.Entry entry)
          Adds an entry to the scene, assigning it a unique id in the process if it is an TudeySceneModel.IdEntry.
 boolean addEntry(TudeySceneModel.Entry entry, boolean assignId)
          Adds an entry to the scene.
 int addLayer(String n)
          Deprecated. 
 int addLayer(String name, int position)
          Add a new layer to the model.
 void addObserver(TudeySceneModel.Observer observer)
          Adds an observer for scene changes.
 void clearPaint()
          Clears all paint from the scene.
 TudeySceneModel clone()
           
 boolean collides(Actor actor, Shape shape)
          Checks the specified actor for a collision with the environment.
 boolean collides(int mask, Shape shape)
          Checks the specified mask for a collision with the environment.
 boolean containsEntry(Object key)
          Determines whether the scene contains an entry with the supplied key.
 CoordIntMap getCollisionFlags()
          Returns a reference to the map containing the tile collision flags.
 ConfigManager getConfigManager()
          Returns a reference to the scene's configuration manager.
 byte[] getData()
          Returns the cached exported binary representation of the model.
 Map<Object,SpaceElement> getElements()
          Returns a reference to the map from entry key to space elements.
 Collection<TudeySceneModel.Entry> getEntries()
          Returns a reference to the collection of entries.
 void getEntries(Shape shape, Collection<TudeySceneModel.Entry> results)
          Retrieves all entries intersecting the supplied shape.
 void getEntries(Shape shape, Predicate<? super TudeySceneModel.Entry> pred, Collection<TudeySceneModel.Entry> results)
          Retrieves all entries intersecting the supplied shape and matching the predicate.
 TudeySceneModel.Entry getEntry(Object key)
          Looks up the entry with the supplied key.
 int getLayer(Object key)
          Get the layer of the entry with the specified key.
 List<String> getLayers()
          Get the layer names.
 String getNotes()
          Returns the scene notes.
 TudeySceneModel.Paint getPaint(int x, int y)
          Returns the paint at the specified coordinates, if any.
 boolean getPenetration(Actor actor, Shape shape, Vector2f result)
          Checks whether the actor is colliding with anything and, if it is, populates the provided object with the penetration vector (the minimum translation required to cancel the penetration).
 TudeySceneConfig getPlaceConfig()
          Returns a reference to the model's place config.
 void getPreloads(PreloadableSet preloads)
          Adds the resources to preload for this scene model to the supplied set.
 void getResources(Set<String> paths)
          Adds the resources referenced by this scene model to the supplied set.
 TudeySceneModel getSceneModel()
          Returns a reference to the scene model.
 Space getSpace()
          Returns a reference to the space containing the (non-tile) entry elements.
 List<TudeySceneModel.Entry> getTaggedEntries(String tag)
          Returns the list of all entries bearing the specified tag, or null for none.
 TudeySceneModel.Entry getTaggedEntry(String tag)
          Returns the first entry bearing the specified tag, or null for none.
 int getTileElevation(int x, int y)
          Returns the tile elevation at the specified coordinates, or Integer.MIN_VALUE if there is no tile there.
 void getTileEntries(Rectangle region, Collection<TudeySceneModel.TileEntry> results)
          Retrieves all of the tile entries intersecting the supplied region.
 TudeySceneModel.TileEntry getTileEntry(int x, int y)
          Returns the tile entry intersecting the specified coordinates, if any.
 void init(ConfigManager cfgmgr)
          Initializes the model.
 void invalidate()
          Invalidates any cached data in the model, forcing it to be recreated (and sets the dirty flag).
 boolean isDirty()
          Returns the value of the dirty flag.
 boolean isLayerEmpty(int layer)
          Return true if the specified layer not 0 and is empty.
 void readFields(Importer in)
          Custom field read method.
 void readObject(com.threerings.io.ObjectInputStream in)
          Custom read method for streaming.
 TudeySceneModel.Entry removeEntry(Object key)
          Removes an entry from the scene.
 void removeLayer(int layer)
          Remove the specified layer, moving anything present to the base layer.
 void removeObserver(TudeySceneModel.Observer observer)
          Removes a scene observer.
 void renameLayer(int layer, String name)
          Rename one of the layers.
 void setDirty(boolean dirty)
          Sets the value of the dirty flag.
 void setLayer(Object key, int layer)
          Set the layer of the entry with the specified key.
 void setName(String name)
          Sets the scene's name and invalidates.
 void setNotes(String notes)
          Sets the scene notes.
 TudeySceneModel.Paint setPaint(int x, int y, TudeySceneModel.Paint paint)
          Sets the paint at the specified coordinates.
 void setPlaceConfig(TudeySceneConfig config)
          Sets the place config for the model.
 TudeySceneModel.Entry updateEntry(TudeySceneModel.Entry nentry)
          Updates an entry within the scene.
 boolean validateReferences(String where, PrintStream out)
          Validates the references in the scene.
 void writeFields(Exporter out)
          Custom field write method.
 void writeObject(com.threerings.io.ObjectOutputStream out)
          Custom write method for streaming.
 
Methods inherited from class com.threerings.whirled.data.SceneModel
addAuxModel, blankSceneModel
 
Methods inherited from class com.threerings.io.SimpleStreamableObject
toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TudeySceneModel

public TudeySceneModel()
Creates a new, empty scene model.

Method Detail

init

public void init(ConfigManager cfgmgr)
Initializes the model.


getConfigManager

public ConfigManager getConfigManager()
Returns a reference to the scene's configuration manager.


addObserver

public void addObserver(TudeySceneModel.Observer observer)
Adds an observer for scene changes.


removeObserver

public void removeObserver(TudeySceneModel.Observer observer)
Removes a scene observer.


setName

public void setName(String name)
Sets the scene's name and invalidates.


setNotes

public void setNotes(String notes)
Sets the scene notes.


getNotes

public String getNotes()
Returns the scene notes.


setPlaceConfig

public void setPlaceConfig(TudeySceneConfig config)
Sets the place config for the model.


getPlaceConfig

public TudeySceneConfig getPlaceConfig()
Returns a reference to the model's place config.


getCollisionFlags

public CoordIntMap getCollisionFlags()
Returns a reference to the map containing the tile collision flags.


getSpace

public Space getSpace()
Returns a reference to the space containing the (non-tile) entry elements.


getElements

public Map<Object,SpaceElement> getElements()
Returns a reference to the map from entry key to space elements.


addEntry

public boolean addEntry(TudeySceneModel.Entry entry)
Adds an entry to the scene, assigning it a unique id in the process if it is an TudeySceneModel.IdEntry.

Returns:
true if the entry was successfully added, false if there was already an entry with the same key (in which case a warning will be logged).

addEntry

public boolean addEntry(TudeySceneModel.Entry entry,
                        boolean assignId)
Adds an entry to the scene.

Parameters:
assignId - if true and the entry is an TudeySceneModel.IdEntry, assign a unique id to the entry.
Returns:
true if the entry was successfully added, false if there was already an entry with the same id (in which case a warning will be logged).

updateEntry

public TudeySceneModel.Entry updateEntry(TudeySceneModel.Entry nentry)
Updates an entry within the scene.

Returns:
a reference to the entry that was replaced, or null for none (in which case a warning will be logged).

removeEntry

public TudeySceneModel.Entry removeEntry(Object key)
Removes an entry from the scene.

Returns:
a reference to the entry that was removed, or null for none (in which case a warning will be logged).

containsEntry

public boolean containsEntry(Object key)
Determines whether the scene contains an entry with the supplied key.


getEntry

public TudeySceneModel.Entry getEntry(Object key)
Looks up the entry with the supplied key.

Returns:
a reference to the identified entry, or null if not found.

getTaggedEntry

public TudeySceneModel.Entry getTaggedEntry(String tag)
Returns the first entry bearing the specified tag, or null for none.


getTaggedEntries

public List<TudeySceneModel.Entry> getTaggedEntries(String tag)
Returns the list of all entries bearing the specified tag, or null for none.


getEntries

public Collection<TudeySceneModel.Entry> getEntries()
Returns a reference to the collection of entries.


getEntries

public void getEntries(Shape shape,
                       Collection<TudeySceneModel.Entry> results)
Retrieves all entries intersecting the supplied shape.


getEntries

public void getEntries(Shape shape,
                       Predicate<? super TudeySceneModel.Entry> pred,
                       Collection<TudeySceneModel.Entry> results)
Retrieves all entries intersecting the supplied shape and matching the predicate.


getTileEntries

public void getTileEntries(Rectangle region,
                           Collection<TudeySceneModel.TileEntry> results)
Retrieves all of the tile entries intersecting the supplied region.


getTileEntry

public TudeySceneModel.TileEntry getTileEntry(int x,
                                              int y)
Returns the tile entry intersecting the specified coordinates, if any.


getTileElevation

public int getTileElevation(int x,
                            int y)
Returns the tile elevation at the specified coordinates, or Integer.MIN_VALUE if there is no tile there.


addLayer

public int addLayer(String name,
                    int position)
Add a new layer to the model.


addLayer

@Deprecated
public int addLayer(String n)
Deprecated. 


renameLayer

public void renameLayer(int layer,
                        String name)
Rename one of the layers.


getLayers

public List<String> getLayers()
Get the layer names. Layer 0, always present, is named ""


isLayerEmpty

public boolean isLayerEmpty(int layer)
Return true if the specified layer not 0 and is empty.


removeLayer

public void removeLayer(int layer)
Remove the specified layer, moving anything present to the base layer.


getLayer

public int getLayer(Object key)
Get the layer of the entry with the specified key.


setLayer

public void setLayer(Object key,
                     int layer)
Set the layer of the entry with the specified key.


setPaint

public TudeySceneModel.Paint setPaint(int x,
                                      int y,
                                      TudeySceneModel.Paint paint)
Sets the paint at the specified coordinates.

Returns:
the previous paint at the coordinates, if any.

getPaint

public TudeySceneModel.Paint getPaint(int x,
                                      int y)
Returns the paint at the specified coordinates, if any.


clearPaint

public void clearPaint()
Clears all paint from the scene.


getPreloads

public void getPreloads(PreloadableSet preloads)
Adds the resources to preload for this scene model to the supplied set.


getResources

public void getResources(Set<String> paths)
Adds the resources referenced by this scene model to the supplied set.


validateReferences

public boolean validateReferences(String where,
                                  PrintStream out)
Validates the references in the scene.


writeFields

public void writeFields(Exporter out)
                 throws IOException
Custom field write method.

Throws:
IOException

readFields

public void readFields(Importer in)
                throws IOException
Custom field read method.

Throws:
IOException

writeObject

public void writeObject(com.threerings.io.ObjectOutputStream out)
                 throws IOException
Custom write method for streaming.

Throws:
IOException

readObject

public void readObject(com.threerings.io.ObjectInputStream in)
                throws IOException
Custom read method for streaming.

Throws:
IOException

getData

public byte[] getData()
Returns the cached exported binary representation of the model.


invalidate

public void invalidate()
Invalidates any cached data in the model, forcing it to be recreated (and sets the dirty flag).


setDirty

public void setDirty(boolean dirty)
Sets the value of the dirty flag.


isDirty

public boolean isDirty()
Returns the value of the dirty flag.


collides

public boolean collides(Actor actor,
                        Shape shape)
Checks the specified actor for a collision with the environment.

Specified by:
collides in interface ActorAdvancer.Environment

collides

public boolean collides(int mask,
                        Shape shape)
Checks the specified mask for a collision with the environment.


getSceneModel

public TudeySceneModel getSceneModel()
Description copied from interface: ActorAdvancer.Environment
Returns a reference to the scene model.

Specified by:
getSceneModel in interface ActorAdvancer.Environment

getPenetration

public boolean getPenetration(Actor actor,
                              Shape shape,
                              Vector2f result)
Description copied from interface: ActorAdvancer.Environment
Checks whether the actor is colliding with anything and, if it is, populates the provided object with the penetration vector (the minimum translation required to cancel the penetration).

Specified by:
getPenetration in interface ActorAdvancer.Environment
Returns:
true if a collision was detected (in which case the result vector will be populated), false otherwise.

clone

public TudeySceneModel clone()
Overrides:
clone in class com.threerings.whirled.data.SceneModel


Copyright © 2011. All Rights Reserved.