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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| 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); } } |