Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Uhm, my game is going 3fps and I think I found..  (Read 1037 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Member




Java games rock!


« Posted 2004-10-17 11:36:10 »

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);
            }
      }

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Mithrandir

Senior Member




Cut from being on the bleeding edge too long


« Reply #1 - Posted 2004-10-17 14:18:13 »

Way too many comparisons in there, and way too much sorting.

Firstly, get rid of all the iterators. Lots of garbage generation and don't add anything to performance. Stick to a simple indexed getter. You're running array lists, and you know that, so make use of it. Only ever use iterators if you have a generic List instance and it doesn't also implement RandomAccess.

Next, all that sorting at the start of the loop is bad. There are many things wrong with that code, starting with the big if/else ladder where you should have used a switch.

However, what you really want to do is throw all that code out and use a priority queue. A single queue will do all your sorting for you before you get to the point of needing to render and you then only need to walk through a single list of values as you render.

The site for 3D Graphics information http://www.j3d.org/
Aviatrix3D JOGL Scenegraph http://aviatrix3d.j3d.org/
Programming is essentially a markup language surrounding mathematical formulae and thus, should not be patentable.
Offline tom
« Reply #2 - Posted 2004-10-17 15:22:35 »

Don't think the code above is the reason why your getting 3fps. Has more to do with how your drawing your images. Maybe you did not understand the benchmark correctly?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #3 - Posted 2004-10-18 09:06:18 »

cT = System.nanotime();

mainLoop();

dT = System.nanotime() - cT;

fps = (int)1000000000L/dT;

Isn't that how you would calc fps?

I can tell it's slow because the input has a very slow response time.

I just use buffered images to render pics.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (35 views)
2013-05-17 21:29:12

alaslipknot (44 views)
2013-05-16 21:24:48

gouessej (73 views)
2013-05-16 00:53:38

gouessej (73 views)
2013-05-16 00:17:58

theagentd (81 views)
2013-05-15 15:01:13

theagentd (75 views)
2013-05-15 15:00:54

StreetDoggy (117 views)
2013-05-14 15:56:26

kutucuk (141 views)
2013-05-12 17:10:36

kutucuk (141 views)
2013-05-12 15:36:09

UnluckyDevil (151 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.125 seconds with 20 queries.