I benchmarked this segment of code, gave me 3fps.
The reason I did it this way is because I love to organise the items.
Any help on how to achieve my level of organisation without the performance hit?
I should add that I am using buffered images.
Only 2 items are being rendered, background and space ship.
public void render(Graphics2D g)
{
ArrayList<Entity>
low = new ArrayList<Entity> (),
med = new ArrayList<Entity> (),
high = new ArrayList<Entity> ();
Entity hnd = null;
for( Enumeration<Entity> e = items.elements(); e.hasMoreElements(); )
{
hnd = e.nextElement();
if( !hnd.isDead() )
{
if( hnd.getRenderPriority() == PRIORITY_LOW )
{
low.add(hnd);
}
else if( hnd.getRenderPriority() == PRIORITY_MEDIUM )
{
med.add(hnd);
}
else
{
high.add(hnd);
}
}
}
for( Iterator<Entity> eL = low.iterator(); eL.hasNext(); )
{
eL.next().render(g);
}
for( Iterator<Entity> eM = med.iterator(); eM.hasNext(); )
{
eM.next().render(g);
}
for( Iterator<Entity> eH = high.iterator(); eH.hasNext(); )
{
eH.next().render(g);
}
}