wyvern.kernel.player
Class GroundCamera

java.lang.Object
  extended bywyvern.kernel.maps.AbstractCamera
      extended bywyvern.kernel.player.GroundCamera
All Implemented Interfaces:
Camera, RPCDataSource

public class GroundCamera
extends AbstractCamera

This class implements a camera that views the ground beneath the player, to update the ground-display on the client.

Ground-cameras are pretty simple beasts. They're only interested in what's under the player. They show everything, in the order the objects appear in the map cell. Whenever the player moves, the camera is completely invalidated. The only tricky thing the ground camera does is to examine the lists of objects being sent, and see if exactly one entry is being added, removed, or modified. If so, it sends a RemoteInventory command to add, remove or modify the index in question. This results in a big speedup for handheld clients.

Version:
1.0, Mar 28, 1998
Author:
Steve Yegge

Field Summary
protected  java.util.List lastFrame_
           
 
Fields inherited from class wyvern.kernel.maps.AbstractCamera
bounds_, client_, completelyInvalid_, frame_, hasMoved_, height_, left_, map_, player_, ready_, size_, top_, width_, xoffset_, yoffset_
 
Constructor Summary
GroundCamera(RemoteClient client, Player player)
          Constructs a new GroundCamera for the specified player.
 
Method Summary
protected  void add(GroundFrame frame, int index)
          Adds an item from the new frame at the specified index.
 boolean changesNotVisible(MapDirtyRegions changes)
          Returns true if none of the map changes were visible to us.
 void clearLastFrame()
          Nulls out the lastFrame_ field, which forces the next refresh request to go through, even if the contents haven't changed.
protected  int examineChanges(GroundFrame frame)
          Figures out what's changed since the last frame.
 java.util.List getLastFrame()
          Returns the list of objects that were last sent to the client.
 DisplayPolicy makeFrame()
          Creates an AbstractFrame subclass to use as our DisplayPolicy.
protected  void modify(GroundFrame frame, int index)
          Modifies an item in place.
 void move(int xoffset, int yoffset)
          Makes sure the GroundCamera is invalidated when it moves.
protected  void resendAll(GroundFrame frame)
          Resends the entire new frame to the client.
 void sendEmptyList()
          Sends a blank screen.
 boolean sendInfo(GroundFrame frame)
          Sends the information gathered by the GroundViewer to the client.
 void setMap(GameMap map, int x, int y)
          Sets the map for the camera.
 void setShowingSpells(boolean show)
          Turns the display of spells on or off in the Ground View.
 void setViewRect(Rectangle r)
          Resets the view rectangle; dumps the saved-object list.
 void setViewSize(int w, int h)
          Changes the view size; dumps the saved-object list.
 boolean showingSpells()
          Returns true if we're displaying spells in the ground view.
protected  int tryAdd(java.util.List objects, GroundFrame frame)
          The new list has one more item than the previous list.
protected  int tryModify(java.util.List objects, GroundFrame frame)
          Looks to see if exactly one item was modified since the last send.
protected  int tryRemove(java.util.List objects, GroundFrame frame)
          The new list has one less item than the previous list.
 boolean updateClient(DisplayPolicy frame)
          Sends the current set of map changes to the client.
 boolean updateGroundDisplay(GroundFrame frame)
          Shows what's beneath the player.
 void validate(MapDirtyRegions changes)
          CameraManager tells camera to update itself.
 
Methods inherited from class wyvern.kernel.maps.AbstractCamera
forceInvalidate, getCenter, getFrame, getMap, getOwner, getPosition, getViewRect, getViewSize, hasBeenMoved, invalidate, invalidateNoRayCast, isHandheld, isInvalid, isShutDown, markReady, markValid, moveFrame, setHandheld, setMap, setMoved, setPosition, shutDown, toString, tryUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lastFrame_

protected java.util.List lastFrame_
Constructor Detail

GroundCamera

public GroundCamera(RemoteClient client,
                    Player player)
             throws java.lang.Exception
Constructs a new GroundCamera for the specified player.

Method Detail

validate

public void validate(MapDirtyRegions changes)
CameraManager tells camera to update itself.

Specified by:
validate in interface Camera
Overrides:
validate in class AbstractCamera

changesNotVisible

public boolean changesNotVisible(MapDirtyRegions changes)
Returns true if none of the map changes were visible to us.


updateClient

public boolean updateClient(DisplayPolicy frame)
Sends the current set of map changes to the client.

Specified by:
updateClient in class AbstractCamera
Parameters:
frame - the frame to gather the data
Returns:
true if any data was sent. It's essential that subclasses set this flag correctly for the camera to work properly. If the subclass determines that nothing has changed within the view of the camera, and doesn't make any calls to the RemoteClient as a result, then it should return false.

makeFrame

public DisplayPolicy makeFrame()
Creates an AbstractFrame subclass to use as our DisplayPolicy.

Returns:
the frame implementation we want to use

updateGroundDisplay

public boolean updateGroundDisplay(GroundFrame frame)
                            throws java.lang.Exception
Shows what's beneath the player. Called by updateClient().

Parameters:
frame - the frame this camera has opted to use
Returns:
true if any data was sent
Throws:
java.lang.Exception

sendInfo

public boolean sendInfo(GroundFrame frame)
                 throws java.lang.Exception
Sends the information gathered by the GroundViewer to the client.

Parameters:
frame - the frame we're using
Returns:
true if we actually sent any data
Throws:
java.lang.Exception

resendAll

protected void resendAll(GroundFrame frame)
                  throws java.lang.Exception
Resends the entire new frame to the client.

Parameters:
frame - the new frame
Throws:
java.lang.Exception

examineChanges

protected int examineChanges(GroundFrame frame)
                      throws java.lang.Exception
Figures out what's changed since the last frame. If nothing has changed, we return NO_CHANGE , and don't resend anything. If more than one item has changed, we return RESEND_ALL and resend the whole frame.

If exactly one item has changed, we just resend that one, and we do it from this method (actually from a helper that knows how to add, remove, or modify an item in the list). This situation happens whenever someone drops something or picks it up, so it greatly increases the refresh speed for buying, selling, repairing, and so on, particularly on handheld devices.

Parameters:
frame - the GroundFrame to send
Returns:
NO_CHANGE, RESEND_ALL, or MODIFY
Throws:
java.lang.Exception

tryModify

protected int tryModify(java.util.List objects,
                        GroundFrame frame)
                 throws java.lang.Exception
Looks to see if exactly one item was modified since the last send.

Parameters:
objects - the new list of GroundObjDescriptors in the frame
Returns:
NO_CHANGE if the list hasn't changed. RESEND_ALL if more than one item changed. MODIFY if we modified an item in place.
Throws:
java.lang.Exception

modify

protected void modify(GroundFrame frame,
                      int index)
               throws java.lang.Exception
Modifies an item in place.

Parameters:
frame - the frame containing the new objects in the window
index - the index of the item to resend
Throws:
java.lang.Exception

tryAdd

protected int tryAdd(java.util.List objects,
                     GroundFrame frame)
              throws java.lang.Exception
The new list has one more item than the previous list. Check to see if we just added a single item somewhere in the list.

Parameters:
objects - the new list of GroundObjDescriptors in the frame
Returns:
NO_CHANGE if the list hasn't changed. RESEND_ALL if more than one item changed. MODIFY if we added an item.
Throws:
java.lang.Exception

add

protected void add(GroundFrame frame,
                   int index)
            throws java.lang.Exception
Adds an item from the new frame at the specified index.

Parameters:
frame - the new frame
index - the index at which to add the item
Throws:
java.lang.Exception

tryRemove

protected int tryRemove(java.util.List objects,
                        GroundFrame frame)
                 throws java.lang.Exception
The new list has one less item than the previous list. Check to see if we just removed a single item somewhere in the list.

Parameters:
objects - the new list of GroundObjDescriptors in the frame
Returns:
NO_CHANGE if the list hasn't changed. RESEND_ALL if more than one item changed. MODIFY if we removed an item.
Throws:
java.lang.Exception

sendEmptyList

public void sendEmptyList()
                   throws java.lang.Exception
Sends a blank screen.

Throws:
java.lang.Exception

setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Sets the map for the camera.

Specified by:
setMap in interface Camera
Overrides:
setMap in class AbstractCamera

move

public void move(int xoffset,
                 int yoffset)
Makes sure the GroundCamera is invalidated when it moves.

Specified by:
move in interface Camera
Overrides:
move in class AbstractCamera
Parameters:
xoffset - the map x offset to move by
yoffset - the map y offset to move by

setViewRect

public void setViewRect(Rectangle r)
Resets the view rectangle; dumps the saved-object list.

Specified by:
setViewRect in interface Camera
Overrides:
setViewRect in class AbstractCamera
Parameters:
r - the view rectangle

setViewSize

public void setViewSize(int w,
                        int h)
Changes the view size; dumps the saved-object list.

Specified by:
setViewSize in interface Camera
Overrides:
setViewSize in class AbstractCamera
Parameters:
w - new width
h - new height

getLastFrame

public java.util.List getLastFrame()
Returns the list of objects that were last sent to the client.

Returns:
a list of GroundObjDescriptor objects corresponding to the images & descriptions that were last sent over, in the same order they were sent.

clearLastFrame

public void clearLastFrame()
Nulls out the lastFrame_ field, which forces the next refresh request to go through, even if the contents haven't changed. Used when the client asks to refresh their views.


setShowingSpells

public void setShowingSpells(boolean show)
Turns the display of spells on or off in the Ground View.

Parameters:
show - to show spells in the view.

showingSpells

public boolean showingSpells()
Returns true if we're displaying spells in the ground view. Default is OFF. Settable by the client, by sending a #ground-spells command.

Returns:
true if showing spells.