Re-coding and Optimizing Cocos2d-x Games for 64-bit ARM Processors (PART 2)

Datetime:2016-08-23 04:31:45         Topic: Cocos2d-X          Share        Original >>
Here to See The Original Article!!!

The links of the full article:

4. Re-coding and Optimizing 64-bit Cocos¶

4.1 Compile the 64-bit third party software¶

These libraries contained in cocos2d-x are 32-bit, in order to compile 64-bit engine, we should download and compile these third party software in 64-bit mode.

Configure 64-bit compile environment:

#export NDK=$PATH/android-ndk-r10b

#export CC="$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc –sysroot=$NDK/platforms/android-L/arch-arm64"

4.1.1 libfreetype¶

#cd ~/libfreetype
#./configure --host=aarch64-linux –disable-shared
#cd ./objs/.libs/

The static library libfreetype.a is we need.

4.1.2 webp¶

#cd ~/webp
#./configure --host=aarch64-linux
#cd ./src/.libs/

The static library libwebp.a is we need.

4.1.3 tiff¶

#cd ~/tiff
#./configure --host=aarch64-linux
#cd ./libtiff/.libs/

The static library libtiff.a is we need.

4.1.4 png¶

#cd ~/libfreetype
#./configure --host=aarch64-linux
#cd ./.libs/

The static library libpng.a is we need.

4.1.5 jpeg¶

#cd ~/jpeg
#./configure --host=aarch64-linux
#cd ./.libs/

The static library libjpeg.a is we need.

4.1.6 libcurl¶

#cd ~/libcurl
#./configure --host=aarch64-linux
#cd ./lib/.libs/

The static library libcurl.a is we need.

4.1.7 libwebsocket¶

#cd ~/libwebsocket
#./configure --host=aarch64-linux
#cd ./objs/.libs/

The static library libwebsocket.a is we need.

4.2 Re-coding and Optimizing Cocos2d-x and apps¶

In order to compile 64-bit apps, we need change some code in cocos2d-x and apps, such as libraries, code and configuration options. In addition, for improving performance, we make some optimization in cocos2d-x engine.

4.2.1 Re-coding¶

Add 64bit libraries to cocos2d-x engine, libjpeg.a as a example:

#cd ~/cocos2d-x/external/jpeg/prebuilt/android

#mkdir arm64-v8a

#cp ~/libjpeg.a ~/cocos2d-x/external/jpeg/prebuilt/android/arm64-v8a/

By the same method to add other 64-bit third party libraries, similar as the following screen shot:

Change the in cocos for compiler can identify the neon instruction:

Change the in tests/cpp-tests/, because of the older 64bit NDK can not identify the v register:

In the 64-bit mode, the variable intptr_t is long type, so we can not assign a int pointer to a long pointer. We should modify those error codes.

4.2.2 Optimizing¶

In order to obtain better performance in 64-bit mode, we optimize the math algorithm in the cocos2d-x engine, rewrite the related those code using arm64-v8a neon instruction. Detail please refer to the committed patches on the upstream (cocos2d-x project)

4.3 Build 64-bit Cocos2d-x and apps¶

To build 64-bit cocos2d-x and apps, we should use ndk-r10b and 64-bit SDK, add APP_ABI='arm64-v8a' in the compiling options:

#android list targets

#cd ~/build
#python -n "APP_ABI='arm64-v8a'"  -p 20 cpp-tests

#cd  cocos2d-x/tests/cpp-tests/

In the directory of libs, we can see arm64-v8a which include 64-bit shared library; the 64-bit CppTests-debug.apk in directory of bin.

To be continued...


Put your ads here, just $200 per month.