Best practices for managing C++ app with Win32 and UWP/Xbox platform support?

615 views Asked by At

I'm working on a project, specifically a game engine, that has support for both Windows Desktop (Win32) and Universal Windows (UWP/WinRT for Xbox One) platforms. Though I'm having trouble managing it. For Visual Studio, WinRT projects and standard C++ projects need to be compiled with different project types. So for each project I need to build I need to have two projects that build the same source code. For example, the engine needs to be compiled using two different projects. Once, for each platform I want to run on. Meaning everytime I need to run and test it on each platform I need to manually set the startup project to the project I want to launch. I hope that makes sense.

So my question is: Are there any tools, best practices or design patterns, for dealing with projects like this? Ideally I would like to just change the configuration to, say Xbox One, to launch for Xbox One, or Win32, to launch for Windows Desktop. But am open to new sugggestions.

Thanks!

1

There are 1 answers

3
Chuck Walbourn On

I have a number of C++ libraries that build for "classic" Win32 desktop, Windows 10 desktop, UWP, and Xbox. The majority of the code is Win32 C++ or DirectX. For games, audio, and rendering, there's a pretty clear overlap of these platforms which is where I focused.

I have a blog series that captures much of the 'best practices' I used you may want to reference: Dual-use Coding Techniques for Games.

There are a few cases where I needed to interact with Windows Runtime APIs. In some contexts, I use the C++/CX extension guarded with __cplusplus_winrt. In some cases I used WRL via the low-level ABI (which is frankly pretty ugly, but I didn't need to do all that much). C++/CX is only supported by Microsoft Visual C++, so WRL or better yet C++/WinRT is a better choice for new projects.

Concrete examples would be:

All multi-platform engines isolate things like the 'window management, presentation loop, and swap chain'. For the Microsoft platforms, I've captured these in VS templates on GitHub.

Each platform also has it's own implementation of things like Cloud-based Storage, Store/licensing APIs, Multiplayer matching/connection, etc. so you'll need to isolate these as well if you implement them.

All that said, you should think about what your goals are for this project. If you want to create a game, use something that's readily available like UnrealEngine or Unity. If you want to learn more about graphics and games technology like Direct3D, audio, etc. then a small engine is a good idea but you should really scope your target platform to something simple. Writing a 'multi-platform' engine is a huge task, so just sticking to one to start is usually the better option.