|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.common.util.ClientImageCache
Client-side cache mapping tile numbers to images.
The cache provides methods for extracting 32x32 pieces of an image, and it will cache the pieces.
Field Summary | |
protected IntHashtable |
cache_
This table caches Images; the keys are the tile numbers for the images (from the tile registry). |
protected java.util.Hashtable |
images_
Maps image names to tile numbers. |
protected static ClientImageCache |
instance_
|
protected wyvern.common.util.LinkedQueue |
itemList_
|
protected int |
maxSize_
|
protected int |
QMARK
|
static int |
TILE_WIDTH
|
protected IntHashtable |
tiles_
Maps tile numbers to image names. |
Constructor Summary | |
protected |
ClientImageCache()
Prevent instantiation. |
Method Summary | |
static void |
addTileNumber(int tile,
java.lang.String path)
Called by client when an image/tile mapping comes in. |
static void |
clear()
Clears all the images and mappings - used when Client disconnects, so connecting to a new server doesn't dork the artwork. |
static java.awt.Image |
extractImage(int tile,
int x,
int y)
Loads (and caches) a piece of an image given its tile number and (x,y) offsets. |
protected java.awt.Image |
extractPiece(java.awt.Image img,
int xoffset,
int yoffset)
Returns a 32x32 piece of the specified image, at the requested relative x & y offsets. |
protected static java.awt.Image |
extractSpecial(java.awt.Image img,
int x,
int y)
Extracts the bottom half of a 1x2 image - the CropImageFilter seems to choke on this, as of JDK1.2beta4 (it returns top half). |
static java.awt.Image |
getImage(int tile)
Loads an image from its tile number. |
java.lang.String |
getImageNameFromTile(int tile)
Looks up the image name in our cache. |
static ClientImageCache |
getInstance()
|
protected java.awt.Image |
iextractImage(int tile,
int x,
int y)
Loads (and caches) a piece of an image given its tile number and (x,y) offsets. |
protected java.awt.Image |
igetImage(int tile)
Maps a tile ID to its Image. |
protected java.awt.Image |
loadImageResource(java.lang.String path)
Calls Wyvern.loadImage(), but subclasses can use a different way to load the image. |
static void |
setInitialTileMappings(IntHashtable tiles)
Sets the initial tile/image mappings, received from the server. |
static void |
setMaxSize(int max)
Sets the maximum size for the cache, after which we'll start aging out images. |
static void |
storeImage(java.lang.String path,
java.awt.Image img)
Stores an image in the cache - called by wyvern.client.core.Timestamps for the Applet version, since it can't write the image to disk. |
static void |
uncacheImage(java.lang.String path)
Uncaches an image by name. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int TILE_WIDTH
protected static ClientImageCache instance_
protected int QMARK
protected IntHashtable cache_
protected IntHashtable tiles_
protected java.util.Hashtable images_
protected int maxSize_
protected wyvern.common.util.LinkedQueue itemList_
Constructor Detail |
protected ClientImageCache()
Method Detail |
public static ClientImageCache getInstance()
public static java.awt.Image getImage(int tile)
tile
- the database tile number
public static java.awt.Image extractImage(int tile, int x, int y)
The (x,y) offsets correspond to the tile location within the image to extract. For instance, if the image is 64x64, i.e. 2x2 tiles, then an (x,y) offset of (0,1) will extract and return the lower-left corner of the image.
tile
- the TileDatabase number of the imagex
- the x tile offset into the imagey
- the y tile offset into the image
java.lang.IllegalArgumentException
- if either offset is invalidpublic static void setMaxSize(int max)
max
- the max number of images to keep in the cache,
or -1 to make it unlimited.protected java.awt.Image igetImage(int tile)
tile
- the tile database number
protected java.awt.Image loadImageResource(java.lang.String path)
path
- the relative path to the image, using the naming
conventions required by wyvern.common.config.Wyvern.loadImage()public static void storeImage(java.lang.String path, java.awt.Image img)
img
- the imagepath
- the relative image pathpublic static void uncacheImage(java.lang.String path)
public java.lang.String getImageNameFromTile(int tile)
protected java.awt.Image iextractImage(int tile, int x, int y)
The (x,y) offsets correspond to the tile location within the image to extract. For instance, if the image is 64x64, i.e. 2x2 tiles, then an (x,y) offset of (0,1) will extract and return the lower-left corner of the image.
tile
- the TileDatabase number of the imagex
- the x tile offset into the imagey
- the y tile offset into the image
java.lang.IllegalArgumentException
- if either offset is invalidprotected java.awt.Image extractPiece(java.awt.Image img, int xoffset, int yoffset)
img
- the image to cropxoffset
- the x tile-offsetyoffset
- the y tile-offsetprotected static java.awt.Image extractSpecial(java.awt.Image img, int x, int y)
public static void addTileNumber(int tile, java.lang.String path)
public static void setInitialTileMappings(IntHashtable tiles)
tiles
- a hashtable of Integers to Stringspublic static void clear()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |