On Wed, 27 Jul 2011 13:41:37 -0400, Dainius (GreatEmerald) <past...@gmail.com> wrote:

I have one program design problem and I wonder if anyone here could
give any suggestions about it. The situation is like this: I am
splitting a game into a frontend (a library) and a backend (an
executable). The backend is going to handle all the game mechanics,
while the frontend is going to handle I/O. But there are certain
problems. For example, now I have a function Shuffle() that calls
PlaySound(SHUFFLE). Shuffle() is a backend function, while PlaySound()
is a frontend one, so obviously it won't work that way after the
split. It would be ideal if there was a way to create hooks - say an
empty PlaySound() function that the frontend could receive calls to.
But I can't see a way to do that. Another way to do that that was
suggested to me was to use an event loop - set a global variable, then
have the frontend monitor it for changes and then respond as
necessary, but that just isn't a very clean way to do it.

Actually, an event loop is a good way to do it. If your front end is a GUI, it's already likely running an event loop. All you need to do is stick an event in the event queue.

I'd examine how to create custom events for your front end's probably already existing event loop.

-Steve

Reply via email to