📜 ⬆️ ⬇️

We are friends with AirPlaySDK

It's no secret that coding for mobile phones is an interesting, profitable and promising business. I always launch a game on the PDA when I go down to the subway and see how the people around me do the same. But unfortunately the current variety of platforms often forces us to limit the range of supported devices.

Ideaworks Labs took care of us and created AirPlaySDK. This toolkit allows you to write code in C ++ once and compile it into native applications for iOS, Android, Samsung Bada, Symbian, Windows Mobile, BREW, Palm / HP WebOS and Maemo platforms. Well, impressive? In addition, AirPlaySDK has excellent documentation (albeit in English) and allows you to use the unique features of a particular platform. You can download and try AirPlaySDK for free from www.airplaysdk.com or buy a Indie license for only $ 99, and iPhone developers can use this tool for free (that is, for free).

Creating a project


AirPlaySDK allows you to write applications in Windows or Mac OS, and integrates well with Visual Studio (from version 6.0) and XCode, respectively. I will be guided by the Visual Studio, but I am sure that for XCode everything will look just as easy.
So, you downloaded and installed AirPlaySDK and Visual Studio. Create a HelloWorld folder in some place on your disk. It is in this folder will be placed our first project.
The main file of the entire solution is HelloWorld.mkb in the HelloWorld folder, create and open it for editing and enter the following contents there:
')
options { s3e-data-dir="data" } files { (source) HelloWorld.cpp HelloWorld.h HelloWorldMain.cpp } subprojects { iw2d } 


Here, the s3e-data-dir parameter of the options section defines the folder in which the resources of the future application will be located. It can be images, music or something else. Create the data folder we declared in the HelloWorld folder.

The files section describes the list of project files. In parentheses we indicate the source folder, which should also be created. In it we will put three files: HelloWorld.cpp , HelloWorld.h and HelloWorldMain.cpp .

The subprojects section contains the names of the libraries that we want to use in our project.

Cross-platform “Hello World!”


So, the preparation of the project is completed and we can start programming. To do this, double-click on the HelloWorld.mkb file and you will first see the AirPlaySDK logo, and then you will see a project in Visual Studio. Beat the code below into the HelloWorldMain.cpp file, but for now I’ll explain what's what.

 #include "s3e.h" #include “HelloWorld.h” int main() { GameInit(); while (true) { s3eDeviceYield(0); s3eKeyboardUpdate(); bool result = GameUpdate(); if ((result == false) || (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyLSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest())) break; GameRender(); } GameShutdown(); } 


With the help of the directive #include “s3e.h” we connect the standard header file AirPlaySDK, which allows us to work with a mobile device.

The GameInit () function we write ourselves. It will initialize the variables we need, create objects in every possible way, load resources and perform other actions immediately when the program starts.

The s3eDeviceYield (..) function stops the device operation for the time specified in the parameter and allows the operating system to perform some actions. As a parameter of this function, we passed a zero, and therefore we obtain the minimum possible delay allowed by the operating system.

s3eKeyboardUpdate () updates the information on the current status of the keys of the mobile phone and checks whether the user has pressed any keys during the cycle pass.

We will write the function GetUpdate () by ourselves. As usual, all the logic of the application operation is usually placed in it. If you are writing a game, then in this function you should check if the next monster has died after the user's shot. It should be noted that the function returns true if the application continues its work, or false if, for example, the user has clicked “Exit game”.

This is followed by checking whether the user did not want to exit the application by pressing the corresponding menu item or the phone key, and whether the operating system asks our application to terminate, and in case of a positive result, ends the main loop. If the application should continue to work - go ahead.

In GameRender () , which we will again create independently, there is a drawing of everything and everything on the screen. And finally, GameShutdown () (the fourth so far non-existent function) terminates the work of our application, saving the results, freeing up memory and performing other operations.
Well, we have disassembled the main function of the application. It is worth noting that the HelloWorldMain.cpp file is a template. Such a file with almost the same content will be present in all projects that you will create using AirPlaySDK.

We describe the application logic


Now it's time to do the functions that will directly determine the logic of the application. To do this, open the HelloWorld.cpp file and type in the code:

 #include "Iw2D.h" void GameInit() { Iw2DInit(); } bool GameUpdate() { return true; } void GameRender() { Iw2DSetColour(0xFF000000); Iw2DFillRect( CIwSVec2(0, 0), CIwSVec2(Iw2DGetSurfaceWidth(), Iw2DGetSurfaceHeight()) ); Iw2DSetColour(0xFF00FF00); Iw2DFillArc( CIwSVec2(Iw2DGetSurfaceWidth()/2, Iw2DGetSurfaceHeight()/2), CIwSVec2(30, 30), 0, 0x800 * 2 ); Iw2DSurfaceShow(); } void GameShutdown() { Iw2DTerminate(); } 


As you have already noticed, the HelloWorld.cpp file code contains the functions that I promised to describe. There is nothing difficult in this listing. He just fills the screen with black color and displays a green circle in the middle.

Now it is worth describing the prototypes of these functions in the header file HelloWorld.h , to be able to call them from the main function main () . It will look like this:

 #ifndef HELLOWORLD_H #define HELLOWORLD_H void GameInit(); bool GameUpdate(); void GameRender(); void GameShutdown(); #endif 


Listing does not need comments. The code of our application is ready and you can run it for execution by pressing the F5 key in Visual Studio. Before you open the emulator window, which will demonstrate our first creation on AirPlaySDK.

Build project


Well, it is time to demonstrate the main advantage of AirPlaySDK - application portability from one platform to another.

Select “GCC (ARM) Release” as the active project configuration and press F5. You will see the Airplay System Deployment Tool window. Check the “ARM GCC Release” and click “Next”. The next step is nothing interesting for us so far, so click “Next” once more. It is here that you want to note the variety of platforms under which we want to compile our application. Let's mark the OS Bada, click “Deploy All” and wait for the end of the compilation of our project.

PS In addition to the two-dimensional graphics, AirPlaySDK allows you to create three-dimensional games , work with GPS, sounds, contact lists, a network, video, and a bunch of other things.

UPD. For some time, the Airplay SDK has been renamed to Marmalade SDK.

Source: https://habr.com/ru/post/120684/


All Articles