Archived

This topic is now archived and is closed to further replies.

wrathgame

an event prompter

Recommended Posts

wrathgame    122
Hi, I am developing a MMORPG.. OK... I rambled ! to put this short : I want to be prompted after x amount of time that say for example that a NPC needs to do something new any ideas ?? .. the long explanation below of what i have done (basically) I came up with the following for when an NPC needs to do something : Note - its a kind of realtime/turn based game - by this i meen.. for example a NPC moves 3 squares and then has to wait x time before they can do something else. I needed to have some way of assigning new tasks to NPCs who are ready to do something.. I could have looped through every NPC checking if they are inactive and then assign a task.. but this could waste a lot of time if there are 1000s of NPC so I made a component which basically did the following : contained a circular array of linked lists. each ellement of the list represents a set period (say 250 ms) and each ellement can hold a pointer to an "event" which can in turn point to another "event" and so on (so 2 events can occure on the same 250ms period) By using this structure and a timer i managed to produce something that would call a event after a set period (rounded up to the nearest time slot) returning the data i passed in (ie the NPC id) so i would know that NPC would need processing the problem i have narrowed down to the fact that sometimes during the event more items are added to the list which causes a problem if it adds to the same ellement which is been processed (ie if there are 10 ellements and time gape of 1000MS if i add an event at 10 seconds from now it will be added to the current ellement in the circular array. Any advice would be great Thanks Tim

Share this post


Link to post
Share on other sites
Kylotan    9881
Idea #1: Remove the element from the list just before you process it. That way, you''re never going to attach new elements to it.

Idea #2: I don''t see why adding extra elements while processing one will cause a problem unless your circular linked-list structure is not totally reliable. Consider using an array of pointers or even better, an STL container if you are using C++.

Share this post


Link to post
Share on other sites