Tuesday, August 8, 2017

c++ - Any tips for creating cross-platform games?



Do you have any tips/recommendations when creating a cross-platform game in C/C++?



Answer




Hide anything platform-specific behind abstraction layers


This means stuff like rendering, audio, user input, and file IO. One common trick to abstracting that without inducing a run-time performance penalty is platform-agnostic headers with platform-specific implementation files:


// FileSystem.h
class FileSystem {
public:
FileHandle OpenFile(const char * path);
// other stuff...
}

// FileSystemWindows.cpp

FileHandle FileSystem::OpenFile(const char * path) {
// call windows API...
}

Then configure the builds for each platform to build against the proper .cpp file.


Make your content pipelines read in platform-independent assets and output platform-specific content for each platform


For example, author your textures as .tga or just .psd, then have a pipeline that can automatically convert those to the different platform-specific formats you need.


Don't assume a specific memory layout or endianness in your data


Platforms may vary in byte order, padding, alignment, and word size. Any code that cares about that must be thoroughly tested on all platforms.


Test on all platforms, all the time



You will get bitten by platform-specific bugs. Would you rather get bitten now, or right when you're trying to get the game out the door?


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...