|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.kernel.maps.Frame
This is the DisplayPolicy implementation that handles sending map updates to the client map view. Each MapCamera in the game has one Frame object (at a time) for gathering the updates.
When it's time to gather the frame data, a DisplayPolicy is given a set of invalid map rectangles. It's the DisplayPolicy's responsibility to query the map for the information needed to generate a "snapshot" of the map for the client.
This DisplayPolicy implementation gets all the map objects in its invalid regions and sorts them into "buckets" based on their DrawingLayer properties. The Frame decides how many objects in each layer to send to the client. For some layers it may be only one; for other layers it may choose to send 2 or more objects per cell.
The Frame will provide a mechanism for "input filters" to filter the object stream coming from the map. This is the way, for example, that the visibility and lighting-model computations are merged into the data that goes to the client.
Nested Class Summary | |
protected class |
Frame.VisibilityConstants
Basically we hardcode all the properties on the agent that affect what they can see. |
Field Summary | |
protected Commandable |
agent_
|
protected short[] |
allTerrain_
A packed 2D array for sending over all the terrain. |
protected wyvern.kernel.lighting.RayShadowCaster |
caster_
|
protected boolean |
completeUpdate_
Set to true when visiting map objects during a complete frame refresh, false when doing a partial refresh. |
protected java.util.HashSet |
frameCache_
|
protected boolean |
handheld_
True if player is playing on a PDA. |
protected int |
height_
|
protected boolean |
lightOff_
|
protected GameMap |
map_
|
protected int |
nightVision_
The amount to add to the light level based on racial night vision. |
protected java.util.ArrayList |
objects_
This set contains a "sparse array" of the objects to send to the client. |
protected java.util.HashMap |
terrain_
Information about the terrain & borders - used for smaller updates where the whole view isn't being sent over. |
protected int[][] |
terrainInfo_
A 2D array of terrain records used in drawing borders. |
protected BitMatrix |
updateMap_
|
protected int |
viewx_
|
protected int |
viewy_
|
protected Frame.VisibilityConstants |
visCache_
This is an optimization, plain and simple. |
protected int |
width_
|
Fields inherited from interface wyvern.lib.properties.LightingConstants |
DARKNESS, DAYLIGHT, DIM, DUSK, GLOOM, NUM_SHADES, SHADED, TWILIGHT |
Constructor Summary | |
Frame(Commandable agent)
Constructs a new Frame object with a default 1x1 bounding rectangle, anchored at (0, 0) in the map. |
|
Frame(Commandable agent,
int x,
int y,
int width,
int height)
Constructs a new Frame object with the specified bounds. |
Method Summary | |
protected void |
add(GameObject obj)
Adds an object to the specified layer in the snapshot. |
protected void |
addDescriptor(int x,
int y,
int layer,
int tile,
GameObject obj,
int alpha)
Adds an object appearance descriptor to the sorted frame list. |
void |
addObject(GameObject obj)
Adds an object to the frame. |
void |
addTerrain(int x,
int y)
Adds a terrain object. |
void |
addUpdateRegions(MapDirtyRegions updates)
Adds in all the cells in the map that have become invalid since this method was last called. |
protected void |
cacheVisFlags()
Looks up any properties on the agent we need in advance, and remembers them. |
boolean |
canSee(int x,
int y)
Returns true if the player has a clear line of sight to this square. |
boolean |
checkAdd(GameObject obj)
Returns true if this object should be added to the snapshot. |
protected int |
computeDistance(int x,
int y)
Computes the distance from the passed point to the caster. |
protected int |
computeNightVision(int distance)
Returns the lighting level contribution from night vision. |
protected boolean |
computeXRayVision(int distance)
Returns true if the agent's x-ray vision allows them to see this point regardless of line-of-sight. |
void |
discardChanges()
Discards any information the frame is currently caching. |
void |
doRayCast()
Invokes a raycaster to see what's visible to the frame. |
static java.lang.String |
getProfilingInfo()
Returns a profiling string. |
java.lang.Object[] |
getSparseTerrainInfo()
Returns information about the terrain in, and immediately adjacent to, the update rectangles. |
int[][] |
getTerrainInfo()
Returns the array of terrain records produced in the last call to grabAll(). |
void |
grabAll()
Grabs the entire view from the map. |
boolean |
grabLight(int x,
int y)
Grabs the lighting tile at (x, y). |
boolean |
grabLocation(int tcol,
int trow)
Grabs all the objects at the given map location and adds their appearances to the frame. |
void |
grabObjects()
This is called by the CameraManager to tell the Frame which regions of the camera have become invalid, so it can refresh them. |
boolean |
isHandheld()
Returns true if player is playing on a handheld device. |
short[] |
makeSparseArray()
Returns an array of the objects to draw in the client view. |
void |
printSparseTree()
Prints all the objects in the tree (debugging method). |
void |
setBounds(int x,
int y,
int w,
int h,
GameMap map)
Sets the bounds of the frame. |
void |
setBounds(int x,
int y,
int w,
int h,
GameMap map,
boolean raycast)
Sets the bounds of the frame. |
void |
setHandheld(boolean handheld)
Sets whether we're playing on a handheld. |
static short |
stuffPoint(short x,
short y)
Stuffs two short values ( which must each be < 256 ) into a single short value with x in the high byte and y in the low byte. |
void |
visit(GameObject obj)
Visits an object in the map and puts its appearance in the frame. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int viewx_
protected int viewy_
protected int width_
protected int height_
protected GameMap map_
protected BitMatrix updateMap_
protected boolean lightOff_
protected java.util.HashMap terrain_
protected short[] allTerrain_
protected int[][] terrainInfo_
protected java.util.HashSet frameCache_
protected java.util.ArrayList objects_
protected boolean completeUpdate_
protected wyvern.kernel.lighting.RayShadowCaster caster_
protected Frame.VisibilityConstants visCache_
protected Commandable agent_
protected int nightVision_
protected boolean handheld_
Constructor Detail |
public Frame(Commandable agent)
public Frame(Commandable agent, int x, int y, int width, int height)
x
- the left (x) coord of the snapshot (in world coords)y
- the top (y) coord of the snapshot (in world coords)width
- the width of the snapshot we're takingheight
- the height of the snapshot we're takingMethod Detail |
public void grabObjects()
The Frame implementation gets a Visitor and visits the map at all the invalid spots. It also gathers the terrain. The data is sorted into drawing layers for the client.
Before calling this method, the MapCamera must add all the invalid rectangles to the Frame with calls to addUpdateRect(), so the frame knows what map squares to visit.
grabObjects
in interface DisplayPolicy
public boolean grabLocation(int tcol, int trow)
tcol
- map x location (in map coordinate space)trow
- map y location (in map coordinate space)
public boolean grabLight(int x, int y)
x
- map x locationy
- map y location
protected int computeNightVision(int distance)
distance
- the distance from the point to the agent
protected boolean computeXRayVision(int distance)
distance
- the distance from the agent to the point
protected int computeDistance(int x, int y)
x
- map xy
- map y
public void grabAll()
grabAll
in interface DisplayPolicy
public void doRayCast()
doRayCast
in interface DisplayPolicy
public void visit(GameObject obj)
visit
in interface Visitor
obj
- the object (a GameObject) to examinepublic void addObject(GameObject obj)
obj
- the object to consider for addingpublic void setBounds(int x, int y, int w, int h, GameMap map, boolean raycast)
setBounds
in interface DisplayPolicy
x
- map xy
- map yw
- view widthh
- view heightmap
- the mapraycast
- true to do a raycastpublic void setBounds(int x, int y, int w, int h, GameMap map)
setBounds
in interface DisplayPolicy
x
- map xy
- map yw
- view widthh
- view heightmap
- the mappublic void discardChanges()
public boolean canSee(int x, int y)
canSee
in interface DisplayPolicy
x
- map xy
- map y
public void addUpdateRegions(MapDirtyRegions updates)
addUpdateRegions
in interface DisplayPolicy
updates
- a matrix, the size of the map, that has
all areas that have become invalid in the map since the
last camera refresh.public void addTerrain(int x, int y)
We need to send over border information with the terrain, so for each square to be redrawn, we add a 3x3 int[][] of info (obtained from the map) so the client can draw the center square.
x
- the x map location (not view location)y
- the y map location (not view location)public boolean checkAdd(GameObject obj)
checkAdd
in interface DisplayPolicy
obj
- the object to consider for adding
protected void add(GameObject obj)
obj
- the object (needed for hashcode comparison)protected void addDescriptor(int x, int y, int layer, int tile, GameObject obj, int alpha)
x
- map xy
- map ylayer
- drawing layertile
- tile numberobj
- the object whose bitmap we're drawing. Can be null,
if we're drawing some sort of effect (e.g. lighting level).alpha
- the transparency, 0-100public int[][] getTerrainInfo()
public java.lang.Object[] getSparseTerrainInfo()
public static short stuffPoint(short x, short y)
x
- a short value between -128 and 127y
- a short value between -128 and 127
public short[] makeSparseArray()
public void printSparseTree()
protected void cacheVisFlags()
public boolean isHandheld()
public void setHandheld(boolean handheld)
handheld
- true if playing on a handheldpublic static java.lang.String getProfilingInfo()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |