Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Extending Gosu / Gosu and Event Machine Integration
- By ? Date 2008-11-26 09:16
I am making a graphic client for a networked game, and I was wondering how to get Gosu and EventMachine to work together, since they both have their own non-completing main loops (Window#show and EM#run) 

My current solution is to useEM#defer to run a proc containing Window#show in a separate thread.  The EM event handlers call functions to update the window's status, and the Gosu window uses callbacks to send messages through EM. 

It seems to be working so far, but I'm wondering if there is a better way to integrate them so that there is only one event loop.  Any ideas?

-Adam
- By codekitchen Date 2008-12-10 17:08
I can't speak for Gosu integration exactly, but I recently did something very similar, integrating EventMachine with a Shoes app. I ended up with the same solution you did, spawning a separate thread for EM and running the EM event loop there. The only way you could combine the two event loops is if EM provided a #one_step type method that you could call each step through the Gosu event loop (or vice versa).

Although after I got EM working with Shoes, I ended up dropping EM and switching to the Rev library anyway. I'm not sure how far along you are in your networking code, but you might want to check out Rev as an alternative -- I much prefer the API over EM's, and it has said #run_nonblock method so you can integrate it into the Gosu event loop directly. http://rev.rubyforge.org/rdoc/
- By leviathan Date 2009-05-16 21:55
What I did was I separated the game and the networking. I have a network class that runs as a separate thread and a game class that runs as a separate thread.

They're both loaded by the main class, which instantiates both and starts them. Both classes have functions to communicate with each other.
Up Topic Gosu / Extending Gosu / Gosu and Event Machine Integration

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill