Mouse integration and the event queue

An important part of release 0.2 will be a better mouse integration. Using the mouse will be the best way to select multiple spirits at the same time to unleash spell combinations. Not only that, but the mouse pointer will be one of the primary way to receive feedbacks about what can be targeted or not.


Spell icons will double as mouse pointers once selected, changing color when over a viable target

Right now I am facing a problem with mouse integration, however. The current input manager is based on the event-driven structure of SFML.NET: each clickable item registers itself on several event streams to be notified about mouse clicks or key presses. The problem is that they are registered, and drawn, in the same order in which they are created. What happens then is that, when you click somewhere, the first item that responds to the click is the one that is “more into the background”, even if covered by another item.


The simple solution would have been to push items to the front of the event stream when created, instead of the bottom (for the technically inclined: using a LIFO stack instead of the default FIFO implementation). Unfortunately I have not found a way to do this without having to modify SFML and recompile it myself, which is something that I would like to avoid.

Right now my solution would be to register a single class to the event queue, my I/O Manager, and then implement a second inverted event queue. It will be a bit slower and less streamlined/elegant, but I doubt that it will have any noticeable impact on the game and I still prefer it to modifying the default behavior of a library.

Another possibility is to implement it as a “legacy” polling mechanism in the game loop (in specific, simulate it by wrapping the events that are dispatched by SFML), but I actually like the event driven approach more.

What do you think would be the best solution? Have you ever faced something analogue?

Thanks for reading.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s