Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Currently I am using arrays to handle all of my game objects in the game I am making, and I know how terrible this is for performance. My question is what is the best way to handle game objects and not hurt performance?

Here is how I am creating an array and then looping through it to update the objects in the array:

public static ArrayList<VboCube> game_objects =  new ArrayList<VboCube>();
/* add objects to the game */

while (!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        for (int i = 0; i < game_objects.size(); i++){
            // draw the object
            game_objects.get(i).Draw();
            game_objects.get(i).Update();
            //world.updatePhysics();
        }
}

I am not looking for someone to write me code for asset or object management, just point me into a better direction to get better performance. I appreciate the help you guys have provided me in the past, and I dont think I would be as far along with my project without the support on stack exchange!

share|improve this question
2  
In which part of your code do you have perfomance problems? Did you profile? –  Maik Semder Nov 3 '12 at 21:40
2  
Are you sure your performance problems come from the way you store entities? You may want to look at the way the Artemis framework store entities. It uses what they call a Bag. From the doc: Collection type a bit like ArrayList but does not preserve the order of its entities, speedwise it is very good, especially suited for games. Maybe you should check it out :) –  nathan Nov 3 '12 at 21:48
    
I will take a look at this Nathan, thank you for the recommendation. –  Kenneth Bray Nov 4 '12 at 2:04

1 Answer 1

As far as storing and retrieving game objects is concerned, you could use a native array but an ArrayList is already nearly as fast as it gets.

Now I'm making a guess, not knowing what your list of game objects contains nor how the objects are drawn and updated, but I'd venture that maybe you do not need to update and draw all objects on every frame. That or the draw or update code itself is inefficient.

HTH

share|improve this answer
    
All the update code does is update the location of the object, with that of the jBullet collision object. The update code is so basic that it would not be the cause I dont think. If an ArrayList is the best method I guess I need to look at other places I can improve on code wise. –  Kenneth Bray Nov 4 '12 at 2:08
2  
In this regard, I strongly support Maik's suggestion that you use a profiler. It's the best way to avoid optimizing parts of your code that are already fast enough. –  Thomas Dufour Nov 4 '12 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.