wyvern.lib.classes.sound
Class LoopingSound

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.StaticObject
              extended bywyvern.lib.classes.sound.LoopingSound
All Implemented Interfaces:
Broadcaster, GameObject, MapPlayerListener, MethodHookable, PropertyList

public class LoopingSound
extends StaticObject
implements MapPlayerListener

A fixed sound source that generates a continous sound for players who are near enough to the source. Examples: a stream, a humming generator, a waterfall, or a jukebox.

You configure it with the following properties:

The property needs to be set before setMap() is called, since its gets cached in instance data for various reasons.

Version:
1.0, Aug 05, 2003
Author:
Steve Yegge

Field Summary
static int DEFAULT_RANGE
          We'll have to tune this number based on playtesting, to see what value works best.
static int ENTERED_AREA
           
static int LEFT_AREA
           
static int MOVED_IN_AREA
           
static int OUT_OF_RANGE
           
 
Fields inherited from class wyvern.kernel.maps.MapObject
IN_MAP_EDITOR, listenerList_
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
LoopingSound()
           
 
Method Summary
static int checkRange(MapPlayerEvent event, int x, int y, int range)
          Returns true if the specified MapPlayerEvent is entirely outside our sound range, so we don't need to process the event.
 double computeGain(Player p, GameMap map)
          Computes the gain level to use for the specified player, based on their distance from the source, and possibly other properties.
 void destroy()
          Turns off the sound if disposed.
 double getGain()
          Returns the gain specified for this sound, when the listener is standing at the source of the sound.
 java.lang.String getID()
          Returns the unique ID for this sound.
 Music getMusic()
          Returns the Music object for this LoopingSound.
 java.lang.String getPath()
          Returns the path to the music file for this sound.
 int getRange()
          Returns the range that this sound should extend before attenuating completely.
protected  void grabProperties()
          Pulls the "music" bean property out of instance data, and stores the sub-properties, so we can do very fast checks in playerEvent.
 void initialize()
          Sets default properties.
 void playerEvent(MapPlayerEvent event)
          Player moved/entered/left/teleported.
 void playForPlayer(Player p)
          Plays the sound for a particular player.
 void remove()
          Removes from map.
 void setMap(GameMap map, int x, int y)
          Registers map-hooks.
 void shutdown()
          Shuts the sound down.
 void startup()
          Starts the sound up.
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMethodHook, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMethodHook, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, runMethodHook, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport, toString, updateMapLocation
 
Methods inherited from class wyvern.kernel.properties.PList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, debugProperties, dismantlePropertyList, getDoubleProperty, getInheritedProperty, getInteger, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProfilingInfo, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface wyvern.lib.PropertyList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, getDoubleProperty, getInheritedProperty, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 

Field Detail

DEFAULT_RANGE

public static final int DEFAULT_RANGE
We'll have to tune this number based on playtesting, to see what value works best. It may be totally dependent on the sound - a harp might have a small range, and a waterfall a very large one. You want the range to be small enough that you can actually hear the sound falling off as you move away from it, even in a small-ish outdoor map.

See Also:
Constant Field Values

OUT_OF_RANGE

public static final int OUT_OF_RANGE
See Also:
Constant Field Values

ENTERED_AREA

public static final int ENTERED_AREA
See Also:
Constant Field Values

LEFT_AREA

public static final int LEFT_AREA
See Also:
Constant Field Values

MOVED_IN_AREA

public static final int MOVED_IN_AREA
See Also:
Constant Field Values
Constructor Detail

LoopingSound

public LoopingSound()
Method Detail

initialize

public void initialize()
Sets default properties.

Specified by:
initialize in interface GameObject
Overrides:
initialize in class StaticObject

setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Registers map-hooks.

Specified by:
setMap in interface GameObject
Overrides:
setMap in class MapObject

remove

public void remove()
Removes from map.

Specified by:
remove in interface GameObject
Overrides:
remove in class MapObject

grabProperties

protected void grabProperties()
Pulls the "music" bean property out of instance data, and stores the sub-properties, so we can do very fast checks in playerEvent.


playerEvent

public void playerEvent(MapPlayerEvent event)
Player moved/entered/left/teleported. Turn the sound on or off for them, or adjust the volume.

Specified by:
playerEvent in interface MapPlayerListener
Parameters:
event - the MapPlayerEvent telling us what happened

getMusic

public Music getMusic()
Returns the Music object for this LoopingSound.


computeGain

public double computeGain(Player p,
                          GameMap map)
Computes the gain level to use for the specified player, based on their distance from the source, and possibly other properties.

Returns:
the gain level (0.0-1.0) to use for the player.

destroy

public void destroy()
Turns off the sound if disposed.

Specified by:
destroy in interface GameObject
Overrides:
destroy in class MapObject

shutdown

public void shutdown()
Shuts the sound down. Stops the sound for all players who can hear it, and stops playing it for new players entering the map or moving in the map.


startup

public void startup()
Starts the sound up. Looks in the sound's map for all the current players, and starts the sound for any of them who are close enough to hear it.


playForPlayer

public void playForPlayer(Player p)
Plays the sound for a particular player. If they move or leave the map, the sound may change volume or stop.

Computes the gain to use for the player based on their distance from the nearest source point. Always passes Music.LOOP_FOREVER to the client for the number of repeats.

If we're not in a map, this method does nothing.

Parameters:
p - the player to start playing the sound for.

Normally you don't need to call this; it's handled automatically if the player is in our map.


getID

public java.lang.String getID()
Returns the unique ID for this sound.

Returns:
the unique ID, which in our case is our hashcode

getGain

public double getGain()
Returns the gain specified for this sound, when the listener is standing at the source of the sound.

Returns:
gain (0.0 to 1.0)

getPath

public java.lang.String getPath()
Returns the path to the music file for this sound.

Returns:
the relative path, including extension, under the Wyvern root

getRange

public int getRange()
Returns the range that this sound should extend before attenuating completely.

Returns:
the radius of the sound

checkRange

public static int checkRange(MapPlayerEvent event,
                             int x,
                             int y,
                             int range)
Returns true if the specified MapPlayerEvent is entirely outside our sound range, so we don't need to process the event.

Parameters:
event - the event
range - the circular radius, from each source point, beyond which the sound is no longer audible.
Returns:
an integer code telling us one of four things.

Returns ENTERED_AREA if either of the following is true:

  • the player entered the map at a point inside our range
  • the player moved or teleported from a point outside our range to a point inside our range.
Returns LEFT_AREA if either of the following is true:
  • the player left the map at a point inside our range
  • the player moved or teleported from a point inside our range to a point outside our range.
Returns MOVED_IN_AREA if the player moved or teleported from a point inside our range to another point inside our range. Returns OUT_OF_RANGE if either of the following is true:
  • the player left the map at a point outside our range
  • the player moved or teleported from a point outside our range to a point inside our range.
I suspect that this code will be useful enough to move into the MapPlayerEvent at some point. You'll call it and tell the event which points you're interested in; it will compute the player's distance from each of those points, and if the player is out of range of ALL of the points, it would return true.