I'm writing a simple game using Python/wxWidgets.
I've written a class for the main window and a simple class for another frame that gets user input.
The architecture I have so far is that the app starts up and runs a second thread that runs a function called "gameLogic". The main thread then goes into main app loop.
The gameLogic thread runs sequentially and needs to control the UI. For example, it needs to open a new dialog with the main frame as its parent. However, I've found that doing this ends up causing crashes (bad enough to pop up the report crash window in OS X).
I've been looking around and gathering that I need to refactor to use events, but what I'm not sure of how to do is to create my own events. I could have my gameLogic thread raise an event in the main window that will then bring up the input dialog and wait for input (modally) then return that data back to the gameLogic thread. The gameLogic thread can block while waiting because the UI thread is separate.
In a function (event handler) in my main frame, I can create a new instance of an input dialog, show it modally, and then get the input.
I've seen all sorts of ideas for implementing this but haven't been able to find a good example of how to create the custom event in my wxFrame object and call it from the other thread, and also to have the logic thread block and wait till input comes back, and then how to get that input back to gameThread.
Advice greatly appreciated!
CallAfterandPublisher, which is often simpler for simple cases). As for having the logic thread block… if you just want to block, use normal thread synchronization; you don't need anything fancy.