|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
DisplayCache instance does the actual work of drawing, that is, game frame updating.
A DisplayCache instance accepts DrawCommand objects and caches them in its buffer. While its flush() method is called, it will flush all the DrawCommand objects onto the screen. While drawing, the depth field of the DrawCommand objects will be considered as the priority of drawing. ( A less deep DrawCommand object will be drawn earlier. )
This class also deals with control of viewport.
NOTE that all the positions of DrawCommand objects are logical coordonates (which represents blocks). DisplayCache instance can calculate their physical coordonates (which represents pixels).
DisplayCache interface can be implemented differently to improve performance or to integrate with different java application platforms. For example, we can have a Swing implementation and a j2me one.
Method Summary | |
void |
addToCache(DrawCommand cmd)
Add a DrawCommand object into display buffer. |
void |
flush(java.lang.Object helper)
Flush display buffer. |
int |
getDepth()
Get depth of this display cache. |
void |
setDepth(int d)
Set depth of this display cache. |
void |
setViewport(Position vp)
Set the viewport of Background. |
Method Detail |
public void addToCache(DrawCommand cmd) throws GameException
All draw commands are ordered in the buffer by their depths.
Note that before this method is called, the viewport must be set, so we can decide whether the parameter cmd is out of the viewport scope by referring to its position field. If is out of scope, cmd will be ignored.
cmd
- DrawCommand
GameException
- if any error occured.public void flush(java.lang.Object helper) throws GameException
While drawing, the priority(depth) will be considered. This method is called by game container at the end of a frame updating, when all the roles have finished their work. After flushing, the buffer should be cleaned.
NOTE that this method does the actual work of drawing, so its implementation depends heavily on different application platforms. On many platforms, drawing an image onto the screen needs the help of other objects (for example in Swing, a Graphics instance is necessary for drawing). So this method takes an Object as parameter, which is the helper instance, or is a wrapper which holds the helper instances if there are more than one.
helper
- helper instance for drawing
GameException
- if any error occured.public void setViewport(Position vp) throws GameException
This method should be called before any DrawCommand is added into the buffer. That is to say, while setting viewport, the display buffer of this DisplayCache instance must be empty.
It sets the viewport of Background, so while adding DrawCommand, we can decide whether the DrawCommand object is out of the viewport. If is out, we needn't add it into the buffer (for better performance).
vp
- position (logical coordonate) of the viewport.
GameException
- if display buffer is not empty.public int getDepth()
public void setDepth(int d)
d
- depth of the display cache
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |