Is there a way to pass the wxWidget GUI to a wxThread?

I have made a game that uses a game loop. Now i am trying to implement a GUI for this game in wxWidgets.

The problem is that when I initialize the GUI the control of the program remains on a GUI loop and doesn't go to the game loop.

So, can i make the GUI run on its own thread?

Answers


You can, but leave all code, which interacts with the GUI on the main thread/EDT (Event Dispatch Thread). Concurrent access to GUI elements is not intended by design and will cause problems. Instead, put the game loop into a wxThread and fire appropriate events from there. Those events can then be handled on the EDT to update the GUI or for rendering a frame.

Another solution would be, to invoke single iterations of your game loop on the main thread, using wxTimer.

Note:

  • Throttle the game loop or coalesce the events if necessary. wxTimer does perfectly support throttling by frequency and coalescing of update events. In a separate thread, you'd need to sleep for the remaining time of the desired cycle/iteration time or wait on a semaphore, triggered by the main thread.
  • Implement access to share data like the game state with a synchronization object like wxMutex. Preferably, you could instead use std::mutex and std::thread from C++11.

Examples:


Need Your Help

Extjs4 RESTful CRUD grid with Spring Controllers

spring rest datagrid extjs4

I am new to Extjs4 and the javascript world in general. I have looked up the documentation and samples and trying to get a basic CRUD grid up and running with my spring backend.

Wrong SQL Syntax?

php mysql sql

I am building a small Twitter clone for personal use, and I have so trouble with it.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.