While working on some new exercises for the monkeys, I realised we’d need some new functionality in the virtual machine. This would then need to be exposed to C# via the C++/CLI interface and then displayed in the WPF-based UI. For me, these latter steps are neither fun nor efficient, and as the complexity increases then so will the work required to maintain this approach.
At the same time, I’m trying to brush up on modern C++. I’m pretty much stuck in the past when it comes to the language (pre-C++11, thanks to a combination of working in videogames and, well, not using C++ much in the last decade or so).
While watching some C++ YouTube videos from ‘The Cherno’, I stumbled across his video on Dear ImGui and was converted:
I love retained mode UI and much prefer to use it for game and application dev, for rendering efficiency, layout features and so on, but it was proving to be a bit restrictive when iterating on the monkeys. ImGui is just super flexible and fast when prototyping new ideas. I’d also like to try native Linux at some point and I don’t think WPF will port easily.
Dear ImGui
I was sold by the docking features of Dear ImGui that were highlighted in the video. My interface is going to become more and more complex and I want to be able to rearrange it depending on the Exercises, Generators and VMs I’m playing with, as well as making easily reusable components for complex panels like the Virtual Machine. Being able to easily pop-out new Virtual Machine windows will be super useful.
So, I grabbed the docking branch, as suggested in the video, and set up a new C++ project. It really was as simply as dropping in a handful of cpp+h files.
It didn’t take long to get some basic panels set up so I could start hooking up the MWA library. Here’s an early example showing the docking feature when dragging my new Log panel:

There are examples provided which include every type of component I was using in WPF as well as a wide selection of others. It’s going to be pretty easy to replicate the previous implementation.
It also looks like it’ll be much easier to create specific components for complex features like the assembler and memory panels, which are due an upgrade anyway, as well as adding more visual components to display the progress and status of the code generator. Those are currently thrown together as text in the Stats + Info panels.
C++
Hooking up a C++ frontend posed more of a challenge. Although it felt immediately liberating to be able to access the MWA C++ library directly, without the need for an intermediate interface, there was still quite a bit of work to do to get to the same stage as the WPF version:
- Handle the asynchronous code generation efficiently and robustly. This just required a lot of wrestling with std::threads and synchronisation to replace the old BackgroundWorker, but I appreciated the practice.
- Replace the C# StopWatch – Used for tracking elapsed time, now replaced with std::chrono::steady_clock
- Email support – Used to send emails on code generation completion. I couldn’t find a library that integrated easily and efficiently so I went with CMail instead. It’s command line based and easy to use, I just launch a command line process to send an SMTP mail containing the results grabbed from a temporary .txt file.
- Disassembler – I previously threw this together in C# because it was only required by UI. This was just a simple port to C++, which also makes it reusable in the command line version which was already written in C++.
- Hex Editor – I needed a replacement for the handy WPFHexEditorControl. I thought this would result in a LOT of work, but it turns out there’s an ImGui memory editor which is pretty close to what I need. It looks like it’s easy to customize later too.
- Program Results – A class which encapsulates the final VM state, score, timing, name, etc. for a specific monkey. This was another simple port to C++.
- Processor hardware queries – Used to auto-select a reasonable amount of logical processors for the parallel generator. Switched from Environment.ProcessorCount to std::thread::hardware_concurrency. They both report the same number of logical processors on my main machine, I’ll have to try on other systems to see how reliable it is.
- Monkey naming system – The important stuff! Another port to C++.
This all took a bit longer than expected but I expect that having direct access to the C++ library and a much simpler UI to work with is going to pay for itself in the medium-term.
C++11 And Beyond!
Another bonus is that I can treat this new UI project as a playground to try out C++ concepts that are new to me, such as RAII, move semantics, constexpr, lambdas, std::filesystem, template improvements, etc.
The UI is higher level so I’m less concerned about performance and can focus on ‘correct’ implementations instead. At the lower level, however, the monkeys will continue flinging pointers around with reckless abandon!
Messy Monkeys
Here’s a rough pass using the new ImGui functionality:

I added a simple Log window which should come in handy, and was able to add a new ‘Live Update’ option to the population group window which should be useful for future debugging. Otherwise everything is working in pretty much the same way.
New Monkey Suit
And here it is after a bit of a cleanup:

I thought I’d stick with the light colour scheme because it’s grown on me over the months, but it’s pretty trivial to add a dark-mode toggle in future.
Side-by-side, we’re not too different from the WPF version, except now we have the option to resize and dock/undock each of the panels:

That’s all for now. The monkeys are trimmed and washed and ready to get back to the new Exercises I was preparing for them. We’ll see how they get on next time…