|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.kernel.maps.AbstractCamera
This class handles much of the overhead of creating a Camera. It registers with the map and collects any changes to the map that happen within its view. Subclasses are responsible for sizing and positioning the camera, and deciding how to pass the map changes to the client.
A Camera registers itself with a map by calling the CameraManager, passing itself and the map with which to register. The mapping of cameras to GameMaps is done externally in the CameraManager to keep the map code independent of the game display engine.
When a camera registers, the CameraManager makes the camera's entire view invalid, and adds the camera to its lists. Whenever a game map is changed, it notifies the CameraManager. The CameraManager remembers that the map is dirty, and the map remembers the change. Whenever a camera moves or resizes, it must inform the CameraManager, so the CameraManager knows what map changes are visible to the camera in its new location.
Periodically, the game Scheduler pauses in its event handling and tells the CameraManager to refresh all the cameras. The Scheduler pauses to make sure the map is in a consistent state when the cameras pull their data from the map.
At refresh-time, the CameraManager goes through its list of dirty maps and processes all the cameras in each map. It figures out which map changes were visible to each camera, and sends the visible changes to those cameras by calling validate().
The changes are sent to the Camera as a matrix the size of the map, where if a bit is set in the matrix, that square was dirty in the map. Each camera implementation will render this information differently: a MapCamera will generate a map-view of the changes, whereas a GroundCamera will check which objects changed, and update the client's ground display.
A camera uses a DisplayPolicy object to gather and filter the map information to be sent to the client. Each camera implementation uses its own DisplayPolicy implementation. The DisplayPolicy is reponsible for using the invalid-rectangles list to pull information from the map and render it suitably for the output display.
An AbstractCamera subclass must do the following:
Field Summary | |
protected Rectangle |
bounds_
|
protected RemoteClient |
client_
|
protected boolean |
completelyInvalid_
|
protected DisplayPolicy |
frame_
|
protected boolean |
hasMoved_
|
protected int |
height_
|
protected int |
left_
|
protected GameMap |
map_
|
protected Player |
player_
|
protected boolean |
ready_
|
protected Dimension |
size_
|
protected int |
top_
|
protected int |
width_
|
protected int |
xoffset_
|
protected int |
yoffset_
|
Constructor Summary | |
AbstractCamera(RemoteClient client,
Player player)
Constructs a new AbstractCamera. |
Method Summary | |
void |
forceInvalidate()
Forces the camera contents to refresh, even if it's already been marked as completely invalid. |
Point |
getCenter()
Returns the center point of the camera view, in map coords. |
DisplayPolicy |
getFrame()
Returns the object used for collecting and filtering the objects sent to the camera by the map. |
GameMap |
getMap()
Returns the map this camera is viewing. |
Player |
getOwner()
Returns the player associated with this camera. |
Point |
getPosition()
Returns the upper-left corner of the camera, in map coords. |
Rectangle |
getViewRect()
Gets the rectangle that this camera is viewing in the map. |
Dimension |
getViewSize()
Returns the width and height of the camera. |
boolean |
hasBeenMoved()
Returns whether the camera has been moved since the last client refresh. |
void |
invalidate()
Markes the camera as dirty (i.e. needing a refresh). |
void |
invalidateNoRayCast()
Forces the camera contents to refresh, but without redoing the visibility model raycasting. |
boolean |
isHandheld()
Returns true if this camera is for a player using a handheld device. |
boolean |
isInvalid()
Returns whether the entire camera is invalid. |
boolean |
isShutDown()
Returns true if this camera has been shut down. |
void |
markReady()
Called by the networking layer when the camera's last request has finished sending over the wire. |
void |
markValid()
Sets the "completely-invalid" flag for the camera. |
void |
move(int xoffset,
int yoffset)
Moves the camera by a relative (x, y) amount without resizing it. |
void |
moveFrame()
|
void |
setHandheld(boolean handheld)
|
void |
setMap(GameMap map,
int x,
int y)
Sets a new map and position for the camera simultaneously. |
void |
setMap(GameMap map,
Point p)
Sets a new map and position for the camera simultaneously. |
void |
setMoved(int xoffset,
int yoffset)
Remembers that the camera has been moved by a small amount, so the client can blit the old contents over. |
void |
setPosition(int x,
int y)
Tells the camera where in the map to view. |
void |
setViewRect(Rectangle r)
Sets the view rectangle to a new position and size. |
void |
setViewSize(int width,
int height)
Resizes the camera view without moving the upper-left corner. |
void |
shutDown()
Turns the camera off (permanently). |
java.lang.String |
toString()
|
protected void |
tryUpdate()
Calls updateClient, and if we succeed, clears the ready flag. |
abstract boolean |
updateClient(DisplayPolicy frame)
This method is called from validate() if the camera has been marked ready via markReady(). |
void |
validate(MapDirtyRegions updates)
Tells the camera to check if it should update itself. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface wyvern.lib.Camera |
makeFrame |
Field Detail |
protected RemoteClient client_
protected Player player_
protected GameMap map_
protected int width_
protected int height_
protected int left_
protected int top_
protected Rectangle bounds_
protected Dimension size_
protected DisplayPolicy frame_
protected volatile boolean completelyInvalid_
protected boolean hasMoved_
protected int xoffset_
protected int yoffset_
protected volatile boolean ready_
Constructor Detail |
public AbstractCamera(RemoteClient client, Player player) throws java.rmi.RemoteException
client
- the RemoteClient to send data toplayer
- the Player this camera is forMethod Detail |
public abstract boolean updateClient(DisplayPolicy frame)
frame
- the frame to gather the data with
public void markReady()
markReady
in interface Camera
public void validate(MapDirtyRegions updates)
Camera
This method is called by the game scheduler thread, via the CameraManager. When this method is called, the CameraManager has determined that some changes have occurred in the map that we're viewing (or that we've marked ourselves dirty). This method is called even if none of those changes are visible (the 'updates' parameter will be null or empty). It's up to this method, or a subclass, to determine whether to do a client update.
The camera doesn't actually pull any data from the map unless it has been marked "ready" by the network output thread. If it's not ready, it just remembers the invalid regions and waits until it's ready again.
validate
in interface Camera
updates
- a MapDirtyRegions that contains a BitMatrix the
size of the map we're viewing, with bits set everywhere there
was a map cell invalidated. Can be null if camera is
completely invalid, in which case it won't be used. Called by
the CameraManager when refreshing the camera.protected void tryUpdate()
public Rectangle getViewRect()
Camera
getViewRect
in interface Camera
public void setViewRect(Rectangle r)
Camera
setViewRect
in interface Camera
r
- the map rectangle to viewpublic void setViewSize(int width, int height)
Camera
setViewSize
in interface Camera
width
- the new view widthheight
- the new view heightpublic Dimension getViewSize()
Camera
getViewSize
in interface Camera
public void setPosition(int x, int y)
Camera
setPosition
in interface Camera
x
- the new map X position for the camera upper-left cornery
- the new map Y position for the camera upper-left cornerpublic Point getPosition()
Camera
getPosition
in interface Camera
public void move(int xoffset, int yoffset)
Camera
move
in interface Camera
xoffset
- the relative X offset to move the camerayoffset
- the relative Y offset to move the camerapublic void setMap(GameMap map, Point p)
Camera
setMap
in interface Camera
map
- the GameMap to viewp
- the map coordinatespublic void setMap(GameMap map, int x, int y)
Camera
setMap
in interface Camera
map
- the GameMap to viewx
- the x position to viewy
- the y position to viewpublic Point getCenter()
Camera
getCenter
in interface Camera
public GameMap getMap()
Camera
getMap
in interface Camera
public Player getOwner()
Camera
getOwner
in interface Camera
public void invalidate()
Camera
invalidate
in interface Camera
public void forceInvalidate()
Camera
forceInvalidate
in interface Camera
public void invalidateNoRayCast()
Camera
invalidateNoRayCast
in interface Camera
public void setMoved(int xoffset, int yoffset)
Camera
setMoved
in interface Camera
public boolean hasBeenMoved()
Camera
hasBeenMoved
in interface Camera
public boolean isInvalid()
Camera
isInvalid
in interface Camera
public void markValid()
Camera
markValid
in interface Camera
public DisplayPolicy getFrame()
Camera
getFrame
in interface Camera
public void moveFrame()
public void shutDown()
Camera
shutDown
in interface Camera
public boolean isShutDown()
Camera
isShutDown
in interface Camera
public boolean isHandheld()
Camera
isHandheld
in interface Camera
public void setHandheld(boolean handheld)
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |