An advice about events handler

Started by
3 comments, last by BlueChip 20 years, 6 months ago
Hi folks... I must manage events that act on my 2d and 3d objects (i.e sprites and meshes).. so I''ve thought of writing a method to do it, but I''m undecided between 2 ways: 1)to the end of each loop, I check each 2d and 3d element in my structures, and if it has a special flag I handle it. This is linear ( because I use only pre-existent data) but is expensive (because I must do a check for each element in my structures) 2)when I set a flag on an object, I put a pointer to it in a special list, and to the end of each loop, I handle the objects in the list. This is cheap ( because I must do a check only on some element) but is not linear ( because I must do new strucures - like a specil list - ) In your opinion which ways is the best? Or there is a third solution? thanks =)
Advertisement
you should only update when needed. It is better than looking through all your scene elements'' flags each game loop to see if they triggered an event. Check for event triggers as elements are updated (I.E. they move or whatever) then apply the effects of the event. This is simmilar to collision checking. And usually events are triggered from collisions.
Now I do that that you say,
but this gave me some troubles...

for example, if an object triggered five events, for each event, I must take it and manage it....

but if I use an event-handler, I can take and manage the object one time...

is this a bad idea?
it sounds like you are tying to implement some sort of event queue. consider the following example:

Event Trigger : A Character steps on a snake

Snake Hisses
Snake bites
Character jumps out of the way

end Event

what i was getting at is when the character moves, check to see if he stepped on a snake... if he did...handle the event. in your case there could be more events in one update of an object so as the object is updated check for all of the possible event triggers. you could eliminate checking for every single trigger by taking in consideration what type of "update" occured. for example if your character jumped into the air...you wouldn''t really need to check if he stepped on a snake because he didnt "step". I''m just throwing out specific examples but the pricipal is the same.

as a piece of advice. it may be helpful to develop a simple scripting system to handle events. it would make your engine more powerful, and it would be easier to create events. just a thought.

hope that helps things.
All right... good advice.
I''ll move myself long this way....

thanks

This topic is closed to new replies.

Advertisement