Wednesday, December 18, 2013

Enabling http gzip compression (mod_deflate) in apache

Installing apache on linux server took somewhat a bit long time, 'cause many additional libraries need  installation first.

Here is the list:

apr apr-1.5.0.tar.gz
apr-util apr-util-1.5.3.tar.gz
pcre libpcre
zlib zlib
apache (actually I'm using 2.4.6) httpd-2.4.7.tar.gz

Unzip the files and install them in your server. After installing apr, apr-util, libpcre, zlib, goto the unzipped httpd directory and run
./configure --enable-deflate
If you need enable other modules you can specify in the command. Running above command may tip you missing libraries (in my server I miss apr/apr-util/pcre), just install them. When the configuration is done, run
make
make install
Then apache should have been installed.

To enable HTTP gzip compression, modify the httpd config file:
cd /usr/local/apache2vim conf/httpd.conf
Add lines in the config files:
LoadModule deflate_module modules/mod_deflate.so
<IfModule mod_deflate.c>
        SetOutputFilter DEFLATE
        # You can't compress what is already compressed
        SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
        SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
        # Make proxies work as they should.
        <IfModule mod_headers.c>
                Header append Vary User-Agent
        </IfModule>
</IfModule>

Exit editting and restart apache
bin/apachectl restart

Now your server has enabled gzip compression! You can validate whether you have succeed or not in this website  HTTP gzip compression test .

Tuesday, December 17, 2013

Make TeamCity to work with git submodule

Recently I'm using TeamCity to build .ipa automatically from github, however when I ran project in TeamCity and came to the step checkout files into agent, it always reported an error:
Clone of 'git@github.com:cocos2d/cocos2d-html5.git' into submodule path 'external/cocos2d-html5' failed
I checked the account authority and even cloned files via terminal git, all things run well. So it mustn't be the authority problem.

At last this error was solved by changing git from SSH to HTTPS access.

1. Edit .gitmodules file in the root project, change the addresses of submodules to HTTPS addresses

2. Change directory in every submodule, set fetch and push address to HTTPS
cd $submodule
git remote -v
git remote origin set-url https://github.com/your_git_address

And then TeamCity works properly.

Wednesday, November 27, 2013

Be caution fo uninitialized pointer in jni (android ndk)

ClassFoo* foo;if (foo == NULL) {    // do someting..}
I compiled above code in Xcode simulator and iPhone, do something runs correctly as I expect. 

However, on Android (foo == NULL) returns false, so do something never got to execute. I'm compiling the code with APP_CPPFLAGS := -std=c++11 in Application.mk.


So you'd better initialize pointer to NULL to ensure your code runs correctly on both iOS and android... 

ClassFoo* foo = NULL;if (foo == NULL) {    // do someting..}
BTW, working with android NDK and SDK really sucks.

Hybrid development with cocos2d-x jsb and cocos2d-html5

Somewhat it seems that in game development, the testing and making changes using only cocos2d-x is a bit time-consuming, and version publication in app store takes a long time.

Hybrid development with cocos2d-x javascript binding seems to solve the above problems. We develop in javascript, test and make changes can be done via web browser, and make solutions for resources update to advance version publication progress. Everything becomes flexible.


So how to do it? Here I'll show a simple example. I'm using cocos2d-x-2.2 and cocos2d-html5 2.2.  Download here and decompress somewhere in your disk.


1. Creating a project

create a project in your terminal:
$ cd cocos2d-x-2.2/tools/project-creator/ 
$ python ./create_project.py -project HelloWorldJS -language javascript -package com.example.AwesomeGame
proj.ios : Done!
proj.android : Done!
proj.win32 : Done!
New project has been created in this path: /Users/yourname/Projects/cocos2d-x-2.2/projects/HelloWorldJS
Have Fun!

2. Importing project to Xcode

open the project in Xcode, you can see javesript files created in your app's Resources folder.

3. JavaScript Coding

Since coding javascript in Xcode would be painful because there are no completions and error checking.. I use WebStorm of JetBrains to write javascript codes. 

Open WebStorm and select Create New Project from Existing Files, next check Source files are in a local directory, no Web server is yet configured.
next select the project folder you just created in step 1 as Project Root. You can edit javascript code now but without cocos2d related code completion.

4. JavaScript code completion

Import cocos2d-html5 library to your WebStorm. Open WebStorm preference, and find JavaScript->Libraries, click Add:
select cocos2d-html5 folder you downloaded in step 1.
after adding cocos2d-html5 library your can use code completion in WebStorm. Enjoy!






5. Testing with Xcode/browser

As you code in WebStorm and save file, you can directly use Xcode to run and see the result.
Also, since it's written by javascript, you can also run you app in web browser. This step is rather straight-forward.



a. Just create a project(namely HelloWorldHtml5) using cocos2d-html5 and put your $HelloWorldJS/Resources/src/ files into $HelloWorldHtml5/src/ and overwrite it. 

b. In your terminal, navigate to $HelloWorldHtml5 folder and start web server with a simple command: 

$cd $HelloWorldHtml5
$python -m SimpleHTTPServer 8000
c. open http://localhost:8000 in your browser and you can now play your game in it!

(or the better way is to copy cocos2d.js/build.xml/index.html/main.js etc. files into HelloWorldJS folder and start web server there, in this way we needn't copy files every time.)


6. Summary

As you finished 5 steps you can now code and test your game easily. For the resources update part, there are many solutions. I came up with one with myself and maybe we can talk about it someday.

Friday, November 22, 2013

IntelliJ IDEA deploy to android device with error "USB device not found"

I downloaded IntelliJ and created the first android project, but I got "USB device not found" error when I tried to run project in my device.


Solution:
goto the android sdk root directory (noted as <sdk>),

$cd <sdk>/platform-tools 
$./adb kill-server 
$./adb devices

in my mac, I got the message in my terminal:
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached 
E616 device

Return to IntelliJ and run, you will found application run in your devices successfully.

Hello World!

From today on I decide to start writing something down on the way in game development. Mainly focus on mobile games on iOS and android. Move on to make best game!