NDK with Cocos2dx made easy

Whenever i worked on Cocos2dx(http://www.cocos2d-x.org), a framework for making 2d games for free, I always thought how would i integrate the 3rd party SDKs into my game. After loads of search and messing up with code, i found out that to do that i need to jump into the languages that the platform provides to connect it easily, or to rewrite the whole thing again on C++ to make sense to the code i am using.

Even writing in different platforms wasn’t that easy when you have to deal with C++ as a core language and jump into the other language to perform some tasks and get back to where you were to make game running smooth. I scratched my head alot of times just to make sure things are working as they should be and most of my time was spent to test the code and linking between languages. After some efforts i was able to run my game as well as get it integrated with some frameworks and 3rd party SDKs on iOS specifically. The time had come to get done with the same game on android platform. My whole code was running, everything was flawless until i found that none of my integration code would work on Android as it was on iOS. It was a sad day for me to find that out, my code was creating un-necessary bugs, stupid errors and most of all includes errors. Finally i managed to work around here and there and on bits to make it work correctly on Android. Done thing!

But from there i thought, why not to create a library on which i can simply pass a message to the language above C++ that is my native platform that is Java or Objective-C and keep my C++ code clean to run on other platforms too that Cocos2dx is supporting or might be supporting. Hence i create something known as EasyNDK.

With this library i can connect to the native platform with minimalistic work to be done and the benefit was as the code was written in the native language any thing that can be done in the native could be done through this mechanism, hence any 3rd party SDK or any work that has to be done on Java or Obj-C could be done here. I my self integrated many libraries using this library. Finally i launched the library on Github for the world to use it and comment over it. Be a part of the users or even testers if you wish to. Let me know about any changes or any improvements that could be done to the library, i will be more than welcome to serve you with my best.

Thanks for reading and giving me your time. Below is the link to Github and the Wiki page i created on Cocos2dx.

Github Code Base : https://github.com/aajiwani/EasyNDK-for-cocos2dx

Wiki Page : http://cocos2d-x.org/projects/cocos2d-x/wiki/EasyNDK


Easy CURL for PHP

Hello all the readers,

This time its about PHP. Yes PHP ! Last project on which i was working on was on PHP. Quite many MySQL in it and quite many web requests. When it came to web requests, the only thing that was in my mind was CURL. That a good to use way to make web requests. As i was working quite after a long time on PHP, didn’t remember much of its library. Went to php.net and searched through the whole libraries and some tutorials to follow to make dummy requests to servers. It was kinda messy. I searched through net to find some wrappers for the CURL in PHP. But ! wasn’t able to find any good OOP based wrapper for CURL in PHP.

Many wrappers were there, and some were really good. But mostly all of them dealt with the underlying curl resource of PHP. Actually that was the problem, remembering all those constants was a pain for me (and i guess for many others). So i thought for a way out of this problem. MAKE MY OWN WRAPPER CLASS.

My goals were quite clear, i have to write such a wrapper that can give the strength of underlying yet be a simple one. So that the pain part can be removed. More over the result should be parsed and fetch in a properties way so that i don’t have to much working on the result to just get out the cookies or headers from it.

Getting inspiration from C# WebRequest class. I tried to create the PHP’s curl class. Please take out your time to view the Examples given with the code. And comment if you like and if you found anything missing or not properly done please report. I would be waiting for the comments.


Link to the Code Repository : Easy CURL for PHP

C# style WebClient for Android

In last several months, i have been working on multiple mobile devices, like iPhone, WinPhone, Android and Palm Pre. I have came to a conclusion after making apps for these devices, that internet is quite a must in each application almost. And all platforms do support the web in quite an awesome way. Although i have tried every basic thing to run web in the device, but i found C#/.NET does it in a natural way that is more intuitive. It simply creates a WebClient and has call back style APIs, whenever any event is fired if we have attached any delegate for that event, that delegate is called. Thats quite AWESOME ! But while working on android i never found such thing in Java, that are delegates to call (Java 6).

And the HttpClient in android is although not a pain to call and work with, but its quite messy to just call a single url. I worked with it for many things, but was not satisfied. So after a while i was like tired of the HttpClient in android, so i tried to port the C# WebClient in android. For that i have to find a generic way that won’t make it even more pain to work with, i tried many things like Handlers and Threads (As it has to be thread safe), but they weren’t that good, the pain is still there. Needed to find a structure that is not verbose but works like a charm.

I came across AsyncTask in android, and it was an easy way to get rid of threads and was thread safe too. I liked it, and decided to make my WebClient a subclass of AsyncTask and it was quite nice to just create and object of this class and call a web page because it is a safe and easy way to handle threads, UI thread is not disturbed. Quite awesome, i found a way out to get out of the mess. But a thing that is left are delegates, else there is no use for it, because it won’t be a generic way to call the webpages.

I searched over net for any delegates thing i found, i found several ways. Two of them were Interface and Reflections (I know its costly). I thought if i would go for Interface any activity that will implement the interface can just have a single call back function to respond on any event WebClient would generate, that is cool but again there would be a mess in that single function that will implement it, there would be a whole lots of switch cases or if then else. Ah that would be bad again. Then the last option was Reflections API, i know, i know its costly. But the effectiveness is more costly than computing. So i decided to move on with Reflections API.

Method was the class that can do the stuff like delegates, but i wanted a better way to call them. So i decided to go for strings as the function name to pass instead of Method. So it makes the API look cool and easy to use, just pass the string as the name of the function, the Class in which this function exists, and if its an instance method pass the receivers instance else just null if the function is static. Well thats just how i made it, i have posted the whole source code on GITHUB, if you want it you may go there and have it, if you don’t want to get messy with code just download the jars and get started. More over i have added a README file over there that contains all the info you require to use the WebClient with examples. Hope you find it good and please comment in either cases if you like it or not.

I will be waiting impatiently for the comments. Thanks.

Link for GIT-HUB : WebClient for Android