Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Shattering the Cross Platform Myth

25 Jul 2014 1  
Fragmentation is bad for business and mobile game development is a very fragmented business that is ripe with pitfalls and difficulties. This article outlines these factors and explains how developers are able to overcome them, cutting costs and without the need for compromise.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

Fragmentation is bad for business, and mobile game development is a very fragmented business that is ripe with pitfalls and difficulties. Developers have to contend with a variety of difficult problems that relate to developing games for different platforms and different vendors.

These problems include:

  • Programming languages – Different platforms use different programming languages. For example, iOS uses Objective-C, Android uses Java, Windows Phone 8 uses C#, BlackBerry uses C++ and so on.
  • Frameworks – Each platform has its own different framework and set of API's that have to be learnt thoroughly to use with any kind of efficiency.
  • Services – Each platform has its own unique way of implementing various services, for example in-app purchases. In addition, manufacturers that support the platform have their own ways of implementing these services, examples for Android being Google Play, Amazon, Samsung Apps and so on.
  • Performance – To obtain close to best performance on each platform requires programmers that know the platforms very well.
  • Development equipment – Development for most platforms can be done on Mac and PC. However, iOS development can only be done using a Mac.
  • Testing – Testing begins under emulation which provides an easy way to test a variety of different form factors, screen resolutions, input devices etc. The problem is that some of the device emulators are slow and not very responsive which can make testing for different scenarios difficult.
  • Maintenance – Rolling out an update to an app across multiple platforms is a daunting task, especially as it could have been weeks or months since the project was last looked at.

The factors described above represent risk and spiralling costs, which mobile game developers definitely need to avoid.

What can be done to cut the costs and risks associated with taking games across different platforms? How can developers avoid most of the above issues?

One answer that addresses all of these problems is to look to cross platform development systems. It’s a common misconception that the cross platform approach brings with it a degree of compromise, be it around coverage of platform features, sacrificing performance or longer overall development cycles.

We will illustrate in this article that this need not be the case!

The Marmalade solution

This article will focus on Marmalade C++, the core of the Marmalade SDK, and how it tackles all of the above problems head on:

  • Single language – Marmalade C++, not surprisingly, uses C/C++ as its language of choice for all platforms.
  • Unified framework – Marmalade is a single SDK that wraps up access to sub-systems such as graphics, audio, input, network services and so on.
  • Unified middleware – Services such as In-App purchasing use a single unified API across all platforms.
  • Native performance – Code is compiled to native code for ARM, x86 and MIPS processors. Optimisations for one platform apply to all platforms.
  • Desktop / IDE agnostic – Developers can develop for most platforms on Windows or Mac, this includes iOS. There's no need to create or manage projects within an IDE, this can be done using an easy to use common user interface provided by the Marmalade Hub.
  • Testing made simple – The Marmalade simulator comes complete with metrics and enables rapid testing across a huge range of different screen sizes and a variety of different input devices. Marmalade also supports direct deployment of debug and release builds to device.
  • Easy maintenance – With a single language, single framework and easy unified testing and deployment, rolling out updates is much easier and quicker.

Marmalade C++ has evolved over many years into a reliable, stable and user-friendly product supporting many platforms including:

  • Android (ARM, MIPS and x86)
  • iOS (iPhone, iPad, iPod)
  • BlackBerry (PlayBook, BB10)
  • Windows Phone 8
  • Windows Store 8/8.1
  • Windows Desktop
  • Mac OS X
  • Tizen
  • Smart TV (LG / ROKU)

Time saving unified frameworks

The entire Marmalade C++ framework is C/C++ based and provides access to device sub systems via individual APIs. Let’s take a look at a few examples.

Example 1 – Loading an image file and drawing a 2D sprite

// Load an image from storage
CIw2DImage* image = Iw2DCreateImage("candy_gem.png"); 
// Draw the image on screen
Iw2DDrawImage(image, CIwFVec2(x, y), CIwFVec2(width, height));

Marmalade can load a variety of different image formats directly from storage.

Example 2 – Loading a 3D model, materials and textures and rendering it

// Load a 3D model, its material and textures
CIwResGroup* group = IwGetResManager()->LoadGroup("my_model.group");
// Find the model resource
CIwModel* my_model = (CIwModel*)group->GetResNamed("my_model", IW_GRAPHICS_RESTYPE_MODEL);

// Build models 3D transform
CIwFMat transform
transform.SetRotY(rotation.y);
transform.ScaleRot(scale);
transform.SetTrans(position);
IwGxSetModelMatrix(&transform);

// Render model
my_model->Render();

Marmalade stores 3D models and their associated data together in a convenient resource group, allowing the related resources to be loaded and unloaded together. Tools are provided that convert data from 3D Studio Max and Maya directly to Marmalade resource groups, providing an efficient and reliable asset conversion pipeline.

Example 3 – Playing streamed music

// Check if MP3 is supported and play an MP3 file
if (s3eAudioIsCodecSupported(S3E_AUDIO_CODEC_MP3))
    s3eAudioPlay("background_music.mp3");

Marmalade supports playback of a variety of different audio and video formats.

Example 4 – Reading the accelerometer

// Read accelerometer values
int x = s3eAccelerometerGetX();
int y = s3eAccelerometerGetY();
int z = s3eAccelerometerGetZ();

Marmalade supports a variety of input devices including accelerometer, compass, touch, keyboard and so on.

Example 5 – Making in-app purchases

// Initialise billing
IwBilling::Init("public_key", IwBilling::BILLING_VENDOR_GOOGLE_PLAY);

// Purchase a product
IwBilling::PurchaseProduct("product_id");
Marmalade supports a wide variety of app stores including

Marmalade supports a wide variety of app stores including Apple App Store, Google Play, Amazon AppStore, Samsung Apps, BlackBerry App World and more.

All of the above examples will behave consistently across all supported platform and devices. Code written using the Marmalade SDK is easy to write and maintain, cutting project costs substantially.

Centralised development hub

The Marmalade Hub is a tool that centralises in a platform independent manner the following functions:

  • Project creation
  • Project compile and test
  • Project deployment to device and for app stores

This eliminates the need for working with makefiles and build scripts and across different sets of tools.

The Marmalade Hub also checks dependencies on the user’s system to ensure that everything is installed and operational.

Easy testing under simulation

The Marmalade simulator is a tool that enables the developer to test their creations directly on the desktop at full speed providing a rapid test environment that can speed up development substantially.

The simulator has a long list of great features that can aid development and testing, including the simulation of a raft of different input devices, screen resolutions / orientations, memory sizes, audio etc.

The simulator also supports metrics, which enables the developer to see how often events such as memory allocations/de-allocations, API calls and GL calls occur.

Pedal to the metal performance

The Marmalade SDK does not use any interpreters or VMs, all code is compiled and optimised for the target processor (ARM, x86 and MIPS) providing super fast 60 frames per second gameplay for both 2D and 3D games.

Summary

Cross platform mobile game development is a difficult, costly and long-winded process, but it doesn't have to be.

The many Made with Marmalade games and apps that are available on the app stores show that developers can take products cross platform whilst at the same time minimising the usual issues that accompany such an approach.

Marmalade’s single language, unified API with convenient tools such as the Hub and the simulator can help to bring costs down, making viable projects that were once out of the question.

The Marmalade SDK is available from here under various licenses including a free license.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here