Sign in to follow this  
Grahf750

Notification something happened in world

Recommended Posts

I have events which are triggered when their preconditions are met. These preconditions have a tile range. The range can be anything from the whole map to a single tile. Precondition Example: A player uses a torch within 10 tiles of the event. My problem is figuring out an efficient way to notify the event that the precondition has happened. I have come up with this idea so far: 1) Each item, spell, ect. which is a possible precondition has a static list of all events which have it as a precondition. When the item, spell, ect. is used it goes through each event in that list and checks if it is within that event's range.

Share this post


Link to post
Share on other sites
What you're describing is a broadcast system, and while it's quite straightforward and would work just fine, it causes a lot of overhead since most of the time you'll be telling events, "Hey the player used a torch!", and their response will be, "I don't care." In other words, you'll be sending information to objects that will just ignore it.

The inversion of this concept is where events register for what they want to be notified about. So all the events that have a torch precondition would register for the "torch lit" message, and whenever a torch is lit the system sends the message to all the events that said they wanted to hear about it. In the end both systems give you the same end result, yet the second one has minimal overhead since only events that care about certain conditions will be told about them.

EDIT: Actually it looks like your idea is like the registration system, only events don't have to register first.

Share this post


Link to post
Share on other sites
broadcast / subscriber system. Have objects interested in the notification register themselves to handle that particular event, and have the world broadcast that event to the subscribers.

Share this post


Link to post
Share on other sites
In that case, have the event check the preconditions when it receives a notification. If your event in question receives a "torch lit" message (because it registered for one), have it check the "player within 10 tiles of event" precondition, and if it doesn't pass you can early out. You don't want to add the precondition test to the notification system because it adds overhead to a system that would be used quite often, and if makes your event handling less flexible.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this