Jump to content
  • Advertisement
Sign in to follow this  
Plethora

Multiple event handling blocks?

This topic is 3951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is probably a pretty simple question but I was just wondering if there is some sort of coding technique that people use to avoid having insanely complex event handling structures. At first I actually put effort into integrating all my user input into one place, but its starting to seem less and less worthwhile as my program moves along. To take a simple example say the code that you run after a left click depends on where exactly you left click the mouse, and further that there are many different options on what to do in a given situation. As it stands I have a series of flags that check this that and the other to determine what the situation is, but as the number of different possible situations increase my event handling gets more and more confusing. So to that end, would it be a good idea to create different event handling structures in different places? What is typically done to combat this problem? Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Advertisement
Ideally, you should be getting input in a single place, sending that as an event and then having your app deal with the input.

Just say we got an event for a mouse click at point (x,y). When your app receives that event, it has to check what was clicked on. If you're working on a game, you would usually have a lower layer than encompasses a game state, and the event would get sent to that. So, you're either in a menu, or playing the game and you can check from there.

If you're playing a game, you have the game state check if a button was clicked on, or a unit, or if the player fired or not. If you're in a menu, you have the menu check if the point clicked on was a button or not and then go from there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!