com.alienfactory.javamappy.viewer.render
Class MIDP10RendererAlt
java.lang.Object
com.alienfactory.javamappy.viewer.render.MIDP10RendererAlt
- All Implemented Interfaces:
- Renderer
public class MIDP10RendererAlt
- extends java.lang.Object
An alternative J2ME Renderer to use with MIDP v1.0 compatible devices. This
implementation stores the tiles as an array of Images rather than a single
tile sheet image. Even though it uses up more memory this can help overcome
heap fragmentation problems caused by a large tile sheet (i.e. not having a
large enough continuous block of memory to accommodate the image).
Consider using if you get OutOfMemoryErrors
when trying to
load your tile sheet but Runtime.freeMemory()
reckons you
should have enough. Also consider using if developing for Motorola V-series
phones as these have notorious heap fragmentation problems.
Confused? Here is an extract from Motocoder.com
in the
Knowledge & Support -> FAQs
section. (See http://motocoder.custhelp.com/cgi-bin/motocoder.cfg/php/enduser/std_adp.php?p_faqid=454,
login required):
You are right in the assumption of heap fragmentation. This is what is
causing the issue. Also the MIDlet jar is stored as a jar in the device and
not as independent class files. The amount of freeMem() returned in the total
unallocated memory not a contiguous block of memory and so when an attempt to
place a file (image) on memory that is large than the largest continuous
block a out of memory exception is thrown.
We have made improvements in later models, i.e E398, etc with fragmentation.
However in some cases these errors are still seen if precautions are not
taken with memory hungry actions.
It should be noted that Image object for image 640x480 will take about 615KB
(640 * 480 * 2 = 614400). It is strongly recommended to release Image objects
if they are not used any more. Our kvm implementation contains a compacting
Garbage Collector and it will help minimise heap memory fragmentation.
Garbage is collected when a new object is allocated and there is no memory in
the heap to allocate this object. It can be because the memory is full or
because of fragmentation reasons. In this case GC is called implicitly. In
addition, GC can be called explicitly via System.gc(). GC dos not reclaim old
objects. Only not referenced objects are reclaimed
When the user selects the MIDlet to run, the kvm reads the necessary classes
and resources from the JAR file and starts the MIDlet. Classes are loaded as
needed into the heap for execution, and some of the heap is reserved for
caching record store information. The most heap-consuming process is the
creation of images. For example, decoding a PNG image requires: temporary
buffer to read image from the JAR file + buffer for decoded image data equal
to size of (image width * image height * 2) bytes + about 35KB for temporary
PNG decoder buffers. Both temporary buffers will be released when process of
decoding will be finished.
Thanks go to Leo Au for bringing this to my attention.
- Author:
- Steve Eynon
Constructor Summary |
MIDP10RendererAlt(Map map,
java.lang.String[] tileSheetFileNames,
boolean block0included)
Initialises itself from the given array of tile sheet images. |
Method Summary |
void |
drawImage(java.lang.Object objGFX,
int imageIndex,
int dstPixX,
int dstPixY,
boolean transparency,
int modification)
Draws an image as given by imageIndex at the given coordinates. |
void |
restoreClip(java.lang.Object objGFX)
This is called after a Layer is drawn to restore the
clipping region to what it used to be. |
void |
setClip(java.lang.Object objGFX,
int x,
int y,
int width,
int height)
This is called just before a Layer is drawn to allow the
Renderer to set the desired clipping region. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
blockWidth
protected final int blockWidth
blockHeight
protected final int blockHeight
halfBlockWidth
protected final int halfBlockWidth
MIDP10RendererAlt
public MIDP10RendererAlt(Map map,
java.lang.String[] tileSheetFileNames,
boolean block0included)
throws java.io.IOException,
java.lang.IllegalArgumentException
- Initialises itself from the given array of tile sheet images.
To use this constructor you must save out each tile as an individual image.
- Parameters:
map
- the Map
to be renderedtileSheetFileNames
- file names of the tile images to load - they should all start with a leading '/'block0included
- set to true
if the tile sheet array includes block 0
- Throws:
java.io.IOException
java.lang.IllegalArgumentException
drawImage
public void drawImage(java.lang.Object objGFX,
int imageIndex,
int dstPixX,
int dstPixY,
boolean transparency,
int modification)
throws java.lang.IllegalArgumentException
- Description copied from interface:
Renderer
- Draws an image as given by
imageIndex
at the given coordinates.
- Parameters:
objGFX
- the gfx object specific to the Renderer
imageIndex
- the index of the image to draw - see Map.getImageData()
dstPixX
- the coordinate of where the image should be rendereddstPixY
- the coordinate of where the image should be renderedtransparency
- whether or not the image should rendered honouring
it's transparent pixels.modification
- any modification style should be applied to the image
- Throws:
java.lang.IllegalArgumentException
- if objGFX
is null
setClip
public void setClip(java.lang.Object objGFX,
int x,
int y,
int width,
int height)
throws java.lang.IllegalArgumentException
- Description copied from interface:
Renderer
- This is called just before a
Layer
is drawn to allow the
Renderer
to set the desired clipping region.
- Specified by:
setClip
in interface Renderer
- Parameters:
objGFX
- the gfx object specific to the Renderer
x
- the start coordinate of the clipping regiony
- the start coordinate of the clipping regionwidth
- the width of the clipping regionheight
- the height of the clipping region
- Throws:
java.lang.IllegalArgumentException
- if objGFX
is null
restoreClip
public void restoreClip(java.lang.Object objGFX)
throws java.lang.IllegalArgumentException
- Description copied from interface:
Renderer
- This is called after a
Layer
is drawn to restore the
clipping region to what it used to be.
- Specified by:
restoreClip
in interface Renderer
- Parameters:
objGFX
- the gfx object specific to the Renderer
- Throws:
java.lang.IllegalArgumentException
- if objGFX
is null
Copyright © 2001-2009 Alien-Factory Ltd. All Rights Reserved.