Object Update Loops

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
AohmZ
Posts: 3
Joined: Thu Aug 04, 2011 1:47 am

Object Update Loops

Post by AohmZ »

I have been working on a game, that involves individual update loops for each object. I have my program structured so each object class (BaseObject) contains a scene node. Currently the code for updating is as follows:

Code: Select all

void State::run()
{
    for(list<BaseObject*>::Iterator it = objectList.begin(); it != objectList.end(); it++)
    {
        BaseObject *currentObject = *it;
        currentObject->run();
    }
}
The state object is part of the game's state machine, and for the current state it runs through the iterates through a list of objects to run the update loop for. Each object has its own update.
Now, my question is: is there a more efficient way to do this with irrlicht? This is running rather slow it seems, I don't think I'm getting very good frame-rates. Any suggestions/fixes would be great! Thanks!
HerrAlmanack
Posts: 52
Joined: Mon Jun 13, 2011 3:50 pm

Re: Object Update Loops

Post by HerrAlmanack »

is there a specific reason why each object needs to have a scene node?
Xaryl
Posts: 90
Joined: Sat Apr 30, 2011 11:54 pm

Re: Object Update Loops

Post by Xaryl »

This kind of loop, in general, shouldn't be called every frame.
They should be used for game logics that can tolerate delays.

For animations, use animators.
For time sensitive game logics, use triggers.
AohmZ
Posts: 3
Joined: Thu Aug 04, 2011 1:47 am

Re: Object Update Loops

Post by AohmZ »

HerrAlmanack wrote:is there a specific reason why each object needs to have a scene node?
Yes, each object is something that is rendered.
Xaryl wrote:This kind of loop, in general, shouldn't be called every frame.
They should be used for game logics that can tolerate delays.

For animations, use animators.
For time sensitive game logics, use triggers.
Thank you very much, I will look into these.
AohmZ
Posts: 3
Joined: Thu Aug 04, 2011 1:47 am

Re: Object Update Loops

Post by AohmZ »

Is there anywhere you can point me for information on animators and triggers?
Xaryl
Posts: 90
Joined: Sat Apr 30, 2011 11:54 pm

Re: Object Update Loops

Post by Xaryl »

By animators, I meant the classes inherited from the Irrlicht ISceneNodeAnimator
By triggers, I just meant that some events don't need to be done by looping through every nodes.

Basically, I was just trying to say that you can try to figure out what needs to be done every frame and what doesn't, and have more than one loop for them.
Animations needs to be done every frame, and the Irrlicht inbuilt animator system is basically an organized per-framed loop.
Game logics generally don't (since human reaction time is 0.1 seconds, and 1 second delay in, for example, teleporting is often okay).

Edit:
Use a profiler to figure out what's causing the limitation first xD
Post Reply