I am stuck with a little problem, i am rewriting a program to include a GUI.
I have experimented with various options and because of the program only requiring limited interaction i am just writing the interface myself using SDL as otherwise i will (i think) be spending ages on back to basics stuff with other GUI options available.
My problem is once the user decides to 'start' after they set up play, then control passes to an algorithm that can take a long time to execute depending on the settings.
I need to be able to still get user events if they decide to 'stop' for example.
apart from this even if the settings mean it will execute quickly i still need the event monitoring there to avoid frustration if somebody clicks and it does not immediately respond.
i was planning to use a state machine (thanks to lazy foo) which i have done before a couple of times with success, but the requirements here mean it might not be as appropriate.
This would be fine but in order to get the event handling i wish for when the algorithm starts then i can only see the option to put another event polling loop into the algorithm loop but that messes with my design ideal.
while not quit
and i think it might slow things down quite a bit also.
Every time i have used sdlpollevent then i see 50%cpu usage even in an otherwise empty program, tried on various computers.
Is it a viable idea to run my algorithm in a seperate thread, can i 'pause' it or control it from the event loop in my main program thread?
sorry for the ramble, there is no code yet either