In this article we shall take a look at how to make the controls in your C++ game editable by the user. Once again we shall use SimpleTetris as the base example, and as with our implementation of the high score table, we will make use of Boost for serializing (saving) data into a file, and my Simple2D library for rendering the interface (although this part is optional).
It has now been several months since PlayStation Mobile (formerly PlayStation Suite) was unleashed onto developers in beta form. On 20th September 2012, Sony announced that store deployment will be made available from October 3rd, with a final version of the SDK to be released in November.
So far, I am sorry to report that, in my opinion, the PSM SDK is not in a fit state for production use, particularly for PlayStation Vita development. Far from it. Before I look at the key issues, I want to make it clear that I do understand that PSM is designed as a portable platform to work on all PS Certified devices (which currently includes a range of Xperia Play, Sony Tablet and HTC One devices as well as the Vita), and as such developers wishing to max out the Vita’s hardware potential should ideally be using the official full-blown Vita SDK for games specific to that platform. And that brings me to the core political problem:
One of my favourite inclusions in C++11 – the latest iteration of C++, formerly known as C++0x – is the ability to create lambda functions. Lambda functions are nothing more than unnamed, essentially anonymous functions that you can define in place of where you would usually use a function name, pointer or reference, and they come in particularly handy in combination with STL, although they are certainly not limited to that use. If you have become used to using
Boost.Lambda in your applications, C++11’s lambda functions provide a more convenient syntax while also eliminating your code’s dependency on
As with function pointers and references, lambda functions can be defined as variables, passed to and returned from other functions (including other lambda functions) and so on.
Let us begin with a simple example comparing the use of C++11 and
Boost.Lambda when iterating over a few numbers in an STL vector:
I have no problem with MSI file downloads. They are as simple as running an EXE. However, for reasons unknown, a lot of people don’t seem to like or understand downloading and running an MSI file; they feel more comfortable with EXEs. Visual Studio Setup projects turn your application into an MSI and a
setup.exe file, which is inconvenient for distribution as generally online we want to provide the user with a single file download. Luckily there is a simple and free solution at hand in the guise of a quirky and little-known application included even as late as the Windows 7 base distribution called IExpress. This tool was originally created to enable branded deployments of Internet Explorer 6 (shocking, I know), but we can subvert it quite easily to our needs.
First of all, we must clear up a misconception. Some people want to programmatically determine whether the underlying processor in use is 32 or 64 bit. This is a misnomer, as modern Intel and AMD processors can and do run in both 32 and 64 bit modes, in addition there are considerations of cache width, bus width and so on. There is no “true, pure” 64-bit processor, therefore trying to determine this information is non-sensical.
You can, however, determine if you are running a 32 or 64 bit Windows environment, and whether your application is built as a 32-bit or 64-bit executable. Obviously, you should know the latter at compile time, but it can occasionally be able to know at run time too. Here is the code:
How to determine programmatically if your processor has hyperthreading, SIMD and other processing capabilities with __cpuid
One of the machine intrinsics in Visual Studio is the
__cpuid function, which returns a 4-byte array containing various bit-wise information about the processor hardware capabilities.
While all the gruesome details can be found on MSDN’s __cpuid, __cpuindex page, here is the basic principle:
int cpuinfo; __cpuid(cpuinfo, 1); bool hasHT = (cpuinfo & (1 << 28)) > 0; std::cout << "Hyperthreading on CPU is " << (hasHT? "supported" : "not supported") << std::endl;
In this article I shall demonstrate a modern, object-oriented, re-usable technique to adding a local high score table to your C++ Windows games using STL and Boost. I shall use our SimpleTetris game of which this article is a follow-on.
Please note that this is by no means an efficient implementation, it is designed to just show the principle of the technique.