Game Development Reference
In-Depth Information
Listing 26-4. Platforms.h
#pragma once
#if defined(_WIN32) || defined(_WIN64)
#define PLATFORM_WINDOWS 1
#define PLATFORM_ANDROID 0
#define PLATFORM_IOS 0
#elif defined(__ANDROID__)
#define PLATFORM_WINDOWS 0
#define PLATFORM_ANDROID 1
#define PLATFORM_IOS 0
#elif defined(TARGET_OS_IPHONE)
#define PLATFORM_WINDOWS 0
#define PLATFORM_ANDROID 0
#define PLATFORM_IOS 1
#endif
This header achieves the task of converting preprocessor symbols provided by the Windows,
Android, and iOS build tools into single definitions that we can now use in our own code. The
_WIN32 and _WIN64 macros are added to your build on Windows machines, whereas __ANDROID__
and TARGET_OS_IPHONE exist when building Android and iOS applications. These definitions can
change over time, and an obvious example is the _WIN64 macro, which did not exist before the 64-
bit versions of the Windows operating system and this is the reason for wanting to create our own
platform macros. We can add or remove from Platforms.h as we see fit without affecting the rest of
our program.
I've updated the Enemy classes to have platform-specific implementations to show you how you can
put these platform-specific classes into action. Listing 26-5 shows that the Enemy class has been
renamed EnemyBase .
Listing 26-5. Renaming Enemy to EnemyBase
#pragma once
#include "Entity.h"
#include "EnemyFactory.h"
#include "Serializable.h"
#include <memory>
class EnemyBase
: public Entity
, public Serializable
 
Search WWH ::




Custom Search